2021-12-05 17:54:36 +00:00
|
|
|
#pragma once
|
|
|
|
#include <map>
|
|
|
|
#include "dCommonVars.h"
|
|
|
|
#include "RakString.h"
|
|
|
|
#include <vector>
|
|
|
|
#include "Game.h"
|
|
|
|
#include "dServer.h"
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2024-01-14 07:03:01 +00:00
|
|
|
enum class eGameMasterLevel : uint8_t;
|
|
|
|
|
2023-11-18 11:55:12 +00:00
|
|
|
struct IgnoreData {
|
2024-02-10 19:44:40 +00:00
|
|
|
IgnoreData(const std::string& name, const LWOOBJID& id) : playerName{ name }, playerId{ id } {}
|
2023-11-18 11:55:12 +00:00
|
|
|
inline bool operator==(const std::string& other) const noexcept {
|
|
|
|
return playerName == other;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator==(const LWOOBJID& other) const noexcept {
|
|
|
|
return playerId == other;
|
|
|
|
}
|
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
LWOOBJID playerId = LWOOBJID_EMPTY;
|
2023-11-18 11:55:12 +00:00
|
|
|
std::string playerName;
|
|
|
|
};
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
struct PlayerData {
|
2024-01-06 04:42:30 +00:00
|
|
|
operator bool() const noexcept {
|
|
|
|
return playerID != LWOOBJID_EMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const PlayerData& other) const noexcept {
|
|
|
|
return playerID == other.playerID;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetIsMuted() const {
|
|
|
|
return muteExpire == 1 || muteExpire > time(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemAddress sysAddr{};
|
|
|
|
LWOZONEID zoneID{};
|
|
|
|
LWOOBJID playerID = LWOOBJID_EMPTY;
|
|
|
|
time_t muteExpire = 0;
|
|
|
|
uint8_t countOfBestFriends = 0;
|
2022-07-17 03:40:46 +00:00
|
|
|
std::string playerName;
|
2021-12-05 17:54:36 +00:00
|
|
|
std::vector<FriendData> friends;
|
2023-11-18 11:55:12 +00:00
|
|
|
std::vector<IgnoreData> ignoredPlayers;
|
2024-02-10 19:44:40 +00:00
|
|
|
eGameMasterLevel gmLevel = static_cast<eGameMasterLevel>(0); // CIVILLIAN
|
2024-01-14 07:03:01 +00:00
|
|
|
bool isFTP = false;
|
2021-12-05 17:54:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct TeamData {
|
2023-10-18 14:18:22 +00:00
|
|
|
TeamData();
|
2021-12-05 17:54:36 +00:00
|
|
|
LWOOBJID teamID = LWOOBJID_EMPTY; // Internal use
|
|
|
|
LWOOBJID leaderID = LWOOBJID_EMPTY;
|
|
|
|
std::vector<LWOOBJID> memberIDs{};
|
|
|
|
uint8_t lootFlag = 0;
|
|
|
|
bool local = false;
|
|
|
|
LWOZONEID zoneId = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
class PlayerContainer {
|
|
|
|
public:
|
2023-11-18 07:15:31 +00:00
|
|
|
void Initialize();
|
2021-12-05 17:54:36 +00:00
|
|
|
void InsertPlayer(Packet* packet);
|
|
|
|
void RemovePlayer(Packet* packet);
|
|
|
|
void MuteUpdate(Packet* packet);
|
|
|
|
void CreateTeamServer(Packet* packet);
|
|
|
|
void BroadcastMuteUpdate(LWOOBJID player, time_t time);
|
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
const PlayerData& GetPlayerData(const LWOOBJID& playerID);
|
|
|
|
const PlayerData& GetPlayerData(const std::string& playerName);
|
|
|
|
PlayerData& GetPlayerDataMutable(const LWOOBJID& playerID);
|
|
|
|
PlayerData& GetPlayerDataMutable(const std::string& playerName);
|
2024-04-18 02:47:28 +00:00
|
|
|
uint32_t GetPlayerCount() { return m_PlayerCount; };
|
|
|
|
uint32_t GetSimCount() { return m_SimCount; };
|
|
|
|
const std::map<LWOOBJID, PlayerData>& GetAllPlayers() { return m_Players; };
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
TeamData* CreateLocalTeam(std::vector<LWOOBJID> 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);
|
2023-11-18 00:44:48 +00:00
|
|
|
uint32_t GetMaxNumberOfBestFriends() { return m_MaxNumberOfBestFriends; }
|
|
|
|
uint32_t GetMaxNumberOfFriends() { return m_MaxNumberOfFriends; }
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
private:
|
2023-11-18 00:44:48 +00:00
|
|
|
LWOOBJID m_TeamIDCounter = 0;
|
2024-01-06 04:42:30 +00:00
|
|
|
std::map<LWOOBJID, PlayerData> m_Players;
|
2021-12-05 17:54:36 +00:00
|
|
|
std::vector<TeamData*> mTeams;
|
2023-11-18 00:44:48 +00:00
|
|
|
std::unordered_map<LWOOBJID, std::u16string> m_Names;
|
|
|
|
uint32_t m_MaxNumberOfBestFriends = 5;
|
|
|
|
uint32_t m_MaxNumberOfFriends = 50;
|
2024-04-18 02:47:28 +00:00
|
|
|
uint32_t m_PlayerCount = 0;
|
|
|
|
uint32_t m_SimCount = 0;
|
2021-12-05 17:54:36 +00:00
|
|
|
};
|
|
|
|
|