chore: Change dServer and related code to use BitStream references (#1476)

This commit is contained in:
jadebenn 2024-02-26 23:43:33 -06:00 committed by GitHub
parent 9e0dd05d42
commit 75544e3eec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 54 additions and 54 deletions

View File

@ -59,7 +59,7 @@ void ChatIgnoreList::GetIgnoreList(Packet* packet) {
bitStream.Write(LUWString(ignoredPlayer.playerName, 36));
}
Game::server->Send(&bitStream, packet->systemAddress, false);
Game::server->Send(bitStream, packet->systemAddress, false);
}
void ChatIgnoreList::AddIgnore(Packet* packet) {
@ -131,7 +131,7 @@ void ChatIgnoreList::AddIgnore(Packet* packet) {
bitStream.Write(playerNameSend);
bitStream.Write(ignoredPlayerId);
Game::server->Send(&bitStream, packet->systemAddress, false);
Game::server->Send(bitStream, packet->systemAddress, false);
}
void ChatIgnoreList::RemoveIgnore(Packet* packet) {
@ -167,5 +167,5 @@ void ChatIgnoreList::RemoveIgnore(Packet* packet) {
LUWString playerNameSend(removedIgnoreStr, 33);
bitStream.Write(playerNameSend);
Game::server->Send(&bitStream, packet->systemAddress, false);
Game::server->Send(bitStream, packet->systemAddress, false);
}

View File

@ -211,7 +211,7 @@ void HandlePacket(Packet* packet) {
case eChatInternalMessageType::ANNOUNCEMENT: {
//we just forward this packet to every connected server
CINSTREAM;
Game::server->Send(&inStream, packet->systemAddress, true); //send to everyone except origin
Game::server->Send(inStream, packet->systemAddress, true); //send to everyone except origin
break;
}

View File

@ -150,7 +150,7 @@ void PlayerContainer::BroadcastMuteUpdate(LWOOBJID player, time_t time) {
bitStream.Write(player);
bitStream.Write(time);
Game::server->Send(&bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
Game::server->Send(bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
}
TeamData* PlayerContainer::CreateLocalTeam(std::vector<LWOOBJID> members) {
@ -365,7 +365,7 @@ void PlayerContainer::UpdateTeamsOnWorld(TeamData* team, bool deleteTeam) {
}
}
Game::server->Send(&bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
Game::server->Send(bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
}
std::u16string PlayerContainer::GetName(LWOOBJID playerID) {

View File

@ -34,8 +34,8 @@ constexpr uint32_t lowFrameDelta = FRAMES_TO_MS(lowFramerate);
#define CINSTREAM RakNet::BitStream inStream(packet->data, packet->length, false);
#define CINSTREAM_SKIP_HEADER CINSTREAM if (inStream.GetNumberOfUnreadBits() >= BYTES_TO_BITS(HEADER_SIZE)) inStream.IgnoreBytes(HEADER_SIZE); else inStream.IgnoreBits(inStream.GetNumberOfUnreadBits());
#define CMSGHEADER BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::GAME_MSG);
#define SEND_PACKET Game::server->Send(&bitStream, sysAddr, false);
#define SEND_PACKET_BROADCAST Game::server->Send(&bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
#define SEND_PACKET Game::server->Send(bitStream, sysAddr, false);
#define SEND_PACKET_BROADCAST Game::server->Send(bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
//=========== TYPEDEFS ==========

View File

@ -185,11 +185,11 @@ void EntityManager::SerializeEntities() {
for (auto* player : PlayerManager::GetAllPlayers()) {
auto* ghostComponent = player->GetComponent<GhostComponent>();
if (ghostComponent && ghostComponent->IsObserved(toSerialize)) {
Game::server->Send(&stream, player->GetSystemAddress(), false);
Game::server->Send(stream, player->GetSystemAddress(), false);
}
}
} else {
Game::server->Send(&stream, UNASSIGNED_SYSTEM_ADDRESS, true);
Game::server->Send(stream, UNASSIGNED_SYSTEM_ADDRESS, true);
}
}
m_EntitiesToSerialize.clear();
@ -364,11 +364,11 @@ void EntityManager::ConstructEntity(Entity* entity, const SystemAddress& sysAddr
if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) {
if (skipChecks) {
Game::server->Send(&stream, UNASSIGNED_SYSTEM_ADDRESS, true);
Game::server->Send(stream, UNASSIGNED_SYSTEM_ADDRESS, true);
} else {
for (auto* player : PlayerManager::GetAllPlayers()) {
if (player->GetPlayerReadyForUpdates()) {
Game::server->Send(&stream, player->GetSystemAddress(), false);
Game::server->Send(stream, player->GetSystemAddress(), false);
} else {
auto* ghostComponent = player->GetComponent<GhostComponent>();
if (ghostComponent) ghostComponent->AddLimboConstruction(entity->GetObjectID());
@ -376,7 +376,7 @@ void EntityManager::ConstructEntity(Entity* entity, const SystemAddress& sysAddr
}
}
} else {
Game::server->Send(&stream, sysAddr, false);
Game::server->Send(stream, sysAddr, false);
}
if (entity->IsPlayer()) {
@ -407,7 +407,7 @@ void EntityManager::DestructEntity(Entity* entity, const SystemAddress& sysAddr)
stream.Write<uint8_t>(ID_REPLICA_MANAGER_DESTRUCTION);
stream.Write<uint16_t>(entity->GetNetworkId());
Game::server->Send(&stream, sysAddr, sysAddr == UNASSIGNED_SYSTEM_ADDRESS);
Game::server->Send(stream, sysAddr, sysAddr == UNASSIGNED_SYSTEM_ADDRESS);
for (auto* player : PlayerManager::GetAllPlayers()) {
if (!player->GetPlayerReadyForUpdates()) {

View File

@ -258,7 +258,7 @@ bool BehaviorContext::CalculateUpdate(const float deltaTime) {
message.Write(this->originator);
echo.Serialize(message);
Game::server->Send(&message, UNASSIGNED_SYSTEM_ADDRESS, true);
Game::server->Send(message, UNASSIGNED_SYSTEM_ADDRESS, true);
}
ExecuteUpdates();

View File

@ -139,7 +139,7 @@ void RocketLaunchpadControlComponent::TellMasterToPrepZone(int zoneID) {
CBITSTREAM;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::PREP_ZONE);
bitStream.Write(zoneID);
Game::server->SendToMaster(&bitStream);
Game::server->SendToMaster(bitStream);
}

View File

@ -307,7 +307,7 @@ SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, c
message.Write(this->m_Parent->GetObjectID());
start.Serialize(message);
Game::server->Send(&message, UNASSIGNED_SYSTEM_ADDRESS, true);
Game::server->Send(message, UNASSIGNED_SYSTEM_ADDRESS, true);
}
context->ExecuteUpdates();
@ -438,7 +438,7 @@ void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry)
message.Write(this->m_Parent->GetObjectID());
projectileImpact.Serialize(message);
Game::server->Send(&message, UNASSIGNED_SYSTEM_ADDRESS, true);
Game::server->Send(message, UNASSIGNED_SYSTEM_ADDRESS, true);
entry.context->ExecuteUpdates();
}

View File

@ -329,7 +329,7 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream& inStream, const System
echoStartSkill.uiSkillHandle = startSkill.uiSkillHandle;
echoStartSkill.Serialize(bitStreamLocal);
Game::server->Send(&bitStreamLocal, entity->GetSystemAddress(), true);
Game::server->Send(bitStreamLocal, entity->GetSystemAddress(), true);
}
} break;
@ -364,7 +364,7 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream& inStream, const System
echo.Serialize(bitStreamLocal);
Game::server->Send(&bitStreamLocal, sysAddr, true);
Game::server->Send(bitStreamLocal, sysAddr, true);
} break;
case eGameMessageType::REQUEST_SMASH_PLAYER:

View File

@ -303,7 +303,7 @@ void Mail::HandleDataRequest(RakNet::BitStream& packet, const SystemAddress& sys
bitStream.Write(uint32_t(0));
}
Game::server->Send(&bitStream, sysAddr, false);
Game::server->Send(bitStream, sysAddr, false);
}
void Mail::HandleAttachmentCollect(RakNet::BitStream& packet, const SystemAddress& sysAddr, Entity* player) {
@ -367,7 +367,7 @@ void Mail::SendSendResponse(const SystemAddress& sysAddr, MailSendResponse respo
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::MAIL);
bitStream.Write(int(MailMessageID::SendResponse));
bitStream.Write(int(response));
Game::server->Send(&bitStream, sysAddr, false);
Game::server->Send(bitStream, sysAddr, false);
}
void Mail::SendNotification(const SystemAddress& sysAddr, int mailCount) {
@ -386,7 +386,7 @@ void Mail::SendNotification(const SystemAddress& sysAddr, int mailCount) {
bitStream.Write(s4);
bitStream.Write(mailCount);
bitStream.Write(int(0)); //Unknown
Game::server->Send(&bitStream, sysAddr, false);
Game::server->Send(bitStream, sysAddr, false);
}
void Mail::SendAttachmentRemoveConfirm(const SystemAddress& sysAddr, uint64_t mailID) {
@ -395,7 +395,7 @@ void Mail::SendAttachmentRemoveConfirm(const SystemAddress& sysAddr, uint64_t ma
bitStream.Write(int(MailMessageID::AttachmentCollectConfirm));
bitStream.Write(int(0)); //unknown
bitStream.Write(mailID);
Game::server->Send(&bitStream, sysAddr, false);
Game::server->Send(bitStream, sysAddr, false);
}
void Mail::SendDeleteConfirm(const SystemAddress& sysAddr, uint64_t mailID, LWOOBJID playerID) {
@ -404,7 +404,7 @@ void Mail::SendDeleteConfirm(const SystemAddress& sysAddr, uint64_t mailID, LWOO
bitStream.Write(int(MailMessageID::MailDeleteConfirm));
bitStream.Write(int(0)); //unknown
bitStream.Write(mailID);
Game::server->Send(&bitStream, sysAddr, false);
Game::server->Send(bitStream, sysAddr, false);
Database::Get()->DeleteMail(mailID);
}
@ -415,7 +415,7 @@ void Mail::SendReadConfirm(const SystemAddress& sysAddr, uint64_t mailID) {
bitStream.Write(int(MailMessageID::MailReadConfirm));
bitStream.Write(int(0)); //unknown
bitStream.Write(mailID);
Game::server->Send(&bitStream, sysAddr, false);
Game::server->Send(bitStream, sysAddr, false);
Database::Get()->MarkMailRead(mailID);
}

View File

@ -757,7 +757,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
//Tell the master server that we're going to be shutting down whole "universe":
CBITSTREAM;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::SHUTDOWN_UNIVERSE);
Game::server->SendToMaster(&bitStream);
Game::server->SendToMaster(bitStream);
ChatPackets::SendSystemMessage(sysAddr, u"Sent universe shutdown notification to master.");
//Tell chat to send an announcement to all servers

View File

@ -181,7 +181,7 @@ void InstanceManager::RequestAffirmation(Instance* instance, const PendingInstan
bitStream.Write(request.id);
Game::server->Send(&bitStream, instance->GetSysAddr(), false);
Game::server->Send(bitStream, instance->GetSysAddr(), false);
LOG("Sent affirmation request %llu to %i/%i", request.id,
static_cast<int>(instance->GetZoneID().GetMapID()),
@ -361,7 +361,7 @@ void Instance::Shutdown() {
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::SHUTDOWN);
Game::server->Send(&bitStream, this->m_SysAddr, false);
Game::server->Send(bitStream, this->m_SysAddr, false);
LOG("Triggered world shutdown for zone/clone/instance %i/%i/%i", GetMapID(), GetCloneID(), GetInstanceID());
}

View File

@ -576,7 +576,7 @@ void HandlePacket(Packet* packet) {
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::SESSION_KEY_RESPONSE);
bitStream.Write(key.first);
bitStream.Write(username);
Game::server->Send(&bitStream, packet->systemAddress, false);
Game::server->Send(bitStream, packet->systemAddress, false);
break;
}
}
@ -786,7 +786,7 @@ int ShutdownSequence(int32_t signal) {
{
CBITSTREAM;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::SHUTDOWN);
Game::server->Send(&bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
Game::server->Send(bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
LOG("Triggered master shutdown");
}

View File

@ -84,7 +84,7 @@ void AuthPackets::SendHandshake(dServer* server, const SystemAddress& sysAddr, c
else bitStream.Write(ServiceId::General);
bitStream.Write<uint64_t>(215523405360);
server->Send(&bitStream, sysAddr, false);
server->Send(bitStream, sysAddr, false);
}
void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
@ -293,14 +293,14 @@ void AuthPackets::SendLoginResponse(dServer* server, const SystemAddress& sysAdd
loginResponse.Write<uint32_t>((sizeof(Stamp) * stamps.size()) + sizeof(uint32_t));
for (auto& stamp : stamps) stamp.Serialize(loginResponse);
server->Send(&loginResponse, sysAddr, false);
server->Send(loginResponse, sysAddr, false);
//Inform the master server that we've created a session for this user:
if (responseCode == eLoginResponse::SUCCESS) {
CBITSTREAM;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::SET_SESSION_KEY);
bitStream.Write(sessionKey);
bitStream.Write(LUString(username));
server->SendToMaster(&bitStream);
server->SendToMaster(bitStream);
LOG("Set sessionKey: %i for user %s", sessionKey, username.c_str());
}

View File

@ -12,7 +12,7 @@ void MasterPackets::SendPersistentIDRequest(dServer* server, uint64_t requestID)
CBITSTREAM;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::REQUEST_PERSISTENT_ID);
bitStream.Write(requestID);
server->SendToMaster(&bitStream);
server->SendToMaster(bitStream);
}
void MasterPackets::SendPersistentIDResponse(dServer* server, const SystemAddress& sysAddr, uint64_t requestID, uint32_t objID) {
@ -22,7 +22,7 @@ void MasterPackets::SendPersistentIDResponse(dServer* server, const SystemAddres
bitStream.Write(requestID);
bitStream.Write(objID);
server->Send(&bitStream, sysAddr, false);
server->Send(bitStream, sysAddr, false);
}
void MasterPackets::SendZoneTransferRequest(dServer* server, uint64_t requestID, bool mythranShift, uint32_t zoneID, uint32_t cloneID) {
@ -34,7 +34,7 @@ void MasterPackets::SendZoneTransferRequest(dServer* server, uint64_t requestID,
bitStream.Write(zoneID);
bitStream.Write(cloneID);
server->SendToMaster(&bitStream);
server->SendToMaster(bitStream);
}
void MasterPackets::SendZoneCreatePrivate(dServer* server, uint32_t zoneID, uint32_t cloneID, const std::string& password) {
@ -49,7 +49,7 @@ void MasterPackets::SendZoneCreatePrivate(dServer* server, uint32_t zoneID, uint
bitStream.Write<char>(character);
}
server->SendToMaster(&bitStream);
server->SendToMaster(bitStream);
}
void MasterPackets::SendZoneRequestPrivate(dServer* server, uint64_t requestID, bool mythranShift, const std::string& password) {
@ -64,7 +64,7 @@ void MasterPackets::SendZoneRequestPrivate(dServer* server, uint64_t requestID,
bitStream.Write<char>(character);
}
server->SendToMaster(&bitStream);
server->SendToMaster(bitStream);
}
void MasterPackets::SendWorldReady(dServer* server, LWOMAPID zoneId, LWOINSTANCEID instanceId) {
@ -74,7 +74,7 @@ void MasterPackets::SendWorldReady(dServer* server, LWOMAPID zoneId, LWOINSTANCE
bitStream.Write(zoneId);
bitStream.Write(instanceId);
server->SendToMaster(&bitStream);
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) {
@ -89,7 +89,7 @@ void MasterPackets::SendZoneTransferResponse(dServer* server, const SystemAddres
bitStream.Write<uint16_t>(serverPort);
bitStream.Write(LUString(serverIP, 255));
server->Send(&bitStream, sysAddr, false);
server->Send(bitStream, sysAddr, false);
}
void MasterPackets::HandleServerInfo(Packet* packet) {
@ -119,5 +119,5 @@ void MasterPackets::SendServerInfo(dServer* server, Packet* packet) {
bitStream.Write(server->GetServerType());
bitStream.Write(LUString(server->GetIP()));
server->SendToMaster(&bitStream);
server->SendToMaster(bitStream);
}

View File

@ -159,13 +159,13 @@ void dServer::DeallocateMasterPacket(Packet* packet) {
mMasterPeer->DeallocatePacket(packet);
}
void dServer::Send(RakNet::BitStream* bitStream, const SystemAddress& sysAddr, bool broadcast) {
mPeer->Send(bitStream, SYSTEM_PRIORITY, RELIABLE_ORDERED, 0, sysAddr, broadcast);
void dServer::Send(RakNet::BitStream& bitStream, const SystemAddress& sysAddr, bool broadcast) {
mPeer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE_ORDERED, 0, sysAddr, broadcast);
}
void dServer::SendToMaster(RakNet::BitStream* bitStream) {
void dServer::SendToMaster(RakNet::BitStream& bitStream) {
if (!mMasterConnectionActive) ConnectToMaster();
mMasterPeer->Send(bitStream, SYSTEM_PRIORITY, RELIABLE_ORDERED, 0, mMasterSystemAddress, false);
mMasterPeer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE_ORDERED, 0, mMasterSystemAddress, false);
}
void dServer::Disconnect(const SystemAddress& sysAddr, eServerDisconnectIdentifiers disconNotifyID) {

View File

@ -52,8 +52,8 @@ public:
Packet* Receive();
void DeallocatePacket(Packet* packet);
void DeallocateMasterPacket(Packet* packet);
virtual void Send(RakNet::BitStream* bitStream, const SystemAddress& sysAddr, bool broadcast);
void SendToMaster(RakNet::BitStream* bitStream);
virtual void Send(RakNet::BitStream& bitStream, const SystemAddress& sysAddr, bool broadcast);
void SendToMaster(RakNet::BitStream& bitStream);
void Disconnect(const SystemAddress& sysAddr, eServerDisconnectIdentifiers disconNotifyID);

View File

@ -730,7 +730,7 @@ void HandleMasterPacket(Packet* packet) {
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::PLAYER_ADDED);
bitStream.Write((LWOMAPID)Game::server->GetZoneID());
bitStream.Write((LWOINSTANCEID)instanceID);
Game::server->SendToMaster(&bitStream);
Game::server->SendToMaster(bitStream);
}
}
@ -746,7 +746,7 @@ void HandleMasterPacket(Packet* packet) {
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::AFFIRM_TRANSFER_RESPONSE);
bitStream.Write(requestID);
Game::server->SendToMaster(&bitStream);
Game::server->SendToMaster(bitStream);
break;
}
@ -832,7 +832,7 @@ void HandlePacket(Packet* packet) {
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::PLAYER_REMOVED);
bitStream.Write((LWOMAPID)Game::server->GetZoneID());
bitStream.Write((LWOINSTANCEID)instanceID);
Game::server->SendToMaster(&bitStream);
Game::server->SendToMaster(bitStream);
}
if (packet->data[0] != ID_USER_PACKET_ENUM || packet->length < 4) return;
@ -895,7 +895,7 @@ void HandlePacket(Packet* packet) {
CBITSTREAM;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::REQUEST_SESSION_KEY);
bitStream.Write(username);
Game::server->SendToMaster(&bitStream);
Game::server->SendToMaster(bitStream);
//Insert info into our pending list
tempSessionInfo info;
@ -1461,5 +1461,5 @@ void FinalizeShutdown() {
void SendShutdownMessageToMaster() {
CBITSTREAM;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::SHUTDOWN_RESPONSE);
Game::server->SendToMaster(&bitStream);
Game::server->SendToMaster(bitStream);
}

View File

@ -19,7 +19,7 @@ public:
dServerMock() {};
~dServerMock() {};
RakNet::BitStream* GetMostRecentBitStream() { return sentBitStream; };
void Send(RakNet::BitStream* bitStream, const SystemAddress& sysAddr, bool broadcast) override { sentBitStream = bitStream; };
void Send(RakNet::BitStream& bitStream, const SystemAddress& sysAddr, bool broadcast) override { sentBitStream = &bitStream; };
};
class GameDependenciesTest : public ::testing::Test {