format codebase

This commit is contained in:
aronwk-aaron
2022-07-28 08:39:57 -05:00
parent 4f7aa11067
commit 19e77a38d8
881 changed files with 34700 additions and 38689 deletions

View File

@@ -119,11 +119,11 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
}
if (sqlBanned) {
AuthPackets::SendLoginResponse(server, packet->systemAddress, LOGIN_RESPONSE_BANNED, "", "", 2001, username); return;
AuthPackets::SendLoginResponse(server, packet->systemAddress, LOGIN_RESPONSE_BANNED, "", "", 2001, username); return;
}
if (sqlLocked) {
AuthPackets::SendLoginResponse(server, packet->systemAddress, LOGIN_RESPONSE_ACCOUNT_LOCKED, "", "", 2001, username); return;
AuthPackets::SendLoginResponse(server, packet->systemAddress, LOGIN_RESPONSE_ACCOUNT_LOCKED, "", "", 2001, username); return;
}
/*
@@ -136,18 +136,14 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
int32_t bcryptState = ::bcrypt_checkpw(password.c_str(), sqlPass.c_str());
if (bcryptState != 0)
{
if (bcryptState != 0) {
// Fallback on old method
std::string oldPassword = sha512(password + username);
if (sqlPass != oldPassword)
{
if (sqlPass != oldPassword) {
loginSuccess = false;
}
else
{
} else {
// Generate new hash for bcrypt
char salt[BCRYPT_HASHSIZE];
@@ -168,17 +164,14 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
accountUpdate->executeUpdate();
}
}
else
{
} else {
// Login success with bcrypt
}
if (!loginSuccess) {
AuthPackets::SendLoginResponse(server, packet->systemAddress, LOGIN_RESPONSE_WRONG_PASS_OR_USER, "", "", 2001, username);
AuthPackets::SendLoginResponse(server, packet->systemAddress, LOGIN_RESPONSE_WRONG_PASS_OR_USER, "", "", 2001, username);
server->GetLogger()->Log("AuthPackets", "Wrong password used");
}
else {
} else {
SystemAddress system = packet->systemAddress; //Copy the sysAddr before the Packet gets destroyed from main
if (!server->GetIsConnectedToMaster()) {
@@ -188,74 +181,74 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
ZoneInstanceManager::Instance()->RequestZoneTransfer(server, 0, 0, false, [system, server, username](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string zoneIP, uint16_t zonePort) {
AuthPackets::SendLoginResponse(server, system, LOGIN_RESPONSE_SUCCESS, "", zoneIP, zonePort, username);
});
});
}
}
void AuthPackets::SendLoginResponse(dServer* server, const SystemAddress& sysAddr, eLoginResponse responseCode, const std::string& errorMsg, const std::string& wServerIP, uint16_t wServerPort, std::string username) {
RakNet::BitStream packet;
PacketUtils::WriteHeader(packet, CLIENT, MSG_CLIENT_LOGIN_RESPONSE);
RakNet::BitStream packet;
PacketUtils::WriteHeader(packet, CLIENT, MSG_CLIENT_LOGIN_RESPONSE);
packet.Write(static_cast<uint8_t>(responseCode));
packet.Write(static_cast<uint8_t>(responseCode));
PacketUtils::WritePacketString("Talk_Like_A_Pirate", 33, &packet);
PacketUtils::WritePacketString("Talk_Like_A_Pirate", 33, &packet);
// 7 unknown strings - perhaps other IP addresses?
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
// 7 unknown strings - perhaps other IP addresses?
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
packet.Write(static_cast<uint16_t>(1)); // Version Major
packet.Write(static_cast<uint16_t>(10)); // Version Current
packet.Write(static_cast<uint16_t>(64)); // Version Minor
packet.Write(static_cast<uint16_t>(1)); // Version Major
packet.Write(static_cast<uint16_t>(10)); // Version Current
packet.Write(static_cast<uint16_t>(64)); // Version Minor
// Writes the user key
// Writes the user key
uint32_t sessionKey = rand(); // not mt but whatever
std::string userHash = std::to_string(sessionKey);
userHash = md5(userHash);
PacketUtils::WritePacketWString(userHash, 33, &packet);
userHash = md5(userHash);
PacketUtils::WritePacketWString(userHash, 33, &packet);
// Write the Character and Chat IPs
PacketUtils::WritePacketString(wServerIP, 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
// Write the Character and Chat IPs
PacketUtils::WritePacketString(wServerIP, 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
// Write the Character and Chat Ports
packet.Write(static_cast<uint16_t>(wServerPort));
packet.Write(static_cast<uint16_t>(0));
// Write the Character and Chat Ports
packet.Write(static_cast<uint16_t>(wServerPort));
packet.Write(static_cast<uint16_t>(0));
// Write another IP
PacketUtils::WritePacketString("", 33, &packet);
// Write another IP
PacketUtils::WritePacketString("", 33, &packet);
// Write a GUID or something...
PacketUtils::WritePacketString("00000000-0000-0000-0000-000000000000", 37, &packet);
// Write a GUID or something...
PacketUtils::WritePacketString("00000000-0000-0000-0000-000000000000", 37, &packet);
packet.Write(static_cast<uint32_t>(0)); // ???
packet.Write(static_cast<uint32_t>(0)); // ???
// Write the localization
PacketUtils::WritePacketString("US", 3, &packet);
// Write the localization
PacketUtils::WritePacketString("US", 3, &packet);
packet.Write(static_cast<uint8_t>(false)); // User first logged in?
packet.Write(static_cast<uint8_t>(false)); // User is F2P?
packet.Write(static_cast<uint64_t>(0)); // ???
packet.Write(static_cast<uint8_t>(false)); // User first logged in?
packet.Write(static_cast<uint8_t>(false)); // User is F2P?
packet.Write(static_cast<uint64_t>(0)); // ???
// Write custom error message
packet.Write(static_cast<uint16_t>(errorMsg.length()));
PacketUtils::WritePacketWString(errorMsg, static_cast<uint32_t>(errorMsg.length()), &packet);
// Write custom error message
packet.Write(static_cast<uint16_t>(errorMsg.length()));
PacketUtils::WritePacketWString(errorMsg, static_cast<uint32_t>(errorMsg.length()), &packet);
// Here write auth logs
packet.Write(static_cast<uint32_t>(20));
for (uint32_t i = 0; i < 20; ++i) {
packet.Write(static_cast<uint32_t>(8));
packet.Write(static_cast<uint32_t>(44));
packet.Write(static_cast<uint32_t>(14000));
packet.Write(static_cast<uint32_t>(0));
}
// Here write auth logs
packet.Write(static_cast<uint32_t>(20));
for (uint32_t i = 0; i < 20; ++i) {
packet.Write(static_cast<uint32_t>(8));
packet.Write(static_cast<uint32_t>(44));
packet.Write(static_cast<uint32_t>(14000));
packet.Write(static_cast<uint32_t>(0));
}
server->Send(&packet, sysAddr, false);
server->Send(&packet, sysAddr, false);
//Inform the master server that we've created a session for this user:
{

View File

@@ -10,9 +10,9 @@ class dServer;
namespace AuthPackets {
void HandleHandshake(dServer* server, Packet* packet);
void SendHandshake(dServer* server, const SystemAddress& sysAddr, const std::string& nextServerIP, uint16_t nextServerPort);
void HandleLoginRequest(dServer* server, Packet* packet);
void SendLoginResponse(dServer* server, const SystemAddress& sysAddr, eLoginResponse responseCode, const std::string& errorMsg, const std::string& wServerIP, uint16_t wServerPort, std::string username);
}
#endif // AUTHPACKETS_H
#endif // AUTHPACKETS_H

View File

@@ -12,63 +12,63 @@
#include "dServer.h"
void ChatPackets::SendChatMessage(const SystemAddress& sysAddr, char chatChannel, const std::string& senderName, LWOOBJID playerObjectID, bool senderMythran, const std::u16string& message) {
CBITSTREAM
PacketUtils::WriteHeader(bitStream, CHAT, MSG_CHAT_GENERAL_CHAT_MESSAGE);
bitStream.Write(static_cast<uint64_t>(0));
bitStream.Write(chatChannel);
bitStream.Write(static_cast<uint32_t>(message.size()));
PacketUtils::WriteWString(bitStream, senderName, 33);
CBITSTREAM
PacketUtils::WriteHeader(bitStream, CHAT, MSG_CHAT_GENERAL_CHAT_MESSAGE);
bitStream.Write(playerObjectID);
bitStream.Write(static_cast<uint16_t>(0));
bitStream.Write(static_cast<char>(0));
bitStream.Write(static_cast<uint64_t>(0));
bitStream.Write(chatChannel);
for (uint32_t i = 0; i < message.size(); ++i) {
bitStream.Write(static_cast<uint16_t>(message[i]));
}
bitStream.Write(static_cast<uint16_t>(0));
SEND_PACKET_BROADCAST
bitStream.Write(static_cast<uint32_t>(message.size()));
PacketUtils::WriteWString(bitStream, senderName, 33);
bitStream.Write(playerObjectID);
bitStream.Write(static_cast<uint16_t>(0));
bitStream.Write(static_cast<char>(0));
for (uint32_t i = 0; i < message.size(); ++i) {
bitStream.Write(static_cast<uint16_t>(message[i]));
}
bitStream.Write(static_cast<uint16_t>(0));
SEND_PACKET_BROADCAST
}
void ChatPackets::SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, const bool broadcast) {
CBITSTREAM
PacketUtils::WriteHeader(bitStream, CHAT, MSG_CHAT_GENERAL_CHAT_MESSAGE);
bitStream.Write(static_cast<uint64_t>(0));
bitStream.Write(static_cast<char>(4));
CBITSTREAM
PacketUtils::WriteHeader(bitStream, CHAT, MSG_CHAT_GENERAL_CHAT_MESSAGE);
bitStream.Write(static_cast<uint32_t>(message.size()));
PacketUtils::WriteWString(bitStream, "", 33);
bitStream.Write(static_cast<uint64_t>(0));
bitStream.Write(static_cast<char>(4));
bitStream.Write(static_cast<uint64_t>(0));
bitStream.Write(static_cast<uint16_t>(0));
bitStream.Write(static_cast<char>(0));
bitStream.Write(static_cast<uint32_t>(message.size()));
PacketUtils::WriteWString(bitStream, "", 33);
for (uint32_t i = 0; i < message.size(); ++i) {
bitStream.Write(static_cast<uint16_t>(message[i]));
}
bitStream.Write(static_cast<uint64_t>(0));
bitStream.Write(static_cast<uint16_t>(0));
bitStream.Write(static_cast<char>(0));
for (uint32_t i = 0; i < message.size(); ++i) {
bitStream.Write(static_cast<uint16_t>(message[i]));
}
bitStream.Write(static_cast<uint16_t>(0));
bitStream.Write(static_cast<uint16_t>(0));
//This is so Wincent's announcement works:
if (sysAddr != UNASSIGNED_SYSTEM_ADDRESS) {
SEND_PACKET;
return;
}
SEND_PACKET_BROADCAST;
}
void ChatPackets::SendMessageFail(const SystemAddress& sysAddr) {
//0x00 - "Chat is currently disabled."
//0x01 - "Upgrade to a full LEGO Universe Membership to chat with other players."
//0x00 - "Chat is currently disabled."
//0x01 - "Upgrade to a full LEGO Universe Membership to chat with other players."
CBITSTREAM;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_SEND_CANNED_TEXT);
bitStream.Write<uint8_t>(0); //response type, options above ^
//docs say there's a wstring here-- no idea what it's for, or if it's even needed so leaving it as is for now.
SEND_PACKET;
CBITSTREAM;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_SEND_CANNED_TEXT);
bitStream.Write<uint8_t>(0); //response type, options above ^
//docs say there's a wstring here-- no idea what it's for, or if it's even needed so leaving it as is for now.
SEND_PACKET;
}

View File

@@ -12,9 +12,9 @@ struct SystemAddress;
#include "dCommonVars.h"
namespace ChatPackets {
void SendChatMessage(const SystemAddress& sysAddr, char chatChannel, const std::string& senderName, LWOOBJID playerObjectID, bool senderMythran, const std::u16string& message);
void SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, bool broadcast = false);
void SendMessageFail(const SystemAddress& sysAddr);
void SendChatMessage(const SystemAddress& sysAddr, char chatChannel, const std::string& senderName, LWOOBJID playerObjectID, bool senderMythran, const std::u16string& message);
void SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, bool broadcast = false);
void SendMessageFail(const SystemAddress& sysAddr);
};
#endif // CHATPACKETS_H

View File

@@ -176,7 +176,7 @@ void ClientPackets::HandleClientPositionUpdate(const SystemAddress& sysAddr, Pac
// Handle statistics
auto* characterComponent = entity->GetComponent<CharacterComponent>();
if (characterComponent != nullptr) {
characterComponent->TrackPositionUpdate(position);
characterComponent->TrackPositionUpdate(position);
}
comp->SetPosition(position);
@@ -254,8 +254,7 @@ void ClientPackets::HandleChatModerationRequest(const SystemAddress& sysAddr, Pa
// Check if the player has restricted chat access
auto* character = entity->GetCharacter();
if (character->HasPermission(PermissionMap::RestrictedChatAccess))
{
if (character->HasPermission(PermissionMap::RestrictedChatAccess)) {
// Send a message to the player
ChatPackets::SendSystemMessage(
sysAddr,
@@ -341,8 +340,7 @@ void ClientPackets::HandleChatModerationRequest(const SystemAddress& sysAddr, Pa
delete res;
delete stmt;
}
else if (user->GetIsBestFriendMap().find(receiver) != user->GetIsBestFriendMap().end()) {
} else if (user->GetIsBestFriendMap().find(receiver) != user->GetIsBestFriendMap().end()) {
isBestFriend = true;
}
}

View File

@@ -9,9 +9,9 @@
#include "RakNetTypes.h"
namespace ClientPackets {
void HandleChatMessage(const SystemAddress& sysAddr, Packet* packet);
void HandleClientPositionUpdate(const SystemAddress& sysAddr, Packet* packet);
void HandleChatModerationRequest(const SystemAddress& sysAddr, Packet* packet);
void HandleChatMessage(const SystemAddress& sysAddr, Packet* packet);
void HandleClientPositionUpdate(const SystemAddress& sysAddr, Packet* packet);
void HandleChatModerationRequest(const SystemAddress& sysAddr, Packet* packet);
};
#endif // CLIENTPACKETS_H

View File

@@ -9,30 +9,30 @@
void MasterPackets::SendPersistentIDRequest(dServer* server, uint64_t requestID) {
CBITSTREAM
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_REQUEST_PERSISTENT_ID);
bitStream.Write(requestID);
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_REQUEST_PERSISTENT_ID);
bitStream.Write(requestID);
server->SendToMaster(&bitStream);
}
void MasterPackets::SendPersistentIDResponse(dServer* server, const SystemAddress& sysAddr, uint64_t requestID, uint32_t objID) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_REQUEST_PERSISTENT_ID_RESPONSE);
bitStream.Write(requestID);
bitStream.Write(objID);
server->Send(&bitStream, sysAddr, false);
}
void MasterPackets::SendZoneTransferRequest(dServer* server, uint64_t requestID, bool mythranShift, uint32_t zoneID, uint32_t cloneID) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_REQUEST_ZONE_TRANSFER);
bitStream.Write(requestID);
bitStream.Write(static_cast<uint8_t>(mythranShift));
bitStream.Write(zoneID);
bitStream.Write(cloneID);
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_REQUEST_ZONE_TRANSFER);
bitStream.Write(requestID);
bitStream.Write(static_cast<uint8_t>(mythranShift));
bitStream.Write(zoneID);
bitStream.Write(cloneID);
server->SendToMaster(&bitStream);
}
@@ -66,58 +66,57 @@ void MasterPackets::SendZoneRequestPrivate(dServer* server, uint64_t requestID,
server->SendToMaster(&bitStream);
}
void MasterPackets::SendWorldReady(dServer* server, LWOMAPID zoneId, LWOINSTANCEID instanceId)
{
void MasterPackets::SendWorldReady(dServer* server, LWOMAPID zoneId, LWOINSTANCEID instanceId) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_WORLD_READY);
bitStream.Write(zoneId);
bitStream.Write(instanceId);
server->SendToMaster(&bitStream);
}
void MasterPackets::SendZoneTransferResponse(dServer* server, const SystemAddress& sysAddr, uint64_t requestID, bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, const std::string& serverIP, uint32_t serverPort) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_REQUEST_ZONE_TRANSFER_RESPONSE);
bitStream.Write(requestID);
bitStream.Write(static_cast<uint8_t>(mythranShift));
bitStream.Write(zoneID);
bitStream.Write(zoneInstance);
bitStream.Write(zoneClone);
bitStream.Write(static_cast<uint16_t>(serverPort));
PacketUtils::WriteString(bitStream, serverIP, static_cast<uint32_t>(serverIP.size() + 1));
server->Send(&bitStream, sysAddr, false);
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_REQUEST_ZONE_TRANSFER_RESPONSE);
bitStream.Write(requestID);
bitStream.Write(static_cast<uint8_t>(mythranShift));
bitStream.Write(zoneID);
bitStream.Write(zoneInstance);
bitStream.Write(zoneClone);
bitStream.Write(static_cast<uint16_t>(serverPort));
PacketUtils::WriteString(bitStream, serverIP, static_cast<uint32_t>(serverIP.size() + 1));
server->Send(&bitStream, sysAddr, false);
}
void MasterPackets::HandleServerInfo(Packet* packet) {
RakNet::BitStream inStream(packet->data, packet->length, false);
uint64_t header = inStream.Read(header);
uint32_t theirPort = 0;
uint32_t theirZoneID = 0;
uint32_t theirInstanceID = 0;
std::string theirIP = "";
inStream.Read(theirPort);
inStream.Read(theirZoneID);
inStream.Read(theirInstanceID);
theirIP = PacketUtils::ReadString(inStream.GetReadOffset(), packet, false); //20 is the current offset
//TODO: Actually mark this server as an available server in the manager
}
void MasterPackets::SendServerInfo(dServer* server, Packet* packet) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_SERVER_INFO);
bitStream.Write(server->GetPort());
bitStream.Write(server->GetZoneID());
bitStream.Write(server->GetInstanceID());
bitStream.Write(server->GetServerType());
PacketUtils::WriteString(bitStream, server->GetIP(), server->GetIP().size());
server->SendToMaster(&bitStream);
}

View File

@@ -8,21 +8,21 @@
class dServer;
namespace MasterPackets {
void SendPersistentIDRequest(dServer* server, uint64_t requestID); //Called from the World server
void SendPersistentIDRequest(dServer* server, uint64_t requestID); //Called from the World server
void SendPersistentIDResponse(dServer* server, const SystemAddress& sysAddr, uint64_t requestID, uint32_t objID);
void SendZoneTransferRequest(dServer* server, uint64_t requestID, bool mythranShift, uint32_t zoneID, uint32_t cloneID);
void SendZoneTransferResponse(dServer* server, const SystemAddress& sysAddr, uint64_t requestID, bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, const std::string& serverIP, uint32_t serverPort);
void HandleServerInfo(Packet* packet);
void SendServerInfo(dServer* server, Packet* packet);
void SendZoneCreatePrivate(dServer* server, uint32_t zoneID, uint32_t cloneID, const std::string& password);
void SendZoneRequestPrivate(dServer* server, uint64_t requestID, bool mythranShift, const std::string& password);
void SendWorldReady(dServer* server, LWOMAPID zoneId, LWOINSTANCEID instanceId);
void HandleSetSessionKey(Packet* packet);
}

View File

@@ -12,75 +12,74 @@ void PacketUtils::WriteHeader(RakNet::BitStream& bitStream, uint16_t connectionT
bitStream.Write(uint8_t(0));
}
uint16_t PacketUtils::ReadPacketU16(uint32_t startLoc, Packet * packet) {
if (startLoc + 2 > packet->length) return 0;
std::vector<unsigned char> t;
for (uint32_t i = startLoc; i < startLoc + 2; i++) t.push_back(packet->data[i]);
return *(uint16_t*)t.data();
uint16_t PacketUtils::ReadPacketU16(uint32_t startLoc, Packet* packet) {
if (startLoc + 2 > packet->length) return 0;
std::vector<unsigned char> t;
for (uint32_t i = startLoc; i < startLoc + 2; i++) t.push_back(packet->data[i]);
return *(uint16_t*)t.data();
}
uint32_t PacketUtils::ReadPacketU32(uint32_t startLoc, Packet * packet) {
if (startLoc + 4 > packet->length) return 0;
std::vector<unsigned char> t;
for (uint32_t i = startLoc; i < startLoc + 4; i++) {
t.push_back(packet->data[i]);
}
return *(uint32_t*)t.data();
uint32_t PacketUtils::ReadPacketU32(uint32_t startLoc, Packet* packet) {
if (startLoc + 4 > packet->length) return 0;
std::vector<unsigned char> t;
for (uint32_t i = startLoc; i < startLoc + 4; i++) {
t.push_back(packet->data[i]);
}
return *(uint32_t*)t.data();
}
uint64_t PacketUtils::ReadPacketU64(uint32_t startLoc, Packet * packet) {
if (startLoc + 8 > packet->length) return 0;
std::vector<unsigned char> t;
for (uint32_t i = startLoc; i < startLoc + 8; i++) t.push_back(packet->data[i]);
return *(uint64_t*)t.data();
uint64_t PacketUtils::ReadPacketU64(uint32_t startLoc, Packet* packet) {
if (startLoc + 8 > packet->length) return 0;
std::vector<unsigned char> t;
for (uint32_t i = startLoc; i < startLoc + 8; i++) t.push_back(packet->data[i]);
return *(uint64_t*)t.data();
}
int64_t PacketUtils::ReadPacketS64(uint32_t startLoc, Packet * packet) {
if (startLoc + 8 > packet->length) return 0;
std::vector<unsigned char> t;
for (size_t i = startLoc; i < startLoc + 8; i++) t.push_back(packet->data[i]);
return *(int64_t*)t.data();
int64_t PacketUtils::ReadPacketS64(uint32_t startLoc, Packet* packet) {
if (startLoc + 8 > packet->length) return 0;
std::vector<unsigned char> t;
for (size_t i = startLoc; i < startLoc + 8; i++) t.push_back(packet->data[i]);
return *(int64_t*)t.data();
}
std::string PacketUtils::ReadString(uint32_t startLoc, Packet* packet, bool wide, uint32_t maxLen) {
std::string readString = "";
std::string readString = "";
if (wide) maxLen *= 2;
if (wide) maxLen *= 2;
if (packet->length > startLoc) {
uint32_t i = 0;
while (packet->data[startLoc + i] != '\0' && packet->length > (uint32_t)(startLoc + i) && maxLen > i) {
readString.push_back(packet->data[startLoc + i]);
if (packet->length > startLoc) {
uint32_t i = 0;
while (packet->data[startLoc + i] != '\0' && packet->length > (uint32_t)(startLoc + i) && maxLen > i) {
readString.push_back(packet->data[startLoc + i]);
if (wide) {
i += 2; // Wide-char string
}
else {
i++; // Regular string
}
}
}
if (wide) {
i += 2; // Wide-char string
} else {
i++; // Regular string
}
}
}
return readString;
return readString;
}
void PacketUtils::WritePacketString(const std::string& string, uint32_t maxSize, RakNet::BitStream * bitStream) {
uint32_t size = static_cast<uint32_t>(string.size());
uint32_t remSize = static_cast<uint32_t>(maxSize - size);
if (size > maxSize) size = maxSize;
for (uint32_t i = 0; i < size; ++i) {
bitStream->Write(static_cast<char>(string[i]));
}
for (uint32_t j = 0; j < remSize; ++j) {
bitStream->Write(static_cast<char>(0));
}
void PacketUtils::WritePacketString(const std::string& string, uint32_t maxSize, RakNet::BitStream* bitStream) {
uint32_t size = static_cast<uint32_t>(string.size());
uint32_t remSize = static_cast<uint32_t>(maxSize - size);
if (size > maxSize) size = maxSize;
for (uint32_t i = 0; i < size; ++i) {
bitStream->Write(static_cast<char>(string[i]));
}
for (uint32_t j = 0; j < remSize; ++j) {
bitStream->Write(static_cast<char>(0));
}
}
void PacketUtils::WriteString(RakNet::BitStream& bitStream, const std::string& s, uint32_t maxSize) {
@@ -99,60 +98,60 @@ void PacketUtils::WriteString(RakNet::BitStream& bitStream, const std::string& s
}
void PacketUtils::WriteWString(RakNet::BitStream& bitStream, const std::string& string, uint32_t maxSize) {
uint32_t size = static_cast<uint32_t>(string.length());
uint32_t remSize = static_cast<uint32_t>(maxSize - size);
if (size > maxSize) size = maxSize;
for (uint32_t i = 0; i < size; ++i) {
bitStream.Write(static_cast<uint16_t>(string[i]));
}
for (uint32_t j = 0; j < remSize; ++j) {
bitStream.Write(static_cast<uint16_t>(0));
}
uint32_t size = static_cast<uint32_t>(string.length());
uint32_t remSize = static_cast<uint32_t>(maxSize - size);
if (size > maxSize) size = maxSize;
for (uint32_t i = 0; i < size; ++i) {
bitStream.Write(static_cast<uint16_t>(string[i]));
}
for (uint32_t j = 0; j < remSize; ++j) {
bitStream.Write(static_cast<uint16_t>(0));
}
}
void PacketUtils::WriteWString(RakNet::BitStream& bitStream, const std::u16string& string, uint32_t maxSize) {
uint32_t size = static_cast<uint32_t>(string.length());
uint32_t remSize = static_cast<uint32_t>(maxSize - size);
if (size > maxSize) size = maxSize;
for (uint32_t i = 0; i < size; ++i) {
bitStream.Write(static_cast<uint16_t>(string[i]));
}
for (uint32_t j = 0; j < remSize; ++j) {
bitStream.Write(static_cast<uint16_t>(0));
}
uint32_t size = static_cast<uint32_t>(string.length());
uint32_t remSize = static_cast<uint32_t>(maxSize - size);
if (size > maxSize) size = maxSize;
for (uint32_t i = 0; i < size; ++i) {
bitStream.Write(static_cast<uint16_t>(string[i]));
}
for (uint32_t j = 0; j < remSize; ++j) {
bitStream.Write(static_cast<uint16_t>(0));
}
}
void PacketUtils::WritePacketWString(const std::string& string, uint32_t maxSize, RakNet::BitStream * bitStream) {
uint32_t size = static_cast<uint32_t>(string.length());
uint32_t remSize = static_cast<uint32_t>(maxSize - size);
if (size > maxSize) size = maxSize;
for (uint32_t i = 0; i < size; ++i) {
bitStream->Write(static_cast<uint16_t>(string[i]));
}
for (uint32_t j = 0; j < remSize; ++j) {
bitStream->Write(static_cast<uint16_t>(0));
}
void PacketUtils::WritePacketWString(const std::string& string, uint32_t maxSize, RakNet::BitStream* bitStream) {
uint32_t size = static_cast<uint32_t>(string.length());
uint32_t remSize = static_cast<uint32_t>(maxSize - size);
if (size > maxSize) size = maxSize;
for (uint32_t i = 0; i < size; ++i) {
bitStream->Write(static_cast<uint16_t>(string[i]));
}
for (uint32_t j = 0; j < remSize; ++j) {
bitStream->Write(static_cast<uint16_t>(0));
}
}
//! Saves a packet to the filesystem
void PacketUtils::SavePacket(const std::string& filename, const char * data, size_t length) {
void PacketUtils::SavePacket(const std::string& filename, const char* data, size_t length) {
//If we don't log to the console, don't save the bin files either. This takes up a lot of time.
if (!Game::logger->GetIsLoggingToConsole()) return;
std::string path = "packets/" + filename;
std::ofstream file(path, std::ios::binary);
if (!file.is_open()) return;
file.write(data, length);
file.close();
std::string path = "packets/" + filename;
std::ofstream file(path, std::ios::binary);
if (!file.is_open()) return;
file.write(data, length);
file.close();
}

View File

@@ -6,20 +6,20 @@
namespace PacketUtils {
void WriteHeader(RakNet::BitStream& bitStream, uint16_t connectionType, uint32_t internalPacketID);
uint16_t ReadPacketU16(uint32_t startLoc, Packet * packet);
uint32_t ReadPacketU32(uint32_t startLoc, Packet * packet);
uint64_t ReadPacketU64(uint32_t startLoc, Packet * packet);
int64_t ReadPacketS64(uint32_t startLoc, Packet * packet);
std::string ReadString(uint32_t startLoc, Packet * packet, bool wide, uint32_t maxLen = 33);
void WritePacketString(const std::string& string, uint32_t maxSize, RakNet::BitStream * bitStream);
uint16_t ReadPacketU16(uint32_t startLoc, Packet* packet);
uint32_t ReadPacketU32(uint32_t startLoc, Packet* packet);
uint64_t ReadPacketU64(uint32_t startLoc, Packet* packet);
int64_t ReadPacketS64(uint32_t startLoc, Packet* packet);
std::string ReadString(uint32_t startLoc, Packet* packet, bool wide, uint32_t maxLen = 33);
void WritePacketString(const std::string& string, uint32_t maxSize, RakNet::BitStream* bitStream);
void WriteString(RakNet::BitStream& bitStream, const std::string& s, uint32_t maxSize);
void WriteWString(RakNet::BitStream& bitStream, const std::string& string, uint32_t maxSize);
void WriteWString(RakNet::BitStream& bitStream, const std::u16string& string, uint32_t maxSize);
void WritePacketWString(const std::string& string, uint32_t maxSize, RakNet::BitStream * bitStream);
void SavePacket(const std::string& filename, const char * data, size_t length);
void WritePacketWString(const std::string& string, uint32_t maxSize, RakNet::BitStream* bitStream);
void SavePacket(const std::string& filename, const char* data, size_t length);
};
#endif // PACKETUTILS_H

View File

@@ -16,8 +16,8 @@
#include "ZCompression.h"
void WorldPackets::SendLoadStaticZone(const SystemAddress& sysAddr, float x, float y, float z, uint32_t checksum) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_LOAD_STATIC_ZONE);
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_LOAD_STATIC_ZONE);
auto zone = dZoneManager::Instance()->GetZone()->GetZoneID();
bitStream.Write(static_cast<uint16_t>(zone.GetMapID()));
@@ -25,19 +25,19 @@ void WorldPackets::SendLoadStaticZone(const SystemAddress& sysAddr, float x, flo
//bitStream.Write(static_cast<uint32_t>(zone.GetCloneID()));
bitStream.Write(0);
bitStream.Write(checksum);
bitStream.Write(static_cast<uint16_t>(0)); // ??
bitStream.Write(checksum);
bitStream.Write(static_cast<uint16_t>(0)); // ??
bitStream.Write(x);
bitStream.Write(y);
bitStream.Write(z);
bitStream.Write(x);
bitStream.Write(y);
bitStream.Write(z);
bitStream.Write(static_cast<uint32_t>(0)); // Change this to eventually use 4 on activity worlds
bitStream.Write(static_cast<uint32_t>(0)); // Change this to eventually use 4 on activity worlds
SEND_PACKET
SEND_PACKET
}
void WorldPackets::SendCharacterList ( const SystemAddress& sysAddr, User* user ) {
void WorldPackets::SendCharacterList(const SystemAddress& sysAddr, User* user) {
if (!user) return;
RakNet::BitStream bitStream;
@@ -45,57 +45,57 @@ void WorldPackets::SendCharacterList ( const SystemAddress& sysAddr, User* user
std::vector<Character*> characters = user->GetCharacters();
bitStream.Write(static_cast<uint8_t>(characters.size()));
bitStream.Write(static_cast<uint8_t>(0)); //character index in front, just picking 0
bitStream.Write(static_cast<uint8_t>(0)); //character index in front, just picking 0
for (uint32_t i = 0; i < characters.size(); ++i) {
bitStream.Write(characters[i]->GetObjectID());
bitStream.Write(static_cast<uint32_t>(0));
bitStream.Write(static_cast<uint32_t>(0));
PacketUtils::WriteWString(bitStream, characters[i]->GetName(), 33);
PacketUtils::WriteWString(bitStream, characters[i]->GetUnapprovedName(), 33);
PacketUtils::WriteWString(bitStream, characters[i]->GetUnapprovedName(), 33);
bitStream.Write(static_cast<uint8_t>(characters[i]->GetNameRejected()));
bitStream.Write(static_cast<uint8_t>(false));
bitStream.Write(static_cast<uint8_t>(false));
PacketUtils::WriteString(bitStream, "", 10);
bitStream.Write(characters[i]->GetShirtColor());
bitStream.Write(characters[i]->GetShirtStyle());
bitStream.Write(characters[i]->GetPantsColor());
bitStream.Write(characters[i]->GetHairStyle());
bitStream.Write(characters[i]->GetHairColor());
bitStream.Write(characters[i]->GetLeftHand());
bitStream.Write(characters[i]->GetRightHand());
bitStream.Write(characters[i]->GetEyebrows());
bitStream.Write(characters[i]->GetEyes());
bitStream.Write(characters[i]->GetMouth());
bitStream.Write(static_cast<uint32_t>(0));
bitStream.Write(characters[i]->GetShirtStyle());
bitStream.Write(characters[i]->GetPantsColor());
bitStream.Write(characters[i]->GetHairStyle());
bitStream.Write(characters[i]->GetHairColor());
bitStream.Write(characters[i]->GetLeftHand());
bitStream.Write(characters[i]->GetRightHand());
bitStream.Write(characters[i]->GetEyebrows());
bitStream.Write(characters[i]->GetEyes());
bitStream.Write(characters[i]->GetMouth());
bitStream.Write(static_cast<uint32_t>(0));
bitStream.Write(static_cast<uint16_t>(characters[i]->GetZoneID()));
bitStream.Write(static_cast<uint16_t>(characters[i]->GetZoneInstance()));
bitStream.Write(characters[i]->GetZoneClone());
bitStream.Write(static_cast<uint16_t>(characters[i]->GetZoneID()));
bitStream.Write(static_cast<uint16_t>(characters[i]->GetZoneInstance()));
bitStream.Write(characters[i]->GetZoneClone());
bitStream.Write(characters[i]->GetLastLogin());
bitStream.Write(characters[i]->GetLastLogin());
const auto& equippedItems = characters[i]->GetEquippedItems();
bitStream.Write(static_cast<uint16_t>(equippedItems.size()));
const auto& equippedItems = characters[i]->GetEquippedItems();
bitStream.Write(static_cast<uint16_t>(equippedItems.size()));
for (uint32_t j = 0; j < equippedItems.size(); ++j) {
bitStream.Write(equippedItems[j]);
}
for (uint32_t j = 0; j < equippedItems.size(); ++j) {
bitStream.Write(equippedItems[j]);
}
}
SEND_PACKET
}
void WorldPackets::SendCharacterCreationResponse ( const SystemAddress& sysAddr, eCreationResponse response ) {
void WorldPackets::SendCharacterCreationResponse(const SystemAddress& sysAddr, eCreationResponse response) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CHARACTER_CREATE_RESPONSE);
bitStream.Write(response);
SEND_PACKET
}
void WorldPackets::SendCharacterRenameResponse ( const SystemAddress& sysAddr, eRenameResponse response ) {
void WorldPackets::SendCharacterRenameResponse(const SystemAddress& sysAddr, eRenameResponse response) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CHARACTER_RENAME_RESPONSE);
bitStream.Write(response);
@@ -103,13 +103,13 @@ void WorldPackets::SendCharacterRenameResponse ( const SystemAddress& sysAddr, e
}
void WorldPackets::SendCharacterDeleteResponse(const SystemAddress& sysAddr, bool response) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_DELETE_CHARACTER_RESPONSE);
bitStream.Write(static_cast<uint8_t>(response));
SEND_PACKET
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_DELETE_CHARACTER_RESPONSE);
bitStream.Write(static_cast<uint8_t>(response));
SEND_PACKET
}
void WorldPackets::SendTransferToWorld ( const SystemAddress& sysAddr, const std::string& serverIP, uint32_t serverPort, bool mythranShift ) {
void WorldPackets::SendTransferToWorld(const SystemAddress& sysAddr, const std::string& serverIP, uint32_t serverPort, bool mythranShift) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_TRANSFER_TO_WORLD);
@@ -120,7 +120,7 @@ void WorldPackets::SendTransferToWorld ( const SystemAddress& sysAddr, const std
SEND_PACKET
}
void WorldPackets::SendServerState ( const SystemAddress& sysAddr ) {
void WorldPackets::SendServerState(const SystemAddress& sysAddr) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_SERVER_STATES);
bitStream.Write(static_cast<uint8_t>(1)); //If the server is receiving this request, it probably is ready anyway.
@@ -128,98 +128,98 @@ void WorldPackets::SendServerState ( const SystemAddress& sysAddr ) {
}
void WorldPackets::SendCreateCharacter(const SystemAddress& sysAddr, Entity* entity, const std::string& xmlData, const std::u16string& username, int32_t gm) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CREATE_CHARACTER);
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CREATE_CHARACTER);
RakNet::BitStream data;
data.Write<uint32_t>(7); //LDF key count
RakNet::BitStream data;
data.Write<uint32_t>(7); //LDF key count
auto character = entity->GetComponent<CharacterComponent>();
if (!character) {
Game::logger->Log("WorldPackets", "Entity is not a character?? what??");
return;
}
auto character = entity->GetComponent<CharacterComponent>();
if (!character) {
Game::logger->Log("WorldPackets", "Entity is not a character?? what??");
return;
}
LDFData<LWOOBJID>* objid = new LDFData<LWOOBJID>(u"objid", entity->GetObjectID());
LDFData<LOT>* lot = new LDFData<LOT>(u"template", 1);
LDFData<std::string> * xmlConfigData = new LDFData<std::string>(u"xmlData", xmlData);
LDFData<std::u16string>* name = new LDFData<std::u16string>(u"name", username);
LDFData<int32_t>* gmlevel = new LDFData<int32_t>(u"gmlevel", gm);
LDFData<int32_t>* chatmode = new LDFData<int32_t>(u"chatmode", gm);
LDFData<int64_t>* reputation = new LDFData<int64_t>(u"reputation", character->GetReputation());
LDFData<LWOOBJID>* objid = new LDFData<LWOOBJID>(u"objid", entity->GetObjectID());
LDFData<LOT>* lot = new LDFData<LOT>(u"template", 1);
LDFData<std::string>* xmlConfigData = new LDFData<std::string>(u"xmlData", xmlData);
LDFData<std::u16string>* name = new LDFData<std::u16string>(u"name", username);
LDFData<int32_t>* gmlevel = new LDFData<int32_t>(u"gmlevel", gm);
LDFData<int32_t>* chatmode = new LDFData<int32_t>(u"chatmode", gm);
LDFData<int64_t>* reputation = new LDFData<int64_t>(u"reputation", character->GetReputation());
objid->WriteToPacket(&data);
lot->WriteToPacket(&data);
name->WriteToPacket(&data);
gmlevel->WriteToPacket(&data);
chatmode->WriteToPacket(&data);
xmlConfigData->WriteToPacket(&data);
reputation->WriteToPacket(&data);
objid->WriteToPacket(&data);
lot->WriteToPacket(&data);
name->WriteToPacket(&data);
gmlevel->WriteToPacket(&data);
chatmode->WriteToPacket(&data);
xmlConfigData->WriteToPacket(&data);
reputation->WriteToPacket(&data);
delete objid;
delete lot;
delete xmlConfigData;
delete gmlevel;
delete chatmode;
delete name;
delete reputation;
delete objid;
delete lot;
delete xmlConfigData;
delete gmlevel;
delete chatmode;
delete name;
delete reputation;
#ifdef _WIN32
bitStream.Write<uint32_t>(data.GetNumberOfBytesUsed() + 1);
bitStream.Write<uint8_t>(0);
bitStream.Write((char*)data.GetData(), data.GetNumberOfBytesUsed());
bitStream.Write<uint32_t>(data.GetNumberOfBytesUsed() + 1);
bitStream.Write<uint8_t>(0);
bitStream.Write((char*)data.GetData(), data.GetNumberOfBytesUsed());
#else
//Compress the data before sending:
const int reservedSize = 5 * 1024 * 1024;
uint8_t compressedData[reservedSize];
size_t size = ZCompression::Compress(data.GetData(), data.GetNumberOfBytesUsed(), compressedData, reservedSize);
//Compress the data before sending:
const int reservedSize = 5 * 1024 * 1024;
uint8_t compressedData[reservedSize];
size_t size = ZCompression::Compress(data.GetData(), data.GetNumberOfBytesUsed(), compressedData, reservedSize);
bitStream.Write<uint32_t>(size + 9); //size of data + header bytes (8)
bitStream.Write<uint8_t>(1); //compressed boolean, true
bitStream.Write<uint32_t>(data.GetNumberOfBytesUsed());
bitStream.Write<uint32_t>(size);
bitStream.Write<uint32_t>(size + 9); //size of data + header bytes (8)
bitStream.Write<uint8_t>(1); //compressed boolean, true
bitStream.Write<uint32_t>(data.GetNumberOfBytesUsed());
bitStream.Write<uint32_t>(size);
for (size_t i = 0; i < size; i++)
bitStream.Write(compressedData[i]);
for (size_t i = 0; i < size; i++)
bitStream.Write(compressedData[i]);
#endif
PacketUtils::SavePacket("chardata.bin", (const char *)bitStream.GetData(), static_cast<uint32_t>(bitStream.GetNumberOfBytesUsed()));
SEND_PACKET
Game::logger->Log("WorldPackets", "Sent CreateCharacter for ID: %llu", entity->GetObjectID());
PacketUtils::SavePacket("chardata.bin", (const char*)bitStream.GetData(), static_cast<uint32_t>(bitStream.GetNumberOfBytesUsed()));
SEND_PACKET
Game::logger->Log("WorldPackets", "Sent CreateCharacter for ID: %llu", entity->GetObjectID());
}
void WorldPackets::SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::vector<std::pair<uint8_t, uint8_t>> unacceptedItems) {
CBITSTREAM
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CHAT_MODERATION_STRING);
CBITSTREAM
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CHAT_MODERATION_STRING);
bitStream.Write<uint8_t>(unacceptedItems.empty()); // Is sentence ok?
bitStream.Write<uint16_t>(0x16); // Source ID, unknown
bitStream.Write<uint8_t>(unacceptedItems.empty()); // Is sentence ok?
bitStream.Write<uint16_t>(0x16); // Source ID, unknown
bitStream.Write(static_cast<uint8_t>(requestID)); // request ID
bitStream.Write(static_cast<char>(0)); // chat mode
bitStream.Write(static_cast<uint8_t>(requestID)); // request ID
bitStream.Write(static_cast<char>(0)); // chat mode
PacketUtils::WritePacketWString(receiver, 42, &bitStream); // receiver name
PacketUtils::WritePacketWString(receiver, 42, &bitStream); // receiver name
for (auto it : unacceptedItems) {
bitStream.Write<uint8_t>(it.first); // start index
bitStream.Write<uint8_t>(it.second); // length
}
for (auto it : unacceptedItems) {
bitStream.Write<uint8_t>(it.first); // start index
bitStream.Write<uint8_t>(it.second); // length
}
for (int i = unacceptedItems.size(); 64 > i; i++) {
bitStream.Write<uint16_t>(0);
}
for (int i = unacceptedItems.size(); 64 > i; i++) {
bitStream.Write<uint16_t>(0);
}
SEND_PACKET
SEND_PACKET
}
void WorldPackets::SendGMLevelChange(const SystemAddress& sysAddr, bool success, uint8_t highestLevel, uint8_t prevLevel, uint8_t newLevel) {
CBITSTREAM
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_MAKE_GM_RESPONSE);
CBITSTREAM
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_MAKE_GM_RESPONSE);
bitStream.Write<uint8_t>(success);
bitStream.Write<uint16_t>(highestLevel);
bitStream.Write<uint16_t>(prevLevel);
bitStream.Write<uint16_t>(newLevel);
bitStream.Write<uint8_t>(success);
bitStream.Write<uint16_t>(highestLevel);
bitStream.Write<uint16_t>(prevLevel);
bitStream.Write<uint16_t>(newLevel);
SEND_PACKET
SEND_PACKET
}

View File

@@ -10,16 +10,16 @@ class User;
struct SystemAddress;
namespace WorldPackets {
void SendLoadStaticZone(const SystemAddress& sysAddr, float x, float y, float z, uint32_t checksum);
void SendCharacterList(const SystemAddress& sysAddr, User * user);
void SendLoadStaticZone(const SystemAddress& sysAddr, float x, float y, float z, uint32_t checksum);
void SendCharacterList(const SystemAddress& sysAddr, User* user);
void SendCharacterCreationResponse(const SystemAddress& sysAddr, eCreationResponse response);
void SendCharacterRenameResponse(const SystemAddress& sysAddr, eRenameResponse response);
void SendCharacterDeleteResponse(const SystemAddress& sysAddr, bool response);
void SendCharacterDeleteResponse(const SystemAddress& sysAddr, bool response);
void SendTransferToWorld(const SystemAddress& sysAddr, const std::string& serverIP, uint32_t serverPort, bool mythranShift);
void SendServerState(const SystemAddress& sysAddr);
void SendCreateCharacter(const SystemAddress& sysAddr, Entity* entity, const std::string& xmlData, const std::u16string& username, int32_t gm);
void SendCreateCharacter(const SystemAddress& sysAddr, Entity* entity, const std::string& xmlData, const std::u16string& username, int32_t gm);
void SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::vector<std::pair<uint8_t, uint8_t>> unacceptedItems);
void SendGMLevelChange(const SystemAddress& sysAddr, bool success, uint8_t highestLevel, uint8_t prevLevel, uint8_t newLevel);
void SendGMLevelChange(const SystemAddress& sysAddr, bool success, uint8_t highestLevel, uint8_t prevLevel, uint8_t newLevel);
}
#endif // WORLDPACKETS_H

View File

@@ -10,60 +10,58 @@
#include <future>
// Static Variables
ZoneInstanceManager * ZoneInstanceManager::m_Address = nullptr;
ZoneInstanceManager* ZoneInstanceManager::m_Address = nullptr;
//! Requests a zone transfer
void ZoneInstanceManager::RequestZoneTransfer(dServer* server, uint32_t zoneID, uint32_t zoneClone, bool mythranShift, std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t)> callback) {
ZoneTransferRequest * request = new ZoneTransferRequest();
request->requestID = ++currentRequestID;
request->callback = callback;
this->requests.push_back(request);
MasterPackets::SendZoneTransferRequest(server, request->requestID, mythranShift, zoneID, zoneClone);
ZoneTransferRequest* request = new ZoneTransferRequest();
request->requestID = ++currentRequestID;
request->callback = callback;
this->requests.push_back(request);
MasterPackets::SendZoneTransferRequest(server, request->requestID, mythranShift, zoneID, zoneClone);
}
//! Handles a zone transfer response
void ZoneInstanceManager::HandleRequestZoneTransferResponse(uint64_t requestID, Packet * packet) {
bool mythranShift = static_cast<bool>(packet->data[16]);
uint32_t zoneID = PacketUtils::ReadPacketU32(17, packet);
uint32_t zoneInstance = PacketUtils::ReadPacketU32(21, packet);
uint32_t zoneClone = PacketUtils::ReadPacketU32(25, packet);
uint16_t serverPort = PacketUtils::ReadPacketU16(29, packet);
std::string serverIP = PacketUtils::ReadString(31, packet, false);
for (uint32_t i = 0; i < this->requests.size(); ++i) {
if (this->requests[i]->requestID == requestID) {
// Call the request callback
this->requests[i]->callback(mythranShift, zoneID, zoneInstance, zoneClone, serverIP, serverPort);
delete this->requests[i];
this->requests.erase(this->requests.begin() + i);
return;
}
}
void ZoneInstanceManager::HandleRequestZoneTransferResponse(uint64_t requestID, Packet* packet) {
bool mythranShift = static_cast<bool>(packet->data[16]);
uint32_t zoneID = PacketUtils::ReadPacketU32(17, packet);
uint32_t zoneInstance = PacketUtils::ReadPacketU32(21, packet);
uint32_t zoneClone = PacketUtils::ReadPacketU32(25, packet);
uint16_t serverPort = PacketUtils::ReadPacketU16(29, packet);
std::string serverIP = PacketUtils::ReadString(31, packet, false);
for (uint32_t i = 0; i < this->requests.size(); ++i) {
if (this->requests[i]->requestID == requestID) {
// Call the request callback
this->requests[i]->callback(mythranShift, zoneID, zoneInstance, zoneClone, serverIP, serverPort);
delete this->requests[i];
this->requests.erase(this->requests.begin() + i);
return;
}
}
}
void ZoneInstanceManager::CreatePrivateZone(dServer* server, uint32_t zoneID, uint32_t zoneClone, const std::string& password)
{
MasterPackets::SendZoneCreatePrivate(server, zoneID, zoneClone, password);
void ZoneInstanceManager::CreatePrivateZone(dServer* server, uint32_t zoneID, uint32_t zoneClone, const std::string& password) {
MasterPackets::SendZoneCreatePrivate(server, zoneID, zoneClone, password);
}
void ZoneInstanceManager::RequestPrivateZone(
dServer* server,
bool mythranShift,
dServer* server,
bool mythranShift,
const std::string& password,
std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t)> callback)
{
ZoneTransferRequest* request = new ZoneTransferRequest();
request->requestID = ++currentRequestID;
request->callback = callback;
std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t)> callback) {
ZoneTransferRequest* request = new ZoneTransferRequest();
request->requestID = ++currentRequestID;
request->callback = callback;
this->requests.push_back(request);
this->requests.push_back(request);
MasterPackets::SendZoneRequestPrivate(server, request->requestID, mythranShift, password);
MasterPackets::SendZoneRequestPrivate(server, request->requestID, mythranShift, password);
}

View File

@@ -16,50 +16,50 @@ class dServer;
\brief A class for handling zone transfers and zone-related functions
*/
//! The zone request
//! The zone request
struct ZoneTransferRequest {
uint64_t requestID;
std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t)> callback;
uint64_t requestID;
std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t)> callback;
};
//! The zone manager
class ZoneInstanceManager {
private:
static ZoneInstanceManager * m_Address; //!< The singleton instance
std::vector<ZoneTransferRequest*> requests; //!< The zone transfer requests
uint64_t currentRequestID; //!< The current request ID
public:
//! The singleton method
static ZoneInstanceManager * Instance() {
if (m_Address == 0) {
m_Address = new ZoneInstanceManager;
m_Address->currentRequestID = 0;
}
return m_Address;
}
//! Requests a zone transfer
/*!
\param zoneID The zone ID
\param zoneClone The zone clone
\param mythranShift Whether or not this is a mythran shift
\param callback The callback function
*/
void RequestZoneTransfer(dServer* server, uint32_t zoneID, uint32_t zoneClone, bool mythranShift, std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t)> callback);
//! Handles a zone transfer response
/*!
\param requestID The request ID
\param packet The packet
*/
void HandleRequestZoneTransferResponse(uint64_t requestID, Packet * packet);
static ZoneInstanceManager* m_Address; //!< The singleton instance
void CreatePrivateZone(dServer* server, uint32_t zoneID, uint32_t zoneClone, const std::string& password);
void RequestPrivateZone(dServer* server, bool mythranShift, const std::string& password, std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t)> callback);
std::vector<ZoneTransferRequest*> requests; //!< The zone transfer requests
uint64_t currentRequestID; //!< The current request ID
public:
//! The singleton method
static ZoneInstanceManager* Instance() {
if (m_Address == 0) {
m_Address = new ZoneInstanceManager;
m_Address->currentRequestID = 0;
}
return m_Address;
}
//! Requests a zone transfer
/*!
\param zoneID The zone ID
\param zoneClone The zone clone
\param mythranShift Whether or not this is a mythran shift
\param callback The callback function
*/
void RequestZoneTransfer(dServer* server, uint32_t zoneID, uint32_t zoneClone, bool mythranShift, std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t)> callback);
//! Handles a zone transfer response
/*!
\param requestID The request ID
\param packet The packet
*/
void HandleRequestZoneTransferResponse(uint64_t requestID, Packet* packet);
void CreatePrivateZone(dServer* server, uint32_t zoneID, uint32_t zoneClone, const std::string& password);
void RequestPrivateZone(dServer* server, bool mythranShift, const std::string& password, std::function<void(bool, uint32_t, uint32_t, uint32_t, std::string, uint16_t)> callback);
};

