Advertisement
FocusedSG

/saveplayer

Dec 10th, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. else if (str == "/saveplayer") {
  2. if (!isOwner(((PlayerInfo*)(peer->data))->rawName, ((PlayerInfo*)(peer->data))->tankIDPass)) break;
  3. cout << "Player " << ((PlayerInfo*)(peer->data))->rawName << " has saved players data!" << endl;
  4. ENetPeer * currentPeer;
  5.  
  6. for (currentPeer = server->peers;
  7. currentPeer < &server->peers[server->peerCount];
  8. ++currentPeer)
  9. {
  10. if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
  11. continue;
  12. if (((PlayerInfo*)(currentPeer->data))->haveGrowId) {
  13.  
  14. PlayerInfo* p = ((PlayerInfo*)(currentPeer->data));
  15.  
  16. string username = PlayerDB::getProperName(p->rawName);
  17.  
  18. std::ifstream od("players/" + username + ".json");
  19. if (od.is_open()) {
  20. }
  21.  
  22. std::ofstream o("players/" + username + ".json");
  23. if (!o.is_open()) {
  24. cout << GetLastError() << endl;
  25. _getch();
  26. }
  27. json j;
  28.  
  29. int clothback = p->cloth_back;
  30. int clothhand = p->cloth_hand;
  31. int clothface = p->cloth_face;
  32. int clothhair = p->cloth_hair;
  33. int clothfeet = p->cloth_feet;
  34. int clothpants = p->cloth_pants;
  35. int clothneck = p->cloth_necklace;
  36. int clothshirt = p->cloth_shirt;
  37. int clothmask = p->cloth_mask;
  38. int level = p->level;
  39. int gems = p->gems;
  40. int mute = p->mute;
  41. int ban = p->ban;
  42.  
  43. string password = ((PlayerInfo*)(currentPeer->data))->tankIDPass;
  44.  
  45. j["ClothBack"] = clothback;
  46. j["ClothHand"] = clothhand;
  47. j["ClothFace"] = clothface;
  48. j["ClothShirt"] = clothshirt;
  49. j["ClothPants"] = clothpants;
  50. j["ClothNeck"] = clothneck;
  51. j["ClothHair"] = clothhair;
  52. j["ClothFeet"] = clothfeet;
  53. j["ClothMask"] = clothmask;
  54. j["isMuted"] = mute;
  55. j["isBanned"] = ban;
  56. j["Gems"] = gems;
  57. j["Level"] = level;
  58. j["adminLevel"] = 0;
  59. j["password"] = hashPassword(password);
  60. j["username"] = username;
  61.  
  62.  
  63. o << j << std::endl;
  64. }
  65. string name = ((PlayerInfo*)(peer->data))->trueName3;
  66. GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`oSystem Message: `2" + name + " `ohas saved players data!"));
  67. string text = "action|play_sfx\nfile|audio/piano_nice.wav\ndelayMS|0\n";
  68. BYTE* data = new BYTE[5 + text.length()];
  69. BYTE zero = 0;
  70. int type = 3;
  71. memcpy(data, &type, 4);
  72. memcpy(data + 4, text.c_str(), text.length());
  73. memcpy(data + 4 + text.length(), &zero, 1);
  74.  
  75. ENetPacket * packet = enet_packet_create(p.data,
  76. p.len,
  77. ENET_PACKET_FLAG_RELIABLE);
  78.  
  79. enet_peer_send(currentPeer, 0, packet);
  80. ENetPacket * packet2 = enet_packet_create(data,
  81. 5 + text.length(),
  82. ENET_PACKET_FLAG_RELIABLE);
  83.  
  84. enet_peer_send(currentPeer, 0, packet2);
  85.  
  86. //enet_host_flush(server);
  87.  
  88. delete data;
  89. delete p.data;
  90. }
  91. cout << "Saving has completed." << endl;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement