#pragma once #include #include "dCommonVars.h" #include "RakString.h" #include #include "Game.h" #include "dServer.h" #include struct PlayerData { LWOOBJID playerID; RakNet::RakString playerName; SystemAddress sysAddr; LWOZONEID zoneID; std::vector friends; time_t muteExpire; uint8_t countOfBestFriends = 0; }; struct TeamData { LWOOBJID teamID = LWOOBJID_EMPTY; // Internal use LWOOBJID leaderID = LWOOBJID_EMPTY; std::vector memberIDs {}; uint8_t lootFlag = 0; bool local = false; LWOZONEID zoneId = {}; }; class PlayerContainer { public: PlayerContainer(); ~PlayerContainer(); void InsertPlayer(Packet* packet); void RemovePlayer(Packet* packet); void MuteUpdate(Packet* packet); void CreateTeamServer(Packet* packet); void BroadcastMuteUpdate(LWOOBJID player, time_t time); PlayerData* GetPlayerData(const LWOOBJID& playerID) { auto it = mPlayers.find(playerID); if (it != mPlayers.end()) return it->second; return nullptr; } PlayerData* GetPlayerData(const std::string& playerName) { for (auto player : mPlayers) { if (player.second) { std::string pn = player.second->playerName.C_String(); if (pn == playerName) return player.second; } } return nullptr; } TeamData* CreateLocalTeam(std::vector members); TeamData* CreateTeam(LWOOBJID leader, bool local = false); TeamData* GetTeam(LWOOBJID playerID); void AddMember(TeamData* team, LWOOBJID playerID); void RemoveMember(TeamData* team, LWOOBJID playerID, bool disband, bool kicked, bool leaving, bool silent = false); void PromoteMember(TeamData* team, LWOOBJID newLeader); void DisbandTeam(TeamData* team); void TeamStatusUpdate(TeamData* team); void UpdateTeamsOnWorld(TeamData* team, bool deleteTeam); std::u16string GetName(LWOOBJID playerID); LWOOBJID GetId(const std::u16string& playerName); bool GetIsMuted(PlayerData* data); std::map& GetAllPlayerData() { return mPlayers; } private: LWOOBJID mTeamIDCounter = 0; std::map mPlayers; std::vector mTeams; std::unordered_map mNames; };