View File

@@ -252,7 +252,7 @@ enum MASTER {
MSG_MASTER_WORLD_READY,
MSG_MASTER_PREP_ZONE,
MSG_MASTER_SHUTDOWN,
MSG_MASTER_SHUTDOWN_RESPONSE,
MSG_MASTER_SHUTDOWN_IMMEDIATE,

View File

@@ -3,4 +3,4 @@
#include "RakPeer.h"
#define NET_PASSWORD_EXTERNAL "3.25 ND1"
#define NET_PASSWORD_INTERNAL "3.25 DARKFLAME1"
#define NET_PASSWORD_INTERNAL "3.25 DARKFLAME1"

View File

@@ -14,25 +14,25 @@
//! Replica Constructor class
class ReplicaConstructor : public ReceiveConstructionInterface {
public:
ReplicaReturnResult ReceiveConstruction(RakNet::BitStream *inBitStream, RakNetTime timestamp, NetworkID networkID, NetworkIDObject *existingObject, SystemAddress senderId, ReplicaManager *caller) {
return REPLICA_PROCESSING_DONE;
}
ReplicaReturnResult ReceiveConstruction(RakNet::BitStream* inBitStream, RakNetTime timestamp, NetworkID networkID, NetworkIDObject* existingObject, SystemAddress senderId, ReplicaManager* caller) {
return REPLICA_PROCESSING_DONE;
}
} ConstructionCB;
//! Replica Download Sender class
class ReplicaSender : public SendDownloadCompleteInterface {
public:
ReplicaReturnResult SendDownloadComplete(RakNet::BitStream *outBitStream, RakNetTime currentTime, SystemAddress senderId, ReplicaManager *caller) {
return REPLICA_PROCESSING_DONE;
}
ReplicaReturnResult SendDownloadComplete(RakNet::BitStream* outBitStream, RakNetTime currentTime, SystemAddress senderId, ReplicaManager* caller) {
return REPLICA_PROCESSING_DONE;
}
} SendDownloadCompleteCB;
//! Replica Download Receiver class
class ReplicaReceiever : public ReceiveDownloadCompleteInterface {
public:
ReplicaReturnResult ReceiveDownloadComplete(RakNet::BitStream *inBitStream, SystemAddress senderId, ReplicaManager *caller) {
return REPLICA_PROCESSING_DONE;
}
ReplicaReturnResult ReceiveDownloadComplete(RakNet::BitStream* inBitStream, SystemAddress senderId, ReplicaManager* caller) {
return REPLICA_PROCESSING_DONE;
}
} ReceiveDownloadCompleteCB;
dServer::dServer(const std::string& ip, int port, int instanceID, int maxConnections, bool isInternal, bool useEncryption, dLogger* logger, const std::string masterIP, int masterPort, ServerType serverType, unsigned int zoneID) {
@@ -63,8 +63,7 @@ dServer::dServer(const std::string& ip, int port, int instanceID, int maxConnect
mLogger->Log("dServer", "Server is listening on %s:%i with encryption: %i", ip.c_str(), port, int(useEncryption));
else
mLogger->Log("dServer", "Server is listening on %s:%i with encryption: %i, running zone %i / %i", ip.c_str(), port, int(useEncryption), zoneID, instanceID);
}
else { mLogger->Log("dServer", "FAILED TO START SERVER ON IP/PORT: %s:%i", ip.c_str(), port); return; }
} else { mLogger->Log("dServer", "FAILED TO START SERVER ON IP/PORT: %s:%i", ip.c_str(), port); return; }
mLogger->SetLogToConsole(prevLogSetting);
@@ -110,7 +109,7 @@ Packet* dServer::ReceiveFromMaster() {
}
if (packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED) {
mLogger->Log("dServer", "Established connection to master, zone (%i), instance (%i)",this->GetZoneID(), this->GetInstanceID());
mLogger->Log("dServer", "Established connection to master, zone (%i), instance (%i)", this->GetZoneID(), this->GetInstanceID());
mMasterConnectionActive = true;
mMasterSystemAddress = packet->systemAddress;
MasterPackets::SendServerInfo(this, packet);
@@ -119,16 +118,16 @@ Packet* dServer::ReceiveFromMaster() {
if (packet->data[0] == ID_USER_PACKET_ENUM) {
if (packet->data[1] == MASTER) {
switch (packet->data[3]) {
case MSG_MASTER_REQUEST_ZONE_TRANSFER_RESPONSE: {
uint64_t requestID = PacketUtils::ReadPacketU64(8, packet);
ZoneInstanceManager::Instance()->HandleRequestZoneTransferResponse(requestID, packet);
break;
}
case MSG_MASTER_REQUEST_ZONE_TRANSFER_RESPONSE: {
uint64_t requestID = PacketUtils::ReadPacketU64(8, packet);
ZoneInstanceManager::Instance()->HandleRequestZoneTransferResponse(requestID, packet);
break;
}
//When we handle these packets in World instead dServer, we just return the packet's pointer.
default:
//When we handle these packets in World instead dServer, we just return the packet's pointer.
default:
return packet;
return packet;
}
}
}
@@ -143,15 +142,15 @@ Packet* dServer::Receive() {
return mPeer->Receive();
}
void dServer::DeallocatePacket(Packet * packet) {
void dServer::DeallocatePacket(Packet* packet) {
mPeer->DeallocatePacket(packet);
}
void dServer::DeallocateMasterPacket(Packet * packet) {
void dServer::DeallocateMasterPacket(Packet* packet) {
mMasterPeer->DeallocatePacket(packet);
}
void dServer::Send(RakNet::BitStream * bitStream, const SystemAddress & sysAddr, bool broadcast) {
void dServer::Send(RakNet::BitStream* bitStream, const SystemAddress& sysAddr, bool broadcast) {
mPeer->Send(bitStream, SYSTEM_PRIORITY, RELIABLE_ORDERED, 0, sysAddr, broadcast);
}
@@ -182,8 +181,7 @@ bool dServer::Startup() {
if (mIsInternal) {
mPeer->SetIncomingPassword("3.25 DARKFLAME1", 15);
}
else {
} else {
//mPeer->SetPerConnectionOutgoingBandwidthLimit(800000); //100Kb/s
mPeer->SetIncomingPassword("3.25 ND1", 8);
}
@@ -228,12 +226,10 @@ void dServer::UpdateReplica() {
mReplicaManager->Update(mPeer);
}
int dServer::GetPing(const SystemAddress& sysAddr) const
{
int dServer::GetPing(const SystemAddress& sysAddr) const {
return mPeer->GetAveragePing(sysAddr);
}
int dServer::GetLatestPing(const SystemAddress& sysAddr) const
{
int dServer::GetLatestPing(const SystemAddress& sysAddr) const {
return mPeer->GetLastPing(sysAddr);
}

View File

@@ -61,7 +61,7 @@ private:
NetworkIDManager* mNetIDManager;
SocketDescriptor mSocketDescriptor;
std::string mIP;
int mPort;
int mPort;
int mMaxConnections;
unsigned int mZoneID;
int mInstanceID;
@@ -76,4 +76,4 @@ private:
SystemAddress mMasterSystemAddress;
std::string mMasterIP;
int mMasterPort;
};
};