Skip to content

Commit

Permalink
update(scripting): Trying to fix calls for OnClientDisconnect/Connect
Browse files Browse the repository at this point in the history
  • Loading branch information
skuzzis committed Dec 1, 2023
1 parent b26affe commit e821355
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
9 changes: 9 additions & 0 deletions src/entrypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ bool scripting_OnClientConnect(const OnClientConnect *e);

bool SwiftlyPlugin::Hook_ClientConnect(CPlayerSlot slot, const char *pszName, uint64 xuid, const char *pszNetworkID, bool unk1, CBufferString *pRejectReason)
{
Player *player = new Player(false, slot.Get(), pszName, xuid);
g_playerManager->RegisterPlayer(player);

player->SetConnected(true);

OnClientConnect clientConnectEvent = OnClientConnect(&slot, pszName, xuid, pszNetworkID, unk1, pRejectReason);
hooks::emit(clientConnectEvent);
RETURN_META_VALUE(MRES_SUPERCEDE, scripting_OnClientConnect(&clientConnectEvent));
Expand All @@ -252,6 +257,10 @@ void SwiftlyPlugin::Hook_ClientDisconnect(CPlayerSlot slot, int reason, const ch
OnClientDisconnect clientDisconnectEvent = OnClientDisconnect(&slot, reason, pszName, xuid, pszNetworkID);
scripting_OnClientDisconnect(&clientDisconnectEvent);

Player *player = g_playerManager->GetPlayer(&slot);
if (player)
g_playerManager->UnregisterPlayer(&slot);

hooks::emit(clientDisconnectEvent);
}

Expand Down
19 changes: 0 additions & 19 deletions src/player/PlayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,6 @@ void OnClientConnectedOnServer(const OnClientConnected *e)
}
}

void OnClientConnectOnServer(const OnClientConnect *e)
{
Player *player = new Player(false, e->slot->Get(), e->pszName, e->xuid);
g_playerManager->RegisterPlayer(player);

player->SetConnected(true);
}

void OnClientDisconnected(const OnClientDisconnect *e)
{
Player *player = g_playerManager->GetPlayer(e->slot);
if (!player)
return;

g_playerManager->UnregisterPlayer(e->slot);
}

void OnClientSpawn(const OnPlayerSpawn *e)
{
CBasePlayerController *controller = (CBasePlayerController *)e->pEvent->GetPlayerController("userid");
Expand All @@ -63,8 +46,6 @@ void OnClientSpawn(const OnPlayerSpawn *e)
void PlayerManager::SetupHooks()
{
hooks::on<OnClientConnected>(OnClientConnectedOnServer);
hooks::on<OnClientConnect>(OnClientConnectOnServer);
hooks::on<OnClientDisconnect>(OnClientDisconnected);

gameevents::on<OnPlayerSpawn>(OnClientSpawn);
}

0 comments on commit e821355

Please sign in to comment.