Merge branch 'main' into guild_temp

This commit is contained in:
Aaron Kimbre
2023-11-15 21:14:20 -06:00
842 changed files with 22115 additions and 15964 deletions

View File

@@ -1,14 +1,15 @@
#include "AuthPackets.h"
#include "PacketUtils.h"
#include "dMessageIdentifiers.h"
#include "BitStreamUtils.h"
#include "dNetCommon.h"
#include "dServer.h"
#include "dLogger.h"
#include "Logger.h"
#include "Database.h"
#include "ZoneInstanceManager.h"
#include "MD5.h"
#include "SHA512.h"
#include "GeneralUtils.h"
#ifdef _WIN32
#include <bcrypt/BCrypt.hpp>
@@ -21,6 +22,11 @@
#include "Game.h"
#include "dConfig.h"
#include "eServerDisconnectIdentifiers.h"
#include "eLoginResponse.h"
#include "eConnectionType.h"
#include "eServerMessageType.h"
#include "eMasterMessageType.h"
void AuthPackets::HandleHandshake(dServer* server, Packet* packet) {
RakNet::BitStream inStream(packet->data, packet->length, false);
@@ -28,14 +34,19 @@ void AuthPackets::HandleHandshake(dServer* server, Packet* packet) {
uint32_t clientVersion = 0;
inStream.Read(clientVersion);
server->GetLogger()->Log("AuthPackets", "Received client version: %i", clientVersion);
LOG("Received client version: %i", clientVersion);
SendHandshake(server, packet->systemAddress, server->GetIP(), server->GetPort(), server->GetServerType());
}
void AuthPackets::SendHandshake(dServer* server, const SystemAddress& sysAddr, const std::string& nextServerIP, uint16_t nextServerPort, const ServerType serverType) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, SERVER, MSG_SERVER_VERSION_CONFIRM);
bitStream.Write<unsigned int>(NET_VERSION);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::SERVER, eServerMessageType::VERSION_CONFIRM);
uint32_t netVersion;
if (!GeneralUtils::TryParse(Game::config->GetValue("client_net_version"), netVersion)) {
LOG("Failed to parse client_net_version. Cannot authenticate to %s:%i", nextServerIP.c_str(), nextServerPort);
return;
}
bitStream.Write<uint32_t>(netVersion);
bitStream.Write(uint32_t(0x93));
if (serverType == ServerType::Auth) bitStream.Write(uint32_t(1)); //Conn: auth
@@ -59,8 +70,8 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
sql::ResultSet* res = stmt->executeQuery();
if (res->rowsCount() == 0) {
server->GetLogger()->Log("AuthPackets", "No user found!");
AuthPackets::SendLoginResponse(server, packet->systemAddress, LOGIN_RESPONSE_WRONG_PASS_OR_USER, "", "", 2001, username);
LOG("No user found!");
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::INVALID_USER, "", "", 2001, username);
return;
}
@@ -84,15 +95,15 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
//If we aren't running in live mode, then only GMs are allowed to enter:
const auto& closedToNonDevs = Game::config->GetValue("closed_to_non_devs");
if (closedToNonDevs.size() > 0 && bool(std::stoi(closedToNonDevs)) && sqlGmLevel == 0) {
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::LOGIN_RESPONSE_PERMISSIONS_NOT_HIGH_ENOUGH, "The server is currently only open to developers.", "", 2001, username);
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::PERMISSIONS_NOT_HIGH_ENOUGH, "The server is currently only open to developers.", "", 2001, username);
return;
}
if (Game::config->GetValue("dont_use_keys") != "1") {
//Check to see if we have a play key:
if (sqlPlayKey == 0 && sqlGmLevel == 0) {
AuthPackets::SendLoginResponse(server, packet->systemAddress, LOGIN_RESPONSE_PERMISSIONS_NOT_HIGH_ENOUGH, "Your account doesn't have a play key associated with it!", "", 2001, username);
server->GetLogger()->Log("AuthPackets", "User %s tried to log in, but they don't have a play key.", username.c_str());
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::PERMISSIONS_NOT_HIGH_ENOUGH, "Your account doesn't have a play key associated with it!", "", 2001, username);
LOG("User %s tried to log in, but they don't have a play key.", username.c_str());
return;
}
@@ -103,7 +114,7 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
bool isKeyActive = false;
if (keyRes->rowsCount() == 0 && sqlGmLevel == 0) {
AuthPackets::SendLoginResponse(server, packet->systemAddress, LOGIN_RESPONSE_PERMISSIONS_NOT_HIGH_ENOUGH, "Your account doesn't have a play key associated with it!", "", 2001, username);
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::PERMISSIONS_NOT_HIGH_ENOUGH, "Your account doesn't have a play key associated with it!", "", 2001, username);
return;
}
@@ -112,18 +123,18 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
}
if (!isKeyActive && sqlGmLevel == 0) {
AuthPackets::SendLoginResponse(server, packet->systemAddress, LOGIN_RESPONSE_PERMISSIONS_NOT_HIGH_ENOUGH, "Your play key has been disabled.", "", 2001, username);
server->GetLogger()->Log("AuthPackets", "User %s tried to log in, but their play key was disabled", username.c_str());
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::PERMISSIONS_NOT_HIGH_ENOUGH, "Your play key has been disabled.", "", 2001, username);
LOG("User %s tried to log in, but their play key was disabled", username.c_str());
return;
}
}
if (sqlBanned) {
AuthPackets::SendLoginResponse(server, packet->systemAddress, LOGIN_RESPONSE_BANNED, "", "", 2001, username); return;
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::BANNED, "", "", 2001, username); return;
}
if (sqlLocked) {
AuthPackets::SendLoginResponse(server, packet->systemAddress, LOGIN_RESPONSE_ACCOUNT_LOCKED, "", "", 2001, username); return;
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::ACCOUNT_LOCKED, "", "", 2001, username); return;
}
/*
@@ -169,75 +180,74 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
}
if (!loginSuccess) {
AuthPackets::SendLoginResponse(server, packet->systemAddress, LOGIN_RESPONSE_WRONG_PASS_OR_USER, "", "", 2001, username);
server->GetLogger()->Log("AuthPackets", "Wrong password used");
AuthPackets::SendLoginResponse(server, packet->systemAddress, eLoginResponse::WRONG_PASS, "", "", 2001, username);
LOG("Wrong password used");
} else {
SystemAddress system = packet->systemAddress; //Copy the sysAddr before the Packet gets destroyed from main
if (!server->GetIsConnectedToMaster()) {
AuthPackets::SendLoginResponse(server, system, LOGIN_RESPONSE_GENERAL_FAILED, "", "", 0, username);
AuthPackets::SendLoginResponse(server, system, eLoginResponse::GENERAL_FAILED, "", "", 0, username);
return;
}
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);
AuthPackets::SendLoginResponse(server, system, eLoginResponse::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);
BitStreamUtils::WriteHeader(packet, eConnectionType::CLIENT, eClientMessageType::LOGIN_RESPONSE);
packet.Write(static_cast<uint8_t>(responseCode));
PacketUtils::WritePacketString("Talk_Like_A_Pirate", 33, &packet);
// 7 unknown strings - perhaps other IP addresses?
PacketUtils::WritePacketString("guilds", 33, &packet);
PacketUtils::WritePacketString("ninjago2", 33, &packet);
PacketUtils::WritePacketString("test", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
// Event Gating
packet.Write(LUString("Talk_Like_A_Pirate"));
packet.Write(LUString(""));
packet.Write(LUString(""));
packet.Write(LUString(""));
packet.Write(LUString(""));
packet.Write(LUString(""));
packet.Write(LUString(""));
packet.Write(LUString(""));
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
uint32_t sessionKey = rand(); // not mt but whatever
uint32_t sessionKey = GeneralUtils::GenerateRandomNumber<uint32_t>();
std::string userHash = std::to_string(sessionKey);
userHash = md5(userHash);
PacketUtils::WritePacketWString(userHash, 33, &packet);
packet.Write(LUWString(userHash));
// Write the Character and Chat IPs
PacketUtils::WritePacketString(wServerIP, 33, &packet);
PacketUtils::WritePacketString("", 33, &packet);
packet.Write(LUString(wServerIP));
packet.Write(LUString(""));
// 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);
// CDN Key
packet.Write(LUString(""));
// Write a GUID or something...
PacketUtils::WritePacketString("00000000-0000-0000-0000-000000000000", 37, &packet);
// CDN Ticket
packet.Write(LUString("00000000-0000-0000-0000-000000000000", 37));
packet.Write(static_cast<uint32_t>(0)); // ???
packet.Write(static_cast<uint32_t>(0)); // Language
// Write the localization
PacketUtils::WritePacketString("US", 3, &packet);
packet.Write(LUString("US", 3));
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)); // Just upgraded from F2P
packet.Write(static_cast<uint8_t>(false)); // User is F2P
packet.Write(static_cast<uint64_t>(0)); // Time Remaining in F2P
// Write custom error message
packet.Write(static_cast<uint16_t>(errorMsg.length()));
PacketUtils::WritePacketWString(errorMsg, static_cast<uint32_t>(errorMsg.length()), &packet);
packet.Write(LUWString(errorMsg, static_cast<uint32_t>(errorMsg.length())));
// Here write auth logs
packet.Write(static_cast<uint32_t>(20));
@@ -253,11 +263,11 @@ void AuthPackets::SendLoginResponse(dServer* server, const SystemAddress& sysAdd
//Inform the master server that we've created a session for this user:
{
CBITSTREAM;
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_SET_SESSION_KEY);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::SET_SESSION_KEY);
bitStream.Write(sessionKey);
PacketUtils::WriteString(bitStream, username, 66);
bitStream.Write(LUString(username, 66));
server->SendToMaster(&bitStream);
server->GetLogger()->Log("AuthPackets", "Set sessionKey: %i for user %s", sessionKey, username.c_str());
LOG("Set sessionKey: %i for user %s", sessionKey, username.c_str());
}
}

View File

@@ -6,6 +6,7 @@
#include "dNetCommon.h"
enum class ServerType : uint32_t;
enum class eLoginResponse : uint8_t;
class dServer;
namespace AuthPackets {

104
dNet/BitStreamUtils.h Normal file
View File

@@ -0,0 +1,104 @@
#ifndef __BITSTREAMUTILS__H__
#define __BITSTREAMUTILS__H__
#include "GeneralUtils.h"
#include "MessageIdentifiers.h"
#include "BitStream.h"
#include <string>
enum class eConnectionType : uint16_t;
struct LUString {
std::string string;
uint32_t size;
LUString(uint32_t size) {
this->size = size;
};
LUString(std::string string, uint32_t size = 33) {
this->string = string;
this->size = size;
};
std::u16string GetAsU16String() const {
return GeneralUtils::ASCIIToUTF16(this->string);
};
};
struct LUWString {
std::u16string string;
uint32_t size;
LUWString(uint32_t size) {
this->size = size;
};
LUWString(std::u16string string, uint32_t size = 33) {
this->string = string;
this->size = size;
};
LUWString(std::string string, uint32_t size = 33) {
this->string = GeneralUtils::ASCIIToUTF16(string);
this->size = size;
};
std::string GetAsString() const {
return GeneralUtils::UTF16ToWTF8(this->string);
};
};
namespace BitStreamUtils {
template<typename T>
void WriteHeader(RakNet::BitStream& bitStream, eConnectionType connectionType, T internalPacketID) {
bitStream.Write<uint8_t>(MessageID(ID_USER_PACKET_ENUM));
bitStream.Write<eConnectionType>(connectionType);
bitStream.Write<uint32_t>(static_cast<uint32_t>(internalPacketID));
bitStream.Write<uint8_t>(0);
}
}
namespace RakNet {
#ifndef __BITSTREAM_NATIVE_END
#error No definition for big endian reading of LUString
#endif
template <>
inline bool RakNet::BitStream::Read<LUString>(LUString& value) {
value.string.resize(value.size);
bool res = ReadBits(reinterpret_cast<unsigned char*>(value.string.data()), BYTES_TO_BITS(value.string.size()), true);
if (!res) return false;
value.string.erase(std::find(value.string.begin(), value.string.end(), '\0'), value.string.end());
return res;
}
template <>
inline bool RakNet::BitStream::Read<LUWString>(LUWString& value) {
value.string.resize(value.size);
bool res = ReadBits(reinterpret_cast<unsigned char*>(value.string.data()), BYTES_TO_BITS(value.string.size()) * sizeof(std::u16string::value_type), true);
if (!res) return false;
value.string.erase(std::find(value.string.begin(), value.string.end(), u'\0'), value.string.end());
return res;
}
template <>
inline void RakNet::BitStream::Write<std::string>(std::string value) {
this->WriteBits(reinterpret_cast<const unsigned char*>(value.data()), BYTES_TO_BITS(value.size()));
}
template <>
inline void RakNet::BitStream::Write<std::u16string>(std::u16string value) {
this->WriteBits(reinterpret_cast<const unsigned char*>(value.data()), BYTES_TO_BITS(value.size()) * sizeof(std::u16string::value_type));
}
template <>
inline void RakNet::BitStream::Write<LUString>(LUString value) {
value.string.resize(value.size);
this->Write(value.string);
}
template <>
inline void RakNet::BitStream::Write<LUWString>(LUWString value) {
value.string.resize(value.size);
this->Write(value.string);
}
};
#endif //!__BITSTREAMUTILS__H__

View File

@@ -8,18 +8,20 @@
#include "BitStream.h"
#include "Game.h"
#include "PacketUtils.h"
#include "dMessageIdentifiers.h"
#include "BitStreamUtils.h"
#include "dServer.h"
#include "eConnectionType.h"
#include "eChatMessageType.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);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::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);
bitStream.Write(LUWString(senderName));
bitStream.Write(playerObjectID);
bitStream.Write(static_cast<uint16_t>(0));
@@ -35,13 +37,13 @@ void ChatPackets::SendChatMessage(const SystemAddress& sysAddr, char chatChannel
void ChatPackets::SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, const bool broadcast) {
CBITSTREAM;
PacketUtils::WriteHeader(bitStream, CHAT, MSG_CHAT_GENERAL_CHAT_MESSAGE);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::GENERAL_CHAT_MESSAGE);
bitStream.Write(static_cast<uint64_t>(0));
bitStream.Write(static_cast<char>(4));
bitStream.Write(static_cast<uint32_t>(message.size()));
PacketUtils::WriteWString(bitStream, "", 33);
bitStream.Write(LUWString("", 33));
bitStream.Write(static_cast<uint64_t>(0));
bitStream.Write(static_cast<uint16_t>(0));
@@ -67,7 +69,7 @@ void ChatPackets::SendMessageFail(const SystemAddress& sysAddr) {
//0x01 - "Upgrade to a full LEGO Universe Membership to chat with other players."
CBITSTREAM;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_SEND_CANNED_TEXT);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::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

@@ -11,7 +11,7 @@
#include "Entity.h"
#include "ControllablePhysicsComponent.h"
#include "Game.h"
#include "dLogger.h"
#include "Logger.h"
#include "WorldPackets.h"
#include "NiPoint3.h"
#include "NiQuaternion.h"
@@ -33,12 +33,15 @@
#include "Database.h"
#include "PacketUtils.h"
#include "eGuildRank.h"
#include "eGameMasterLevel.h"
#include "eReplicaComponentType.h"
#include "CheatDetection.h"
#include "Amf3.h"
void ClientPackets::HandleChatMessage(const SystemAddress& sysAddr, Packet* packet) {
User* user = UserManager::Instance()->GetUser(sysAddr);
if (!user) {
Game::logger->Log("ClientPackets", "Unable to get user to parse chat message");
LOG("Unable to get user to parse chat message");
return;
}
@@ -47,9 +50,7 @@ void ClientPackets::HandleChatMessage(const SystemAddress& sysAddr, Packet* pack
return;
}
CINSTREAM;
uint64_t header;
inStream.Read(header);
CINSTREAM_SKIP_HEADER;
char chatChannel;
uint16_t unknown;
@@ -67,30 +68,38 @@ void ClientPackets::HandleChatMessage(const SystemAddress& sysAddr, Packet* pack
}
std::string playerName = user->GetLastUsedChar()->GetName();
bool isMythran = user->GetLastUsedChar()->GetGMLevel() > 0;
if (!user->GetLastChatMessageApproved() && !isMythran) return;
bool isMythran = user->GetLastUsedChar()->GetGMLevel() > eGameMasterLevel::CIVILIAN;
bool isOk = Game::chatFilter->IsSentenceOkay(GeneralUtils::UTF16ToWTF8(message), user->GetLastUsedChar()->GetGMLevel()).empty();
LOG_DEBUG("Msg: %s was approved previously? %i", GeneralUtils::UTF16ToWTF8(message).c_str(), user->GetLastChatMessageApproved());
if (!isOk) {
// Add a limit to the string converted by general utils because it is a user received string and may be a bad actor.
CheatDetection::ReportCheat(
user,
sysAddr,
"Player %s attempted to bypass chat filter with message: %s",
playerName.c_str(),
GeneralUtils::UTF16ToWTF8(message, 512).c_str());
}
if (!isOk && !isMythran) return;
std::string sMessage = GeneralUtils::UTF16ToWTF8(message);
Game::logger->Log("Chat", "%s: %s", playerName.c_str(), sMessage.c_str());
LOG("%s: %s", playerName.c_str(), sMessage.c_str());
ChatPackets::SendChatMessage(sysAddr, chatChannel, playerName, user->GetLoggedInChar(), isMythran, message);
}
void ClientPackets::HandleClientPositionUpdate(const SystemAddress& sysAddr, Packet* packet) {
User* user = UserManager::Instance()->GetUser(sysAddr);
if (!user) {
Game::logger->Log("ClientPackets", "Unable to get user to parse position update");
LOG("Unable to get user to parse position update");
return;
}
CINSTREAM;
uint64_t header;
inStream.Read(header);
CINSTREAM_SKIP_HEADER;
Entity* entity = EntityManager::Instance()->GetEntity(user->GetLastUsedChar()->GetObjectID());
Entity* entity = Game::entityManager->GetEntity(user->GetLastUsedChar()->GetObjectID());
if (!entity) return;
ControllablePhysicsComponent* comp = static_cast<ControllablePhysicsComponent*>(entity->GetComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS));
ControllablePhysicsComponent* comp = static_cast<ControllablePhysicsComponent*>(entity->GetComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS));
if (!comp) return;
/*
@@ -100,7 +109,7 @@ void ClientPackets::HandleClientPositionUpdate(const SystemAddress& sysAddr, Pac
comp->SetVelocity(zeroVel);
comp->SetAngularVelocity(zeroVel);
comp->SetIsOnGround(true); //probably8
EntityManager::Instance()->SerializeEntity(entity);
Game::entityManager->SerializeEntity(entity);
return;
}
*/
@@ -141,10 +150,37 @@ void ClientPackets::HandleClientPositionUpdate(const SystemAddress& sysAddr, Pac
inStream.Read(angVelocity.z);
}
// TODO figure out how to use these. Ignoring for now, but reading in if they exist.
bool hasLocalSpaceInfo{};
LWOOBJID objectId{};
NiPoint3 localSpacePosition{};
bool hasLinearVelocity{};
NiPoint3 linearVelocity{};
if (inStream.Read(hasLocalSpaceInfo) && hasLocalSpaceInfo) {
inStream.Read(objectId);
inStream.Read(localSpacePosition.x);
inStream.Read(localSpacePosition.y);
inStream.Read(localSpacePosition.z);
if (inStream.Read(hasLinearVelocity) && hasLinearVelocity) {
inStream.Read(linearVelocity.x);
inStream.Read(linearVelocity.y);
inStream.Read(linearVelocity.z);
}
}
bool hasRemoteInputInfo{};
RemoteInputInfo remoteInput{};
if (inStream.Read(hasRemoteInputInfo) && hasRemoteInputInfo) {
inStream.Read(remoteInput.m_RemoteInputX);
inStream.Read(remoteInput.m_RemoteInputY);
inStream.Read(remoteInput.m_IsPowersliding);
inStream.Read(remoteInput.m_IsModified);
}
bool updateChar = true;
if (possessorComponent != nullptr) {
auto* possassableEntity = EntityManager::Instance()->GetEntity(possessorComponent->GetPossessable());
auto* possassableEntity = Game::entityManager->GetEntity(possessorComponent->GetPossessable());
if (possassableEntity != nullptr) {
auto* possessableComponent = possassableEntity->GetComponent<PossessableComponent>();
@@ -155,9 +191,6 @@ void ClientPackets::HandleClientPositionUpdate(const SystemAddress& sysAddr, Pac
auto* vehiclePhysicsComponent = possassableEntity->GetComponent<VehiclePhysicsComponent>();
if (vehiclePhysicsComponent != nullptr) {
// This is flipped for whatever reason
rotation = NiQuaternion(rotation.z, rotation.y, rotation.x, rotation.w);
vehiclePhysicsComponent->SetPosition(position);
vehiclePhysicsComponent->SetRotation(rotation);
vehiclePhysicsComponent->SetIsOnGround(onGround);
@@ -166,6 +199,7 @@ void ClientPackets::HandleClientPositionUpdate(const SystemAddress& sysAddr, Pac
vehiclePhysicsComponent->SetDirtyVelocity(velocityFlag);
vehiclePhysicsComponent->SetAngularVelocity(angVelocity);
vehiclePhysicsComponent->SetDirtyAngularVelocity(angVelocityFlag);
vehiclePhysicsComponent->SetRemoteInputInfo(remoteInput);
} else {
// Need to get the mount's controllable physics
auto* controllablePhysicsComponent = possassableEntity->GetComponent<ControllablePhysicsComponent>();
@@ -179,7 +213,7 @@ void ClientPackets::HandleClientPositionUpdate(const SystemAddress& sysAddr, Pac
controllablePhysicsComponent->SetAngularVelocity(angVelocity);
controllablePhysicsComponent->SetDirtyAngularVelocity(angVelocityFlag);
}
EntityManager::Instance()->SerializeEntity(possassableEntity);
Game::entityManager->SerializeEntity(possassableEntity);
}
}
@@ -207,9 +241,9 @@ void ClientPackets::HandleClientPositionUpdate(const SystemAddress& sysAddr, Pac
auto* player = static_cast<Player*>(entity);
player->SetGhostReferencePoint(position);
EntityManager::Instance()->QueueGhostUpdate(player->GetObjectID());
Game::entityManager->QueueGhostUpdate(player->GetObjectID());
if (updateChar) EntityManager::Instance()->SerializeEntity(entity);
if (updateChar) Game::entityManager->SerializeEntity(entity);
//TODO: add moving platform stuffs
/*bool movingPlatformFlag;
@@ -247,7 +281,7 @@ void ClientPackets::HandleClientPositionUpdate(const SystemAddress& sysAddr, Pac
continue;
}
EntityManager::Instance()->SerializeEntity(entity, player);
Game::entityManager->SerializeEntity(entity, player);
}
*/
}
@@ -255,21 +289,21 @@ void ClientPackets::HandleClientPositionUpdate(const SystemAddress& sysAddr, Pac
void ClientPackets::HandleChatModerationRequest(const SystemAddress& sysAddr, Packet* packet) {
User* user = UserManager::Instance()->GetUser(sysAddr);
if (!user) {
Game::logger->Log("ClientPackets", "Unable to get user to parse chat moderation request");
LOG("Unable to get user to parse chat moderation request");
return;
}
auto* entity = Player::GetPlayer(sysAddr);
if (entity == nullptr) {
Game::logger->Log("ClientPackets", "Unable to get player to parse chat moderation request");
LOG("Unable to get player to parse chat moderation request");
return;
}
// Check if the player has restricted chat access
auto* character = entity->GetCharacter();
if (character->HasPermission(PermissionMap::RestrictedChatAccess)) {
if (character->HasPermission(ePermissionMap::RestrictedChatAccess)) {
// Send a message to the player
ChatPackets::SendSystemMessage(
sysAddr,
@@ -471,3 +505,40 @@ void ClientPackets::SendGuildCreateResponse(const SystemAddress& sysAddr, eGuild
PacketUtils::WriteWString(bitStream, guildName, 33);
SEND_PACKET;
}
void ClientPackets::SendTop5HelpIssues(Packet* packet) {
auto* user = UserManager::Instance()->GetUser(packet->systemAddress);
if (!user) return;
auto* character = user->GetLastUsedChar();
if (!character) return;
auto * entity = character->GetEntity();
if (!entity) return;
CINSTREAM_SKIP_HEADER;
int32_t language = 0;
inStream.Read(language);
// TODO: Handle different languages in a nice way
// 0: en_US
// 1: pl_US
// 2: de_DE
// 3: en_GB
AMFArrayValue data;
// Summaries
data.Insert("Summary0", Game::config->GetValue("help_0_summary"));
data.Insert("Summary1", Game::config->GetValue("help_1_summary"));
data.Insert("Summary2", Game::config->GetValue("help_2_summary"));
data.Insert("Summary3", Game::config->GetValue("help_3_summary"));
data.Insert("Summary4", Game::config->GetValue("help_4_summary"));
// Descriptions
data.Insert("Description0", Game::config->GetValue("help_0_description"));
data.Insert("Description1", Game::config->GetValue("help_1_description"));
data.Insert("Description2", Game::config->GetValue("help_2_description"));
data.Insert("Description3", Game::config->GetValue("help_3_description"));
data.Insert("Description4", Game::config->GetValue("help_4_description"));
GameMessages::SendUIMessageServerToSingleClient(entity, packet->systemAddress, "UIHelpTop5", data);
}

View File

@@ -14,6 +14,7 @@ namespace ClientPackets {
void HandleChatMessage(const SystemAddress& sysAddr, Packet* packet);
void HandleClientPositionUpdate(const SystemAddress& sysAddr, Packet* packet);
void HandleChatModerationRequest(const SystemAddress& sysAddr, Packet* packet);
void SendTop5HelpIssues(Packet* packet);
// Guild stuff
void HandleGuildCreation(const SystemAddress& sysAddr, Packet* packet);

View File

@@ -1,22 +1,24 @@
#include "MasterPackets.h"
#include "BitStream.h"
#include "PacketUtils.h"
#include "dMessageIdentifiers.h"
#include "dCommonVars.h"
#include "dServer.h"
#include "eConnectionType.h"
#include "eMasterMessageType.h"
#include "BitStreamUtils.h"
#include <string>
void MasterPackets::SendPersistentIDRequest(dServer* server, uint64_t requestID) {
CBITSTREAM;
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_REQUEST_PERSISTENT_ID);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::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);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::REQUEST_PERSISTENT_ID_RESPONSE);
bitStream.Write(requestID);
bitStream.Write(objID);
@@ -26,7 +28,7 @@ void MasterPackets::SendPersistentIDResponse(dServer* server, const SystemAddres
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);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::REQUEST_ZONE_TRANSFER);
bitStream.Write(requestID);
bitStream.Write(static_cast<uint8_t>(mythranShift));
@@ -38,7 +40,7 @@ void MasterPackets::SendZoneTransferRequest(dServer* server, uint64_t requestID,
void MasterPackets::SendZoneCreatePrivate(dServer* server, uint32_t zoneID, uint32_t cloneID, const std::string& password) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_CREATE_PRIVATE_ZONE);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::CREATE_PRIVATE_ZONE);
bitStream.Write(zoneID);
bitStream.Write(cloneID);
@@ -53,7 +55,7 @@ void MasterPackets::SendZoneCreatePrivate(dServer* server, uint32_t zoneID, uint
void MasterPackets::SendZoneRequestPrivate(dServer* server, uint64_t requestID, bool mythranShift, const std::string& password) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_REQUEST_PRIVATE_ZONE);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::REQUEST_PRIVATE_ZONE);
bitStream.Write(requestID);
bitStream.Write(static_cast<uint8_t>(mythranShift));
@@ -68,7 +70,7 @@ void MasterPackets::SendZoneRequestPrivate(dServer* server, uint64_t requestID,
void MasterPackets::SendWorldReady(dServer* server, LWOMAPID zoneId, LWOINSTANCEID instanceId) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_WORLD_READY);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::WORLD_READY);
bitStream.Write(zoneId);
bitStream.Write(instanceId);
@@ -78,7 +80,7 @@ void MasterPackets::SendWorldReady(dServer* server, LWOMAPID zoneId, LWOINSTANCE
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);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::REQUEST_ZONE_TRANSFER_RESPONSE);
bitStream.Write(requestID);
bitStream.Write(static_cast<uint8_t>(mythranShift));
@@ -86,7 +88,7 @@ void MasterPackets::SendZoneTransferResponse(dServer* server, const SystemAddres
bitStream.Write(zoneInstance);
bitStream.Write(zoneClone);
bitStream.Write(static_cast<uint16_t>(serverPort));
PacketUtils::WriteString(bitStream, serverIP, static_cast<uint32_t>(serverIP.size() + 1));
bitStream.Write(LUString(serverIP, static_cast<uint32_t>(serverIP.size() + 1)));
server->Send(&bitStream, sysAddr, false);
}
@@ -110,13 +112,13 @@ void MasterPackets::HandleServerInfo(Packet* packet) {
void MasterPackets::SendServerInfo(dServer* server, Packet* packet) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_SERVER_INFO);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::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());
bitStream.Write(LUString(server->GetIP(), server->GetIP().size()));
server->SendToMaster(&bitStream);
}

