BOOL CHalfLifeMultiplay::ClientCommand( CBasePlayer *pPlayer, const char *pcmd ) { if(g_VoiceGameMgr.ClientCommand(pPlayer, pcmd)) return TRUE; return CGameRules::ClientCommand(pPlayer, pcmd); }
CHalfLifeMultiplay :: CHalfLifeMultiplay() { g_VoiceGameMgr.Init(&g_GameMgrHelper, gpGlobals->maxClients); RefreshSkillData(); m_flIntermissionEndTime = 0; // 11/8/98 // Modified by YWB: Server .cfg file is now a cvar, so that // server ops can run multiple game servers, with different server .cfg files, // from a single installed directory. // Mapcyclefile is already a cvar. // 3/31/99 // Added lservercfg file cvar, since listen and dedicated servers should not // share a single config file. (sjb) if ( IS_DEDICATED_SERVER() ) { // this code has been moved into engine, to only run server.cfg once } else { // listen server char *lservercfgfile = (char *)CVAR_GET_STRING( "lservercfgfile" ); if ( lservercfgfile && lservercfgfile[0] ) { char szCommand[256]; ALERT( at_console, "Executing listen server config file\n" ); sprintf( szCommand, "exec %s\n", lservercfgfile ); SERVER_COMMAND( szCommand ); } } }
//========================================================= //========================================================= BOOL CHalfLifeMultiplay :: ClientConnected( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] ) { g_VoiceGameMgr.ClientConnected(pEntity); // Increase their speed to the Discwar speed MESSAGE_BEGIN( MSG_ONE, SVC_STUFFTEXT, NULL, pEntity ); WRITE_STRING( UTIL_VarArgs("cl_forwardspeed %d\ncl_backspeed %d\ncl_sidespeed %d\n", 320, 320, 320) ); MESSAGE_END(); return TRUE; }
CHeadQuartersRules :: CHeadQuartersRules() { m_DisableDeathMessages = false; FirstBlood = false; g_VoiceGameMgr.Init(&g_GameMgrHelper, gpGlobals->maxClients); RefreshSkillData(); m_flIntermissionEndTime = 0; g_flIntermissionStartTime = 0; State = STATE_IDLE; CurrentBase = LastBase = NULL; LastCurrentTeam = -1; SERVER_COMMAND( "exec server.cfg\n" ); }
//========================================================= // ClientCommand // the user has typed a command which is unrecognized by everything else; // this check to see if the gamerules knows anything about the command //========================================================= BOOL CHalfLifeTeamplay :: ClientCommand( CBasePlayer *pPlayer, const char *pcmd ) { if(g_VoiceGameMgr.ClientCommand(pPlayer, pcmd)) return TRUE; if ( FStrEq( pcmd, "menuselect" ) ) { if ( CMD_ARGC() < 2 ) return TRUE; int slot = atoi( CMD_ARGV(1) ); // select the item from the current menu return TRUE; } return FALSE; }
//// HOST_SAY // String comes in as // say blah blah blah // or as // blah blah blah // void Host_Say( edict_t *pEntity, int teamonly ) { CBasePlayer *client; int j; char *p; char text[128]; char szTemp[256]; const char *cpSay = "say"; const char *cpSayTeam = "say_team"; const char *pcmd = CMD_ARGV(0); // We can get a raw string now, without the "say " prepended if ( CMD_ARGC() == 0 ) return; entvars_t *pev = &pEntity->v; CBasePlayer* player = GetClassPtr((CBasePlayer *)pev); //Not yet. if ( player->m_flNextChatTime > gpGlobals->time ) return; if ( !stricmp( pcmd, cpSay) || !stricmp( pcmd, cpSayTeam ) ) { if ( CMD_ARGC() >= 2 ) { p = (char *)CMD_ARGS(); } else { // say with a blank message, nothing to do return; } } else // Raw text, need to prepend argv[0] { if ( CMD_ARGC() >= 2 ) { sprintf( szTemp, "%s %s", ( char * )pcmd, (char *)CMD_ARGS() ); } else { // Just a one word command, use the first word...sigh sprintf( szTemp, "%s", ( char * )pcmd ); } p = szTemp; } // remove quotes if present if (*p == '"') { p++; p[strlen(p)-1] = 0; } // make sure the text has content char *pc; for ( pc = p; pc != NULL && *pc != 0; pc++ ) { if ( !isspace( *pc ) ) { pc = NULL; // we've found an alphanumeric character, so text is valid break; } } if ( pc != NULL ) return; // no character found, so say nothing // turn on color set 2 (color on, no sound) if ( teamonly ) sprintf( text, "%c(TEAM) %s: ", 2, STRING( pEntity->v.netname ) ); else sprintf( text, "%c%s: ", 2, STRING( pEntity->v.netname ) ); j = sizeof(text) - 2 - strlen(text); // -2 for /n and null terminator if ( (int)strlen(p) > j ) p[j] = 0; strcat( text, p ); strcat( text, "\n" ); player->m_flNextChatTime = gpGlobals->time + CHAT_INTERVAL; // loop through all players // Start with the first player. // This may return the world in single player if the client types something between levels or during spawn // so check it, or it will infinite loop client = NULL; while ( ((client = (CBasePlayer*)UTIL_FindEntityByClassname( client, "player" )) != NULL) && (!FNullEnt(client->edict())) ) { if ( !client->pev ) continue; if ( client->edict() == pEntity ) continue; if ( !(client->IsNetClient()) ) // Not a client ? (should never be true) continue; // can the receiver hear the sender? or has he muted him? if ( g_VoiceGameMgr.PlayerHasBlockedPlayer( client, player ) ) continue; if ( teamonly && g_pGameRules->PlayerRelationship(client, CBaseEntity::Instance(pEntity)) != GR_TEAMMATE ) continue; MESSAGE_BEGIN( MSG_ONE, gmsgSayText, NULL, client->pev ); WRITE_BYTE( ENTINDEX(pEntity) ); WRITE_STRING( text ); MESSAGE_END(); } // print to the sending client MESSAGE_BEGIN( MSG_ONE, gmsgSayText, NULL, &pEntity->v ); WRITE_BYTE( ENTINDEX(pEntity) ); WRITE_STRING( text ); MESSAGE_END(); // echo to server console g_engfuncs.pfnServerPrint( text ); char * temp; if ( teamonly ) temp = "say_team"; else temp = "say"; // team match? if ( g_teamplay ) { UTIL_LogPrintf( "\"%s<%i><%s><%s>\" %s \"%s\"\n", STRING( pEntity->v.netname ), GETPLAYERUSERID( pEntity ), GETPLAYERAUTHID( pEntity ), g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( pEntity ), "model" ), temp, p ); } else { UTIL_LogPrintf( "\"%s<%i><%s><%i>\" %s \"%s\"\n", STRING( pEntity->v.netname ), GETPLAYERUSERID( pEntity ), GETPLAYERAUTHID( pEntity ), GETPLAYERUSERID( pEntity ), temp, p ); } }
//========================================================= //========================================================= void CHalfLifeMultiplay :: Think ( void ) { g_VoiceGameMgr.Update(gpGlobals->frametime); ///// Check game rules ///// static int last_frags; static int last_time; int frags_remaining = 0; int time_remaining = 0; if ( g_fGameOver ) // someone else quit the game already { if ( m_flIntermissionEndTime < gpGlobals->time ) { if ( m_iEndIntermissionButtonHit // check that someone has pressed a key, or the max intermission time is over || ((m_flIntermissionEndTime + MAX_INTERMISSION_TIME) < gpGlobals->time) ) ChangeLevel(); // intermission is over } return; } float flTimeLimit = timelimit.value * 60; float flFragLimit = fraglimit.value; time_remaining = (int)(flTimeLimit ? ( flTimeLimit - gpGlobals->time ) : 0); if ( flTimeLimit != 0 && gpGlobals->time >= flTimeLimit ) { GoToIntermission(); return; } if ( flFragLimit ) { int bestfrags = 9999; int remain; // check if any player is over the frag limit for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { CBaseEntity *pPlayer = UTIL_PlayerByIndex( i ); if ( pPlayer && pPlayer->pev->frags >= flFragLimit ) { GoToIntermission(); return; } if ( pPlayer ) { remain = static_cast<int>(flFragLimit - pPlayer->pev->frags); if ( remain < bestfrags ) { bestfrags = remain; } } } frags_remaining = bestfrags; } // Updates when frags change if ( frags_remaining != last_frags ) { g_engfuncs.pfnCvar_DirectSet( &fragsleft, UTIL_VarArgs( "%i", frags_remaining ) ); } // Updates once per second if ( timeleft.value != last_time ) { g_engfuncs.pfnCvar_DirectSet( &timeleft, UTIL_VarArgs( "%i", time_remaining ) ); } last_frags = frags_remaining; last_time = time_remaining; }
//========================================================= //========================================================= BOOL CHalfLifeMultiplay :: ClientConnected( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] ) { g_VoiceGameMgr.ClientConnected(pEntity); return TRUE; }
void CHeadQuartersRules :: Think ( void ) { if( gamemode.value != 4 ) SERVER_COMMAND( "restart\n" ); HeadQThink(); g_VoiceGameMgr.Update(gpGlobals->frametime); ///// Check game rules ///// static int last_frags; static int last_time; int frags_remaining = 0; int time_remaining = 0; if ( g_fGameOver ) // someone else quit the game already { // bounds check int time = (int)CVAR_GET_FLOAT( "mp_chattime" ); if ( time < 1 ) CVAR_SET_STRING( "mp_chattime", "1" ); else if ( time > MAX_INTERMISSION_TIME ) CVAR_SET_STRING( "mp_chattime", UTIL_dtos1( MAX_INTERMISSION_TIME ) ); m_flIntermissionEndTime = g_flIntermissionStartTime + mp_chattime.value; // check to see if we should change levels now if ( m_flIntermissionEndTime < gpGlobals->time ) { if ( m_iEndIntermissionButtonHit // check that someone has pressed a key, or the max intermission time is over || ( ( g_flIntermissionStartTime + MAX_INTERMISSION_TIME ) < gpGlobals->time) ) ChangeLevel(); // intermission is over } return; } float flTimeLimit = timelimit.value * 60; float flFragLimit = fraglimit.value; time_remaining = (int)(flTimeLimit ? ( flTimeLimit - gpGlobals->time ) : 0); if ( flTimeLimit != 0 && gpGlobals->time >= flTimeLimit ) { GoToIntermission(); return; } if ( flFragLimit ) { int bestfrags = 9999; int remain; // check if any player is over the frag limit for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { CBaseEntity *pPlayer = UTIL_PlayerByIndex( i ); if ( pPlayer && pPlayer->pev->frags >= flFragLimit ) { GoToIntermission(); return; } if ( pPlayer ) { remain = flFragLimit - pPlayer->pev->frags; if ( remain < bestfrags ) { bestfrags = remain; } } } frags_remaining = bestfrags; } // Updates when frags change if ( frags_remaining != last_frags ) { g_engfuncs.pfnCvar_DirectSet( &fragsleft, UTIL_VarArgs( "%i", frags_remaining ) ); } // Updates once per second if ( timeleft.value != last_time ) { g_engfuncs.pfnCvar_DirectSet( &timeleft, UTIL_VarArgs( "%i", time_remaining ) ); } last_frags = frags_remaining; last_time = time_remaining; }
void CHalfLifeTeamplay :: Think ( void ) { ///// Check game rules ///// static int last_frags; static int last_time; int frags_remaining = 0; int time_remaining = 0; g_VoiceGameMgr.Update(gpGlobals->frametime); if ( g_fGameOver ) // someone else quit the game already { CHalfLifeMultiplay::Think(); return; } float flTimeLimit = CVAR_GET_FLOAT("mp_timelimit") * 60; time_remaining = (int)(flTimeLimit ? ( flTimeLimit - gpGlobals->time ) : 0); // Don't map switch in tourny mode, it signals the end of the match instead bool theIsTournyMode = (CVAR_GET_FLOAT(kvTournamentMode) > 0); if ( flTimeLimit != 0 && (gpGlobals->time >= flTimeLimit) && !theIsTournyMode) { GoToIntermission(); return; } float flFragLimit = fraglimit.value; if ( flFragLimit ) { int bestfrags = 9999; int remain; // check if any team is over the frag limit for ( int i = 0; i < num_teams; i++ ) { if ( team_scores[i] >= flFragLimit ) { GoToIntermission(); return; } remain = flFragLimit - team_scores[i]; if ( remain < bestfrags ) { bestfrags = remain; } } frags_remaining = bestfrags; } // Updates when frags change if ( frags_remaining != last_frags ) { g_engfuncs.pfnCvar_DirectSet( &fragsleft, UTIL_VarArgs( "%i", frags_remaining ) ); } // Updates once per second if ( timeleft.value != last_time ) { g_engfuncs.pfnCvar_DirectSet( &timeleft, UTIL_VarArgs( "%i", time_remaining ) ); } last_frags = frags_remaining; last_time = time_remaining; }