Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class OCP {
- private $god;
- private $ip;
- private $count;
- private $port;
- public $users = array();
- public $name;
- public $config;
- public $mysql;
- private $socket;
- public $serverCount;
- public $debugMode;
- public function __construct($parent,$file) {
- $this->god = $parent;
- global $count;
- $count++;
- $this->count = $count;
- echo "\n\n\n";
- echo "|----------------------------------------------|\n";
- echo "| Iniciando Servidor ... |\n";
- echo "|----------------------------------------------|\n";
- $this->config = json_decode(json_encode($file));
- date_default_timezone_set($this->config->timezone);
- $this->name = $file["Server". ($this->count-1) ."Name"];
- ($this->count == 1)? $name = "de " : $name = "";
- $this->writeOutput("Iniciando server $name". $this->name ."... ", "INF");
- //$this->god->mysql = &$this->god->mysql;
- $this->bind(6111+$this->count);
- $this->port = 6111+$this->count;
- $this->writeOutput("SERVER PRONTO ! porta: ".(6111+$this->count)."\n", "PERFEITO");
- $this->debugMode = $this->config->DebugMode?true:false;
- }
- public function bind($port) {
- $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or $this->shutDown("Problema nos sockets, desligando...");
- socket_set_option($this->socket, SOL_SOCKET, SO_REUSEADDR, 1);
- socket_bind($this->socket, 0, $port) or $this->shutDown("Erro ao vincular a porta, desligando...");
- socket_listen($this->socket);
- }
- public function loopFunction() {
- socket_set_block($this->socket);
- $read = array();
- $read[0] = $this->socket;
- foreach ($this->users as $i=>&$user) {
- if (!empty($user))
- $read[] = &$user->sock;
- if ($user->selfDestruct == true)
- unset($this->users[$i]);
- }
- $ready = socket_select($read,$null, $null, 0);
- if (in_array($this->socket, $read)) {
- if (count($this->users) <= 1000) {
- $this->users[] = new OCPUser(socket_accept($this->socket), $this, $this->god);
- if ($this->count > 1)
- $usersOn = "online, Total: ".$this->getServerCount(); else $usersOn = "logado";
- $this->writeOutput("Novo user ".$usersOn, "BOM");
- } else if(count($this->users) >= 1000)
- $this->writeOutput("Server cheio ! :(", "INFO");
- }
- if ($ready-- <= 0)
- return;
- else {
- foreach ($this->users as $index=>&$user) {
- if (in_array($user->sock, $read)) {
- $input = socket_read($user->sock, 65536);
- if ($input == null) {
- unset($this->users[$index]);
- continue;
- }
- $x = explode(chr(0), $input);
- array_pop($x);
- foreach ($x as $input2){
- $this->handleRawPacket($input2, $user);
- }unset($x);
- }
- }
- }
- }
- public function getServerCount() {
- $i = 0;
- foreach ($this->users as $user) {
- $i++;
- }
- $this->serverCount = $i;
- return $i;
- }
- public function doLogin(&$user, $packet) {
- $username = $this->god->mysql->escape($this->stribet($packet, "<nick><![CDATA[", "]]"));
- $password = $this->god->mysql->escape($this->stribet($packet, "<pword><![CDATA[", "]]"));
- $query = mysql_query("SELECT * FROM {$this->config->userTableName} WHERE `username`='" . $username . "';");
- if (mysql_num_rows($query) > 0) {
- $dbv = $this->god->mysql->returnArray($query); $dbv = $dbv[0];
- $ModLogin = false;
- socket_getpeername($user->sock, $ip);
- $ModIps = explode("|",$this->config->ModIPs);
- foreach($ModIps as $mips)$ModIps[$mips]=gethostbyname($mips);
- if (in_array($ip,$ModIps))$ModLogin=true;
- $this->writeOutput("Login feito: $username IP: $ip Moderador: $ModLogin");
- if($this->count == 1) $hash = $this->swapMD5(md5($this->swapMD5(strtoupper($dbv["password"])) . $user->key . 'Y(02.>\'H}t":E1')); else $hash = $password;
- if ($password == $hash || $ModLogin) {
- if ($dbv["active"] !== "0" || $ModLogin) {
- if ($dbv["ubdate"] !== "PERMABANNED" || ($ModLogin && $this->config->ModsAreBannable)) {
- if ($dbv["ubdate"] < strtotime("NOW") || ($ModLogin && $this->config->ModsAreBannable)) {
- if ($this->count == 1) {
- //$user->writeSocket($user, "%xt%gs%-1%". . "|".$this->config->Server2IP.":6114:".$this->config->Server2Name.":" . intval($GLOBALS['s2c']/161) . "%3;");
- $this->sendServerPacket($ModLogin,$user);
- $this->writeSocket($user, "%xt%l%-1%" . $dbv["id"] . "%" . md5(strrev($user->key)) . "%0%");
- //mysql_query("UPDATE {$this->config->userTableName} SET lkey='" . md5(strrev($user->key)) . "' WHERE id='" . $dbv["id"] . "';");
- } else {
- $user->id = $dbv["id"];
- $user->isModerator = $ModLogin;
- $user->resetDetails();
- $user->sendPacket("%xt%l%-1%");
- }
- } else $this->writeSocket($user, "%xt%e%-1%601%".round(($dbv["ubdate"]-strtotime("NOW")) /3600)."%");
- } else $this->writeSocket($user, "%xt%e%-1%603%");
- } else $this->writeSocket($user, "%xt%e%-1%900%");
- } else $this->writeSocket($user, "%xt%e%-1%101%");
- } else $this->writeSocket($user, "%xt%e%-1%100%");
- }
- public function sendServerPacket($modLogin,&$user){ $server="";
- for ($l=1;$l<=$this->config->numServers;$l++)
- {
- if (($this->config->{"Server".$l."ModOnly"} && $modLogin) || (!$this->config->{"Server".$l."ModOnly"} && $modLogin) || (!$this->config->{"Server".$l."ModOnly"} && !$modLogin)){
- //if ($this->config->{"Server".$l."ModOnly"}==false){
- if (!empty($this->config->{"Server".$l."Port"})) $port = $this->config->{"Server".$l."Port"}; else $port = 6112+$l;
- $server .= $this->config->{"Server".$l."IP"} .":$port:".$this->config->{"Server".$l."Name"}.":" . intval(($this->god->serverHandle[$l+1]->serverCount)/161+1).':0:0|';
- }
- }
- $server = substr($server,0,strlen($server)-1);
- $user->sendPacket("%xt%gs%-1%$server%3;");
- }
- public function encryptPassword($password, $key) {
- return $this->swapMD5(md5($this->swapMD5($password) . $key . 'Y(02.>\'H}t":E1'));
- }
- public function swapMD5($func_md5) {
- return substr($func_md5, 16, 16) . substr($func_md5, 0, 16);
- }
- public function handleRawPacket($packet, &$user) {
- if ($this->config->DebugMode == true) $this->writeOutput("Pacote recebido: ".$packet);
- switch(substr($packet, 0, 1))
- {
- case "<": $this->handleSysPacket($packet, $user); break;
- case "%": $this->handleXtPacket($packet, $user); break;
- }
- }
- public function handleSysPacket($packet, &$user) {
- if (stristr($packet, "<policy-file-request/>") > -1)
- $this->writeSocket($user, "<cross-domain-policy><allow-access-from domain='*' to-ports='*' /></cross-domain-policy>");
- if (stristr($packet, "<msg t='sys'><body action='verChk'") > -1)
- $this->writeSocket($user, "<msg t='sys'><body action='apiOK' r='0'></body></msg>");
- if (stristr($packet, "<msg t='sys'><body action='rndK' r='-1'></body></msg>") > -1)
- $this->writeSocket($user, "<msg t='sys'><body action='rndK' r='-1'><k>" . $this->generateRandomKey($user) . "</k></body></msg>");
- if (stristr($packet, "<msg t='sys'><body action='login' r='0'>") > -1)
- $this->doLogin($user, $packet);
- }
- public function handleXtPacket($packet, &$user) {
- $packet = $this->god->mysql->escape($packet);
- $raw = explode("%", $packet);
- if ($raw[2] == "s") $this->handleStandardPacket($packet, $user);
- if ($raw[2] == "z") $this->handleGamePacket($packet, $user);
- if ($raw[2] == "iCP") $this->handleCustomPacket($packet, $user);
- if ($raw[2] == "red") $this->handleRedemptionPacket($packet,$user);
- }
- public function getDefaultRoom(){
- $rooms = explode(",",$this->config->DefaultRoom);
- return $rooms[array_rand($rooms)];
- }
- public function handleStandardPacket($packet, &$user) {
- $cmd = explode("%", $packet);$cmd = $cmd[3];
- $h = explode("#", $cmd); $h = $h[0];
- if ($h == "j") $this->handleJoinPacket($packet,$user);
- if ($h == "p") $this->handlePufflePacket($packet,$user);
- if ($h == "i" || $h == "n") $this->handlePlayerPacket($packet,$user);
- if ($h == "l") $this->handleMailPacket($packet,$user);
- if ($h == "m") $this->handleMultiplayerPacket($packet,$user);
- if ($h == "o") $this->handleModeratorPacket($packet,$user);
- if ($h == "s" || $h == "u") $this->handleUserSettingPacket($packet, $user);
- if ($h == "f") $this->handleEPFPacket($packet, $user);
- if ($h == "b") $this->handleBuddyPacket($packet, $user);
- if ($h == "g") $this->handleIglooPacket($packet, $user);
- if ($h == "st" || $h == "i") $this->handleStampsPacket($packet, $user);
- if ($h == "iCP") $this->handleCustomPacket($packet,$user);
- }
- public function handleJoinPacket($packet,&$user){
- $raw = explode("%", $packet);
- $cmd = $raw[3];
- if ($cmd == "j#js") $user->sendPacket("%xt%js%-1%0%1%" . $user->isModerator . "%0%");
- if ($cmd == "j#jp"){
- $user->sendPacket("%xt%jp%" . $raw[4] . "%" . $raw[5] . "%");
- if ($raw[5] == $user->id+1000) $user->joinRoom($raw[5],0,0); else $user->joinRoom($raw[5], $raw[6], $raw[7]);
- }
- if ($cmd == "j#jr") $user->joinRoom($raw[5], $raw[6], $raw[7]);
- }
- public function handlePufflePacket($packet, &$user){
- $raw = explode("%", $packet);
- $cmd = $raw[3];
- if ($cmd == "p#pg"){//Player Puffles
- //$user->sendPacket("%xt%pg%" . $raw[4] . "%");
- $user->sendPacket("%xt%pg%19%199872124|0|Primeiro|0|76|82|88|94|0|0|0|0%199872212|5|Segundo|0|95|100|95|95|0|0|0|0%");
- }
- }
- public function handlePlayerPacket($packet, &$user){
- $raw = explode("%", $packet);
- $cmd = $raw[3];
- if ($cmd == "i#ai")//Add Item
- $user->addItem($raw[5]);
- if ($cmd == "i#gi"){//Get Inventory
- $user->sendPacket("%xt%lp%-1%" . $user->getString() . "%" . $user->getCoins() . "%". $user->isSafe ."%1440%" . time() . "%" . $user->getAge() . "%0%%%");
- $user->sendPacket("%xt%glr%-1%1%");
- $user->joinRoom($this->getDefaultRoom());
- $user->sendPacket("%xt%gi%-1%" . implode("%", $user->getInventory()) . "%");
- $user->sendPacket("%xt%gps%-1%" . $user->getID() . "%".implode("|",$user->getStamps())."%");
- }
- if ($cmd == "n#gn")//Get Ignored List
- $user->sendPacket("%xt%gn%-1%");
- }
- public function handleMailPacket($packet, &$user){
- $raw = explode("%", $packet);
- $cmd = $raw[3];
- if ($cmd == "l#mst"){//???
- $user->loadMail();
- $readCount = 0; foreach($user->mail as $m){ if($m["read"] == "0") { $readCount++; } }
- $user->sendPacket("%xt%mst%" . $user->room . "%" . $readCount . "%" . count($user->mail) . "%");
- }
- if ($cmd == "l#mg")//Mail Get
- $user->sendPacket("%xt%mg%" . $user->room . "%" . $user->getMail());
- if ($cmd == "l#ms")//Mail Send
- $user->sendMail($raw[5],$raw[6],$raw[7]);
- if ($cmd == "l#mdp"){//Mail Delete from Player
- mysql_query("DELETE FROM ps_mail WHERE from = '".$raw[5]."' AND to='".$user->getId()."'");
- $user->sendPacket("%xt%mdp%" . $user->room . "%" . $raw[5] . "%");
- }
- if ($cmd == "l#mc") {
- mysql_query("UPDATE ps_mail SET read = 1 WHERE to = ".$user->getId());
- }//Mail Read
- if ($cmd == "l#md") {
- }//Mail Delete
- }
- public function handleMultiplayerPacket($packet, &$user){
- $raw = explode("%", $packet);
- $cmd = $raw[3];
- if ($cmd == "m#sm")//Send Message
- $user->speak($raw[6]);
- if ($cmd == "m#r"){//Report
- $this->writeOutput($user->getName() . " has reported " . $raw[7] . ". Reason: " . $reasons[$raw[6]], "FINEST");
- foreach($this->users as &$user){
- if($user->getRank() > 2){
- $reasons = array("Swearing", "Sexual Language", "Racial Words", "Personal Info", "Email Address", "Real Name", "Name Calling", "Bad Penguin Name");
- $user->sendPacket("%xt%xy%" . $user->room . "%" . $user->room . "%" . $reasons[$raw[6]] . "%" . $raw[5] . "%" . $raw[7] . "%");
- }
- }
- }
- }
- public function handleModeratorPacket($packet, &$user){
- if (!$this->isModerator) return;
- $raw = explode("%", $packet);
- $cmd = $raw[3];
- foreach($this->users as &$suser){
- if($suser->getID() == $raw[5]){
- if ($cmd == "o#k") $suser->kick();
- if ($cmd == "o#m") $suser->muted = true;
- }
- }
- }
- public function handleStampsPacket($packet, &$user){
- $raw = explode("%", $packet);
- $cmd = explode("#", $raw[3]); $ex = $cmd[0];$cmd = $cmd[1];
- if($ex == "st"){
- if ($cmd == "sse")
- //Send Stamp Earned
- $user->addStamp($raw[5]);
- if( $cmd == "gps"){
- //Get Players Stamps
- $stamps2 = $this->god->mysql->returnArray("SELECT stamps FROM {$this->config->userTableName} WHERE id='" .$raw[5]. "';");
- $stamps2 = $stamps2[0]["stamps"];
- $user->sendPacket("%xt%gps%$user->room%" . $raw[5] . "%" . $stamps2 . "%");
- }
- if ($cmd == "gmres"){
- //Get My Recently Earned Stamps
- $stamps = $this->god->mysql->returnArray("SELECT * FROM {$this->config->userTableName} WHERE id='" .$user->id. "';");
- mysql_query("UPDATE `{$this->config->userTableName}` SET `REStamps`=NULL WHERE `id`='".$user->id."';");
- $user->sendPacket("%xt%gmres%$user->room%" . $stamps[0]['REStamps'] . "%");
- }
- if ($cmd == "gsbcd"){
- //Get Stampbook Cover Details
- $Cover = $this->god->mysql->returnArray("SELECT stampsCover FROM {$this->config->userTableName} WHERE id='" .$raw[5]. "';");
- $user->sendPacket("%xt%gsbcd%$user->room%". $user->id .$Cover[0]["stampsCover"]);
- }
- if ($cmd == "ssbcd"){/*
- //Set Stampbook Cover Details
- $stamp = "%";
- for ($i=6;$i<=count($raw);$i++) $stamp .= $raw[$i]."%";
- $user->sendPacket("%xt%gsbcd%$user->room%$stamp%");
- mysql_query("UPDATE {$this->config->userTableName} SET stampsCover='$stamp' WHERE id='" .$user->id. "';");*/
- }
- } else if($ex == "i"){
- if ($cmd == "qpp"){
- //Query Players Pins
- global $crumbs;
- $items = $this->god->mysql->returnArray("SELECT items FROM {$this->config->userTableName} WHERE id='" .$raw[5]. "';");
- $items = explode(',',$items[0]['items']);
- $str = "";
- for($i=0;$i<count($items);$i++) if($crumbs[$items[$i]]["type"] == "FLAG") $str .= $items[$i] . "|" . strtotime("-25 days") . "|0%";
- $str = substr($str, 0, strlen($str) -1);
- $user->sendPacket("%xt%qpp%" . $user->room . "%" . $str . "%");
- }
- else if ($cmd == "qpa")
- //Query Players Awards
- $user->sendPacket("%xt%qpa%" . $user->room . "%" . $user->id . "%");
- }
- }
- public function handleCustomPacket($packet, &$user){
- $raw = explode("%", $packet);
- $cmd = $raw[3];
- if($cmd == "iCP#umo") $user->setMood($raw[5]);
- }
- public function handleBuddyPacket($packet, &$user){
- $raw = explode("%", $packet);
- $cmd = $raw[3];
- if ($cmd == "b#gb") $user->sendPacket("%xt%gb%-1%" . $user->getBuddyStr());
- if ($cmd == "b#br") $user->requestBuddy($raw[5]);
- if ($cmd == "b#ba") $user->acceptBuddy($raw[5]);
- if ($cmd == "b#rb") $user->removeBuddy($raw[5]);
- if ($cmd == "b#bf") $user->findBuddy($raw[5]);
- }
- public function handleIglooPacket($packet, &$user){
- $raw = explode("%", $packet);
- $cmd = $raw[3];
- $id = $raw[5];
- switch($cmd) {
- case "g#gm":
- $user->sendPacket("%xt%gm%".$raw[4]."%" . $raw[5] . "%" .$user->getIGLOO(). "%" . $user->getFURNITURE() . "%".$user->getFLOOR()."%");
- break;
- case "g#go":
- $user->sendPacket("%xt%go%" . $raw[4] . "%1%");
- break;
- case"g#gf":
- $furn = $user->getFURNITURE();
- $user->sendPacket("%xt%gf%" . $raw[4] . "%" . $user->getFURNITURE() ."%");
- break;
- case "g#af":
- $user->sendPacket("%xt%af%" . $raw[4] . "%" . $raw[5] ."%" .$user->getCoins(). "%");
- break;
- case "g#au":
- $user->changeIGLOO($raw[5]);
- $user->sendPacket("%xt%au%" . $raw[4] . "%" . $raw[5] ."%" .$user->getCoins(). "%");
- break;
- case "g#ag":
- $user->changeFloor($raw[5]);
- $user->sendPacket("%xt%ag%" . $raw[4] . "%" . $raw[5] ."%" .$user->getCoins(). "%");
- break;
- case"g#um":
- $user->sendPacket("%xt%um%" . $raw[4] . "%" . $raw[5] ."%");
- break;
- case "g#ur":
- $furniture1 = str_replace("%xt%s%g#ur%" . $raw[4] . "%", "" , $packet);
- $furniture2 = str_replace("%", "," , $furniture1);
- $user->setFurniture($furniture2);
- $user->sendPacket("%xt%ur%" . $raw[4] . "%");
- break;
- }
- }
- public function handleUserSettingPacket($packet, &$user) {
- $raw = explode("%", $packet); global $crumbs;
- $cmd = $raw[3];
- if ($cmd == "u#gp"){
- $playerInfo = $this->god->mysql->returnArray("SELECT * FROM {$this->config->userTableName} WHERE id='" . $raw[5] . "';");
- $playerInfo = $playerInfo[0];
- $playerInfoStr = $playerInfo['id'].'|'.$playerInfo['nickname'].'|1|'.$playerInfo['colour'].'|'.$playerInfo['curhead'].'|'.$playerInfo['curface'].'|'.$playerInfo['curneck'].'|'.$playerInfo['curbody'].'|'.$playerInfo['curhands'].'|'.$playerInfo['curfeet'].'|'.$playerInfo['curflag'].'|'.$playerInfo['curphoto'].'|'.$playerInfo['rank']*146;
- $user->sendPacket("%xt%gp%-1%" . $raw[5] . "%" . $playerInfoStr . "%");
- }
- if ($cmd == "s#upc") $user->setColour($raw[5]);
- if ($cmd == "s#uph") $user->setHead($raw[5]);
- if ($cmd == "s#upf") $user->setFace($raw[5]);
- if ($cmd == "s#upn") $user->setNeck($raw[5]);
- if ($cmd == "s#upb") $user->setBody($raw[5]);
- if ($cmd == "s#upa") $user->setHands($raw[5]);
- if ($cmd == "s#upe") $user->setFeet($raw[5]);
- if ($cmd == "s#upp") $user->setPhoto($raw[5]);
- if ($cmd == "s#upl") $user->setPin($raw[5]);
- if ($cmd == "u#sma") $user->sendRoom("%xt%sma%-1%" . $user->getID() . "%" . $raw[5] . "%");
- if ($cmd == "u#sf") $user->setFrame($raw[5]);
- if ($cmd == "u#sp") $user->setXY($raw[5], $raw[6]);
- if ($cmd == "u#sb") $user->sendRoom("%xt%sb%-1%" . $user->getID() . "%" . $raw[5] . "%" . $raw[6] . "%");
- if ($cmd == "u#se") $user->sendRoom("%xt%se%-1%" . $user->getID() . "%" . $raw[5] . "%");
- if ($cmd == "u#sa") $user->setAction($raw[5]);
- if ($cmd == "u#ss") $user->sendRoom("%xt%ss%-1%" . $user->getID() . "%" . $raw[5] . "%");
- if ($cmd == "u#sl") $user->sendRoom("%xt%sl%-1%" . $user->getID() . "%" . $raw[5] . "%");
- if ($cmd == "u#sq") $user->sendRoom("%xt%sq%-1%" . $user->getID() . "%" . $raw[5] . "%");
- if ($cmd == "u#sg") $user->sendRoom("%xt%sg%-1%" . $user->getID() . "%" . $raw[5] . "%");
- if ($cmd == "u#sj") $user->sendRoom("%xt%sj%-1%" . $user->getID() . "%" . $raw[5] . "%");
- if ($cmd == "u#h") $user->sendPacket("%xt%h%" . $raw[4] . "%");
- }
- public function handleEPFPacket($packet, &$user) {
- $raw = explode("%", $packet);
- $cmd = $raw[3];
- if ($cmd == "f#epfga") $user->sendPacket("%xt%epfga%-1%".$user->isEPF."%");
- if ($cmd == "f#epfsa") mysql_query("UPDATE {$this->config->userTableName} SET isEPF='1' WHERE id='" .$raw[5]. "';");
- if ($cmd == "f#epfsf") mysql_query("UPDATE {$this->config->userTableName} SET FieldOPStatus='" .$raw[5]. "' WHERE id='" .$user->getID(). "';");
- if ($cmd == "f#epfgr") $user->sendPacket("%xt%epfgr%-1%".$user->TotalMedals."%".$user->TotalMedalsUnused."%");
- if ($cmd == "f#epfgf") $user->sendPacket("%xt%epfgf%-1%".$user->FieldOPStatus."%");
- if ($cmd == "f#epfai") $user->sendPacket("%xt%epfai%-1%".$raw[3]."%");
- if ($cmd == "f#epfgm") $user->sendPacket("%xt%epfgm%-1%1%Still no sign of Herbert or Klutzy. I'll be meeting with the Director this week to discuss what we should do next. G has your orders.|1331229660|15%I was keeping an eye on the Migrator, in case Herbert tried to board in disguise. Saw lots of Vikings, dinosaurs, and pirates. No polar bears.|1330624860|17%Man, I can't believe we still haven't heard from Herbert! You'd think he'd be bragging about how he got away. Where IS he?|1330106460|17%Rockhopper has requested my help to upgrade his ship. For now I'll be assigning orders, but Dot is taking over the Herbert investigation.|1329415260|25%Finished another sweep of the island. No sign of Herbert. How did he just vanish into thin air? You'd think he'd be groggy from his four month nap...|1328810460|17%All reports confirm that Herbert has vanished without a trace. We believe he will lie low for the time being. G has your orders.|1328205660|18%RED ALERT! All agents respond! Focus all efforts on protecting Club Penguin citizens. This is not a drill!|1327600860|18%I'm so excited for next week's Underwater Expedition! I guarantee it's going to be a party to remember!|1326996060|16%Good luck with the party planning Rookie. Your request has been approved. All agents - be on alert to help Rookie with his preparations.|1326391260|25%I've got BIG news! I was asked to help plan this month's Expedition Party! I have lots of good ideas too. Read about it in next week's newspaper!|1325786460|16%Well done this year Agents. There were many challenges, but we faced them together. No matter what 2012 holds for us, I know we'll be ready.|1325181660|25%Attention Agents - we are aware of the situation in Herbert's hibernation cell. G has your orders.|1324576860|18%");
- }
- public function handleGamePacket($packet, &$user){
- /*$raw = explode("%", $packet);
- $cmd = $raw[3];
- $gameID = (int) $raw[4];
- if($cmd == "m")
- $user->sendRoom("%xt%zm%" . $user->room . "%{$cmd[5]}%{$cmd[6]}%{$cmd[7]}%{$cmd[8]}%{$cmd[9]}%");
- if($user->game != null){
- $game = &$user->game;
- $game->handlePacket($packet, $user);
- } else if($gameID < 1000){
- $this->writeOutput("Dojo Game Debug: " . $gameID . " " . $packet, "FINEST");
- } else {
- $this->writeOutput($user->getName() . " has just tried to send a packet to a game room that doesn't exist (" . $gameID . ")", "FINER");
- }*/
- }
- public function handleRedemptionPacket($packet, &$user){
- $raw = explode("%", $packet);
- if($raw[3] == 'rjs')$user->sendPacket("%xt%rjs%-1%%1,2,4,6,7,8,9,10,11,12,14,15,16,17%0%");
- if($raw[3] == 'rsc')$this->sendCode($packet, $user);
- }
- public function sendCode($packet, &$user) {
- global $code;
- $raw = explode("%", $packet);
- $id = $raw[5];
- if ($code[$id] == null)
- $this->sendPacket("%xt%e%-1%402%");
- else {
- $user->sendPacket("%xt%rsc%-1%CAMPAIGN%" . $code[$id]['items'] . "%%");
- $items = explode(",", $code[$id]['items']);
- foreach ($items as $add ) {
- $user->addItem($add);
- }
- }
- }
- public function writeSocket(&$user, $packet) {
- if ($this->config->DebugMode == true) $this->writeOutput("Pacote enviado: ".$packet);
- if (@stristr($packet, strlen($packet) - 1, 1) !== chr(0)) $packet .= chr(0);
- socket_write($user->sock, $packet, strlen($packet));
- }
- public function stribet($input, $left, $right) {
- $pl = stripos($input, $left) + strlen($left);
- $pr = stripos($input, $right, $pl);
- return substr($input, $pl, $pr - $pl);
- }
- public function generateRandomKey(&$user) {
- $keyset = "abcdefghijklmABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789[]{}^~!@#$%ยจ&*+-";
- $randkey = "";
- for ($i = 0; $i < 9; $i++) $randkey .= substr($keyset, rand(0, strlen($keyset) - 1), 1);
- $user->key = $randkey;
- return $randkey;
- }
- public function __destruct() {
- @socket_shutdown($this->socket);
- }
- public function shutDown($error) {
- $this->writeOutput("System error. Terminating server", "CRITICAL");
- $this->writeOutput($error, "CRITICAL");
- $this->writeOutput("Server terminated.", "CRITICAL");
- if ($this->socket != null)
- $this->writeOutput("Closing ports", "INFO");
- die();
- }
- public function writeOutput($msg, $type = "INF") {
- echo date("H\:i\:s") . " - [$type] [" . $this->name . "]> $msg\n";
- }
- public function handleCommand(&$user, $msg) {
- if (function_exists("handleCommand") && in_array(substr($msg,0,1),explode(",",$this->config->CommandPrefix))){
- handleCommand($user, $msg, $this, $this->god);
- }
- }
- public function sendPacket($packet) {
- if ($this->config->DebugMode == true) $this->writeOutput("Pacote enviado: ".$packet);
- foreach ($this->users as $user)
- $user->sendPacket($packet);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement