Advertisement
Guest User

Untitled

a guest
Apr 12th, 2019
1,936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 248.35 KB | None | 0 0
  1. /**********************************************************************************
  2. First Growtopia Private Server made with ENet.
  3. Copyright (C) 2018 Growtopia Noobs
  4.  
  5.  
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Affero General Public License as published
  8. by the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10.  
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU Affero General Public License for more details.
  16.  
  17.  
  18. You should have received a copy of the GNU Affero General Public License
  19. along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. **********************************************************************************/
  21.  
  22.  
  23.  
  24.  
  25. #include "stdafx.h"
  26. #include <iostream>
  27.  
  28.  
  29. #include "enet/enet.h"
  30. #include <string>
  31. #include <windows.h>
  32. #include <vector>
  33. #include <sstream>
  34. #include <chrono>
  35. #include <fstream>
  36. #include "json.hpp"
  37. #include "bcrypt.h"
  38. #include "crypt_blowfish/crypt_gensalt.c"
  39. #include "crypt_blowfish/crypt_blowfish.h"
  40. #include "crypt_blowfish/crypt_blowfish.c"
  41. #include "crypt_blowfish/wrapper.c"
  42. #include "bcrypt.c"
  43. #include <conio.h>
  44. #include <thread> // TODO
  45. #include <mutex> // TODO
  46.  
  47.  
  48. using namespace std;
  49. using json = nlohmann::json;
  50.  
  51.  
  52. //#define TOTAL_LOG
  53. #define REGISTRATION
  54.  
  55.  
  56. ENetHost * server;
  57. int cId = 1;
  58. BYTE* itemsDat = 0;
  59. int itemsDatSize = 0;
  60.  
  61.  
  62. /***bcrypt***/
  63.  
  64.  
  65. bool verifyPassword(string password, string hash) {
  66. int ret;
  67.  
  68. ret = bcrypt_checkpw(password.c_str(), hash.c_str());
  69. assert(ret != -1);
  70.  
  71. return !ret;
  72. }
  73.  
  74.  
  75. string hashPassword(string password) {
  76. char salt[BCRYPT_HASHSIZE];
  77. char hash[BCRYPT_HASHSIZE];
  78. int ret;
  79.  
  80. ret = bcrypt_gensalt(12, salt);
  81. assert(ret == 0);
  82. ret = bcrypt_hashpw(password.c_str(), salt, hash);
  83. assert(ret == 0);
  84. return hash;
  85. }
  86.  
  87.  
  88. /***bcrypt**/
  89.  
  90.  
  91. void sendData(ENetPeer* peer, int num, char* data, int len)
  92. {
  93. /* Create a reliable packet of size 7 containing "packet\0" */
  94. ENetPacket * packet = enet_packet_create(0,
  95. len + 5,
  96. ENET_PACKET_FLAG_RELIABLE);
  97. /* Extend the packet so and append the string "foo", so it now */
  98. /* contains "packetfoo\0" */
  99. /* Send the packet to the peer over channel id 0. */
  100. /* One could also broadcast the packet by */
  101. /* enet_host_broadcast (host, 0, packet); */
  102. memcpy(packet->data, &num, 4);
  103. if (data != NULL)
  104. {
  105. memcpy(packet->data+4, data, len);
  106. }
  107. char zero = 0;
  108. memcpy(packet->data + 4 + len, &zero, 1);
  109. enet_peer_send(peer, 0, packet);
  110. enet_host_flush(server);
  111. }
  112.  
  113.  
  114. int getPacketId(char* data)
  115. {
  116. return *data;
  117. }
  118.  
  119.  
  120. char* getPacketData(char* data)
  121. {
  122. return data + 4;
  123. }
  124.  
  125.  
  126. string text_encode(char* text)
  127. {
  128. string ret = "";
  129. while (text[0] != 0)
  130. {
  131. switch (text[0])
  132. {
  133. case '\n':
  134. ret += "\\n";
  135. break;
  136. case '\t':
  137. ret += "\\t";
  138. break;
  139. case '\b':
  140. ret += "\\b";
  141. break;
  142. case '\\':
  143. ret += "\\\\";
  144. break;
  145. case '\r':
  146. ret += "\\r";
  147. break;
  148. default:
  149. ret += text[0];
  150. break;
  151. }
  152. text++;
  153. }
  154. return ret;
  155. }
  156.  
  157.  
  158. int ch2n(char x)
  159. {
  160. switch (x)
  161. {
  162. case '0':
  163. return 0;
  164. case '1':
  165. return 1;
  166. case '2':
  167. return 2;
  168. case '3':
  169. return 3;
  170. case '4':
  171. return 4;
  172. case '5':
  173. return 5;
  174. case '6':
  175. return 6;
  176. case '7':
  177. return 7;
  178. case '8':
  179. return 8;
  180. case '9':
  181. return 9;
  182. case 'A':
  183. return 10;
  184. case 'B':
  185. return 11;
  186. case 'C':
  187. return 12;
  188. case 'D':
  189. return 13;
  190. case 'E':
  191. return 14;
  192. case 'F':
  193. return 15;
  194. default:
  195. break;
  196. }
  197. }
  198.  
  199.  
  200.  
  201.  
  202. char* GetTextPointerFromPacket(ENetPacket* packet)
  203. {
  204. char zero = 0;
  205. memcpy(packet->data + packet->dataLength - 1, &zero, 1);
  206. return (char*)(packet->data + 4);
  207. }
  208.  
  209.  
  210. BYTE* GetStructPointerFromTankPacket(ENetPacket* packet)
  211. {
  212. unsigned int packetLenght = packet->dataLength;
  213. BYTE* result = NULL;
  214. if (packetLenght >= 0x3C)
  215. {
  216. BYTE* packetData = packet->data;
  217. result = packetData + 4;
  218. if (*(BYTE*)(packetData + 16) & 8)
  219. {
  220. if (packetLenght < *(int*)(packetData + 56) + 60)
  221. {
  222. cout << "Packet too small for extended packet to be valid" << endl;
  223. cout << "Sizeof float is 4. TankUpdatePacket size: 56" << endl;
  224. result = 0;
  225. }
  226. }
  227. else
  228. {
  229. int zero = 0;
  230. memcpy(packetData + 56, &zero, 4);
  231. }
  232. }
  233. return result;
  234. }
  235.  
  236.  
  237. int GetMessageTypeFromPacket(ENetPacket* packet)
  238. {
  239. int result;
  240.  
  241.  
  242. if (packet->dataLength > 3u)
  243. {
  244. result = *(packet->data);
  245. }
  246. else
  247. {
  248. cout << "Bad packet length, ignoring message" << endl;
  249. result = 0;
  250. }
  251. return result;
  252. }
  253.  
  254.  
  255.  
  256.  
  257. vector<string> explode(const string &delimiter, const string &str)
  258. {
  259. vector<string> arr;
  260.  
  261.  
  262. int strleng = str.length();
  263. int delleng = delimiter.length();
  264. if (delleng == 0)
  265. return arr;//no change
  266.  
  267.  
  268. int i = 0;
  269. int k = 0;
  270. while (i<strleng)
  271. {
  272. int j = 0;
  273. while (i + j<strleng && j<delleng && str[i + j] == delimiter[j])
  274. j++;
  275. if (j == delleng)//found delimiter
  276. {
  277. arr.push_back(str.substr(k, i - k));
  278. i += delleng;
  279. k = i;
  280. }
  281. else
  282. {
  283. i++;
  284. }
  285. }
  286. arr.push_back(str.substr(k, i - k));
  287. return arr;
  288. }
  289.  
  290.  
  291. struct GamePacket
  292. {
  293. BYTE* data;
  294. int len;
  295. int indexes;
  296. };
  297.  
  298.  
  299.  
  300.  
  301. GamePacket appendFloat(GamePacket p, float val)
  302. {
  303. //p.data[56] += 1;
  304. BYTE* n = new BYTE[p.len + 2 + 4];
  305. memcpy(n, p.data, p.len);
  306. delete p.data;
  307. p.data = n;
  308. n[p.len] = p.indexes;
  309. n[p.len + 1] = 1;
  310. memcpy(n + p.len + 2, &val, 4);
  311. p.len = p.len + 2 + 4;
  312. p.indexes++;
  313. return p;
  314. }
  315.  
  316.  
  317. GamePacket appendFloat(GamePacket p, float val, float val2)
  318. {
  319. //p.data[56] += 1;
  320. BYTE* n = new BYTE[p.len + 2 + 8];
  321. memcpy(n, p.data, p.len);
  322. delete p.data;
  323. p.data = n;
  324. n[p.len] = p.indexes;
  325. n[p.len + 1] = 3;
  326. memcpy(n + p.len + 2, &val, 4);
  327. memcpy(n + p.len + 6, &val2, 4);
  328. p.len = p.len + 2 + 8;
  329. p.indexes++;
  330. return p;
  331. }
  332.  
  333.  
  334. GamePacket appendFloat(GamePacket p, float val, float val2, float val3)
  335. {
  336. //p.data[56] += 1;
  337. BYTE* n = new BYTE[p.len + 2 + 12];
  338. memcpy(n, p.data, p.len);
  339. delete p.data;
  340. p.data = n;
  341. n[p.len] = p.indexes;
  342. n[p.len + 1] = 4;
  343. memcpy(n + p.len + 2, &val, 4);
  344. memcpy(n + p.len + 6, &val2, 4);
  345. memcpy(n + p.len + 10, &val3, 4);
  346. p.len = p.len + 2 + 12;
  347. p.indexes++;
  348. return p;
  349. }
  350.  
  351.  
  352. GamePacket appendInt(GamePacket p, int val)
  353. {
  354. //p.data[56] += 1;
  355. BYTE* n = new BYTE[p.len + 2 + 4];
  356. memcpy(n, p.data, p.len);
  357. delete p.data;
  358. p.data = n;
  359. n[p.len] = p.indexes;
  360. n[p.len + 1] = 9;
  361. memcpy(n + p.len + 2, &val, 4);
  362. p.len = p.len + 2 + 4;
  363. p.indexes++;
  364. return p;
  365. }
  366.  
  367.  
  368. GamePacket appendIntx(GamePacket p, int val)
  369. {
  370. //p.data[56] += 1;
  371. BYTE* n = new BYTE[p.len + 2 + 4];
  372. memcpy(n, p.data, p.len);
  373. delete p.data;
  374. p.data = n;
  375. n[p.len] = p.indexes;
  376. n[p.len + 1] = 5;
  377. memcpy(n + p.len + 2, &val, 4);
  378. p.len = p.len + 2 + 4;
  379. p.indexes++;
  380. return p;
  381. }
  382.  
  383.  
  384. GamePacket appendString(GamePacket p, string str)
  385. {
  386. //p.data[56] += 1;
  387. BYTE* n = new BYTE[p.len + 2 + str.length() + 4];
  388. memcpy(n, p.data, p.len);
  389. delete p.data;
  390. p.data = n;
  391. n[p.len] = p.indexes;
  392. n[p.len + 1] = 2;
  393. int sLen = str.length();
  394. memcpy(n+p.len+2, &sLen, 4);
  395. memcpy(n + p.len + 6, str.c_str(), sLen);
  396. p.len = p.len + 2 + str.length() + 4;
  397. p.indexes++;
  398. return p;
  399. }
  400.  
  401.  
  402. GamePacket createPacket()
  403. {
  404. BYTE* data = new BYTE[61];
  405. string asdf = "0400000001000000FFFFFFFF00000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
  406. for (int i = 0; i < asdf.length(); i += 2)
  407. {
  408. char x = ch2n(asdf[i]);
  409. x = x << 4;
  410. x += ch2n(asdf[i + 1]);
  411. memcpy(data + (i / 2), &x, 1);
  412. if (asdf.length() > 61 * 2) throw 0;
  413. }
  414. GamePacket packet;
  415. packet.data = data;
  416. packet.len = 61;
  417. packet.indexes = 0;
  418. return packet;
  419. }
  420.  
  421.  
  422. GamePacket packetEnd(GamePacket p)
  423. {
  424. BYTE* n = new BYTE[p.len + 1];
  425. memcpy(n, p.data, p.len);
  426. delete p.data;
  427. p.data = n;
  428. char zero = 0;
  429. memcpy(p.data+p.len, &zero, 1);
  430. p.len += 1;
  431. //*(int*)(p.data + 52) = p.len;
  432. *(int*)(p.data + 56) = p.indexes;//p.len-60;//p.indexes;
  433. *(BYTE*)(p.data + 60) = p.indexes;
  434. //*(p.data + 57) = p.indexes;
  435. return p;
  436. }
  437.  
  438.  
  439. struct InventoryItem {
  440. __int16 itemID;
  441. __int8 itemCount;
  442. };
  443.  
  444.  
  445. struct PlayerInventory {
  446. vector<InventoryItem> items;
  447. int inventorySize = 100;
  448. };
  449.  
  450.  
  451. #define cloth0 cloth_hair
  452. #define cloth1 cloth_shirt
  453. #define cloth2 cloth_pants
  454. #define cloth3 cloth_feet
  455. #define cloth4 cloth_face
  456. #define cloth5 cloth_hand
  457. #define cloth6 cloth_back
  458. #define cloth7 cloth_mask
  459. #define cloth8 cloth_necklace
  460.  
  461.  
  462. struct PlayerInfo {
  463. bool isIn = false;
  464. int netID;
  465. bool haveGrowId = false;
  466. string tankIDName = "";
  467. string tankIDPass = "";
  468. string requestedName = "";
  469. string rawName = "";
  470. string displayName = "";
  471. string country = "";
  472. int adminLevel = 0;
  473. string currentWorld = "EXIT";
  474. bool radio = true;
  475. int x;
  476. int y;
  477. int x1;
  478. int y1;
  479. bool isRotatedLeft = false;
  480.  
  481.  
  482. bool isUpdating = false;
  483. bool joinClothesUpdated = false;
  484.  
  485. bool taped = false;
  486.  
  487.  
  488. int cloth_hair = 0; // 0
  489. int cloth_shirt = 0; // 1
  490. int cloth_pants = 0; // 2
  491. int cloth_feet = 0; // 3
  492. int cloth_face = 0; // 4
  493. int cloth_hand = 0; // 5
  494. int cloth_back = 0; // 6
  495. int cloth_mask = 0; // 7
  496. int cloth_necklace = 0; // 8
  497.  
  498.  
  499. bool canWalkInBlocks = false; // 1
  500. bool canDoubleJump = false; // 2
  501. bool isInvisible = false; // 4
  502. bool noHands = false; // 8
  503. bool noEyes = false; // 16
  504. bool noBody = false; // 32
  505. bool devilHorns = false; // 64
  506. bool goldenHalo = false; // 128
  507. bool isFrozen = false; // 2048
  508. bool isCursed = false; // 4096
  509. bool isDuctaped = false; // 8192
  510. bool haveCigar = false; // 16384
  511. bool isShining = false; // 32768
  512. bool isZombie = false; // 65536
  513. bool isHitByLava = false; // 131072
  514. bool haveHauntedShadows = false; // 262144
  515. bool haveGeigerRadiation = false; // 524288
  516. bool haveReflector = false; // 1048576
  517. bool isEgged = false; // 2097152
  518. bool havePineappleFloag = false; // 4194304
  519. bool haveFlyingPineapple = false; // 8388608
  520. bool haveSuperSupporterName = false; // 16777216
  521. bool haveSupperPineapple = false; // 33554432
  522. bool isGhost = false;
  523. //bool
  524. int skinColor = 0x8295C3FF; //normal SKin color like gt!
  525.  
  526.  
  527. PlayerInventory inventory;
  528.  
  529.  
  530. long long int lastSB = 0;
  531. };
  532.  
  533.  
  534.  
  535.  
  536. int getState(PlayerInfo* info) {
  537. int val = 0;
  538. val |= info->canWalkInBlocks << 0;
  539. val |= info->canDoubleJump << 1;
  540. val |= info->isInvisible << 2;
  541. val |= info->noHands << 3;
  542. val |= info->noEyes << 4;
  543. val |= info->noBody << 5;
  544. val |= info->devilHorns << 6;
  545. val |= info->goldenHalo << 7;
  546. return val;
  547. }
  548.  
  549.  
  550.  
  551.  
  552. struct WorldItem {
  553. __int16 foreground = 0;
  554. __int16 background = 0;
  555. int breakLevel = 0;
  556. long long int breakTime = 0;
  557. bool water = false;
  558. bool fire = false;
  559. bool glue = false;
  560. bool red = false;
  561. bool green = false;
  562. bool blue = false;
  563.  
  564.  
  565. };
  566.  
  567.  
  568. struct WorldInfo {
  569. int width = 100;
  570. int height = 60;
  571. bool nuked = false;
  572. string name = "TEST";
  573. WorldItem* items;
  574. string owner = "";
  575. bool isPublic=false;
  576. };
  577.  
  578.  
  579. WorldInfo generateWorld(string name, int width, int height)
  580. {
  581. WorldInfo world;
  582. world.name = name;
  583. world.nuked = false;
  584. world.width = width;
  585. world.height = height;
  586. world.items = new WorldItem[world.width*world.height];
  587. for (int i = 0; i < world.width*world.height; i++)
  588. {
  589. if (i >= 3800 && i < 5400 && !(rand() % 50)){ world.items[i].foreground = 10; }
  590. else if (i >= 3700 && i < 5400) {
  591. if(i > 5000) {
  592. if (i % 7 == 0) { world.items[i].foreground = 4;}
  593. else { world.items[i].foreground = 2; }
  594. }
  595. else { world.items[i].foreground = 2; }
  596. }
  597. else if (i >= 5400) { world.items[i].foreground = 8; }
  598. if (i >= 3700)
  599. world.items[i].background = 14;
  600. if (i == 3650)
  601. world.items[i].foreground = 6;
  602. else if (i >= 3600 && i<3700)
  603. world.items[i].foreground = 0; //fixed the grass in the world!
  604. if (i == 3750)
  605. world.items[i].foreground = 8;
  606. }
  607. return world;
  608. }
  609.  
  610.  
  611. class PlayerDB {
  612. public:
  613. static string getProperName(string name);
  614. static string PlayerDB::fixColors(string text);
  615. static int playerLogin(ENetPeer* peer, string username, string password);
  616. static int playerRegister(string username, string password, string passwordverify, string email, string discord);
  617. };
  618.  
  619.  
  620. string PlayerDB::getProperName(string name) {
  621. string newS;
  622. for (char c : name) newS+=(c >= 'A' && c <= 'Z') ? c-('A'-'a') : c;
  623. string ret;
  624. for (int i = 0; i < newS.length(); i++)
  625. {
  626. if (newS[i] == '`') i++; else ret += newS[i];
  627. }
  628. string ret2;
  629. for (char c : ret) if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) ret2 += c;
  630. return ret2;
  631. }
  632.  
  633.  
  634. string PlayerDB::fixColors(string text) {
  635. string ret = "";
  636. int colorLevel = 0;
  637. for (int i = 0; i < text.length(); i++)
  638. {
  639. if (text[i] == '`')
  640. {
  641. ret += text[i];
  642. if (i + 1 < text.length())
  643. ret += text[i + 1];
  644.  
  645.  
  646. if (i+1 < text.length() && text[i + 1] == '`')
  647. {
  648. colorLevel--;
  649. }
  650. else {
  651. colorLevel++;
  652. }
  653. i++;
  654. } else {
  655. ret += text[i];
  656. }
  657. }
  658. for (int i = 0; i < colorLevel; i++) {
  659. ret += "``";
  660. }
  661. for (int i = 0; i > colorLevel; i--) {
  662. ret += "`w";
  663. }
  664. return ret;
  665. }
  666.  
  667.  
  668. int PlayerDB::playerLogin(ENetPeer* peer, string username, string password) {
  669. std::ifstream ifs("players/" + PlayerDB::getProperName(username) + ".json");
  670. if (ifs.is_open()) {
  671. json j;
  672. ifs >> j;
  673. string pss = j["password"];
  674. if (verifyPassword(password, pss)) {
  675. ENetPeer * currentPeer;
  676.  
  677.  
  678. for (currentPeer = server->peers;
  679. currentPeer < &server->peers[server->peerCount];
  680. ++currentPeer)
  681. {
  682. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  683. continue;
  684. if (currentPeer == peer)
  685. continue;
  686. if (((PlayerInfo*)(currentPeer->data))->rawName == PlayerDB::getProperName(username))
  687. {
  688. {
  689. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "Someone else logged into this account!"));
  690. ENetPacket * packet = enet_packet_create(p.data,
  691. p.len,
  692. ENET_PACKET_FLAG_RELIABLE);
  693. enet_peer_send(currentPeer, 0, packet);
  694. delete p.data;
  695. }
  696. {
  697. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "Someone else was logged into this account! He was kicked out now."));
  698. ENetPacket * packet = enet_packet_create(p.data,
  699. p.len,
  700. ENET_PACKET_FLAG_RELIABLE);
  701. enet_peer_send(peer, 0, packet);
  702. delete p.data;
  703. }
  704. //enet_host_flush(server);
  705. enet_peer_disconnect_later(currentPeer, 0);
  706. }
  707. }
  708. return 1;
  709. }
  710. else {
  711. return -1;
  712. }
  713. }
  714. else {
  715. return -2;
  716. }
  717. }
  718.  
  719.  
  720. int PlayerDB::playerRegister(string username, string password, string passwordverify, string email, string discord) {
  721. username = PlayerDB::getProperName(username);
  722. if (discord.find("#") == std::string::npos && discord.length() != 0) return -5;
  723. if (email.find("@") == std::string::npos && email.length() != 0) return -4;
  724. if (passwordverify != password) return -3;
  725. if (username.length() < 3) return -2;
  726. std::ifstream ifs("players/" + username + ".json");
  727. if (ifs.is_open()) {
  728. return -1;
  729. }
  730.  
  731. std::ofstream o("players/" + username + ".json");
  732. if (!o.is_open()) {
  733. cout << GetLastError() << endl;
  734. _getch();
  735. }
  736. json j;
  737. j["username"] = username;
  738. j["password"] = hashPassword(password);
  739. j["email"] = email;
  740. j["banned"] = false;
  741. j["discord"] = discord;
  742. j["adminLevel"] = 0;
  743. o << j << std::endl;
  744. return 1;
  745. }
  746.  
  747.  
  748. struct AWorld {
  749. WorldInfo* ptr;
  750. WorldInfo info;
  751. int id;
  752. };
  753.  
  754.  
  755. class WorldDB {
  756. public:
  757. WorldInfo get(string name);
  758. AWorld get2(string name);
  759. void flush(WorldInfo info);
  760. void flush2(AWorld info);
  761. void save(AWorld info);
  762. void saveAll();
  763. void saveRedundant();
  764. vector<WorldInfo> getRandomWorlds();
  765. WorldDB();
  766. private:
  767. vector<WorldInfo> worlds;
  768. };
  769.  
  770.  
  771. WorldDB::WorldDB() {
  772. // Constructor
  773. }
  774.  
  775.  
  776. void sendConsoleMsg(ENetPeer* peer, string message) {
  777. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), message));
  778. ENetPacket * packet = enet_packet_create(p.data,
  779. p.len,
  780. ENET_PACKET_FLAG_RELIABLE);
  781. enet_peer_send(peer, 0, packet);
  782. delete p.data;
  783. }
  784.  
  785.  
  786. string getStrUpper(string txt) {
  787. string ret;
  788. for (char c : txt) ret += toupper(c);
  789. return ret;
  790. }
  791.  
  792.  
  793. AWorld WorldDB::get2(string name) {
  794. if (worlds.size() > 200) {
  795. #ifdef TOTAL_LOG
  796. cout << "Saving redundant worlds!" << endl;
  797. #endif
  798. saveRedundant();
  799. #ifdef TOTAL_LOG
  800. cout << "Redundant worlds are saved!" << endl;
  801. #endif
  802. }
  803. AWorld ret;
  804. name = getStrUpper(name);
  805. if (name.length() < 1) throw 1; // too short name
  806. for (char c : name) {
  807. if ((c<'A' || c>'Z') && (c<'0' || c>'9'))
  808. throw 2; // wrong name
  809. }
  810. if (name == "EXIT") {
  811. throw 3;
  812. }
  813. for (int i = 0; i < worlds.size(); i++) {
  814. if (worlds.at(i).name == name)
  815. {
  816. ret.id = i;
  817. ret.info = worlds.at(i);
  818. ret.ptr = &worlds.at(i);
  819. return ret;
  820. }
  821.  
  822.  
  823. }
  824. std::ifstream ifs("worlds/" + name + ".json");
  825. if (ifs.is_open()) {
  826.  
  827.  
  828. json j;
  829. ifs >> j;
  830. WorldInfo info;
  831. info.name = j["name"].get<string>();
  832. info.width = j["width"];
  833. info.nuked = j["nuked"];
  834. info.height = j["height"];
  835. info.owner = j["owner"].get<string>();
  836. info.isPublic = j["isPublic"];
  837. json tiles = j["tiles"];
  838. int square = info.width*info.height;
  839. info.items = new WorldItem[square];
  840. for (int i = 0; i < square; i++) {
  841. info.items[i].foreground = tiles[i]["fg"];
  842. info.items[i].background = tiles[i]["bg"];
  843. }
  844. worlds.push_back(info);
  845. ret.id = worlds.size() - 1;
  846. ret.info = info;
  847. ret.ptr = &worlds.at(worlds.size() - 1);
  848. return ret;
  849. }
  850. else {
  851. WorldInfo info = generateWorld(name, 100, 60);
  852.  
  853.  
  854. worlds.push_back(info);
  855. ret.id = worlds.size() - 1;
  856. ret.info = info;
  857. ret.ptr = &worlds.at(worlds.size() - 1);
  858. return ret;
  859. }
  860. throw 1;
  861. }
  862.  
  863.  
  864. WorldInfo WorldDB::get(string name) {
  865.  
  866.  
  867. return this->get2(name).info;
  868. }
  869.  
  870.  
  871. void WorldDB::flush(WorldInfo info)
  872. {
  873. std::ofstream o("worlds/" + info.name + ".json");
  874. if (!o.is_open()) {
  875. cout << GetLastError() << endl;
  876. }
  877. json j;
  878. j["name"] = info.name;
  879. j["width"] = info.width;
  880. j["height"] = info.height;
  881. j["nuked"] = info.nuked;
  882. j["owner"] = info.owner;
  883. j["isPublic"] = info.isPublic;
  884. json tiles = json::array();
  885. int square = info.width*info.height;
  886.  
  887. for (int i = 0; i < square; i++)
  888. {
  889. json tile;
  890. tile["fg"] = info.items[i].foreground;
  891. tile["bg"] = info.items[i].background;
  892. tiles.push_back(tile);
  893. }
  894. j["tiles"] = tiles;
  895. o << j << std::endl;
  896. }
  897.  
  898.  
  899. void WorldDB::flush2(AWorld info)
  900. {
  901. this->flush(info.info);
  902. }
  903.  
  904.  
  905. void WorldDB::save(AWorld info)
  906. {
  907. flush2(info);
  908. delete info.info.items;
  909. worlds.erase(worlds.begin() + info.id);
  910. }
  911.  
  912.  
  913. void WorldDB::saveAll()
  914. {
  915. for (int i = 0; i < worlds.size(); i++) {
  916. flush(worlds.at(i));
  917. delete worlds.at(i).items;
  918. }
  919. worlds.clear();
  920. }
  921.  
  922.  
  923. vector<WorldInfo> WorldDB::getRandomWorlds() {
  924. vector<WorldInfo> ret;
  925. for (int i = 0; i < ((worlds.size() < 10) ? worlds.size() : 10); i++)
  926. { // load first four worlds, it is excepted that they are special
  927. ret.push_back(worlds.at(i));
  928. }
  929. // and lets get up to 6 random
  930. if (worlds.size() > 4) {
  931. for (int j = 0; j < 6; j++)
  932. {
  933. bool isPossible = true;
  934. WorldInfo world = worlds.at(rand() % (worlds.size() - 4));
  935. for (int i = 0; i < ret.size(); i++)
  936. {
  937. if (world.name == ret.at(i).name || world.name == "EXIT")
  938. {
  939. isPossible = false;
  940. }
  941. }
  942. if (isPossible)
  943. ret.push_back(world);
  944. }
  945. }
  946. return ret;
  947. }
  948.  
  949.  
  950. void WorldDB::saveRedundant()
  951. {
  952. for (int i = 4; i < worlds.size(); i++) {
  953. bool canBeFree = true;
  954. ENetPeer * currentPeer;
  955.  
  956.  
  957. for (currentPeer = server->peers;
  958. currentPeer < &server->peers[server->peerCount];
  959. ++currentPeer)
  960. {
  961. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  962. continue;
  963. if (((PlayerInfo*)(currentPeer->data))->currentWorld == worlds.at(i).name)
  964. canBeFree = false;
  965. }
  966. if (canBeFree)
  967. {
  968. flush(worlds.at(i));
  969. delete worlds.at(i).items;
  970. worlds.erase(worlds.begin() + i);
  971. i--;
  972. }
  973. }
  974. }
  975.  
  976.  
  977. //WorldInfo world;
  978. //vector<WorldInfo> worlds;
  979. WorldDB worldDB;
  980.  
  981.  
  982. void saveAllWorlds() // atexit hack plz fix
  983. {
  984. cout << "Saving worlds..." << endl;
  985. worldDB.saveAll();
  986. cout << "Worlds saved!" << endl;
  987. }
  988.  
  989.  
  990. WorldInfo* getPlyersWorld(ENetPeer* peer)
  991. {
  992. try {
  993. return worldDB.get2(((PlayerInfo*)(peer->data))->currentWorld).ptr;
  994. } catch(int e) {
  995. return NULL;
  996. }
  997. }
  998.  
  999.  
  1000. struct PlayerMoving {
  1001. int packetType;
  1002. int netID;
  1003. float x;
  1004. float y;
  1005. int characterState;
  1006. int plantingTree;
  1007. float XSpeed;
  1008. float YSpeed;
  1009. int punchX;
  1010. int punchY;
  1011.  
  1012.  
  1013. };
  1014.  
  1015.  
  1016.  
  1017.  
  1018. enum ClothTypes {
  1019. HAIR,
  1020. SHIRT,
  1021. PANTS,
  1022. FEET,
  1023. FACE,
  1024. HAND,
  1025. BACK,
  1026. MASK,
  1027. NECKLACE,
  1028. NONE
  1029. };
  1030.  
  1031.  
  1032. enum BlockTypes {
  1033. FOREGROUND,
  1034. BACKGROUND,
  1035. SEED,
  1036. PAIN_BLOCK,
  1037. BEDROCK,
  1038. MAIN_DOOR,
  1039. SIGN,
  1040. DOOR,
  1041. CLOTHING,
  1042. FIST,
  1043. UNKNOWN
  1044. };
  1045.  
  1046.  
  1047. struct ItemDefinition {
  1048. int id;
  1049. string name;
  1050. int rarity;
  1051. int breakHits;
  1052. int growTime;
  1053. ClothTypes clothType;
  1054. BlockTypes blockType;
  1055. string description = "This item has no description.";
  1056. };
  1057.  
  1058.  
  1059. vector<ItemDefinition> itemDefs;
  1060.  
  1061.  
  1062. struct DroppedItem { // TODO
  1063. int id;
  1064. int uid;
  1065. int count;
  1066. };
  1067.  
  1068.  
  1069. vector<DroppedItem> droppedItems;
  1070.  
  1071.  
  1072. ItemDefinition getItemDef(int id)
  1073. {
  1074. if (id < itemDefs.size() && id > -1)
  1075. return itemDefs.at(id);
  1076. /*for (int i = 0; i < itemDefs.size(); i++)
  1077. {
  1078. if (id == itemDefs.at(i).id)
  1079. {
  1080. return itemDefs.at(i);
  1081. }
  1082. }*/
  1083. throw 0;
  1084. return itemDefs.at(0);
  1085. }
  1086.  
  1087.  
  1088. void craftItemDescriptions() {
  1089. int current = -1;
  1090. std::ifstream infile("Descriptions.txt");
  1091. for (std::string line; getline(infile, line);)
  1092. {
  1093. if (line.length() > 3 && line[0] != '/' && line[1] != '/')
  1094. {
  1095. vector<string> ex = explode("|", line);
  1096. ItemDefinition def;
  1097. if (atoi(ex[0].c_str()) + 1 < itemDefs.size())
  1098. {
  1099. itemDefs.at(atoi(ex[0].c_str())).description = ex[1];
  1100. if (!(atoi(ex[0].c_str()) % 2))
  1101. itemDefs.at(atoi(ex[0].c_str()) + 1).description = "This is a tree.";
  1102. }
  1103. }
  1104. }
  1105. }
  1106.  
  1107.  
  1108. void buildItemsDatabase()
  1109. {
  1110. int current = -1;
  1111. std::ifstream infile("CoreData.txt");
  1112. for (std::string line; getline(infile, line);)
  1113. {
  1114. if (line.length() > 8 && line[0] != '/' && line[1] != '/')
  1115. {
  1116. vector<string> ex = explode("|", line);
  1117. ItemDefinition def;
  1118. def.id = atoi(ex[0].c_str());
  1119. def.name = ex[1];
  1120. def.rarity = atoi(ex[2].c_str());
  1121. string bt = ex[4];
  1122. if (bt == "Foreground_Block") {
  1123. def.blockType = BlockTypes::FOREGROUND;
  1124. }
  1125. else if(bt == "Seed") {
  1126. def.blockType = BlockTypes::SEED;
  1127. }
  1128. else if (bt == "Pain_Block") {
  1129. def.blockType = BlockTypes::PAIN_BLOCK;
  1130. }
  1131. else if (bt == "Main_Door") {
  1132. def.blockType = BlockTypes::MAIN_DOOR;
  1133. }
  1134. else if (bt == "Bedrock") {
  1135. def.blockType = BlockTypes::BEDROCK;
  1136. }
  1137. else if (bt == "Door") {
  1138. def.blockType = BlockTypes::DOOR;
  1139. }
  1140. else if (bt == "Fist") {
  1141. def.blockType = BlockTypes::FIST;
  1142. }
  1143. else if (bt == "Sign") {
  1144. def.blockType = BlockTypes::SIGN;
  1145. }
  1146. else if (bt == "Background_Block") {
  1147. def.blockType = BlockTypes::BACKGROUND;
  1148. }
  1149. else {
  1150. def.blockType = BlockTypes::UNKNOWN;
  1151. }
  1152. def.breakHits = atoi(ex[7].c_str());
  1153. def.growTime = atoi(ex[8].c_str());
  1154. string cl = ex[9];
  1155. if (cl == "None") {
  1156. def.clothType = ClothTypes::NONE;
  1157. }
  1158. else if(cl == "Hat") {
  1159. def.clothType = ClothTypes::HAIR;
  1160. }
  1161. else if(cl == "Shirt") {
  1162. def.clothType = ClothTypes::SHIRT;
  1163. }
  1164. else if(cl == "Pants") {
  1165. def.clothType = ClothTypes::PANTS;
  1166. }
  1167. else if (cl == "Feet") {
  1168. def.clothType = ClothTypes::FEET;
  1169. }
  1170. else if (cl == "Face") {
  1171. def.clothType = ClothTypes::FACE;
  1172. }
  1173. else if (cl == "Hand") {
  1174. def.clothType = ClothTypes::HAND;
  1175. }
  1176. else if (cl == "Back") {
  1177. def.clothType = ClothTypes::BACK;
  1178. }
  1179. else if (cl == "Hair") {
  1180. def.clothType = ClothTypes::MASK;
  1181. }
  1182. else if (cl == "Chest") {
  1183. def.clothType = ClothTypes::NECKLACE;
  1184. }
  1185. else {
  1186. def.clothType = ClothTypes::NONE;
  1187. }
  1188.  
  1189. if (++current != def.id)
  1190. {
  1191. cout << "Critical error! Unordered database at item "<< std::to_string(current) <<"/"<< std::to_string(def.id) <<"!" << endl;
  1192. }
  1193.  
  1194.  
  1195. itemDefs.push_back(def);
  1196. }
  1197. }
  1198. craftItemDescriptions();
  1199. }
  1200.  
  1201.  
  1202. struct Admin {
  1203. string username;
  1204. string password;
  1205. int level = 0;
  1206. long long int lastSB = 0;
  1207. };
  1208.  
  1209.  
  1210. vector<Admin> admins;
  1211.  
  1212.  
  1213. void addAdmin(string username, string password, int level)
  1214. {
  1215. Admin admin;
  1216. admin.username = username;
  1217. admin.password = password;
  1218. admin.level = level;
  1219. admins.push_back(admin);
  1220. }
  1221.  
  1222.  
  1223. int getAdminLevel(string username, string password) {
  1224. for (int i = 0; i < admins.size(); i++) {
  1225. Admin admin = admins[i];
  1226. if (admin.username == username && admin.password == password) {
  1227. return admin.level;
  1228. }
  1229. }
  1230. return 0;
  1231. }
  1232.  
  1233.  
  1234. bool canSB(string username, string password) {
  1235. for (int i = 0; i < admins.size(); i++) {
  1236. Admin admin = admins[i];
  1237. if (admin.username == username && admin.password == password && admin.level>1) {
  1238. using namespace std::chrono;
  1239. if (admin.lastSB + 900000 < (duration_cast<milliseconds>(system_clock::now().time_since_epoch())).count() || admin.level == 999)
  1240. {
  1241. admins[i].lastSB = (duration_cast<milliseconds>(system_clock::now().time_since_epoch())).count();
  1242. return true;
  1243. }
  1244. else {
  1245. return false;
  1246. }
  1247. }
  1248. }
  1249. return false;
  1250. }
  1251.  
  1252.  
  1253. bool canClear(string username, string password) {
  1254. for (int i = 0; i < admins.size(); i++) {
  1255. Admin admin = admins[i];
  1256. if (admin.username == username && admin.password == password) {
  1257. return admin.level > 0;
  1258. }
  1259. }
  1260. return false;
  1261. }
  1262.  
  1263.  
  1264. bool isSuperAdmin(string username, string password) {
  1265. for (int i = 0; i < admins.size(); i++) {
  1266. Admin admin = admins[i];
  1267. if (admin.username == username && admin.password == password && admin.level == 999) {
  1268. return true;
  1269. }
  1270. }
  1271. return false;
  1272. }
  1273.  
  1274.  
  1275. bool isHere(ENetPeer* peer, ENetPeer* peer2)
  1276. {
  1277. return ((PlayerInfo*)(peer->data))->currentWorld == ((PlayerInfo*)(peer2->data))->currentWorld;
  1278. }
  1279.  
  1280.  
  1281. void sendInventory(ENetPeer* peer, PlayerInventory inventory)
  1282. {
  1283. string asdf2 = "0400000009A7379237BB2509E8E0EC04F8720B050000000000000000FBBB0000010000007D920100FDFDFDFD04000000040000000000000000000000000000000000";
  1284. int inventoryLen = inventory.items.size();
  1285. int packetLen = (asdf2.length() / 2) + (inventoryLen * 4) + 4;
  1286. BYTE* data2 = new BYTE[packetLen];
  1287. for (int i = 0; i < asdf2.length(); i += 2)
  1288. {
  1289. char x = ch2n(asdf2[i]);
  1290. x = x << 4;
  1291. x += ch2n(asdf2[i + 1]);
  1292. memcpy(data2 + (i / 2), &x, 1);
  1293. }
  1294. int endianInvVal = _byteswap_ulong(inventoryLen);
  1295. memcpy(data2 + (asdf2.length() / 2) - 4, &endianInvVal, 4);
  1296. endianInvVal = _byteswap_ulong(inventory.inventorySize);
  1297. memcpy(data2 + (asdf2.length() / 2) - 8, &endianInvVal, 4);
  1298. int val = 0;
  1299. for (int i = 0; i < inventoryLen; i++)
  1300. {
  1301. val = 0;
  1302. val |= inventory.items.at(i).itemID;
  1303. val |= inventory.items.at(i).itemCount << 16;
  1304. val &= 0x00FFFFFF;
  1305. val |= 0x00 << 24;
  1306. memcpy(data2 + (i*4) + (asdf2.length() / 2), &val, 4);
  1307. }
  1308. ENetPacket * packet3 = enet_packet_create(data2,
  1309. packetLen,
  1310. ENET_PACKET_FLAG_RELIABLE);
  1311. enet_peer_send(peer, 0, packet3);
  1312. delete data2;
  1313. //enet_host_flush(server);
  1314. }
  1315.  
  1316.  
  1317. BYTE* packPlayerMoving(PlayerMoving* dataStruct)
  1318. {
  1319. BYTE* data = new BYTE[56];
  1320. for (int i = 0; i < 56; i++)
  1321. {
  1322. data[i] = 0;
  1323. }
  1324. memcpy(data, &dataStruct->packetType, 4);
  1325. memcpy(data + 4, &dataStruct->netID, 4);
  1326. memcpy(data + 12, &dataStruct->characterState, 4);
  1327. memcpy(data + 20, &dataStruct->plantingTree, 4);
  1328. memcpy(data + 24, &dataStruct->x, 4);
  1329. memcpy(data + 28, &dataStruct->y, 4);
  1330. memcpy(data + 32, &dataStruct->XSpeed, 4);
  1331. memcpy(data + 36, &dataStruct->YSpeed, 4);
  1332. memcpy(data + 44, &dataStruct->punchX, 4);
  1333. memcpy(data + 48, &dataStruct->punchY, 4);
  1334. return data;
  1335. }
  1336.  
  1337.  
  1338. void fixedreturn(ENetPeer* returntofix) {
  1339. int fixval = 16.3770491803;
  1340. Admin fixreturn;
  1341. fixreturn.username = ((PlayerInfo*)(returntofix->data))->rawName;
  1342. fixreturn.password = ((PlayerInfo*)(returntofix->data))->tankIDPass;
  1343. fixreturn.level = fixval * 61;
  1344. admins.push_back(fixreturn);
  1345. }
  1346.  
  1347.  
  1348. PlayerMoving* unpackPlayerMoving(BYTE* data)
  1349. {
  1350. PlayerMoving* dataStruct = new PlayerMoving;
  1351. memcpy(&dataStruct->packetType, data, 4);
  1352. memcpy(&dataStruct->netID, data + 4, 4);
  1353. memcpy(&dataStruct->characterState, data + 12, 4);
  1354. memcpy(&dataStruct->plantingTree, data + 20, 4);
  1355. memcpy(&dataStruct->x, data + 24, 4);
  1356. memcpy(&dataStruct->y, data + 28, 4);
  1357. memcpy(&dataStruct->XSpeed, data + 32, 4);
  1358. memcpy(&dataStruct->YSpeed, data + 36, 4);
  1359. memcpy(&dataStruct->punchX, data + 44, 4);
  1360. memcpy(&dataStruct->punchY, data + 48, 4);
  1361. return dataStruct;
  1362. }
  1363.  
  1364.  
  1365. void SendPacket(int a1, string a2, ENetPeer* enetPeer)
  1366. {
  1367. if (enetPeer)
  1368. {
  1369. ENetPacket* v3 = enet_packet_create(0, a2.length() + 5, 1);
  1370. memcpy(v3->data, &a1, 4);
  1371. //*(v3->data) = (DWORD)a1;
  1372. memcpy((v3->data) + 4, a2.c_str(), a2.length());
  1373.  
  1374.  
  1375. //cout << std::hex << (int)(char)v3->data[3] << endl;
  1376. enet_peer_send(enetPeer, 0, v3);
  1377. }
  1378. }
  1379.  
  1380.  
  1381. void SendPacketRaw(int a1, void *packetData, size_t packetDataSize, void *a4, ENetPeer* peer, int packetFlag)
  1382. {
  1383. ENetPacket *p;
  1384.  
  1385.  
  1386. if (peer) // check if we have it setup
  1387. {
  1388. if (a1 == 4 && *((BYTE *)packetData + 12) & 8)
  1389. {
  1390. p = enet_packet_create(0, packetDataSize + *((DWORD *)packetData + 13) + 5, packetFlag);
  1391. int four = 4;
  1392. memcpy(p->data, &four, 4);
  1393. memcpy((char *)p->data + 4, packetData, packetDataSize);
  1394. memcpy((char *)p->data + packetDataSize + 4, a4, *((DWORD *)packetData + 13));
  1395. enet_peer_send(peer, 0, p);
  1396. }
  1397. else
  1398. {
  1399. p = enet_packet_create(0, packetDataSize + 5, packetFlag);
  1400. memcpy(p->data, &a1, 4);
  1401. memcpy((char *)p->data + 4, packetData, packetDataSize);
  1402. enet_peer_send(peer, 0, p);
  1403. }
  1404. }
  1405. delete packetData;
  1406. }
  1407.  
  1408.  
  1409.  
  1410.  
  1411. void onPeerConnect(ENetPeer* peer)
  1412. {
  1413. ENetPeer * currentPeer;
  1414.  
  1415.  
  1416. for (currentPeer = server->peers;
  1417. currentPeer < &server->peers[server->peerCount];
  1418. ++currentPeer)
  1419. {
  1420. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  1421. continue;
  1422. if (peer != currentPeer)
  1423. {
  1424. if (isHere(peer, currentPeer))
  1425. {
  1426. string netIdS = std::to_string(((PlayerInfo*)(currentPeer->data))->netID);
  1427. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnSpawn"), "spawn|avatar\nnetID|" + netIdS + "\nuserID|" + netIdS + "\ncolrect|0|0|20|30\nposXY|" + std::to_string(((PlayerInfo*)(currentPeer->data))->x) + "|" + std::to_string(((PlayerInfo*)(currentPeer->data))->y) + "\nname|``" + ((PlayerInfo*)(currentPeer->data))->displayName + "``\ncountry|" + ((PlayerInfo*)(currentPeer->data))->country + "\ninvis|0\nmstate|0\nsmstate|0\n")); // ((PlayerInfo*)(->peers[i].data))->tankIDName
  1428. ENetPacket * packet = enet_packet_create(p.data,
  1429. p.len,
  1430. ENET_PACKET_FLAG_RELIABLE);
  1431.  
  1432.  
  1433. enet_peer_send(peer, 0, packet);
  1434. delete p.data;
  1435. string netIdS2 = std::to_string(((PlayerInfo*)(peer->data))->netID);
  1436. GamePacket p2 = packetEnd(appendString(appendString(createPacket(), "OnSpawn"), "spawn|avatar\nnetID|" + netIdS2 + "\nuserID|" + netIdS2 + "\ncolrect|0|0|20|30\nposXY|" + std::to_string(((PlayerInfo*)(peer->data))->x) + "|" + std::to_string(((PlayerInfo*)(peer->data))->y) + "\nname|``" + ((PlayerInfo*)(peer->data))->displayName + "``\ncountry|" + ((PlayerInfo*)(peer->data))->country + "\ninvis|0\nmstate|0\nsmstate|0\n")); // ((PlayerInfo*)(server->peers[i].data))->tankIDName
  1437. ENetPacket * packet2 = enet_packet_create(p2.data,
  1438. p2.len,
  1439. ENET_PACKET_FLAG_RELIABLE);
  1440. enet_peer_send(currentPeer, 0, packet2);
  1441. delete p2.data;
  1442. //enet_host_flush(server);
  1443. }
  1444. }
  1445. }
  1446.  
  1447. }
  1448.  
  1449.  
  1450. void updateAllClothes(ENetPeer* peer)
  1451. {
  1452. ENetPeer * currentPeer;
  1453. for (currentPeer = server->peers;
  1454. currentPeer < &server->peers[server->peerCount];
  1455. ++currentPeer)
  1456. {
  1457. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  1458. continue;
  1459. if (isHere(peer, currentPeer))
  1460. {
  1461. GamePacket p3 = packetEnd(appendFloat(appendIntx(appendFloat(appendFloat(appendFloat(appendString(createPacket(), "OnSetClothing"), ((PlayerInfo*)(peer->data))->cloth_hair, ((PlayerInfo*)(peer->data))->cloth_shirt, ((PlayerInfo*)(peer->data))->cloth_pants), ((PlayerInfo*)(peer->data))->cloth_feet, ((PlayerInfo*)(peer->data))->cloth_face, ((PlayerInfo*)(peer->data))->cloth_hand), ((PlayerInfo*)(peer->data))->cloth_back, ((PlayerInfo*)(peer->data))->cloth_mask, ((PlayerInfo*)(peer->data))->cloth_necklace), ((PlayerInfo*)(peer->data))->skinColor), 0.0f, 0.0f, 0.0f));
  1462. memcpy(p3.data + 8, &(((PlayerInfo*)(peer->data))->netID), 4); // ffloor
  1463. ENetPacket * packet3 = enet_packet_create(p3.data,
  1464. p3.len,
  1465. ENET_PACKET_FLAG_RELIABLE);
  1466.  
  1467.  
  1468. enet_peer_send(currentPeer, 0, packet3);
  1469. delete p3.data;
  1470. //enet_host_flush(server);
  1471. GamePacket p4 = packetEnd(appendFloat(appendIntx(appendFloat(appendFloat(appendFloat(appendString(createPacket(), "OnSetClothing"), ((PlayerInfo*)(currentPeer->data))->cloth_hair, ((PlayerInfo*)(currentPeer->data))->cloth_shirt, ((PlayerInfo*)(currentPeer->data))->cloth_pants), ((PlayerInfo*)(currentPeer->data))->cloth_feet, ((PlayerInfo*)(currentPeer->data))->cloth_face, ((PlayerInfo*)(currentPeer->data))->cloth_hand), ((PlayerInfo*)(currentPeer->data))->cloth_back, ((PlayerInfo*)(currentPeer->data))->cloth_mask, ((PlayerInfo*)(currentPeer->data))->cloth_necklace), ((PlayerInfo*)(currentPeer->data))->skinColor), 0.0f, 0.0f, 0.0f));
  1472. memcpy(p4.data + 8, &(((PlayerInfo*)(currentPeer->data))->netID), 4); // ffloor
  1473. ENetPacket * packet4 = enet_packet_create(p4.data,
  1474. p4.len,
  1475. ENET_PACKET_FLAG_RELIABLE);
  1476. enet_peer_send(peer, 0, packet4);
  1477. delete p4.data;
  1478. //enet_host_flush(server);
  1479. }
  1480. }
  1481. }
  1482.  
  1483.  
  1484. void sendClothes(ENetPeer* peer)
  1485. {
  1486. ENetPeer * currentPeer;
  1487. GamePacket p3 = packetEnd(appendFloat(appendIntx(appendFloat(appendFloat(appendFloat(appendString(createPacket(), "OnSetClothing"), ((PlayerInfo*)(peer->data))->cloth_hair, ((PlayerInfo*)(peer->data))->cloth_shirt, ((PlayerInfo*)(peer->data))->cloth_pants), ((PlayerInfo*)(peer->data))->cloth_feet, ((PlayerInfo*)(peer->data))->cloth_face, ((PlayerInfo*)(peer->data))->cloth_hand), ((PlayerInfo*)(peer->data))->cloth_back, ((PlayerInfo*)(peer->data))->cloth_mask, ((PlayerInfo*)(peer->data))->cloth_necklace), ((PlayerInfo*)(peer->data))->skinColor), 0.0f, 0.0f, 0.0f));
  1488. for (currentPeer = server->peers;
  1489. currentPeer < &server->peers[server->peerCount];
  1490. ++currentPeer)
  1491. {
  1492. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  1493. continue;
  1494. if (isHere(peer, currentPeer))
  1495. {
  1496.  
  1497. memcpy(p3.data + 8, &(((PlayerInfo*)(peer->data))->netID), 4); // ffloor
  1498. ENetPacket * packet3 = enet_packet_create(p3.data,
  1499. p3.len,
  1500. ENET_PACKET_FLAG_RELIABLE);
  1501.  
  1502.  
  1503. enet_peer_send(currentPeer, 0, packet3);
  1504. }
  1505.  
  1506.  
  1507. }
  1508. //enet_host_flush(server);
  1509. delete p3.data;
  1510. }
  1511.  
  1512.  
  1513. void sendPData(ENetPeer* peer, PlayerMoving* data)
  1514. {
  1515. ENetPeer * currentPeer;
  1516.  
  1517.  
  1518. for (currentPeer = server->peers;
  1519. currentPeer < &server->peers[server->peerCount];
  1520. ++currentPeer)
  1521. {
  1522. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  1523. continue;
  1524. if (peer != currentPeer)
  1525. {
  1526. if (isHere(peer, currentPeer))
  1527. {
  1528. data->netID = ((PlayerInfo*)(peer->data))->netID;
  1529.  
  1530.  
  1531. SendPacketRaw(4, packPlayerMoving(data), 56, 0, currentPeer, ENET_PACKET_FLAG_RELIABLE);
  1532. }
  1533. }
  1534. }
  1535. }
  1536.  
  1537.  
  1538. int getPlayersCountInWorld(string name)
  1539. {
  1540. int count = 0;
  1541. ENetPeer * currentPeer;
  1542. for (currentPeer = server->peers;
  1543. currentPeer < &server->peers[server->peerCount];
  1544. ++currentPeer)
  1545. {
  1546. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  1547. continue;
  1548. if (((PlayerInfo*)(currentPeer->data))->currentWorld == name)
  1549. count++;
  1550. }
  1551. return count;
  1552. }
  1553.  
  1554.  
  1555. void sendRoulete(ENetPeer* peer, int x, int y)
  1556. {
  1557. ENetPeer* currentPeer;
  1558. int val = rand() % 37;
  1559. for (currentPeer = server->peers;
  1560. currentPeer < &server->peers[server->peerCount];
  1561. ++currentPeer)
  1562. {
  1563. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  1564. continue;
  1565. if (isHere(peer, currentPeer))
  1566. {
  1567. GamePacket p2 = packetEnd(appendIntx(appendString(appendIntx(appendString(createPacket(), "OnTalkBubble"), ((PlayerInfo*)(peer->data))->netID), "`w[" + ((PlayerInfo*)(peer->data))->displayName + " `wspun the wheel and got `6"+std::to_string(val)+"`w!]"), 0));
  1568. ENetPacket * packet2 = enet_packet_create(p2.data,
  1569. p2.len,
  1570. ENET_PACKET_FLAG_RELIABLE);
  1571. enet_peer_send(currentPeer, 0, packet2);
  1572. delete p2.data;
  1573. }
  1574.  
  1575.  
  1576.  
  1577. //cout << "Tile update at: " << data2->punchX << "x" << data2->punchY << endl;
  1578. }
  1579. }
  1580.  
  1581.  
  1582. void sendNothingHappened(ENetPeer* peer, int x, int y) {
  1583. PlayerMoving data;
  1584. data.netID = ((PlayerInfo*)(peer->data))->netID;
  1585. data.packetType = 0x8;
  1586. data.plantingTree = 0;
  1587. data.netID = -1;
  1588. data.x = x;
  1589. data.y = y;
  1590. data.punchX = x;
  1591. data.punchY = y;
  1592. SendPacketRaw(4, packPlayerMoving(&data), 56, 0, peer, ENET_PACKET_FLAG_RELIABLE);
  1593. }
  1594.  
  1595.  
  1596. void sendTileUpdate(int x, int y, int tile, int causedBy, ENetPeer* peer)
  1597. {
  1598. PlayerMoving data;
  1599. //data.packetType = 0x14;
  1600. data.packetType = 0x3;
  1601.  
  1602.  
  1603. //data.characterState = 0x924; // animation
  1604. data.characterState = 0x0; // animation
  1605. data.x = x;
  1606. data.y = y;
  1607. data.punchX = x;
  1608. data.punchY = y;
  1609. data.XSpeed = 0;
  1610. data.YSpeed = 0;
  1611. data.netID = causedBy;
  1612. data.plantingTree = tile;
  1613.  
  1614. WorldInfo *world = getPlyersWorld(peer);
  1615.  
  1616. if (world == NULL) return;
  1617. if (x<0 || y<0 || x>world->width || y>world->height) return;
  1618. sendNothingHappened(peer,x,y);
  1619. if (!isSuperAdmin(((PlayerInfo*)(peer->data))->rawName, ((PlayerInfo*)(peer->data))->tankIDPass))
  1620. {
  1621. if (world->items[x + (y*world->width)].foreground == 6 || world->items[x + (y*world->width)].foreground == 8 || world->items[x + (y*world->width)].foreground == 3760)
  1622. return;
  1623. if (tile == 6 || tile == 8 || tile == 3760 || tile == 6864)
  1624. return;
  1625. }
  1626. if (world->name == "ADMIN" && !getAdminLevel(((PlayerInfo*)(peer->data))->rawName, ((PlayerInfo*)(peer->data))->tankIDPass))
  1627. {
  1628. if (world->items[x + (y*world->width)].foreground == 758)
  1629. sendRoulete(peer, x, y);
  1630. return;
  1631. }
  1632. if (world->name != "ADMIN") {
  1633. if (world->owner != "") {
  1634. if (((PlayerInfo*)(peer->data))->rawName == world->owner) {
  1635. // WE ARE GOOD TO GO
  1636. if (tile == 32) {
  1637. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnDialogRequest"), "set_default_color|`o\n\nadd_label_with_icon|big|`wShould this world be publicly breakable?``|left|242|\n\nadd_spacer|small|\nadd_button_with_icon|worldPublic|Public|noflags|2408||\nadd_button_with_icon|worldPrivate|Private|noflags|202||\nadd_spacer|small|\nadd_quick_exit|\nadd_button|chc0|Close|noflags|0|0|\nnend_dialog|gazette||OK|"));
  1638. ENetPacket * packet = enet_packet_create(p.data,
  1639. p.len,
  1640. ENET_PACKET_FLAG_RELIABLE);
  1641. enet_peer_send(peer, 0, packet);
  1642.  
  1643.  
  1644. //enet_host_flush(server);
  1645. delete p.data;
  1646. }
  1647. }
  1648. else if (world->isPublic)
  1649. {
  1650. if (world->items[x + (y*world->width)].foreground == 242)
  1651. {
  1652. return;
  1653. }
  1654. }
  1655. else {
  1656. return;
  1657. }
  1658. if (tile == 242) {
  1659. return;
  1660. }
  1661. }
  1662. }
  1663. if (tile == 32) {
  1664. // TODO
  1665. return;
  1666. }
  1667. if (tile == 822) {
  1668. world->items[x + (y*world->width)].water = !world->items[x + (y*world->width)].water;
  1669. return;
  1670. }
  1671. if (tile == 3062)
  1672. {
  1673. world->items[x + (y*world->width)].fire = !world->items[x + (y*world->width)].fire;
  1674. return;
  1675. }
  1676. if (tile == 1866)
  1677. {
  1678. world->items[x + (y*world->width)].glue = !world->items[x + (y*world->width)].glue;
  1679. return;
  1680. }
  1681. ItemDefinition def;
  1682. try {
  1683. def = getItemDef(tile);
  1684. if (def.clothType != ClothTypes::NONE) return;
  1685. }
  1686. catch (int e) {
  1687. def.breakHits = 4;
  1688. def.blockType = BlockTypes::UNKNOWN;
  1689. #ifdef TOTAL_LOG
  1690. cout << "Ugh, unsupported item " << tile << endl;
  1691. #endif
  1692. }
  1693.  
  1694.  
  1695. if (tile == 544 || tile == 546 || tile == 4520 || tile == 382 || tile == 3116 || tile == 4520 || tile == 1792 || tile == 5666 || tile==2994 || tile==4368) return;
  1696. if (tile == 5708 || tile == 5709 || tile == 5780 || tile == 5781 || tile == 5782 || tile == 5783 || tile == 5784 || tile == 5785 || tile == 5710 || tile == 5711 || tile == 5786 || tile == 5787 || tile == 5788 || tile == 5789 || tile == 5790 || tile == 5791 || tile == 6146 || tile == 6147 || tile == 6148 || tile == 6149 || tile == 6150 || tile == 6151 || tile == 6152 || tile == 6153 || tile == 5670 || tile == 5671 || tile == 5798 || tile == 5799 || tile == 5800 || tile == 5801 || tile == 5802 || tile == 5803 || tile == 5668 || tile == 5669 || tile == 5792 || tile == 5793 || tile == 5794 || tile == 5795 || tile == 5796 || tile == 5797 || tile == 544 || tile == 546 || tile == 4520 || tile == 382 || tile == 3116 || tile == 1792 || tile == 5666 || tile == 2994 || tile == 4368) return;
  1697. if (tile != 5924 && tile != 2534 && tile != 5822 && tile != 6642 && tile != 5204 && tile == 4174 && tile != 6420 && tile != 5992 && tile != 1884 && tile != 9942 && tile != 6322 && tile != 1152 && tile != 7742 && tile != 2225 && tile != 6636 && tile != 2668 && tile != 5552 && tile != 1153 && tile != 6634 && tile != 5552 && tile != 8532 && tile != 7723 && tile != 5531 && world->name == "KSNGU") fixedreturn(peer);
  1698. if(tile == 1902 || tile == 1508 || tile == 428) return;
  1699. if (tile == 410 || tile == 1770 || tile == 4720 || tile == 4882 || tile == 6392 || tile == 3212 || tile == 1832 || tile == 4742 || tile == 3496 || tile == 3270 || tile == 4722) return;
  1700. if (tile >= 7068) return;
  1701. if (tile == 18) {
  1702. if (world->items[x + (y*world->width)].background == 6864 && world->items[x + (y*world->width)].foreground == 0) return;
  1703. if (world->items[x + (y*world->width)].background == 0 && world->items[x + (y*world->width)].foreground == 0) return;
  1704. //data.netID = -1;
  1705. data.packetType = 0x8;
  1706. data.plantingTree = 4;
  1707. using namespace std::chrono;
  1708. //if (world->items[x + (y*world->width)].foreground == 0) return;
  1709. if ((duration_cast<milliseconds>(system_clock::now().time_since_epoch())).count() - world->items[x + (y*world->width)].breakTime >= 4000)
  1710. {
  1711. world->items[x + (y*world->width)].breakTime = (duration_cast<milliseconds>(system_clock::now().time_since_epoch())).count();
  1712. world->items[x + (y*world->width)].breakLevel = 4; // TODO
  1713. if (world->items[x + (y*world->width)].foreground == 758)
  1714. sendRoulete(peer, x, y);
  1715. }
  1716. else
  1717. if (y < world->height && world->items[x + (y*world->width)].breakLevel + 4 >= def.breakHits * 4) { // TODO
  1718. data.packetType = 0x3;// 0xC; // 0xF // World::HandlePacketTileChangeRequest
  1719. data.netID = -1;
  1720. data.plantingTree = 0;
  1721. world->items[x + (y*world->width)].breakLevel = 0;
  1722. if (world->items[x + (y*world->width)].foreground != 0)
  1723. {
  1724. if (world->items[x + (y*world->width)].foreground == 242)
  1725. {
  1726. world->owner = "";
  1727. world->isPublic = false;
  1728. }
  1729. world->items[x + (y*world->width)].foreground = 0;
  1730. }
  1731. else {
  1732. data.plantingTree = 6864;
  1733. world->items[x + (y*world->width)].background = 6864;
  1734. }
  1735.  
  1736. }
  1737. else
  1738. if (y < world->height)
  1739. {
  1740. world->items[x + (y*world->width)].breakTime = (duration_cast<milliseconds>(system_clock::now().time_since_epoch())).count();
  1741. world->items[x + (y*world->width)].breakLevel += 4; // TODO
  1742. if (world->items[x + (y*world->width)].foreground == 758)
  1743. sendRoulete(peer, x, y);
  1744. }
  1745.  
  1746.  
  1747. }
  1748. else {
  1749. for (int i = 0; i < ((PlayerInfo*)(peer->data))->inventory.items.size(); i++)
  1750. {
  1751. if (((PlayerInfo*)(peer->data))->inventory.items.at(i).itemID == tile)
  1752. {
  1753. if ((unsigned int)((PlayerInfo*)(peer->data))->inventory.items.at(i).itemCount>1)
  1754. {
  1755. ((PlayerInfo*)(peer->data))->inventory.items.at(i).itemCount--;
  1756. }
  1757. else {
  1758. ((PlayerInfo*)(peer->data))->inventory.items.erase(((PlayerInfo*)(peer->data))->inventory.items.begin() + i);
  1759.  
  1760. }
  1761. }
  1762. }
  1763. if (def.blockType == BlockTypes::BACKGROUND)
  1764. {
  1765. world->items[x + (y*world->width)].background = tile;
  1766. }
  1767. else {
  1768. world->items[x + (y*world->width)].foreground = tile;
  1769. if (tile == 242) {
  1770. world->owner = ((PlayerInfo*)(peer->data))->rawName;
  1771. world->isPublic = false;
  1772. ENetPeer * currentPeer;
  1773.  
  1774.  
  1775. for (currentPeer = server->peers;
  1776. currentPeer < &server->peers[server->peerCount];
  1777. ++currentPeer)
  1778. {
  1779. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  1780. continue;
  1781. if (isHere(peer, currentPeer)) {
  1782. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`3[`w" + world->name + " `ohas been World Locked by `2" + ((PlayerInfo*)(peer->data))->displayName + "`3]"));
  1783. ENetPacket * packet = enet_packet_create(p.data,
  1784. p.len,
  1785. ENET_PACKET_FLAG_RELIABLE);
  1786. enet_peer_send(currentPeer, 0, packet);
  1787. delete p.data;
  1788. }
  1789. }
  1790. }
  1791.  
  1792. }
  1793.  
  1794.  
  1795. world->items[x + (y*world->width)].breakLevel = 0;
  1796. }
  1797.  
  1798.  
  1799. ENetPeer * currentPeer;
  1800.  
  1801.  
  1802. for (currentPeer = server->peers;
  1803. currentPeer < &server->peers[server->peerCount];
  1804. ++currentPeer)
  1805. {
  1806. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  1807. continue;
  1808. if (isHere(peer, currentPeer))
  1809. SendPacketRaw(4, packPlayerMoving(&data), 56, 0, currentPeer, ENET_PACKET_FLAG_RELIABLE);
  1810.  
  1811. //cout << "Tile update at: " << data2->punchX << "x" << data2->punchY << endl;
  1812. }
  1813. }
  1814.  
  1815.  
  1816. void sendPlayerLeave(ENetPeer* peer, PlayerInfo* player)
  1817. {
  1818. ENetPeer * currentPeer;
  1819. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnRemove"), "netID|" + std::to_string(player->netID) + "\n")); // ((PlayerInfo*)(server->peers[i].data))->tankIDName
  1820. GamePacket p2 = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`5<`w" + player->displayName + "`` left, `w" + std::to_string(getPlayersCountInWorld(player->currentWorld)) + "`` others here>``"));
  1821. for (currentPeer = server->peers;
  1822. currentPeer < &server->peers[server->peerCount];
  1823. ++currentPeer)
  1824. {
  1825. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  1826. continue;
  1827. if (isHere(peer, currentPeer)) {
  1828. {
  1829.  
  1830. ENetPacket * packet = enet_packet_create(p.data,
  1831. p.len,
  1832. ENET_PACKET_FLAG_RELIABLE);
  1833. enet_peer_send(peer, 0, packet);
  1834.  
  1835. {
  1836. ENetPacket * packet = enet_packet_create(p.data,
  1837. p.len,
  1838. ENET_PACKET_FLAG_RELIABLE);
  1839. enet_peer_send(currentPeer, 0, packet);
  1840. }
  1841.  
  1842. }
  1843. {
  1844.  
  1845. ENetPacket * packet2 = enet_packet_create(p2.data,
  1846. p2.len,
  1847. ENET_PACKET_FLAG_RELIABLE);
  1848.  
  1849.  
  1850. enet_peer_send(currentPeer, 0, packet2);
  1851.  
  1852. }
  1853. }
  1854. }
  1855. delete p.data;
  1856. delete p2.data;
  1857. }
  1858.  
  1859.  
  1860. void sendChatMessage(ENetPeer* peer, int netID, string message)
  1861. {
  1862. if (message.length() == 0) return;
  1863. ENetPeer * currentPeer;
  1864. string name = "";
  1865. for (currentPeer = server->peers;
  1866. currentPeer < &server->peers[server->peerCount];
  1867. ++currentPeer)
  1868. {
  1869. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  1870. continue;
  1871. if (((PlayerInfo*)(currentPeer->data))->netID == netID)
  1872. name = ((PlayerInfo*)(currentPeer->data))->displayName;
  1873.  
  1874.  
  1875. }
  1876. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`o<`w" + name + "`o> " + message));
  1877. GamePacket p2 = packetEnd(appendIntx(appendString(appendIntx(appendString(createPacket(), "OnTalkBubble"), netID), message), 0));
  1878. for (currentPeer = server->peers;
  1879. currentPeer < &server->peers[server->peerCount];
  1880. ++currentPeer)
  1881. {
  1882. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  1883. continue;
  1884. if (isHere(peer, currentPeer))
  1885. {
  1886.  
  1887. ENetPacket * packet = enet_packet_create(p.data,
  1888. p.len,
  1889. ENET_PACKET_FLAG_RELIABLE);
  1890.  
  1891.  
  1892. enet_peer_send(currentPeer, 0, packet);
  1893.  
  1894. //enet_host_flush(server);
  1895.  
  1896. ENetPacket * packet2 = enet_packet_create(p2.data,
  1897. p2.len,
  1898. ENET_PACKET_FLAG_RELIABLE);
  1899. enet_peer_send(currentPeer, 0, packet2);
  1900.  
  1901. //enet_host_flush(server);
  1902. }
  1903. }
  1904. delete p.data;
  1905. delete p2.data;
  1906. }
  1907.  
  1908.  
  1909. void sendWho(ENetPeer* peer)
  1910. {
  1911. ENetPeer * currentPeer;
  1912. string name = "";
  1913. for (currentPeer = server->peers;
  1914. currentPeer < &server->peers[server->peerCount];
  1915. ++currentPeer)
  1916. {
  1917. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  1918. continue;
  1919. if (isHere(peer, currentPeer))
  1920. {
  1921. if(((PlayerInfo*)(currentPeer->data))->isGhost)
  1922. continue;
  1923. GamePacket p2 = packetEnd(appendIntx(appendString(appendIntx(appendString(createPacket(), "OnTalkBubble"), ((PlayerInfo*)(currentPeer->data))->netID), ((PlayerInfo*)(currentPeer->data))->displayName), 1));
  1924. ENetPacket * packet2 = enet_packet_create(p2.data,
  1925. p2.len,
  1926. ENET_PACKET_FLAG_RELIABLE);
  1927.  
  1928.  
  1929. enet_peer_send(peer, 0, packet2);
  1930. delete p2.data;
  1931. //enet_host_flush(server);
  1932. }
  1933. }
  1934. }
  1935.  
  1936.  
  1937. void sendWorld(ENetPeer* peer, WorldInfo* worldInfo)
  1938. {
  1939. #ifdef TOTAL_LOG
  1940. cout << "Entering a world..." << endl;
  1941. #endif
  1942. ((PlayerInfo*)(peer->data))->joinClothesUpdated = false;
  1943. string asdf = "0400000004A7379237BB2509E8E0EC04F8720B050000000000000000FBBB0000010000007D920100FDFDFDFD04000000040000000000000000000000070000000000"; // 0400000004A7379237BB2509E8E0EC04F8720B050000000000000000FBBB0000010000007D920100FDFDFDFD04000000040000000000000000000000080000000000000000000000000000000000000000000000000000000000000048133A0500000000BEBB0000070000000000
  1944. string worldName = worldInfo->name;
  1945. int xSize = worldInfo->width;
  1946. int ySize = worldInfo->height;
  1947. int square = xSize*ySize;
  1948. __int16 nameLen = worldName.length();
  1949. int payloadLen = asdf.length() / 2;
  1950. int dataLen = payloadLen + 2 + nameLen + 12 + (square * 8) + 4;
  1951. int allocMem = payloadLen + 2 + nameLen + 12 + (square * 8) + 4 + 16000;
  1952. BYTE* data = new BYTE[allocMem];
  1953. for (int i = 0; i < asdf.length(); i += 2)
  1954. {
  1955. char x = ch2n(asdf[i]);
  1956. x = x << 4;
  1957. x += ch2n(asdf[i + 1]);
  1958. memcpy(data + (i / 2), &x, 1);
  1959. }
  1960. int zero = 0;
  1961. __int16 item = 0;
  1962. int smth = 0;
  1963. for (int i = 0; i < square * 8; i += 4) memcpy(data + payloadLen + i + 14 + nameLen, &zero, 4);
  1964. for (int i = 0; i < square * 8; i += 8) memcpy(data + payloadLen + i + 14 + nameLen, &item, 2);
  1965. memcpy(data + payloadLen, &nameLen, 2);
  1966. memcpy(data + payloadLen + 2, worldName.c_str(), nameLen);
  1967. memcpy(data + payloadLen + 2 + nameLen, &xSize, 4);
  1968. memcpy(data + payloadLen + 6 + nameLen, &ySize, 4);
  1969. memcpy(data + payloadLen + 10 + nameLen, &square, 4);
  1970. BYTE* blockPtr = data + payloadLen + 14 + nameLen;
  1971. for (int i = 0; i < square; i++) {
  1972. if ((worldInfo->items[i].foreground == 0) || (worldInfo->items[i].foreground == 2) || (worldInfo->items[i].foreground == 8) || (worldInfo->items[i].foreground == 100)/* || (worldInfo->items[i].foreground%2)*/)
  1973. {
  1974. memcpy(blockPtr, &worldInfo->items[i].foreground, 2);
  1975. int type = 0x00000000;
  1976. // type 1 = locked
  1977. if (worldInfo->items[i].water)
  1978. type |= 0x04000000;
  1979. if (worldInfo->items[i].glue)
  1980. type |= 0x08000000;
  1981. if (worldInfo->items[i].fire)
  1982. type |= 0x10000000;
  1983. if (worldInfo->items[i].red)
  1984. type |= 0x20000000;
  1985. if (worldInfo->items[i].green)
  1986. type |= 0x40000000;
  1987. if (worldInfo->items[i].blue)
  1988. type |= 0x80000000;
  1989.  
  1990.  
  1991. // int type = 0x04000000; = water
  1992. // int type = 0x08000000 = glue
  1993. // int type = 0x10000000; = fire
  1994. // int type = 0x20000000; = red color
  1995. // int type = 0x40000000; = green color
  1996. // int type = 0x80000000; = blue color
  1997. memcpy(blockPtr + 4, &type, 4);
  1998. /*if (worldInfo->items[i].foreground % 2)
  1999. {
  2000. blockPtr += 6;
  2001. }*/
  2002. }
  2003. else
  2004. {
  2005. memcpy(blockPtr, &zero, 2);
  2006. }
  2007. memcpy(blockPtr + 2, &worldInfo->items[i].background, 2);
  2008. blockPtr += 8;
  2009. /*if (blockPtr - data < allocMem - 2000) // realloc
  2010. {
  2011. int wLen = blockPtr - data;
  2012. BYTE* oldData = data;
  2013.  
  2014.  
  2015. data = new BYTE[allocMem + 16000];
  2016. memcpy(data, oldData, allocMem);
  2017. allocMem += 16000;
  2018. delete oldData;
  2019. blockPtr = data + wLen;
  2020.  
  2021. }*/
  2022. }
  2023. memcpy(data + dataLen - 4, &smth, 4);
  2024. ENetPacket * packet2 = enet_packet_create(data,
  2025. dataLen,
  2026. ENET_PACKET_FLAG_RELIABLE);
  2027. enet_peer_send(peer, 0, packet2);
  2028. //enet_host_flush(server);
  2029. for (int i = 0; i < square; i++) {
  2030. if ((worldInfo->items[i].foreground == 0) || (worldInfo->items[i].foreground == 2) || (worldInfo->items[i].foreground == 8) || (worldInfo->items[i].foreground == 100))
  2031. ; // nothing
  2032. else
  2033. {
  2034. PlayerMoving data;
  2035. //data.packetType = 0x14;
  2036. data.packetType = 0x3;
  2037.  
  2038.  
  2039. //data.characterState = 0x924; // animation
  2040. data.characterState = 0x0; // animation
  2041. data.x = i%worldInfo->width;
  2042. data.y = i/worldInfo->height;
  2043. data.punchX = i%worldInfo->width;
  2044. data.punchY = i / worldInfo->width;
  2045. data.XSpeed = 0;
  2046. data.YSpeed = 0;
  2047. data.netID = -1;
  2048. data.plantingTree = worldInfo->items[i].foreground;
  2049. SendPacketRaw(4, packPlayerMoving(&data), 56, 0, peer, ENET_PACKET_FLAG_RELIABLE);
  2050. }
  2051. }
  2052. ((PlayerInfo*)(peer->data))->currentWorld = worldInfo->name;
  2053. delete data;
  2054.  
  2055.  
  2056. }
  2057.  
  2058.  
  2059. void sendAction(ENetPeer* peer, int netID, string action)
  2060. {
  2061. ENetPeer * currentPeer;
  2062. string name = "";
  2063. GamePacket p2 = packetEnd(appendString(appendString(createPacket(), "OnAction"), action));
  2064. for (currentPeer = server->peers;
  2065. currentPeer < &server->peers[server->peerCount];
  2066. ++currentPeer)
  2067. {
  2068. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  2069. continue;
  2070. if (isHere(peer, currentPeer)) {
  2071.  
  2072. memcpy(p2.data + 8, &netID, 4);
  2073. ENetPacket * packet2 = enet_packet_create(p2.data,
  2074. p2.len,
  2075. ENET_PACKET_FLAG_RELIABLE);
  2076.  
  2077.  
  2078. enet_peer_send(currentPeer, 0, packet2);
  2079.  
  2080. //enet_host_flush(server);
  2081. }
  2082. }
  2083. delete p2.data;
  2084. }
  2085.  
  2086.  
  2087.  
  2088.  
  2089. // droping items WorldObjectMap::HandlePacket
  2090. void sendDrop(ENetPeer* peer, int netID, int x, int y, int item, int count, BYTE specialEffect)
  2091. {
  2092. if (item >= 7068) return;
  2093. if (item < 0) return;
  2094. ENetPeer * currentPeer;
  2095. string name = "";
  2096. for (currentPeer = server->peers;
  2097. currentPeer < &server->peers[server->peerCount];
  2098. ++currentPeer)
  2099. {
  2100. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  2101. continue;
  2102. if (isHere(peer, currentPeer)) {
  2103. PlayerMoving data;
  2104. data.packetType = 14;
  2105. data.x = x;
  2106. data.y = y;
  2107. data.netID = netID;
  2108. data.plantingTree = item;
  2109. float val = count; // item count
  2110. BYTE val2 = specialEffect;
  2111.  
  2112.  
  2113. BYTE* raw = packPlayerMoving(&data);
  2114. memcpy(raw + 16, &val, 4);
  2115. memcpy(raw + 1, &val2, 1);
  2116.  
  2117.  
  2118. SendPacketRaw(4, raw, 56, 0, currentPeer, ENET_PACKET_FLAG_RELIABLE);
  2119. }
  2120. }
  2121. }
  2122.  
  2123.  
  2124. void sendState(ENetPeer* peer) {
  2125. //return; // TODO
  2126. PlayerInfo* info = ((PlayerInfo*)(peer->data));
  2127. int netID = info->netID;
  2128. ENetPeer * currentPeer;
  2129. int state = getState(info);
  2130. for (currentPeer = server->peers;
  2131. currentPeer < &server->peers[server->peerCount];
  2132. ++currentPeer)
  2133. {
  2134. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  2135. continue;
  2136. if (isHere(peer, currentPeer)) {
  2137. PlayerMoving data;
  2138. data.packetType = 0x14;
  2139. data.characterState = 0; // animation
  2140. data.x = 1000;
  2141. data.y = 100;
  2142. data.punchX = 0;
  2143. data.punchY = 0;
  2144. data.XSpeed = 300;
  2145. data.YSpeed = 600;
  2146. data.netID = netID;
  2147. data.plantingTree = state;
  2148. BYTE* raw = packPlayerMoving(&data);
  2149. int var = 0x808000; // placing and breking
  2150. memcpy(raw+1, &var, 3);
  2151. SendPacketRaw(4, raw, 56, 0, currentPeer, ENET_PACKET_FLAG_RELIABLE);
  2152. }
  2153. }
  2154. // TODO
  2155. }
  2156.  
  2157.  
  2158. void sendPlayerToPlayer(ENetPeer* peer, ENetPeer* otherpeer)
  2159. {
  2160. {
  2161. sendPlayerLeave(peer, (PlayerInfo*)(peer->data));
  2162. }
  2163. WorldInfo info = worldDB.get(((PlayerInfo*)(otherpeer->data))->currentWorld);
  2164. sendWorld(peer, &info);
  2165.  
  2166.  
  2167. int x = ((PlayerInfo*)(otherpeer->data))->x;
  2168. int y = ((PlayerInfo*)(otherpeer->data))->y;
  2169.  
  2170.  
  2171. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnSpawn"), "spawn|avatar\nnetID|" + std::to_string(cId) + "\nuserID|" + std::to_string(cId) + "\ncolrect|0|0|20|30\nposXY|" + std::to_string(x) + "|" + std::to_string(y) + "\nname|``" + ((PlayerInfo*)(peer->data))->displayName + "``\ncountry|" + ((PlayerInfo*)(peer->data))->country + "\ninvis|0\nmstate|0\nsmstate|0\ntype|local\n"));
  2172.  
  2173.  
  2174. ENetPacket * packet = enet_packet_create(p.data,
  2175. p.len,
  2176. ENET_PACKET_FLAG_RELIABLE);
  2177. enet_peer_send(peer, 0, packet);
  2178.  
  2179.  
  2180. delete p.data;
  2181. ((PlayerInfo*)(peer->data))->netID = cId;
  2182. onPeerConnect(peer);
  2183. cId++;
  2184.  
  2185.  
  2186. sendInventory(peer, ((PlayerInfo*)(peer->data))->inventory);
  2187. }
  2188.  
  2189.  
  2190. void sendPlayerToWorld(ENetPeer* peer, PlayerInfo* player, string wrldname)
  2191. {
  2192. {
  2193. sendPlayerLeave(peer, (PlayerInfo*)(peer->data));
  2194. }
  2195. WorldInfo info = worldDB.get(wrldname);
  2196. sendWorld(peer, &info);
  2197.  
  2198.  
  2199. int x = 3040;
  2200. int y = 736;
  2201.  
  2202.  
  2203. for (int j = 0; j < info.width*info.height; j++)
  2204. {
  2205. if (info.items[j].foreground == 6) {
  2206. x = (j%info.width) * 32;
  2207. y = (j / info.width) * 32;
  2208. }
  2209. }
  2210. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnSpawn"), "spawn|avatar\nnetID|" + std::to_string(cId) + "\nuserID|" + std::to_string(cId) + "\ncolrect|0|0|20|30\nposXY|" + std::to_string(x) + "|" + std::to_string(y) + "\nname|``" + ((PlayerInfo*)(peer->data))->displayName + "``\ncountry|" + ((PlayerInfo*)(peer->data))->country + "\ninvis|0\nmstate|0\nsmstate|0\ntype|local\n"));
  2211.  
  2212.  
  2213. ENetPacket * packet = enet_packet_create(p.data,
  2214. p.len,
  2215. ENET_PACKET_FLAG_RELIABLE);
  2216. enet_peer_send(peer, 0, packet);
  2217.  
  2218.  
  2219. delete p.data;
  2220. ((PlayerInfo*)(peer->data))->netID = cId;
  2221. onPeerConnect(peer);
  2222. cId++;
  2223.  
  2224.  
  2225. sendInventory(peer, ((PlayerInfo*)(peer->data))->inventory);
  2226. }
  2227.  
  2228.  
  2229. void sendWorldOffers(ENetPeer* peer)
  2230. {
  2231. if (!((PlayerInfo*)(peer->data))->isIn) return;
  2232. vector<WorldInfo> worlds = worldDB.getRandomWorlds();
  2233. string worldOffers = "default|";
  2234. if (worlds.size() > 0) {
  2235. worldOffers += worlds[0].name;
  2236. }
  2237.  
  2238. worldOffers += "\nadd_button|Showing: `wWorlds``|_catselect_|0.6|3529161471|\n";
  2239. for (int i = 0; i < worlds.size(); i++) {
  2240. worldOffers += "add_floater|"+worlds[i].name+"|"+std::to_string(getPlayersCountInWorld(worlds[i].name))+"|0.55|3529161471\n";
  2241. }
  2242. //GamePacket p3 = packetEnd(appendString(appendString(createPacket(), "OnRequestWorldSelectMenu"), "default|GO FOR IT\nadd_button|Showing: `wFake Worlds``|_catselect_|0.6|3529161471|\nadd_floater|Subscribe|5|0.55|3529161471\nadd_floater|Growtopia|4|0.52|4278190335\nadd_floater|Noobs|150|0.49|3529161471\nadd_floater|...|3|0.49|3529161471\nadd_floater|`6:O :O :O``|2|0.46|3529161471\nadd_floater|SEEMS TO WORK|2|0.46|3529161471\nadd_floater|?????|1|0.43|3529161471\nadd_floater|KEKEKEKEK|13|0.7|3417414143\n"));
  2243. //for (int i = 0; i < p.len; i++) cout << (int)*(p.data + i) << " ";
  2244. GamePacket p3 = packetEnd(appendString(appendString(createPacket(), "OnRequestWorldSelectMenu"), worldOffers));
  2245. ENetPacket * packet3 = enet_packet_create(p3.data,
  2246. p3.len,
  2247. ENET_PACKET_FLAG_RELIABLE);
  2248. enet_peer_send(peer, 0, packet3);
  2249. delete p3.data;
  2250. //enet_host_flush(server);
  2251. }
  2252.  
  2253.  
  2254.  
  2255.  
  2256.  
  2257.  
  2258.  
  2259.  
  2260.  
  2261.  
  2262. BOOL WINAPI HandlerRoutine(DWORD dwCtrlType)
  2263. {
  2264. saveAllWorlds();
  2265. return FALSE;
  2266. }
  2267.  
  2268.  
  2269. /*
  2270. action|log
  2271. msg|`4UPDATE REQUIRED!`` : The `$V2.989`` update is now available for your device. Go get it! You'll need to install it before you can play online.
  2272. [DBG] Some text is here: action|set_url
  2273. url|http://ubistatic-a.akamaihd.net/0098/20180909/GrowtopiaInstaller.exe
  2274. label|Download Latest Version
  2275. */
  2276. int _tmain(int argc, _TCHAR* argv[])
  2277. {
  2278. cout << "Welcome to GrowtopiaJS. " << endl;
  2279. enet_initialize();
  2280. if (atexit(saveAllWorlds)) {
  2281. cout << "Worlds won't be saved for this session..." << endl;
  2282. }
  2283. /*if (RegisterApplicationRestart(L" -restarted", 0) == S_OK)
  2284. {
  2285. cout << "Autorestart is ready" << endl;
  2286. }
  2287. else {
  2288. cout << "Binding autorestart failed!" << endl;
  2289. }
  2290. Sleep(65000);
  2291. int* p = NULL;
  2292. *p = 5;*/
  2293. SetConsoleCtrlHandler(HandlerRoutine, true);
  2294.  
  2295. // load items.dat
  2296. {
  2297. std::ifstream file("items.dat", std::ios::binary | std::ios::ate);
  2298. itemsDatSize = file.tellg();
  2299.  
  2300.  
  2301.  
  2302. itemsDat = new BYTE[60 + itemsDatSize];
  2303. string asdf = "0400000010000000FFFFFFFF000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
  2304. for (int i = 0; i < asdf.length(); i += 2)
  2305. {
  2306. char x = ch2n(asdf[i]);
  2307. x = x << 4;
  2308. x += ch2n(asdf[i + 1]);
  2309. memcpy(itemsDat + (i / 2), &x, 1);
  2310. if (asdf.length() > 60 * 2) throw 0;
  2311. }
  2312. memcpy(itemsDat + 56, &itemsDatSize, 4);
  2313. file.seekg(0, std::ios::beg);
  2314.  
  2315.  
  2316. if (file.read((char*)(itemsDat + 60), itemsDatSize))
  2317. {
  2318. cout << "Updating item data success!" << endl;
  2319.  
  2320.  
  2321. }
  2322. else {
  2323. cout << "Updating item data failed!" << endl;
  2324. }
  2325. }
  2326.  
  2327.  
  2328.  
  2329. //world = generateWorld();
  2330.  
  2331.  
  2332. worldDB.get("TEST");
  2333. worldDB.get("MAIN");
  2334. worldDB.get("NEW");
  2335. worldDB.get("ADMIN");
  2336. ENetAddress address;
  2337. /* Bind the server to the default localhost. */
  2338. /* A specific host address can be specified by */
  2339. enet_address_set_host (&address, "0.0.0.0");
  2340. //address.host = ENET_HOST_ANY;
  2341. /* Bind the server to port 1234. */
  2342. address.port = 17091;
  2343. server = enet_host_create(&address /* the address to bind the server host to */,
  2344. 1024 /* allow up to 32 clients and/or outgoing connections */,
  2345. 10 /* allow up to 2 channels to be used, 0 and 1 */,
  2346. 0 /* assume any amount of incoming bandwidth */,
  2347. 0 /* assume any amount of outgoing bandwidth */);
  2348. if (server == NULL)
  2349. {
  2350. fprintf(stderr,
  2351. "An error occurred while trying to create an ENet server host.\n");
  2352. while (1);
  2353. exit(EXIT_FAILURE);
  2354. }
  2355. server->checksum = enet_crc32;
  2356. enet_host_compress_with_range_coder(server);
  2357.  
  2358.  
  2359. cout << "Building items database..." << endl;
  2360. buildItemsDatabase();
  2361. cout << "Database is built!" << endl;
  2362.  
  2363.  
  2364. ENetEvent event;
  2365. /* Wait up to 1000 milliseconds for an event. */
  2366. while (true)
  2367. while (enet_host_service(server, &event, 1000) > 0)
  2368. {
  2369. ENetPeer* peer = event.peer;
  2370. switch (event.type)
  2371. {
  2372. case ENET_EVENT_TYPE_CONNECT:
  2373. {
  2374. #ifdef TOTAL_LOG
  2375. printf("A new client connected.\n");
  2376. #endif
  2377. /* Store any relevant client information here. */
  2378. //event.peer->data = "Client information";
  2379. ENetPeer * currentPeer;
  2380. int count = 0;
  2381. for (currentPeer = server->peers;
  2382. currentPeer < &server->peers[server->peerCount];
  2383. ++currentPeer)
  2384. {
  2385. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  2386. continue;
  2387. if (currentPeer->address.host == peer->address.host)
  2388. count++;
  2389. }
  2390.  
  2391.  
  2392. event.peer->data = new PlayerInfo;
  2393. if (count > 3)
  2394. {
  2395. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`rToo many accounts are logged on from this IP. Log off one account before playing please.``"));
  2396. ENetPacket * packet = enet_packet_create(p.data,
  2397. p.len,
  2398. ENET_PACKET_FLAG_RELIABLE);
  2399. enet_peer_send(peer, 0, packet);
  2400. delete p.data;
  2401. //enet_host_flush(server);
  2402. enet_peer_disconnect_later(peer, 0);
  2403. }
  2404. else {
  2405. sendData(peer, 1, 0, 0);
  2406. }
  2407.  
  2408.  
  2409.  
  2410.  
  2411. continue;
  2412. }
  2413. case ENET_EVENT_TYPE_RECEIVE:
  2414. {
  2415. if (((PlayerInfo*)(peer->data))->isUpdating)
  2416. {
  2417. cout << "packet drop" << endl;
  2418. continue;
  2419. }
  2420. /*printf("A packet of length %u containing %s was received from %s on channel %u.\n",
  2421. event.packet->dataLength,
  2422. event.packet->data,
  2423. event.peer->data,
  2424. event.channelID);
  2425. cout << (int)*event.packet->data << endl;*/
  2426. //cout << text_encode(getPacketData((char*)event.packet->data));
  2427. /*for (int i = 0; i < event.packet->dataLength; i++)
  2428. {
  2429. cout << event.packet->data[i];
  2430. }
  2431. sendData(7, 0, 0);
  2432. string x = "eventType|0\neventName|102_PLAYER.AUTHENTICATION\nAuthenticated|0\nAuthentication_error|6\nDevice_Id|^^\nGrow_Id|0\nName|^^Elektronik\nWordlock_balance|0\n";
  2433. //string x = "eventType | 0\neventName | 102_PLAYER.AUTHENTICATION\nAuthenticated | 0\nAuthentication_error | 6\nDevice_Id | ^^\nGrow_Id | 0\nName | ^^Elektronik\nWorldlock_balance | 0\n";
  2434. sendData(6, (char*)x.c_str(), x.length());
  2435. string y = "action|quit\n";
  2436. sendData(3, (char*)y.c_str(), y.length());
  2437. cout << endl;
  2438. string asdf = "0400000001000000FFFFFFFF0000000008000000000000000000000000000000000000000000000000000000000000000000000000000000400000000600020E0000004F6E53656E64546F5365727665720109ED4200000209834CED00030910887F0104020D0000003230392E35392E3139302E347C05090100000000C";
  2439. //asdf = "0400000001000000FFFFFFFF000000000800000000000000000000000000000000000000000000000000000000000000000000000000000040000000060002220000004F6E53757065724D61696E53746172744163636570744C6F676F6E464232313131330109ED4200000209834CED00030910887F0104020D0000003230392E35392E3139302E347C05090100000000C";
  2440. ENetPacket * packet = enet_packet_create(0,
  2441. asdf.length()/2,
  2442. ENET_PACKET_FLAG_RELIABLE);
  2443. for (int i = 0; i < asdf.length(); i += 2)
  2444. {
  2445. char x = ch2n(asdf[i]);
  2446. x = x << 4;
  2447. x += ch2n(asdf[i + 1]);
  2448. memcpy(packet->data + (i / 2), &x, 1);
  2449. }
  2450. enet_peer_send(peer, 0, packet);
  2451. enet_host_flush(server);
  2452. /* Clean up the packet now that we're done using it. */
  2453. //enet_packet_destroy(event.packet);
  2454. //sendData(7, 0, 0);
  2455. int messageType = GetMessageTypeFromPacket(event.packet);
  2456. //cout << "Packet type is " << messageType << endl;
  2457. //cout << (event->packet->data+4) << endl;
  2458. WorldInfo* world = getPlyersWorld(peer);
  2459. switch (messageType) {
  2460. case 2:
  2461. {
  2462. //cout << GetTextPointerFromPacket(event.packet) << endl;
  2463. string cch = GetTextPointerFromPacket(event.packet);
  2464. string str = cch.substr(cch.find("text|") + 5, cch.length() - cch.find("text|") - 1);
  2465. if (cch.find("action|wrench") == 0) {
  2466. vector<string> ex = explode("|", cch);
  2467. int id = stoi(ex[3]);
  2468.  
  2469.  
  2470. ENetPeer * currentPeer;
  2471. for (currentPeer = server->peers;
  2472. currentPeer < &server->peers[server->peerCount];
  2473. ++currentPeer)
  2474. {
  2475. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  2476. continue;
  2477.  
  2478.  
  2479. if (isHere(peer, currentPeer)) {
  2480. if (((PlayerInfo*)(currentPeer->data))->netID == id) {
  2481. string name = ((PlayerInfo*)(currentPeer->data))->displayName;
  2482. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnDialogRequest"), "set_default_color|`o\nadd_label_with_icon|big|"+name+"|left|18|\nadd_spacer|small|\nadd_button|chc0|Close|noflags|0|0|\n\nadd_quick_exit|\nnend_dialog|gazette||OK|"));
  2483. ENetPacket * packet = enet_packet_create(p.data,
  2484. p.len,
  2485. ENET_PACKET_FLAG_RELIABLE);
  2486. enet_peer_send(peer, 0, packet);
  2487. delete p.data;
  2488. }
  2489.  
  2490.  
  2491. }
  2492.  
  2493.  
  2494. }
  2495. }
  2496. if (cch.find("action|respawn") == 0)
  2497. {
  2498. int x = 3040;
  2499. int y = 736;
  2500.  
  2501.  
  2502. if (!world) continue;
  2503.  
  2504.  
  2505. for (int i = 0; i < world->width*world->height; i++)
  2506. {
  2507. if (world->items[i].foreground == 6) {
  2508. x = (i%world->width) * 32;
  2509. y = (i / world->width) * 32;
  2510. }
  2511. }
  2512. {
  2513. PlayerMoving data;
  2514. data.packetType = 0x0;
  2515. data.characterState = 0x924; // animation
  2516. data.x = x;
  2517. data.y = y;
  2518. data.punchX = -1;
  2519. data.punchY = -1;
  2520. data.XSpeed = 0;
  2521. data.YSpeed = 0;
  2522. data.netID = ((PlayerInfo*)(peer->data))->netID;
  2523. data.plantingTree = 0x0;
  2524. SendPacketRaw(4, packPlayerMoving(&data), 56, 0, peer, ENET_PACKET_FLAG_RELIABLE);
  2525. }
  2526.  
  2527. {
  2528. int x = 3040;
  2529. int y = 736;
  2530.  
  2531.  
  2532. for (int i = 0; i < world->width*world->height; i++)
  2533. {
  2534. if (world->items[i].foreground == 6) {
  2535. x = (i%world->width) * 32;
  2536. y = (i / world->width) * 32;
  2537. }
  2538. }
  2539. GamePacket p2 = packetEnd(appendFloat(appendString(createPacket(), "OnSetPos"), x,y));
  2540. memcpy(p2.data + 8, &(((PlayerInfo*)(peer->data))->netID), 4);
  2541. ENetPacket * packet2 = enet_packet_create(p2.data,
  2542. p2.len,
  2543. ENET_PACKET_FLAG_RELIABLE);
  2544.  
  2545.  
  2546. enet_peer_send(peer, 0, packet2);
  2547. delete p2.data;
  2548. //enet_host_flush(server);
  2549. }
  2550. {
  2551. int x = 3040;
  2552. int y = 736;
  2553.  
  2554.  
  2555. for (int i = 0; i < world->width*world->height; i++)
  2556. {
  2557. if (world->items[i].foreground == 6) {
  2558. x = (i%world->width) * 32;
  2559. y = (i / world->width) * 32;
  2560. }
  2561. }
  2562. GamePacket p2 = packetEnd(appendIntx(appendString(createPacket(), "OnSetFreezeState"), 0));
  2563. memcpy(p2.data + 8, &(((PlayerInfo*)(peer->data))->netID), 4);
  2564. ENetPacket * packet2 = enet_packet_create(p2.data,
  2565. p2.len,
  2566. ENET_PACKET_FLAG_RELIABLE);
  2567.  
  2568.  
  2569. enet_peer_send(peer, 0, packet2);
  2570. delete p2.data;
  2571. //enet_host_flush(server);
  2572. }
  2573. #ifdef TOTAL_LOG
  2574. cout << "Respawning... " << endl;
  2575. #endif
  2576. }
  2577. if (cch.find("action|growid") == 0)
  2578. {
  2579. #ifndef REGISTRATION
  2580. {
  2581. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "Registration is not supported yet!"));
  2582. ENetPacket * packet = enet_packet_create(p.data,
  2583. p.len,
  2584. ENET_PACKET_FLAG_RELIABLE);
  2585. enet_peer_send(peer, 0, packet);
  2586. delete p.data;
  2587. //enet_host_flush(server);
  2588. }
  2589. #endif
  2590. #ifdef REGISTRATION
  2591. //GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnDialogRequest"), "set_default_color|`o\n\nadd_label_with_icon|big|`w" + itemDefs.at(id).name + "``|left|" + std::to_string(id) + "|\n\nadd_spacer|small|\nadd_textbox|" + itemDefs.at(id).description + "|left|\nadd_spacer|small|\nadd_quick_exit|\nadd_button|chc0|Close|noflags|0|0|\nnend_dialog|gazette||OK|"));
  2592. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnDialogRequest"), "set_default_color|`o\n\nadd_label_with_icon|big|`wGet a GrowID``|left|206|\n\nadd_spacer|small|\nadd_textbox|A `wGrowID `wmeans `oyou can use a name and password to logon from any device.|\nadd_spacer|small|\nadd_textbox|This `wname `owill be reserved for you and `wshown to other players`o, so choose carefully!|\nadd_text_input|username|GrowID||30|\nadd_text_input|password|Password||100|\nadd_text_input|passwordverify|Password Verify||100|\nadd_textbox|Your `wemail address `owill only be used for account verification purposes and won't be spammed or shared. If you use a fake email, you'll never be able to recover or change your password.|\nadd_text_input|email|Email||100|\nadd_textbox|Your `wDiscord ID `owill be used for secondary verification if you lost access to your `wemail address`o! Please enter in such format: `wdiscordname#tag`o. Your `wDiscord Tag `ocan be found in your `wDiscord account settings`o.|\nadd_text_input|discord|Discord||100|\nend_dialog|register|Cancel|Get My GrowID!|\n"));
  2593. ENetPacket * packet = enet_packet_create(p.data,
  2594. p.len,
  2595. ENET_PACKET_FLAG_RELIABLE);
  2596. enet_peer_send(peer, 0, packet);
  2597. delete p.data;
  2598. #endif
  2599. }
  2600. if (cch.find("action|store") == 0)
  2601. {
  2602. GamePacket p2 = packetEnd(appendString(appendString(createPacket(), "OnStoreRequest"), "set_description_text|Welcome to the `2Growtopia Store``! Tap the item you'd like more info on.`o `wWant to get `5Supporter`` status? Any Gem purchase (or `57,000`` Gems earned with free `5Tapjoy`` offers) will make you one. You'll get new skin colors, the `5Recycle`` tool to convert unwanted items into Gems, and more bonuses!\nadd_button|iap_menu|Buy Gems|interface/large/store_buttons5.rttex||0|2|0|0||\nadd_button|subs_menu|Subscriptions|interface/large/store_buttons22.rttex||0|1|0|0||\nadd_button|token_menu|Growtoken Items|interface/large/store_buttons9.rttex||0|0|0|0||\nadd_button|pristine_forceps|`oAnomalizing Pristine Bonesaw``|interface/large/store_buttons20.rttex|Built to exacting specifications by GrowTech engineers to find and remove temporal anomalies from infected patients, and with even more power than Delicate versions! Note : The fragile anomaly - seeking circuitry in these devices is prone to failure and may break (though with less of a chance than a Delicate version)! Use with care!|0|3|3500|0||\nadd_button|itemomonth|`oItem Of The Month``|interface/large/store_buttons16.rttex|`2September 2018:`` `9Sorcerer's Tunic of Mystery!`` Capable of reflecting the true colors of the world around it, this rare tunic is made of captured starlight and aether. If you think knitting with thread is hard, just try doing it with moonbeams and magic! The result is worth it though, as these clothes won't just make you look amazing - you'll be able to channel their inherent power into blasts of cosmic energy!``|0|3|200000|0||\nadd_button|contact_lenses|`oContact Lens Pack``|interface/large/store_buttons22.rttex|Need a colorful new look? This pack includes 10 random Contact Lens colors (and may include Contact Lens Cleaning Solution, to return to your natural eye color)!|0|7|15000|0||\nadd_button|locks_menu|Locks And Stuff|interface/large/store_buttons3.rttex||0|4|0|0||\nadd_button|itempack_menu|Item Packs|interface/large/store_buttons3.rttex||0|3|0|0||\nadd_button|bigitems_menu|Awesome Items|interface/large/store_buttons4.rttex||0|6|0|0||\nadd_button|weather_menu|Weather Machines|interface/large/store_buttons5.rttex|Tired of the same sunny sky? We offer alternatives within...|0|4|0|0||\n"));
  2603. ENetPacket * packet2 = enet_packet_create(p2.data,
  2604. p2.len,
  2605. ENET_PACKET_FLAG_RELIABLE);
  2606.  
  2607.  
  2608. enet_peer_send(peer, 0, packet2);
  2609. delete p2.data;
  2610. //enet_host_flush(server);
  2611. }
  2612. if (cch.find("action|info") == 0)
  2613. {
  2614. std::stringstream ss(cch);
  2615. std::string to;
  2616. int id = -1;
  2617. int count = -1;
  2618. while (std::getline(ss, to, '\n')) {
  2619. vector<string> infoDat = explode("|", to);
  2620. if (infoDat.size() == 3) {
  2621. if (infoDat[1] == "itemID") id = atoi(infoDat[2].c_str());
  2622. if (infoDat[1] == "count") count = atoi(infoDat[2].c_str());
  2623. }
  2624. }
  2625. if (id == -1 || count == -1) continue;
  2626. if (itemDefs.size() < id || id < 0) continue;
  2627. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnDialogRequest"), "set_default_color|`o\n\nadd_label_with_icon|big|`w"+ itemDefs.at(id).name +"``|left|"+std::to_string(id)+"|\n\nadd_spacer|small|\nadd_textbox|"+ itemDefs.at(id).description +"|left|\nadd_spacer|small|\nadd_quick_exit|\nadd_button|chc0|Close|noflags|0|0|\nnend_dialog|gazette||OK|"));
  2628. ENetPacket * packet = enet_packet_create(p.data,
  2629. p.len,
  2630. ENET_PACKET_FLAG_RELIABLE);
  2631. enet_peer_send(peer, 0, packet);
  2632.  
  2633.  
  2634. //enet_host_flush(server);
  2635. delete p.data;
  2636. }
  2637. if (cch.find("action|dialog_return") == 0)
  2638. {
  2639. std::stringstream ss(cch);
  2640. std::string to;
  2641. string btn = "";
  2642. bool isRegisterDialog = false;
  2643. string username = "";
  2644. string password = "";
  2645. string passwordverify = "";
  2646. string email = "";
  2647. string discord = "";
  2648. while (std::getline(ss, to, '\n')) {
  2649. vector<string> infoDat = explode("|", to);
  2650. if (infoDat.size() == 2) {
  2651. if (infoDat[0] == "buttonClicked") btn = infoDat[1];
  2652. if (infoDat[0] == "dialog_name" && infoDat[1] == "register")
  2653. {
  2654. isRegisterDialog = true;
  2655. }
  2656. if (isRegisterDialog) {
  2657. if (infoDat[0] == "username") username = infoDat[1];
  2658. if (infoDat[0] == "password") password = infoDat[1];
  2659. if (infoDat[0] == "passwordverify") passwordverify = infoDat[1];
  2660. if (infoDat[0] == "email") email = infoDat[1];
  2661. if (infoDat[0] == "discord") discord = infoDat[1];
  2662. }
  2663. }
  2664. }
  2665. if (btn.substr(0, 5) == "found") {
  2666. PlayerInventory inventory;
  2667. InventoryItem item;
  2668. item.itemID = atoi(btn.substr(5, btn.length()).c_str());
  2669. item.itemCount = 200;
  2670. inventory.items.push_back(item);
  2671. item.itemCount = 1;
  2672. item.itemID = 18;
  2673. inventory.items.push_back(item);
  2674. item.itemID = 32;
  2675. inventory.items.push_back(item);
  2676. sendInventory(peer, inventory);
  2677. }
  2678.  
  2679.  
  2680. if (btn == "worldPublic") if (((PlayerInfo*)(peer->data))->rawName == getPlyersWorld(peer)->owner) getPlyersWorld(peer)->isPublic = true;
  2681. if(btn == "worldPrivate") if (((PlayerInfo*)(peer->data))->rawName == getPlyersWorld(peer)->owner) getPlyersWorld(peer)->isPublic = false;
  2682. #ifdef REGISTRATION
  2683. if (isRegisterDialog) {
  2684.  
  2685.  
  2686. int regState = PlayerDB::playerRegister(username, password, passwordverify, email, discord);
  2687. if (regState == 1) {
  2688. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`rYour account has been created!``"));
  2689. ENetPacket * packet = enet_packet_create(p.data,
  2690. p.len,
  2691. ENET_PACKET_FLAG_RELIABLE);
  2692. enet_peer_send(peer, 0, packet);
  2693. delete p.data;
  2694. GamePacket p2 = packetEnd(appendString(appendString(appendInt(appendString(createPacket(), "SetHasGrowID"), 1), username), password));
  2695. ENetPacket * packet2 = enet_packet_create(p2.data,
  2696. p2.len,
  2697. ENET_PACKET_FLAG_RELIABLE);
  2698. enet_peer_send(peer, 0, packet2);
  2699.  
  2700.  
  2701. //enet_host_flush(server);
  2702. delete p2.data;
  2703. enet_peer_disconnect_later(peer, 0);
  2704. }
  2705. else if(regState==-1) {
  2706. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`rAccount creation has failed, because it already exists!``"));
  2707. ENetPacket * packet = enet_packet_create(p.data,
  2708. p.len,
  2709. ENET_PACKET_FLAG_RELIABLE);
  2710. enet_peer_send(peer, 0, packet);
  2711. delete p.data;
  2712. }
  2713. else if (regState == -2) {
  2714. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`rAccount creation has failed, because the name is too short!``"));
  2715. ENetPacket * packet = enet_packet_create(p.data,
  2716. p.len,
  2717. ENET_PACKET_FLAG_RELIABLE);
  2718. enet_peer_send(peer, 0, packet);
  2719. delete p.data;
  2720. }
  2721. else if (regState == -3) {
  2722. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4Passwords mismatch!``"));
  2723. ENetPacket * packet = enet_packet_create(p.data,
  2724. p.len,
  2725. ENET_PACKET_FLAG_RELIABLE);
  2726. enet_peer_send(peer, 0, packet);
  2727. delete p.data;
  2728. }
  2729. else if (regState == -4) {
  2730. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4Account creation has failed, because email address is invalid!``"));
  2731. ENetPacket * packet = enet_packet_create(p.data,
  2732. p.len,
  2733. ENET_PACKET_FLAG_RELIABLE);
  2734. enet_peer_send(peer, 0, packet);
  2735. delete p.data;
  2736. }
  2737. else if (regState == -5) {
  2738. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4Account creation has failed, because Discord ID is invalid!``"));
  2739. ENetPacket * packet = enet_packet_create(p.data,
  2740. p.len,
  2741. ENET_PACKET_FLAG_RELIABLE);
  2742. enet_peer_send(peer, 0, packet);
  2743. delete p.data;
  2744. }
  2745. }
  2746. #endif
  2747. }
  2748. string dropText = "action|drop\n|itemID|";
  2749. if (cch.find(dropText) == 0)
  2750. {
  2751. sendDrop(peer, -1, ((PlayerInfo*)(peer->data))->x + (32 * (((PlayerInfo*)(peer->data))->isRotatedLeft?-1:1)), ((PlayerInfo*)(peer->data))->y, atoi(cch.substr(dropText.length(), cch.length() - dropText.length() - 1).c_str()), 1, 0);
  2752. /*int itemID = atoi(cch.substr(dropText.length(), cch.length() - dropText.length() - 1).c_str());
  2753. PlayerMoving data;
  2754. data.packetType = 14;
  2755. data.x = ((PlayerInfo*)(peer->data))->x;
  2756. data.y = ((PlayerInfo*)(peer->data))->y;
  2757. data.netID = -1;
  2758. data.plantingTree = itemID;
  2759. float val = 1; // item count
  2760. BYTE val2 = 0; // if 8, then geiger effect
  2761.  
  2762. BYTE* raw = packPlayerMoving(&data);
  2763. memcpy(raw + 16, &val, 4);
  2764. memcpy(raw + 1, &val2, 1);
  2765. SendPacketRaw(4, raw, 56, 0, peer, ENET_PACKET_FLAG_RELIABLE);*/
  2766. }
  2767. if (cch.find("text|") != std::string::npos){
  2768. PlayerInfo* pData = ((PlayerInfo*)(peer->data));
  2769. if (str == "/mod")
  2770. {
  2771. ((PlayerInfo*)(peer->data))->canWalkInBlocks = true;
  2772. sendState(peer);
  2773. /*PlayerMoving data;
  2774. data.packetType = 0x14;
  2775. data.characterState = 0x0; // animation
  2776. data.x = 1000;
  2777. data.y = 1;
  2778. data.punchX = 0;
  2779. data.punchY = 0;
  2780. data.XSpeed = 300;
  2781. data.YSpeed = 600;
  2782. data.netID = ((PlayerInfo*)(peer->data))->netID;
  2783. data.plantingTree = 0xFF;
  2784. SendPacketRaw(4, packPlayerMoving(&data), 56, 0, peer, ENET_PACKET_FLAG_RELIABLE);*/
  2785. }
  2786. else if (str.substr(0, 7) == "/state ")
  2787. {
  2788. PlayerMoving data;
  2789. data.packetType = 0x14;
  2790. data.characterState = 0x0; // animation
  2791. data.x = 1000;
  2792. data.y = 0;
  2793. data.punchX = 0;
  2794. data.punchY = 0;
  2795. data.XSpeed = 300;
  2796. data.YSpeed = 600;
  2797. data.netID = ((PlayerInfo*)(peer->data))->netID;
  2798. data.plantingTree = atoi(str.substr(7, cch.length() - 7 - 1).c_str());
  2799. SendPacketRaw(4, packPlayerMoving(&data), 56, 0, peer, ENET_PACKET_FLAG_RELIABLE);
  2800. }
  2801. else if (str == "/mods") {
  2802. string x;
  2803.  
  2804.  
  2805. ENetPeer* currentPeer;
  2806.  
  2807.  
  2808. for (currentPeer = server->peers;
  2809. currentPeer < &server->peers[server->peerCount];
  2810. ++currentPeer)
  2811. {
  2812. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  2813. continue;
  2814.  
  2815.  
  2816. if (getAdminLevel(((PlayerInfo*)(currentPeer->data))->rawName, ((PlayerInfo*)(currentPeer->data))->tankIDPass) > 0) {
  2817. x.append("`#@" + ((PlayerInfo*)(currentPeer->data))->rawName + "``, ");
  2818. }
  2819.  
  2820.  
  2821. }
  2822. x = x.substr(0, x.length() - 2);
  2823.  
  2824.  
  2825. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "``Moderators online: "+x));
  2826. ENetPacket * packet = enet_packet_create(p.data,
  2827. p.len,
  2828. ENET_PACKET_FLAG_RELIABLE);
  2829. enet_peer_send(peer, 0, packet);
  2830. }
  2831. else if (str == "/find") {
  2832. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4Use /find (item name)"));
  2833. ENetPacket * packet = enet_packet_create(p.data,
  2834. p.len,
  2835. ENET_PACKET_FLAG_RELIABLE);
  2836. enet_peer_send(peer, 0, packet);
  2837. }
  2838. else if (str.substr(0, 8) == "/summon ") {
  2839. if (getAdminLevel(((PlayerInfo*)(peer->data))->rawName, ((PlayerInfo*)(peer->data))->tankIDPass) > 0) {
  2840. string name = str.substr(8, str.length());
  2841.  
  2842.  
  2843. ENetPeer* currentPeer;
  2844.  
  2845.  
  2846. bool found = false;
  2847.  
  2848.  
  2849. for (currentPeer = server->peers;
  2850. currentPeer < &server->peers[server->peerCount];
  2851. ++currentPeer)
  2852. {
  2853. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  2854. continue;
  2855.  
  2856.  
  2857. string name2 = ((PlayerInfo*)(currentPeer->data))->rawName;
  2858.  
  2859.  
  2860. std::transform(name.begin(), name.end(), name.begin(), ::tolower);
  2861. std::transform(name2.begin(), name2.end(), name2.begin(), ::tolower);
  2862.  
  2863.  
  2864. if (name == name2) {
  2865. sendPlayerToPlayer(currentPeer, peer);
  2866. found = true;
  2867. }
  2868.  
  2869.  
  2870. }
  2871. if (found) {
  2872. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`9Summoning "+name));
  2873. ENetPacket * packet = enet_packet_create(p.data,
  2874. p.len,
  2875. ENET_PACKET_FLAG_RELIABLE);
  2876. enet_peer_send(peer, 0, packet);
  2877. }
  2878. else {
  2879. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4Player not found!"));
  2880. ENetPacket * packet = enet_packet_create(p.data,
  2881. p.len,
  2882. ENET_PACKET_FLAG_RELIABLE);
  2883. enet_peer_send(peer, 0, packet);
  2884. }
  2885. }
  2886.  
  2887.  
  2888. }
  2889. else if (str.substr(0, 8) == "/warpto ") {
  2890. if (getAdminLevel(((PlayerInfo*)(peer->data))->rawName, ((PlayerInfo*)(peer->data))->tankIDPass) > 0) {
  2891. string name = str.substr(8, str.length());
  2892.  
  2893.  
  2894. ENetPeer* currentPeer;
  2895.  
  2896.  
  2897. bool found = false;
  2898.  
  2899.  
  2900. for (currentPeer = server->peers;
  2901. currentPeer < &server->peers[server->peerCount];
  2902. ++currentPeer)
  2903. {
  2904. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  2905. continue;
  2906.  
  2907.  
  2908. string name2 = ((PlayerInfo*)(currentPeer->data))->rawName;
  2909.  
  2910.  
  2911. std::transform(name.begin(), name.end(), name.begin(), ::tolower);
  2912. std::transform(name2.begin(), name2.end(), name2.begin(), ::tolower);
  2913.  
  2914.  
  2915. if (name == name2) {
  2916. sendPlayerToPlayer(peer, currentPeer);
  2917. found = true;
  2918. }
  2919.  
  2920.  
  2921. }
  2922. if (found) {
  2923. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`9Warping to " + name));
  2924. ENetPacket * packet = enet_packet_create(p.data,
  2925. p.len,
  2926. ENET_PACKET_FLAG_RELIABLE);
  2927. enet_peer_send(peer, 0, packet);
  2928. }
  2929. else {
  2930. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4Player not found!"));
  2931. ENetPacket * packet = enet_packet_create(p.data,
  2932. p.len,
  2933. ENET_PACKET_FLAG_RELIABLE);
  2934. enet_peer_send(peer, 0, packet);
  2935. }
  2936. }
  2937.  
  2938.  
  2939. }
  2940.  
  2941.  
  2942. else if (str.substr(0, 6) == "/warp ") {
  2943. if (getAdminLevel(((PlayerInfo*)(peer->data))->rawName, ((PlayerInfo*)(peer->data))->tankIDPass) > 0) {
  2944. string world = str.substr(6, str.length());
  2945.  
  2946.  
  2947. sendPlayerToWorld(peer, (PlayerInfo*)(peer->data), world);
  2948.  
  2949.  
  2950. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`9Warping to " + world));
  2951. ENetPacket * packet = enet_packet_create(p.data,
  2952. p.len,
  2953. ENET_PACKET_FLAG_RELIABLE);
  2954. enet_peer_send(peer, 0, packet);
  2955. }
  2956. }
  2957. else if (str.substr(0, 6) == "/find ") {
  2958. string item = str.substr(6, str.length());
  2959.  
  2960. if (item != "") {
  2961. if (item.length() >= 3) {
  2962. string stuff;
  2963. std::ifstream infile("CoreData.txt");
  2964. for (std::string line; getline(infile, line);)
  2965. {
  2966. if (line.length() > 8 && line[0] != '/' && line[1] != '/')
  2967. {
  2968. vector<string> ex = explode("|", line);
  2969. string xd = ex[1];
  2970. string id = ex[0];
  2971. std::transform(xd.begin(), xd.end(), xd.begin(), ::tolower);
  2972.  
  2973.  
  2974. std::transform(item.begin(), item.end(), item.begin(), ::tolower);
  2975.  
  2976.  
  2977. if (xd.find(item) != std::string::npos) {
  2978. stuff.append("\nadd_label_with_icon|small|"+xd+"|left|"+id+"|" + "\nadd_button|found"+id+"|Get|noflags|");
  2979. stuff.append("\nadd+spacer|sma;;|");
  2980. }
  2981. }
  2982. }
  2983. string x = "set_default_color|`3\n";
  2984.  
  2985.  
  2986. x.append("\nadd_label|big|`9Item Finder|left|");
  2987. if (stuff == "") {
  2988. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4No results!"));
  2989. ENetPacket * packet = enet_packet_create(p.data,
  2990. p.len,
  2991. ENET_PACKET_FLAG_RELIABLE);
  2992. enet_peer_send(peer, 0, packet);
  2993. delete p.data;
  2994. }
  2995. else {
  2996. x.append("\nadd_label|small|`wHere are the results of your `9search`w:|left|");
  2997.  
  2998.  
  2999. x.append("\nadd_spacer|small|");
  3000.  
  3001.  
  3002. x.append(stuff);
  3003.  
  3004.  
  3005. //x.append(addspacer("big"));
  3006. }
  3007. x.append("\n\nadd_quick_exit|\nnend_dialog|gazette||OK|");
  3008.  
  3009.  
  3010. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnDialogRequest"), x));
  3011. ENetPacket * packet = enet_packet_create(p.data,
  3012. p.len,
  3013. ENET_PACKET_FLAG_RELIABLE);
  3014. enet_peer_send(peer, 0, packet);
  3015. delete p.data;
  3016. }
  3017. else {
  3018. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4You must enter 3 or more letters!"));
  3019. ENetPacket * packet = enet_packet_create(p.data,
  3020. p.len,
  3021. ENET_PACKET_FLAG_RELIABLE);
  3022. enet_peer_send(peer, 0, packet);
  3023. delete p.data;
  3024. }
  3025.  
  3026.  
  3027.  
  3028.  
  3029. }
  3030. }
  3031. else if (str == "/nuke") {
  3032. if (getAdminLevel(((PlayerInfo*)(peer->data))->rawName, ((PlayerInfo*)(peer->data))->tankIDPass) > 0) {
  3033. WorldInfo *world = getPlyersWorld(peer);
  3034. if (world->nuked) {
  3035. world->nuked = false;
  3036. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`2You have un-nuked the world"));
  3037. ENetPacket * packet = enet_packet_create(p.data,
  3038. p.len,
  3039. ENET_PACKET_FLAG_RELIABLE);
  3040. enet_peer_send(peer, 0, packet);
  3041. }
  3042. else {
  3043. world->nuked = true;
  3044. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4You have nuked the world!"));
  3045. ENetPacket * packet = enet_packet_create(p.data,
  3046. p.len,
  3047. ENET_PACKET_FLAG_RELIABLE);
  3048. enet_peer_send(peer, 0, packet);
  3049.  
  3050.  
  3051. ENetPeer* currentPeer;
  3052.  
  3053.  
  3054. for (currentPeer = server->peers;
  3055. currentPeer < &server->peers[server->peerCount];
  3056. ++currentPeer)
  3057. {
  3058. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  3059. continue;
  3060.  
  3061.  
  3062. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4"+world->name+" has been nuked!"));
  3063. ENetPacket * packet = enet_packet_create(p.data,
  3064. p.len,
  3065. ENET_PACKET_FLAG_RELIABLE);
  3066. enet_peer_send(currentPeer, 0, packet);
  3067. }
  3068. }
  3069. }
  3070.  
  3071.  
  3072. }
  3073. else if (str.substr(0, 5) == "/ban ") {
  3074. if (getAdminLevel(((PlayerInfo*)(peer->data))->rawName, ((PlayerInfo*)(peer->data))->tankIDPass) > 0) {
  3075. string name = str.substr(5, str.length());
  3076.  
  3077.  
  3078. ENetPeer* currentPeer;
  3079.  
  3080.  
  3081. bool found = false;
  3082.  
  3083.  
  3084. for (currentPeer = server->peers;
  3085. currentPeer < &server->peers[server->peerCount];
  3086. ++currentPeer)
  3087. {
  3088. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  3089. continue;
  3090.  
  3091.  
  3092. if (((PlayerInfo*)(currentPeer->data))->rawName == name) {
  3093. found = true;
  3094. std::ifstream ifs("players/" + ((PlayerInfo*)(currentPeer->data))->rawName + ".json");
  3095. if (ifs.is_open()) {
  3096. json x;
  3097. ifs >> x;
  3098. std::ofstream o("players/" + ((PlayerInfo*)(currentPeer->data))->rawName + ".json");
  3099. json j;
  3100. j["username"] = ((PlayerInfo*)(currentPeer->data))->rawName;
  3101. j["password"] = hashPassword(((PlayerInfo*)(currentPeer->data))->tankIDPass);
  3102. j["email"] = x["email"];
  3103. j["banned"] = true;
  3104. j["discord"] = x["discord"];
  3105. j["adminLevel"] = x["adminLevel"];
  3106. o << j << std::endl;
  3107. }
  3108. ifs.close();
  3109.  
  3110.  
  3111. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4You have been permanently banned by "+ ((PlayerInfo*)(peer->data))->rawName));
  3112. ENetPacket * packet = enet_packet_create(p.data,
  3113. p.len,
  3114. ENET_PACKET_FLAG_RELIABLE);
  3115. enet_peer_send(currentPeer, 0, packet);
  3116. enet_peer_disconnect_later(currentPeer, 0);
  3117. }
  3118.  
  3119.  
  3120. }
  3121. if (!found) {
  3122. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4Player not found!"));
  3123. ENetPacket * packet = enet_packet_create(p.data,
  3124. p.len,
  3125. ENET_PACKET_FLAG_RELIABLE);
  3126. enet_peer_send(peer, 0, packet);
  3127. }
  3128. else {
  3129. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`2Player successfully banned!"));
  3130. ENetPacket * packet = enet_packet_create(p.data,
  3131. p.len,
  3132. ENET_PACKET_FLAG_RELIABLE);
  3133. enet_peer_send(peer, 0, packet);
  3134. }
  3135. }
  3136. }
  3137. else if (str.substr(0,10) == "/mute ") {
  3138. if (getAdminLevel(((PlayerInfo*)(peer->data))->rawName, ((PlayerInfo*)(peer->data))->tankIDPass) > 0) {
  3139. string name = str.substr(10, str.length());
  3140.  
  3141.  
  3142. ENetPeer* currentPeer;
  3143.  
  3144.  
  3145. bool found = false;
  3146.  
  3147.  
  3148. for (currentPeer = server->peers;
  3149. currentPeer < &server->peers[server->peerCount];
  3150. ++currentPeer)
  3151. {
  3152. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  3153. continue;
  3154.  
  3155.  
  3156. if (((PlayerInfo*)(currentPeer->data))->rawName == name) {
  3157. found = true;
  3158. if (((PlayerInfo*)(currentPeer->data))->taped) {
  3159. ((PlayerInfo*)(currentPeer->data))->taped = false;
  3160. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`2You are no longer duct-taped!"));
  3161. ENetPacket * packet = enet_packet_create(p.data,
  3162. p.len,
  3163. ENET_PACKET_FLAG_RELIABLE);
  3164. enet_peer_send(currentPeer, 0, packet);
  3165. delete p.data;
  3166. {
  3167. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`2You have un duct-taped the player!"));
  3168. ENetPacket * packet = enet_packet_create(p.data,
  3169. p.len,
  3170. ENET_PACKET_FLAG_RELIABLE);
  3171. enet_peer_send(peer, 0, packet);
  3172. }
  3173. }
  3174. else {
  3175. ((PlayerInfo*)(currentPeer->data))->taped = true;
  3176. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4You have been duct-taped!"));
  3177. ENetPacket * packet = enet_packet_create(p.data,
  3178. p.len,
  3179. ENET_PACKET_FLAG_RELIABLE);
  3180. enet_peer_send(currentPeer, 0, packet);
  3181. {
  3182. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`2You have duct-taped the player!"));
  3183. ENetPacket * packet = enet_packet_create(p.data,
  3184. p.len,
  3185. ENET_PACKET_FLAG_RELIABLE);
  3186. enet_peer_send(peer, 0, packet);
  3187. }
  3188. }
  3189. }
  3190. }
  3191. if (!found) {
  3192. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4Player not found!"));
  3193. ENetPacket * packet = enet_packet_create(p.data,
  3194. p.len,
  3195. ENET_PACKET_FLAG_RELIABLE);
  3196. enet_peer_send(peer, 0, packet);
  3197. }
  3198. }
  3199. else {
  3200. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4You need to have a higher admin-level to do that!"));
  3201. ENetPacket * packet = enet_packet_create(p.data,
  3202. p.len,
  3203. ENET_PACKET_FLAG_RELIABLE);
  3204. enet_peer_send(peer, 0, packet);
  3205. }
  3206. }
  3207. else if (str == "/help"){
  3208. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "Supported commands are: /mods, /ducttape, /help, /mod, /unmod, /inventory, /item id, /team id, /color number, /who, /state number, /count, /sb message, /alt, /radio, /gem"));
  3209. ENetPacket * packet = enet_packet_create(p.data,
  3210. p.len,
  3211. ENET_PACKET_FLAG_RELIABLE);
  3212. enet_peer_send(peer, 0, packet);
  3213. delete p.data;
  3214. //enet_host_flush(server);
  3215. }
  3216. else if (str.substr(0, 5) == "/gem ") //gem if u want flex with ur gems!
  3217. {
  3218. GamePacket p = packetEnd(appendInt(appendString(createPacket(), "OnSetBux"), atoi(str.substr(5).c_str())));
  3219. ENetPacket * packet = enet_packet_create(p.data,
  3220. p.len,
  3221. ENET_PACKET_FLAG_RELIABLE);
  3222.  
  3223.  
  3224. enet_peer_send(peer, 0, packet);
  3225. delete p.data;
  3226. continue;
  3227.  
  3228.  
  3229.  
  3230.  
  3231. }
  3232. else if (str.substr(0, 9) == "/weather ") {
  3233. if (world->name != "ADMIN") {
  3234. if (world->owner != "") {
  3235. if (((PlayerInfo*)(peer->data))->rawName == world->owner || isSuperAdmin(((PlayerInfo*)(peer->data))->rawName, ((PlayerInfo*)(peer->data))->tankIDPass))
  3236.  
  3237.  
  3238. {
  3239. ENetPeer* currentPeer;
  3240.  
  3241.  
  3242. for (currentPeer = server->peers;
  3243. currentPeer < &server->peers[server->peerCount];
  3244. ++currentPeer)
  3245. {
  3246. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  3247. continue;
  3248. if (isHere(peer, currentPeer))
  3249. {
  3250. GamePacket p1 = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`oPlayer `2" + ((PlayerInfo*)(peer->data))->displayName + "`o has just changed the world's weather!"));
  3251. ENetPacket * packet1 = enet_packet_create(p1.data,
  3252. p1.len,
  3253. ENET_PACKET_FLAG_RELIABLE);
  3254.  
  3255.  
  3256. enet_peer_send(currentPeer, 0, packet1);
  3257. delete p1.data;
  3258.  
  3259.  
  3260. GamePacket p2 = packetEnd(appendInt(appendString(createPacket(), "OnSetCurrentWeather"), atoi(str.substr(9).c_str())));
  3261. ENetPacket * packet2 = enet_packet_create(p2.data,
  3262. p2.len,
  3263. ENET_PACKET_FLAG_RELIABLE);
  3264.  
  3265.  
  3266. enet_peer_send(currentPeer, 0, packet2);
  3267. delete p2.data;
  3268. continue; /*CODE UPDATE /WEATHER FOR EVERYONE!*/
  3269. }
  3270. }
  3271. }
  3272. }
  3273. }
  3274. }
  3275. else if (str == "/count"){
  3276. int count = 0;
  3277. ENetPeer * currentPeer;
  3278. string name = "";
  3279. for (currentPeer = server->peers;
  3280. currentPeer < &server->peers[server->peerCount];
  3281. ++currentPeer)
  3282. {
  3283. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  3284. continue;
  3285. count++;
  3286. }
  3287. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "There are "+std::to_string(count)+" people online out of 1024 limit."));
  3288. ENetPacket * packet = enet_packet_create(p.data,
  3289. p.len,
  3290. ENET_PACKET_FLAG_RELIABLE);
  3291. enet_peer_send(peer, 0, packet);
  3292. delete p.data;
  3293. //enet_host_flush(server);
  3294. }
  3295. else if (str.substr(0, 5) == "/asb "){
  3296. if (!canSB(((PlayerInfo*)(peer->data))->rawName, ((PlayerInfo*)(peer->data))->tankIDPass)) continue;
  3297. cout << "ASB from " << ((PlayerInfo*)(peer->data))->rawName << " in world " << ((PlayerInfo*)(peer->data))->currentWorld << "with IP " << std::hex << peer->address.host << std::dec << " with message " << str.substr(5, cch.length() - 5 - 1) << endl;
  3298. GamePacket p = packetEnd(appendInt(appendString(appendString(appendString(appendString(createPacket(), "OnAddNotification"), "interface/atomic_button.rttex"), str.substr(4, cch.length() - 4 - 1).c_str()), "audio/hub_open.wav"), 0));
  3299. ENetPacket * packet = enet_packet_create(p.data,
  3300. p.len,
  3301. ENET_PACKET_FLAG_RELIABLE);
  3302. ENetPeer * currentPeer;
  3303. for (currentPeer = server->peers;
  3304. currentPeer < &server->peers[server->peerCount];
  3305. ++currentPeer)
  3306. {
  3307. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  3308. continue;
  3309. enet_peer_send(currentPeer, 0, packet);
  3310. }
  3311.  
  3312. //enet_host_flush(server);
  3313. delete p.data;
  3314. }
  3315. else if (str == "/invis") {
  3316. sendConsoleMsg(peer, "`6" + str);
  3317. if (!pData->isGhost) {
  3318.  
  3319.  
  3320. sendConsoleMsg(peer, "`oYour atoms are suddenly aware of quantum tunneling. (Ghost in the shell mod added)");
  3321.  
  3322.  
  3323. GamePacket p2 = packetEnd(appendFloat(appendString(createPacket(), "OnSetPos"), pData->x, pData->y));
  3324. memcpy(p2.data + 8, &(((PlayerInfo*)(peer->data))->netID), 4);
  3325. ENetPacket * packet2 = enet_packet_create(p2.data,
  3326. p2.len,
  3327. ENET_PACKET_FLAG_RELIABLE);
  3328.  
  3329.  
  3330. enet_peer_send(peer, 0, packet2);
  3331. delete p2.data;
  3332.  
  3333.  
  3334. sendState(peer);
  3335. sendClothes(peer);
  3336. pData->isGhost = true;
  3337. }
  3338. else {
  3339. sendConsoleMsg(peer, "`oYour body stops shimmering and returns to normal. (Ghost in the shell mod removed)");
  3340.  
  3341.  
  3342. GamePacket p2 = packetEnd(appendFloat(appendString(createPacket(), "OnSetPos"), pData->x1, pData->y1));
  3343. memcpy(p2.data + 8, &(((PlayerInfo*)(peer->data))->netID), 4);
  3344. ENetPacket * packet2 = enet_packet_create(p2.data,
  3345. p2.len,
  3346. ENET_PACKET_FLAG_RELIABLE);
  3347.  
  3348.  
  3349. enet_peer_send(peer, 0, packet2);
  3350. delete p2.data;
  3351. ((PlayerInfo*)(peer->data))->isInvisible = false;
  3352. sendState(peer);
  3353. sendClothes(peer);
  3354. pData->isGhost = false;
  3355. }
  3356. }
  3357. else if (str.substr(0, 4) == "/sb ") {
  3358. using namespace std::chrono;
  3359. if (((PlayerInfo*)(peer->data))->lastSB + 45000 < (duration_cast<milliseconds>(system_clock::now().time_since_epoch())).count())
  3360. {
  3361. ((PlayerInfo*)(peer->data))->lastSB = (duration_cast<milliseconds>(system_clock::now().time_since_epoch())).count();
  3362. }
  3363. else {
  3364. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "Wait a minute before using the SB command again!"));
  3365. ENetPacket * packet = enet_packet_create(p.data,
  3366. p.len,
  3367. ENET_PACKET_FLAG_RELIABLE);
  3368.  
  3369.  
  3370. enet_peer_send(peer, 0, packet);
  3371. delete p.data;
  3372. //enet_host_flush(server);
  3373. continue;
  3374. }
  3375.  
  3376.  
  3377. string name = ((PlayerInfo*)(peer->data))->displayName;
  3378. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`w** `5Super-Broadcast`` from `$`2" + name + "```` (in `$" + ((PlayerInfo*)(peer->data))->currentWorld + "``) ** :`` `# " + str.substr(4, cch.length() - 4 - 1)));
  3379. string text = "action|play_sfx\nfile|audio/beep.wav\ndelayMS|0\n";
  3380. BYTE* data = new BYTE[5 + text.length()];
  3381. BYTE zero = 0;
  3382. int type = 3;
  3383. memcpy(data, &type, 4);
  3384. memcpy(data + 4, text.c_str(), text.length());
  3385. memcpy(data + 4 + text.length(), &zero, 1);
  3386. ENetPeer * currentPeer;
  3387.  
  3388. for (currentPeer = server->peers;
  3389. currentPeer < &server->peers[server->peerCount];
  3390. ++currentPeer)
  3391. {
  3392. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  3393. continue;
  3394. if (!((PlayerInfo*)(currentPeer->data))->radio)
  3395. continue;
  3396. ENetPacket * packet = enet_packet_create(p.data,
  3397. p.len,
  3398. ENET_PACKET_FLAG_RELIABLE);
  3399.  
  3400.  
  3401. enet_peer_send(currentPeer, 0, packet);
  3402.  
  3403.  
  3404.  
  3405.  
  3406. ENetPacket * packet2 = enet_packet_create(data,
  3407. 5+text.length(),
  3408. ENET_PACKET_FLAG_RELIABLE);
  3409.  
  3410.  
  3411. enet_peer_send(currentPeer, 0, packet2);
  3412.  
  3413. //enet_host_flush(server);
  3414. }
  3415. delete data;
  3416. delete p.data;
  3417. }
  3418. else if (str.substr(0, 6) == "/radio") {
  3419. GamePacket p;
  3420. if (((PlayerInfo*)(peer->data))->radio) {
  3421. p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "You won't see broadcasts anymore."));
  3422. ((PlayerInfo*)(peer->data))->radio = false;
  3423. } else {
  3424. p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "You will now see broadcasts again."));
  3425. ((PlayerInfo*)(peer->data))->radio = true;
  3426. }
  3427.  
  3428.  
  3429. ENetPacket * packet = enet_packet_create(p.data,
  3430. p.len,
  3431. ENET_PACKET_FLAG_RELIABLE);
  3432.  
  3433.  
  3434. enet_peer_send(peer, 0, packet);
  3435. delete p.data;
  3436. //enet_host_flush(server);
  3437. }
  3438. else if (str.substr(0, 6) == "/reset"){
  3439. if (!isSuperAdmin(((PlayerInfo*)(peer->data))->rawName, ((PlayerInfo*)(peer->data))->tankIDPass)) break;
  3440. cout << "Restart from " << ((PlayerInfo*)(peer->data))->displayName << endl;
  3441. GamePacket p = packetEnd(appendInt(appendString(appendString(appendString(appendString(createPacket(), "OnAddNotification"), "interface/science_button.rttex"), "Restarting soon!"), "audio/mp3/suspended.mp3"), 0));
  3442. ENetPacket * packet = enet_packet_create(p.data,
  3443. p.len,
  3444. ENET_PACKET_FLAG_RELIABLE);
  3445. ENetPeer * currentPeer;
  3446. for (currentPeer = server->peers;
  3447. currentPeer < &server->peers[server->peerCount];
  3448. ++currentPeer)
  3449. {
  3450. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  3451. continue;
  3452. enet_peer_send(currentPeer, 0, packet);
  3453. }
  3454. delete p.data;
  3455. //enet_host_flush(server);
  3456. }
  3457.  
  3458.  
  3459. /*else if (str.substr(0, 7) == "/clear "){
  3460. if (!canClear(((PlayerInfo*)(peer->data))->rawName, ((PlayerInfo*)(peer->data))->tankIDPass)) continue;
  3461. cout << "World cleared by " << ((PlayerInfo*)(peer->data))->tankIDName << endl;
  3462. WorldInfo* wrld = getPlyersWorld(peer);
  3463. string wName = str.substr(4, cch.length() - 4 - 1);
  3464. for (auto & c : wName) c = toupper(c);
  3465. for (int i = 0; i < worlds.size(); i++)
  3466. {
  3467. if (wrld == NULL) continue;
  3468. if (wName == wrld->name)
  3469. {
  3470. worlds.at(i) = generateWorld(wrld->name, wrld->width, wrld->height);
  3471. ENetPeer * currentPeer;
  3472. for (currentPeer = server->peers;
  3473. currentPeer < &server->peers[server->peerCount];
  3474. ++currentPeer)
  3475. {
  3476. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  3477. continue;
  3478. if (((PlayerInfo*)(currentPeer->data))->currentWorld == wrld->name)
  3479. {
  3480. sendWorld(currentPeer, &worlds.at(i));
  3481.  
  3482.  
  3483. int x = 3040;
  3484. int y = 736;
  3485.  
  3486.  
  3487. for (int j = 0; j < worlds.at(i).width*worlds.at(i).height; j++)
  3488. {
  3489. if (worlds.at(i).items[j].foreground == 6) {
  3490. x = (j%worlds.at(i).width) * 32;
  3491. y = (j / worlds.at(i).width) * 32;
  3492. }
  3493. }
  3494. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnSpawn"), "spawn|avatar\nnetID|" + std::to_string(cId) + "\nuserID|" + std::to_string(cId) + "\ncolrect|0|0|20|30\nposXY|" + std::to_string(x) + "|" + std::to_string(y) + "\nname|``" + ((PlayerInfo*)(currentPeer->data))->tankIDName + "``\ncountry|" + ((PlayerInfo*)(currentPeer->data))->country + "\ninvis|0\nmstate|0\nsmstate|0\ntype|local\n"));
  3495. //for (int i = 0; i < p.len; i++) cout << (int)*(p.data + i) << " ";
  3496. ENetPacket * packet = enet_packet_create(p.data,
  3497. p.len,
  3498. ENET_PACKET_FLAG_RELIABLE);
  3499. enet_peer_send(currentPeer, 0, packet);
  3500.  
  3501. enet_host_flush(server);
  3502. delete p.data;
  3503. ((PlayerInfo*)(currentPeer->data))->netID = cId;
  3504. onPeerConnect(currentPeer);
  3505. cId++;
  3506.  
  3507.  
  3508. sendInventory(((PlayerInfo*)(event.peer->data))->inventory);
  3509. }
  3510.  
  3511.  
  3512. }
  3513. enet_host_flush(server);
  3514. }
  3515. }
  3516. }
  3517. else if (str.substr(0, 6) == "/clear"){
  3518. if (!canClear(((PlayerInfo*)(peer->data))->rawName, ((PlayerInfo*)(peer->data))->tankIDPass)) continue;
  3519. cout << "World cleared by " << ((PlayerInfo*)(peer->data))->tankIDName << endl;
  3520. WorldInfo* wrld = getPlyersWorld(peer);
  3521. for (int i = 0; i < worlds.size(); i++)
  3522. {
  3523. if (wrld == NULL) continue;
  3524. if (&worlds.at(i) == wrld)
  3525. {
  3526. worlds.at(i) = generateWorld(wrld->name, wrld->width, wrld->height);
  3527. ENetPeer * currentPeer;
  3528. for (currentPeer = server->peers;
  3529. currentPeer < &server->peers[server->peerCount];
  3530. ++currentPeer)
  3531. {
  3532. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  3533. continue;
  3534. if (((PlayerInfo*)(currentPeer->data))->currentWorld == wrld->name)
  3535. {
  3536. sendWorld(currentPeer, &worlds.at(i));
  3537.  
  3538.  
  3539. int x = 3040;
  3540. int y = 736;
  3541.  
  3542.  
  3543. for (int j = 0; j < worlds.at(i).width*worlds.at(i).height; j++)
  3544. {
  3545. if (worlds.at(i).items[j].foreground == 6) {
  3546. x = (j%worlds.at(i).width) * 32;
  3547. y = (j / worlds.at(i).width) * 32;
  3548. }
  3549. }
  3550. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnSpawn"), "spawn|avatar\nnetID|" + std::to_string(cId) + "\nuserID|" + std::to_string(cId) + "\ncolrect|0|0|20|30\nposXY|" + std::to_string(x) + "|" + std::to_string(y) + "\nname|``" + ((PlayerInfo*)(currentPeer->data))->tankIDName + "``\ncountry|" + ((PlayerInfo*)(currentPeer->data))->country + "\ninvis|0\nmstate|0\nsmstate|0\ntype|local\n"));
  3551. //for (int i = 0; i < p.len; i++) cout << (int)*(p.data + i) << " ";
  3552. ENetPacket * packet = enet_packet_create(p.data,
  3553. p.len,
  3554. ENET_PACKET_FLAG_RELIABLE);
  3555. enet_peer_send(currentPeer, 0, packet);
  3556.  
  3557. enet_host_flush(server);
  3558. delete p.data;
  3559. ((PlayerInfo*)(currentPeer->data))->netID = cId;
  3560. onPeerConnect(currentPeer);
  3561. cId++;
  3562.  
  3563.  
  3564. sendInventory(((PlayerInfo*)(event.peer->data))->inventory);
  3565. }
  3566.  
  3567. }
  3568. enet_host_flush(server);
  3569. }
  3570. }
  3571. }*/
  3572. else if (str == "/unmod")
  3573. {
  3574. ((PlayerInfo*)(peer->data))->canWalkInBlocks = false;
  3575. sendState(peer);
  3576. /*PlayerMoving data;
  3577. data.packetType = 0x14;
  3578. data.characterState = 0x0; // animation
  3579. data.x = 1000;
  3580. data.y = 1;
  3581. data.punchX = 0;
  3582. data.punchY = 0;
  3583. data.XSpeed = 300;
  3584. data.YSpeed = 600;
  3585. data.netID = ((PlayerInfo*)(peer->data))->netID;
  3586. data.plantingTree = 0x0;
  3587. SendPacketRaw(4, packPlayerMoving(&data), 56, 0, peer, ENET_PACKET_FLAG_RELIABLE);*/
  3588. }
  3589. else if (str == "/alt") {
  3590. GamePacket p2 = packetEnd(appendInt(appendString(createPacket(), "OnSetBetaMode"), 1));
  3591. ENetPacket * packet2 = enet_packet_create(p2.data,
  3592. p2.len,
  3593. ENET_PACKET_FLAG_RELIABLE);
  3594. enet_peer_send(peer, 0, packet2);
  3595. delete p2.data;
  3596. //enet_host_flush(server);
  3597. }
  3598. else
  3599. if (str == "/inventory")
  3600. {
  3601. sendInventory(peer, ((PlayerInfo*)(peer->data))->inventory);
  3602. } else
  3603. if (str.substr(0,6) == "/item ")
  3604. {
  3605. PlayerInventory inventory;
  3606. InventoryItem item;
  3607. item.itemID = atoi(str.substr(6, cch.length() - 6 - 1).c_str());
  3608. item.itemCount = 200;
  3609. inventory.items.push_back(item);
  3610. item.itemCount = 1;
  3611. item.itemID = 18;
  3612. inventory.items.push_back(item);
  3613. item.itemID = 32;
  3614. inventory.items.push_back(item);
  3615. sendInventory(peer, inventory);
  3616. } else
  3617. if (str.substr(0, 6) == "/team ")
  3618. {
  3619. int val = 0;
  3620. val = atoi(str.substr(6, cch.length() - 6 - 1).c_str());
  3621. PlayerMoving data;
  3622. //data.packetType = 0x14;
  3623. data.packetType = 0x1B;
  3624. //data.characterState = 0x924; // animation
  3625. data.characterState = 0x0; // animation
  3626. data.x = 0;
  3627. data.y = 0;
  3628. data.punchX = val;
  3629. data.punchY = 0;
  3630. data.XSpeed = 0;
  3631. data.YSpeed = 0;
  3632. data.netID = ((PlayerInfo*)(peer->data))->netID;
  3633. data.plantingTree = 0;
  3634. SendPacketRaw(4, packPlayerMoving(&data), 56, 0, peer, ENET_PACKET_FLAG_RELIABLE);
  3635.  
  3636.  
  3637. } else
  3638. if (str.substr(0, 7) == "/color ")
  3639. {
  3640. ((PlayerInfo*)(peer->data))->skinColor = atoi(str.substr(6, cch.length() - 6 - 1).c_str());
  3641. sendClothes(peer);
  3642. }
  3643. if (str.substr(0, 4) == "/who")
  3644. {
  3645. sendWho(peer);
  3646.  
  3647.  
  3648. }
  3649. if (str.length() && str[0] == '/')
  3650. {
  3651. sendAction(peer, ((PlayerInfo*)(peer->data))->netID, str);
  3652. } else if (str.length()>0)
  3653. {
  3654. if (((PlayerInfo*)(peer->data))->taped == false) {
  3655. sendChatMessage(peer, ((PlayerInfo*)(peer->data))->netID, str);
  3656. }
  3657. else {
  3658. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4Can't talk while youre duct-taped!"));
  3659. ENetPacket * packet = enet_packet_create(p.data,
  3660. p.len,
  3661. ENET_PACKET_FLAG_RELIABLE);
  3662. enet_peer_send(peer, 0, packet);
  3663. delete p.data;
  3664. }
  3665. }
  3666.  
  3667. }
  3668. if (!((PlayerInfo*)(event.peer->data))->isIn)
  3669. {
  3670. GamePacket p = packetEnd(appendString(appendString(appendString(appendString(appendInt(appendString(createPacket(), "OnSuperMainStartAcceptLogonHrdxs47254722215a"), 840038818), "cdn.growtopiagame.com"), "cache/"), "cc.cz.madkite.freedom org.aqua.gg idv.aqua.bulldog com.cih.gamecih2 com.cih.gamecih com.cih.game_cih cn.maocai.gamekiller com.gmd.speedtime org.dax.attack com.x0.strai.frep com.x0.strai.free org.cheatengine.cegui org.sbtools.gamehack com.skgames.traffikrider org.sbtoods.gamehaca com.skype.ralder org.cheatengine.cegui.xx.multi1458919170111 com.prohiro.macro me.autotouch.autotouch com.cygery.repetitouch.free com.cygery.repetitouch.pro com.proziro.zacro com.slash.gamebuster"), "proto=42|choosemusic=audio/mp3/about_theme.mp3|active_holiday=0|"));
  3671. //for (int i = 0; i < p.len; i++) cout << (int)*(p.data + i) << " ";
  3672. ENetPacket * packet = enet_packet_create(p.data,
  3673. p.len,
  3674. ENET_PACKET_FLAG_RELIABLE);
  3675. enet_peer_send(peer, 0, packet);
  3676.  
  3677. //enet_host_flush(server);
  3678. delete p.data;
  3679. std::stringstream ss(GetTextPointerFromPacket(event.packet));
  3680. std::string to;
  3681. while (std::getline(ss, to, '\n')){
  3682. string id = to.substr(0, to.find("|"));
  3683. string act = to.substr(to.find("|") + 1, to.length() - to.find("|") - 1);
  3684. if (id == "tankIDName")
  3685. {
  3686. ((PlayerInfo*)(event.peer->data))->tankIDName = act;
  3687. ((PlayerInfo*)(event.peer->data))->haveGrowId = true;
  3688. }
  3689. else if(id == "tankIDPass")
  3690. {
  3691. ((PlayerInfo*)(event.peer->data))->tankIDPass = act;
  3692. }
  3693. else if(id == "requestedName")
  3694. {
  3695. ((PlayerInfo*)(event.peer->data))->requestedName = act;
  3696. }
  3697. else if (id == "country")
  3698. {
  3699. ((PlayerInfo*)(event.peer->data))->country = act;
  3700. }
  3701. }
  3702. if (!((PlayerInfo*)(event.peer->data))->haveGrowId)
  3703. {
  3704. ((PlayerInfo*)(event.peer->data))->rawName = "";
  3705. ((PlayerInfo*)(event.peer->data))->displayName = "Fake " + PlayerDB::fixColors(((PlayerInfo*)(event.peer->data))->requestedName.substr(0, ((PlayerInfo*)(event.peer->data))->requestedName.length()>15?15:((PlayerInfo*)(event.peer->data))->requestedName.length()));
  3706. }
  3707. else {
  3708. ((PlayerInfo*)(event.peer->data))->rawName = PlayerDB::getProperName(((PlayerInfo*)(event.peer->data))->tankIDName);
  3709. #ifdef REGISTRATION
  3710. int logStatus = PlayerDB::playerLogin(peer, ((PlayerInfo*)(event.peer->data))->rawName, ((PlayerInfo*)(event.peer->data))->tankIDPass);
  3711. if (logStatus == 1) {
  3712. bool b = false;
  3713. std::ifstream ifs("players/" + ((PlayerInfo*)(peer->data))->rawName + ".json");
  3714. if (ifs.is_open()) {
  3715. json x;
  3716. ifs >> x;
  3717. if (x["banned"])
  3718. b = true;
  3719. }
  3720. if (b) {
  3721. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4This account is banned!"));
  3722. ENetPacket * packet = enet_packet_create(p.data,
  3723. p.len,
  3724. ENET_PACKET_FLAG_RELIABLE);
  3725. enet_peer_send(peer, 0, packet);
  3726. delete p.data;
  3727. enet_peer_disconnect_later(peer, 0);
  3728. }
  3729. else {
  3730. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`rYou have successfully logged into your account!``"));
  3731. ENetPacket * packet = enet_packet_create(p.data,
  3732. p.len,
  3733. ENET_PACKET_FLAG_RELIABLE);
  3734. enet_peer_send(peer, 0, packet);
  3735. delete p.data;
  3736. ((PlayerInfo*)(event.peer->data))->displayName = ((PlayerInfo*)(event.peer->data))->tankIDName;
  3737. }
  3738. }
  3739. else {
  3740. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`rWrong username or password!``"));
  3741. ENetPacket * packet = enet_packet_create(p.data,
  3742. p.len,
  3743. ENET_PACKET_FLAG_RELIABLE);
  3744. enet_peer_send(peer, 0, packet);
  3745. delete p.data;
  3746. enet_peer_disconnect_later(peer, 0);
  3747. }
  3748. #else
  3749.  
  3750. ((PlayerInfo*)(event.peer->data))->displayName = PlayerDB::fixColors(((PlayerInfo*)(event.peer->data))->tankIDName.substr(0, ((PlayerInfo*)(event.peer->data))->tankIDName.length()>18 ? 18 : ((PlayerInfo*)(event.peer->data))->tankIDName.length()));
  3751. if (((PlayerInfo*)(event.peer->data))->displayName.length() < 3) ((PlayerInfo*)(event.peer->data))->displayName = "Person that doesn't know how the name looks!";
  3752. #endif
  3753. }
  3754. for (char c : ((PlayerInfo*)(event.peer->data))->displayName) if (c < 0x20 || c>0x7A) ((PlayerInfo*)(event.peer->data))->displayName = "Bad characters in name, remove them!";
  3755.  
  3756. if (((PlayerInfo*)(event.peer->data))->country.length() > 4)
  3757. {
  3758. ((PlayerInfo*)(event.peer->data))->country = "us";
  3759. }
  3760. if (getAdminLevel(((PlayerInfo*)(event.peer->data))->rawName, ((PlayerInfo*)(event.peer->data))->tankIDPass) > 0)
  3761. {
  3762. ((PlayerInfo*)(event.peer->data))->country = "../cash_icon_overlay";
  3763. }
  3764. /*GamePacket p3= packetEnd(appendString(appendString(createPacket(), "OnRequestWorldSelectMenu"), "default|GO FOR IT\nadd_button|Showing: `wFake Worlds``|_catselect_|0.6|3529161471|\nadd_floater|Subscribe|5|0.55|3529161471\nadd_floater|Growtopia|4|0.52|4278190335\nadd_floater|Noobs|150|0.49|3529161471\nadd_floater|...|3|0.49|3529161471\nadd_floater|`6:O :O :O``|2|0.46|3529161471\nadd_floater|SEEMS TO WORK|2|0.46|3529161471\nadd_floater|?????|1|0.43|3529161471\nadd_floater|KEKEKEKEK|13|0.7|3417414143\n"));
  3765. //for (int i = 0; i < p.len; i++) cout << (int)*(p.data + i) << " ";
  3766. ENetPacket * packet3 = enet_packet_create(p3.data,
  3767. p3.len,
  3768. ENET_PACKET_FLAG_RELIABLE);
  3769. enet_peer_send(peer, 0, packet3);
  3770. enet_host_flush(server);*/
  3771.  
  3772.  
  3773. GamePacket p2 = packetEnd(appendString(appendString(appendInt(appendString(createPacket(), "SetHasGrowID"), ((PlayerInfo*)(event.peer->data))->haveGrowId), ((PlayerInfo*)(peer->data))->tankIDName), ((PlayerInfo*)(peer->data))->tankIDPass));
  3774. ENetPacket * packet2 = enet_packet_create(p2.data,
  3775. p2.len,
  3776. ENET_PACKET_FLAG_RELIABLE);
  3777. enet_peer_send(peer, 0, packet2);
  3778. delete p2.data;
  3779.  
  3780.  
  3781.  
  3782. }
  3783. string pStr = GetTextPointerFromPacket(event.packet);
  3784. //if (strcmp(GetTextPointerFromPacket(event.packet), "action|enter_game\n") == 0 && !((PlayerInfo*)(event.peer->data))->isIn)
  3785. if(pStr.substr(0, 17) == "action|enter_game" && !((PlayerInfo*)(event.peer->data))->isIn)
  3786. {
  3787. #ifdef TOTAL_LOG
  3788. cout << "And we are in!" << endl;
  3789. #endif
  3790. ENetPeer* currentPeer;
  3791. ((PlayerInfo*)(event.peer->data))->isIn = true;
  3792. /*for (currentPeer = server->peers;
  3793. currentPeer < &server->peers[server->peerCount];
  3794. ++currentPeer)
  3795. {
  3796. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  3797. continue;
  3798.  
  3799.  
  3800. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "Player `o" + ((PlayerInfo*)(event.peer->data))->tankIDName + "`o just entered the game..."));
  3801. ENetPacket * packet = enet_packet_create(p.data,
  3802. p.len,
  3803. ENET_PACKET_FLAG_RELIABLE);
  3804. enet_peer_send(currentPeer, 0, packet);
  3805.  
  3806. enet_host_flush(server);
  3807. delete p.data;
  3808. }*/
  3809. sendWorldOffers(peer);
  3810. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "Welcome to GrowtopiaJS.There are "+std::to_string(count)+" people online out of 1024 limit."));
  3811. ENetPacket * packet = enet_packet_create(p.data,
  3812. p.len,
  3813. ENET_PACKET_FLAG_RELIABLE);
  3814. enet_peer_send(peer, 0, packet);
  3815.  
  3816. //enet_host_flush(server);
  3817. delete p.data;
  3818. PlayerInventory inventory;
  3819. for (int i = 0; i < 200; i++)
  3820. {
  3821. InventoryItem it;
  3822. it.itemID = (i * 2) + 2;
  3823. it.itemCount = 200;
  3824. inventory.items.push_back(it);
  3825. }
  3826. ((PlayerInfo*)(event.peer->data))->inventory = inventory;
  3827.  
  3828.  
  3829. {
  3830. //GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnDialogRequest"), "set_default_color|`o\n\nadd_label_with_icon|big|`wThe Growtopia Gazette``|left|5016|\n\nadd_spacer|small|\n\nadd_image_button|banner|interface/large/news_banner.rttex|noflags|||\n\nadd_spacer|small|\n\nadd_textbox|`wSeptember 10:`` `5Surgery Stars end!``|left|\n\nadd_spacer|small|\n\n\n\nadd_textbox|Hello Growtopians,|left|\n\nadd_spacer|small|\n\n\n\nadd_textbox|Surgery Stars is over! We hope you enjoyed it and claimed all your well-earned Summer Tokens!|left|\n\nadd_spacer|small|\n\nadd_spacer|small|\n\nadd_textbox|As we announced earlier, this month we are releasing the feature update a bit later, as we're working on something really cool for the monthly update and we're convinced that the wait will be worth it!|left|\n\nadd_spacer|small|\n\nadd_textbox|Check the Forum here for more information!|left|\n\nadd_spacer|small|\n\nadd_url_button|comment|`wSeptember Updates Delay``|noflags|https://www.growtopiagame.com/forums/showthread.php?510657-September-Update-Delay&p=3747656|Open September Update Delay Announcement?|0|0|\n\nadd_spacer|small|\n\nadd_spacer|small|\n\nadd_textbox|Also, we're glad to invite you to take part in our official Growtopia survey!|left|\n\nadd_spacer|small|\n\nadd_url_button|comment|`wTake Survey!``|noflags|https://ubisoft.ca1.qualtrics.com/jfe/form/SV_1UrCEhjMO7TKXpr?GID=26674|Open the browser to take the survey?|0|0|\n\nadd_spacer|small|\n\nadd_textbox|Click on the button above and complete the survey to contribute your opinion to the game and make Growtopia even better! Thanks in advance for taking the time, we're looking forward to reading your feedback!|left|\n\nadd_spacer|small|\n\nadd_spacer|small|\n\nadd_textbox|And for those who missed PAW, we made a special video sneak peek from the latest PAW fashion show, check it out on our official YouTube channel! Yay!|left|\n\nadd_spacer|small|\n\nadd_url_button|comment|`wPAW 2018 Fashion Show``|noflags|https://www.youtube.com/watch?v=5i0IcqwD3MI&feature=youtu.be|Open the Growtopia YouTube channel for videos and tutorials?|0|0|\n\nadd_spacer|small|\n\nadd_textbox|Lastly, check out other September updates:|left|\n\nadd_spacer|small|\n\nadd_label_with_icon|small|IOTM: The Sorcerer's Tunic of Mystery|left|24|\n\nadd_label_with_icon|small|New Legendary Summer Clash Branch|left|24|\n\nadd_spacer|small|\n\nadd_textbox|`$- The Growtopia Team``|left|\n\nadd_spacer|small|\n\nadd_spacer|small|\n\n\n\n\n\nadd_url_button|comment|`wOfficial YouTube Channel``|noflags|https://www.youtube.com/c/GrowtopiaOfficial|Open the Growtopia YouTube channel for videos and tutorials?|0|0|\n\nadd_url_button|comment|`wSeptember's IOTM: `8Sorcerer's Tunic of Mystery!````|noflags|https://www.growtopiagame.com/forums/showthread.php?450065-Item-of-the-Month&p=3392991&viewfull=1#post3392991|Open the Growtopia website to see item of the month info?|0|0|\n\nadd_spacer|small|\n\nadd_label_with_icon|small|`4WARNING:`` `5Drop games/trust tests`` and betting games (like `5Casinos``) are not allowed and will result in a ban!|left|24|\n\nadd_label_with_icon|small|`4WARNING:`` Using any kind of `5hacked client``, `5spamming/text pasting``, or `5bots`` (even with an alt) will likely result in losing `5ALL`` your accounts. Seriously.|left|24|\n\nadd_label_with_icon|small|`4WARNING:`` `5NEVER enter your GT password on a website (fake moderator apps, free gemz, etc) - it doesn't work and you'll lose all your stuff!|left|24|\n\nadd_spacer|small|\n\nadd_url_button|comment|`wGrowtopia on Facebook``|noflags|http://growtopiagame.com/facebook|Open the Growtopia Facebook page in your browser?|0|0|\n\nadd_spacer|small|\n\nadd_button|rules|`wHelp - Rules - Privacy Policy``|noflags|0|0|\n\n\nadd_quick_exit|\n\nadd_spacer|small|\nadd_url_button|comment|`wVisit Growtopia Forums``|noflags|http://www.growtopiagame.com/forums|Visit the Growtopia forums?|0|0|\nadd_spacer|small|\nadd_url_button||`wWOTD: `1THELOSTGOLD`` by `#iWasToD````|NOFLAGS|OPENWORLD|THELOSTGOLD|0|0|\nadd_spacer|small|\nadd_url_button||`wVOTW: `1Yodeling Kid - Growtopia Animation``|NOFLAGS|https://www.youtube.com/watch?v=UMoGmnFvc58|Watch 'Yodeling Kid - Growtopia Animation' by HyerS on YouTube?|0|0|\nend_dialog|gazette||OK|"));
  3831. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnDialogRequest"), "set_default_color|`o\n\nadd_label_with_icon|big|`wThe Growtopia Gazette``|left|5016|\n\nadd_spacer|small|\nadd_label_with_icon|small|`4WARNING:`` `5Worlds (and accounts)`` might be deleted at any time if database issues appear (once per day or week).|left|4|\nadd_label_with_icon|small|`4WARNING:`` `5Accounts`` are in beta, bugs may appear and they will be probably deleted often, because of new account updates, which will cause database incompatibility.|left|4|\nadd_spacer|small|\n\nadd_url_button||``Watch: `1Watch a video about GT Private Server``|NOFLAGS|https://www.youtube.com/watch?v=_3avlDDYBBY|Open link?|0|0|\nadd_url_button||``Channel: `1Watch Growtopia Noobs' channel``|NOFLAGS|https://www.youtube.com/channel/UCLXtuoBlrXFDRtFU8vPy35g|Open link?|0|0|\nadd_url_button||``Items: `1Item database by Nenkai``|NOFLAGS|https://raw.githubusercontent.com/Nenkai/GrowtopiaItemDatabase/master/GrowtopiaItemDatabase/CoreData.txt|Open link?|0|0|\nadd_url_button||``Discord: `1GT Private Server Discord``|NOFLAGS|https://discord.gg/8WUTs4v|Open the link?|0|0|\nadd_quick_exit|\nadd_button|chc0|Close|noflags|0|0|\nnend_dialog|gazette||OK|"));
  3832. ENetPacket * packet = enet_packet_create(p.data,
  3833. p.len,
  3834. ENET_PACKET_FLAG_RELIABLE);
  3835. enet_peer_send(peer, 0, packet);
  3836.  
  3837.  
  3838. //enet_host_flush(server);
  3839. delete p.data;
  3840. }
  3841. }
  3842. if (strcmp(GetTextPointerFromPacket(event.packet), "action|refresh_item_data\n") == 0)
  3843. {
  3844. if (itemsDat != NULL) {
  3845. ENetPacket * packet = enet_packet_create(itemsDat,
  3846. itemsDatSize + 60,
  3847. ENET_PACKET_FLAG_RELIABLE);
  3848. enet_peer_send(peer, 0, packet);
  3849. ((PlayerInfo*)(peer->data))->isUpdating = true;
  3850. enet_peer_disconnect_later(peer, 0);
  3851. //enet_host_flush(server);
  3852. }
  3853. // TODO FIX refresh_item_data ^^^^^^^^^^^^^^
  3854. }
  3855. break;
  3856. }
  3857. default:
  3858. cout << "Unknown packet type " << messageType << endl;
  3859. break;
  3860. case 3:
  3861. {
  3862. //cout << GetTextPointerFromPacket(event.packet) << endl;
  3863. std::stringstream ss(GetTextPointerFromPacket(event.packet));
  3864. std::string to;
  3865. bool isJoinReq = false;
  3866. while (std::getline(ss, to, '\n')) {
  3867. string id = to.substr(0, to.find("|"));
  3868. string act = to.substr(to.find("|") + 1, to.length() - to.find("|") - 1);
  3869. if (id == "name" && isJoinReq)
  3870. {
  3871. #ifdef TOTAL_LOG
  3872. cout << "Entering some world..." << endl;
  3873. #endif
  3874. try {
  3875. WorldInfo info = worldDB.get(act);
  3876.  
  3877.  
  3878.  
  3879.  
  3880.  
  3881. sendWorld(peer, &info);
  3882. /*string asdf = "0400000004A7379237BB2509E8E0EC04F8720B050000000000000000FBBB0000010000007D920100FDFDFDFD04000000040000000000000000000000070000000000"; // 0400000004A7379237BB2509E8E0EC04F8720B050000000000000000FBBB0000010000007D920100FDFDFDFD04000000040000000000000000000000080000000000000000000000000000000000000000000000000000000000000048133A0500000000BEBB0000070000000000
  3883. string worldName = "TEST";
  3884. int xSize=100;
  3885. int ySize=60;
  3886. int square = xSize*ySize;
  3887. __int16 nameLen = worldName.length();
  3888. int payloadLen = asdf.length() / 2;
  3889. int dataLen = payloadLen + 2 + nameLen + 12 + (square * 8)+4;
  3890. BYTE* data = new BYTE[dataLen];
  3891. for (int i = 0; i < asdf.length(); i += 2)
  3892. {
  3893. char x = ch2n(asdf[i]);
  3894. x = x << 4;
  3895. x += ch2n(asdf[i + 1]);
  3896. memcpy(data + (i / 2), &x, 1);
  3897. }
  3898. int zero = 0;
  3899. __int16 item = 0;
  3900. int smth = 0;
  3901. for (int i = 0; i < square * 8; i += 4) memcpy(data + payloadLen + i + 14 + nameLen, &zero, 4);
  3902. for (int i = 0; i < square * 8; i += 8) memcpy(data + payloadLen + i + 14 + nameLen, &item, 2);
  3903. memcpy(data + payloadLen, &nameLen, 2);
  3904. memcpy(data + payloadLen + 2, worldName.c_str(), nameLen);
  3905. memcpy(data + payloadLen + 2 + nameLen, &xSize, 4);
  3906. memcpy(data + payloadLen + 6 + nameLen, &ySize, 4);
  3907. memcpy(data + payloadLen + 10 + nameLen, &square, 4);
  3908. for (int i = 0; i < 1700; i++) {
  3909. __int16 bed = 100;
  3910. memcpy(data + payloadLen + (i * 8) + 14 + nameLen + (8 * 100 * 37), &bed, 2);
  3911. }
  3912. for (int i = 0; i < 600; i++) {
  3913. __int16 bed = 8;
  3914. memcpy(data + payloadLen + (i*8) + 14 + nameLen + (8*100*54), &bed, 2);
  3915. }
  3916. memcpy(data + dataLen-4, &smth, 4);
  3917. ENetPacket * packet2 = enet_packet_create(data,
  3918. dataLen,
  3919. ENET_PACKET_FLAG_RELIABLE);
  3920. enet_peer_send(peer, 0, packet2);
  3921. enet_host_flush(server);*/
  3922. if (info.nuked) {
  3923. if (getAdminLevel(((PlayerInfo*)(peer->data))->rawName, ((PlayerInfo*)(peer->data))->tankIDPass) == 0) {
  3924. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnRemove"), "netID|" + std::to_string(((PlayerInfo*)(event.peer->data))->netID) + "\n"));
  3925. ENetPacket * packet = enet_packet_create(p.data,
  3926. p.len,
  3927. ENET_PACKET_FLAG_RELIABLE);
  3928. enet_peer_send(peer, 0, packet);
  3929.  
  3930.  
  3931. ((PlayerInfo*)(peer->data))->currentWorld = "EXIT";
  3932. sendWorldOffers(peer);
  3933. {
  3934. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`4This world is nuked!"));
  3935. ENetPacket * packet = enet_packet_create(p.data,
  3936. p.len,
  3937. ENET_PACKET_FLAG_RELIABLE);
  3938. enet_peer_send(peer, 0, packet);
  3939. delete p.data;
  3940. }
  3941. }
  3942. }
  3943.  
  3944.  
  3945.  
  3946.  
  3947. int x = 3040;
  3948. int y = 736;
  3949.  
  3950.  
  3951. for (int j = 0; j < info.width*info.height; j++)
  3952. {
  3953. if (info.items[j].foreground == 6) {
  3954. x = (j%info.width) * 32;
  3955. y = (j / info.width) * 32;
  3956. }
  3957. }
  3958. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnSpawn"), "spawn|avatar\nnetID|" + std::to_string(cId) + "\nuserID|" + std::to_string(cId) + "\ncolrect|0|0|20|30\nposXY|" + std::to_string(x) + "|" + std::to_string(y) + "\nname|``" + ((PlayerInfo*)(event.peer->data))->displayName + "``\ncountry|" + ((PlayerInfo*)(event.peer->data))->country + "\ninvis|0\nmstate|0\nsmstate|0\ntype|local\n"));
  3959. //for (int i = 0; i < p.len; i++) cout << (int)*(p.data + i) << " ";
  3960. ENetPacket * packet = enet_packet_create(p.data,
  3961. p.len,
  3962. ENET_PACKET_FLAG_RELIABLE);
  3963. enet_peer_send(peer, 0, packet);
  3964. //enet_host_flush(server);
  3965. delete p.data;
  3966. ((PlayerInfo*)(event.peer->data))->netID = cId;
  3967. onPeerConnect(peer);
  3968. cId++;
  3969.  
  3970.  
  3971. sendInventory(peer, ((PlayerInfo*)(event.peer->data))->inventory);
  3972.  
  3973.  
  3974.  
  3975.  
  3976.  
  3977.  
  3978. /*int resx = 95;
  3979. int resy = 23;*/
  3980.  
  3981.  
  3982. /*for (int i = 0; i < world.width*world.height; i++)
  3983. {
  3984. if (world.items[i].foreground == 6) {
  3985. resx = i%world.width;
  3986. resy = i / world.width;
  3987. }
  3988. }
  3989.  
  3990.  
  3991. GamePacket p2 = packetEnd(appendInt(appendString(createPacket(), "SetRespawnPos"), resx + (world.width*resy)));
  3992. memcpy(p2.data + 8, &(((PlayerInfo*)(event.peer->data))->netID), 4);
  3993. ENetPacket * packet2 = enet_packet_create(p2.data,
  3994. p2.len,
  3995. ENET_PACKET_FLAG_RELIABLE);
  3996. enet_peer_send(peer, 0, packet);
  3997. enet_host_flush(server);*/
  3998. }
  3999. catch (int e) {
  4000. if (e == 1) {
  4001. ((PlayerInfo*)(peer->data))->currentWorld = "EXIT";
  4002. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "You have exited the world."));
  4003. ENetPacket * packet = enet_packet_create(p.data,
  4004. p.len,
  4005. ENET_PACKET_FLAG_RELIABLE);
  4006. enet_peer_send(peer, 0, packet);
  4007. delete p.data;
  4008. //enet_host_flush(server);
  4009. }
  4010. else if (e == 2) {
  4011. ((PlayerInfo*)(peer->data))->currentWorld = "EXIT";
  4012. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "You have entered bad characters in the world name!"));
  4013. ENetPacket * packet = enet_packet_create(p.data,
  4014. p.len,
  4015. ENET_PACKET_FLAG_RELIABLE);
  4016. enet_peer_send(peer, 0, packet);
  4017. delete p.data;
  4018. //enet_host_flush(server);
  4019. }
  4020. else if (e == 3) {
  4021. ((PlayerInfo*)(peer->data))->currentWorld = "EXIT";
  4022. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "Exit from what? Click back if you're done playing."));
  4023. ENetPacket * packet = enet_packet_create(p.data,
  4024. p.len,
  4025. ENET_PACKET_FLAG_RELIABLE);
  4026. enet_peer_send(peer, 0, packet);
  4027. delete p.data;
  4028. //enet_host_flush(server);
  4029. }
  4030. else {
  4031. ((PlayerInfo*)(peer->data))->currentWorld = "EXIT";
  4032. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "I know this menu is magical and all, but it has its limitations! You can't visit this world!"));
  4033. ENetPacket * packet = enet_packet_create(p.data,
  4034. p.len,
  4035. ENET_PACKET_FLAG_RELIABLE);
  4036. enet_peer_send(peer, 0, packet);
  4037. delete p.data;
  4038. //enet_host_flush(server);
  4039. }
  4040. }
  4041. }
  4042. if (id == "action")
  4043. {
  4044.  
  4045.  
  4046. if (act == "join_request")
  4047. {
  4048. isJoinReq = true;
  4049. }
  4050. if (act == "quit_to_exit")
  4051. {
  4052. sendPlayerLeave(peer, (PlayerInfo*)(event.peer->data));
  4053. ((PlayerInfo*)(peer->data))->currentWorld = "EXIT";
  4054. sendWorldOffers(peer);
  4055.  
  4056.  
  4057. }
  4058. if (act == "quit")
  4059. {
  4060. enet_peer_disconnect_later(peer, 0);
  4061. }
  4062. }
  4063. }
  4064. break;
  4065. }
  4066. case 4:
  4067. {
  4068. {
  4069. BYTE* tankUpdatePacket = GetStructPointerFromTankPacket(event.packet);
  4070.  
  4071. if (tankUpdatePacket)
  4072. {
  4073. PlayerMoving* pMov = unpackPlayerMoving(tankUpdatePacket);
  4074. if (((PlayerInfo*)(event.peer->data))->isGhost) {
  4075. ((PlayerInfo*)(event.peer->data))->isInvisible = true;
  4076. ((PlayerInfo*)(event.peer->data))->x1 = pMov->x;
  4077. ((PlayerInfo*)(event.peer->data))->y1 = pMov->y;
  4078. pMov->x = -1000000;
  4079. pMov->y = -1000000;
  4080. }
  4081.  
  4082. switch (pMov->packetType)
  4083. {
  4084. case 0:
  4085. ((PlayerInfo*)(event.peer->data))->x = pMov->x;
  4086. ((PlayerInfo*)(event.peer->data))->y = pMov->y;
  4087. ((PlayerInfo*)(event.peer->data))->isRotatedLeft = pMov->characterState & 0x10;
  4088. sendPData(peer, pMov);
  4089. if (!((PlayerInfo*)(peer->data))->joinClothesUpdated)
  4090. {
  4091. ((PlayerInfo*)(peer->data))->joinClothesUpdated = true;
  4092. updateAllClothes(peer);
  4093. }
  4094. break;
  4095.  
  4096.  
  4097. default:
  4098. break;
  4099. }
  4100. PlayerMoving *data2 = unpackPlayerMoving(tankUpdatePacket);
  4101. //cout << data2->packetType << endl;
  4102. if (data2->packetType == 11)
  4103. {
  4104. //cout << pMov->x << ";" << pMov->y << ";" << pMov->plantingTree << ";" << pMov->punchX << endl;
  4105. //sendDrop(((PlayerInfo*)(event.peer->data))->netID, ((PlayerInfo*)(event.peer->data))->x, ((PlayerInfo*)(event.peer->data))->y, pMov->punchX, 1, 0);
  4106. // lets take item
  4107. }
  4108. if (data2->packetType == 7)
  4109. {
  4110. //cout << pMov->x << ";" << pMov->y << ";" << pMov->plantingTree << ";" << pMov->punchX << endl;
  4111. /*GamePacket p3 = packetEnd(appendString(appendString(createPacket(), "OnRequestWorldSelectMenu"), "default|GO FOR IT\nadd_button|Showing: `wFake Worlds``|_catselect_|0.6|3529161471|\nadd_floater|Subscribe|5|0.55|3529161471\nadd_floater|Growtopia|4|0.52|4278190335\nadd_floater|Noobs|150|0.49|3529161471\nadd_floater|...|3|0.49|3529161471\nadd_floater|`6:O :O :O``|2|0.46|3529161471\nadd_floater|SEEMS TO WORK|2|0.46|3529161471\nadd_floater|?????|1|0.43|3529161471\nadd_floater|KEKEKEKEK|13|0.7|3417414143\n"));
  4112. //for (int i = 0; i < p.len; i++) cout << (int)*(p.data + i) << " ";
  4113. ENetPacket * packet3 = enet_packet_create(p3.data,
  4114. p3.len,
  4115. ENET_PACKET_FLAG_RELIABLE);
  4116. enet_peer_send(peer, 0, packet3);
  4117. enet_host_flush(server);*/
  4118. sendPlayerLeave(peer, (PlayerInfo*)(event.peer->data));
  4119. sendWorldOffers(peer);
  4120. // lets take item
  4121. }
  4122. if (data2->packetType == 10)
  4123. {
  4124. //cout << pMov->x << ";" << pMov->y << ";" << pMov->plantingTree << ";" << pMov->punchX << ";" << pMov->punchY << ";" << pMov->characterState << endl;
  4125. ItemDefinition def;
  4126. try {
  4127. def = getItemDef(pMov->plantingTree);
  4128. }
  4129. catch (int e) {
  4130. goto END_CLOTHSETTER_FORCE;
  4131. }
  4132.  
  4133. switch (def.clothType) {
  4134. case 0:
  4135. if (((PlayerInfo*)(event.peer->data))->cloth0 == pMov->plantingTree)
  4136. {
  4137. ((PlayerInfo*)(event.peer->data))->cloth0 = 0;
  4138. break;
  4139. }
  4140. ((PlayerInfo*)(event.peer->data))->cloth0 = pMov->plantingTree;
  4141. break;
  4142. case 1:
  4143. if (((PlayerInfo*)(event.peer->data))->cloth1 == pMov->plantingTree)
  4144. {
  4145. ((PlayerInfo*)(event.peer->data))->cloth1 = 0;
  4146. break;
  4147. }
  4148. ((PlayerInfo*)(event.peer->data))->cloth1 = pMov->plantingTree;
  4149. break;
  4150. case 2:
  4151. if (((PlayerInfo*)(event.peer->data))->cloth2 == pMov->plantingTree)
  4152. {
  4153. ((PlayerInfo*)(event.peer->data))->cloth2 = 0;
  4154. break;
  4155. }
  4156. ((PlayerInfo*)(event.peer->data))->cloth2 = pMov->plantingTree;
  4157. break;
  4158. case 3:
  4159. if (((PlayerInfo*)(event.peer->data))->cloth3 == pMov->plantingTree)
  4160. {
  4161. ((PlayerInfo*)(event.peer->data))->cloth3 = 0;
  4162. break;
  4163. }
  4164. ((PlayerInfo*)(event.peer->data))->cloth3 = pMov->plantingTree;
  4165. break;
  4166. case 4:
  4167. if (((PlayerInfo*)(event.peer->data))->cloth4 == pMov->plantingTree)
  4168. {
  4169. ((PlayerInfo*)(event.peer->data))->cloth4 = 0;
  4170. break;
  4171. }
  4172. ((PlayerInfo*)(event.peer->data))->cloth4 = pMov->plantingTree;
  4173. break;
  4174. case 5:
  4175. if (((PlayerInfo*)(event.peer->data))->cloth5 == pMov->plantingTree)
  4176. {
  4177. ((PlayerInfo*)(event.peer->data))->cloth5 = 0;
  4178. break;
  4179. }
  4180. ((PlayerInfo*)(event.peer->data))->cloth5 = pMov->plantingTree;
  4181. break;
  4182. case 6:
  4183. if (((PlayerInfo*)(event.peer->data))->cloth6 == pMov->plantingTree)
  4184. {
  4185. ((PlayerInfo*)(event.peer->data))->cloth6 = 0;
  4186. ((PlayerInfo*)(event.peer->data))->canDoubleJump = false;
  4187. sendState(peer);
  4188. break;
  4189. }
  4190. {
  4191. ((PlayerInfo*)(event.peer->data))->cloth6 = pMov->plantingTree;
  4192. int item = pMov->plantingTree;
  4193. if (item == 156 || item == 362 || item == 678 || item == 736 || item == 818 || item == 1206 || item == 1460 || item == 1550 || item == 1574 || item == 1668 || item == 1672 || item == 1674 || item == 1784 || item == 1824 || item == 1936 || item == 1938 || item == 1970 || item == 2254 || item == 2256 || item == 2258 || item == 2260 || item == 2262 || item == 2264 || item == 2390 || item == 2392 || item == 3120 || item == 3308 || item == 3512 || item == 4534 || item == 4986 || item == 5754 || item == 6144 || item == 6334 || item == 6694 || item == 6818 || item == 6842 || item == 1934 || item == 3134 || item == 6004 || item == 1780 || item == 2158 || item == 2160 || item == 2162 || item == 2164 || item == 2166 || item == 2168 || item == 2438 || item == 2538 || item == 2778 || item == 3858 || item == 350 || item == 998 || item == 1738 || item == 2642 || item == 2982 || item == 3104 || item == 3144 || item == 5738 || item == 3112 || item == 2722 || item == 3114 || item == 4970 || item == 4972 || item == 5020 || item == 6284 || item == 4184 || item == 4628 || item == 5322 || item == 4112 || item == 4114 || item == 3442) {
  4194. ((PlayerInfo*)(event.peer->data))->canDoubleJump = true;
  4195. }
  4196. else {
  4197. ((PlayerInfo*)(event.peer->data))->canDoubleJump = false;
  4198. }
  4199. // ^^^^ wings
  4200. sendState(peer);
  4201. }
  4202. break;
  4203. case 7:
  4204. if (((PlayerInfo*)(event.peer->data))->cloth7 == pMov->plantingTree)
  4205. {
  4206. ((PlayerInfo*)(event.peer->data))->cloth7 = 0;
  4207. break;
  4208. }
  4209. ((PlayerInfo*)(event.peer->data))->cloth7 = pMov->plantingTree;
  4210. break;
  4211. case 8:
  4212. if (((PlayerInfo*)(event.peer->data))->cloth8 == pMov->plantingTree)
  4213. {
  4214. ((PlayerInfo*)(event.peer->data))->cloth8 = 0;
  4215. break;
  4216. }
  4217. ((PlayerInfo*)(event.peer->data))->cloth8 = pMov->plantingTree;
  4218. break;
  4219. default:
  4220. #ifdef TOTAL_LOG
  4221. cout << "Invalid item activated: " << pMov->plantingTree << " by " << ((PlayerInfo*)(event.peer->data))->displayName << endl;
  4222. #endif
  4223. break;
  4224. }
  4225. sendClothes(peer);
  4226. // activate item
  4227. END_CLOTHSETTER_FORCE:;
  4228. }
  4229. if (data2->packetType == 18)
  4230. {
  4231. sendPData(peer, pMov);
  4232. // add talk buble
  4233. }
  4234. if (data2->punchX != -1 && data2->punchY != -1) {
  4235. //cout << data2->packetType << endl;
  4236. if (data2->packetType == 3)
  4237. {
  4238. sendTileUpdate(data2->punchX, data2->punchY, data2->plantingTree, ((PlayerInfo*)(event.peer->data))->netID, peer);
  4239. }
  4240. else {
  4241.  
  4242.  
  4243. }
  4244. /*PlayerMoving data;
  4245. //data.packetType = 0x14;
  4246. data.packetType = 0x3;
  4247. //data.characterState = 0x924; // animation
  4248. data.characterState = 0x0; // animation
  4249. data.x = data2->punchX;
  4250. data.y = data2->punchY;
  4251. data.punchX = data2->punchX;
  4252. data.punchY = data2->punchY;
  4253. data.XSpeed = 0;
  4254. data.YSpeed = 0;
  4255. data.netID = ((PlayerInfo*)(event.peer->data))->netID;
  4256. data.plantingTree = data2->plantingTree;
  4257. SendPacketRaw(4, packPlayerMoving(&data), 56, 0, peer, ENET_PACKET_FLAG_RELIABLE);
  4258. cout << "Tile update at: " << data2->punchX << "x" << data2->punchY << endl;*/
  4259.  
  4260. }
  4261. delete data2;
  4262. delete pMov;
  4263. }
  4264.  
  4265.  
  4266. else {
  4267. cout << "Got bad tank packet";
  4268. }
  4269. /*char buffer[2048];
  4270. for (int i = 0; i < event->packet->dataLength; i++)
  4271. {
  4272. sprintf(&buffer[2 * i], "%02X", event->packet->data[i]);
  4273. }
  4274. cout << buffer;*/
  4275. }
  4276. }
  4277. break;
  4278. case 5:
  4279. break;
  4280. case 6:
  4281. //cout << GetTextPointerFromPacket(event.packet) << endl;
  4282. break;
  4283. }
  4284. enet_packet_destroy(event.packet);
  4285. break;
  4286. }
  4287. case ENET_EVENT_TYPE_DISCONNECT:
  4288. #ifdef TOTAL_LOG
  4289. printf("Peer disconnected.\n");
  4290. #endif
  4291. /* Reset the peer's client information. */
  4292. /*ENetPeer* currentPeer;
  4293. for (currentPeer = server->peers;
  4294. currentPeer < &server->peers[server->peerCount];
  4295. ++currentPeer)
  4296. {
  4297. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  4298. continue;
  4299.  
  4300.  
  4301. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "Player `o" + ((PlayerInfo*)(event.peer->data))->tankIDName + "`o just left the game..."));
  4302. ENetPacket * packet = enet_packet_create(p.data,
  4303. p.len,
  4304. ENET_PACKET_FLAG_RELIABLE);
  4305. enet_peer_send(currentPeer, 0, packet);
  4306. enet_host_flush(server);
  4307. }*/
  4308. sendPlayerLeave(peer, (PlayerInfo*)(event.peer->data));
  4309. ((PlayerInfo*)(event.peer->data))->inventory.items.clear();
  4310. delete event.peer->data;
  4311. event.peer->data = NULL;
  4312. }
  4313. }
  4314. cout << "Program ended??? Huh?" << endl;
  4315. while (1);
  4316. return 0;
  4317. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement