@@ -338,6 +338,14 @@ LUA_FUNCTION_STATIC(CBaseClient_IsActive)
338338 return 1 ;
339339}
340340
341+ LUA_FUNCTION_STATIC (CBaseClient_GetSignonState)
342+ {
343+ CBaseClient* pClient = Get_CBaseClient (1 , true );
344+
345+ LUA->PushNumber (pClient->m_nSignonState );
346+ return 1 ;
347+ }
348+
341349LUA_FUNCTION_STATIC (CBaseClient_IsFakeClient)
342350{
343351 CBaseClient* pClient = Get_CBaseClient (1 , true );
@@ -854,6 +862,7 @@ void Push_CBaseClientMeta()
854862 Util::AddFunc (CBaseClient_IsConnected, " IsConnected" );
855863 Util::AddFunc (CBaseClient_IsSpawned, " IsSpawned" );
856864 Util::AddFunc (CBaseClient_IsActive, " IsActive" );
865+ Util::AddFunc (CBaseClient_GetSignonState, " GetSignonState" );
857866 Util::AddFunc (CBaseClient_IsFakeClient, " IsFakeClient" );
858867 Util::AddFunc (CBaseClient_IsHLTV, " IsHLTV" );
859868 Util::AddFunc (CBaseClient_IsHearingClient, " IsHearingClient" );
@@ -1462,6 +1471,9 @@ class CExtentedNetMessage : public CNetMessage
14621471 */
14631472static void MoveCGameClientIntoCGameClient (CGameClient* origin, CGameClient* target)
14641473{
1474+ if (g_pGameServerModule.InDebug ())
1475+ Msg (" holylib: Reassigned client to from slot %i to %i\n " , origin->m_nClientSlot , target->m_nClientSlot );
1476+
14651477 target->Inactivate ();
14661478 target->Clear ();
14671479
@@ -1573,17 +1585,8 @@ static void MoveCGameClientIntoCGameClient(CGameClient* origin, CGameClient* tar
15731585}
15741586
15751587#define MAX_PLAYERS 128
1576- static CFrameSnapshotManager* framesnapshotmanager = NULL ;
1577- static Detouring::Hook detour_CGameClient_SpawnPlayer;
1578- static Symbols::CBaseClient_SpawnPlayer func_CBaseClient_SpawnPlayer;
1579- void hook_CGameClient_SpawnPlayer (CGameClient* client)
1588+ static int FindFreeClientSlot ()
15801589{
1581- if (client->m_nClientSlot < MAX_PLAYERS)
1582- {
1583- detour_CGameClient_SpawnPlayer.GetTrampoline <Symbols::CGameClient_SpawnPlayer>()(client);
1584- return ;
1585- }
1586-
15871590 int nextFreeEntity = 255 ;
15881591 int count = Util::server->GetClientCount ();
15891592 if (count > MAX_PLAYERS)
@@ -1600,14 +1603,24 @@ void hook_CGameClient_SpawnPlayer(CGameClient* client)
16001603 nextFreeEntity = pClient->m_nEntityIndex ;
16011604 }
16021605
1606+ return nextFreeEntity;
1607+ }
1608+
1609+ static Detouring::Hook detour_CGameClient_SpawnPlayer;
1610+ void hook_CGameClient_SpawnPlayer (CGameClient* client)
1611+ {
1612+ if (client->m_nClientSlot < MAX_PLAYERS)
1613+ {
1614+ detour_CGameClient_SpawnPlayer.GetTrampoline <Symbols::CGameClient_SpawnPlayer>()(client);
1615+ return ;
1616+ }
1617+
1618+ int nextFreeEntity = FindFreeClientSlot ();
16031619 if (nextFreeEntity > MAX_PLAYERS)
16041620 {
16051621 Warning (" holylib: Failed to find a valid player slot to use! Stopping client spawn! (%i, %i, %i)\n " , client->m_nClientSlot , client->GetUserID (), nextFreeEntity);
16061622 return ;
16071623 }
1608-
1609- if (g_pGameServerModule.InDebug ())
1610- Msg (" holylib: Reassigned client to from slot %i to %i\n " , client->m_nClientSlot , nextFreeEntity - 1 );
16111624
16121625 CGameClient* pClient = (CGameClient*)Util::GetClientByIndex (nextFreeEntity - 1 );
16131626 if (pClient->m_nSignonState != SIGNONSTATE_NONE)
@@ -1621,6 +1634,27 @@ void hook_CGameClient_SpawnPlayer(CGameClient* client)
16211634 // detour_CGameClient_SpawnPlayer.GetTrampoline<Symbols::CGameClient_SpawnPlayer>()(pClient);
16221635}
16231636
1637+ // Called by SourceTV from CSteam3Server::NotifyClientDisconnect
1638+ void GameServer_OnClientDisconnect (CBaseClient* pClient)
1639+ {
1640+ if (pClient->GetServer () != Util::server)
1641+ return ;
1642+
1643+ if (Lua::PushHook (" HolyLib:OnClientDisconnect" ))
1644+ {
1645+ Push_CBaseClient (pClient);
1646+ g_Lua->CallFunctionProtected (2 , 0 , true );
1647+ }
1648+
1649+ auto it = g_pPushedCBaseClient.find (pClient);
1650+ if (it != g_pPushedCBaseClient.end ())
1651+ {
1652+ g_Lua->ReferenceFree (it->second ->iTableReference );
1653+ g_Lua->CreateTable ();
1654+ it->second ->iTableReference = g_Lua->ReferenceCreate (); // Create a new empty Lua table for the next client.
1655+ }
1656+ }
1657+
16241658void CGameServerModule::InitDetour (bool bPreServer)
16251659{
16261660 if (bPreServer)
@@ -1660,12 +1694,6 @@ void CGameServerModule::InitDetour(bool bPreServer)
16601694 func_CBaseClient_OnRequestFullUpdate = (Symbols::CBaseClient_OnRequestFullUpdate)Detour::GetFunction (engine_loader.GetModule (), Symbols::CBaseClient_OnRequestFullUpdateSym);
16611695 Detour::CheckFunction ((void *)func_CBaseClient_OnRequestFullUpdate, " CBaseClient::OnRequestFullUpdate" );
16621696
1663- func_CBaseClient_SpawnPlayer = (Symbols::CBaseClient_SpawnPlayer)Detour::GetFunction (engine_loader.GetModule (), Symbols::CBaseClient_SpawnPlayerSym);
1664- Detour::CheckFunction ((void *)func_CBaseClient_SpawnPlayer, " CBaseClient::SpawnPlayer" );
1665-
1666- framesnapshotmanager = Detour::ResolveSymbol<CFrameSnapshotManager>(engine_loader, Symbols::g_FrameSnapshotManagerSym);
1667- Detour::CheckValue (" get class" , " framesnapshotmanager" , framesnapshotmanager != NULL );
1668-
16691697 SourceSDK::FactoryLoader server_loader (" server" );
16701698 if (!g_pModuleManager.IsMarkedAsBinaryModule ()) // Loaded by require? Then we skip this.
16711699 {
0 commit comments