Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- else if (str == "/saveplayer") {
- if (!isOwner(((PlayerInfo*)(peer->data))->rawName, ((PlayerInfo*)(peer->data))->tankIDPass)) break;
- cout << "Player " << ((PlayerInfo*)(peer->data))->rawName << " has saved players data!" << endl;
- ENetPeer * currentPeer;
- for (currentPeer = server->peers;
- currentPeer < &server->peers[server->peerCount];
- ++currentPeer)
- {
- if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
- continue;
- if (((PlayerInfo*)(currentPeer->data))->haveGrowId) {
- PlayerInfo* p = ((PlayerInfo*)(currentPeer->data));
- string username = PlayerDB::getProperName(p->rawName);
- std::ifstream od("players/" + username + ".json");
- if (od.is_open()) {
- }
- std::ofstream o("players/" + username + ".json");
- if (!o.is_open()) {
- cout << GetLastError() << endl;
- _getch();
- }
- json j;
- int clothback = p->cloth_back;
- int clothhand = p->cloth_hand;
- int clothface = p->cloth_face;
- int clothhair = p->cloth_hair;
- int clothfeet = p->cloth_feet;
- int clothpants = p->cloth_pants;
- int clothneck = p->cloth_necklace;
- int clothshirt = p->cloth_shirt;
- int clothmask = p->cloth_mask;
- int level = p->level;
- int gems = p->gems;
- int mute = p->mute;
- int ban = p->ban;
- string password = ((PlayerInfo*)(currentPeer->data))->tankIDPass;
- j["ClothBack"] = clothback;
- j["ClothHand"] = clothhand;
- j["ClothFace"] = clothface;
- j["ClothShirt"] = clothshirt;
- j["ClothPants"] = clothpants;
- j["ClothNeck"] = clothneck;
- j["ClothHair"] = clothhair;
- j["ClothFeet"] = clothfeet;
- j["ClothMask"] = clothmask;
- j["isMuted"] = mute;
- j["isBanned"] = ban;
- j["Gems"] = gems;
- j["Level"] = level;
- j["adminLevel"] = 0;
- j["password"] = hashPassword(password);
- j["username"] = username;
- o << j << std::endl;
- }
- string name = ((PlayerInfo*)(peer->data))->trueName3;
- GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnConsoleMessage"), "`oSystem Message: `2" + name + " `ohas saved players data!"));
- string text = "action|play_sfx\nfile|audio/piano_nice.wav\ndelayMS|0\n";
- BYTE* data = new BYTE[5 + text.length()];
- BYTE zero = 0;
- int type = 3;
- memcpy(data, &type, 4);
- memcpy(data + 4, text.c_str(), text.length());
- memcpy(data + 4 + text.length(), &zero, 1);
- ENetPacket * packet = enet_packet_create(p.data,
- p.len,
- ENET_PACKET_FLAG_RELIABLE);
- enet_peer_send(currentPeer, 0, packet);
- ENetPacket * packet2 = enet_packet_create(data,
- 5 + text.length(),
- ENET_PACKET_FLAG_RELIABLE);
- enet_peer_send(currentPeer, 0, packet2);
- //enet_host_flush(server);
- delete data;
- delete p.data;
- }
- cout << "Saving has completed." << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement