Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void sendWorld(ENetPeer* peer, WorldInfo* worldInfo)
- {
- #ifdef TOTAL_LOG
- cout << "Entering a world..." << endl;
- #endif
- ((PlayerInfo*)(peer->data))->joinClothesUpdated = false;
- string asdf = "0400000004A7379237BB2509E8E0EC04F8720B050000000000000000FBBB0000010000007D920100FDFDFDFD04000000040000000000000000000000070000000000"; // 0400000004A7379237BB2509E8E0EC04F8720B050000000000000000FBBB0000010000007D920100FDFDFDFD04000000040000000000000000000000080000000000000000000000000000000000000000000000000000000000000048133A0500000000BEBB0000070000000000
- string worldName = worldInfo->name;
- int xSize = worldInfo->width;
- int ySize = worldInfo->height;
- int square = xSize*ySize;
- __int16 nameLen = worldName.length();
- int payloadLen = asdf.length() / 2;
- int dataLen = payloadLen + 2 + nameLen + 12 + (square * 8) + 4;
- int allocMem = payloadLen + 2 + nameLen + 12 + (square * 8) + 4 + 16000;
- BYTE* data = new BYTE[allocMem];
- for (int i = 0; i < asdf.length(); i += 2)
- {
- char x = ch2n(asdf[i]);
- x = x << 4;
- x += ch2n(asdf[i + 1]);
- memcpy(data + (i / 2), &x, 1);
- }
- int zero = 0;
- __int16 item = 0;
- int smth = 0;
- for (int i = 0; i < square * 8; i += 4) memcpy(data + payloadLen + i + 14 + nameLen, &zero, 4);
- for (int i = 0; i < square * 8; i += 8) memcpy(data + payloadLen + i + 14 + nameLen, &item, 2);
- memcpy(data + payloadLen, &nameLen, 2);
- memcpy(data + payloadLen + 2, worldName.c_str(), nameLen);
- memcpy(data + payloadLen + 2 + nameLen, &xSize, 4);
- memcpy(data + payloadLen + 6 + nameLen, &ySize, 4);
- memcpy(data + payloadLen + 10 + nameLen, &square, 4);
- BYTE* blockPtr = data + payloadLen + 14 + nameLen;
- for (int i = 0; i < square; i++) {
- 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)*/)
- {
- memcpy(blockPtr, &worldInfo->items[i].foreground, 2);
- int type = 0x00000000;
- // type 1 = locked
- if (worldInfo->items[i].water)
- type |= 0x04000000;
- if (worldInfo->items[i].glue)
- type |= 0x08000000;
- if (worldInfo->items[i].fire)
- type |= 0x10000000;
- if (worldInfo->items[i].red)
- type |= 0x20000000;
- if (worldInfo->items[i].green)
- type |= 0x40000000;
- if (worldInfo->items[i].blue)
- type |= 0x80000000;
- // int type = 0x04000000; = water
- // int type = 0x08000000 = glue
- // int type = 0x10000000; = fire
- // int type = 0x20000000; = red color
- // int type = 0x40000000; = green color
- // int type = 0x80000000; = blue color
- memcpy(blockPtr + 4, &type, 4);
- /*if (worldInfo->items[i].foreground % 2)
- {
- blockPtr += 6;
- }*/
- }
- else
- {
- memcpy(blockPtr, &zero, 2);
- }
- memcpy(blockPtr + 2, &worldInfo->items[i].background, 2);
- blockPtr += 8;
- /*if (blockPtr - data < allocMem - 2000) // realloc
- {
- int wLen = blockPtr - data;
- BYTE* oldData = data;
- data = new BYTE[allocMem + 16000];
- memcpy(data, oldData, allocMem);
- allocMem += 16000;
- delete oldData;
- blockPtr = data + wLen;
- }*/
- }
- memcpy(data + dataLen - 4, &smth, 4);
- ENetPacket * packet2 = enet_packet_create(data,
- dataLen,
- ENET_PACKET_FLAG_RELIABLE);
- enet_peer_send(peer, 0, packet2);
- //enet_host_flush(server);
- for (int i = 0; i < square; i++) {
- if ((worldInfo->items[i].foreground == 0) || (worldInfo->items[i].foreground == 2) || (worldInfo->items[i].foreground == 8) || (worldInfo->items[i].foreground == 100))
- ; // nothing
- else
- {
- PlayerMoving data;
- //data.packetType = 0x14;
- data.packetType = 0x3;
- //data.characterState = 0x924; // animation
- data.characterState = 0x0; // animation
- data.x = i%worldInfo->width;
- data.y = i/worldInfo->height;
- data.punchX = i%worldInfo->width;
- data.punchY = i / worldInfo->width;
- data.XSpeed = 0;
- data.YSpeed = 0;
- data.netID = -1;
- data.plantingTree = worldInfo->items[i].foreground;
- SendPacketRaw(4, packPlayerMoving(&data), 56, 0, peer, ENET_PACKET_FLAG_RELIABLE);
- }
- }
- ((PlayerInfo*)(peer->data))->currentWorld = worldInfo->name;
- if (((PlayerInfo*)(peer->data))->haveGrowId) {
- PlayerInfo* p = ((PlayerInfo*)(peer->data));
- std::ifstream ifff("players/" + PlayerDB::getProperName(p->rawName) + ".json");
- json j;
- ifff >> j;
- p->currentWorld = worldInfo->name;
- int bac, han, fac, hai, fee, pan, nec, shi, mas;
- bac = j["ClothBack"];
- han = j["ClothHand"];
- fac = j["ClothFace"];
- hai = j["ClothHair"];
- fee = j["ClothFeet"];
- pan = j["ClothPants"];
- nec = j["ClothNeck"];
- shi = j["ClothShirt"];
- mas = j["ClothMask"];
- p->cloth_back = bac;
- p->cloth_hand = han;
- p->cloth_face = fac;
- p->cloth_hair = hai;
- p->cloth_feet = fee;
- p->cloth_pants = pan;
- p->cloth_necklace = nec;
- p->cloth_shirt = shi;
- p->cloth_mask = mas;
- sendClothes(peer);
- ifff.close();
- }
- delete data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement