Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- ===============================================================
- * Orginal RealCP Source *
- * Created by Myles nobody else. *
- * 20+ Hours of code, 0 exploits. *
- ===============================================================
- */
- ini_set('mysql.connect_timeout', 5);
- error_reporting(E_ALL);
- ini_set('display_errors', '1');
- set_time_limit(0);
- date_default_timezone_set('America/Los_Angeles');
- include "plugins.php";
- include "crumbs.php";
- $ipbans = array("92.19.100.64","125.239.10.105","71.187.163.210","88.115.213.41","92.235.154.40","98.178.129.141","142.177.159.221","142.68.175.60");
- $init = false;
- $count = 0;
- function contain($str, array $arr)
- {
- foreach($arr as $a) {
- if (stripos($str,$a) !== false) return true;
- }
- return false;
- }
- function rank($rank){
- //Calculates how many stripes
- // x * 146
- $level = 0;
- switch($rank){
- case 1: //Normal
- $level = 1;
- break;
- case 2: //Guard
- $level = 2;
- break;
- case 3: //Mediator
- $level = 2;
- break;
- case 4: //Moderator
- $level = 3;
- break;
- case 5: //Admin
- $level = 4;
- break;
- case 6: //Super Admin
- $level = 4;
- break;
- case 7: //Owner
- $level = 6;
- break;
- case 8: //Main Owner
- $level = 6;
- break;
- }
- return $level * 146;
- }
- class OpenCP {
- public $ip;
- public $count;
- public $port;
- public $users = array();
- public $mode;
- public $config;
- public $mysql;
- public $bot;
- public $bots;
- public $party = false;
- public $socket;
- public $plugins;
- public $color;
- public $mapigloos;
- public $time = 99;
- public $up = 99;
- public function __construct($config = "config.xml") {
- global $init, $count;
- $count++;
- $this->count = $count;
- if ($init == false)
- $this->createHeader();
- else
- $this->writeOutput("Starting next server...", "INFO");
- $init = true;
- sleep(1);
- $this->readConfig($config);
- }
- public function readConfig($file) {
- echo "\n\n\n";
- echo "|----------------------------------------------|\n";
- echo "| Reading Configuration Files |\n";
- echo "|----------------------------------------------|\n";
- if (!file_exists($file))
- $this->shutDown("Could not find $file. Does it exist?");
- $this->config = simplexml_load_file($file) or $this->shutDown("$file has errors!");
- $this->writeOutput("Running as " . $this->config->type . " server", "INFO");
- $this->writeOutput("Successfully read config files");
- $type = $this->config->type;
- $this->plugins = new PluginManager($this,$type);
- }
- public function init() {
- $this->mysql = new mysql();
- $err = false;
- $this->writeOutput("Connecting to MySQL database...", "INFO");
- $this->mysql->connect($this->config->mysql->host, $this->config->mysql->username, $this->config->mysql->password) or $err = true;
- if ($err == true)
- $this->shutDown("Could not connect to mysql. Reason: " . $this->mysql->getError());
- $this->mysql->selectDB($this->config->mysql->dbname);
- if ($err == true)
- $this->shutDown("Could not select the database. Reason: " . $this->mysql->getError());
- $this->bind((integer)$this->config->port, (string)$this->config->ip);
- $this->writeOutput("We recommend using a while loop here to accept connections", "FINEST");
- }
- public function bind($port, $ip = "0") {
- $this->socket = socket_create(AF_INET, SOCK_STREAM, 0) or $this->shutDown("Could not create socket. Please check php.ini to see if sockets are enabled!");
- socket_bind($this->socket, $ip, $port) or $this->shutDown("Could not bind to port. Make sure the port is over 1024 if you are using linux");
- socket_listen($this->socket);
- }
- public function loopFunction() {
- global $network;
- socket_set_block($this->socket);
- $read = array();
- $read[0] = $this->socket;
- foreach ($this->users as $i=>&$user) {
- if (!empty($user))
- if(is_object($user)){
- $read[] = &$user->sock;
- }else
- {
- $read[] = &$user;
- }
- if(is_object($user)){
- if ($user->selfDestruct == true)
- unset($this->users[$i]);
- }
- }
- usleep(0);
- if($this->config->type == "game"){
- $min = date("i");
- if(is_int($min / 2) && $this->up != $min){
- $result = $this->mysql->query("UPDATE servers SET users='".count($this->users)."' WHERE ip='".$network."realcp.info:".$this->config->port."'");
- $this->up = $min;
- }
- if($min == 10 || $min == 30 || $min == 50 || $min == 0){
- if($this->time != $min){
- $num = rand(1,5);
- if($num == 1){
- $welcome = "Donating Gets You Exclusive Commands Consider it, Email donate@realcp.info";
- $this->sendPacket("%xt%pmsg%-1%Info%0%".$welcome."%");
- }
- if($num == 2){
- $welcome = "Manage Your User realcp.info/panel!";
- $this->sendPacket("%xt%pmsg%-1%Info%0%".$welcome."%");
- }
- if($num == 3){
- $welcome = "Made a Video? email video@realcp.info with the link!";
- $this->sendPacket("%xt%pmsg%-1%Info%0%".$welcome."%");
- }
- if($num == 4){
- $welcome = "Want a Custom Glow? Donate! Email donate@realcp.info";
- $this->sendPacket("%xt%pmsg%-1%Info%0%".$welcome."%");
- }
- if($num == 5){
- $welcome = "Donate4More! Email donate@realcp.info";
- $this->sendPacket("%xt%pmsg%-1%Info%0%".$welcome."%");
- }
- $this->time = $min;
- }
- }
- }
- $w = null;
- $e = null;
- $t = 0;
- $ready = socket_select($read, $w, $e, $t);
- if (in_array($this->socket, $read)) {
- if (count($this->users) <= 100) {
- $this->users[] = new CPUser(socket_accept($this->socket), $this);
- $this->writeOutput("New Client Connected", "FINE");
- }
- if (count($this->users) >= 100)
- $this->writeOutput("Server is full", "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);
- }
- }
- }
- }
- if(is_array($this->bots)){
- foreach($this->bots as $bot){
- $bot->heartBeat();
- }
- }
- usleep(0);
- }
- public function doLogin(&$user, $packet) {
- global $ipbans;
- if(is_object($user)){
- socket_getpeername($user->sock, $ip);
- }else
- {
- socket_getpeername($user, $ip);
- }
- if(in_array($ip,$ipbans)){
- $user->sendPacket($user->sock, "%xt%er%You are <b>IP Banned</b> from RealCP please contact IP@realcp.info %Okay%0%");
- return;
- }
- $username = $this->mysql->escape($this->stribet($packet, "<nick><![CDATA[", "]]"));
- $password = $this->stribet($packet, "<pword><![CDATA[", "]]");
- if($username != "" || $password != "" || $password != "e9800998ecf8427ed41d8cd98f00b204"){
- if ($this->mysql->getRows("SELECT username FROM {$this->config->mysql->userTableName} WHERE username='" . $username . "';") > 0) {
- $dbv = $this->mysql->returnArray("SELECT username, password, lkey, rank, ismoderator, nickname, id, active, ubdate FROM {$this->config->mysql->userTableName} WHERE username='" . $this->mysql->escape($username) . "';");
- if($this->config->type == "login"){
- $hash = strtoupper($dbv[0]["password"]);
- $hash = $this->encryptPassword($hash, $user->key);
- } else {
- if($user->key == ""){
- echo "[Warning]: HACKER! \n";
- $user->sendPacket("%xt%l%-1%");
- $user->sendPacket("%xt%e%-1%603%");
- return;
- }
- $hash = $this->swapMD5(md5($dbv[0]["lkey"] . $user->key)) . $dbv[0]["lkey"];
- }
- if ($password == $hash) {
- if ($dbv[0]["active"] != "0") {
- if ($dbv[0]["ubdate"] != "PERMABANNED") {
- if ($dbv[0]["ubdate"] < strtotime("NOW MDT")) {
- if ($this->config->type == "login") {
- // This is A Plugin Handler, Do Not Remove or Your Plugins May Die.
- //Block Multiple Same Users :')
- $return = $this->plugins->handle("Servers",$username,$password,$user,$packet,$dbv);
- if($return['return'] == true){
- $this->writeSocket($user, "%xt%gs%-1%".$return['servers']."%");
- }else
- {
- $this->writeSocket($user, "%xt%gs%-1%127.0.0.1:6113:Safari World:2|127.0.0.1:6114:Snowy Forts:2%");
- }
- $this->writeSocket($user, "%xt%l%-1%" . $dbv[0]["id"] . "%" . md5(strrev($user->key)) . "%0%");
- $this->mysql->query("UPDATE {$this->config->mysql->userTableName} SET lkey='" . md5(strrev($user->key)) . "' WHERE id='" . $dbv[0]["id"] . "';");
- } else {
- foreach ($this->users as $i=>&$u) {
- if (isset($u->username)) {
- if ($u->username == $username) {
- unset($this->users[$i]);
- return;
- }
- }
- }
- $user->id = $dbv[0]["id"];
- $this->mysql->query("UPDATE {$this->config->mysql->userTableName} SET ips='" . $this->mysql->escape($ip) . "' WHERE id='" . $user->getID() . "';");
- $user->resetDetails();
- $user->sendPacket("%xt%l%-1%");
- }
- } else
- $this->writeSocket($user, "%xt%e%-1%601%24%");
- } 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%");
- }else
- {
- echo "[Warning]: HACKER! \n";
- $this->writeSocket($user, "%xt%e%-1%603%");
- }
- }
- 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 (substr($packet, 0, 1) == "<"){
- $this->handleSysPacket($packet, $user);
- }
- else{
- if(is_object($user)){
- if (substr($packet, 0, 1) == "%" & $user->loggedin == true){
- $this->handleXtPacket($packet, $user);
- }
- }else
- {
- socket_getpeername($user, $ip);
- socket_close($user);
- unset($user);
- file_put_contents("bad.txt", $ip." ".$packet."\n", FILE_APPEND);
- }
- }
- }
- public function handleAdminPacket($packet, &$user) {
- //Packets are xml :-D
- echo "Admin Packet: ".$packet."\n";
- $mypacket = new SimpleXMLElement($packet);
- $username = $mypacket->attributes()->username;
- $password = $mypacket->attributes()->password;
- if($username != "Admin" && $password != "consolemin2934"){
- $this->writeSocket($user, "<admin><result msg=\"Failed Login\"/></admin>");
- socket_close($user);
- unset($user);
- return;
- }
- $action = $mypacket->action->attributes()->a;
- switch($action){
- case "find":
- foreach($mypacket->action->find as $find){
- foreach ($this->users as $i=>&$u) {
- if (is_object($u)) {
- if($u->username == $find->attributes()->name){
- $this->writeSocket($user, "<admin><result msg=\"Found User\" room=\"".$u->room."\"/></admin>");
- }
- }
- }
- }
- break;
- case "getall":
- $str = "";
- foreach ($this->users as $i=>&$u) {
- if (is_object($u)) {
- $str .= "<user name=\"".$u->username."\" id=\"".$u->id."\" room=\"".$u->room."\" />";
- }
- }
- $this->writeSocket($user, "<admin><result msg=\"Collected Users\" />".$str."</admin>");
- break;
- case "eval":
- foreach($mypacket->action->cmd as $cmd){
- eval($cmd->attributes()->code);
- }
- break;
- case "msg":
- foreach($mypacket->action->msg as $msg){
- echo "Global Message\n";
- $this->sendPacket("%xt%er%".$msg->attributes()->m."%Ok%1%");
- $this->writeSocket($user, "<admin><result msg=\"Global'd Message\" /></admin>");
- }
- break;
- case "packet":
- foreach($mypacket->action->packet as $msg){
- echo "Global Message\n";
- $this->sendPacket($msg->attributes()->p);
- $this->writeSocket($user, "<admin><result msg=\"Sent Packet\" /></admin>");
- }
- break;
- case "ban":
- //By ID or By Name.
- foreach($mypacket->action->user as $banu){
- //Figure if they have a Name or id
- if(isset($banu->attributes()->id)){
- foreach ($this->users as $i=>&$u) {
- if ($u->id == $banu->attributes()->id){
- $u->sendPacket("%xt%er%Banned by ".$banu->attributes()->username."%Ok%0%");
- $u->ban();
- unset($this->openCP->users[$i]);
- }
- }
- $this->writeSocket($user, "<admin><result msg=\"Banned By ID\" /></admin>");
- }else
- {
- if(isset($banu->attributes()->name)){
- foreach ($this->users as $i=>&$u) {
- if ($u->username == $banu->attributes()->name)
- $u->sendPacket("%xt%er%Banned by ".$banu->attributes()->username."%Ok%0%");
- $u->ban();
- unset($this->openCP->users[$i]);
- }
- $this->writeSocket($user, "<admin><result msg=\"Banned By Name\" /></admin>");
- }
- echo "Ban Console \n";
- }
- }
- break;
- case "kick":
- //By ID or By Name.
- foreach($mypacket->action->user as $kicku){
- //Figure if they have a Name or id
- if(isset($kicku->attributes()->id)){
- foreach ($this->users as $i=>&$u) {
- if ($u->id == $kicku->attributes()->id)
- $u->kick();
- }
- $this->writeSocket($user, "<admin><result msg=\"Kicked By ID\" /></admin>");
- }else
- {
- if(isset($kicku->attributes()->name)){
- foreach ($this->users as $i=>&$u) {
- if ($u->username == $kicku->attributes()->name)
- $u->kick();
- }
- $this->writeSocket($user, "<admin><result msg=\"Kicked By Name\" /></admin>");
- }
- echo "Kick Console \n";
- }
- }
- break;
- }
- $this->writeSocket($user, "<admin><result msg=\"Done\"/></admin>");
- socket_close($user);
- unset($user);
- //Close After done ;D
- }
- 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){
- $user->key = $this->generateRandomKey();
- $this->writeSocket($user, "<msg t='sys'><body action='rndK' r='-1'><k>" . $user->key . "</k></body></msg>");
- }
- if (stristr($packet, "<admin") > -1){
- $this->handleAdminPacket($packet,$user);
- }
- if (stristr($packet, "<msg t='sys'><body action='login' r='0'>") > -1)
- $this->doLogin($user, $packet);
- }
- public function handleXtPacket($packet, &$user) {
- $raw = explode("%", $packet);
- $handler = $raw[2];
- if ($handler == "s")
- $this->handleStandardPacket($packet, $user);
- if ($handler == "z")
- $this->handleGamePacket($packet, $user);
- if($handler == "red")
- $this->handleRedemptionPacket($packet,$user);
- }
- 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) {
- $code = array();
- $code["COLOUR123"] = array("items"=>"1,2,3,4,5,6,7,8", "coins"=> "100");
- $code["BETAHATTROLL"] = array("items"=>"413", "coins"=> "100");
- $code["MORETHAN9LETTES"] = array("items"=>"465", "coins"=> "100");
- $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,true);
- }
- }
- }
- public function getDefaultRoom(){
- $rooms = array("100");
- return $rooms[array_rand($rooms)];
- }
- public function handleStandardPacket($packet, &$user) {
- $raw = explode("%", $packet);
- $cmd = $raw[3];
- if ($cmd == "j#js") {
- $lkey = $raw[6];
- $res = $this->mysql->returnArray("SELECT username, ismoderator, id, password FROM {$this->config->mysql->userTableName} WHERE id='" . $user->getID() . "'");
- if (count($res) > 0)
- $user->sendPacket("%xt%js%-1%0%1%" . $res[0]["ismoderator"] . "%0%");
- $this->mysql->query("UPDATE {$this->config->mysql->userTableName} SET lkey='' WHERE id='" . $user->getID() . "';");
- }
- if ($cmd == "j#jp"){
- $user->sendPacket("%xt%jp%" . $raw[4] . "%" . $raw[5] . "%");
- $user->joinRoom($raw[5], $raw[6], $raw[7]);
- }
- if ($cmd == "s#jt"){
- //Handle JoinTable
- $id = $raw[4];
- $user->sendPacket("%xt%jt%".$user->room."%".$id."%1%");
- }
- if($cmd == "s#lg"){
- if($user->ready == true){
- $user->ready2 = true;
- $user->joinRoom($this->getDefaultRoom());
- //Set Online to Buddies
- foreach($this->users as &$suser){
- if(is_object($suser)){
- if(isset($suser->buddies[$user->id])){
- //Send Online
- $suser->sendPacket("%xt%bon%-1%".$user->id."%");
- }
- }
- }
- $return = $this->plugins->handle("joinServer",$user);
- $user->sendPacket("%xt%gi%-1%" . implode("%", $user->getInventory()) . "%");
- }
- }
- if($cmd == "s#gra"){
- echo "GETRANK\n";
- echo "PC: $packet\n";
- $res = $this->mysql->returnArray("SELECT msg, cmsg, username, rank FROM {$this->config->mysql->userTableName} WHERE id='" . $this->mysql->escape($raw[5]) . "'");
- // $type = "".$res[0]["rank"];
- if($res[0]["msg"] == "false"){
- switch($res[0]["rank"]){
- case 1:
- $type = "User";
- break;
- case 2:
- $type = "Guard";
- break;
- case 3:
- $type = "Mediator";
- break;
- case 4:
- $type = "Moderator";
- break;
- case 5:
- $type = "Admin";
- break;
- case 6:
- $type = "Super Admin";
- break;
- case 7:
- $type = "Owner";
- break;
- case 8:
- $type = "Creator";
- break;
- default:
- $type = "Error";
- }
- }else
- {
- $type = $res[0]["msg"];
- }
- echo "Sent Back ".$type;
- $user->sendPacket("%xt%gra%".$type."%");
- }
- if ($cmd == "undefined#gv"){
- if($user->ready == false){
- echo $packet."\n";
- if($raw[5] == 30051){
- $user->ready = true;
- //We Have passed stage1 :-)
- $user->sendPacket("%xt%lg%0%11%10%");
- }else
- {
- $this->writeSocket($user, "%xt%e%-1%10005%");
- file_put_contents("bad.txt",$user->username."\n",FILE_APPEND);
- $user->selfDestruct = true;
- $user->ready = false;
- unset($user);
- }
- }
- }
- if ($cmd == "p#pg"){
- $user->sendPacket("%xt%pg%" . $raw[4] . "%");
- }
- if ($cmd == "i#gi"){
- $user->sendPacket("%xt%gps%-1%" . $user->getID() . "%9|10|11|14|20|183%");
- $user->sendPacket("%xt%glr%-1%3555%");
- $user->sendPacket("%xt%lp%-1%" . implode("|", $user->getDetails()) . "%" . $user->getCoins() . "%0%1440%" . rand(1200000000000, 1500000000000) . "%" . $user->getAge() . "%4%" . 1000 . "% %7%");
- //Set Ready
- $user->sendPacket("%xt%gv%");
- //10005
- // $user->joinRoom($this->getDefaultRoom());
- //This is the first time they join a Room So We Can use this
- // $return = $this->plugins->handle("joinServer",$user);
- // $user->sendPacket("%xt%gi%-1%" . implode("%", $user->getInventory()) . "%");
- }
- if ($cmd == "g#ai")
- $user->addItem($raw[5]);
- if ($cmd == "i#ai")
- $user->addItem($raw[5]);
- if ($cmd == "n#gn")
- $user->sendPacket("%xt%gn%-1%");
- if ($cmd == "l#mst")
- $user->sendPacket("%xt%mst%-1%0%1");
- if ($cmd == "l#mg")
- $user->sendPacket("%xt%mg%-1%Safari|0|12|OpenCP|0|63%");
- if ($cmd == "t#at")
- $user->readNews(true);
- if ($cmd == "t#rt")
- $user->readNews(false);
- if ($cmd == "j#jr")
- $user->joinRoom($raw[5], $raw[6], $raw[7]);
- if ($cmd == "m#sm")
- $user->speak($raw[6]);
- if ($cmd == "o#m"){
- if($user->isModerator == true){
- foreach($this->users as &$suser){
- if($suser->getID() == $raw[5]){
- if($user->rank > $suser->rank){
- if($suser->muted == false){
- $suser->muted = true;
- $user->sendPacket("%xt%pmsg%-1%Server%0%Muted User%");
- }else
- {
- $suser->muted = false;
- $user->sendPacket("%xt%pmsg%-1%Server%0%Unmuted User%");
- }
- }else
- {
- $user->sendPacket("%xt%pmsg%-1%Server%0%Access Denied: Mute User%");
- }
- }
- }
- }
- }
- if ($cmd == "o#k"){
- if($user->isModerator == true){
- foreach($this->users as &$suser){
- if($suser->getID() == $raw[5]){
- if($user->rank > $suser->rank){
- $suser->kick();
- file_put_contents("commandlog-".date('Y-m-d').".txt","[".$user->username." - ".date("H:i:s")."] Kicked ".$suser->username."\n",FILE_APPEND);
- }
- }
- }
- }
- }
- $h = explode("#", $cmd);
- $h = $h[0];
- if ($h == "s")
- $this->handleUserSettingPacket($packet, $user);
- if ($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);
- }
- 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 getIgloo($rmid){
- $id = $rmid - 1000;
- if(!is_numeric($rmid)){
- return;
- }
- $igloo = 0;
- $result = $this->mysql->query("SELECT igloo FROM {$this->config->mysql->userTableName} WHERE id='$id';");
- while ($row = mysql_fetch_assoc($result)) {
- $igloo = $row['igloo'];
- }
- return $igloo;
- }
- public function handleIglooPacket($packet, &$user){
- $raw = explode("%", $packet);
- $cmd = $raw[3];
- $id = $raw[5];
- if($cmd == "g#gr"){
- $igloos = "";
- foreach($this->mapigloos as $key=>$ig){
- $igloos = $igloos.$key."|".$ig."%";
- }
- $user->sendPacket("%xt%gr%" . $raw[4] ."%". $igloos);
- }
- if($cmd == "g#or"){
- $this->mapigloos[$user->id] = $user->getName();
- }
- if($cmd == "g#cr"){
- unset($this->mapigloos[$user->id]);
- }
- $raw = explode("%", $packet);
- $cmd = $raw[3];
- $id = $raw[5];
- if($cmd == "g#gm") {
- //Get igloo by ID.
- $iglooInfo = $this->mysql->returnArray("SELECT igloo, floor, furniture FROM {$this->config->mysql->userTableName} WHERE id='" . $this->mysql->escape($raw[5]) . "';");
- $iglooInfo = $iglooInfo[0];
- $user->sendPacket("%xt%gm%" . $id . "%" . $raw[5] . "%" . $iglooInfo['igloo'] . "%" . $iglooInfo['furniture'] . "%" . $iglooInfo['floor'] . "%");
- } elseif($cmd == "g#go") {
- $user->sendPacket("%xt%go%" . $raw[4] . "%1%");
- } elseif($cmd == "g#gf") {
- $furn = $user->getFURNITURE();
- $user->sendPacket("%xt%gf%" . $raw[4] . "%" . $user->getFURNITURE() ."%");
- } elseif($cmd == "g#af") {
- $user->sendPacket("%xt%af%" . $raw[4] . "%" . $raw[5] ."%" . $user->getCoins() . "%");
- } elseif($cmd == "g#au") {
- $user->changeIGLOO($raw[5]);
- $user->sendPacket("%xt%au%" . $raw[4] . "%" . $raw[5] ."%" . $user->getCoins() . "%");
- } elseif($cmd == "g#ag") {
- $user->changeFloor($raw[5]);
- $user->sendPacket("%xt%ag%" . $raw[4] . "%" . $raw[5] ."%" . $user->getCoins() . "%");
- } elseif($cmd == "g#um") {
- $user->sendPacket("%xt%um%" . $raw[4] . "%" . $raw[5] ."%");
- } elseif($cmd == "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] . "%");
- }
- }
- public function handleUserSettingPacket($packet, &$user) {
- $raw = explode("%", $packet);
- $cmd = $raw[3];
- if ($cmd == "u#sp")
- $user->setXY($raw[5], $raw[6]);
- if ($cmd == "u#gp"){
- $playerInfo = $this->mysql->returnArray("SELECT id, nickname, '1', colour, curhead, curface, curneck, curbody, curhands, curfeet, curflag, curphoto, rank FROM {$this->config->mysql->userTableName} WHERE id='" . $this->mysql->escape($raw[5]) . "';");
- $playerInfo = $playerInfo[0];
- $playerInfo["rank"] = rank($playerInfo["rank"]);
- $user->sendPacket("%xt%gp%-1%" . $raw[5] . "%" . implode("|", $playerInfo) . "%");
- }
- 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#h")
- $user->sendPacket("%xt%h%" . $raw[4] . "%");
- if ($cmd == "u#sf")
- $user->setFrame($raw[5]);
- if($cmd == "u#sb"){
- $return = $this->plugins->handle("UserSnowball",$raw[5],$raw[6],$user);
- if($return['hide'] == true){
- }else
- {
- $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#sma")
- $user->sendRoom("%xt%sma%-1%" . $user->getID() . "%" . $raw[5] . "%");
- }
- public function handleEPFPacket($packet, &$user) {
- $raw = explode("%", $packet);
- $cmd = $raw[3];
- if ($cmd == "f#epfga")
- $user->sendPacket("%xt%epfga%-1%1%");
- if ($cmd == "f#epfgr")
- $user->sendPacket("%xt%epfgr%-1%0%0%");
- if ($cmd == "f#epfgf")
- $user->sendPacket("%xt%epfgf%-1%1%");
- }
- public function handleGamePacket($packet, &$user) {
- $raw = explode("%", $packet);
- $cmd = $raw[3];
- $gameID = (int) $raw[4];
- if($cmd == "gz"){
- return $user->sendPacket("%xt%gz%-1%%%0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0%");
- }
- if($cmd == "m")
- return $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 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 writeSocket(&$user, $packet) {
- if (@stristr($packet, strlen($packet) - 1, 1) != chr(0))
- $packet = $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($amount = 9) {
- return "abc12345";
- $keyset = "abcdefghijklmABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"\A3$%^&*()_+-=[]{}:@~;'#<>?|\\,./";
- $randkey = "";
- for ($i = 0; $i < $amount; $i++)
- $randkey .= substr($keyset, rand(0, strlen($keyset) - 1), 1);
- 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();
- }
- private function createHeader() {
- echo "\033[2J";
- echo "\n |----------------------------------------------|\n";
- echo " | OpenCP - The free CPPS |\n";
- echo " |----------------------------------------------|\n";
- echo " | Created by the OpenCP Team |\n";
- echo " | Copyright 2011 OpenCP Team |\n";
- echo " | Licensed under the GNU licence |\n";
- echo " |----------------------------------------------|\n";
- echo "\n";
- $this->writeOutput("License loaded - Personal Version");
- $this->writeOutput("Limit: 100 users");
- $this->writeOutput("To get a commercial license, please contact a staff member");
- echo "\n";
- }
- private function writeOutput($msg, $type = "INFO") {
- echo date("H\:i\:s") . " - [$type] [" . $this->count . "] > $msg\n";
- }
- public function handleCommand(&$user, $msg) {
- if (function_exists("handleCommand") && substr($msg, 0, 1) == "!"){
- handleCommand($user, $msg, $this);
- }
- }
- public function sendPacket($packet) {
- foreach ($this->users as $user){
- if(is_object($user)){
- $user->sendPacket($packet);
- }}
- }
- }
- /* CPBOT by Myles: This Completely Emulates a User and Can Do Anything, We can make it so Admin Panel can Control so less Server Lag!
- This Class won't be counted as a bot. :D, It is fully functional, You need to makesure bot is a registered user though!
- */
- class CPBot extends CPUser{
- public $loggedin = true;
- public $ready2 = true;
- public $ready = true;
- public $time = 0;
- public $parent;
- public function __construct($info, &$parent) {
- //Its a bot so we don't need mr Socket :D
- //Info :)
- $parent->bots[] = $this;
- $this->username = $info['username'];
- //Work out ID
- $res = $parent->mysql->returnArray("SELECT id, username FROM {$parent->config->mysql->userTableName} WHERE username='" . $this->username . "'");
- $id = $res[0]["id"];
- $this->id = $id;
- $this->sock = null;
- $this->parent = $parent;
- $this->data = array();
- $this->joinRoom($info['room']);
- }
- public function kick(){
- foreach($this->parent->users as $i=>$suser){
- if($suser == $this){
- unset($this->parent->users[$i]);
- }
- }
- foreach($this->parent->bots as $i=>$suser){
- if($suser == $this){
- unset($this->parent->bots[$i]);
- }
- }
- $this->__destruct();
- unset($this);
- }
- public function __destruct() {
- $this->sendRoom("%xt%rp%-1%" . $this->getID() . "%");
- //Show offline to buddies
- foreach($this->parent->users as &$suser){
- if(is_object($suser)){
- if(isset($suser->buddies[$this->id])){
- //Send Online
- $suser->sendPacket("%xt%bof%-1%".$this->id."%");
- }
- }
- }
- unset($this->parent->mapigloos[$this->getId()]);
- }
- public function sendPacket($packet) {
- //We Currently Don't have Anything here. :(
- //We'll just pretend there is something.
- //Actually I'll put something. We'll add simple Emulator :D
- $raw = explode("%",$packet);
- switch($raw[1]){
- case "xt":
- //Handle Packet
- $this->handlePacket($raw);
- break;
- }
- }
- public function heartBeat(){
- //Happens when server done stuff ;3
- //We need this to happen on average every 5secs.
- //We check if last time
- if($this->time != 0){
- $diff = microtime(true) - $this->time;
- if($diff > 4){
- //Nothing :D
- }else
- {
- return; //TooQuick
- }
- }
- $r = rand(1,5);
- if($r == 1){
- if($this->username == "Rockhopper"){
- $msg = array("Where is YAR?","SHIVER ME TIMBERS!","AHOY CAPTAINS!","YA WANT TO BE ME BUDDY?","RUM ANYONE?","RUM FOR ALL!","ME HAVE BEEN SAILING!","HOW WAS YE DAY?","EVERY PIRATE BE JOLLY!","SINGING SAILOR SONGS!","HAS ANYYONE SEEN ME PUFFLE?","AHOY I SEE LAND!");
- $this->speak($msg[rand(1,count($msg) - 1)]);
- $this->setXY(rand(100,1000),rand(100,1000));
- }
- //$this->setColour(rand(1,10));
- }
- //record time now.
- $this->time = microtime(true);
- }
- public function handleMSG($msg){
- if(contain(strtolower($msg),array("buddy","friend","accept","add"))){
- $this->speak("Feel Free to Add me Pirates!");
- }
- if(rand(1,10) == 1){
- $this->setXY(rand(100,1000),rand(100,1000));
- }
- }
- public function handlePacket($raw){
- switch($raw[2]){
- case "br":
- //Buddy Request.
- $id = $raw[4];
- $this->acceptBuddy($id);
- break;
- case "sm":
- $this->handleMSG($raw[5]);
- break;
- }
- }
- }
- class CPUser {
- public $selfDestruct;
- public $sock;
- public $parent;
- public $inventory;
- public $coins;
- public $username;
- public $room;
- public $lkey;
- public $colour;
- public $ready = false;
- public $id;
- public $head;
- public $face;
- public $neck;
- public $body;
- public $hands;
- public $feet;
- public $pin;
- public $photo;
- public $loggedin = true;
- public $x;
- public $mascot;
- public $y;
- public $key;
- public $rank;
- public $frame;
- public $buddies;
- public $data;
- public $nickname;
- public $buddyRequests = array();
- public $isModerator = false;
- public $ready2 = false;
- public $igloo;
- public $floor;
- public $muted = false;
- public $furniture;
- public function __construct($socket, &$parent) {
- $this->sock = $socket;
- $this->parent = $parent;
- $this->data = array();
- }
- public function __destruct() {
- $this->sendRoom("%xt%rp%-1%" . $this->getID() . "%");
- //Show offline to buddies
- foreach($this->parent->users as &$suser){
- if(is_object($suser)){
- if(isset($suser->buddies[$this->id])){
- //Send Online
- $suser->sendPacket("%xt%bof%-1%".$this->id."%");
- }
- }
- }
- unset($this->parent->mapigloos[$this->getId()]);
- }
- public function getName() {
- return $this->username;
- }
- public function getID() {
- return $this->id;
- }
- public function getHead() {
- return $this->head;
- }
- public function getFace() {
- return $this->face;
- }
- public function getNeck() {
- return $this->neck;
- }
- public function getBody() {
- return $this->body;
- }
- public function getHands() {
- return $this->hands;
- }
- public function getFeet() {
- return $this->feet;
- }
- public function getPin() {
- return $this->pin;
- }
- public function getPhoto() {
- return $this->photo;
- }
- public function getColour() {
- return $this->colour;
- }
- public function getAge() {
- return $this->age;
- }
- public function getCoins() {
- return $this->coins;
- }
- public function getX() {
- return $this->x;
- }
- public function getY() {
- return $this->y;
- }
- public function getInventory() {
- return $this->inventory;
- }
- public function getFrame() {
- return $this->frame;
- }
- public function setHead($id) {
- $id = $this->parent->mysql->escape($id);
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curhead='$id' WHERE id='" . $this->getID() . "';");
- $this->sendRoom("%xt%uph%-1%{$this->getID()}%" . $id . "%");
- $this->head = $id;
- }
- public function setFace($id) {
- $id = $this->parent->mysql->escape($id);
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curface='$id' WHERE id='" . $this->getID() . "';");
- $this->sendRoom("%xt%upf%-1%{$this->getID()}%" . $id . "%");
- $this->face = $id;
- }
- public function setNeck($id) {
- $id = $this->parent->mysql->escape($id);
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curneck='$id' WHERE id='" . $this->getID() . "';");
- $this->sendRoom("%xt%upn%-1%{$this->getID()}%" . $id . "%");
- $this->neck = $id;
- }
- public function setBody($id) {
- $id = $this->parent->mysql->escape($id);
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curbody='$id' WHERE id='" . $this->getID() . "';");
- $this->sendRoom("%xt%upb%-1%{$this->getID()}%" . $id . "%");
- $this->body = $id;
- }
- public function setHands($id) {
- $id = $this->parent->mysql->escape($id);
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curhands='$id' WHERE id='" . $this->getID() . "';");
- $this->sendRoom("%xt%upa%-1%{$this->getID()}%" . $id . "%");
- $this->hands = $id;
- }
- public function setFeet($id) {
- $id = $this->parent->mysql->escape($id);
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curfeet='$id' WHERE id='" . $this->getID() . "';");
- $this->sendRoom("%xt%upe%-1%{$this->getID()}%" . $id . "%");
- $this->feet = $id;
- }
- public function setPin($id) {
- $id = $this->parent->mysql->escape($id);
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curflag='$id' WHERE id='" . $this->getID() . "';");
- $this->sendRoom("%xt%upl%-1%{$this->getID()}%" . $id . "%");
- $this->pin = $id;
- }
- public function setPhoto($id) {
- $id = $this->parent->mysql->escape($id);
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curphoto='$id' WHERE id='" . $this->getID() . "';");
- $this->sendRoom("%xt%upp%-1%{$this->getID()}%" . $id . "%");
- $this->photo = $id;
- }
- public function setColour($id) {
- $id = $this->parent->mysql->escape($id);
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET colour='$id' WHERE id='" . $this->getID() . "';");
- $this->sendRoom("%xt%upc%-1%{$this->getID()}%" . $id . "%");
- $this->colour = $id;
- }
- public function ban() {
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET ubdate='PERMABANNED' WHERE username='" . $this->username . "';");
- }
- public function setCoins($coins) {
- $coins = $this->parent->mysql->escape($coins);
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET coins='$coins' WHERE id='" . $this->getID() . "';");
- $this->sendPacket("%xt%zo%-1%" . $coins . "%Open%CP%");
- }
- public function setXY($x, $y) {
- $this->x = $x;
- $this->y = $y;
- foreach($this->data["simpleCommands"]["bots"] as $bot){
- if($bot['follow'] == true){
- $this->sendRoom("%xt%sp%-1%" . $bot["id"] . "%".$this->x."%".$this->y."%");
- }
- }
- $this->sendRoom("%xt%sp%-1%" . $this->getID() . "%$x%$y%");
- }
- public function setFrame($frame) {
- $this->frame = $frame;
- $this->sendRoom("%xt%sf%-1%" . $this->getID() . "%" . $frame . "%");
- }
- public function setAction($action) {
- $this->frame = $action;
- $this->sendRoom("%xt%sf%-1%" . $this->getID() . "%" . $action . "%");
- }
- //Igloo Functions
- public function setFurniture($furn) {;
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET furniture='".$this->parent->mysql->escape($furn)."' WHERE id='" . $this->getID() . "';");
- $this->furniture = $furn;
- }
- public function changeIGLOO($iglooid) {
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET igloo='" . $this->parent->mysql->escape($iglooid) ."' WHERE id='" . $this->getID() . "';");
- }
- public function changeFloor($floorid) {
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET floor='" . $this->parent->mysql->escape($floorid) ."' WHERE id='" . $this->getID() . "';");
- }
- public function getIGLOO() {
- return $this->igloo;
- }
- public function getFLOOR() {
- return $this->floor;
- }
- public function getFURNITURE() {
- return $this->furniture;
- }
- public function speak($msg = "I need friends") {
- if($this->muted == false){
- $omsg = str_replace("%","",$msg);
- $msg = $this->parent->mysql->escape($msg);
- $return = $this->parent->plugins->handle("Message",$msg,$this);
- if($return['hide'] == true){
- }else
- {
- $this->sendRoom("%xt%sm%-1%" . $this->getID() . "%" . $omsg . "%");
- }
- }else
- {
- $this->sendPacket("%xt%pmsg%-1%Server%0%You Cannont Talk Because You Are Muted!%");
- }
- }
- public function readNews($bool) {
- if($bool == true){
- $this->sendRoom("%xt%at%37%".$this->getID()."%1%1%");
- }else
- {
- $this->sendRoom("%xt%rt%37%".$this->getID()."%");
- $this->sendRoom("%xt%h%37%");
- }
- }
- public function resetDetails() {
- $res = $this->parent->mysql->returnArray("SELECT * FROM {$this->parent->config->mysql->userTableName} WHERE id='" . $this->getID() . "'");
- $res = $res[0];
- $this->username = $res["nickname"];
- $this->isModerator = $res["ismoderator"];
- $this->inventory = explode(",", $res["items"]);
- $this->mascot = $res["mascot"];
- if($this->inventory[0] == "0")
- array_shift($this->inventory);
- $this->buddies = explode(",", $res["buddies"]);
- $this->rank = $res["rank"];
- if($res["curhead"],"head",true){
- $this->head = $res["curhead"];
- }else
- {
- $this->head = 0;
- }
- if($res["curface"],"face",true){
- $this->face = $res["curface"];
- }else
- {
- $this->face = 0;
- }
- if($res["curneck"],"neck",true){
- $this->neck = $res["curneck"];
- }else
- {
- $this->neck = 0;
- }
- if($res["curbody"],"body",true){
- $this->body = $res["curbody"];
- }else
- {
- $this->body = 0;
- }
- if($res["curhands"],"hand",true){
- $this->hands = $res["curhands"];
- }else
- {
- $this->hands = 0;
- }
- if($res["curfeet"],"feet",true){
- $this->feet = $res["curfeet"];
- }else
- {
- $this->feet = 0;
- }
- if($res["curflag"],"pin",true){
- $this->pin = $res["curflag"];
- }else
- {
- $this->pin = 0;
- }
- if($res["curphoto"],"photo",true){
- $this->photo = $res["curphoto"];
- }else
- {
- $this->photo = 0;
- }
- if($res["colour"],"colour"){
- $this->colour = $res["colour"];
- }else
- {
- $this->colour= 0;
- }
- $this->igloo = $res["igloo"];
- $this->floor = $res["floor"];
- $this->furniture = $res["furniture"];
- $this->age = round((strtotime("NOW") - strtotime($res['joindate'])) / (60 * 60 * 24));
- if($res["coins"] == null){
- $res["coins"] = 1000;
- }
- $this->coins = $res["coins"];
- }
- public function getBuddyStr(){
- $buddyStr = "";
- foreach($this->buddies as $buddyID){
- $buddyInfo = $this->parent->mysql->returnArray("SELECT * FROM {$this->parent->config->mysql->userTableName} WHERE id='" . $this->parent->mysql->escape($buddyID) . "';");
- $buddyName = $buddyInfo[0]["nickname"];
- $isOnline = false;
- foreach($this->parent->users as &$user){
- if(is_object($user)){
- if($user->getID() == $buddyID){
- $isOnline = true;
- break;
- }
- }
- }
- $buddyStr .= "$buddyID|" . $buddyName . "|" . $isOnline . "%";
- }
- if($buddyStr == "")
- $buddyStr = "%";
- return $buddyStr;
- }
- public function requestBuddy($id){
- $isOnline = false;
- foreach($this->parent->users as &$user){
- if(is_object($user)){
- if($user->getID() == $id){
- $isOnline = true;
- break;
- }
- }
- }
- if($isOnline){
- $user->buddyRequests[$this->getID()] = true;
- $user->sendPacket("%xt%br%-1%" . $this->parent->mysql->escape($this->getID()) . "%" . $this->parent->mysql->escape($this->getName()) . "%");
- }
- }
- public function acceptBuddy($id){
- $isOnline = false;
- foreach($this->parent->users as &$user){
- if(is_object($user)){
- if($user->getID() == $id){
- $isOnline = true;
- break;
- }
- }
- }
- if($isOnline == false){ return;}
- if($this->buddyRequests[$id] != true){ return; }
- unset($user->buddyRequests[$this->getID()]);
- $this->buddies[$id] = $id;
- $user->buddies[$this->getID()] = $this->getID();
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET buddies='" . $this->parent->mysql->escape(implode(",", $this->buddies)) . "' WHERE id='" . $this->getID() . "';");
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET buddies='" . $this->parent->mysql->escape(implode(",", $user->buddies)) . "' WHERE id='" . $user->getID() . "';");
- $user->sendPacket("%xt%ba%-1%" . $this->getID() . "%" . $this->getName() . "%");
- }
- public function removeBuddy($id){
- foreach($this->parent->users as &$user){
- if(is_object($user)){
- if($user->getID() == $id){
- break;
- }
- }
- }
- unset($this->buddies[$id]);
- unset($user->buddies[$id]);
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET buddies='" . $this->parent->mysql->escape(implode(",", $this->buddies)) . "' WHERE id='" . $this->getID() . "';");
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET buddies='" . $this->parent->mysql->escape(implode(",", $user->buddies)) . "' WHERE id='" . $user->getID() . "';");
- $user->sendPacket("%xt%rb%-1%" . $this->getID() . "%" . $this->getName() . "%");
- }
- public function findBuddy($id){
- foreach($this->parent->users as &$user){
- if(is_object($user)){
- if($user->getID() == $id){
- break;
- }
- }
- }
- $this->sendPacket("%xt%bf%-1%" . $user->room . "%");
- }
- public function getRoomCount() {
- $i = 0;
- foreach ($this->parent->users as $user) {
- if ($user->room == $this->room)
- $i++;
- }
- return $i;
- }
- public function joinRoom($id = 811, $x = 330, $y = 300) {
- if($this->ready2 == true){
- $this->resetDetails();
- if ($this->getRoomCount() > 100)
- $this->sendPacket("%xt%e%-1%210%");
- else {
- if($id>900 && $id<1000){
- $this->sendPacket("%xt%jg%".$this->getID()."%".$id."%");
- }
- else{
- $this->sendRoom("%xt%rp%-1%" . $this->getID() . "%");
- $this->x = $x;
- $this->room = $id;
- $this->y = $y;
- $s = "%xt%jr%-1%$id%" . $this->getString() . "%";
- foreach($this->data["simpleCommands"]["bots"] as $bot){
- if($bot['follow'] == true){
- foreach ($this->parent->users as $user) {
- if ($user->room == $bot["room"])
- $user->sendPacket("%xt%rp%-1%".$bot["id"]."%");
- }
- $this->sendRoom("%xt%ap%-1%".$bot["name"]."|".$bot["id"]."|0|".$bot["colour"]."|".$bot["head"]."|".$bot["face"]."|".$bot["neck"]."|".$bot["body"]."|".$bot["hand"]."|".$bot["feet"]."|".$bot["flag"]."|".$bot["photo"]."|380|300|0|0|0%");
- }
- }
- foreach ($this->getUserList() as $user){
- $s .= $user->getString() . "%";
- }
- foreach($this->parent->users as $user){
- foreach($this->data["simpleCommands"]["bots"] as $bot){
- if($bot->room == $this->room){
- $s .= $bot["id"]."|".$bot["name"]."|0|".$bot["colour"]."|".$bot["head"]."|".$bot["face"]."|".$bot["neck"]."|".$bot["body"]."|".$bot["hand"]."|".$bot["feet"]."|".$bot["flag"]."|".$bot["photo"]."|380|300|0|0|0%";
- }
- }
- }
- $this->sendPacket($s);
- $this->sendRoom("%xt%ap%-1%" . $this->getString() . "%");
- }
- }
- }
- }
- public function sendRoom($packet) {
- foreach ($this->parent->users as $user) {
- if ($user->room == $this->room && is_object($user))
- $user->sendPacket($packet);
- }
- }
- public function getUserList() {
- $users = array();
- foreach ($this->parent->users as &$user) {
- if ($user->room == $this->room)
- $users[] = $user;
- }
- return $users;
- }
- public function sendPacket($packet) {
- if (@stristr($packet, strlen($packet) - 1, 1) != chr(0))
- $packet = $packet . chr(0);
- if(!socket_write($this->sock, $packet, strlen($packet))){
- $this->selfDestruct = true;
- }
- }
- public function getDetails(){
- $name = $this->getName();
- if($this->nickname != ""){
- $name = $this->nickname;
- }
- return array($this->getID(), $name, "1", $this->getColour(), $this->getHead(), $this->getFace(), $this->getNeck(), $this->getBody(), $this->getHands(), $this->getFeet(), $this->getPin(), $this->getPhoto(), $this->getX(), $this->getY(), $this->getFrame(), "1", rank($this->getRank()));
- }
- public function getDetails2($id) {
- return array($id, $this->getName(), "1", $this->getColour(), $this->getHead(), $this->getFace(), $this->getNeck(), $this->getBody(), $this->getHands(), $this->getFeet(), $this->getPin(), $this->getPhoto(), $this->getX(), $this->getY(), $this->getFrame(), "1", rank($this->getRank()));
- }
- public function getRank(){
- return $this->rank;
- }
- public function getString() {
- return implode("|", $this->getDetails());
- }
- public function getString2($id) {
- return implode("|", $this->getDetails2($id));
- }
- public function addItem($id, $force = false) {
- global $crumbs;
- /* if($force == true){
- $this->inventory[] = $id;
- $this->coins = $this->coins - $crumbs[$id]["cost"];
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET items='" . implode(",", $this->inventory) . "', coins='" . $this->getCoins() . "' WHERE id='" . $this->getID() . "';");
- $this->sendPacket("%xt%ai%-1%" . $id . "%" . $this->getCoins() . "%");
- return;
- }*/
- if ($crumbs[$id] == null){
- $this->sendPacket("%xt%e%-1%402%");
- echo $crumbs[$id]."\n";
- }elseif(in_array($id, $this->inventory)){
- $this->sendPacket("%xt%e%-1%400%");
- }elseif($this->coins < $crumbs[$id]["cost"]){
- $this->sendPacket("%xt%e%-1%401%");
- }elseif($crumbs[$id]["can_buy"] == false){
- $this->sendPacket("%xt%e%-1%402%");
- }else{
- $this->inventory[] = $id;
- $this->coins = $this->coins - $crumbs[$id]["cost"];
- $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET items='" . implode(",", $this->inventory) . "', coins='" . $this->getCoins() . "' WHERE id='" . $this->getID() . "';");
- $this->sendPacket("%xt%ai%-1%" . $id . "%" . $this->getCoins() . "%");
- }
- }
- public function timerKick($minutes, $from){
- $this->sendPacket("%xt%tk%-1%$minutes%$from%");
- }
- public function kick(){
- $this->sendPacket("%xt%e%-1%5%");
- unset($this);
- }
- }
- class MySQL {
- public $host;
- public $username;
- public $password;
- private $ref;
- public function mysql() {
- }
- public function connect($host, $username, $password) {
- $this->ref = @mysql_connect($host, $username, $password);
- $this->host = $host;
- $this->username = $username;
- $this->password = $password;
- if ($this->ref == false)
- return false;
- else
- return true;
- }
- public function escape($string) {
- $this->checkConnection();
- return @mysql_real_escape_string($string, $this->ref);
- }
- public function getError() {
- $this->checkConnection();
- return mysql_error($this->ref);
- }
- public function selectDB($db) {
- $this->checkConnection();
- $newRes = @mysql_select_db($db, $this->ref);
- if ($newRes == true)
- return true;
- else
- return false;
- }
- public function query($query) {
- // echo "MYSQL: $query\n";
- $this->checkConnection();
- return @mysql_query($query, $this->ref);
- }
- public function getRows($query) {
- $this->checkConnection();
- $result = $this->query($query);
- return @mysql_num_rows($result);
- }
- public function returnArray($query) {
- $this->checkConnection();
- $result = $this->query($query);
- if (@mysql_num_rows($result) != 0) {
- $arr = array();
- while ($row = @mysql_fetch_assoc($result)){
- $arr[] = $row;
- $r = $arr;
- }
- } else{
- $r = array();
- }
- mysql_free_result($result);
- return $r;
- }
- public function checkConnection() {
- @$this->connect($this->host, $this->username, $this->password);
- }
- public function disconnect(){
- return @mysql_close($this->ref);
- }
- public function __destruct(){
- $this->disconnect();
- }
- }
- ?>
Add Comment
Please, Sign In to add comment