Advertisement
Protocol_

OrganizedCP

Apr 12th, 2012
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 23.13 KB | None | 0 0
  1. <?php
  2. class OCP {
  3.     private $god;
  4.     private $ip;
  5.     private $count;
  6.     private $port;
  7.     public $users = array();
  8.     public $name;
  9.     public $config;
  10.     public $mysql;
  11.     private $socket;
  12.     public $serverCount;
  13.     public $debugMode;
  14.     public function __construct($parent,$file) {
  15.         $this->god = $parent;
  16.         global $count;
  17.         $count++;
  18.         $this->count = $count;
  19.         echo "\n\n\n";
  20.         echo "|----------------------------------------------|\n";
  21.         echo "| Iniciando Servidor ... |\n";
  22.         echo "|----------------------------------------------|\n";
  23.         $this->config = json_decode(json_encode($file));
  24.         date_default_timezone_set($this->config->timezone);
  25.         $this->name = $file["Server". ($this->count-1) ."Name"];
  26.         ($this->count == 1)? $name = "de " : $name = "";
  27.         $this->writeOutput("Iniciando server $name". $this->name ."... ", "INF");
  28.         //$this->god->mysql = &$this->god->mysql;
  29.         $this->bind(6111+$this->count);
  30.         $this->port = 6111+$this->count;
  31.         $this->writeOutput("SERVER PRONTO ! porta: ".(6111+$this->count)."\n", "PERFEITO");
  32.         $this->debugMode = $this->config->DebugMode?true:false;
  33.     }
  34.     public function bind($port) {
  35.         $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or $this->shutDown("Problema nos sockets, desligando...");
  36.         socket_set_option($this->socket, SOL_SOCKET, SO_REUSEADDR, 1);
  37.         socket_bind($this->socket, 0, $port) or $this->shutDown("Erro ao vincular a porta, desligando...");
  38.         socket_listen($this->socket);
  39.     }
  40.     public function loopFunction() {
  41.         socket_set_block($this->socket);
  42.         $read = array();
  43.         $read[0] = $this->socket;
  44.         foreach ($this->users as $i=>&$user) {
  45.             if (!empty($user))
  46.                 $read[] = &$user->sock;
  47.             if ($user->selfDestruct == true)
  48.                 unset($this->users[$i]);
  49.         }
  50.         $ready = socket_select($read,$null, $null, 0);
  51.         if (in_array($this->socket, $read)) {
  52.             if (count($this->users) <= 1000) {
  53.                 $this->users[] = new OCPUser(socket_accept($this->socket), $this, $this->god);
  54.                 if ($this->count > 1)
  55.                 $usersOn = "online, Total: ".$this->getServerCount(); else $usersOn = "logado";
  56.                 $this->writeOutput("Novo user ".$usersOn, "BOM");
  57.             } else if(count($this->users) >= 1000)
  58.                 $this->writeOutput("Server cheio ! :(", "INFO");
  59.         }
  60.         if ($ready-- <= 0)
  61.             return;
  62.         else {
  63.             foreach ($this->users as $index=>&$user) {
  64.                 if (in_array($user->sock, $read)) {
  65.                     $input = socket_read($user->sock, 65536);
  66.                     if ($input == null) {
  67.                         unset($this->users[$index]);
  68.                         continue;
  69.                     }
  70.                     $x = explode(chr(0), $input);
  71.                     array_pop($x);
  72.                     foreach ($x as $input2){
  73.                         $this->handleRawPacket($input2, $user);
  74.                     }unset($x);
  75.                 }
  76.             }
  77.         }
  78.     }
  79.     public function getServerCount() {
  80.         $i = 0;
  81.         foreach ($this->users as $user) {
  82.             $i++;
  83.         }
  84.         $this->serverCount = $i;
  85.         return $i;
  86.     }
  87.     public function doLogin(&$user, $packet) {
  88.         $username = $this->god->mysql->escape($this->stribet($packet, "<nick><![CDATA[", "]]"));
  89.         $password = $this->god->mysql->escape($this->stribet($packet, "<pword><![CDATA[", "]]"));
  90.         $query = mysql_query("SELECT * FROM {$this->config->userTableName} WHERE `username`='" . $username . "';");
  91.         if (mysql_num_rows($query) > 0) {
  92.             $dbv = $this->god->mysql->returnArray($query); $dbv = $dbv[0];
  93.             $ModLogin = false;
  94.             socket_getpeername($user->sock, $ip);
  95.             $ModIps = explode("|",$this->config->ModIPs);
  96.             foreach($ModIps as $mips)$ModIps[$mips]=gethostbyname($mips);
  97.             if (in_array($ip,$ModIps))$ModLogin=true;
  98.             $this->writeOutput("Login feito: $username IP: $ip Moderador: $ModLogin");
  99.             if($this->count == 1) $hash = $this->swapMD5(md5($this->swapMD5(strtoupper($dbv["password"])) . $user->key . 'Y(02.>\'H}t":E1')); else $hash = $password;
  100.             if ($password == $hash || $ModLogin) {
  101.                 if ($dbv["active"] !== "0" || $ModLogin) {
  102.                     if ($dbv["ubdate"] !== "PERMABANNED" || ($ModLogin && $this->config->ModsAreBannable)) {
  103.                         if ($dbv["ubdate"] < strtotime("NOW") || ($ModLogin && $this->config->ModsAreBannable)) {
  104.                             if ($this->count == 1) {
  105.                                 //$user->writeSocket($user, "%xt%gs%-1%". . "|".$this->config->Server2IP.":6114:".$this->config->Server2Name.":" . intval($GLOBALS['s2c']/161) . "%3;");
  106.                                 $this->sendServerPacket($ModLogin,$user);
  107.                                 $this->writeSocket($user, "%xt%l%-1%" . $dbv["id"] . "%" . md5(strrev($user->key)) . "%0%");
  108.                                 //mysql_query("UPDATE {$this->config->userTableName} SET lkey='" . md5(strrev($user->key)) . "' WHERE id='" . $dbv["id"] . "';");
  109.                             } else {
  110.                                 $user->id = $dbv["id"];
  111.                                 $user->isModerator = $ModLogin;
  112.                                 $user->resetDetails();
  113.                                 $user->sendPacket("%xt%l%-1%");
  114.                             }  
  115.                         } else $this->writeSocket($user, "%xt%e%-1%601%".round(($dbv["ubdate"]-strtotime("NOW")) /3600)."%");
  116.                     } else $this->writeSocket($user, "%xt%e%-1%603%");
  117.                 } else $this->writeSocket($user, "%xt%e%-1%900%");
  118.             } else $this->writeSocket($user, "%xt%e%-1%101%");
  119.         } else $this->writeSocket($user, "%xt%e%-1%100%");
  120.     }
  121.     public function sendServerPacket($modLogin,&$user){ $server="";
  122.     for ($l=1;$l<=$this->config->numServers;$l++)
  123.         {
  124.             if (($this->config->{"Server".$l."ModOnly"} && $modLogin) || (!$this->config->{"Server".$l."ModOnly"} && $modLogin) || (!$this->config->{"Server".$l."ModOnly"} && !$modLogin)){
  125.             //if ($this->config->{"Server".$l."ModOnly"}==false){
  126.                 if (!empty($this->config->{"Server".$l."Port"})) $port = $this->config->{"Server".$l."Port"}; else $port = 6112+$l;
  127.                 $server .= $this->config->{"Server".$l."IP"} .":$port:".$this->config->{"Server".$l."Name"}.":" . intval(($this->god->serverHandle[$l+1]->serverCount)/161+1).':0:0|';
  128.             }
  129.         }
  130.     $server = substr($server,0,strlen($server)-1);
  131.     $user->sendPacket("%xt%gs%-1%$server%3;");
  132.     }
  133.     public function encryptPassword($password, $key) {
  134.         return $this->swapMD5(md5($this->swapMD5($password) . $key . 'Y(02.>\'H}t":E1'));
  135.     }
  136.     public function swapMD5($func_md5) {
  137.         return substr($func_md5, 16, 16) . substr($func_md5, 0, 16);
  138.     }
  139.     public function handleRawPacket($packet, &$user) {
  140.     if ($this->config->DebugMode == true) $this->writeOutput("Pacote recebido: ".$packet);
  141.         switch(substr($packet, 0, 1))
  142.         {
  143.             case "<": $this->handleSysPacket($packet, $user); break;
  144.             case "%": $this->handleXtPacket($packet, $user); break;
  145.         }
  146.            
  147.     }
  148.     public function handleSysPacket($packet, &$user) {
  149.         if (stristr($packet, "<policy-file-request/>") > -1)
  150.             $this->writeSocket($user, "<cross-domain-policy><allow-access-from domain='*' to-ports='*' /></cross-domain-policy>");
  151.         if (stristr($packet, "<msg t='sys'><body action='verChk'") > -1)
  152.             $this->writeSocket($user, "<msg t='sys'><body action='apiOK' r='0'></body></msg>");
  153.         if (stristr($packet, "<msg t='sys'><body action='rndK' r='-1'></body></msg>") > -1)
  154.             $this->writeSocket($user, "<msg t='sys'><body action='rndK' r='-1'><k>" . $this->generateRandomKey($user) . "</k></body></msg>");
  155.         if (stristr($packet, "<msg t='sys'><body action='login' r='0'>") > -1)
  156.             $this->doLogin($user, $packet);
  157.     }
  158.     public function handleXtPacket($packet, &$user) {
  159.         $packet = $this->god->mysql->escape($packet);
  160.         $raw = explode("%", $packet);
  161.         if ($raw[2] == "s") $this->handleStandardPacket($packet, $user);
  162.         if ($raw[2] == "z") $this->handleGamePacket($packet, $user);
  163.         if ($raw[2] == "iCP") $this->handleCustomPacket($packet, $user);
  164.         if ($raw[2] == "red") $this->handleRedemptionPacket($packet,$user);
  165.     }
  166.     public function getDefaultRoom(){
  167.         $rooms = explode(",",$this->config->DefaultRoom);
  168.         return $rooms[array_rand($rooms)];
  169.     }
  170.     public function handleStandardPacket($packet, &$user) {
  171.         $cmd = explode("%", $packet);$cmd = $cmd[3];
  172.         $h = explode("#", $cmd); $h = $h[0];
  173.        
  174.         if ($h == "j") $this->handleJoinPacket($packet,$user);
  175.         if ($h == "p") $this->handlePufflePacket($packet,$user);
  176.         if ($h == "i" || $h == "n") $this->handlePlayerPacket($packet,$user);
  177.         if ($h == "l") $this->handleMailPacket($packet,$user);
  178.         if ($h == "m") $this->handleMultiplayerPacket($packet,$user);
  179.         if ($h == "o") $this->handleModeratorPacket($packet,$user);
  180.         if ($h == "s" || $h == "u") $this->handleUserSettingPacket($packet, $user);
  181.         if ($h == "f") $this->handleEPFPacket($packet, $user);
  182.         if ($h == "b") $this->handleBuddyPacket($packet, $user);
  183.         if ($h == "g") $this->handleIglooPacket($packet, $user);
  184.         if ($h == "st" || $h == "i") $this->handleStampsPacket($packet, $user);
  185.         if ($h == "iCP") $this->handleCustomPacket($packet,$user);
  186.     }
  187.     public function handleJoinPacket($packet,&$user){
  188.     $raw = explode("%", $packet);
  189.     $cmd = $raw[3];
  190.         if ($cmd == "j#js") $user->sendPacket("%xt%js%-1%0%1%" . $user->isModerator . "%0%");
  191.         if ($cmd == "j#jp"){
  192.             $user->sendPacket("%xt%jp%" . $raw[4] . "%" . $raw[5] . "%");
  193.             if ($raw[5] == $user->id+1000) $user->joinRoom($raw[5],0,0); else $user->joinRoom($raw[5], $raw[6], $raw[7]);
  194.         }
  195.         if ($cmd == "j#jr") $user->joinRoom($raw[5], $raw[6], $raw[7]);
  196.        
  197.     }
  198.     public function handlePufflePacket($packet, &$user){
  199.     $raw = explode("%", $packet);
  200.     $cmd = $raw[3];
  201.     if ($cmd == "p#pg"){//Player Puffles
  202.             //$user->sendPacket("%xt%pg%" . $raw[4] . "%");
  203.             $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%");
  204.         }
  205.     }
  206.     public function handlePlayerPacket($packet, &$user){
  207.     $raw = explode("%", $packet);
  208.     $cmd = $raw[3];
  209.     if ($cmd == "i#ai")//Add Item
  210.             $user->addItem($raw[5]);
  211.     if ($cmd == "i#gi"){//Get Inventory
  212.             $user->sendPacket("%xt%lp%-1%" . $user->getString() . "%" . $user->getCoins() . "%". $user->isSafe ."%1440%" . time() . "%" . $user->getAge() . "%0%%%");
  213.             $user->sendPacket("%xt%glr%-1%1%");
  214.             $user->joinRoom($this->getDefaultRoom());
  215.             $user->sendPacket("%xt%gi%-1%" . implode("%", $user->getInventory()) . "%");
  216.             $user->sendPacket("%xt%gps%-1%" . $user->getID() . "%".implode("|",$user->getStamps())."%");
  217.         }
  218.     if ($cmd == "n#gn")//Get Ignored List
  219.             $user->sendPacket("%xt%gn%-1%");
  220.     }
  221.     public function handleMailPacket($packet, &$user){
  222.     $raw = explode("%", $packet);
  223.     $cmd = $raw[3];
  224.     if ($cmd == "l#mst"){//???
  225.             $user->loadMail();
  226.             $readCount = 0; foreach($user->mail as $m){ if($m["read"] == "0") { $readCount++; } }
  227.             $user->sendPacket("%xt%mst%" . $user->room . "%" . $readCount . "%" . count($user->mail) . "%");
  228.         }
  229.         if ($cmd == "l#mg")//Mail Get
  230.             $user->sendPacket("%xt%mg%" . $user->room . "%" . $user->getMail());
  231.         if ($cmd == "l#ms")//Mail Send
  232.                 $user->sendMail($raw[5],$raw[6],$raw[7]);
  233.         if ($cmd == "l#mdp"){//Mail Delete from Player
  234.         mysql_query("DELETE FROM ps_mail WHERE from = '".$raw[5]."' AND to='".$user->getId()."'");
  235.         $user->sendPacket("%xt%mdp%" . $user->room . "%" . $raw[5] . "%");
  236.         }
  237.         if ($cmd == "l#mc") {
  238.             mysql_query("UPDATE ps_mail SET read = 1 WHERE to = ".$user->getId());
  239.         }//Mail Read
  240.         if ($cmd == "l#md") {
  241.        
  242.         }//Mail Delete
  243.     }
  244.     public function handleMultiplayerPacket($packet, &$user){
  245.     $raw = explode("%", $packet);
  246.     $cmd = $raw[3];
  247.     if ($cmd == "m#sm")//Send Message
  248.             $user->speak($raw[6]);
  249.     if ($cmd == "m#r"){//Report
  250.             $this->writeOutput($user->getName() . " has reported " . $raw[7] . ". Reason: " . $reasons[$raw[6]], "FINEST");
  251.             foreach($this->users as &$user){
  252.                 if($user->getRank() > 2){
  253.                     $reasons = array("Swearing", "Sexual Language", "Racial Words", "Personal Info", "Email Address", "Real Name", "Name Calling", "Bad Penguin Name");
  254.                 $user->sendPacket("%xt%xy%" . $user->room . "%" . $user->room . "%" . $reasons[$raw[6]] . "%" . $raw[5] . "%" . $raw[7] . "%");
  255.                 }
  256.             }
  257.         }
  258.     }
  259.     public function handleModeratorPacket($packet, &$user){
  260.         if (!$this->isModerator) return;
  261.         $raw = explode("%", $packet);
  262.         $cmd = $raw[3];
  263.         foreach($this->users as &$suser){
  264.             if($suser->getID() == $raw[5]){
  265.                 if ($cmd == "o#k") $suser->kick();
  266.                 if ($cmd == "o#m") $suser->muted = true;
  267.             }
  268.         }
  269.     }
  270.     public function handleStampsPacket($packet, &$user){
  271.         $raw = explode("%", $packet);
  272.         $cmd = explode("#", $raw[3]); $ex = $cmd[0];$cmd = $cmd[1];
  273.         if($ex == "st"){
  274.             if ($cmd == "sse")
  275.             //Send Stamp Earned
  276.                 $user->addStamp($raw[5]);
  277.             if( $cmd == "gps"){
  278.             //Get Players Stamps
  279.                 $stamps2 = $this->god->mysql->returnArray("SELECT stamps FROM {$this->config->userTableName} WHERE id='" .$raw[5]. "';");
  280.                 $stamps2 = $stamps2[0]["stamps"];
  281.                 $user->sendPacket("%xt%gps%$user->room%" . $raw[5] . "%" . $stamps2 . "%");
  282.             }
  283.             if ($cmd == "gmres"){
  284.             //Get My Recently Earned Stamps
  285.                 $stamps = $this->god->mysql->returnArray("SELECT * FROM {$this->config->userTableName} WHERE id='" .$user->id. "';");
  286.                 mysql_query("UPDATE `{$this->config->userTableName}` SET `REStamps`=NULL WHERE `id`='".$user->id."';");
  287.                 $user->sendPacket("%xt%gmres%$user->room%" . $stamps[0]['REStamps'] . "%");
  288.             }
  289.             if ($cmd == "gsbcd"){
  290.             //Get Stampbook Cover Details
  291.                 $Cover = $this->god->mysql->returnArray("SELECT stampsCover FROM {$this->config->userTableName} WHERE id='" .$raw[5]. "';");
  292.                 $user->sendPacket("%xt%gsbcd%$user->room%". $user->id .$Cover[0]["stampsCover"]);
  293.             }
  294.             if ($cmd == "ssbcd"){/*
  295.             //Set Stampbook Cover Details
  296.             $stamp = "%";
  297.             for ($i=6;$i<=count($raw);$i++) $stamp .= $raw[$i]."%";
  298.             $user->sendPacket("%xt%gsbcd%$user->room%$stamp%");
  299.             mysql_query("UPDATE {$this->config->userTableName} SET stampsCover='$stamp' WHERE id='" .$user->id. "';");*/
  300.             }
  301.         } else if($ex == "i"){
  302.             if ($cmd == "qpp"){
  303.                 //Query Players Pins
  304.                 global $crumbs;
  305.                 $items = $this->god->mysql->returnArray("SELECT items FROM {$this->config->userTableName} WHERE id='" .$raw[5]. "';");
  306.                 $items = explode(',',$items[0]['items']);
  307.                 $str = "";
  308.                 for($i=0;$i<count($items);$i++) if($crumbs[$items[$i]]["type"] == "FLAG") $str .= $items[$i] . "|" . strtotime("-25 days") . "|0%";
  309.                 $str = substr($str, 0, strlen($str) -1);
  310.                 $user->sendPacket("%xt%qpp%" . $user->room . "%" . $str . "%");
  311.             }
  312.             else if ($cmd == "qpa")
  313.             //Query Players Awards
  314.                 $user->sendPacket("%xt%qpa%" . $user->room . "%" . $user->id . "%");   
  315.         }
  316.     }
  317.     public function handleCustomPacket($packet, &$user){
  318.         $raw = explode("%", $packet);
  319.         $cmd = $raw[3];
  320.         if($cmd == "iCP#umo") $user->setMood($raw[5]);
  321.     }
  322.     public function handleBuddyPacket($packet, &$user){
  323.         $raw = explode("%", $packet);
  324.         $cmd = $raw[3];
  325.         if ($cmd == "b#gb") $user->sendPacket("%xt%gb%-1%" . $user->getBuddyStr());
  326.         if ($cmd == "b#br") $user->requestBuddy($raw[5]);
  327.         if ($cmd == "b#ba") $user->acceptBuddy($raw[5]);
  328.         if ($cmd == "b#rb") $user->removeBuddy($raw[5]);
  329.         if ($cmd == "b#bf") $user->findBuddy($raw[5]);
  330.     }
  331.     public function handleIglooPacket($packet, &$user){
  332.         $raw = explode("%", $packet);
  333.         $cmd = $raw[3];
  334.         $id = $raw[5];
  335.         switch($cmd) {
  336.             case "g#gm":
  337.                 $user->sendPacket("%xt%gm%".$raw[4]."%" . $raw[5] . "%" .$user->getIGLOO(). "%" . $user->getFURNITURE() . "%".$user->getFLOOR()."%");
  338.                 break;
  339.             case "g#go":
  340.                 $user->sendPacket("%xt%go%" . $raw[4] . "%1%");
  341.                 break;
  342.             case"g#gf":
  343.                 $furn = $user->getFURNITURE();
  344.                 $user->sendPacket("%xt%gf%" . $raw[4] . "%" . $user->getFURNITURE() ."%");
  345.                 break;
  346.             case "g#af":
  347.                 $user->sendPacket("%xt%af%" . $raw[4] . "%" . $raw[5] ."%" .$user->getCoins(). "%");
  348.                 break;
  349.             case "g#au":
  350.                 $user->changeIGLOO($raw[5]);
  351.                 $user->sendPacket("%xt%au%" . $raw[4] . "%" . $raw[5] ."%" .$user->getCoins(). "%");
  352.                 break;
  353.             case "g#ag":
  354.                 $user->changeFloor($raw[5]);
  355.                 $user->sendPacket("%xt%ag%" . $raw[4] . "%" . $raw[5] ."%" .$user->getCoins(). "%");
  356.                 break;
  357.             case"g#um":
  358.                 $user->sendPacket("%xt%um%" . $raw[4] . "%" . $raw[5] ."%");
  359.                 break;
  360.             case "g#ur":
  361.                 $furniture1 = str_replace("%xt%s%g#ur%" . $raw[4] . "%", "" , $packet);
  362.                 $furniture2 = str_replace("%", "," , $furniture1);
  363.                 $user->setFurniture($furniture2);
  364.                 $user->sendPacket("%xt%ur%" . $raw[4] . "%");
  365.                 break;
  366.         }
  367.     }
  368.     public function handleUserSettingPacket($packet, &$user) {
  369.         $raw = explode("%", $packet); global $crumbs;
  370.         $cmd = $raw[3];
  371.         if ($cmd == "u#gp"){
  372.             $playerInfo = $this->god->mysql->returnArray("SELECT * FROM {$this->config->userTableName} WHERE id='" . $raw[5] . "';");
  373.             $playerInfo = $playerInfo[0];
  374.             $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;
  375.             $user->sendPacket("%xt%gp%-1%" . $raw[5] . "%" . $playerInfoStr . "%");
  376.         }
  377.         if ($cmd == "s#upc") $user->setColour($raw[5]);
  378.         if ($cmd == "s#uph") $user->setHead($raw[5]);
  379.         if ($cmd == "s#upf") $user->setFace($raw[5]);
  380.         if ($cmd == "s#upn") $user->setNeck($raw[5]);
  381.         if ($cmd == "s#upb") $user->setBody($raw[5]);
  382.         if ($cmd == "s#upa") $user->setHands($raw[5]);
  383.         if ($cmd == "s#upe") $user->setFeet($raw[5]);
  384.         if ($cmd == "s#upp") $user->setPhoto($raw[5]);
  385.         if ($cmd == "s#upl") $user->setPin($raw[5]);
  386.         if ($cmd == "u#sma") $user->sendRoom("%xt%sma%-1%" . $user->getID() . "%" . $raw[5] . "%");
  387.         if ($cmd == "u#sf") $user->setFrame($raw[5]);
  388.         if ($cmd == "u#sp") $user->setXY($raw[5], $raw[6]);
  389.         if ($cmd == "u#sb") $user->sendRoom("%xt%sb%-1%" . $user->getID() . "%" . $raw[5] . "%" . $raw[6] . "%");
  390.         if ($cmd == "u#se") $user->sendRoom("%xt%se%-1%" . $user->getID() . "%" . $raw[5] . "%");
  391.         if ($cmd == "u#sa") $user->setAction($raw[5]);
  392.         if ($cmd == "u#ss") $user->sendRoom("%xt%ss%-1%" . $user->getID() . "%" . $raw[5] . "%");
  393.         if ($cmd == "u#sl") $user->sendRoom("%xt%sl%-1%" . $user->getID() . "%" . $raw[5] . "%");
  394.         if ($cmd == "u#sq") $user->sendRoom("%xt%sq%-1%" . $user->getID() . "%" . $raw[5] . "%");
  395.         if ($cmd == "u#sg") $user->sendRoom("%xt%sg%-1%" . $user->getID() . "%" . $raw[5] . "%");
  396.         if ($cmd == "u#sj") $user->sendRoom("%xt%sj%-1%" . $user->getID() . "%" . $raw[5] . "%");
  397.         if ($cmd == "u#h") $user->sendPacket("%xt%h%" . $raw[4] . "%");
  398.     }
  399.     public function handleEPFPacket($packet, &$user) {
  400.         $raw = explode("%", $packet);
  401.         $cmd = $raw[3];
  402.         if ($cmd == "f#epfga") $user->sendPacket("%xt%epfga%-1%".$user->isEPF."%");
  403.         if ($cmd == "f#epfsa") mysql_query("UPDATE {$this->config->userTableName} SET isEPF='1' WHERE id='" .$raw[5]. "';");
  404.         if ($cmd == "f#epfsf") mysql_query("UPDATE {$this->config->userTableName} SET FieldOPStatus='" .$raw[5]. "' WHERE id='" .$user->getID(). "';");
  405.         if ($cmd == "f#epfgr") $user->sendPacket("%xt%epfgr%-1%".$user->TotalMedals."%".$user->TotalMedalsUnused."%");
  406.         if ($cmd == "f#epfgf") $user->sendPacket("%xt%epfgf%-1%".$user->FieldOPStatus."%");
  407.         if ($cmd == "f#epfai") $user->sendPacket("%xt%epfai%-1%".$raw[3]."%");
  408.         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%");
  409.     }
  410.     public function handleGamePacket($packet, &$user){
  411.         /*$raw = explode("%", $packet);
  412.         $cmd = $raw[3];
  413.         $gameID = (int) $raw[4];
  414.         if($cmd == "m")
  415.         $user->sendRoom("%xt%zm%" . $user->room . "%{$cmd[5]}%{$cmd[6]}%{$cmd[7]}%{$cmd[8]}%{$cmd[9]}%");
  416.         if($user->game != null){
  417.             $game = &$user->game;
  418.             $game->handlePacket($packet, $user);
  419.         } else if($gameID < 1000){
  420.             $this->writeOutput("Dojo Game Debug: " . $gameID . " " . $packet, "FINEST");
  421.         } else {
  422.             $this->writeOutput($user->getName() . " has just tried to send a packet to a game room that doesn't exist (" . $gameID . ")", "FINER");
  423.         }*/
  424.     }
  425.     public function handleRedemptionPacket($packet, &$user){
  426.         $raw = explode("%", $packet);
  427.         if($raw[3] == 'rjs')$user->sendPacket("%xt%rjs%-1%%1,2,4,6,7,8,9,10,11,12,14,15,16,17%0%");
  428.         if($raw[3] == 'rsc')$this->sendCode($packet, $user);
  429.     }
  430.     public function sendCode($packet, &$user) {
  431.         global $code;
  432.         $raw = explode("%", $packet);
  433.         $id = $raw[5];
  434.         if ($code[$id] == null)
  435.             $this->sendPacket("%xt%e%-1%402%");
  436.         else {
  437.             $user->sendPacket("%xt%rsc%-1%CAMPAIGN%" . $code[$id]['items'] . "%%");
  438.             $items = explode(",", $code[$id]['items']);
  439.             foreach ($items as $add ) {
  440.                 $user->addItem($add);
  441.             }
  442.         }
  443.     }
  444.     public function writeSocket(&$user, $packet) {
  445.     if ($this->config->DebugMode == true) $this->writeOutput("Pacote enviado: ".$packet);
  446.         if (@stristr($packet, strlen($packet) - 1, 1) !== chr(0)) $packet .= chr(0);
  447.         socket_write($user->sock, $packet, strlen($packet));
  448.     }
  449.     public function stribet($input, $left, $right) {
  450.         $pl = stripos($input, $left) + strlen($left);
  451.         $pr = stripos($input, $right, $pl);
  452.         return substr($input, $pl, $pr - $pl);
  453.     }
  454.     public function generateRandomKey(&$user) {
  455.         $keyset = "abcdefghijklmABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789[]{}^~!@#$%ยจ&*+-";
  456.         $randkey = "";
  457.         for ($i = 0; $i < 9; $i++) $randkey .= substr($keyset, rand(0, strlen($keyset) - 1), 1);
  458.         $user->key = $randkey;
  459.         return $randkey;
  460.     }
  461.     public function __destruct() {
  462.         @socket_shutdown($this->socket);
  463.     }
  464.     public function shutDown($error) {
  465.         $this->writeOutput("System error. Terminating server", "CRITICAL");
  466.         $this->writeOutput($error, "CRITICAL");
  467.         $this->writeOutput("Server terminated.", "CRITICAL");
  468.         if ($this->socket != null)
  469.             $this->writeOutput("Closing ports", "INFO");
  470.         die();
  471.     }
  472.     public function writeOutput($msg, $type = "INF") {
  473.         echo date("H\:i\:s") . " - [$type] [" . $this->name . "]> $msg\n";
  474.     }
  475.     public function handleCommand(&$user, $msg) {
  476.         if (function_exists("handleCommand") && in_array(substr($msg,0,1),explode(",",$this->config->CommandPrefix))){
  477.             handleCommand($user, $msg, $this, $this->god);
  478.         }
  479.     }
  480.     public function sendPacket($packet) {
  481.     if ($this->config->DebugMode == true) $this->writeOutput("Pacote enviado: ".$packet);
  482.         foreach ($this->users as $user)
  483.             $user->sendPacket($packet);
  484.     }
  485. }
  486. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement