2021-12-05 17:54:36 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <algorithm>
|
2024-04-22 02:56:10 +00:00
|
|
|
|
|
|
|
#include "PlayerContainer.h"
|
|
|
|
#include "dNetCommon.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "Game.h"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "ChatPacketHandler.h"
|
|
|
|
#include "GeneralUtils.h"
|
2023-09-21 01:06:28 +00:00
|
|
|
#include "BitStreamUtils.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "Database.h"
|
2023-05-03 21:38:32 +00:00
|
|
|
#include "eConnectionType.h"
|
2023-08-18 23:58:27 +00:00
|
|
|
#include "ChatPackets.h"
|
2023-10-18 14:18:22 +00:00
|
|
|
#include "dConfig.h"
|
2024-04-01 03:27:50 +00:00
|
|
|
#include "eChatMessageType.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-04-22 02:56:10 +00:00
|
|
|
|
|
|
|
const json PlayerData::to_json() const {
|
|
|
|
json data;
|
|
|
|
data["id"] = this->playerID;
|
|
|
|
data["name"] = this->playerName;
|
|
|
|
data["gm_level"] = this->gmLevel;
|
|
|
|
data["muted"] = this->GetIsMuted();
|
|
|
|
|
|
|
|
json zoneID;
|
|
|
|
zoneID["map_id"] = std::to_string(this->zoneID.GetMapID());
|
|
|
|
zoneID["instance_id"] = std::to_string(this->zoneID.GetInstanceID());
|
|
|
|
zoneID["clone_id"] = std::to_string(this->zoneID.GetCloneID());
|
|
|
|
data["zone_id"] = zoneID;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2023-11-18 07:15:31 +00:00
|
|
|
void PlayerContainer::Initialize() {
|
2024-02-10 11:05:25 +00:00
|
|
|
m_MaxNumberOfBestFriends =
|
|
|
|
GeneralUtils::TryParse<uint32_t>(Game::config->GetValue("max_number_of_best_friends")).value_or(m_MaxNumberOfBestFriends);
|
|
|
|
m_MaxNumberOfFriends =
|
|
|
|
GeneralUtils::TryParse<uint32_t>(Game::config->GetValue("max_number_of_friends")).value_or(m_MaxNumberOfFriends);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-10-18 14:18:22 +00:00
|
|
|
TeamData::TeamData() {
|
|
|
|
lootFlag = Game::config->GetValue("default_team_loot") == "0" ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
void PlayerContainer::InsertPlayer(Packet* packet) {
|
2023-05-08 11:31:10 +00:00
|
|
|
CINSTREAM_SKIP_HEADER;
|
2024-01-06 04:42:30 +00:00
|
|
|
LWOOBJID playerId;
|
|
|
|
if (!inStream.Read(playerId)) {
|
|
|
|
LOG("Failed to read player ID");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& data = m_Players[playerId];
|
|
|
|
data.playerID = playerId;
|
2022-07-17 03:40:46 +00:00
|
|
|
|
|
|
|
uint32_t len;
|
|
|
|
inStream.Read<uint32_t>(len);
|
|
|
|
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
char character; inStream.Read<char>(character);
|
2024-01-06 04:42:30 +00:00
|
|
|
data.playerName += character;
|
2022-07-17 03:40:46 +00:00
|
|
|
}
|
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
inStream.Read(data.zoneID);
|
|
|
|
inStream.Read(data.muteExpire);
|
2024-01-14 07:03:01 +00:00
|
|
|
inStream.Read(data.gmLevel);
|
2024-01-06 04:42:30 +00:00
|
|
|
data.sysAddr = packet->systemAddress;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
m_Names[data.playerID] = GeneralUtils::UTF8ToUTF16(data.playerName);
|
2024-04-18 02:47:28 +00:00
|
|
|
m_PlayerCount++;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
LOG("Added user: %s (%llu), zone: %i", data.playerName.c_str(), data.playerID, data.zoneID.GetMapID());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
Database::Get()->UpdateActivityLog(data.playerID, eActivityType::PlayerLoggedIn, data.zoneID.GetMapID());
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerContainer::RemovePlayer(Packet* packet) {
|
2023-05-08 11:31:10 +00:00
|
|
|
CINSTREAM_SKIP_HEADER;
|
2021-12-05 17:54:36 +00:00
|
|
|
LWOOBJID playerID;
|
|
|
|
inStream.Read(playerID);
|
|
|
|
|
|
|
|
//Before they get kicked, we need to also send a message to their friends saying that they disconnected.
|
2024-01-06 04:42:30 +00:00
|
|
|
const auto& player = GetPlayerData(playerID);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
if (!player) {
|
|
|
|
LOG("Failed to find user: %llu", playerID);
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
for (const auto& fr : player.friends) {
|
|
|
|
const auto& fd = this->GetPlayerData(fr.friendID);
|
|
|
|
if (fd) ChatPacketHandler::SendFriendUpdate(fd, player, 0, fr.isBestFriend);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto* team = GetTeam(playerID);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (team != nullptr) {
|
2024-01-06 04:42:30 +00:00
|
|
|
const auto memberName = GeneralUtils::UTF8ToUTF16(player.playerName);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto memberId : team->memberIDs) {
|
2024-01-06 04:42:30 +00:00
|
|
|
const auto& otherMember = GetPlayerData(memberId);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
if (!otherMember) continue;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
ChatPacketHandler::SendTeamSetOffWorldFlag(otherMember, playerID, { 0, 0, 0 });
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-18 02:47:28 +00:00
|
|
|
m_PlayerCount--;
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Removed user: %llu", playerID);
|
2023-11-18 00:44:48 +00:00
|
|
|
m_Players.erase(playerID);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
Database::Get()->UpdateActivityLog(playerID, eActivityType::PlayerLoggedOut, player.zoneID.GetMapID());
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void PlayerContainer::MuteUpdate(Packet* packet) {
|
2023-05-08 11:31:10 +00:00
|
|
|
CINSTREAM_SKIP_HEADER;
|
2021-12-05 17:54:36 +00:00
|
|
|
LWOOBJID playerID;
|
|
|
|
inStream.Read(playerID);
|
|
|
|
time_t expire = 0;
|
|
|
|
inStream.Read(expire);
|
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
auto& player = this->GetPlayerDataMutable(playerID);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
if (!player) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Failed to find user: %llu", playerID);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
player.muteExpire = expire;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
BroadcastMuteUpdate(playerID, expire);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void PlayerContainer::CreateTeamServer(Packet* packet) {
|
2023-05-08 11:31:10 +00:00
|
|
|
CINSTREAM_SKIP_HEADER;
|
2021-12-05 17:54:36 +00:00
|
|
|
LWOOBJID playerID;
|
|
|
|
inStream.Read(playerID);
|
|
|
|
size_t membersSize = 0;
|
|
|
|
inStream.Read(membersSize);
|
|
|
|
|
|
|
|
std::vector<LWOOBJID> members;
|
|
|
|
|
|
|
|
members.reserve(membersSize);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (size_t i = 0; i < membersSize; i++) {
|
2021-12-05 17:54:36 +00:00
|
|
|
LWOOBJID member;
|
|
|
|
inStream.Read(member);
|
|
|
|
members.push_back(member);
|
|
|
|
}
|
|
|
|
|
|
|
|
LWOZONEID zoneId;
|
|
|
|
|
|
|
|
inStream.Read(zoneId);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* team = CreateLocalTeam(members);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (team != nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
team->zoneId = zoneId;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateTeamsOnWorld(team, false);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void PlayerContainer::BroadcastMuteUpdate(LWOOBJID player, time_t time) {
|
2021-12-05 17:54:36 +00:00
|
|
|
CBITSTREAM;
|
2024-04-01 03:27:50 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::GM_MUTE);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
bitStream.Write(player);
|
|
|
|
bitStream.Write(time);
|
|
|
|
|
2024-02-27 05:43:33 +00:00
|
|
|
Game::server->Send(bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
TeamData* PlayerContainer::CreateLocalTeam(std::vector<LWOOBJID> members) {
|
|
|
|
if (members.empty()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TeamData* newTeam = nullptr;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto member : members) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* team = GetTeam(member);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (team != nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
RemoveMember(team, member, false, false, true);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (newTeam == nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
newTeam = CreateTeam(member, true);
|
2022-07-28 13:39:57 +00:00
|
|
|
} else {
|
2021-12-05 17:54:36 +00:00
|
|
|
AddMember(newTeam, member);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newTeam->lootFlag = 1;
|
|
|
|
|
|
|
|
TeamStatusUpdate(newTeam);
|
|
|
|
|
|
|
|
return newTeam;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
TeamData* PlayerContainer::CreateTeam(LWOOBJID leader, bool local) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* team = new TeamData();
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2023-11-18 00:44:48 +00:00
|
|
|
team->teamID = ++m_TeamIDCounter;
|
2021-12-05 17:54:36 +00:00
|
|
|
team->leaderID = leader;
|
|
|
|
team->local = local;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
mTeams.push_back(team);
|
|
|
|
|
|
|
|
AddMember(team, leader);
|
|
|
|
|
|
|
|
return team;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
TeamData* PlayerContainer::GetTeam(LWOOBJID playerID) {
|
|
|
|
for (auto* team : mTeams) {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (std::find(team->memberIDs.begin(), team->memberIDs.end(), playerID) == team->memberIDs.end()) continue;
|
|
|
|
|
|
|
|
return team;
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void PlayerContainer::AddMember(TeamData* team, LWOOBJID playerID) {
|
2024-01-06 04:42:30 +00:00
|
|
|
if (team->memberIDs.size() >= 4) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Tried to add player to team that already had 4 players");
|
2024-01-06 04:42:30 +00:00
|
|
|
const auto& player = GetPlayerData(playerID);
|
2023-08-18 23:58:27 +00:00
|
|
|
if (!player) return;
|
2024-01-06 04:42:30 +00:00
|
|
|
ChatPackets::SendSystemMessage(player.sysAddr, u"The teams is full! You have not been added to a team!");
|
2023-08-18 23:58:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto index = std::find(team->memberIDs.begin(), team->memberIDs.end(), playerID);
|
|
|
|
|
|
|
|
if (index != team->memberIDs.end()) return;
|
|
|
|
|
|
|
|
team->memberIDs.push_back(playerID);
|
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
const auto& leader = GetPlayerData(team->leaderID);
|
|
|
|
const auto& member = GetPlayerData(playerID);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
if (!leader || !member) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
const auto leaderName = GeneralUtils::UTF8ToUTF16(leader.playerName);
|
|
|
|
const auto memberName = GeneralUtils::UTF8ToUTF16(member.playerName);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
ChatPacketHandler::SendTeamInviteConfirm(member, false, leader.playerID, leader.zoneID, team->lootFlag, 0, 0, leaderName);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!team->local) {
|
2024-01-06 04:42:30 +00:00
|
|
|
ChatPacketHandler::SendTeamSetLeader(member, leader.playerID);
|
2022-07-28 13:39:57 +00:00
|
|
|
} else {
|
2021-12-05 17:54:36 +00:00
|
|
|
ChatPacketHandler::SendTeamSetLeader(member, LWOOBJID_EMPTY);
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateTeamsOnWorld(team, false);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto memberId : team->memberIDs) {
|
2024-01-06 04:42:30 +00:00
|
|
|
const auto& otherMember = GetPlayerData(memberId);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (otherMember == member) continue;
|
|
|
|
|
|
|
|
const auto otherMemberName = GetName(memberId);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
ChatPacketHandler::SendTeamAddPlayer(member, false, team->local, false, memberId, otherMemberName, otherMember ? otherMember.zoneID : LWOZONEID(0, 0, 0));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
if (otherMember) {
|
|
|
|
ChatPacketHandler::SendTeamAddPlayer(otherMember, false, team->local, false, member.playerID, memberName, member.zoneID);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void PlayerContainer::RemoveMember(TeamData* team, LWOOBJID playerID, bool disband, bool kicked, bool leaving, bool silent) {
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto index = std::find(team->memberIDs.begin(), team->memberIDs.end(), playerID);
|
|
|
|
|
|
|
|
if (index == team->memberIDs.end()) return;
|
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
const auto& member = GetPlayerData(playerID);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
if (member && !silent) {
|
2021-12-05 17:54:36 +00:00
|
|
|
ChatPacketHandler::SendTeamSetLeader(member, LWOOBJID_EMPTY);
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto memberName = GetName(playerID);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto memberId : team->memberIDs) {
|
|
|
|
if (silent && memberId == playerID) {
|
2021-12-05 17:54:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
const auto& otherMember = GetPlayerData(memberId);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
if (!otherMember) continue;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
ChatPacketHandler::SendTeamRemovePlayer(otherMember, disband, kicked, leaving, false, team->leaderID, playerID, memberName);
|
|
|
|
}
|
|
|
|
|
|
|
|
team->memberIDs.erase(index);
|
|
|
|
|
|
|
|
UpdateTeamsOnWorld(team, false);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (team->memberIDs.size() <= 1) {
|
2021-12-05 17:54:36 +00:00
|
|
|
DisbandTeam(team);
|
2022-07-28 13:39:57 +00:00
|
|
|
} else {
|
|
|
|
if (playerID == team->leaderID) {
|
2021-12-05 17:54:36 +00:00
|
|
|
PromoteMember(team, team->memberIDs[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void PlayerContainer::PromoteMember(TeamData* team, LWOOBJID newLeader) {
|
2021-12-05 17:54:36 +00:00
|
|
|
team->leaderID = newLeader;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto memberId : team->memberIDs) {
|
2024-01-06 04:42:30 +00:00
|
|
|
const auto& otherMember = GetPlayerData(memberId);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
if (!otherMember) continue;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
ChatPacketHandler::SendTeamSetLeader(otherMember, newLeader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void PlayerContainer::DisbandTeam(TeamData* team) {
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto index = std::find(mTeams.begin(), mTeams.end(), team);
|
|
|
|
|
|
|
|
if (index == mTeams.end()) return;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto memberId : team->memberIDs) {
|
2024-01-06 04:42:30 +00:00
|
|
|
const auto& otherMember = GetPlayerData(memberId);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
if (!otherMember) continue;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
const auto memberName = GeneralUtils::UTF8ToUTF16(otherMember.playerName);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
ChatPacketHandler::SendTeamSetLeader(otherMember, LWOOBJID_EMPTY);
|
2024-01-06 04:42:30 +00:00
|
|
|
ChatPacketHandler::SendTeamRemovePlayer(otherMember, true, false, false, team->local, team->leaderID, otherMember.playerID, memberName);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
UpdateTeamsOnWorld(team, true);
|
|
|
|
|
|
|
|
mTeams.erase(index);
|
|
|
|
|
|
|
|
delete team;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void PlayerContainer::TeamStatusUpdate(TeamData* team) {
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto index = std::find(mTeams.begin(), mTeams.end(), team);
|
|
|
|
|
|
|
|
if (index == mTeams.end()) return;
|
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
const auto& leader = GetPlayerData(team->leaderID);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
if (!leader) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
const auto leaderName = GeneralUtils::UTF8ToUTF16(leader.playerName);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto memberId : team->memberIDs) {
|
2024-01-06 04:42:30 +00:00
|
|
|
const auto& otherMember = GetPlayerData(memberId);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
if (!otherMember) continue;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!team->local) {
|
2024-01-06 04:42:30 +00:00
|
|
|
ChatPacketHandler::SendTeamStatus(otherMember, team->leaderID, leader.zoneID, team->lootFlag, 0, leaderName);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateTeamsOnWorld(team, false);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void PlayerContainer::UpdateTeamsOnWorld(TeamData* team, bool deleteTeam) {
|
2021-12-05 17:54:36 +00:00
|
|
|
CBITSTREAM;
|
2024-04-01 03:27:50 +00:00
|
|
|
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::TEAM_GET_STATUS);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
bitStream.Write(team->teamID);
|
|
|
|
bitStream.Write(deleteTeam);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!deleteTeam) {
|
2021-12-05 17:54:36 +00:00
|
|
|
bitStream.Write(team->lootFlag);
|
2023-12-28 04:18:20 +00:00
|
|
|
bitStream.Write<char>(team->memberIDs.size());
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto memberID : team->memberIDs) {
|
2021-12-05 17:54:36 +00:00
|
|
|
bitStream.Write(memberID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-27 05:43:33 +00:00
|
|
|
Game::server->Send(bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
std::u16string PlayerContainer::GetName(LWOOBJID playerID) {
|
2024-01-06 04:42:30 +00:00
|
|
|
const auto iter = m_Names.find(playerID);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
if (iter == m_Names.end()) return u"";
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
return iter->second;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
LWOOBJID PlayerContainer::GetId(const std::u16string& playerName) {
|
2024-01-06 04:42:30 +00:00
|
|
|
LWOOBJID toReturn = LWOOBJID_EMPTY;
|
|
|
|
|
|
|
|
for (const auto& [id, name] : m_Names) {
|
|
|
|
if (name == playerName) {
|
|
|
|
toReturn = id;
|
|
|
|
break;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayerData& PlayerContainer::GetPlayerDataMutable(const LWOOBJID& playerID) {
|
2024-03-26 11:20:45 +00:00
|
|
|
return m_Players.contains(playerID) ? m_Players[playerID] : m_Players[LWOOBJID_EMPTY];
|
2024-01-06 04:42:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PlayerData& PlayerContainer::GetPlayerDataMutable(const std::string& playerName) {
|
|
|
|
for (auto& [id, player] : m_Players) {
|
|
|
|
if (!player) continue;
|
|
|
|
if (player.playerName == playerName) return player;
|
|
|
|
}
|
|
|
|
return m_Players[LWOOBJID_EMPTY];
|
|
|
|
}
|
|
|
|
|
|
|
|
const PlayerData& PlayerContainer::GetPlayerData(const LWOOBJID& playerID) {
|
|
|
|
return GetPlayerDataMutable(playerID);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-01-06 04:42:30 +00:00
|
|
|
const PlayerData& PlayerContainer::GetPlayerData(const std::string& playerName) {
|
|
|
|
return GetPlayerDataMutable(playerName);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|