Skip to content

Commit

Permalink
Events: Client disconnect: Add PLAYER_NAME, CDKEY as event data
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrikgit committed Sep 8, 2024
1 parent cca23fd commit a38939d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ https://github.com/nwnxee/unified/compare/build8193.36.12...HEAD
- Player: ReloadColorPalettes()

### Changed
- Player: added bChatWindow parameter to FloatingTextStringOnCreature()
- Player: added bChatWindow parameter to FloatingTextStringOnCreature()
- Damage: added iSpellId to the NWNX_Damage_DamageEventData struct.
- Docker: Add dotnet-runtime-8.0, dotnet-apphost-pack-8.0 packages.
- Item: Added parameter `bUpdateCreatureAppearance` to SetItemAppearance() to update the appearance of the item's possessor.
- Events: Added PLAYER_NAME, CDKEY as event data to the client disconnect events `NWNX_ON_CLIENT_DISCONNECT_{BEFORE|AFTER}`.

### Deprecated
- DotNET: GetFunctionPointer()
Expand Down
8 changes: 8 additions & 0 deletions Plugins/Events/Events/ClientEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,16 @@ void RemovePCFromWorldHook(CServerExoAppInternal *pServerExoAppInternal, CNWSPla
{
// NOTE: Events won't be processed for disconnecting characters, e.g. RemoveEffect events.
// If we wanted that to happen, we'd need to process the event like CServerAIMaster__GetPendingEvent.
auto *pNetLayer = Globals::AppManager()->m_pServerExoApp->GetNetLayer();
auto *pPlayerInfo = pNetLayer->GetPlayerInfo(pPlayer->m_nPlayerID);
auto playerName = pPlayerInfo->m_sPlayerName.CStr();
auto cdKey = pPlayerInfo->m_lstKeys[0].sPublic.CStr();
PushEventData("PLAYER_NAME", playerName);
PushEventData("CDKEY", cdKey);
SignalEvent("NWNX_ON_CLIENT_DISCONNECT_BEFORE" , pPlayer->m_oidNWSObject);
s_RemovePCFromWorldHook->CallOriginal<void>(pServerExoAppInternal, pPlayer);
PushEventData("PLAYER_NAME", playerName);
PushEventData("CDKEY", cdKey);
SignalEvent("NWNX_ON_CLIENT_DISCONNECT_AFTER", pPlayer->m_oidNWSObject);
}

Expand Down
5 changes: 5 additions & 0 deletions Plugins/Events/NWScript/nwnx_events.nss
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,11 @@ _______________________________________
`OBJECT_SELF` = The player disconnecting from the server
Event Data Tag | Type | Notes
----------------------|--------|-------
PLAYER_NAME | string | Player name of the disconnecting client
CDKEY | string | Public cdkey of the disconnecting client
@note This event also runs when a player connects to the server but cancels out of character select.
OBJECT_SELF will be OBJECT_INVALID in this case.
Expand Down

0 comments on commit a38939d

Please sign in to comment.