View File

@@ -1,18 +1,10 @@
#include "PacketUtils.h"
#include <MessageIdentifiers.h>
#include <vector>
#include <fstream>
#include "dLogger.h"
#include "Logger.h"
#include "Game.h"
void PacketUtils::WriteHeader(RakNet::BitStream& bitStream, uint16_t connectionType, uint32_t internalPacketID) {
bitStream.Write(MessageID(ID_USER_PACKET_ENUM));
bitStream.Write(connectionType);
bitStream.Write(internalPacketID);
bitStream.Write(uint8_t(0));
}
uint16_t PacketUtils::ReadPacketU16(uint32_t startLoc, Packet* packet) {
uint16_t PacketUtils::ReadU16(uint32_t startLoc, Packet* packet) {
if (startLoc + 2 > packet->length) return 0;
std::vector<unsigned char> t;
@@ -20,7 +12,7 @@ uint16_t PacketUtils::ReadPacketU16(uint32_t startLoc, Packet* packet) {
return *(uint16_t*)t.data();
}
uint32_t PacketUtils::ReadPacketU32(uint32_t startLoc, Packet* packet) {
uint32_t PacketUtils::ReadU32(uint32_t startLoc, Packet* packet) {
if (startLoc + 4 > packet->length) return 0;
std::vector<unsigned char> t;
@@ -30,7 +22,7 @@ uint32_t PacketUtils::ReadPacketU32(uint32_t startLoc, Packet* packet) {
return *(uint32_t*)t.data();
}
uint64_t PacketUtils::ReadPacketU64(uint32_t startLoc, Packet* packet) {
uint64_t PacketUtils::ReadU64(uint32_t startLoc, Packet* packet) {
if (startLoc + 8 > packet->length) return 0;
std::vector<unsigned char> t;
@@ -38,7 +30,7 @@ uint64_t PacketUtils::ReadPacketU64(uint32_t startLoc, Packet* packet) {
return *(uint64_t*)t.data();
}
int64_t PacketUtils::ReadPacketS64(uint32_t startLoc, Packet* packet) {
int64_t PacketUtils::ReadS64(uint32_t startLoc, Packet* packet) {
if (startLoc + 8 > packet->length) return 0;
std::vector<unsigned char> t;
@@ -67,85 +59,10 @@ std::string PacketUtils::ReadString(uint32_t startLoc, Packet* packet, bool wide
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::WriteString(RakNet::BitStream& bitStream, const std::string& s, uint32_t maxSize) {
uint32_t size = s.size();
uint32_t emptySize = maxSize - size;
if (size > maxSize) size = maxSize;
for (uint32_t i = 0; i < size; i++) {
bitStream.Write((char)s[i]);
}
for (uint32_t i = 0; i < emptySize; i++) {
bitStream.Write((char)0);
}
}
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));
}
}
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));
}
}
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) {
//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;
if (!Game::logger->GetLogToConsole()) return;
std::string path = "packets/" + filename;

View File

@@ -1,24 +1,18 @@
#ifndef PACKETUTILS_H
#define PACKETUTILS_H
#include <MessageIdentifiers.h>
#include <BitStream.h>
#include <string>
enum class eConnectionType : uint16_t;
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);
uint16_t ReadU16(uint32_t startLoc, Packet* packet);
uint32_t ReadU32(uint32_t startLoc, Packet* packet);
uint64_t ReadU64(uint32_t startLoc, Packet* packet);
int64_t ReadS64(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);
};

