Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
-Fixed a bug with player list not showing some players when their identity is null
-Fixed a bug where join message wasn't sending in Webhooks
  • Loading branch information
Da0ne committed Nov 30, 2022
1 parent 7857d98 commit 02bbfa3
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 29 deletions.
37 changes: 29 additions & 8 deletions 3_Game/VPPAdminTools/PlayerList/PlayerList.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class PlayerListManager
{
static ref PlayerListManager m_Instance = new PlayerListManager();
static ref PlayerListManager m_Instance;
static ref map<string, PlayerIdentity> PLAYERS; //Bohemia UID, Identity ref (server only)
static ref map<string, ref VPPUser> PLAYERS_CLIENT; //sending this via RPC to clients (client + server)
static ref array<PlayerIdentity> RECEIVERS; //hold onto administrator identities (server only)
Expand Down Expand Up @@ -42,7 +42,13 @@ class PlayerListManager
void OnRPC(PlayerIdentity sender, Object target, int rpc_type, ParamsReadContext ctx)
{
#ifdef SERVER
if (rpc_type == VPPATRPCs.RPC_PLAYERLIST_FORCESYNC)
{
if (!sender || !GetGame().IsDedicatedServer())
return;

PlayerListManager.SyncListToClient(sender, true);
}
#else
if (rpc_type == VPPATRPCs.RPC_SYNC_PLAYER_LIST)
{
Expand All @@ -55,7 +61,7 @@ class PlayerListManager

PlayerListManager.PLAYERS_CLIENT.Clear();
PlayerListManager.PLAYERS_CLIENT.Copy(tmp);
PlayerListManager.DebugListClient();
Print("YUP");
}

string uid;
Expand Down Expand Up @@ -111,6 +117,16 @@ class PlayerListManager
return false;
}

/*
* (client)
* Send RPC to server to force build a list and send back to all RECEIVERS
*/
void RequestForceSync()
{
ScriptRPC rpc = new ScriptRPC();
rpc.Send(NULL, VPPATRPCs.RPC_PLAYERLIST_FORCESYNC, true, NULL);
}

/*
* Give the player count from what World module has.
* Best used to determine if our list is out of sync somehow
Expand All @@ -137,7 +153,7 @@ class PlayerListManager
if (GetGame().IsDedicatedServer() && GetGame().IsMultiplayer())
{
if (PLAYERS_CLIENT.Count() != GetCountActual())
PlayerListManager.BuildList();
PlayerListManager.BuildList();
}

array<ref VPPUser> elements = {};
Expand Down Expand Up @@ -226,11 +242,11 @@ class PlayerListManager
return false;
}

static void BuildList()
static void BuildList(bool useWorldPtr = false)
{
if (PLAYERS.Count() <= 0)
if (useWorldPtr || PLAYERS.Count() <= 0)
{
//fail-safe measure incase PLAYERS was wiped, rebuild one from world array
//rebuild one from world array
array<Man> players = new array<Man>;
GetGame().GetWorld().GetPlayerList(players);
for (int i = 0; i < players.Count(); ++i)
Expand All @@ -242,19 +258,24 @@ class PlayerListManager
PLAYERS_CLIENT.Clear();
foreach(string uid, PlayerIdentity identity : PLAYERS)
{
if (!identity)
{
Print("[PlayerListManager] UID: " + uid + " no identity");
continue;
}
PLAYERS_CLIENT.Insert(uid, new VPPUser(identity.GetName(), identity.GetPlainId(), identity.GetPlayerId()));
}
}

/*
* Sends entire Sync list to a specified client via RPC
*/
static void SyncListToClient(notnull PlayerIdentity identity)
static void SyncListToClient(notnull PlayerIdentity identity, bool useWorldPtr = false)
{
if (!identity)
return;

BuildList();
BuildList(useWorldPtr);

ScriptRPC rpc = new ScriptRPC();
rpc.Write(PLAYERS_CLIENT);
Expand Down
1 change: 1 addition & 0 deletions 3_Game/VPPAdminTools/VPPATRPCs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ enum VPPATRPCs
RPC_SYNC_PLAYER_LIST,
RPC_PLAYERLIST_ADD,
RPC_PLAYERLIST_REMOVE,
RPC_PLAYERLIST_FORCESYNC,
};
1 change: 1 addition & 0 deletions 3_Game/VPPAdminTools/VanillaPlusPlus.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ modded class DayZGame

void DayZGame()
{
new PlayerListManager();
m_VPPDebugMissions = new map<string,string>;
Print("[DayZ Game]:: DayZGame(): Initializing V++ Admin Tools.");
vppatEventHandler = new VPPEventHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ class MenuPlayerManager extends AdminHudSubMenu

private void UpdateEntries()
{
GetPlayerListManager().RequestForceSync();
GetRPCManager().VSendRPC("RPC_PlayerManager", "GetPlayerCount", NULL, true);
m_PlayerEntries = Compare();
SendForPlayerStats();
Expand Down
48 changes: 27 additions & 21 deletions 5_Mission/VPPAdminTools/missionServer.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,14 @@ modded class MissionServer
//Called when player joins/respawns (PREP STAGE)
case ClientPrepareEventTypeID:
{
Print("ClientPrepareEventTypeID");
ClientPrepareEventParams clientPrepareParams;
Class.CastTo(clientPrepareParams, params);

identity = clientPrepareParams.param1;

if (GetPermissionManager().HasUserGroup(identity.GetPlainId()))
{
PlayerListManager.AddReceiver(identity);
PlayerListManager.AddEntry(identity.GetId(), identity);
PlayerListManager.SyncListToClient(identity);
}
else
{
PlayerListManager.AddEntry(identity.GetId(), identity);
}

BannedPlayer bannedPlayer = GetBansManager().GetBannedPlayer(identity.GetPlainId());
if (bannedPlayer != NULL)
{
Print("Banned player");
BanDuration expireDate = bannedPlayer.expirationDate;
string banReason = bannedPlayer.banReason;
if (expireDate.Permanent)
Expand All @@ -105,9 +92,8 @@ modded class MissionServer

if (!m_KickQueue.Contains(identity.GetPlainId()))
{
Print("Add to ban queue");
m_KickQueue.Insert(identity.GetPlainId(), 0);
GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(this.InvokeKickPlayer, 1/*m_LoginTimeMs*/, true, identity.GetPlainId(), banReason);
GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(this.InvokeKickPlayer, m_LoginTimeMs, true, identity.GetPlainId(), banReason);
}
}

Expand All @@ -126,8 +112,6 @@ modded class MissionServer
identity = readyParams.param1;
player = PlayerBase.Cast(readyParams.param2);

PlayerListManager.SyncEntryToReceivers(identity.GetId()); //sync player list
Print("ClientReadyEventTypeID::SyncEntryToReceivers");

onPlayerConnect = VPPATGetEventHandler().GetEventInvoker("OnPlayerConnect");
if(onPlayerConnect)
Expand All @@ -136,6 +120,19 @@ modded class MissionServer
onPlayerConnect.Invoke(player, identity, false, announceLogin);
}

if (GetPermissionManager().HasUserGroup(identity.GetPlainId()))
{
PlayerListManager.AddReceiver(identity);
PlayerListManager.AddEntry(identity.GetId(), identity);
PlayerListManager.SyncListToClient(identity);
}
else
{
PlayerListManager.AddEntry(identity.GetId(), identity);
}

PlayerListManager.SyncEntryToReceivers(identity.GetId()); //sync player list

break;
}

Expand All @@ -156,16 +153,26 @@ modded class MissionServer
identity = newReadyParams.param1;
player = PlayerBase.Cast(newReadyParams.param2);

PlayerListManager.SyncEntryToReceivers(identity.GetId()); //sync player list
Print("ClientNewReadyEventTypeID::SyncEntryToReceivers");

onPlayerConnect = VPPATGetEventHandler().GetEventInvoker("OnPlayerConnect");
if(onPlayerConnect)
{
announceLogin = !GetPlayerListManager().HasPlayerInList(identity.GetId());
onPlayerConnect.Invoke(player, identity, false, announceLogin);
}

if (GetPermissionManager().HasUserGroup(identity.GetPlainId()))
{
PlayerListManager.AddReceiver(identity);
PlayerListManager.AddEntry(identity.GetId(), identity);
PlayerListManager.SyncListToClient(identity);
}
else
{
PlayerListManager.AddEntry(identity.GetId(), identity);
}

PlayerListManager.SyncEntryToReceivers(identity.GetId()); //sync player list

break;
}

Expand Down Expand Up @@ -400,7 +407,6 @@ modded class MissionServer
PlayerIdentity identity = GetPermissionManager().GetIdentityById( id );
if( identity != NULL )
{
Print("Send kick RPC");
GetSimpleLogger().Log(string.Format("Kicking banned player \"%1\" (steamId=%2) kick message: (%3)", identity.GetName(), id, msg));
GetRPCManager().SendRPC( "RPC_MissionGameplay", "KickClientHandle", new Param1<string>( msg ), true, identity);
GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.InvokeKickPlayer);
Expand Down

0 comments on commit 02bbfa3

Please sign in to comment.