Initial commit
This commit is contained in:
commit
43ad32700c
7085 changed files with 447606 additions and 0 deletions
181
modules/chat/chatfunctions.inc.php
Normal file
181
modules/chat/chatfunctions.inc.php
Normal file
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
If (!defined("in_astat")) {
|
||||
die("Dieses Script kann nicht ausserhalb des Frameworks laufen!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Case insensitive version of array_key_exists.
|
||||
* Returns the matching key on success, else false.
|
||||
*
|
||||
* @param string $key
|
||||
* @param array $search
|
||||
* @return string|false
|
||||
*/
|
||||
function array_key_exists_chat($key, $search) {
|
||||
if (array_key_exists($key, $search)) {
|
||||
return $key;
|
||||
}
|
||||
if (!(is_string($key) && is_array($search) && count($search))) {
|
||||
return false;
|
||||
}
|
||||
$key = strtolower($key);
|
||||
foreach ($search as $k => $v) {
|
||||
if (strtolower($k) == $key) {
|
||||
return $k;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_user_list() {
|
||||
global $config, $ccache;
|
||||
// Open URL to userlist
|
||||
// erzeuge einen neuen cURL-Handle
|
||||
$ch = curl_init();
|
||||
// setze die URL und andere Optionen
|
||||
curl_setopt($ch, CURLOPT_URL, "https://chatsrv.austriachat.net/info");
|
||||
//curl_setopt($ch, CURLOPT_URL, "https://46.4.58.184/info");
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
// führe die Aktion aus und gebe die Daten an den Browser weiter
|
||||
$fh=curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
//var_dump(curl_getinfo($ch));
|
||||
|
||||
// schließe den cURL-Handle und gebe die Systemresourcen frei
|
||||
curl_close($ch);
|
||||
|
||||
if($httpCode >= 200 && $httpCode < 300){
|
||||
//$content = $ccache->get('roomdata');
|
||||
|
||||
$content = json_decode($fh,true);
|
||||
$userlist = array();
|
||||
foreach($content as $room) {
|
||||
$room_name = $room['room'];
|
||||
$userlist[$room_name]['s'] = $room_state;
|
||||
$userlist[$room_name]['u'] = array();
|
||||
$userlist[$room_name]['g'] = $type;
|
||||
if(!is_array($room['users'])){
|
||||
unset($userlist[$room_name]);
|
||||
continue;
|
||||
}
|
||||
foreach($room['users'] as $user) {
|
||||
$userlist[$room_name]['u'][$user['nick']] = $user['color'];
|
||||
}
|
||||
}
|
||||
|
||||
// Return userlist
|
||||
return $userlist;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function get_user_room($username) {
|
||||
global $config;
|
||||
/* Open URL to userlist
|
||||
if (!$fh = @fopen("http://localhost.localdomain:".$config['SOCK_PORT']."/info/?", "r"))
|
||||
return false;
|
||||
|
||||
// Read data and close
|
||||
while(!feof($fh))
|
||||
$content .= fread($fh, 1024);
|
||||
fclose($fh); */
|
||||
$content = $ccache->get('roomdata');
|
||||
$content = trim($content);
|
||||
$content = explode("\n", $content);
|
||||
|
||||
// Create userlist array
|
||||
// Format of array:
|
||||
// $userlist[$room_name]['s'] = $room_state
|
||||
// $userlist[$room_name]['u'][$nick] = $color
|
||||
foreach($content as $line) {
|
||||
$data = explode("|", $line);
|
||||
list($nick, $color) = explode(",", $data[1]);
|
||||
list($room, $status,$type) = explode(",", $data[0]);
|
||||
$list[$nick]['c']=$color;
|
||||
$list[$nick]['r']=$room;
|
||||
$list[$nick]['s']=$status;
|
||||
$list[$nick]['g']=$type;
|
||||
}
|
||||
if(array_key_exists_chat($username,$list)){
|
||||
return $list[$username];
|
||||
}else{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
function chat_online(){
|
||||
global $session, $config;
|
||||
$online=get_user_list();
|
||||
if($online!==FALSE){
|
||||
$rooms=array_keys($online);
|
||||
$i=0;
|
||||
$data["usercount"]=0;
|
||||
$data["gdusercount"]=0;
|
||||
if(!isset($online[""])){
|
||||
foreach($rooms as $room){
|
||||
if(($session->userdata['allow_grimdark']==0 || $session->userdata['uid']==0) && $online[$room]['g']=='grimdark'){
|
||||
continue;
|
||||
}
|
||||
if($online[$room]["s"]=="locked"){
|
||||
$data[$i]["room"]=$room . " <span style=\"color:red;\">[abgeschlossen]</span>";
|
||||
}elseif($online[$room]["s"]=="password"){
|
||||
$data[$i]["room"]=$room . " <span style=\"color:red;\">[password]</span>";
|
||||
}else{
|
||||
$data[$i]["room"]=$room . " <span style=\"color:green;\">[offen]</span>";
|
||||
}
|
||||
$users=array_keys($online[$room]["u"]);
|
||||
foreach($users as $user){
|
||||
if($data[$i]["users"]){
|
||||
$data[$i]["users"].=', ';
|
||||
}
|
||||
if($online[$room]['g']=='grimdark'){
|
||||
$data['gdusercount']++;
|
||||
}else{
|
||||
$data['usercount']++;
|
||||
}
|
||||
$data[$i]["users"].='<a href="//'.$config['domain'].'/np/'.$user.'" target="_blank"><span style="color:#'.$online[$room]["u"][$user].'">'.$user.'</span></a>';
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}else{
|
||||
$data["chat_offline"]=true;
|
||||
$data["usercount"]=0;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
function chat_data(){
|
||||
$online=get_user_list();
|
||||
if($online!==FALSE){
|
||||
$rooms=array_keys($online);
|
||||
$i=0;
|
||||
if(!isset($online[""])){
|
||||
foreach($rooms as $room){
|
||||
$users=array_keys($online[$room]["u"]);
|
||||
foreach($users as $user){
|
||||
$data[$i]["user"]=$user;
|
||||
$data[$i]["room"]=$room;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($data as $user){
|
||||
echo "(".$user["user"].") (".$user["room"].")\n";
|
||||
}
|
||||
|
||||
}else{
|
||||
$data["chat_offline"]=true;
|
||||
$data["usercount"]=0;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue