Guest User

aa

a guest
Aug 15th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 56.39 KB | None | 0 0
  1. <?php
  2. /*
  3. ===============================================================
  4. * Orginal RealCP Source *
  5. * Created by Myles nobody else. *
  6. * 20+ Hours of code, 0 exploits. *
  7. ===============================================================
  8. */
  9. ini_set('mysql.connect_timeout', 5);
  10. error_reporting(E_ALL);
  11. ini_set('display_errors', '1');
  12. set_time_limit(0);
  13. date_default_timezone_set('America/Los_Angeles');
  14. include "plugins.php";
  15. include "crumbs.php";
  16. $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");
  17. $init = false;
  18. $count = 0;
  19. function contain($str, array $arr)
  20. {
  21. foreach($arr as $a) {
  22. if (stripos($str,$a) !== false) return true;
  23. }
  24. return false;
  25. }
  26. function rank($rank){
  27. //Calculates how many stripes
  28. // x * 146
  29. $level = 0;
  30. switch($rank){
  31. case 1: //Normal
  32. $level = 1;
  33. break;
  34. case 2: //Guard
  35. $level = 2;
  36. break;
  37. case 3: //Mediator
  38. $level = 2;
  39. break;
  40. case 4: //Moderator
  41. $level = 3;
  42. break;
  43. case 5: //Admin
  44. $level = 4;
  45. break;
  46. case 6: //Super Admin
  47. $level = 4;
  48. break;
  49. case 7: //Owner
  50. $level = 6;
  51. break;
  52. case 8: //Main Owner
  53. $level = 6;
  54. break;
  55. }
  56. return $level * 146;
  57. }
  58. class OpenCP {
  59. public $ip;
  60. public $count;
  61. public $port;
  62. public $users = array();
  63. public $mode;
  64. public $config;
  65. public $mysql;
  66. public $bot;
  67. public $bots;
  68. public $party = false;
  69. public $socket;
  70. public $plugins;
  71. public $color;
  72. public $mapigloos;
  73. public $time = 99;
  74. public $up = 99;
  75. public function __construct($config = "config.xml") {
  76. global $init, $count;
  77. $count++;
  78.  
  79.  
  80. $this->count = $count;
  81. if ($init == false)
  82. $this->createHeader();
  83. else
  84. $this->writeOutput("Starting next server...", "INFO");
  85. $init = true;
  86. sleep(1);
  87. $this->readConfig($config);
  88. }
  89.  
  90. public function readConfig($file) {
  91. echo "\n\n\n";
  92. echo "|----------------------------------------------|\n";
  93. echo "| Reading Configuration Files |\n";
  94. echo "|----------------------------------------------|\n";
  95. if (!file_exists($file))
  96. $this->shutDown("Could not find $file. Does it exist?");
  97. $this->config = simplexml_load_file($file) or $this->shutDown("$file has errors!");
  98. $this->writeOutput("Running as " . $this->config->type . " server", "INFO");
  99. $this->writeOutput("Successfully read config files");
  100. $type = $this->config->type;
  101. $this->plugins = new PluginManager($this,$type);
  102. }
  103.  
  104. public function init() {
  105. $this->mysql = new mysql();
  106. $err = false;
  107. $this->writeOutput("Connecting to MySQL database...", "INFO");
  108. $this->mysql->connect($this->config->mysql->host, $this->config->mysql->username, $this->config->mysql->password) or $err = true;
  109. if ($err == true)
  110. $this->shutDown("Could not connect to mysql. Reason: " . $this->mysql->getError());
  111. $this->mysql->selectDB($this->config->mysql->dbname);
  112. if ($err == true)
  113. $this->shutDown("Could not select the database. Reason: " . $this->mysql->getError());
  114. $this->bind((integer)$this->config->port, (string)$this->config->ip);
  115. $this->writeOutput("We recommend using a while loop here to accept connections", "FINEST");
  116. }
  117. public function bind($port, $ip = "0") {
  118. $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!");
  119. 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");
  120. socket_listen($this->socket);
  121. }
  122. public function loopFunction() {
  123. global $network;
  124. socket_set_block($this->socket);
  125. $read = array();
  126. $read[0] = $this->socket;
  127. foreach ($this->users as $i=>&$user) {
  128. if (!empty($user))
  129. if(is_object($user)){
  130. $read[] = &$user->sock;
  131. }else
  132. {
  133. $read[] = &$user;
  134. }
  135. if(is_object($user)){
  136. if ($user->selfDestruct == true)
  137. unset($this->users[$i]);
  138. }
  139. }
  140. usleep(0);
  141. if($this->config->type == "game"){
  142.  
  143. $min = date("i");
  144. if(is_int($min / 2) && $this->up != $min){
  145. $result = $this->mysql->query("UPDATE servers SET users='".count($this->users)."' WHERE ip='".$network."realcp.info:".$this->config->port."'");
  146. $this->up = $min;
  147. }
  148. if($min == 10 || $min == 30 || $min == 50 || $min == 0){
  149. if($this->time != $min){
  150. $num = rand(1,5);
  151. if($num == 1){
  152. $welcome = "Donating Gets You Exclusive Commands Consider it, Email donate@realcp.info";
  153. $this->sendPacket("%xt%pmsg%-1%Info%0%".$welcome."%");
  154. }
  155. if($num == 2){
  156. $welcome = "Manage Your User realcp.info/panel!";
  157. $this->sendPacket("%xt%pmsg%-1%Info%0%".$welcome."%");
  158. }
  159. if($num == 3){
  160. $welcome = "Made a Video? email video@realcp.info with the link!";
  161. $this->sendPacket("%xt%pmsg%-1%Info%0%".$welcome."%");
  162. }
  163. if($num == 4){
  164. $welcome = "Want a Custom Glow? Donate! Email donate@realcp.info";
  165. $this->sendPacket("%xt%pmsg%-1%Info%0%".$welcome."%");
  166. }
  167. if($num == 5){
  168. $welcome = "Donate4More! Email donate@realcp.info";
  169. $this->sendPacket("%xt%pmsg%-1%Info%0%".$welcome."%");
  170. }
  171. $this->time = $min;
  172. }
  173. }
  174. }
  175. $w = null;
  176. $e = null;
  177. $t = 0;
  178.  
  179. $ready = socket_select($read, $w, $e, $t);
  180. if (in_array($this->socket, $read)) {
  181. if (count($this->users) <= 100) {
  182. $this->users[] = new CPUser(socket_accept($this->socket), $this);
  183. $this->writeOutput("New Client Connected", "FINE");
  184. }
  185. if (count($this->users) >= 100)
  186. $this->writeOutput("Server is full", "INFO");
  187. }
  188. if ($ready-- <= 0)
  189. return;
  190. else {
  191. foreach ($this->users as $index=>&$user) {
  192. if (in_array($user->sock, $read)) {
  193. $input = socket_read($user->sock, 65536);
  194. if ($input == null) {
  195. unset($this->users[$index]);
  196.  
  197. continue;
  198. }
  199. $x = explode(chr(0), $input);
  200. array_pop($x);
  201. foreach ($x as $input2){
  202. $this->handleRawPacket($input2, $user);
  203. }
  204. }
  205. }
  206. }
  207. if(is_array($this->bots)){
  208. foreach($this->bots as $bot){
  209. $bot->heartBeat();
  210. }
  211. }
  212. usleep(0);
  213. }
  214. public function doLogin(&$user, $packet) {
  215. global $ipbans;
  216. if(is_object($user)){
  217. socket_getpeername($user->sock, $ip);
  218. }else
  219. {
  220. socket_getpeername($user, $ip);
  221. }
  222. if(in_array($ip,$ipbans)){
  223. $user->sendPacket($user->sock, "%xt%er%You are <b>IP Banned</b> from RealCP please contact IP@realcp.info %Okay%0%");
  224. return;
  225. }
  226. $username = $this->mysql->escape($this->stribet($packet, "<nick><![CDATA[", "]]"));
  227. $password = $this->stribet($packet, "<pword><![CDATA[", "]]");
  228. if($username != "" || $password != "" || $password != "e9800998ecf8427ed41d8cd98f00b204"){
  229. if ($this->mysql->getRows("SELECT username FROM {$this->config->mysql->userTableName} WHERE username='" . $username . "';") > 0) {
  230. $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) . "';");
  231. if($this->config->type == "login"){
  232. $hash = strtoupper($dbv[0]["password"]);
  233. $hash = $this->encryptPassword($hash, $user->key);
  234. } else {
  235. if($user->key == ""){
  236. echo "[Warning]: HACKER! \n";
  237. $user->sendPacket("%xt%l%-1%");
  238. $user->sendPacket("%xt%e%-1%603%");
  239. return;
  240. }
  241. $hash = $this->swapMD5(md5($dbv[0]["lkey"] . $user->key)) . $dbv[0]["lkey"];
  242. }
  243. if ($password == $hash) {
  244. if ($dbv[0]["active"] != "0") {
  245. if ($dbv[0]["ubdate"] != "PERMABANNED") {
  246. if ($dbv[0]["ubdate"] < strtotime("NOW MDT")) {
  247.  
  248. if ($this->config->type == "login") {
  249. // This is A Plugin Handler, Do Not Remove or Your Plugins May Die.
  250. //Block Multiple Same Users :')
  251.  
  252. $return = $this->plugins->handle("Servers",$username,$password,$user,$packet,$dbv);
  253. if($return['return'] == true){
  254.  
  255. $this->writeSocket($user, "%xt%gs%-1%".$return['servers']."%");
  256. }else
  257. {
  258. $this->writeSocket($user, "%xt%gs%-1%127.0.0.1:6113:Safari World:2|127.0.0.1:6114:Snowy Forts:2%");
  259. }
  260. $this->writeSocket($user, "%xt%l%-1%" . $dbv[0]["id"] . "%" . md5(strrev($user->key)) . "%0%");
  261. $this->mysql->query("UPDATE {$this->config->mysql->userTableName} SET lkey='" . md5(strrev($user->key)) . "' WHERE id='" . $dbv[0]["id"] . "';");
  262. } else {
  263.  
  264. foreach ($this->users as $i=>&$u) {
  265. if (isset($u->username)) {
  266. if ($u->username == $username) {
  267. unset($this->users[$i]);
  268. return;
  269. }
  270.  
  271. }
  272. }
  273.  
  274. $user->id = $dbv[0]["id"];
  275.  
  276. $this->mysql->query("UPDATE {$this->config->mysql->userTableName} SET ips='" . $this->mysql->escape($ip) . "' WHERE id='" . $user->getID() . "';");
  277. $user->resetDetails();
  278. $user->sendPacket("%xt%l%-1%");
  279. }
  280. } else
  281. $this->writeSocket($user, "%xt%e%-1%601%24%");
  282. } else
  283. $this->writeSocket($user, "%xt%e%-1%603%");
  284. } else
  285. $this->writeSocket($user, "%xt%e%-1%900%");
  286. } else
  287. $this->writeSocket($user, "%xt%e%-1%101%");
  288. } else
  289. $this->writeSocket($user, "%xt%e%-1%100%");
  290. }else
  291. {
  292. echo "[Warning]: HACKER! \n";
  293. $this->writeSocket($user, "%xt%e%-1%603%");
  294. }
  295. }
  296. public function encryptPassword($password, $key) {
  297. return $this->swapMD5(md5($this->swapMD5($password) . $key . 'Y(02.>\'H}t":E1'));
  298. }
  299. public function swapMD5($func_md5) {
  300. return substr($func_md5, 16, 16) . substr($func_md5, 0, 16);
  301. }
  302. public function handleRawPacket($packet, &$user) {
  303. if (substr($packet, 0, 1) == "<"){
  304. $this->handleSysPacket($packet, $user);
  305. }
  306. else{
  307. if(is_object($user)){
  308. if (substr($packet, 0, 1) == "%" & $user->loggedin == true){
  309. $this->handleXtPacket($packet, $user);
  310. }
  311. }else
  312. {
  313.  
  314. socket_getpeername($user, $ip);
  315. socket_close($user);
  316. unset($user);
  317. file_put_contents("bad.txt", $ip." ".$packet."\n", FILE_APPEND);
  318.  
  319. }
  320. }
  321.  
  322. }
  323. public function handleAdminPacket($packet, &$user) {
  324. //Packets are xml :-D
  325. echo "Admin Packet: ".$packet."\n";
  326. $mypacket = new SimpleXMLElement($packet);
  327. $username = $mypacket->attributes()->username;
  328. $password = $mypacket->attributes()->password;
  329. if($username != "Admin" && $password != "consolemin2934"){
  330. $this->writeSocket($user, "<admin><result msg=\"Failed Login\"/></admin>");
  331. socket_close($user);
  332. unset($user);
  333. return;
  334. }
  335. $action = $mypacket->action->attributes()->a;
  336. switch($action){
  337. case "find":
  338. foreach($mypacket->action->find as $find){
  339.  
  340. foreach ($this->users as $i=>&$u) {
  341. if (is_object($u)) {
  342. if($u->username == $find->attributes()->name){
  343. $this->writeSocket($user, "<admin><result msg=\"Found User\" room=\"".$u->room."\"/></admin>");
  344. }
  345. }
  346. }
  347.  
  348. }
  349. break;
  350. case "getall":
  351. $str = "";
  352. foreach ($this->users as $i=>&$u) {
  353. if (is_object($u)) {
  354. $str .= "<user name=\"".$u->username."\" id=\"".$u->id."\" room=\"".$u->room."\" />";
  355. }
  356. }
  357. $this->writeSocket($user, "<admin><result msg=\"Collected Users\" />".$str."</admin>");
  358. break;
  359. case "eval":
  360. foreach($mypacket->action->cmd as $cmd){
  361.  
  362. eval($cmd->attributes()->code);
  363. }
  364. break;
  365. case "msg":
  366. foreach($mypacket->action->msg as $msg){
  367. echo "Global Message\n";
  368. $this->sendPacket("%xt%er%".$msg->attributes()->m."%Ok%1%");
  369. $this->writeSocket($user, "<admin><result msg=\"Global'd Message\" /></admin>");
  370. }
  371. break;
  372. case "packet":
  373. foreach($mypacket->action->packet as $msg){
  374. echo "Global Message\n";
  375. $this->sendPacket($msg->attributes()->p);
  376. $this->writeSocket($user, "<admin><result msg=\"Sent Packet\" /></admin>");
  377. }
  378. break;
  379. case "ban":
  380. //By ID or By Name.
  381. foreach($mypacket->action->user as $banu){
  382. //Figure if they have a Name or id
  383. if(isset($banu->attributes()->id)){
  384. foreach ($this->users as $i=>&$u) {
  385. if ($u->id == $banu->attributes()->id){
  386. $u->sendPacket("%xt%er%Banned by ".$banu->attributes()->username."%Ok%0%");
  387. $u->ban();
  388. unset($this->openCP->users[$i]);
  389. }
  390. }
  391. $this->writeSocket($user, "<admin><result msg=\"Banned By ID\" /></admin>");
  392. }else
  393. {
  394. if(isset($banu->attributes()->name)){
  395. foreach ($this->users as $i=>&$u) {
  396. if ($u->username == $banu->attributes()->name)
  397. $u->sendPacket("%xt%er%Banned by ".$banu->attributes()->username."%Ok%0%");
  398. $u->ban();
  399. unset($this->openCP->users[$i]);
  400. }
  401. $this->writeSocket($user, "<admin><result msg=\"Banned By Name\" /></admin>");
  402. }
  403. echo "Ban Console \n";
  404. }
  405.  
  406. }
  407. break;
  408. case "kick":
  409. //By ID or By Name.
  410. foreach($mypacket->action->user as $kicku){
  411. //Figure if they have a Name or id
  412. if(isset($kicku->attributes()->id)){
  413. foreach ($this->users as $i=>&$u) {
  414. if ($u->id == $kicku->attributes()->id)
  415. $u->kick();
  416. }
  417. $this->writeSocket($user, "<admin><result msg=\"Kicked By ID\" /></admin>");
  418. }else
  419. {
  420. if(isset($kicku->attributes()->name)){
  421. foreach ($this->users as $i=>&$u) {
  422. if ($u->username == $kicku->attributes()->name)
  423. $u->kick();
  424. }
  425. $this->writeSocket($user, "<admin><result msg=\"Kicked By Name\" /></admin>");
  426. }
  427. echo "Kick Console \n";
  428. }
  429.  
  430. }
  431. break;
  432. }
  433. $this->writeSocket($user, "<admin><result msg=\"Done\"/></admin>");
  434. socket_close($user);
  435. unset($user);
  436. //Close After done ;D
  437.  
  438. }
  439. public function handleSysPacket($packet, &$user) {
  440. if (stristr($packet, "<policy-file-request/>") > -1)
  441. $this->writeSocket($user, "<cross-domain-policy><allow-access-from domain='*' to-ports='*' /></cross-domain-policy>");
  442. if (stristr($packet, "<msg t='sys'><body action='verChk'") > -1)
  443. $this->writeSocket($user, "<msg t='sys'><body action='apiOK' r='0'></body></msg>");
  444. if (stristr($packet, "<msg t='sys'><body action='rndK' r='-1'></body></msg>") > -1){
  445. $user->key = $this->generateRandomKey();
  446. $this->writeSocket($user, "<msg t='sys'><body action='rndK' r='-1'><k>" . $user->key . "</k></body></msg>");
  447. }
  448. if (stristr($packet, "<admin") > -1){
  449. $this->handleAdminPacket($packet,$user);
  450. }
  451. if (stristr($packet, "<msg t='sys'><body action='login' r='0'>") > -1)
  452. $this->doLogin($user, $packet);
  453. }
  454. public function handleXtPacket($packet, &$user) {
  455. $raw = explode("%", $packet);
  456. $handler = $raw[2];
  457. if ($handler == "s")
  458. $this->handleStandardPacket($packet, $user);
  459. if ($handler == "z")
  460. $this->handleGamePacket($packet, $user);
  461. if($handler == "red")
  462. $this->handleRedemptionPacket($packet,$user);
  463. }
  464. public function handleRedemptionPacket($packet, &$user){
  465. $raw = explode("%", $packet);
  466. if($raw[3] == 'rjs') $user->sendPacket("%xt%rjs%-1%%1,2,4,6,7,8,9,10,11,12,14,15,16,17%0%");
  467. if($raw[3] == 'rsc') $this->sendCode($packet, $user);
  468. }
  469. public function sendCode($packet, &$user) {
  470. $code = array();
  471. $code["COLOUR123"] = array("items"=>"1,2,3,4,5,6,7,8", "coins"=> "100");
  472. $code["BETAHATTROLL"] = array("items"=>"413", "coins"=> "100");
  473. $code["MORETHAN9LETTES"] = array("items"=>"465", "coins"=> "100");
  474. $raw = explode("%", $packet);
  475. $id = $raw[5];
  476. if ($code[$id] == null) {
  477. $this->sendPacket("%xt%e%-1%402%");
  478. } else {
  479. $user->sendPacket("%xt%rsc%-1%CAMPAIGN%" . $code[$id]['items'] . "%%");
  480. $items = explode(",", $code[$id]['items']);
  481. foreach ($items as $add ) {
  482. $user->addItem($add,true);
  483. }
  484. }
  485. }
  486. public function getDefaultRoom(){
  487. $rooms = array("100");
  488. return $rooms[array_rand($rooms)];
  489. }
  490. public function handleStandardPacket($packet, &$user) {
  491. $raw = explode("%", $packet);
  492. $cmd = $raw[3];
  493. if ($cmd == "j#js") {
  494. $lkey = $raw[6];
  495. $res = $this->mysql->returnArray("SELECT username, ismoderator, id, password FROM {$this->config->mysql->userTableName} WHERE id='" . $user->getID() . "'");
  496. if (count($res) > 0)
  497. $user->sendPacket("%xt%js%-1%0%1%" . $res[0]["ismoderator"] . "%0%");
  498. $this->mysql->query("UPDATE {$this->config->mysql->userTableName} SET lkey='' WHERE id='" . $user->getID() . "';");
  499. }
  500. if ($cmd == "j#jp"){
  501. $user->sendPacket("%xt%jp%" . $raw[4] . "%" . $raw[5] . "%");
  502. $user->joinRoom($raw[5], $raw[6], $raw[7]);
  503. }
  504. if ($cmd == "s#jt"){
  505. //Handle JoinTable
  506. $id = $raw[4];
  507. $user->sendPacket("%xt%jt%".$user->room."%".$id."%1%");
  508. }
  509.  
  510. if($cmd == "s#lg"){
  511. if($user->ready == true){
  512. $user->ready2 = true;
  513. $user->joinRoom($this->getDefaultRoom());
  514. //Set Online to Buddies
  515. foreach($this->users as &$suser){
  516.  
  517. if(is_object($suser)){
  518. if(isset($suser->buddies[$user->id])){
  519.  
  520. //Send Online
  521. $suser->sendPacket("%xt%bon%-1%".$user->id."%");
  522. }
  523.  
  524. }
  525. }
  526. $return = $this->plugins->handle("joinServer",$user);
  527. $user->sendPacket("%xt%gi%-1%" . implode("%", $user->getInventory()) . "%");
  528. }
  529. }
  530. if($cmd == "s#gra"){
  531. echo "GETRANK\n";
  532. echo "PC: $packet\n";
  533. $res = $this->mysql->returnArray("SELECT msg, cmsg, username, rank FROM {$this->config->mysql->userTableName} WHERE id='" . $this->mysql->escape($raw[5]) . "'");
  534. // $type = "".$res[0]["rank"];
  535. if($res[0]["msg"] == "false"){
  536. switch($res[0]["rank"]){
  537. case 1:
  538. $type = "User";
  539. break;
  540. case 2:
  541. $type = "Guard";
  542. break;
  543. case 3:
  544. $type = "Mediator";
  545. break;
  546. case 4:
  547. $type = "Moderator";
  548. break;
  549. case 5:
  550. $type = "Admin";
  551. break;
  552. case 6:
  553. $type = "Super Admin";
  554. break;
  555. case 7:
  556. $type = "Owner";
  557. break;
  558. case 8:
  559. $type = "Creator";
  560. break;
  561. default:
  562. $type = "Error";
  563. }
  564. }else
  565. {
  566. $type = $res[0]["msg"];
  567. }
  568.  
  569. echo "Sent Back ".$type;
  570. $user->sendPacket("%xt%gra%".$type."%");
  571.  
  572. }
  573. if ($cmd == "undefined#gv"){
  574. if($user->ready == false){
  575. echo $packet."\n";
  576. if($raw[5] == 30051){
  577. $user->ready = true;
  578. //We Have passed stage1 :-)
  579. $user->sendPacket("%xt%lg%0%11%10%");
  580. }else
  581. {
  582. $this->writeSocket($user, "%xt%e%-1%10005%");
  583. file_put_contents("bad.txt",$user->username."\n",FILE_APPEND);
  584. $user->selfDestruct = true;
  585. $user->ready = false;
  586. unset($user);
  587.  
  588. }
  589. }
  590. }
  591. if ($cmd == "p#pg"){
  592. $user->sendPacket("%xt%pg%" . $raw[4] . "%");
  593. }
  594. if ($cmd == "i#gi"){
  595. $user->sendPacket("%xt%gps%-1%" . $user->getID() . "%9|10|11|14|20|183%");
  596. $user->sendPacket("%xt%glr%-1%3555%");
  597. $user->sendPacket("%xt%lp%-1%" . implode("|", $user->getDetails()) . "%" . $user->getCoins() . "%0%1440%" . rand(1200000000000, 1500000000000) . "%" . $user->getAge() . "%4%" . 1000 . "% %7%");
  598. //Set Ready
  599.  
  600. $user->sendPacket("%xt%gv%");
  601. //10005
  602. // $user->joinRoom($this->getDefaultRoom());
  603. //This is the first time they join a Room So We Can use this
  604. // $return = $this->plugins->handle("joinServer",$user);
  605. // $user->sendPacket("%xt%gi%-1%" . implode("%", $user->getInventory()) . "%");
  606. }
  607. if ($cmd == "g#ai")
  608. $user->addItem($raw[5]);
  609. if ($cmd == "i#ai")
  610. $user->addItem($raw[5]);
  611. if ($cmd == "n#gn")
  612. $user->sendPacket("%xt%gn%-1%");
  613. if ($cmd == "l#mst")
  614. $user->sendPacket("%xt%mst%-1%0%1");
  615. if ($cmd == "l#mg")
  616. $user->sendPacket("%xt%mg%-1%Safari|0|12|OpenCP|0|63%");
  617. if ($cmd == "t#at")
  618. $user->readNews(true);
  619. if ($cmd == "t#rt")
  620. $user->readNews(false);
  621. if ($cmd == "j#jr")
  622. $user->joinRoom($raw[5], $raw[6], $raw[7]);
  623. if ($cmd == "m#sm")
  624. $user->speak($raw[6]);
  625. if ($cmd == "o#m"){
  626. if($user->isModerator == true){
  627.  
  628. foreach($this->users as &$suser){
  629. if($suser->getID() == $raw[5]){
  630. if($user->rank > $suser->rank){
  631. if($suser->muted == false){
  632. $suser->muted = true;
  633.  
  634. $user->sendPacket("%xt%pmsg%-1%Server%0%Muted User%");
  635. }else
  636. {
  637. $suser->muted = false;
  638.  
  639. $user->sendPacket("%xt%pmsg%-1%Server%0%Unmuted User%");
  640. }
  641. }else
  642. {
  643. $user->sendPacket("%xt%pmsg%-1%Server%0%Access Denied: Mute User%");
  644. }
  645. }
  646. }
  647. }
  648. }
  649. if ($cmd == "o#k"){
  650. if($user->isModerator == true){
  651.  
  652. foreach($this->users as &$suser){
  653. if($suser->getID() == $raw[5]){
  654. if($user->rank > $suser->rank){
  655. $suser->kick();
  656. file_put_contents("commandlog-".date('Y-m-d').".txt","[".$user->username." - ".date("H:i:s")."] Kicked ".$suser->username."\n",FILE_APPEND);
  657. }
  658. }
  659. }
  660. }
  661. }
  662. $h = explode("#", $cmd);
  663. $h = $h[0];
  664. if ($h == "s")
  665. $this->handleUserSettingPacket($packet, $user);
  666. if ($h == "u")
  667. $this->handleUserSettingPacket($packet, $user);
  668. if ($h == "f")
  669. $this->handleEPFPacket($packet, $user);
  670. if ($h == "b")
  671. $this->handleBuddyPacket($packet, $user);
  672. if ($h == "g")
  673. $this->handleIglooPacket($packet, $user);
  674. }
  675. public function handleBuddyPacket($packet, &$user){
  676. $raw = explode("%", $packet);
  677. $cmd = $raw[3];
  678. if ($cmd == "b#gb")
  679. $user->sendPacket("%xt%gb%-1%" . $user->getBuddyStr());
  680. if($cmd == "b#br")
  681. $user->requestBuddy($raw[5]);
  682. if($cmd == "b#ba")
  683. $user->acceptBuddy($raw[5]);
  684. if($cmd == "b#rb")
  685. $user->removeBuddy($raw[5]);
  686. if($cmd == "b#bf")
  687. $user->findBuddy($raw[5]);
  688. }
  689. public function getIgloo($rmid){
  690. $id = $rmid - 1000;
  691. if(!is_numeric($rmid)){
  692. return;
  693. }
  694. $igloo = 0;
  695. $result = $this->mysql->query("SELECT igloo FROM {$this->config->mysql->userTableName} WHERE id='$id';");
  696. while ($row = mysql_fetch_assoc($result)) {
  697. $igloo = $row['igloo'];
  698. }
  699. return $igloo;
  700.  
  701. }
  702.  
  703. public function handleIglooPacket($packet, &$user){
  704. $raw = explode("%", $packet);
  705. $cmd = $raw[3];
  706.  
  707. $id = $raw[5];
  708. if($cmd == "g#gr"){
  709. $igloos = "";
  710. foreach($this->mapigloos as $key=>$ig){
  711. $igloos = $igloos.$key."|".$ig."%";
  712. }
  713. $user->sendPacket("%xt%gr%" . $raw[4] ."%". $igloos);
  714. }
  715. if($cmd == "g#or"){
  716. $this->mapigloos[$user->id] = $user->getName();
  717. }
  718. if($cmd == "g#cr"){
  719. unset($this->mapigloos[$user->id]);
  720. }
  721. $raw = explode("%", $packet);
  722. $cmd = $raw[3];
  723. $id = $raw[5];
  724. if($cmd == "g#gm") {
  725. //Get igloo by ID.
  726. $iglooInfo = $this->mysql->returnArray("SELECT igloo, floor, furniture FROM {$this->config->mysql->userTableName} WHERE id='" . $this->mysql->escape($raw[5]) . "';");
  727. $iglooInfo = $iglooInfo[0];
  728.  
  729. $user->sendPacket("%xt%gm%" . $id . "%" . $raw[5] . "%" . $iglooInfo['igloo'] . "%" . $iglooInfo['furniture'] . "%" . $iglooInfo['floor'] . "%");
  730. } elseif($cmd == "g#go") {
  731. $user->sendPacket("%xt%go%" . $raw[4] . "%1%");
  732. } elseif($cmd == "g#gf") {
  733. $furn = $user->getFURNITURE();
  734. $user->sendPacket("%xt%gf%" . $raw[4] . "%" . $user->getFURNITURE() ."%");
  735. } elseif($cmd == "g#af") {
  736. $user->sendPacket("%xt%af%" . $raw[4] . "%" . $raw[5] ."%" . $user->getCoins() . "%");
  737. } elseif($cmd == "g#au") {
  738. $user->changeIGLOO($raw[5]);
  739. $user->sendPacket("%xt%au%" . $raw[4] . "%" . $raw[5] ."%" . $user->getCoins() . "%");
  740. } elseif($cmd == "g#ag") {
  741. $user->changeFloor($raw[5]);
  742. $user->sendPacket("%xt%ag%" . $raw[4] . "%" . $raw[5] ."%" . $user->getCoins() . "%");
  743. } elseif($cmd == "g#um") {
  744. $user->sendPacket("%xt%um%" . $raw[4] . "%" . $raw[5] ."%");
  745. } elseif($cmd == "g#ur") {
  746. $furniture1 = str_replace("%xt%s%g#ur%" . $raw[4] . "%", "" , $packet);
  747. $furniture2 = str_replace("%", "," , $furniture1);
  748. $user->setFurniture($furniture2);
  749. $user->sendPacket("%xt%ur%" . $raw[4] . "%");
  750. }
  751.  
  752. }
  753. public function handleUserSettingPacket($packet, &$user) {
  754. $raw = explode("%", $packet);
  755. $cmd = $raw[3];
  756. if ($cmd == "u#sp")
  757. $user->setXY($raw[5], $raw[6]);
  758. if ($cmd == "u#gp"){
  759. $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]) . "';");
  760. $playerInfo = $playerInfo[0];
  761. $playerInfo["rank"] = rank($playerInfo["rank"]);
  762. $user->sendPacket("%xt%gp%-1%" . $raw[5] . "%" . implode("|", $playerInfo) . "%");
  763. }
  764. if ($cmd == "s#upc")
  765. $user->setColour($raw[5]);
  766. if ($cmd == "s#uph")
  767. $user->setHead($raw[5]);
  768. if ($cmd == "s#upf")
  769. $user->setFace($raw[5]);
  770. if ($cmd == "s#upn")
  771. $user->setNeck($raw[5]);
  772. if ($cmd == "s#upb")
  773. $user->setBody($raw[5]);
  774. if ($cmd == "s#upa")
  775. $user->setHands($raw[5]);
  776. if ($cmd == "s#upe")
  777. $user->setFeet($raw[5]);
  778. if ($cmd == "s#upp")
  779. $user->setPhoto($raw[5]);
  780. if ($cmd == "s#upl")
  781. $user->setPin($raw[5]);
  782. if ($cmd == "u#h")
  783. $user->sendPacket("%xt%h%" . $raw[4] . "%");
  784. if ($cmd == "u#sf")
  785. $user->setFrame($raw[5]);
  786. if($cmd == "u#sb"){
  787. $return = $this->plugins->handle("UserSnowball",$raw[5],$raw[6],$user);
  788. if($return['hide'] == true){
  789.  
  790. }else
  791. {
  792. $user->sendRoom("%xt%sb%-1%" . $user->getID() . "%" . $raw[5] . "%" . $raw[6] . "%");
  793. }
  794. }
  795. if($cmd == "u#se")
  796. $user->sendRoom("%xt%se%-1%" . $user->getID() . "%" . $raw[5] . "%");
  797. if($cmd == "u#sa")
  798. $user->setAction($raw[5]);
  799. if($cmd == "u#ss")
  800. $user->sendRoom("%xt%ss%-1%" . $user->getID() . "%" . $raw[5] . "%");
  801. if($cmd == "u#sl")
  802. $user->sendRoom("%xt%sl%-1%" . $user->getID() . "%" . $raw[5] . "%");
  803. if($cmd == "u#sq")
  804. $user->sendRoom("%xt%sq%-1%" . $user->getID() . "%" . $raw[5] . "%");
  805. if($cmd == "u#sg")
  806. $user->sendRoom("%xt%sg%-1%" . $user->getID() . "%" . $raw[5] . "%");
  807. if($cmd == "u#sj")
  808. $user->sendRoom("%xt%sj%-1%" . $user->getID() . "%" . $raw[5] . "%");
  809. if($cmd == "u#sma")
  810. $user->sendRoom("%xt%sma%-1%" . $user->getID() . "%" . $raw[5] . "%");
  811. }
  812. public function handleEPFPacket($packet, &$user) {
  813. $raw = explode("%", $packet);
  814. $cmd = $raw[3];
  815. if ($cmd == "f#epfga")
  816. $user->sendPacket("%xt%epfga%-1%1%");
  817. if ($cmd == "f#epfgr")
  818. $user->sendPacket("%xt%epfgr%-1%0%0%");
  819. if ($cmd == "f#epfgf")
  820. $user->sendPacket("%xt%epfgf%-1%1%");
  821. }
  822. public function handleGamePacket($packet, &$user) {
  823. $raw = explode("%", $packet);
  824. $cmd = $raw[3];
  825. $gameID = (int) $raw[4];
  826. if($cmd == "gz"){
  827. 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%");
  828. }
  829. if($cmd == "m")
  830. return $user->sendRoom("%xt%zm%" . $user->room . "%{$cmd[5]}%{$cmd[6]}%{$cmd[7]}%{$cmd[8]}%{$cmd[9]}%");
  831. if($user->game != null){
  832. $game = &$user->game;
  833. $game->handlePacket($packet, $user);
  834. } else if($gameID < 1000){
  835. $this->writeOutput("Dojo Debug: " . $gameID . " " . $packet, "FINEST");
  836. } else {
  837. $this->writeOutput($user->getName() . " has just tried to send a packet to a game room that doesn't exist (" . $gameID . ")", "FINER");
  838. }
  839. }
  840. public function writeSocket(&$user, $packet) {
  841. if (@stristr($packet, strlen($packet) - 1, 1) != chr(0))
  842. $packet = $packet . chr(0);
  843. socket_write($user->sock, $packet, strlen($packet));
  844. }
  845. public function stribet($input, $left, $right) {
  846. $pl = stripos($input, $left) + strlen($left);
  847. $pr = stripos($input, $right, $pl);
  848. return substr($input, $pl, $pr - $pl);
  849. }
  850. public function generateRandomKey($amount = 9) {
  851. return "abc12345";
  852. $keyset = "abcdefghijklmABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"\A3$%^&*()_+-=[]{}:@~;'#<>?|\\,./";
  853. $randkey = "";
  854. for ($i = 0; $i < $amount; $i++)
  855. $randkey .= substr($keyset, rand(0, strlen($keyset) - 1), 1);
  856. return $randkey;
  857. }
  858. public function __destruct() {
  859. @socket_shutdown($this->socket);
  860. }
  861. public function shutDown($error) {
  862. $this->writeOutput("System error. Terminating server", "CRITICAL");
  863. $this->writeOutput($error, "CRITICAL");
  864. $this->writeOutput("Server terminated.", "CRITICAL");
  865. if ($this->socket != null)
  866. $this->writeOutput("Closing ports", "INFO");
  867. die();
  868. }
  869. private function createHeader() {
  870. echo "\033[2J";
  871. echo "\n |----------------------------------------------|\n";
  872. echo " | OpenCP - The free CPPS |\n";
  873. echo " |----------------------------------------------|\n";
  874. echo " | Created by the OpenCP Team |\n";
  875. echo " | Copyright 2011 OpenCP Team |\n";
  876. echo " | Licensed under the GNU licence |\n";
  877. echo " |----------------------------------------------|\n";
  878. echo "\n";
  879. $this->writeOutput("License loaded - Personal Version");
  880. $this->writeOutput("Limit: 100 users");
  881. $this->writeOutput("To get a commercial license, please contact a staff member");
  882. echo "\n";
  883. }
  884. private function writeOutput($msg, $type = "INFO") {
  885. echo date("H\:i\:s") . " - [$type] [" . $this->count . "] > $msg\n";
  886. }
  887. public function handleCommand(&$user, $msg) {
  888. if (function_exists("handleCommand") && substr($msg, 0, 1) == "!"){
  889. handleCommand($user, $msg, $this);
  890. }
  891. }
  892. public function sendPacket($packet) {
  893. foreach ($this->users as $user){
  894. if(is_object($user)){
  895. $user->sendPacket($packet);
  896. }}
  897. }
  898. }
  899. /* 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!
  900. This Class won't be counted as a bot. :D, It is fully functional, You need to makesure bot is a registered user though!
  901. */
  902. class CPBot extends CPUser{
  903. public $loggedin = true;
  904. public $ready2 = true;
  905. public $ready = true;
  906. public $time = 0;
  907. public $parent;
  908. public function __construct($info, &$parent) {
  909. //Its a bot so we don't need mr Socket :D
  910. //Info :)
  911. $parent->bots[] = $this;
  912. $this->username = $info['username'];
  913. //Work out ID
  914. $res = $parent->mysql->returnArray("SELECT id, username FROM {$parent->config->mysql->userTableName} WHERE username='" . $this->username . "'");
  915. $id = $res[0]["id"];
  916. $this->id = $id;
  917. $this->sock = null;
  918. $this->parent = $parent;
  919. $this->data = array();
  920. $this->joinRoom($info['room']);
  921.  
  922. }
  923. public function kick(){
  924.  
  925. foreach($this->parent->users as $i=>$suser){
  926. if($suser == $this){
  927. unset($this->parent->users[$i]);
  928. }
  929. }
  930. foreach($this->parent->bots as $i=>$suser){
  931. if($suser == $this){
  932. unset($this->parent->bots[$i]);
  933. }
  934. }
  935. $this->__destruct();
  936. unset($this);
  937. }
  938. public function __destruct() {
  939. $this->sendRoom("%xt%rp%-1%" . $this->getID() . "%");
  940. //Show offline to buddies
  941. foreach($this->parent->users as &$suser){
  942.  
  943. if(is_object($suser)){
  944. if(isset($suser->buddies[$this->id])){
  945.  
  946. //Send Online
  947. $suser->sendPacket("%xt%bof%-1%".$this->id."%");
  948. }
  949.  
  950. }
  951. }
  952. unset($this->parent->mapigloos[$this->getId()]);
  953.  
  954. }
  955.  
  956. public function sendPacket($packet) {
  957. //We Currently Don't have Anything here. :(
  958. //We'll just pretend there is something.
  959. //Actually I'll put something. We'll add simple Emulator :D
  960. $raw = explode("%",$packet);
  961. switch($raw[1]){
  962. case "xt":
  963. //Handle Packet
  964. $this->handlePacket($raw);
  965.  
  966. break;
  967.  
  968. }
  969.  
  970. }
  971. public function heartBeat(){
  972. //Happens when server done stuff ;3
  973. //We need this to happen on average every 5secs.
  974. //We check if last time
  975. if($this->time != 0){
  976. $diff = microtime(true) - $this->time;
  977. if($diff > 4){
  978. //Nothing :D
  979. }else
  980. {
  981. return; //TooQuick
  982. }
  983. }
  984. $r = rand(1,5);
  985. if($r == 1){
  986. if($this->username == "Rockhopper"){
  987. $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!");
  988. $this->speak($msg[rand(1,count($msg) - 1)]);
  989. $this->setXY(rand(100,1000),rand(100,1000));
  990. }
  991. //$this->setColour(rand(1,10));
  992.  
  993. }
  994.  
  995.  
  996.  
  997. //record time now.
  998. $this->time = microtime(true);
  999. }
  1000. public function handleMSG($msg){
  1001. if(contain(strtolower($msg),array("buddy","friend","accept","add"))){
  1002. $this->speak("Feel Free to Add me Pirates!");
  1003. }
  1004. if(rand(1,10) == 1){
  1005. $this->setXY(rand(100,1000),rand(100,1000));
  1006. }
  1007. }
  1008. public function handlePacket($raw){
  1009. switch($raw[2]){
  1010. case "br":
  1011. //Buddy Request.
  1012. $id = $raw[4];
  1013. $this->acceptBuddy($id);
  1014. break;
  1015. case "sm":
  1016. $this->handleMSG($raw[5]);
  1017. break;
  1018. }
  1019. }
  1020.  
  1021. }
  1022. class CPUser {
  1023. public $selfDestruct;
  1024. public $sock;
  1025. public $parent;
  1026. public $inventory;
  1027. public $coins;
  1028. public $username;
  1029. public $room;
  1030. public $lkey;
  1031. public $colour;
  1032. public $ready = false;
  1033. public $id;
  1034. public $head;
  1035. public $face;
  1036. public $neck;
  1037. public $body;
  1038. public $hands;
  1039. public $feet;
  1040. public $pin;
  1041. public $photo;
  1042. public $loggedin = true;
  1043. public $x;
  1044. public $mascot;
  1045. public $y;
  1046. public $key;
  1047. public $rank;
  1048. public $frame;
  1049. public $buddies;
  1050. public $data;
  1051. public $nickname;
  1052. public $buddyRequests = array();
  1053. public $isModerator = false;
  1054. public $ready2 = false;
  1055. public $igloo;
  1056. public $floor;
  1057. public $muted = false;
  1058. public $furniture;
  1059. public function __construct($socket, &$parent) {
  1060. $this->sock = $socket;
  1061. $this->parent = $parent;
  1062. $this->data = array();
  1063. }
  1064. public function __destruct() {
  1065. $this->sendRoom("%xt%rp%-1%" . $this->getID() . "%");
  1066. //Show offline to buddies
  1067. foreach($this->parent->users as &$suser){
  1068.  
  1069. if(is_object($suser)){
  1070. if(isset($suser->buddies[$this->id])){
  1071.  
  1072. //Send Online
  1073. $suser->sendPacket("%xt%bof%-1%".$this->id."%");
  1074. }
  1075.  
  1076. }
  1077. }
  1078. unset($this->parent->mapigloos[$this->getId()]);
  1079.  
  1080. }
  1081. public function getName() {
  1082. return $this->username;
  1083.  
  1084. }
  1085. public function getID() {
  1086. return $this->id;
  1087. }
  1088. public function getHead() {
  1089. return $this->head;
  1090. }
  1091. public function getFace() {
  1092. return $this->face;
  1093. }
  1094. public function getNeck() {
  1095. return $this->neck;
  1096. }
  1097. public function getBody() {
  1098. return $this->body;
  1099. }
  1100. public function getHands() {
  1101. return $this->hands;
  1102. }
  1103. public function getFeet() {
  1104. return $this->feet;
  1105. }
  1106. public function getPin() {
  1107. return $this->pin;
  1108. }
  1109. public function getPhoto() {
  1110. return $this->photo;
  1111. }
  1112. public function getColour() {
  1113. return $this->colour;
  1114. }
  1115. public function getAge() {
  1116. return $this->age;
  1117. }
  1118. public function getCoins() {
  1119. return $this->coins;
  1120. }
  1121. public function getX() {
  1122. return $this->x;
  1123. }
  1124. public function getY() {
  1125. return $this->y;
  1126. }
  1127. public function getInventory() {
  1128. return $this->inventory;
  1129. }
  1130. public function getFrame() {
  1131. return $this->frame;
  1132. }
  1133.  
  1134.  
  1135. public function wearItem($id,$type,$login = false){
  1136. if($type == "pin"){
  1137. return true;
  1138. }
  1139. if($id == 97){
  1140. if($this->id == 4999){
  1141. return true;
  1142. }else
  1143. {
  1144. $this->sendPacket("%xt%er%Access Denied%Failz%1%");
  1145. return false;
  1146. }
  1147. }
  1148. if(in_array($id, $this->inventory) == true || in_array($id, explode(",",file_get_contents("allowedids.txt"))) == true && $this->mascot == 1|| $id < 14 || $this->isModerator == true){
  1149. //Check if allowed/Is on head or if null
  1150. global $crumbs;
  1151.  
  1152. if ($crumbs[$id] == null){
  1153. if(in_array($id, explode(",",file_get_contents("allowedids.txt"))) == true && $this->mascot == 1|| $this->isModerator == true || $id < 14){
  1154. return true;
  1155. }else
  1156. {
  1157. if($login != true){
  1158. $this->sendPacket("%xt%er%Hmm Seems like that item isn't in our Database.%Shame%1%");
  1159. //Override This
  1160. switch($type){
  1161. case "head":
  1162. $this->setHead(0);
  1163. break;
  1164. case "face":
  1165. $this->setFace(0);
  1166. break;
  1167. case "neck":
  1168. $this->setNeck(0);
  1169. break;
  1170. case "body":
  1171. $this->setBody(0);
  1172. break;
  1173. case "hand":
  1174. $this->setHands(0);
  1175. break;
  1176. case "feet":
  1177. $this->setFeet(0);
  1178. break;
  1179. }
  1180. return false;
  1181. }else
  1182. {
  1183. switch($type){
  1184. case "head":
  1185. $this->setHead(0);
  1186. break;
  1187. case "face":
  1188. $this->setFace(0);
  1189. break;
  1190. case "neck":
  1191. $this->setNeck(0);
  1192. break;
  1193. case "body":
  1194. $this->setBody(0);
  1195. break;
  1196. case "hand":
  1197. $this->setHands(0);
  1198. break;
  1199. case "feet":
  1200. $this->setFeet(0);
  1201. break;
  1202. }
  1203. return false;
  1204. }
  1205. }
  1206. }else
  1207. {
  1208. if($crumbs[$id]["type"] == strtoupper($type) || $id < 14){
  1209. return true;
  1210. }else
  1211. {
  1212. $this->sendPacket("%xt%er%Hmm Seems like that item shouldn't be worn that way.%Shame%1%");
  1213. switch($type){
  1214. case "head":
  1215. $this->setHead(0);
  1216. break;
  1217. case "face":
  1218. $this->setFace(0);
  1219. break;
  1220. case "neck":
  1221. $this->setNeck(0);
  1222. break;
  1223. case "body":
  1224. $this->setBody(0);
  1225. break;
  1226. case "hand":
  1227. $this->setHands(0);
  1228. break;
  1229. case "feet":
  1230. $this->setFeet(0);
  1231. break;
  1232. }
  1233. echo $this->username." Tried to wear $id on his/her $type when it should be on ".$crumbs[$id]["type"]."\n";
  1234. return false;
  1235. }
  1236. }
  1237. return true;
  1238. }else
  1239. {
  1240. $this->sendPacket("%xt%er%You tried putting an item on which wasn't in your inventory%Hax%1%");
  1241. switch($type){
  1242. case "head":
  1243. $this->setHead(0);
  1244. break;
  1245. case "face":
  1246. $this->setFace(0);
  1247. break;
  1248. case "neck":
  1249. $this->setNeck(0);
  1250. break;
  1251. case "body":
  1252. $this->setBody(0);
  1253. break;
  1254. case "hand":
  1255. $this->setHands(0);
  1256. break;
  1257. case "feet":
  1258. $this->setFeet(0);
  1259. break;
  1260. }
  1261. return false;
  1262. }
  1263.  
  1264. }
  1265.  
  1266. public function setHead($id) {
  1267. if($this->wearItem($id,"head")){
  1268. $id = $this->parent->mysql->escape($id);
  1269. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curhead='$id' WHERE id='" . $this->getID() . "';");
  1270. $this->sendRoom("%xt%uph%-1%{$this->getID()}%" . $id . "%");
  1271. $this->head = $id;
  1272. }
  1273. }
  1274. public function setFace($id) {
  1275. if($this->wearItem($id,"face")){
  1276. $id = $this->parent->mysql->escape($id);
  1277. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curface='$id' WHERE id='" . $this->getID() . "';");
  1278. $this->sendRoom("%xt%upf%-1%{$this->getID()}%" . $id . "%");
  1279. $this->face = $id;
  1280. }
  1281. }
  1282. public function setNeck($id) {
  1283. if($this->wearItem($id,"neck")){
  1284. $id = $this->parent->mysql->escape($id);
  1285. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curneck='$id' WHERE id='" . $this->getID() . "';");
  1286. $this->sendRoom("%xt%upn%-1%{$this->getID()}%" . $id . "%");
  1287. $this->neck = $id;
  1288. }
  1289. }
  1290. public function setBody($id) {
  1291. if($this->wearItem($id,"body")){
  1292. $id = $this->parent->mysql->escape($id);
  1293. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curbody='$id' WHERE id='" . $this->getID() . "';");
  1294. $this->sendRoom("%xt%upb%-1%{$this->getID()}%" . $id . "%");
  1295. $this->body = $id;
  1296. }
  1297. }
  1298. public function setHands($id) {
  1299. if($this->wearItem($id,"hand")){
  1300. $id = $this->parent->mysql->escape($id);
  1301. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curhands='$id' WHERE id='" . $this->getID() . "';");
  1302. $this->sendRoom("%xt%upa%-1%{$this->getID()}%" . $id . "%");
  1303. $this->hands = $id;
  1304. }
  1305. }
  1306. public function setFeet($id) {
  1307. if($this->wearItem($id,"feet")){
  1308. $id = $this->parent->mysql->escape($id);
  1309. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curfeet='$id' WHERE id='" . $this->getID() . "';");
  1310. $this->sendRoom("%xt%upe%-1%{$this->getID()}%" . $id . "%");
  1311. $this->feet = $id;
  1312. }
  1313. }
  1314. public function setPin($id) {
  1315. if($this->wearItem($id,"pin")){
  1316. $id = $this->parent->mysql->escape($id);
  1317. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curflag='$id' WHERE id='" . $this->getID() . "';");
  1318. $this->sendRoom("%xt%upl%-1%{$this->getID()}%" . $id . "%");
  1319. $this->pin = $id;
  1320. }
  1321. }
  1322. public function setPhoto($id) {
  1323. if($this->wearItem($id,"photo")){
  1324. $id = $this->parent->mysql->escape($id);
  1325. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curphoto='$id' WHERE id='" . $this->getID() . "';");
  1326. $this->sendRoom("%xt%upp%-1%{$this->getID()}%" . $id . "%");
  1327. $this->photo = $id;
  1328. }
  1329. }
  1330. public function setColour($id) {
  1331. if($this->wearItem($id,"colour")){
  1332. $id = $this->parent->mysql->escape($id);
  1333. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET colour='$id' WHERE id='" . $this->getID() . "';");
  1334. $this->sendRoom("%xt%upc%-1%{$this->getID()}%" . $id . "%");
  1335. $this->colour = $id;
  1336. }
  1337. }
  1338. public function ban() {
  1339. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET ubdate='PERMABANNED' WHERE username='" . $this->username . "';");
  1340. }
  1341. public function setCoins($coins) {
  1342. $coins = $this->parent->mysql->escape($coins);
  1343. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET coins='$coins' WHERE id='" . $this->getID() . "';");
  1344. $this->sendPacket("%xt%zo%-1%" . $coins . "%Open%CP%");
  1345. }
  1346. public function setXY($x, $y) {
  1347. $this->x = $x;
  1348. $this->y = $y;
  1349. foreach($this->data["simpleCommands"]["bots"] as $bot){
  1350. if($bot['follow'] == true){
  1351. $this->sendRoom("%xt%sp%-1%" . $bot["id"] . "%".$this->x."%".$this->y."%");
  1352. }
  1353. }
  1354. $this->sendRoom("%xt%sp%-1%" . $this->getID() . "%$x%$y%");
  1355. }
  1356. public function setFrame($frame) {
  1357. $this->frame = $frame;
  1358. $this->sendRoom("%xt%sf%-1%" . $this->getID() . "%" . $frame . "%");
  1359. }
  1360. public function setAction($action) {
  1361. $this->frame = $action;
  1362. $this->sendRoom("%xt%sf%-1%" . $this->getID() . "%" . $action . "%");
  1363. }
  1364. //Igloo Functions
  1365. public function setFurniture($furn) {;
  1366. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET furniture='".$this->parent->mysql->escape($furn)."' WHERE id='" . $this->getID() . "';");
  1367. $this->furniture = $furn;
  1368. }
  1369. public function changeIGLOO($iglooid) {
  1370. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET igloo='" . $this->parent->mysql->escape($iglooid) ."' WHERE id='" . $this->getID() . "';");
  1371. }
  1372. public function changeFloor($floorid) {
  1373. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET floor='" . $this->parent->mysql->escape($floorid) ."' WHERE id='" . $this->getID() . "';");
  1374. }
  1375. public function getIGLOO() {
  1376. return $this->igloo;
  1377. }
  1378. public function getFLOOR() {
  1379. return $this->floor;
  1380. }
  1381. public function getFURNITURE() {
  1382. return $this->furniture;
  1383. }
  1384. public function speak($msg = "I need friends") {
  1385. if($this->muted == false){
  1386. $omsg = str_replace("%","",$msg);
  1387. $msg = $this->parent->mysql->escape($msg);
  1388. $return = $this->parent->plugins->handle("Message",$msg,$this);
  1389.  
  1390. if($return['hide'] == true){
  1391.  
  1392. }else
  1393. {
  1394. $this->sendRoom("%xt%sm%-1%" . $this->getID() . "%" . $omsg . "%");
  1395. }
  1396. }else
  1397. {
  1398. $this->sendPacket("%xt%pmsg%-1%Server%0%You Cannont Talk Because You Are Muted!%");
  1399. }
  1400.  
  1401.  
  1402. }
  1403. public function readNews($bool) {
  1404. if($bool == true){
  1405. $this->sendRoom("%xt%at%37%".$this->getID()."%1%1%");
  1406. }else
  1407. {
  1408. $this->sendRoom("%xt%rt%37%".$this->getID()."%");
  1409. $this->sendRoom("%xt%h%37%");
  1410. }
  1411. }
  1412. public function resetDetails() {
  1413. $res = $this->parent->mysql->returnArray("SELECT * FROM {$this->parent->config->mysql->userTableName} WHERE id='" . $this->getID() . "'");
  1414. $res = $res[0];
  1415. $this->username = $res["nickname"];
  1416. $this->isModerator = $res["ismoderator"];
  1417. $this->inventory = explode(",", $res["items"]);
  1418. $this->mascot = $res["mascot"];
  1419. if($this->inventory[0] == "0")
  1420. array_shift($this->inventory);
  1421. $this->buddies = explode(",", $res["buddies"]);
  1422. $this->rank = $res["rank"];
  1423. if($this->wearItem($res["curhead"],"head",true)){
  1424. $this->head = $res["curhead"];
  1425. }else
  1426. {
  1427. $this->head = 0;
  1428. }
  1429. if($this->wearItem($res["curface"],"face",true)){
  1430. $this->face = $res["curface"];
  1431. }else
  1432. {
  1433. $this->face = 0;
  1434. }
  1435. if($this->wearItem($res["curneck"],"neck",true)){
  1436. $this->neck = $res["curneck"];
  1437. }else
  1438. {
  1439. $this->neck = 0;
  1440. }
  1441. if($this->wearItem($res["curbody"],"body",true)){
  1442. $this->body = $res["curbody"];
  1443. }else
  1444. {
  1445. $this->body = 0;
  1446. }
  1447. if($this->wearItem($res["curhands"],"hand",true)){
  1448. $this->hands = $res["curhands"];
  1449. }else
  1450. {
  1451. $this->hands = 0;
  1452. }
  1453. if($this->wearItem($res["curfeet"],"feet",true)){
  1454. $this->feet = $res["curfeet"];
  1455. }else
  1456. {
  1457. $this->feet = 0;
  1458. }
  1459. if($this->wearItem($res["curflag"],"pin",true)){
  1460. $this->pin = $res["curflag"];
  1461. }else
  1462. {
  1463. $this->pin = 0;
  1464. }
  1465. if($this->wearItem($res["curphoto"],"photo",true)){
  1466. $this->photo = $res["curphoto"];
  1467. }else
  1468. {
  1469. $this->photo = 0;
  1470. }
  1471. if($this->wearItem($res["colour"],"colour")){
  1472. $this->colour = $res["colour"];
  1473. }else
  1474. {
  1475. $this->colour= 0;
  1476.  
  1477. }
  1478.  
  1479. $this->igloo = $res["igloo"];
  1480. $this->floor = $res["floor"];
  1481. $this->furniture = $res["furniture"];
  1482. $this->age = round((strtotime("NOW") - strtotime($res['joindate'])) / (60 * 60 * 24));
  1483. if($res["coins"] == null){
  1484. $res["coins"] = 1000;
  1485. }
  1486. $this->coins = $res["coins"];
  1487.  
  1488. }
  1489. public function getBuddyStr(){
  1490. $buddyStr = "";
  1491. foreach($this->buddies as $buddyID){
  1492. $buddyInfo = $this->parent->mysql->returnArray("SELECT * FROM {$this->parent->config->mysql->userTableName} WHERE id='" . $this->parent->mysql->escape($buddyID) . "';");
  1493. $buddyName = $buddyInfo[0]["nickname"];
  1494. $isOnline = false;
  1495. foreach($this->parent->users as &$user){
  1496. if(is_object($user)){
  1497. if($user->getID() == $buddyID){
  1498. $isOnline = true;
  1499. break;
  1500. }
  1501. }
  1502. }
  1503. $buddyStr .= "$buddyID|" . $buddyName . "|" . $isOnline . "%";
  1504. }
  1505. if($buddyStr == "")
  1506. $buddyStr = "%";
  1507. return $buddyStr;
  1508. }
  1509.  
  1510. public function requestBuddy($id){
  1511. $isOnline = false;
  1512. foreach($this->parent->users as &$user){
  1513. if(is_object($user)){
  1514. if($user->getID() == $id){
  1515. $isOnline = true;
  1516. break;
  1517. }
  1518. }
  1519. }
  1520. if($isOnline){
  1521. $user->buddyRequests[$this->getID()] = true;
  1522. $user->sendPacket("%xt%br%-1%" . $this->parent->mysql->escape($this->getID()) . "%" . $this->parent->mysql->escape($this->getName()) . "%");
  1523. }
  1524. }
  1525. public function acceptBuddy($id){
  1526. $isOnline = false;
  1527. foreach($this->parent->users as &$user){
  1528. if(is_object($user)){
  1529. if($user->getID() == $id){
  1530. $isOnline = true;
  1531. break;
  1532. }
  1533. }
  1534. }
  1535. if($isOnline == false){ return;}
  1536. if($this->buddyRequests[$id] != true){ return; }
  1537. unset($user->buddyRequests[$this->getID()]);
  1538. $this->buddies[$id] = $id;
  1539. $user->buddies[$this->getID()] = $this->getID();
  1540. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET buddies='" . $this->parent->mysql->escape(implode(",", $this->buddies)) . "' WHERE id='" . $this->getID() . "';");
  1541. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET buddies='" . $this->parent->mysql->escape(implode(",", $user->buddies)) . "' WHERE id='" . $user->getID() . "';");
  1542. $user->sendPacket("%xt%ba%-1%" . $this->getID() . "%" . $this->getName() . "%");
  1543. }
  1544. public function removeBuddy($id){
  1545. foreach($this->parent->users as &$user){
  1546. if(is_object($user)){
  1547. if($user->getID() == $id){
  1548. break;
  1549. }
  1550. }
  1551. }
  1552. unset($this->buddies[$id]);
  1553. unset($user->buddies[$id]);
  1554. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET buddies='" . $this->parent->mysql->escape(implode(",", $this->buddies)) . "' WHERE id='" . $this->getID() . "';");
  1555. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET buddies='" . $this->parent->mysql->escape(implode(",", $user->buddies)) . "' WHERE id='" . $user->getID() . "';");
  1556. $user->sendPacket("%xt%rb%-1%" . $this->getID() . "%" . $this->getName() . "%");
  1557. }
  1558. public function findBuddy($id){
  1559. foreach($this->parent->users as &$user){
  1560. if(is_object($user)){
  1561. if($user->getID() == $id){
  1562. break;
  1563. }
  1564. }
  1565. }
  1566. $this->sendPacket("%xt%bf%-1%" . $user->room . "%");
  1567. }
  1568. public function getRoomCount() {
  1569. $i = 0;
  1570. foreach ($this->parent->users as $user) {
  1571. if ($user->room == $this->room)
  1572. $i++;
  1573. }
  1574. return $i;
  1575. }
  1576. public function joinRoom($id = 811, $x = 330, $y = 300) {
  1577. if($this->ready2 == true){
  1578. $this->resetDetails();
  1579. if ($this->getRoomCount() > 100)
  1580. $this->sendPacket("%xt%e%-1%210%");
  1581. else {
  1582. if($id>900 && $id<1000){
  1583. $this->sendPacket("%xt%jg%".$this->getID()."%".$id."%");
  1584. }
  1585. else{
  1586.  
  1587. $this->sendRoom("%xt%rp%-1%" . $this->getID() . "%");
  1588. $this->x = $x;
  1589. $this->room = $id;
  1590. $this->y = $y;
  1591. $s = "%xt%jr%-1%$id%" . $this->getString() . "%";
  1592. foreach($this->data["simpleCommands"]["bots"] as $bot){
  1593. if($bot['follow'] == true){
  1594. foreach ($this->parent->users as $user) {
  1595. if ($user->room == $bot["room"])
  1596. $user->sendPacket("%xt%rp%-1%".$bot["id"]."%");
  1597. }
  1598. $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%");
  1599. }
  1600. }
  1601. foreach ($this->getUserList() as $user){
  1602. $s .= $user->getString() . "%";
  1603. }
  1604. foreach($this->parent->users as $user){
  1605. foreach($this->data["simpleCommands"]["bots"] as $bot){
  1606. if($bot->room == $this->room){
  1607. $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%";
  1608.  
  1609. }
  1610. }
  1611. }
  1612. $this->sendPacket($s);
  1613. $this->sendRoom("%xt%ap%-1%" . $this->getString() . "%");
  1614. }
  1615. }
  1616. }
  1617. }
  1618. public function sendRoom($packet) {
  1619. foreach ($this->parent->users as $user) {
  1620. if ($user->room == $this->room && is_object($user))
  1621. $user->sendPacket($packet);
  1622. }
  1623. }
  1624. public function getUserList() {
  1625. $users = array();
  1626. foreach ($this->parent->users as &$user) {
  1627. if ($user->room == $this->room)
  1628. $users[] = $user;
  1629. }
  1630. return $users;
  1631. }
  1632. public function sendPacket($packet) {
  1633. if (@stristr($packet, strlen($packet) - 1, 1) != chr(0))
  1634. $packet = $packet . chr(0);
  1635. if(!socket_write($this->sock, $packet, strlen($packet))){
  1636. $this->selfDestruct = true;
  1637. }
  1638. }
  1639. public function getDetails(){
  1640. $name = $this->getName();
  1641. if($this->nickname != ""){
  1642. $name = $this->nickname;
  1643. }
  1644. 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()));
  1645. }
  1646. public function getDetails2($id) {
  1647. 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()));
  1648. }
  1649. public function getRank(){
  1650. return $this->rank;
  1651. }
  1652. public function getString() {
  1653. return implode("|", $this->getDetails());
  1654. }
  1655. public function getString2($id) {
  1656. return implode("|", $this->getDetails2($id));
  1657. }
  1658. public function addItem($id, $force = false) {
  1659. global $crumbs;
  1660. /* if($force == true){
  1661.  
  1662. $this->inventory[] = $id;
  1663. $this->coins = $this->coins - $crumbs[$id]["cost"];
  1664. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET items='" . implode(",", $this->inventory) . "', coins='" . $this->getCoins() . "' WHERE id='" . $this->getID() . "';");
  1665. $this->sendPacket("%xt%ai%-1%" . $id . "%" . $this->getCoins() . "%");
  1666. return;
  1667. }*/
  1668. if ($crumbs[$id] == null){
  1669. $this->sendPacket("%xt%e%-1%402%");
  1670. echo $crumbs[$id]."\n";
  1671. }elseif(in_array($id, $this->inventory)){
  1672. $this->sendPacket("%xt%e%-1%400%");
  1673. }elseif($this->coins < $crumbs[$id]["cost"]){
  1674. $this->sendPacket("%xt%e%-1%401%");
  1675. }elseif($crumbs[$id]["can_buy"] == false){
  1676. $this->sendPacket("%xt%e%-1%402%");
  1677. }else{
  1678.  
  1679. $this->inventory[] = $id;
  1680. $this->coins = $this->coins - $crumbs[$id]["cost"];
  1681. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET items='" . implode(",", $this->inventory) . "', coins='" . $this->getCoins() . "' WHERE id='" . $this->getID() . "';");
  1682. $this->sendPacket("%xt%ai%-1%" . $id . "%" . $this->getCoins() . "%");
  1683. }
  1684. }
  1685. public function timerKick($minutes, $from){
  1686. $this->sendPacket("%xt%tk%-1%$minutes%$from%");
  1687. }
  1688. public function kick(){
  1689. $this->sendPacket("%xt%e%-1%5%");
  1690. unset($this);
  1691. }
  1692. }
  1693. class MySQL {
  1694. public $host;
  1695. public $username;
  1696. public $password;
  1697. private $ref;
  1698. public function mysql() {
  1699. }
  1700. public function connect($host, $username, $password) {
  1701. $this->ref = @mysql_connect($host, $username, $password);
  1702. $this->host = $host;
  1703. $this->username = $username;
  1704. $this->password = $password;
  1705. if ($this->ref == false)
  1706. return false;
  1707. else
  1708. return true;
  1709. }
  1710. public function escape($string) {
  1711. $this->checkConnection();
  1712. return @mysql_real_escape_string($string, $this->ref);
  1713. }
  1714. public function getError() {
  1715. $this->checkConnection();
  1716. return mysql_error($this->ref);
  1717. }
  1718. public function selectDB($db) {
  1719. $this->checkConnection();
  1720. $newRes = @mysql_select_db($db, $this->ref);
  1721. if ($newRes == true)
  1722. return true;
  1723. else
  1724. return false;
  1725. }
  1726. public function query($query) {
  1727. // echo "MYSQL: $query\n";
  1728. $this->checkConnection();
  1729. return @mysql_query($query, $this->ref);
  1730. }
  1731. public function getRows($query) {
  1732. $this->checkConnection();
  1733. $result = $this->query($query);
  1734. return @mysql_num_rows($result);
  1735. }
  1736. public function returnArray($query) {
  1737. $this->checkConnection();
  1738. $result = $this->query($query);
  1739.  
  1740. if (@mysql_num_rows($result) != 0) {
  1741. $arr = array();
  1742. while ($row = @mysql_fetch_assoc($result)){
  1743. $arr[] = $row;
  1744. $r = $arr;
  1745. }
  1746. } else{
  1747. $r = array();
  1748. }
  1749. mysql_free_result($result);
  1750. return $r;
  1751. }
  1752. public function checkConnection() {
  1753. @$this->connect($this->host, $this->username, $this->password);
  1754. }
  1755. public function disconnect(){
  1756. return @mysql_close($this->ref);
  1757. }
  1758. public function __destruct(){
  1759. $this->disconnect();
  1760. }
  1761. }
  1762. ?>
Add Comment
Please, Sign In to add comment