View File

@@ -1,12 +1,11 @@
#include "dCommonVars.h"
#include "WorldPackets.h"
#include "BitStream.h"
#include "dMessageIdentifiers.h"
#include "PacketUtils.h"
#include "GeneralUtils.h"
#include "User.h"
#include "Character.h"
#include "dLogger.h"
#include "Logger.h"
#include <iostream>
#include "Game.h"
#include "LDFFormat.h"
@@ -14,12 +13,14 @@
#include "dZoneManager.h"
#include "CharacterComponent.h"
#include "ZCompression.h"
#include "eConnectionType.h"
#include "BitStreamUtils.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);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::LOAD_STATIC_ZONE);
auto zone = dZoneManager::Instance()->GetZone()->GetZoneID();
auto zone = Game::zoneManager->GetZone()->GetZoneID();
bitStream.Write(static_cast<uint16_t>(zone.GetMapID()));
bitStream.Write(static_cast<uint16_t>(zone.GetInstanceID()));
//bitStream.Write(static_cast<uint32_t>(zone.GetCloneID()));
@@ -41,7 +42,7 @@ void WorldPackets::SendCharacterList(const SystemAddress& sysAddr, User* user) {
if (!user) return;
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CHARACTER_LIST_RESPONSE);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::CHARACTER_LIST_RESPONSE);
std::vector<Character*> characters = user->GetCharacters();
bitStream.Write(static_cast<uint8_t>(characters.size()));
@@ -51,13 +52,13 @@ void WorldPackets::SendCharacterList(const SystemAddress& sysAddr, User* user) {
bitStream.Write(characters[i]->GetObjectID());
bitStream.Write(static_cast<uint32_t>(0));
PacketUtils::WriteWString(bitStream, characters[i]->GetName(), 33);
PacketUtils::WriteWString(bitStream, characters[i]->GetUnapprovedName(), 33);
bitStream.Write(LUWString(characters[i]->GetName()));
bitStream.Write(LUWString(characters[i]->GetUnapprovedName()));
bitStream.Write(static_cast<uint8_t>(characters[i]->GetNameRejected()));
bitStream.Write(static_cast<uint8_t>(false));
PacketUtils::WriteString(bitStream, "", 10);
bitStream.Write(LUString("", 10));
bitStream.Write(characters[i]->GetShirtColor());
bitStream.Write(characters[i]->GetShirtStyle());
@@ -88,32 +89,32 @@ void WorldPackets::SendCharacterList(const SystemAddress& sysAddr, User* user) {
SEND_PACKET;
}
void WorldPackets::SendCharacterCreationResponse(const SystemAddress& sysAddr, eCreationResponse response) {
void WorldPackets::SendCharacterCreationResponse(const SystemAddress& sysAddr, eCharacterCreationResponse response) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CHARACTER_CREATE_RESPONSE);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::CHARACTER_CREATE_RESPONSE);
bitStream.Write(response);
SEND_PACKET;
}
void WorldPackets::SendCharacterRenameResponse(const SystemAddress& sysAddr, eRenameResponse response) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CHARACTER_RENAME_RESPONSE);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::CHARACTER_RENAME_RESPONSE);
bitStream.Write(response);
SEND_PACKET;
}
void WorldPackets::SendCharacterDeleteResponse(const SystemAddress& sysAddr, bool response) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_DELETE_CHARACTER_RESPONSE);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::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) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_TRANSFER_TO_WORLD);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::TRANSFER_TO_WORLD);
PacketUtils::WriteString(bitStream, serverIP, 33);
bitStream.Write(LUString(serverIP));
bitStream.Write(static_cast<uint16_t>(serverPort));
bitStream.Write(static_cast<uint8_t>(mythranShift));
@@ -122,21 +123,21 @@ void WorldPackets::SendTransferToWorld(const SystemAddress& sysAddr, const std::
void WorldPackets::SendServerState(const SystemAddress& sysAddr) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_SERVER_STATES);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::SERVER_STATES);
bitStream.Write(static_cast<uint8_t>(1)); //If the server is receiving this request, it probably is ready anyway.
SEND_PACKET;
}
void WorldPackets::SendCreateCharacter(const SystemAddress& sysAddr, Entity* entity, const std::string& xmlData, const std::u16string& username, int32_t gm) {
void WorldPackets::SendCreateCharacter(const SystemAddress& sysAddr, Entity* entity, const std::string& xmlData, const std::u16string& username, eGameMasterLevel gm) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CREATE_CHARACTER);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::CREATE_CHARACTER);
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??");
LOG("Entity is not a character?? what??");
return;
}
@@ -144,8 +145,8 @@ void WorldPackets::SendCreateCharacter(const SystemAddress& sysAddr, Entity* ent
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<int32_t>* gmlevel = new LDFData<int32_t>(u"gmlevel", static_cast<int32_t>(gm));
LDFData<int32_t>* chatmode = new LDFData<int32_t>(u"chatmode", static_cast<int32_t>(gm));
LDFData<int64_t>* reputation = new LDFData<int64_t>(u"reputation", character->GetReputation());
objid->WriteToPacket(&data);
@@ -193,12 +194,12 @@ void WorldPackets::SendCreateCharacter(const SystemAddress& sysAddr, Entity* ent
// PacketUtils::SavePacket("chardata.bin", (const char*)bitStream.GetData(), static_cast<uint32_t>(bitStream.GetNumberOfBytesUsed()));
SEND_PACKET;
delete[] compressedData;
Game::logger->Log("WorldPackets", "Sent CreateCharacter for ID: %llu", entity->GetObjectID());
LOG("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);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::CHAT_MODERATION_STRING);
bitStream.Write<uint8_t>(unacceptedItems.empty()); // Is sentence ok?
bitStream.Write<uint16_t>(0x16); // Source ID, unknown
@@ -206,7 +207,7 @@ void WorldPackets::SendChatModerationResponse(const SystemAddress& sysAddr, bool
bitStream.Write(static_cast<uint8_t>(requestID)); // request ID
bitStream.Write(static_cast<char>(0)); // chat mode
PacketUtils::WritePacketWString(receiver, 42, &bitStream); // receiver name
bitStream.Write(LUWString(receiver, 42)); // receiver name
for (auto it : unacceptedItems) {
bitStream.Write<uint8_t>(it.first); // start index
@@ -220,14 +221,14 @@ void WorldPackets::SendChatModerationResponse(const SystemAddress& sysAddr, bool
SEND_PACKET;
}
void WorldPackets::SendGMLevelChange(const SystemAddress& sysAddr, bool success, uint8_t highestLevel, uint8_t prevLevel, uint8_t newLevel) {
void WorldPackets::SendGMLevelChange(const SystemAddress& sysAddr, bool success, eGameMasterLevel highestLevel, eGameMasterLevel prevLevel, eGameMasterLevel newLevel) {
CBITSTREAM;
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_MAKE_GM_RESPONSE);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::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(static_cast<uint16_t>(highestLevel));
bitStream.Write(static_cast<uint16_t>(prevLevel));
bitStream.Write(static_cast<uint16_t>(newLevel));
SEND_PACKET;
}

View File

@@ -8,18 +8,21 @@
class User;
struct SystemAddress;
enum class eGameMasterLevel : uint8_t;
enum class eCharacterCreationResponse : uint8_t;
enum class eRenameResponse : uint8_t;
namespace WorldPackets {
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 SendCharacterCreationResponse(const SystemAddress& sysAddr, eCharacterCreationResponse response);
void SendCharacterRenameResponse(const SystemAddress& sysAddr, eRenameResponse 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, eGameMasterLevel 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, eGameMasterLevel highestLevel, eGameMasterLevel prevLevel, eGameMasterLevel newLevel);
}
#endif // WORLDPACKETS_H

View File

@@ -28,10 +28,10 @@ void ZoneInstanceManager::RequestZoneTransfer(dServer* server, uint32_t zoneID,
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);
uint32_t zoneID = PacketUtils::ReadU32(17, packet);
uint32_t zoneInstance = PacketUtils::ReadU32(21, packet);
uint32_t zoneClone = PacketUtils::ReadU32(25, packet);
uint16_t serverPort = PacketUtils::ReadU16(29, packet);
std::string serverIP = PacketUtils::ReadString(31, packet, false);
for (uint32_t i = 0; i < this->requests.size(); ++i) {

View File

@@ -1,14 +1,17 @@
#define _VARIADIC_MAX 10
#include "dServer.h"
#include "dNetCommon.h"
#include "dLogger.h"
#include "Logger.h"
#include "dConfig.h"
#include "RakNetworkFactory.h"
#include "MessageIdentifiers.h"
#include "eConnectionType.h"
#include "eServerMessageType.h"
#include "eMasterMessageType.h"
#include "PacketUtils.h"
#include "dMessageIdentifiers.h"
#include "BitStreamUtils.h"
#include "MasterPackets.h"
#include "ZoneInstanceManager.h"
@@ -36,7 +39,7 @@ public:
}
} 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, dConfig* config, bool* shouldShutdown, unsigned int zoneID) {
dServer::dServer(const std::string& ip, int port, int instanceID, int maxConnections, bool isInternal, bool useEncryption, Logger* logger, const std::string masterIP, int masterPort, ServerType serverType, dConfig* config, bool* shouldShutdown, unsigned int zoneID) {
mIP = ip;
mPort = port;
mZoneID = zoneID;
@@ -57,18 +60,18 @@ dServer::dServer(const std::string& ip, int port, int instanceID, int maxConnect
mIsOkay = Startup();
//Forcibly log to both the console and our file what ip, port and possibly zoneID / instanceID we're running on:
bool prevLogSetting = mLogger->GetIsLoggingToConsole();
bool prevLogSetting = mLogger->GetLogToConsole();
mLogger->SetLogToConsole(true);
if (mIsOkay) {
if (zoneID == 0)
mLogger->Log("dServer", "Server is listening on %s:%i with encryption: %i", ip.c_str(), port, int(useEncryption));
LOG("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; }
LOG("Server is listening on %s:%i with encryption: %i, running zone %i / %i", ip.c_str(), port, int(useEncryption), zoneID, instanceID);
} else { LOG("FAILED TO START SERVER ON IP/PORT: %s:%i", ip.c_str(), port); return; }
mLogger->SetLogToConsole(prevLogSetting);
mPeer->SetMTUSize(1228); // This is hard coded by lu for some reason.
//Connect to master if we are not master:
if (serverType != ServerType::Master) {
SetupForMasterConnection();
@@ -105,27 +108,27 @@ Packet* dServer::ReceiveFromMaster() {
if (packet->length < 1) { mMasterPeer->DeallocatePacket(packet); return nullptr; }
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) {
mLogger->Log("dServer", "Lost our connection to master, shutting DOWN!");
LOG("Lost our connection to master, shutting DOWN!");
mMasterConnectionActive = false;
//ConnectToMaster(); //We'll just shut down now
}
if (packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED) {
mLogger->Log("dServer", "Established connection to master, zone (%i), instance (%i)", this->GetZoneID(), this->GetInstanceID());
LOG("Established connection to master, zone (%i), instance (%i)", this->GetZoneID(), this->GetInstanceID());
mMasterConnectionActive = true;
mMasterSystemAddress = packet->systemAddress;
MasterPackets::SendServerInfo(this, packet);
}
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);
if (static_cast<eConnectionType>(packet->data[1]) == eConnectionType::MASTER) {
switch (static_cast<eMasterMessageType>(packet->data[3])) {
case eMasterMessageType::REQUEST_ZONE_TRANSFER_RESPONSE: {
uint64_t requestID = PacketUtils::ReadU64(8, packet);
ZoneInstanceManager::Instance()->HandleRequestZoneTransferResponse(requestID, packet);
break;
}
case MSG_MASTER_SHUTDOWN:
case eMasterMessageType::SHUTDOWN:
*mShouldShutdown = true;
break;
@@ -164,9 +167,9 @@ void dServer::SendToMaster(RakNet::BitStream* bitStream) {
mMasterPeer->Send(bitStream, SYSTEM_PRIORITY, RELIABLE_ORDERED, 0, mMasterSystemAddress, false);
}
void dServer::Disconnect(const SystemAddress& sysAddr, uint32_t disconNotifyID) {
void dServer::Disconnect(const SystemAddress& sysAddr, eServerDisconnectIdentifiers disconNotifyID) {
RakNet::BitStream bitStream;
PacketUtils::WriteHeader(bitStream, SERVER, MSG_SERVER_DISCONNECT_NOTIFY);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::SERVER, eServerMessageType::DISCONNECT_NOTIFY);
bitStream.Write(disconNotifyID);
mPeer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE_ORDERED, 0, sysAddr, false);
@@ -188,6 +191,7 @@ bool dServer::Startup() {
mPeer->SetIncomingPassword("3.25 DARKFLAME1", 15);
} else {
UpdateBandwidthLimit();
UpdateMaximumMtuSize();
mPeer->SetIncomingPassword("3.25 ND1", 8);
}
@@ -197,6 +201,11 @@ bool dServer::Startup() {
return true;
}
void dServer::UpdateMaximumMtuSize() {
auto maxMtuSize = mConfig->GetValue("maximum_mtu_size");
mPeer->SetMTUSize(maxMtuSize.empty() ? 1228 : std::stoi(maxMtuSize));
}
void dServer::UpdateBandwidthLimit() {
auto newBandwidth = mConfig->GetValue("maximum_outgoing_bandwidth");
mPeer->SetPerConnectionOutgoingBandwidthLimit(!newBandwidth.empty() ? std::stoi(newBandwidth) : 0);

View File

@@ -4,8 +4,9 @@
#include "ReplicaManager.h"
#include "NetworkIDManager.h"
class dLogger;
class Logger;
class dConfig;
enum class eServerDisconnectIdentifiers : uint32_t;
enum class ServerType : uint32_t {
Master,
@@ -25,7 +26,7 @@ public:
int maxConnections,
bool isInternal,
bool useEncryption,
dLogger* logger,
Logger* logger,
const std::string masterIP,
int masterPort,
ServerType serverType,
@@ -41,7 +42,7 @@ public:
virtual void Send(RakNet::BitStream* bitStream, const SystemAddress& sysAddr, bool broadcast);
void SendToMaster(RakNet::BitStream* bitStream);
void Disconnect(const SystemAddress& sysAddr, uint32_t disconNotifyID);
void Disconnect(const SystemAddress& sysAddr, eServerDisconnectIdentifiers disconNotifyID);
bool IsConnected(const SystemAddress& sysAddr);
const std::string& GetIP() const { return mIP; }
@@ -50,13 +51,14 @@ public:
const bool GetIsEncrypted() const { return mUseEncryption; }
const bool GetIsInternal() const { return mIsInternal; }
const bool GetIsOkay() const { return mIsOkay; }
dLogger* GetLogger() const { return mLogger; }
Logger* GetLogger() const { return mLogger; }
const bool GetIsConnectedToMaster() const { return mMasterConnectionActive; }
const unsigned int GetZoneID() const { return mZoneID; }
const int GetInstanceID() const { return mInstanceID; }
ReplicaManager* GetReplicaManager() { return mReplicaManager; }
void UpdateReplica();
void UpdateBandwidthLimit();
void UpdateMaximumMtuSize();
int GetPing(const SystemAddress& sysAddr) const;
int GetLatestPing(const SystemAddress& sysAddr) const;
@@ -72,7 +74,7 @@ private:
bool ConnectToMaster();
private:
dLogger* mLogger = nullptr;
Logger* mLogger = nullptr;
dConfig* mConfig = nullptr;
RakPeerInterface* mPeer = nullptr;
ReplicaManager* mReplicaManager = nullptr;