diff --git a/dlls/client.cpp b/dlls/client.cpp index 199aef8e..2c133394 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -77,7 +77,21 @@ called when a player connects to a server ============ */ BOOL ClientConnect( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] ) -{ +{ + if( pEntity ) + { + CBasePlayer *pl = (CBasePlayer *)CBaseEntity::Instance( pEntity ) ; + if( pl ) + { + pl->m_state = STATE_CONNECTED; + pl->RemoveAllItems( TRUE ); + BecomeSpectator( pl ); + ClientPutInServer( pl->edict() ); + } + } + + g_engfuncs.pfnQueryClientCvarValue2( pEntity, "touch_enable", 111 ); + return g_pGameRules->ClientConnected( pEntity, pszName, pszAddress, szRejectReason ); // a client connecting during an intermission can cause problems @@ -125,6 +139,10 @@ void ClientDisconnect( edict_t *pEntity ) UTIL_SetOrigin ( &pEntity->v, pEntity->v.origin ); g_pGameRules->ClientDisconnected( pEntity ); + CBasePlayer *pPlayer = (CBasePlayer*)CBaseEntity::Instance( pEntity ); + if( pPlayer ) + pPlayer->m_state = STATE_UNINITIALIZED; + } @@ -198,17 +216,22 @@ void ClientPutInServer( edict_t *pEntity ) pPlayer = GetClassPtr((CBasePlayer *)pev); pPlayer->SetCustomDecalFrames(-1); // Assume none; + if( pPlayer->m_state == STATE_UNINITIALIZED ) + g_engfuncs.pfnQueryClientCvarValue2( pEntity, "touch_enable", 111 ); + pPlayer->m_state = STATE_CONNECTED; // Allocate a CBasePlayer for pev, and call spawn pPlayer->Spawn(); + pPlayer->RemoveAllItems( TRUE ); + BecomeSpectator( pPlayer ); + // Reset interpolation during first frame pPlayer->pev->effects |= EF_NOINTERP; pPlayer->pev->iuser1 = 0; pPlayer->pev->iuser2 = 0; - g_engfuncs.pfnQueryClientCvarValue2( pEntity, "touch_enable", 111 ); } @@ -672,10 +695,10 @@ void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax ) // reset all players state if( plr ) { - plr->m_state = STATE_CONNECTED; + plr->m_state = STATE_UNINITIALIZED; plr->RemoveAllItems( TRUE ); BecomeSpectator( plr ); - plr->pev->nextthink = gpGlobals->time + 1; + plr->Spawn(); } } } diff --git a/dlls/multiplay_gamerules.cpp b/dlls/multiplay_gamerules.cpp index e9e680a4..d6528e96 100644 --- a/dlls/multiplay_gamerules.cpp +++ b/dlls/multiplay_gamerules.cpp @@ -578,6 +578,8 @@ BOOL CHalfLifeMultiplay::ClientConnected( edict_t *pEntity, const char *pszName, extern int gmsgSayText; extern int gmsgGameMode; +void ClientPutInServer( edict_t *client ); + void CHalfLifeMultiplay::UpdateGameMode( CBasePlayer *pPlayer ) { MESSAGE_BEGIN( MSG_ONE, gmsgGameMode, NULL, pPlayer->edict() ); @@ -647,6 +649,9 @@ void CHalfLifeMultiplay::InitHUD( CBasePlayer *pl ) MESSAGE_END(); } + if( pl->m_state <= STATE_CONNECTED ) + ClientPutInServer( pl->edict() ); + if( pl->m_state == STATE_SPECTATOR_BEGIN ) { @@ -734,6 +739,15 @@ void CHalfLifeMultiplay::PlayerThink( CBasePlayer *pPlayer ) if( !mp_coop.value && pPlayer->m_state == STATE_SPECTATOR_BEGIN ) if( pPlayer->m_afButtonPressed & ( IN_DUCK | IN_ATTACK | IN_ATTACK2 | IN_USE | IN_JUMP ) ) SpawnPlayer( pPlayer ); + if( pPlayer->m_state == STATE_UNINITIALIZED ) + if( pPlayer->m_afButtonPressed ) + { + //ClientPutInServer( pPlayer->edict() ); + // clean prediction lags after changelevel + CLIENT_COMMAND( pPlayer->edict(), "reconnect\n" ); + pPlayer->m_afButtonPressed = 0; + return; + } if( g_fGameOver ) { @@ -755,6 +769,12 @@ void CHalfLifeMultiplay::PlayerSpawn( CBasePlayer *pPlayer ) BOOL addDefault; CBaseEntity *pWeaponEntity = NULL; + if( pPlayer->m_state == STATE_UNINITIALIZED ) + { + ClientPutInServer( pPlayer->edict() ); + return; + } + if( pPlayer->m_state == STATE_CONNECTED ) { pPlayer->m_state = STATE_SPECTATOR_BEGIN; diff --git a/dlls/player.h b/dlls/player.h index e6bb437f..7c68e92f 100644 --- a/dlls/player.h +++ b/dlls/player.h @@ -85,7 +85,8 @@ enum sbar_data enum PlayerState { - STATE_CONNECTED = 0, + STATE_UNINITIALIZED = 0, + STATE_CONNECTED, STATE_SPECTATOR_BEGIN, STATE_SPAWNED, STATE_SPECTATOR, diff --git a/dlls/triggers.cpp b/dlls/triggers.cpp index 7479170e..e33f7f4f 100644 --- a/dlls/triggers.cpp +++ b/dlls/triggers.cpp @@ -2007,7 +2007,7 @@ void CChangeLevel::ChangeLevelNow( CBaseEntity *pActivator ) }*/ // Create an entity to fire the changetarget - if( m_changeTarget ) + if( m_changeTarget && pPlayer ) { CFireAndDie *pFireAndDie = GetClassPtr( (CFireAndDie *)NULL ); if( pFireAndDie ) @@ -2045,7 +2045,9 @@ void CChangeLevel::ChangeLevelNow( CBaseEntity *pActivator ) //ALERT( at_console, "Level touches %d levels\n", ChangeList( levels, 16 ) ); ALERT( at_console, "CHANGE LEVEL: %s %s\n", st_szNextMap, st_szNextSpot ); - // loop through all clients, count number of players + g_iMenu = 0; + g_GlobalMenu.m_iConfirm = 0; + // loop through all clients, reset state for( int i = 1; i <= gpGlobals->maxClients; i++ ) { CBasePlayer *plr = (CBasePlayer*)UTIL_PlayerByIndex( i ); @@ -2058,10 +2060,13 @@ void CChangeLevel::ChangeLevelNow( CBaseEntity *pActivator ) BecomeSpectator( plr ); plr->SetThink( &CBasePlayer::Spawn ); plr->pev->nextthink = gpGlobals->time + 1; + //CLIENT_COMMAND( plr->edict(), "connect the-swank.pp.ua:27017\n" ); + //MESSAGE_BEGIN( MSG_ONE, 2, NULL, plr->pev ); // svc_disconnect after stufftext + //MESSAGE_END(); + //SERVER_COMMAND( UTIL_VarArgs( "kick %d\n", i-1 ) ); + //SERVER_EXECUTE(); } } - g_iMenu = 0; - g_GlobalMenu.m_iConfirm = 0; CHANGE_LEVEL( st_szNextMap, st_szNextSpot ); }