function getHelpTopics($str) { $result = myquery("SELECT COUNT(*) FROM `" . dbprfx . "help` WHERE `typekey` = '" . $str . "'"); if (mysql_result($result, 0) > 0) { $result2 = myquery("SELECT * FROM `" . dbprfx . "help` WHERE `typekey` = '" . $str . "' LIMIT 1"); $array2 = myarray($result2); return $array2['helpdata']; } }
function getLocalConfig($object) { $keyarray = explode(";", $object); // TYPE;SCRIPT;ACTIONSCRIPT $countresult = myquery("SELECT COUNT(*) FROM `" . dbprfx . "master-config` WHERE `key` LIKE ';" . $keyarray[0] . ";" . $keyarray[1] . ";" . $keyarray[2] . ";%'"); $count = mysql_result($countresult, 0); if ($count < 1) { return FALSE; } else { $result = myquery("SELECT * FROM `" . dbprfx . "master-config` WHERE `key` LIKE ';" . $keyarray[0] . ";" . $keyarray[1] . ";" . $keyarray[2] . ";%'"); $x = 1; while ($x <= $count) { $resultarray = myarray($result); $splitarraykey = explode("~", $resultarray['key']); $splitarrayresult = explode("|", $resultarray['data']); if ($splitarrayresult[0] != "") { $foo[$splitarraykey[1]][$splitarraykey[2]][$splitarraykey[3]] = $splitarrayresult[0] + 1 - 1; } elseif ($splitarrayresult[1] != "") { if ($splirarrayresult[1] == "TRUE") { $foo[$splitarraykey[1]][$splitarraykey[2]][$splitarraykey[3]] = TRUE; } else { $foo[$splitarraykey[1]][$splitarraykey[2]][$splitarraykey[3]] = FALSE; } } elseif ($splitarrayresult[2] != "") { $foo[$splitarraykey[1]][$splitarraykey[2]][$splitarraykey[3]] = $splitarrayresult[2]; } else { $foo[$splitarraykey[1]][$splitarraykey[2]][$splitarraykey[3]] = "not"; } unset($splitarrayresult); $x++; } } return $foo; }
function wsOnMessage($clientID, $message, $messageLength, $binary) { global $Server; $ip = long2ip($Server->wsClients[$clientID][6]); // check if message length is 0 if ($messageLength == 0) { $Server->wsClose($clientID); return; } if (preg_match("/\\/##login::/", $message)) { $messageexplode = explode("::", $message); $result = myquery("SELECT COUNT(*) FROM `" . dbprfx . "auth-user` WHERE `username` = '" . myescape($messageexplode[1]) . "'"); if (mysql_result($result, 0) > 0) { $result2 = myquery("SELECT * FROM `" . dbprfx . "auth-user` WHERE `username` = '" . myescape($messageexplode[1]) . "' LIMIT 1"); $array2 = myarray($result2); if (md5($messageexplode[2] . $array2['passsalt']) == $array2['passhash']) { myquery("UPDATE `" . dbprfx . "auth-user` SET `clientid` = '" . $clientID . "',`clientidassigntime` = '" . time() . "' WHERE `username` = '" . myescape($messageexplode[1]) . "'"); $user = $array2; $commandresponse = "You are now logged in as: " . $messageexplode[1]; } else { $commandresponse = "ERROR: Incorrect Password"; } } else { $commandresponse = "ERROR: Unknown User"; } unset($messageexplode); } elseif (preg_match("/\\/##register::/", $message)) { $messageexplode = explode("::", $message); $result = myquery("SELECT COUNT(*) FROM `" . dbprfx . "auth-user` WHERE `username` = '" . myescape($messageexplode[1]) . "'"); if (mysql_result($result, 0) < 1) { $salt = gen_uuid(); myquery("INSERT INTO `" . dbprfx . "auth-user` (`user-uuid`,`clientid`,`clientidassigntime`,`username`,`passhash`,`passsalt`,`userperms`) VALUES ('" . gen_uuid() . "','" . $clientID . "','" . time() . "','" . myescape($messageexplode[1]) . "','" . md5($messageexplode[2] . $salt) . "','" . $salt . "',';user-normal;')"); $result2 = myquery("SELECT * FROM `" . dbprfx . "auth-user` WHERE `username` = '" . myescape($messageexplode[1]) . "' LIMIT 1"); $user = myarray($result2); $commandresponse = "You have successfully registered. You are now logged in as: " . $user['username']; } else { $commandresponse = "ERROR: Username already exists, please select another."; } unset($messageexplode); } elseif (preg_match("/\\/##help/", $message)) { $commandresponse = getHelpTopics("ALL:MAIN"); } //Send the message to everyone but the person who said it foreach ($Server->wsClients as $id => $client) { if ($id != $clientID) { $result = myquery("SELECT COUNT(*) FROM `" . dbprfx . "auth-user` WHERE `clientid` = '" . $clientID . "'"); if (mysql_result($result, 0) > 0) { $result2 = myquery("SELECT * FROM `" . dbprfx . "auth-user` WHERE `clientid` = '" . $clientID . "' ORDER BY `clientidassigntime` DESC LIMIT 1"); $user = myarray($result2); } if (isset($user['username'])) { $Server->wsSend($id, $user['username'] . " said \"{$message}\""); } else { $Server->wsSend($id, "Visitor {$clientID} said \"{$message}\""); } } elseif (isset($commandresponse)) { $Server->wsSend($id, $commandresponse); unset($commandresponse); } } }