Guest User

Untitled

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