Guest User

code

a guest
Aug 24th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.66 KB | None | 0 0
  1. <?php
  2. ini_set('mysql.connect_timeout', 300);
  3. ini_set('default_socket_timeout', 300);
  4.  
  5. error_reporting(E_ALL);
  6. set_time_limit(0);
  7. define("SINGLE_PLAYER", 1);
  8. define("MULTI_PLAYER", 2);
  9.  
  10. include "crumbs.php";
  11. include "config.php";
  12. $init = false;
  13. $count = 0;
  14.  
  15. class penguinelite {
  16. public $ip;
  17. public $count;
  18. public $port;
  19. public $users = array();
  20. public $mode;
  21. public $config;
  22. public $mysql;
  23. public $bot;
  24. public $BotName;
  25. public $StartMsg;
  26. public $games;
  27. private $socket;
  28. public function __construct($config = "config.xml") {
  29. global $init, $count;
  30. $count++;
  31. $this->count = $count;
  32. if ($init == false)
  33. $this->createHeader();
  34. else
  35. $this->writeOutput("Starting next server...", "INFO");
  36. $init = true;
  37. $this->readConfig($config);
  38. }
  39. public function readConfig($file) {
  40. echo "\n\n\n";
  41. echo "|----------------------------------------------|\n";
  42. echo "| Reading Configuration Files |\n";
  43. echo "|----------------------------------------------|\n";
  44. if (!file_exists($file))
  45. $this->shutDown("Could not find $file. Does it exist?");
  46. $this->config = simplexml_load_file($file) or $this->shutDown("$file has errors!");
  47. $this->writeOutput("Running as " . $this->config->type . " server", "INFO");
  48. $this->writeOutput("Successfully read config files");
  49. }
  50. public function init() {
  51. $this->mysql = new mysql();
  52. $err = false;
  53. $this->writeOutput("Connecting to MySQL database...", "INFO");
  54. $this->mysql->connect($this->config->mysql->host, $this->config->mysql->username, $this->config->mysql->password) or $err = true;
  55. if ($err == true)
  56. $this->shutDown("Could not connect to mysql. Reason: " . $this->mysql->getError());
  57. $this->mysql->selectDB($this->config->mysql->dbname);
  58. if ($err == true)
  59. $this->shutDown("Could not select the database. Reason: " . $this->mysql->getError());
  60. $this->bind((integer)$this->config->port, (string)$this->config->ip);
  61. $this->writeOutput("We recommend using a while loop here to accept connections", "FINEST");
  62. }
  63. public function bind($port, $ip = "0") {
  64. $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!");
  65. socket_set_option($this->socket, SOL_SOCKET, SO_REUSEADDR, 1);
  66. 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");
  67. socket_listen($this->socket);
  68. }
  69. public function loopFunction() {
  70. socket_set_block($this->socket);
  71. $read = array();
  72. $read[0] = $this->socket;
  73. foreach ($this->users as $i=>&$user) {
  74. if (!empty($user))
  75. $read[] = &$user->sock;
  76. if ($user->selfDestruct == true)
  77. unset($this->users[$i]);
  78. }
  79. $ready = socket_select($read, $w = null, $e = null, $t = 0);
  80. if (in_array($this->socket, $read)) {
  81. if (count($this->users) <= 1000) {
  82. $this->users[] = new CPUser(socket_accept($this->socket), $this);
  83. $this->writeOutput("New Client Connected", "FINE");
  84. } else if(count($this->users) >= 1000)
  85. $this->writeOutput("Server is full", "INFO");
  86. }
  87. if ($ready-- <= 0)
  88. return;
  89. else {
  90. foreach ($this->users as $index=>&$user) {
  91. if (in_array($user->sock, $read)) {
  92. $input = socket_read($user->sock, 65536);
  93. if ($input == null) {
  94. unset($this->users[$index]);
  95. continue;
  96. }
  97. $x = explode(chr(0), $input);
  98. array_pop($x);
  99. foreach ($x as $input2){
  100. $this->handleRawPacket($input2, $user);
  101. }
  102. }
  103. }
  104. }
  105. }
  106. public function doLogin(&$user, $packet) {
  107. $username = $this->mysql->escape($this->stribet($packet, "<nick><![CDATA[", "]]"));
  108. $password = $this->stribet($packet, "<pword><![CDATA[", "]]");
  109. if($username != "" || $password != "" || $password != "e9800998ecf8427ed41d8cd98f00b204"){
  110. if ($this->mysql->getRows("SELECT * FROM {$this->config->mysql->userTableName} WHERE username='" . $username . "';") > 0) {
  111. $dbv = $this->mysql->returnArray("SELECT * FROM {$this->config->mysql->userTableName} WHERE username='" . $this->mysql->escape($username) . "';");
  112. if($this->config->type == "login"){
  113. $hash = strtoupper($dbv[0]["password"]);
  114. $hash = $this->encryptPassword($hash, $user->key);
  115. } else {
  116. $hash = $this->swapMD5(md5($dbv[0]["lkey"] . $user->key)) . $dbv[0]["lkey"];
  117. }
  118. if ($password == $hash) {
  119. if ($dbv[0]["active"] != "0") {
  120. if ($dbv[0]["ubdate"] != "PERMABANNED") {
  121. if ($dbv[0]["ubdate"] < strtotime("NOW MDT")) {
  122. if ($this->config->type == "login") {
  123. global $server1IP, $server1Port, $server1Name, $server2IP, $server2Port, $server2Name;
  124. $this->writeSocket($user, "%xt%gs%-1%" . $server1IP . ":" . $server1Port . ":" . $server1Name . ":3|" . $server2IP . ":" . $server2Port . ":" . $server2Name . ":2% 3;");
  125. $this->writeSocket($user, "%xt%l%-1%" . $dbv[0]["id"] . "%" . md5(strrev($user->key)) . "%0%");
  126. $this->mysql->query("UPDATE {$this->config->mysql->userTableName} SET lkey='" . md5(strrev($user->key)) . "' WHERE id='" . $dbv[0]["id"] . "';");
  127. } else {
  128. socket_getsockname($user->sock, $ip);
  129. $user->id = $dbv[0]["id"];
  130. $this->mysql->query("UPDATE {$this->config->mysql->userTableName} SET ips=ips + '\n" . $this->mysql->escape($ip) . "' WHERE id='" . $user->getID() . "';");
  131. $user->resetDetails();
  132. $user->sendPacket("%xt%l%-1%");
  133. global $StartMsg;
  134. if($StartMsg != null)
  135. $this->sendPacket("%xt%lm%-1%http://ultimatecheatscp.info/content/loginmsg.swf?msg=$StartMsg%");
  136. }
  137. } else
  138. $this->writeSocket($user, "%xt%e%-1%601%24%");
  139. } else
  140. $this->writeSocket($user, "%xt%e%-1%603%");
  141. } else
  142. $this->writeSocket($user, "%xt%e%-1%900%");
  143. } else
  144. $this->writeSocket($user, "%xt%e%-1%101%");
  145. } else
  146. $this->writeSocket($user, "%xt%e%-1%100%");
  147. }
  148. }
  149. public function encryptPassword($password, $key) {
  150. return $this->swapMD5(md5($this->swapMD5($password) . $key . 'Y(02.>\'H}t":E1'));
  151. }
  152. public function swapMD5($func_md5) {
  153. return substr($func_md5, 16, 16) . substr($func_md5, 0, 16);
  154. }
  155. public function handleRawPacket($packet, &$user) {
  156. if (substr($packet, 0, 1) == "<")
  157. $this->handleSysPacket($packet, $user);
  158. elseif (substr($packet, 0, 1) == "%")
  159. $this->handleXtPacket($packet, $user);
  160. }
  161. public function handleSysPacket($packet, &$user) {
  162. if (stristr($packet, "<policy-file-request/>") > -1)
  163. $this->writeSocket($user, "<cross-domain-policy><allow-access-from domain='*' to-ports='*' /></cross-domain-policy>");
  164. if (stristr($packet, "<msg t='sys'><body action='verChk'") > -1)
  165. $this->writeSocket($user, "<msg t='sys'><body action='apiOK' r='0'></body></msg>");
  166. if (stristr($packet, "<msg t='sys'><body action='rndK' r='-1'></body></msg>") > -1){
  167. $user->key = $this->generateRandomKey();
  168. $this->writeSocket($user, "<msg t='sys'><body action='rndK' r='-1'><k>" . $user->key . "</k></body></msg>");
  169. }
  170. if (stristr($packet, "<msg t='sys'><body action='login' r='0'>") > -1)
  171. $this->doLogin($user, $packet);
  172. }
  173. public function handleXtPacket($packet, &$user) {
  174. $raw = explode("%", $packet);
  175. $handler = $raw[2];
  176. if ($handler == "s")
  177. $this->handleStandardPacket($packet, $user);
  178. if ($handler == "z")
  179. $this->handleGamePacket($packet, $user);
  180. }
  181. public function getDefaultRoom(){
  182. $rooms = array("100", "110", "111", "120", "121", "130", "200", "210", "220", "221", "230", "300", "310", "320", "330", "340", "400", "410", "411", "800", "801", "802", "804", "805", "806", "807", "808", "809");
  183. return $rooms[array_rand($rooms)];
  184. }
  185. public function handleStandardPacket($packet, &$user) {
  186. $raw = explode("%", $packet);
  187. $cmd = $raw[3];
  188. if ($cmd == "j#js") {
  189. $lkey = $raw[6];
  190. $res = $this->mysql->returnArray("SELECT * FROM {$this->config->mysql->userTableName} WHERE id='" . $user->getID() . "'");
  191. if (count($res) > 0)
  192. $user->sendPacket("%xt%js%-1%0%1%" . $res[0]["ismoderator"] . "%0%");
  193. $this->mysql->query("UPDATE {$this->config->mysql->userTableName} SET lkey='' WHERE id='" . $user->getID() . "';");
  194. }
  195. if ($cmd == "j#jp"){
  196. $user->sendPacket("%xt%jp%" . $raw[4] . "%" . $raw[5] . "%");
  197. $user->joinRoom($raw[5], $raw[6], $raw[7]);
  198. }
  199. if ($cmd == "p#pg"){
  200. $user->sendPacket("%xt%pg%" . $raw[4] . "%");
  201. }
  202. if ($cmd == "i#gi"){
  203. $user->sendPacket("%xt%gps%-1%" . $user->getID() . "%9|10|11|14|20|183%");
  204. $user->sendPacket("%xt%glr%-1%3555%");
  205. $user->sendPacket("%xt%lp%-1%" . implode("|", $user->getDetails()) . "%" . $user->getCoins() . "%0%1440%" . rand(1200000000000, 1500000000000) . "%" . $user->getAge() . "%4%" . $user->getAge() . "% %7%");
  206. $user->joinRoom($this->getDefaultRoom());
  207. $user->sendPacket("%xt%gi%-1%" . implode("%", $user->getInventory()) . "%");
  208. }
  209. if ($cmd == "i#ai")
  210. $user->addItem($raw[5]);
  211. if ($cmd == "n#gn")
  212. $user->sendPacket("%xt%gn%-1%");
  213. if ($cmd == "l#mst")
  214. $user->sendPacket("%xt%mst%-1%0%1");
  215. if ($cmd == "l#mg")
  216. $user->sendPacket("%xt%mg%-1%Safari|0|12|penguinelite|0|63%");
  217. if ($cmd == "j#jr")
  218. $user->joinRoom($raw[5], $raw[6], $raw[7]);
  219. if ($cmd == "m#sm")
  220. $user->speak($raw[6]);
  221. if ($cmd == "o#k" && $this->isModerator){
  222. foreach($this->users as &$suser){
  223. if($suser->getID() == $raw[5]){
  224. $suser->kick();
  225. }
  226. }
  227. }
  228. $h = explode("#", $cmd);
  229. $h = $h[0];
  230. if ($h == "s")
  231. $this->handleUserSettingPacket($packet, $user);
  232. if ($h == "u")
  233. $this->handleUserSettingPacket($packet, $user);
  234. if ($h == "f")
  235. $this->handleEPFPacket($packet, $user);
  236. if ($h == "b")
  237. $this->handleBuddyPacket($packet, $user);
  238. if ($h == "g")
  239. $this->handleIglooPacket($packet, $user);
  240. }
  241. public function handleBuddyPacket($packet, &$user){
  242. $raw = explode("%", $packet);
  243. $cmd = $raw[3];
  244. if ($cmd == "b#gb")
  245. $user->sendPacket("%xt%gb%-1%" . $user->getBuddyStr());
  246. if($cmd == "b#br")
  247. $user->requestBuddy($raw[5]);
  248. if($cmd == "b#ba")
  249. $user->acceptBuddy($raw[5]);
  250. if($cmd == "b#rb")
  251. $user->removeBuddy($raw[5]);
  252. if($cmd == "b#bf")
  253. $user->findBuddy($raw[5]);
  254. }
  255. public function handleIglooPacket($packet, &$user){
  256. $raw = explode("%", $packet);
  257. $cmd = $raw[3];
  258. $id = $raw[5];
  259. if($cmd == "g#gm") {
  260. $user->sendPacket("%xt%gm%" . $raw[4] . "%" . $raw[5] . "%" . $user->getIGLOO() . "%" . $user->getFURNITURE() . "%" . $user->getFLOOR() . "%");
  261. } elseif($cmd == "g#go") {
  262. $user->sendPacket("%xt%go%" . $raw[4] . "%1%");
  263. } elseif($cmd == "g#gf") {
  264. $furn = $user->getFURNITURE();
  265. $user->sendPacket("%xt%gf%" . $raw[4] . "%" . $user->getFURNITURE() ."%");
  266. } elseif($cmd == "g#af") {
  267. $user->sendPacket("%xt%af%" . $raw[4] . "%" . $raw[5] ."%" . $user->getCoins() . "%");
  268. } elseif($cmd == "g#au") {
  269. $user->changeIGLOO($raw[5]);
  270. $user->sendPacket("%xt%au%" . $raw[4] . "%" . $raw[5] ."%" . $user->getCoins() . "%");
  271. } elseif($cmd == "g#ag") {
  272. $user->changeFloor($raw[5]);
  273. $user->sendPacket("%xt%ag%" . $raw[4] . "%" . $raw[5] ."%" . $user->getCoins() . "%");
  274. } elseif($cmd == "g#um") {
  275. $user->sendPacket("%xt%um%" . $raw[4] . "%" . $raw[5] ."%");
  276. } elseif($cmd == "g#ur") {
  277. $furniture1 = str_replace("%xt%s%g#ur%" . $raw[4] . "%", "" , $packet);
  278. $furniture2 = str_replace("%", "," , $furniture1);
  279. $user->setFurniture($furniture2);
  280. $user->sendPacket("%xt%ur%" . $raw[4] . "%");
  281. }
  282.  
  283. }
  284. public function handleUserSettingPacket($packet, &$user) {
  285. $raw = explode("%", $packet);
  286. $cmd = $raw[3];
  287. if ($cmd == "u#sp")
  288. $user->setXY($raw[5], $raw[6]);
  289. if ($cmd == "u#gp"){
  290. $playerInfo = $this->mysql->returnArray("SELECT id, nickname, '1', colour, curhead, curface, curneck, curbody, curhands, curfeet, curflag, curphoto, rank * 146 FROM {$this->config->mysql->userTableName} WHERE id='" . $this->mysql->escape($raw[5]) . "';");
  291. $playerInfo = $playerInfo[0];
  292. $user->sendPacket("%xt%gp%-1%" . $raw[5] . "%" . implode("|", $playerInfo) . "%");
  293. }
  294. if ($cmd == "s#upc")
  295. $user->setColour($raw[5]);
  296. if ($cmd == "s#uph")
  297. $user->setHead($raw[5]);
  298. if ($cmd == "s#upf")
  299. $user->setFace($raw[5]);
  300. if ($cmd == "s#upn")
  301. $user->setNeck($raw[5]);
  302. if ($cmd == "s#upb")
  303. $user->setBody($raw[5]);
  304. if ($cmd == "s#upa")
  305. $user->setHands($raw[5]);
  306. if ($cmd == "s#upe")
  307. $user->setFeet($raw[5]);
  308. if ($cmd == "s#upp")
  309. $user->setPhoto($raw[5]);
  310. if ($cmd == "s#upl")
  311. $user->setPin($raw[5]);
  312. if ($cmd == "u#h")
  313. $user->sendPacket("%xt%h%" . $raw[4] . "%");
  314. if ($cmd == "u#sf")
  315. $user->setFrame($raw[5]);
  316. if($cmd == "u#sb")
  317. $user->sendRoom("%xt%sb%-1%" . $user->getID() . "%" . $raw[5] . "%" . $raw[6] . "%");
  318. if($cmd == "u#se")
  319. $user->sendRoom("%xt%se%-1%" . $user->getID() . "%" . $raw[5] . "%");
  320. if($cmd == "u#sa")
  321. $user->setAction($raw[5]);
  322. if($cmd == "u#ss")
  323. $user->sendRoom("%xt%ss%-1%" . $user->getID() . "%" . $raw[5] . "%");
  324. if($cmd == "u#sl")
  325. $user->sendRoom("%xt%sl%-1%" . $user->getID() . "%" . $raw[5] . "%");
  326. if($cmd == "u#sq")
  327. $user->sendRoom("%xt%sq%-1%" . $user->getID() . "%" . $raw[5] . "%");
  328. if($cmd == "u#sg")
  329. $user->sendRoom("%xt%sg%-1%" . $user->getID() . "%" . $raw[5] . "%");
  330. if($cmd == "u#sj")
  331. $user->sendRoom("%xt%sj%-1%" . $user->getID() . "%" . $raw[5] . "%");
  332. if($cmd == "u#sma")
  333. $user->sendRoom("%xt%sma%-1%" . $user->getID() . "%" . $raw[5] . "%");
  334. }
  335. public function handleEPFPacket($packet, &$user) {
  336. $raw = explode("%", $packet);
  337. $cmd = $raw[3];
  338. if ($cmd == "f#epfga")
  339. $user->sendPacket("%xt%epfga%-1%1%");
  340. if ($cmd == "f#epfgr")
  341. $user->sendPacket("%xt%epfgr%-1%0%0%");
  342. if ($cmd == "f#epfgf")
  343. $user->sendPacket("%xt%epfgf%-1%0%");
  344. }
  345. public function handleGamePacket($packet, &$user){
  346. $raw = explode("%", $packet);
  347. $cmd = $raw[3];
  348. $gameID = (int) $raw[4];
  349. if($cmd == "m")
  350. return $user->sendRoom("%xt%zm%" . $user->room . "%{$cmd[5]}%{$cmd[6]}%{$cmd[7]}%{$cmd[8]}%{$cmd[9]}%");
  351. if($user->game != null){
  352. $game = &$user->game;
  353. $game->handlePacket($packet, $user);
  354. } else if($gameID < 1000){
  355. $this->writeOutput("Dojo Debug: " . $gameID . " " . $packet, "FINEST");
  356. } else {
  357. $this->writeOutput($user->getName() . " has just tried to send a packet to a game room that doesn't exist (" . $gameID . ")", "FINER");
  358. }
  359. }
  360. public function writeSocket(&$user, $packet) {
  361. if (@stristr($packet, strlen($packet) - 1, 1) != chr(0))
  362. $packet = $packet . chr(0);
  363. socket_write($user->sock, $packet, strlen($packet));
  364. }
  365. public function stribet($input, $left, $right) {
  366. $pl = stripos($input, $left) + strlen($left);
  367. $pr = stripos($input, $right, $pl);
  368. return substr($input, $pl, $pr - $pl);
  369. }
  370. public function generateRandomKey($amount = 9) {
  371. return "abc12345";
  372. $keyset = "abcdefghijklmABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"£$%^&*()_+-=[]{}:@~;'#<>?|\\,./";
  373. $randkey = "";
  374. for ($i = 0; $i < $amount; $i++)
  375. $randkey .= substr($keyset, rand(0, strlen($keyset) - 1), 1);
  376. return $randkey;
  377. }
  378. public function __destruct() {
  379. @socket_shutdown($this->socket);
  380. }
  381. public function shutDown($error) {
  382. $this->writeOutput("System error. Terminating server", "CRITICAL");
  383. $this->writeOutput($error, "CRITICAL");
  384. $this->writeOutput("Server terminated.", "CRITICAL");
  385. if ($this->socket != null)
  386. $this->writeOutput("Closing ports", "INFO");
  387. die();
  388. }
  389. private function createHeader() {
  390. echo "\033[2J";
  391. echo "\n |----------------------------------------------|\n";
  392. echo " | Penguin Elite v2 - The free CPPS |\n";
  393. echo " |----------------------------------------------|\n";
  394. echo " | Created by Cooldude170 |\n";
  395. echo " | Original by ZKid |\n";
  396. echo " |----------------------------------------------|\n";
  397. echo "\n";
  398. $this->writeOutput("Successfully loaded, welcome to Penguin Elite v2!");
  399. echo "\n";
  400. }
  401. private function writeOutput($msg, $type = "INFO") {
  402. echo date("H\:i\:s") . " - [$type] [" . $this->count . "] > $msg\n";
  403. }
  404. public function handleCommand(&$user, $msg) {
  405. if (function_exists("handleCommand") && substr($msg, 0, 1) == "!"){
  406. handleCommand($user, $msg, $this);
  407. }
  408. }
  409. public function sendPacket($packet) {
  410. foreach ($this->users as $user)
  411. $user->sendPacket($packet);
  412. }
  413. }
  414. class CPUser {
  415. public $selfDestruct;
  416. public $sock;
  417. public $parent;
  418. public $inventory;
  419. public $coins;
  420. public $username;
  421. public $email;
  422. public $room;
  423. public $lkey;
  424. public $colour;
  425. public $id;
  426. public $head;
  427. public $face;
  428. public $neck;
  429. public $body;
  430. public $hands;
  431. public $feet;
  432. public $pin;
  433. public $photo;
  434. public $loggedin;
  435. public $x;
  436. public $y;
  437. public $key;
  438. public $rank;
  439. public $igloo;
  440. public $floor;
  441. public $furniture;
  442. public $frame;
  443. public $buddies;
  444. public $buddyRequests = array();
  445. public $isModerator = false;
  446. public $stamps = array();
  447. public $muted = false;
  448. public $game;
  449. public $mail;
  450. public function __construct($socket, &$parent) {
  451. $this->sock = $socket;
  452. $this->parent = $parent;
  453. }
  454. public function __destruct() {
  455. $this->sendRoom("%xt%rp%-1%" . $this->getID() . "%");
  456. }
  457. public function getName() {
  458. return $this->username;
  459. }
  460. public function getEmail() {
  461. return $this->email;
  462. }
  463. public function getID() {
  464. return $this->id;
  465. }
  466. public function getIGLOO() {
  467. return $this->igloo;
  468. }
  469. public function getFLOOR() {
  470. return $this->floor;
  471. }
  472. public function getFURNITURE() {
  473. return $this->furniture;
  474. }
  475. public function getHead() {
  476. return $this->head;
  477. }
  478. public function getFace() {
  479. return $this->face;
  480. }
  481. public function getNeck() {
  482. return $this->neck;
  483. }
  484. public function getBody() {
  485. return $this->body;
  486. }
  487. public function getHands() {
  488. return $this->hands;
  489. }
  490. public function getFeet() {
  491. return $this->feet;
  492. }
  493. public function getPin() {
  494. return $this->pin;
  495. }
  496. public function getPhoto() {
  497. return $this->photo;
  498. }
  499. public function getColour() {
  500. return $this->colour;
  501. }
  502. public function getAge() {
  503. return $this->age;
  504. }
  505. public function getCoins() {
  506. return $this->coins;
  507. }
  508. public function getX() {
  509. return $this->x;
  510. }
  511. public function getY() {
  512. return $this->y;
  513. }
  514. public function getInventory() {
  515. return $this->inventory;
  516. }
  517. public function getFrame() {
  518. return $this->frame;
  519. }
  520. public function setHead($id) {
  521. $id = $this->parent->mysql->escape($id);
  522. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curhead='$id' WHERE id='" . $this->getID() . "';");
  523. $this->sendRoom("%xt%uph%-1%{$this->getID()}%" . $id . "%");
  524. $this->head = $id;
  525. }
  526. public function setFurniture($furn) {
  527. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET furniture='$furn' WHERE id='" . $this->getID() . "';");
  528. $this->furniture = $furn;
  529. }
  530. public function changeIGLOO($iglooid) {
  531. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET igloo='" . $iglooid ."' WHERE id='" . $this->getID() . "';");
  532. }
  533. public function changeFloor($floorid) {
  534. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET floor='" . $floorid ."' WHERE id='" . $this->getID() . "';");
  535. }
  536. public function setFace($id) {
  537. $id = $this->parent->mysql->escape($id);
  538. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curface='$id' WHERE id='" . $this->getID() . "';");
  539. $this->sendRoom("%xt%upf%-1%{$this->getID()}%" . $id . "%");
  540. $this->face = $id;
  541. }
  542. public function setNeck($id) {
  543. $id = $this->parent->mysql->escape($id);
  544. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curneck='$id' WHERE id='" . $this->getID() . "';");
  545. $this->sendRoom("%xt%upn%-1%{$this->getID()}%" . $id . "%");
  546. $this->neck = $id;
  547. }
  548. public function setBody($id) {
  549. $id = $this->parent->mysql->escape($id);
  550. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curbody='$id' WHERE id='" . $this->getID() . "';");
  551. $this->sendRoom("%xt%upb%-1%{$this->getID()}%" . $id . "%");
  552. $this->body = $id;
  553. }
  554. public function setHands($id) {
  555. $id = $this->parent->mysql->escape($id);
  556. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curhands='$id' WHERE id='" . $this->getID() . "';");
  557. $this->sendRoom("%xt%upa%-1%{$this->getID()}%" . $id . "%");
  558. $this->hands = $id;
  559. }
  560. public function setFeet($id) {
  561. $id = $this->parent->mysql->escape($id);
  562. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curfeet='$id' WHERE id='" . $this->getID() . "';");
  563. $this->sendRoom("%xt%upe%-1%{$this->getID()}%" . $id . "%");
  564. $this->feet = $id;
  565. }
  566. public function setPin($id) {
  567. $id = $this->parent->mysql->escape($id);
  568. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curflag='$id' WHERE id='" . $this->getID() . "';");
  569. $this->sendRoom("%xt%upl%-1%{$this->getID()}%" . $id . "%");
  570. $this->pin = $id;
  571. }
  572. public function setPhoto($id) {
  573. $id = $this->parent->mysql->escape($id);
  574. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET curphoto='$id' WHERE id='" . $this->getID() . "';");
  575. $this->sendRoom("%xt%upp%-1%{$this->getID()}%" . $id . "%");
  576. $this->photo = $id;
  577. }
  578. public function setColour($id) {
  579. $id = $this->parent->mysql->escape($id);
  580. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET colour='$id' WHERE id='" . $this->getID() . "';");
  581. $this->sendRoom("%xt%upc%-1%{$this->getID()}%" . $id . "%");
  582. $this->colour = $id;
  583. }
  584. public function setCoins($coins) {
  585. $coins = $this->parent->mysql->escape($coins);
  586. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET coins='$coins' WHERE id='" . $this->getID() . "';");
  587. $this->sendPacket("%xt%zo%-1%" . $coins . "%Open%CP%");
  588. }
  589. public function setXY($x, $y) {
  590. $this->x = $x;
  591. $this->y = $y;
  592. $this->sendRoom("%xt%sp%-1%" . $this->getID() . "%$x%$y%");
  593. }
  594. public function setFrame($frame) {
  595. $this->frame = $frame;
  596. $this->sendRoom("%xt%sf%-1%" . $this->getID() . "%" . $frame . "%");
  597. }
  598. public function setAction($action) {
  599. $this->frame = 1;
  600. $this->sendRoom("%xt%sf%-1%" . $this->getID() . "%" . $action . "%");
  601. }
  602. public function speak($msg = "I need friends") {
  603. $this->sendRoom("%xt%sm%-1%" . $this->getID() . "%" . htmlspecialchars($msg) . "%");
  604. $this->parent->handleCommand($this, $msg);
  605. include("censor.php");
  606. if(in_array($msg, $censored)){
  607. $this->sendPacket("%xt%e%-1%610%Please do not use bad language. THIS IS NOT A BAN!%");
  608. }
  609. }
  610. public function resetDetails() {
  611. $res = $this->parent->mysql->returnArray(" SELECT* FROM {$this->parent->config->mysql->userTableName} WHERE id='" . $this->getID() . "'");
  612. $res = $res[0];
  613. $this->username = $res["nickname"];
  614. $this->head = $res["curhead"];
  615. $this->face = $res["curface"];
  616. $this->neck = $res["curneck"];
  617. $this->body = $res["curbody"];
  618. $this->hands = $res["curhands"];
  619. $this->feet = $res["curfeet"];
  620. $this->pin = $res["curflag"];
  621. $this->photo = $res["curphoto"];
  622. $this->colour = $res["colour"];
  623. $this->age = round((strtotime("NOW") - strtotime($res['joindate'])) / (60 * 60 * 24));
  624. $this->coins = $res["coins"];
  625. $this->isModerator = $res["ismoderator"];
  626. $this->inventory = explode(",", $res["items"]);
  627. if($this->inventory[0] == "0")
  628. array_shift($this->inventory);
  629. $this->buddies = explode(",", $res["buddies"]);
  630. $this->rank = $res["rank"];
  631. $this->igloo = $res["igloo"];
  632. $this->floor = $res["floor"];
  633. $this->furniture = $res["furniture"];
  634. }
  635. public function getBuddyStr(){
  636. $buddyStr = "";
  637. foreach($this->buddies as $buddyID){
  638. $buddyInfo = $this->parent->mysql->returnArray("SELECT * FROM {$this->parent->config->mysql->userTableName} WHERE id='" . $this->parent->mysql->escape($buddyID) . "';");
  639. $buddyName = $buddyInfo[0]["nickname"];
  640. $isOnline = false;
  641. foreach($this->parent->users as &$user){
  642. if($user->getID() == $buddyID){
  643. $isOnline = true;
  644. break;
  645. }
  646. }
  647. $buddyStr .= "$buddyID|" . $buddyName . "|" . $isOnline . "%";
  648. }
  649. if($buddyStr == "")
  650. $buddyStr = "%";
  651. return $buddyStr;
  652. }
  653. public function requestBuddy($id){
  654. $isOnline = false;
  655. foreach($this->parent->users as &$user){
  656. if($user->getID() == $id){
  657. $isOnline = true;
  658. break;
  659. }
  660. }
  661. if($isOnline){
  662. $user->buddyRequests[$this->getID()] = true;
  663. $user->sendPacket("%xt%br%-1%" . $this->parent->mysql->escape($this->getID()) . "%" . $this->parent->mysql->escape($this->getName()) . "%");
  664. }
  665. }
  666. public function acceptBuddy($id){
  667. $isOnline = false;
  668. foreach($this->parent->users as &$user){
  669. if($user->getID() == $id){
  670. $isOnline = true;
  671. break;
  672. }
  673. }
  674. if($isOnline == false){ return $this->kick(); }
  675. if($this->buddyRequests[$id] != true){ return $this->kick(); }
  676. unset($user->buddyRequests[$this->getID()]);
  677. $this->buddies[$id] = $id;
  678. $user->buddies[$this->getID()] = $this->getID();
  679. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET buddies='" . $this->parent->mysql->escape(implode(",", $this->buddies)) . "' WHERE id='" . $this->getID() . "';");
  680. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET buddies='" . $this->parent->mysql->escape(implode(",", $user->buddies)) . "' WHERE id='" . $user->getID() . "';");
  681. $user->sendPacket("%xt%ba%-1%" . $this->getID() . "%" . $this->getName() . "%");
  682. }
  683. public function removeBuddy($id){
  684. foreach($this->parent->users as &$user){
  685. if($user->getID() == $id){
  686. break;
  687. }
  688. }
  689. unset($this->buddies[$id]);
  690. unset($user->buddies[$id]);
  691. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET buddies='" . $this->parent->mysql->escape(implode(",", $this->buddies)) . "' WHERE id='" . $this->getID() . "';");
  692. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET buddies='" . $this->parent->mysql->escape(implode(",", $user->buddies)) . "' WHERE id='" . $user->getID() . "';");
  693. $user->sendPacket("%xt%rb%-1%" . $this->getID() . "%" . $this->getName() . "%");
  694. }
  695. public function findBuddy($id){
  696. foreach($this->parent->users as &$user){
  697. if($user->getID() == $id){
  698. break;
  699. }
  700. }
  701. $this->sendPacket("%xt%bf%-1%" . $user->room . "%");
  702. }
  703. public function getRoomCount() {
  704. $i = 0;
  705. foreach ($this->parent->users as $user) {
  706. if ($user->room == $this->room)
  707. $i++;
  708. }
  709. return $i;
  710. }
  711. public function joinRoom($id = 100, $x = 330, $y = 300) {
  712. // $this->resetDetails();
  713. if($id > 899){
  714. //Game Room
  715. $this->room = $id;
  716. $this->sendRoom("%xt%rp%" . $this->room . "%" . $this->getID() . "%");
  717. $this->game = new ocpGame(SINGLE_PLAYER, $id);
  718. $this->sendPacket("%xt%jg%" . $this->room . "%$id%"); //Single player game
  719. return;
  720. }
  721. if ($this->getRoomCount() > 50)
  722. $this->sendPacket("%xt%e%-1%210%");
  723. else {
  724. $this->sendRoom("%xt%rp%-1%" . $this->getID() . "%");
  725. $this->x = $x;
  726. $this->room = $id;
  727. $this->y = $y;
  728. $s = "%xt%jr%-1%$id%" . $this->getString() . "%";
  729. global $BotName;
  730. $s .= "0|" . $BotName . "|1|14|413|442|0|0|0|0|0|0|380|300|0|1|999%";
  731. foreach ($this->getUserList() as $user)
  732. $s .= $user->getString() . "%";
  733. $this->sendPacket($s);
  734. $this->sendRoom("%xt%ap%-1%" . $this->getString() . "%");
  735. }
  736. }
  737. public function sendRoom($packet) {
  738. foreach ($this->parent->users as $user) {
  739. if ($user->room == $this->room)
  740. $user->sendPacket($packet);
  741. }
  742. }
  743. public function getUserList() {
  744. $users = array();
  745. foreach ($this->parent->users as &$user) {
  746. if ($user->room == $this->room)
  747. $users[] = $user;
  748. }
  749. return $users;
  750. }
  751. public function sendPacket($packet) {
  752. if (@stristr($packet, strlen($packet) - 1, 1) != chr(0))
  753. $packet = $packet . chr(0);
  754. if(!socket_write($this->sock, $packet, strlen($packet))){
  755. $this->selfDestruct = true;
  756. }
  757. }
  758. public function getDetails() {
  759. return array($this->getID(), $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", $this->getRank() * 146);
  760. }
  761. public function getRank(){
  762. return $this->rank;
  763. }
  764. public function getString() {
  765. return implode("|", $this->getDetails());
  766. }
  767. public function getStamps(){
  768. return $this->stamps;
  769. }
  770. public function addStamp($id){
  771. $stamps = explode("|", $id);
  772. foreach($stamps as $sid){
  773. mysql_query("UPDATE {$this->parent->config->mysql->userTableName} SET stamps='" . $stamps . "' WHERE id='" . $id . "';");
  774. $this->stamps[$id] = "yes";
  775. }
  776. $this->sendPacket("%xt%aabs%" . $this->room . "%" . $id . "%");
  777. $this->sendPacket("%xt%gmres%" . $this->room . "%" . $id . "%");
  778. }
  779. public function addItem($id) {
  780. global $crumbs;
  781. if ($crumbs[$id] == null)
  782. $this->sendPacket("%xt%e%-1%402%");
  783. elseif (in_array($id, $this->inventory))
  784. $this->sendPacket("%xt%e%-1%400%");
  785. elseif ($this->coins < $crumbs[$id]["cost"])
  786. $this->sendPacket("%xt%e%-1%401%");
  787. else {
  788. $this->inventory[] = $id;
  789. $this->coins = $this->coins - $crumbs[$id]["cost"];
  790. $this->parent->mysql->query("UPDATE {$this->parent->config->mysql->userTableName} SET items='" . implode(",", $this->inventory) . "', coins='" . $this->getCoins() . "' WHERE id='" . $this->getID() . "';");
  791. $this->sendPacket("%xt%ai%-1%" . $id . "%" . $this->getCoins() . "%");
  792. }
  793. }
  794. public function timerKick($minutes, $from){
  795. $this->sendPacket("%xt%tk%-1%$minutes%$from%");
  796. }
  797. public function kick(){
  798. $this->sendPacket("%xt%e%-1%5%");
  799. }
  800. }
  801. class ocpGame {
  802. public $type;
  803. public $roomID;
  804. public $server;
  805. public function __construct($type, $roomID){
  806. $this->type = $type;
  807. $this->roomID = $roomID;
  808. }
  809. public function handlePacket($packet, &$user){
  810. $raw = explode("%", $packet);
  811. $cmd = $raw[3];
  812. if((int)$this->type == 1){
  813. //Single User
  814. if($cmd == "zo")
  815. $user->setCoins((int)$user->getCoins() + ((int) $raw[5] / 10));
  816. } else if((int)$this->type == 2){
  817. if($cmd == ""){ }
  818. } else {
  819. //Something's gone horribly wrong
  820. echo "Somethings gone horribly wrong. Game type: " . $this->type . ", room ID: " . $this->roomID . "\n";
  821. }
  822. }
  823. }
  824. class MySQL {
  825. public $host;
  826. public $username;
  827. public $password;
  828. private $ref;
  829. public function mysql() {
  830. }
  831. public function connect($host, $username, $password) {
  832. $this->ref = @mysql_connect($host, $username, $password);
  833. $this->host = $host;
  834. $this->username = $username;
  835. $this->password = $password;
  836. if ($this->ref == false)
  837. return false;
  838. else
  839. return true;
  840. }
  841. public function escape($string) {
  842. $this->checkConnection();
  843. return @mysql_real_escape_string($string, $this->ref);
  844. }
  845. public function getError() {
  846. $this->checkConnection();
  847. return mysql_error($this->ref);
  848. }
  849. public function selectDB($db) {
  850. $this->checkConnection();
  851. $newRes = @mysql_select_db($db, $this->ref);
  852. if ($newRes == true)
  853. return true;
  854. else
  855. return false;
  856. }
  857. public function query($query) {
  858. $this->checkConnection();
  859. return @mysql_query($query, $this->ref);
  860. }
  861. public function getRows($query) {
  862. $this->checkConnection();
  863. $result = $this->query($query);
  864. return @mysql_num_rows($result);
  865. }
  866. public function returnArray($query) {
  867. $this->checkConnection();
  868. $result = $this->query($query);
  869.  
  870. if (@mysql_num_rows($result) != 0) {
  871. $arr = array();
  872. while ($row = @mysql_fetch_assoc($result))
  873. $arr[] = $row;
  874. return $arr;
  875. } else
  876. return array();
  877. }
  878. public function checkConnection() {
  879. @$this->connect($this->host, $this->username, $this->password);
  880. }
  881. public function disconnect(){
  882. return @mysql_close($this->ref);
  883. }
  884. public function __destruct(){
  885. $this->disconnect();
  886. sleep(4);
  887. }
  888. }
  889. ?>
Add Comment
Please, Sign In to add comment