Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1675 lines
41 KiB

9 years ago
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
//
// teamplay_gamerules.cpp
//
9 years ago
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "player.h"
#include "weapons.h"
#include "gamerules.h"
#include "skill.h"
#include "game.h"
#include "items.h"
4 years ago
#if !NO_VOICEGAMEMGR
9 years ago
#include "voice_gamemgr.h"
#endif
9 years ago
#include "hltv.h"
//++ BulliT
#include "aggamerules.h"
#include "multi_gamerules.h"
//extern DLL_GLOBAL CGameRules *g_pGameRules;
extern DLL_GLOBAL AgGameRules *g_pGameRules;
extern int gmsgAuthID;
//-- Martin Webrant
9 years ago
extern DLL_GLOBAL BOOL g_fGameOver;
extern int gmsgDeathMsg; // client dll messages
extern int gmsgScoreInfo;
extern int gmsgMOTD;
extern int gmsgServerName;
extern int g_teamplay;
#define ITEM_RESPAWN_TIME 30
#define WEAPON_RESPAWN_TIME 20
#define AMMO_RESPAWN_TIME 20
float g_flIntermissionStartTime = 0;
4 years ago
#if !NO_VOICEGAMEMGR
9 years ago
CVoiceGameMgr g_VoiceGameMgr;
class CMultiplayGameMgrHelper : public IVoiceGameMgrHelper
{
public:
8 years ago
virtual bool CanPlayerHearPlayer(CBasePlayer *pListener, CBasePlayer *pTalker)
9 years ago
{
8 years ago
if( g_teamplay )
9 years ago
{
//++ BulliT
if( pListener->IsSpectator() && pTalker->IsSpectator() )
return true;
if( pListener->IsSpectator() || pTalker->IsSpectator() )
return false;
//-- Martin Webrant
8 years ago
if( g_pGameRules->PlayerRelationship( pListener, pTalker ) != GR_TEAMMATE )
9 years ago
{
return false;
}
}
return true;
}
};
static CMultiplayGameMgrHelper g_GameMgrHelper;
#endif
9 years ago
//*********************************************************
// Rules for the half-life multiplayer game.
//*********************************************************
8 years ago
CHalfLifeMultiplay::CHalfLifeMultiplay()
9 years ago
{
4 years ago
#if !NO_VOICEGAMEMGR
8 years ago
g_VoiceGameMgr.Init( &g_GameMgrHelper, gpGlobals->maxClients );
#endif
9 years ago
RefreshSkillData();
m_flIntermissionEndTime = 0;
g_flIntermissionStartTime = 0;
//++ BulliT
m_iEndIntermissionButtonHit = 0;
//-- Martin Webrant
9 years ago
// 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)
//++ BulliT
/*
8 years ago
if( IS_DEDICATED_SERVER() )
9 years ago
{
// dedicated server
const char *servercfgfile = CVAR_GET_STRING( "servercfgfile" );
9 years ago
8 years ago
if( servercfgfile && servercfgfile[0] )
9 years ago
{
char szCommand[256];
ALERT( at_console, "Executing dedicated server config file\n" );
sprintf( szCommand, "exec %s\n", servercfgfile );
SERVER_COMMAND( szCommand );
}
// this code has been moved into engine, to only run server.cfg once
9 years ago
}
else
{
// listen server
const char *lservercfgfile = CVAR_GET_STRING( "lservercfgfile" );
9 years ago
8 years ago
if( lservercfgfile && lservercfgfile[0] )
9 years ago
{
char szCommand[256];
ALERT( at_console, "Executing listen server config file\n" );
sprintf( szCommand, "exec %s\n", lservercfgfile );
SERVER_COMMAND( szCommand );
}
}
*/
//-- Martin Webrant
9 years ago
}
BOOL CHalfLifeMultiplay::ClientCommand( CBasePlayer *pPlayer, const char *pcmd )
{
4 years ago
#if !NO_VOICEGAMEMGR
8 years ago
if( g_VoiceGameMgr.ClientCommand( pPlayer, pcmd ) )
9 years ago
return TRUE;
#endif
//++ BulliT
//return CGameRules::ClientCommand( pPlayer, pcmd );
return AgGameRules::ClientCommand( pPlayer, pcmd );
//-- Martin Webrant
9 years ago
}
//=========================================================
//=========================================================
void CHalfLifeMultiplay::RefreshSkillData( void )
{
//++ BulliT
AgGameRules::RefreshSkillData();
return;
//-- Martin Webrant
9 years ago
}
// longest the intermission can last, in seconds
#define MAX_INTERMISSION_TIME 120
extern cvar_t timeleft, fragsleft;
extern cvar_t mp_chattime;
//=========================================================
//=========================================================
8 years ago
void CHalfLifeMultiplay::Think( void )
9 years ago
{
4 years ago
#if !NO_VOICEGAMEMGR
8 years ago
g_VoiceGameMgr.Update( gpGlobals->frametime );
#endif
9 years ago
//++ BulliT
if( !AgGameRules::AgThink() )
return;
//-- Martin Webrant
9 years ago
///// Check game rules /////
static int last_frags;
static int last_time;
int frags_remaining = 0;
int time_remaining = 0;
8 years ago
if( g_fGameOver ) // someone else quit the game already
9 years ago
{
// bounds check
int time = (int)CVAR_GET_FLOAT( "mp_chattime" );
8 years ago
if( time < 1 )
9 years ago
CVAR_SET_STRING( "mp_chattime", "1" );
8 years ago
else if( time > MAX_INTERMISSION_TIME )
9 years ago
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
8 years ago
if( m_flIntermissionEndTime < gpGlobals->time )
9 years ago
{
8 years ago
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
//++ BulliT
{
ChangeNextLevel();
}
//-- Martin Webrant
9 years ago
}
return;
}
//++ BulliT
/*
9 years ago
float flTimeLimit = timelimit.value * 60;
float flFragLimit = fraglimit.value;
8 years ago
time_remaining = (int)( flTimeLimit ? ( flTimeLimit - gpGlobals->time ) : 0);
if( flTimeLimit != 0 && gpGlobals->time >= flTimeLimit )
9 years ago
{
GoToIntermission();
return;
}
*/
if( !m_Timer.TimeRemaining( time_remaining ) )
{
if( !m_SuddenDeath.IsSuddenDeath() )
{
//Go intermission.
GoToIntermission();
return;
}
else
{
//Sudden death!
time_remaining = 0;
}
}
float flFragLimit = fraglimit.value;
//-- Martin Webrant
9 years ago
8 years ago
if( flFragLimit )
9 years ago
{
int bestfrags = 9999;
int remain;
// check if any player is over the frag limit
8 years ago
for( int i = 1; i <= gpGlobals->maxClients; i++ )
9 years ago
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex( i );
8 years ago
if( pPlayer && pPlayer->pev->frags >= flFragLimit )
9 years ago
{
GoToIntermission();
return;
}
8 years ago
if( pPlayer )
9 years ago
{
remain = (int)( flFragLimit - pPlayer->pev->frags );
8 years ago
if( remain < bestfrags )
9 years ago
{
bestfrags = remain;
}
}
}
frags_remaining = bestfrags;
}
// Updates when frags change
8 years ago
if( frags_remaining != last_frags )
9 years ago
{
g_engfuncs.pfnCvar_DirectSet( &fragsleft, UTIL_VarArgs( "%i", frags_remaining ) );
}
// Updates once per second
8 years ago
if( timeleft.value != last_time )
9 years ago
{
g_engfuncs.pfnCvar_DirectSet( &timeleft, UTIL_VarArgs( "%i", time_remaining ) );
}
last_frags = frags_remaining;
8 years ago
last_time = time_remaining;
9 years ago
}
//=========================================================
//=========================================================
BOOL CHalfLifeMultiplay::IsMultiplayer( void )
{
return TRUE;
}
//=========================================================
//=========================================================
BOOL CHalfLifeMultiplay::IsDeathmatch( void )
{
return TRUE;
}
//=========================================================
//=========================================================
BOOL CHalfLifeMultiplay::IsCoOp( void )
{
return gpGlobals->coop ? TRUE : FALSE;
9 years ago
}
//=========================================================
//=========================================================
BOOL CHalfLifeMultiplay::FShouldSwitchWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon )
{
//++ BulliT
return AgGameRules::FShouldSwitchWeapon( pPlayer, pWeapon );
//-- Martin Webrant
9 years ago
}
8 years ago
BOOL CHalfLifeMultiplay::GetNextBestWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon )
9 years ago
{
//++ BulliT
return AgGameRules::GetNextBestWeapon( pPlayer, pCurrentWeapon );
//-- Martin Webrant
9 years ago
}
//=========================================================
//=========================================================
8 years ago
BOOL CHalfLifeMultiplay::ClientConnected( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128] )
9 years ago
{
4 years ago
#if !NO_VOICEGAMEMGR
8 years ago
g_VoiceGameMgr.ClientConnected( pEntity );
#endif
return AgGameRules::ClientConnected( pEntity, pszName, pszAddress, szRejectReason );
9 years ago
}
extern int gmsgSayText;
extern int gmsgGameMode;
8 years ago
void CHalfLifeMultiplay::UpdateGameMode( CBasePlayer *pPlayer )
9 years ago
{
MESSAGE_BEGIN( MSG_ONE, gmsgGameMode, NULL, pPlayer->edict() );
WRITE_BYTE( 0 ); // game mode none
MESSAGE_END();
}
8 years ago
void CHalfLifeMultiplay::InitHUD( CBasePlayer *pl )
9 years ago
{
//++ BulliT
AgGameRules::InitHUD( pl );
//-- Martin Webrant
9 years ago
// notify other clients of player joining the game
UTIL_ClientPrintAll( HUD_PRINTNOTIFY, UTIL_VarArgs( "%s has joined the game\n",
( pl->pev->netname && ( STRING( pl->pev->netname ) )[0] != 0 ) ? STRING( pl->pev->netname ) : "unconnected" ) );
9 years ago
// team match?
8 years ago
if( g_teamplay )
9 years ago
{
UTIL_LogPrintf( "\"%s<%i><%s><%s>\" entered the game\n",
STRING( pl->pev->netname ),
GETPLAYERUSERID( pl->edict() ),
GETPLAYERAUTHID( pl->edict() ),
g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( pl->edict() ), "model" ) );
}
else
{
UTIL_LogPrintf( "\"%s<%i><%s><%i>\" entered the game\n",
STRING( pl->pev->netname ),
GETPLAYERUSERID( pl->edict() ),
GETPLAYERAUTHID( pl->edict() ),
GETPLAYERUSERID( pl->edict() ) );
}
UpdateGameMode( pl );
// sending just one score makes the hud scoreboard active; otherwise
// it is just disabled for single play
MESSAGE_BEGIN( MSG_ONE, gmsgScoreInfo, NULL, pl->edict() );
WRITE_BYTE( ENTINDEX(pl->edict()) );
WRITE_SHORT( 0 );
WRITE_SHORT( 0 );
WRITE_SHORT( 0 );
WRITE_SHORT( 0 );
MESSAGE_END();
SendMOTDToClient( pl->edict() );
// loop through all active players and send their score info to the new client
8 years ago
for( int i = 1; i <= gpGlobals->maxClients; i++ )
9 years ago
{
// FIXME: Probably don't need to cast this just to read m_iDeaths
CBasePlayer *plr = (CBasePlayer *)UTIL_PlayerByIndex( i );
8 years ago
if( plr )
9 years ago
{
MESSAGE_BEGIN( MSG_ONE, gmsgScoreInfo, NULL, pl->edict() );
WRITE_BYTE( i ); // client number
WRITE_SHORT( (int)plr->pev->frags );
9 years ago
WRITE_SHORT( plr->m_iDeaths );
WRITE_SHORT( 0 );
WRITE_SHORT( GetTeamIndex( plr->m_szTeamName ) + 1 );
MESSAGE_END();
//++ BulliT
MESSAGE_BEGIN( MSG_ONE, gmsgSpectator, NULL, pl->edict() );
WRITE_BYTE( ENTINDEX( plr->edict() ) );
WRITE_BYTE( plr->IsSpectator() ? 1 : 0 );
MESSAGE_END();
#ifndef AG_NO_CLIENT_DLL
MESSAGE_BEGIN( MSG_ONE, gmsgAuthID, NULL, pl->edict() );
WRITE_BYTE( plr->entindex() );
WRITE_STRING( plr->GetAuthID() );
MESSAGE_END();
#endif
//-- Martin Webrant
9 years ago
}
}
8 years ago
if( g_fGameOver )
9 years ago
{
MESSAGE_BEGIN( MSG_ONE, SVC_INTERMISSION, NULL, pl->edict() );
MESSAGE_END();
}
}
//=========================================================
//=========================================================
8 years ago
void CHalfLifeMultiplay::ClientDisconnected( edict_t *pClient )
9 years ago
{
//++ BulliT
AgGameRules::ClientDisconnected( pClient );
//-- Martin Webrant
8 years ago
if( pClient )
9 years ago
{
CBasePlayer *pPlayer = (CBasePlayer *)CBaseEntity::Instance( pClient );
8 years ago
if( pPlayer )
9 years ago
{
FireTargets( "game_playerleave", pPlayer, pPlayer, USE_TOGGLE, 0 );
// team match?
8 years ago
if( g_teamplay )
9 years ago
{
UTIL_LogPrintf( "\"%s<%i><%s><%s>\" disconnected\n",
STRING( pPlayer->pev->netname ),
GETPLAYERUSERID( pPlayer->edict() ),
GETPLAYERAUTHID( pPlayer->edict() ),
g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "model" ) );
}
else
{
UTIL_LogPrintf( "\"%s<%i><%s><%i>\" disconnected\n",
STRING( pPlayer->pev->netname ),
GETPLAYERUSERID( pPlayer->edict() ),
GETPLAYERAUTHID( pPlayer->edict() ),
GETPLAYERUSERID( pPlayer->edict() ) );
}
pPlayer->RemoveAllItems( TRUE );// destroy all of the players weapons and items
}
}
}
//=========================================================
//=========================================================
8 years ago
float CHalfLifeMultiplay::FlPlayerFallDamage( CBasePlayer *pPlayer )
9 years ago
{
int iFallDamage = (int)falldamage.value;
8 years ago
switch( iFallDamage )
9 years ago
{
8 years ago
case 1:
//progressive
9 years ago
pPlayer->m_flFallVelocity -= PLAYER_MAX_SAFE_FALL_SPEED;
return pPlayer->m_flFallVelocity * DAMAGE_FOR_FALL_SPEED;
break;
default:
8 years ago
case 0:
// fixed
9 years ago
return 10;
break;
}
}
//=========================================================
//=========================================================
BOOL CHalfLifeMultiplay::FPlayerCanTakeDamage( CBasePlayer *pPlayer, CBaseEntity *pAttacker )
{
//++ BulliT
return AgGameRules::FPlayerCanTakeDamage( pPlayer, pAttacker );
//return TRUE;
//-- Martin Webrant
9 years ago
}
//=========================================================
//=========================================================
8 years ago
void CHalfLifeMultiplay::PlayerThink( CBasePlayer *pPlayer )
9 years ago
{
8 years ago
if( g_fGameOver )
9 years ago
{
// check for button presses
8 years ago
if( pPlayer->m_afButtonPressed & ( IN_DUCK | IN_ATTACK | IN_ATTACK2 | IN_USE | IN_JUMP ) )
9 years ago
m_iEndIntermissionButtonHit = TRUE;
// clear attack/use commands from player
pPlayer->m_afButtonPressed = 0;
pPlayer->pev->button = 0;
pPlayer->m_afButtonReleased = 0;
}
}
//=========================================================
//=========================================================
8 years ago
void CHalfLifeMultiplay::PlayerSpawn( CBasePlayer *pPlayer )
9 years ago
{
//++ BulliT
AgGameRules::PlayerSpawn( pPlayer );
return;
//-- Martin Webrant
9 years ago
}
//=========================================================
//=========================================================
8 years ago
BOOL CHalfLifeMultiplay::FPlayerCanRespawn( CBasePlayer *pPlayer )
9 years ago
{
//++ BulliT
return AgGameRules::FPlayerCanRespawn( pPlayer );
//return TRUE;
//-- Martin Webrant
9 years ago
}
//=========================================================
//=========================================================
8 years ago
float CHalfLifeMultiplay::FlPlayerSpawnTime( CBasePlayer *pPlayer )
9 years ago
{
return gpGlobals->time;//now!
}
8 years ago
BOOL CHalfLifeMultiplay::AllowAutoTargetCrosshair( void )
9 years ago
{
return ( aimcrosshair.value != 0 );
}
//=========================================================
// IPointsForKill - how many points awarded to anyone
// that kills this player?
//=========================================================
8 years ago
int CHalfLifeMultiplay::IPointsForKill( CBasePlayer *pAttacker, CBasePlayer *pKilled )
9 years ago
{
//++ BulliT
AgGameRules::IPointsForKill( pAttacker, pKilled );
//-- Martin Webrant
9 years ago
return 1;
}
//=========================================================
// PlayerKilled - someone/something killed this player
//=========================================================
8 years ago
void CHalfLifeMultiplay::PlayerKilled( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor )
9 years ago
{
DeathNotice( pVictim, pKiller, pInflictor );
pVictim->m_iDeaths += 1;
FireTargets( "game_playerdie", pVictim, pVictim, USE_TOGGLE, 0 );
CBasePlayer *peKiller = NULL;
CBaseEntity *ktmp = CBaseEntity::Instance( pKiller );
8 years ago
if( ktmp && (ktmp->Classify() == CLASS_PLAYER ) )
9 years ago
peKiller = (CBasePlayer*)ktmp;
8 years ago
if( pVictim->pev == pKiller )
{
// killed self
9 years ago
pKiller->frags -= 1;
}
8 years ago
else if( ktmp && ktmp->IsPlayer() )
9 years ago
{
// if a player dies in a deathmatch game and the killer is a client, award the killer some points
pKiller->frags += IPointsForKill( peKiller, pVictim );
8 years ago
9 years ago
FireTargets( "game_playerkill", ktmp, ktmp, USE_TOGGLE, 0 );
}
else
{
// killed by the world
//++ BulliT
//pKiller->frags -= 1;
if( pVictim->pev )
pVictim->pev->frags -= 1;
//-- Martin Webrant
9 years ago
}
// update the scores
// killed scores
MESSAGE_BEGIN( MSG_ALL, gmsgScoreInfo );
WRITE_BYTE( ENTINDEX(pVictim->edict()) );
WRITE_SHORT( (int)pVictim->pev->frags );
9 years ago
WRITE_SHORT( pVictim->m_iDeaths );
//++ BulliT
WRITE_SHORT( g_teamplay );
9 years ago
WRITE_SHORT( GetTeamIndex( pVictim->m_szTeamName ) + 1 );
//-- Martin Webrant
9 years ago
MESSAGE_END();
// killers score, if it's a player
CBaseEntity *ep = CBaseEntity::Instance( pKiller );
8 years ago
if( ep && ep->Classify() == CLASS_PLAYER )
9 years ago
{
CBasePlayer *PK = (CBasePlayer*)ep;
MESSAGE_BEGIN( MSG_ALL, gmsgScoreInfo );
8 years ago
WRITE_BYTE( ENTINDEX( PK->edict() ) );
WRITE_SHORT( (int)PK->pev->frags );
9 years ago
WRITE_SHORT( PK->m_iDeaths );
//++ BulliT
WRITE_SHORT( g_teamplay );
8 years ago
WRITE_SHORT( GetTeamIndex( PK->m_szTeamName ) + 1 );
//-- Martin Webrant
9 years ago
MESSAGE_END();
// let the killer paint another decal as soon as he'd like.
PK->m_flNextDecalTime = gpGlobals->time;
}
//++ BulliT
AgGameRules::PlayerKilled( pVictim, pKiller, pInflictor );
//-- Martin Webrant
9 years ago
}
//=========================================================
// Deathnotice.
//=========================================================
void CHalfLifeMultiplay::DeathNotice( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pevInflictor )
{
//++ BulliT
AgGameRules::DeathNotice( pVictim, pKiller, pevInflictor );
//-- Martin Webrant
9 years ago
// Work out what killed the player, and send a message to all clients about it
CBaseEntity::Instance( pKiller );
9 years ago
const char *killer_weapon_name = "world"; // by default, the player is killed by the world
int killer_index = 0;
8 years ago
9 years ago
// Hack to fix name change
const char *tau = "tau_cannon";
const char *gluon = "gluon gun";
9 years ago
if( pevInflictor )
9 years ago
{
if( pKiller->flags & FL_CLIENT )
9 years ago
{
killer_index = ENTINDEX( ENT( pKiller ) );
8 years ago
if( pevInflictor == pKiller )
9 years ago
{
// If the inflictor is the killer, then it must be their current weapon doing the damage
CBasePlayer *pPlayer = (CBasePlayer*)CBaseEntity::Instance( pKiller );
8 years ago
if( pPlayer->m_pActiveItem )
9 years ago
{
killer_weapon_name = pPlayer->m_pActiveItem->pszName();
}
}
else
{
killer_weapon_name = STRING( pevInflictor->classname ); // it's just that easy
}
}
else
{
killer_weapon_name = STRING( pevInflictor->classname );
}
9 years ago
}
// strip the monster_* or weapon_* from the inflictor's classname
8 years ago
if( strncmp( killer_weapon_name, "weapon_", 7 ) == 0 )
9 years ago
killer_weapon_name += 7;
8 years ago
else if( strncmp( killer_weapon_name, "monster_", 8 ) == 0 )
9 years ago
killer_weapon_name += 8;
8 years ago
else if( strncmp( killer_weapon_name, "func_", 5 ) == 0 )
9 years ago
killer_weapon_name += 5;
MESSAGE_BEGIN( MSG_ALL, gmsgDeathMsg );
WRITE_BYTE( killer_index ); // the killer
8 years ago
WRITE_BYTE( ENTINDEX( pVictim->edict() ) ); // the victim
9 years ago
WRITE_STRING( killer_weapon_name ); // what they were killed by (should this be a string?)
MESSAGE_END();
// replace the code names with the 'real' names
8 years ago
if( !strcmp( killer_weapon_name, "egon" ) )
9 years ago
killer_weapon_name = gluon;
8 years ago
else if( !strcmp( killer_weapon_name, "gauss" ) )
9 years ago
killer_weapon_name = tau;
8 years ago
if( pVictim->pev == pKiller )
9 years ago
{
// killed self
// team match?
8 years ago
if( g_teamplay )
9 years ago
{
UTIL_LogPrintf( "\"%s<%i><%s><%s>\" committed suicide with \"%s\"\n",
STRING( pVictim->pev->netname ),
GETPLAYERUSERID( pVictim->edict() ),
GETPLAYERAUTHID( pVictim->edict() ),
g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( pVictim->edict() ), "model" ),
killer_weapon_name );
}
else
{
UTIL_LogPrintf( "\"%s<%i><%s><%i>\" committed suicide with \"%s\"\n",
STRING( pVictim->pev->netname ),
GETPLAYERUSERID( pVictim->edict() ),
GETPLAYERAUTHID( pVictim->edict() ),
GETPLAYERUSERID( pVictim->edict() ),
killer_weapon_name );
}
}
8 years ago
else if( pKiller->flags & FL_CLIENT )
9 years ago
{
// team match?
8 years ago
if( g_teamplay )
9 years ago
{
UTIL_LogPrintf( "\"%s<%i><%s><%s>\" killed \"%s<%i><%s><%s>\" with \"%s\"\n",
STRING( pKiller->netname ),
GETPLAYERUSERID( ENT(pKiller) ),
GETPLAYERAUTHID( ENT(pKiller) ),
g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( ENT(pKiller) ), "model" ),
STRING( pVictim->pev->netname ),
GETPLAYERUSERID( pVictim->edict() ),
GETPLAYERAUTHID( pVictim->edict() ),
g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( pVictim->edict() ), "model" ),
killer_weapon_name );
}
else
{
UTIL_LogPrintf( "\"%s<%i><%s><%i>\" killed \"%s<%i><%s><%i>\" with \"%s\"\n",
STRING( pKiller->netname ),
GETPLAYERUSERID( ENT(pKiller) ),
GETPLAYERAUTHID( ENT(pKiller) ),
GETPLAYERUSERID( ENT(pKiller) ),
STRING( pVictim->pev->netname ),
GETPLAYERUSERID( pVictim->edict() ),
GETPLAYERAUTHID( pVictim->edict() ),
GETPLAYERUSERID( pVictim->edict() ),
killer_weapon_name );
}
}
else
{
// killed by the world
// team match?
8 years ago
if( g_teamplay )
9 years ago
{
UTIL_LogPrintf( "\"%s<%i><%s><%s>\" committed suicide with \"%s\" (world)\n",
STRING( pVictim->pev->netname ),
GETPLAYERUSERID( pVictim->edict() ),
GETPLAYERAUTHID( pVictim->edict() ),
g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( pVictim->edict() ), "model" ),
killer_weapon_name );
}
else
{
UTIL_LogPrintf( "\"%s<%i><%s><%i>\" committed suicide with \"%s\" (world)\n",
STRING( pVictim->pev->netname ),
GETPLAYERUSERID( pVictim->edict() ),
GETPLAYERAUTHID( pVictim->edict() ),
GETPLAYERUSERID( pVictim->edict() ),
killer_weapon_name );
}
}
//++ BulliT
UTIL_SendDirectorMessage( pVictim->edict(), pevInflictor ? ENT( pevInflictor ) : ENT( pKiller ), 7 | DRC_FLAG_DRAMATIC );
/*
9 years ago
MESSAGE_BEGIN( MSG_SPEC, SVC_DIRECTOR );
8 years ago
WRITE_BYTE( 9 ); // command length in bytes
WRITE_BYTE( DRC_CMD_EVENT ); // player killed
WRITE_SHORT( ENTINDEX( pVictim->edict() ) ); // index number of primary entity
if( pevInflictor )
WRITE_SHORT( ENTINDEX( ENT( pevInflictor ) ) ); // index number of secondary entity
9 years ago
else
8 years ago
WRITE_SHORT( ENTINDEX( ENT( pKiller ) ) ); // index number of secondary entity
WRITE_LONG( 7 | DRC_FLAG_DRAMATIC ); // eventflags (priority and flags)
9 years ago
MESSAGE_END();
*/
//-- Martin Webrant
9 years ago
// Print a standard message
// TODO: make this go direct to console
return; // just remove for now
/*
8 years ago
char szText[128];
9 years ago
8 years ago
if( pKiller->flags & FL_MONSTER )
9 years ago
{
// killed by a monster
8 years ago
strcpy( szText, STRING( pVictim->pev->netname ) );
strcat( szText, " was killed by a monster.\n" );
9 years ago
return;
}
8 years ago
if( pKiller == pVictim->pev )
9 years ago
{
8 years ago
strcpy( szText, STRING( pVictim->pev->netname ) );
strcat( szText, " commited suicide.\n" );
9 years ago
}
8 years ago
else if( pKiller->flags & FL_CLIENT )
9 years ago
{
8 years ago
strcpy( szText, STRING( pKiller->netname ) );
9 years ago
strcat( szText, " : " );
strcat( szText, killer_weapon_name );
strcat( szText, " : " );
8 years ago
strcat( szText, STRING( pVictim->pev->netname ) );
strcat( szText, "\n" );
9 years ago
}
8 years ago
else if( FClassnameIs( pKiller, "worldspawn" ) )
9 years ago
{
8 years ago
strcpy( szText, STRING( pVictim->pev->netname ) );
strcat( szText, " fell or drowned or something.\n" );
9 years ago
}
8 years ago
else if( pKiller->solid == SOLID_BSP )
9 years ago
{
8 years ago
strcpy( szText, STRING( pVictim->pev->netname ) );
strcat( szText, " was mooshed.\n" );
9 years ago
}
else
{
8 years ago
strcpy( szText, STRING( pVictim->pev->netname ) );
strcat( szText, " died mysteriously.\n" );
9 years ago
}
UTIL_ClientPrintAll( szText );
*/
}
//=========================================================
// PlayerGotWeapon - player has grabbed a weapon that was
// sitting in the world
//=========================================================
8 years ago
void CHalfLifeMultiplay::PlayerGotWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon )
9 years ago
{
}
//=========================================================
// FlWeaponRespawnTime - what is the time in the future
// at which this weapon may spawn?
//=========================================================
8 years ago
float CHalfLifeMultiplay::FlWeaponRespawnTime( CBasePlayerItem *pWeapon )
9 years ago
{
8 years ago
if( weaponstay.value > 0 )
9 years ago
{
// make sure it's only certain weapons
8 years ago
if( !(pWeapon->iFlags() & ITEM_FLAG_LIMITINWORLD ) )
9 years ago
{
return gpGlobals->time + 0; // weapon respawns almost instantly
}
}
return gpGlobals->time + WEAPON_RESPAWN_TIME;
}
// when we are within this close to running out of entities, items
// marked with the ITEM_FLAG_LIMITINWORLD will delay their respawn
#define ENTITY_INTOLERANCE 100
//=========================================================
// FlWeaponRespawnTime - Returns 0 if the weapon can respawn
// now, otherwise it returns the time at which it can try
// to spawn again.
//=========================================================
8 years ago
float CHalfLifeMultiplay::FlWeaponTryRespawn( CBasePlayerItem *pWeapon )
9 years ago
{
8 years ago
if( pWeapon && pWeapon->m_iId && ( pWeapon->iFlags() & ITEM_FLAG_LIMITINWORLD ) )
9 years ago
{
8 years ago
if( NUMBER_OF_ENTITIES() < ( gpGlobals->maxEntities - ENTITY_INTOLERANCE ) )
9 years ago
return 0;
// we're past the entity tolerance level, so delay the respawn
return FlWeaponRespawnTime( pWeapon );
}
return 0;
}
//=========================================================
// VecWeaponRespawnSpot - where should this weapon spawn?
// Some game variations may choose to randomize spawn locations
//=========================================================
8 years ago
Vector CHalfLifeMultiplay::VecWeaponRespawnSpot( CBasePlayerItem *pWeapon )
9 years ago
{
return pWeapon->pev->origin;
}
//=========================================================
// WeaponShouldRespawn - any conditions inhibiting the
// respawning of this weapon?
//=========================================================
8 years ago
int CHalfLifeMultiplay::WeaponShouldRespawn( CBasePlayerItem *pWeapon )
9 years ago
{
8 years ago
if( pWeapon->pev->spawnflags & SF_NORESPAWN )
9 years ago
{
return GR_WEAPON_RESPAWN_NO;
}
return GR_WEAPON_RESPAWN_YES;
}
//=========================================================
// CanHaveWeapon - returns FALSE if the player is not allowed
// to pick up this weapon
//=========================================================
BOOL CHalfLifeMultiplay::CanHavePlayerItem( CBasePlayer *pPlayer, CBasePlayerItem *pItem )
{
8 years ago
if( weaponstay.value > 0 )
9 years ago
{
8 years ago
if( pItem->iFlags() & ITEM_FLAG_LIMITINWORLD )
//++ BulliT
return AgGameRules::CanHavePlayerItem( pPlayer, pItem );
//-- Martin Webrant
9 years ago
// check if the player already has this weapon
8 years ago
for( int i = 0; i < MAX_ITEM_TYPES; i++ )
9 years ago
{
CBasePlayerItem *it = pPlayer->m_rgpPlayerItems[i];
8 years ago
while( it != NULL )
9 years ago
{
8 years ago
if( it->m_iId == pItem->m_iId )
9 years ago
{
return FALSE;
}
it = it->m_pNext;
}
}
}
//++ BulliT
return AgGameRules::CanHavePlayerItem( pPlayer, pItem );
//-- Martin Webrant
9 years ago
}
//=========================================================
//=========================================================
BOOL CHalfLifeMultiplay::CanHaveItem( CBasePlayer *pPlayer, CItem *pItem )
{
//++ BulliT
return AgGameRules::CanHaveItem( pPlayer, pItem );
//-- Martin Webrant
9 years ago
}
//=========================================================
//=========================================================
void CHalfLifeMultiplay::PlayerGotItem( CBasePlayer *pPlayer, CItem *pItem )
{
}
//=========================================================
//=========================================================
int CHalfLifeMultiplay::ItemShouldRespawn( CItem *pItem )
{
8 years ago
if( pItem->pev->spawnflags & SF_NORESPAWN )
9 years ago
{
return GR_ITEM_RESPAWN_NO;
}
return GR_ITEM_RESPAWN_YES;
}
//=========================================================
// At what time in the future may this Item respawn?
//=========================================================
float CHalfLifeMultiplay::FlItemRespawnTime( CItem *pItem )
{
return gpGlobals->time + ITEM_RESPAWN_TIME;
}
//=========================================================
// Where should this item respawn?
// Some game variations may choose to randomize spawn locations
//=========================================================
Vector CHalfLifeMultiplay::VecItemRespawnSpot( CItem *pItem )
{
return pItem->pev->origin;
}
//=========================================================
//=========================================================
void CHalfLifeMultiplay::PlayerGotAmmo( CBasePlayer *pPlayer, char *szName, int iCount )
{
}
//=========================================================
//=========================================================
BOOL CHalfLifeMultiplay::IsAllowedToSpawn( CBaseEntity *pEntity )
{
//++ BulliT
return AgGameRules::IsAllowedToSpawn( pEntity );
//-- Martin Webrant
8 years ago
// if( pEntity->pev->flags & FL_MONSTER )
9 years ago
// return FALSE;
// return TRUE;
9 years ago
}
//=========================================================
//=========================================================
int CHalfLifeMultiplay::AmmoShouldRespawn( CBasePlayerAmmo *pAmmo )
{
8 years ago
if( pAmmo->pev->spawnflags & SF_NORESPAWN )
9 years ago
{
return GR_AMMO_RESPAWN_NO;
}
return GR_AMMO_RESPAWN_YES;
}
//=========================================================
//=========================================================
float CHalfLifeMultiplay::FlAmmoRespawnTime( CBasePlayerAmmo *pAmmo )
{
return gpGlobals->time + AMMO_RESPAWN_TIME;
}
//=========================================================
//=========================================================
Vector CHalfLifeMultiplay::VecAmmoRespawnSpot( CBasePlayerAmmo *pAmmo )
{
return pAmmo->pev->origin;
}
//=========================================================
//=========================================================
float CHalfLifeMultiplay::FlHealthChargerRechargeTime( void )
{
return 60;
}
float CHalfLifeMultiplay::FlHEVChargerRechargeTime( void )
{
return 30;
}
//=========================================================
//=========================================================
int CHalfLifeMultiplay::DeadPlayerWeapons( CBasePlayer *pPlayer )
{
//++ BulliT
return AgGameRules::DeadPlayerWeapons( pPlayer );
//-- Martin Webrant
9 years ago
}
//=========================================================
//=========================================================
int CHalfLifeMultiplay::DeadPlayerAmmo( CBasePlayer *pPlayer )
{
//++ BulliT
return AgGameRules::DeadPlayerAmmo( pPlayer );
//-- Martin Webrant
9 years ago
}
edict_t *CHalfLifeMultiplay::GetPlayerSpawnSpot( CBasePlayer *pPlayer )
{
edict_t *pentSpawnSpot = CGameRules::GetPlayerSpawnSpot( pPlayer );
8 years ago
if( IsMultiplayer() && pentSpawnSpot->v.target )
9 years ago
{
8 years ago
FireTargets( STRING( pentSpawnSpot->v.target ), pPlayer, pPlayer, USE_TOGGLE, 0 );
9 years ago
}
return pentSpawnSpot;
}
//=========================================================
//=========================================================
int CHalfLifeMultiplay::PlayerRelationship( CBaseEntity *pPlayer, CBaseEntity *pTarget )
{
// half life deathmatch has only enemies
return GR_NOTTEAMMATE;
}
8 years ago
BOOL CHalfLifeMultiplay::PlayFootstepSounds( CBasePlayer *pl, float fvol )
9 years ago
{
8 years ago
if( g_footsteps && g_footsteps->value == 0 )
9 years ago
return FALSE;
8 years ago
if( pl->IsOnLadder() || pl->pev->velocity.Length2D() > 220 )
9 years ago
return TRUE; // only make step sounds in multiplayer if the player is moving fast enough
return FALSE;
}
8 years ago
BOOL CHalfLifeMultiplay::FAllowFlashlight( void )
{
9 years ago
return flashlight.value != 0;
}
//=========================================================
//=========================================================
8 years ago
BOOL CHalfLifeMultiplay::FAllowMonsters( void )
9 years ago
{
return ( allowmonsters.value != 0 );
}
//=========================================================
//======== CHalfLifeMultiplay private functions ===========
#define INTERMISSION_TIME 6
8 years ago
void CHalfLifeMultiplay::GoToIntermission( void )
9 years ago
{
8 years ago
if( g_fGameOver )
9 years ago
return; // intermission has already been triggered, so ignore.
//++ BulliT
AgGameRules::GoToIntermission();
//-- Martin Webrant
8 years ago
MESSAGE_BEGIN( MSG_ALL, SVC_INTERMISSION );
9 years ago
MESSAGE_END();
// bounds check
int time = (int)CVAR_GET_FLOAT( "mp_chattime" );
8 years ago
if( time < 1 )
9 years ago
CVAR_SET_STRING( "mp_chattime", "1" );
8 years ago
else if( time > MAX_INTERMISSION_TIME )
9 years ago
CVAR_SET_STRING( "mp_chattime", UTIL_dtos1( MAX_INTERMISSION_TIME ) );
m_flIntermissionEndTime = gpGlobals->time + ( (int)mp_chattime.value );
g_flIntermissionStartTime = gpGlobals->time;
g_fGameOver = TRUE;
m_iEndIntermissionButtonHit = FALSE;
}
#define MAX_RULE_BUFFER 1024
typedef struct mapcycle_item_s
{
struct mapcycle_item_s *next;
8 years ago
char mapname[32];
int minplayers, maxplayers;
char rulebuffer[MAX_RULE_BUFFER];
9 years ago
} mapcycle_item_t;
typedef struct mapcycle_s
{
struct mapcycle_item_s *items;
struct mapcycle_item_s *next_item;
} mapcycle_t;
/*
==============
DestroyMapCycle
Clean up memory used by mapcycle when switching it
==============
*/
void DestroyMapCycle( mapcycle_t *cycle )
{
mapcycle_item_t *p, *n, *start;
p = cycle->items;
8 years ago
if( p )
9 years ago
{
start = p;
p = p->next;
8 years ago
while( p != start )
9 years ago
{
n = p->next;
delete p;
p = n;
}
delete cycle->items;
}
cycle->items = NULL;
cycle->next_item = NULL;
}
8 years ago
static char com_token[1500];
9 years ago
/*
==============
COM_Parse
Parse a token out of a string
==============
*/
const char *COM_Parse( const char *data )
9 years ago
{
8 years ago
int c;
int len;
9 years ago
len = 0;
com_token[0] = 0;
8 years ago
if( !data )
9 years ago
return NULL;
9 years ago
// skip whitespace
skipwhite:
8 years ago
while( ( c = *data ) <= ' ')
9 years ago
{
8 years ago
if( c == 0 )
9 years ago
return NULL; // end of file;
data++;
}
// skip // comments
8 years ago
if( c=='/' && data[1] == '/' )
9 years ago
{
8 years ago
while( *data && *data != '\n' )
9 years ago
data++;
goto skipwhite;
}
// handle quoted strings specially
8 years ago
if( c == '\"' )
9 years ago
{
data++;
8 years ago
while( 1 )
9 years ago
{
c = *data++;
8 years ago
if( c=='\"' || !c )
9 years ago
{
com_token[len] = 0;
return data;
}
com_token[len] = c;
len++;
}
}
// parse single characters
8 years ago
if( c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c == ',' )
9 years ago
{
com_token[len] = c;
len++;
com_token[len] = 0;
8 years ago
return data + 1;
9 years ago
}
// parse a regular word
9 years ago
do
{
com_token[len] = c;
data++;
len++;
c = *data;
8 years ago
if( c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c == ',' )
9 years ago
break;
8 years ago
} while ( c > 32 );
9 years ago
com_token[len] = 0;
return data;
}
/*
==============
COM_TokenWaiting
Returns 1 if additional data is waiting to be processed on this line
==============
*/
int COM_TokenWaiting( const char *buffer )
9 years ago
{
const char *p;
9 years ago
p = buffer;
8 years ago
while( *p && *p!='\n')
9 years ago
{
8 years ago
if( !isspace( *p ) || isalnum( *p ) )
9 years ago
return 1;
p++;
}
return 0;
}
/*
==============
ReloadMapCycleFile
Parses mapcycle.txt file into mapcycle_t structure
==============
*/
int ReloadMapCycleFile( const char *filename, mapcycle_t *cycle )
9 years ago
{
8 years ago
char szMap[32];
9 years ago
int length;
const char *pFileList;
const char *aFileList = pFileList = (const char *)LOAD_FILE_FOR_ME( filename, &length );
9 years ago
int hasbuffer;
mapcycle_item_s *item, *newlist = NULL, *next;
8 years ago
if( pFileList && length )
9 years ago
{
// the first map name in the file becomes the default
8 years ago
while( 1 )
9 years ago
{
char szBuffer[MAX_RULE_BUFFER] = {0};
9 years ago
hasbuffer = 0;
pFileList = COM_Parse( pFileList );
if( com_token[0] == '\0' )
9 years ago
break;
strcpy( szMap, com_token );
// Any more tokens on this line?
8 years ago
if( COM_TokenWaiting( pFileList ) )
9 years ago
{
pFileList = COM_Parse( pFileList );
if( com_token[0] != '\0' )
9 years ago
{
hasbuffer = 1;
strcpy( szBuffer, com_token );
}
}
// Check map
8 years ago
if( IS_MAP_VALID( szMap ) )
9 years ago
{
// Create entry
char *s;
item = new mapcycle_item_s;
strcpy( item->mapname, szMap );
item->minplayers = 0;
item->maxplayers = 0;
memset( item->rulebuffer, 0, MAX_RULE_BUFFER );
8 years ago
if( hasbuffer )
9 years ago
{
s = g_engfuncs.pfnInfoKeyValue( szBuffer, "minplayers" );
8 years ago
if( s && s[0] )
9 years ago
{
item->minplayers = atoi( s );
item->minplayers = Q_max( item->minplayers, 0 );
item->minplayers = Q_min( item->minplayers, gpGlobals->maxClients );
9 years ago
}
s = g_engfuncs.pfnInfoKeyValue( szBuffer, "maxplayers" );
8 years ago
if( s && s[0] )
9 years ago
{
item->maxplayers = atoi( s );
item->maxplayers = Q_max( item->maxplayers, 0 );
item->maxplayers = Q_min( item->maxplayers, gpGlobals->maxClients );
9 years ago
}
// Remove keys
//
g_engfuncs.pfnInfo_RemoveKey( szBuffer, "minplayers" );
g_engfuncs.pfnInfo_RemoveKey( szBuffer, "maxplayers" );
strcpy( item->rulebuffer, szBuffer );
}
item->next = cycle->items;
cycle->items = item;
}
else
{
ALERT( at_console, "Skipping %s from mapcycle, not a valid map\n", szMap );
}
}
FREE_FILE( (void*)aFileList );
9 years ago
}
// Fixup circular list pointer
item = cycle->items;
// Reverse it to get original order
8 years ago
while( item )
9 years ago
{
next = item->next;
item->next = newlist;
newlist = item;
item = next;
}
cycle->items = newlist;
item = cycle->items;
// Didn't parse anything
8 years ago
if( !item )
9 years ago
{
return 0;
}
8 years ago
while( item->next )
9 years ago
{
item = item->next;
}
item->next = cycle->items;
9 years ago
cycle->next_item = item->next;
return 1;
}
/*
==============
CountPlayers
Determine the current # of active players on the server for map cycling logic
==============
*/
int CountPlayers( void )
{
8 years ago
int num = 0;
9 years ago
8 years ago
for( int i = 1; i <= gpGlobals->maxClients; i++ )
9 years ago
{
CBaseEntity *pEnt = UTIL_PlayerByIndex( i );
8 years ago
if( pEnt )
9 years ago
{
num = num + 1;
}
}
return num;
}
/*
==============
ExtractCommandString
Parse commands/key value pairs to issue right after map xxx command is issued on server
level transition
==============
*/
void ExtractCommandString( char *s, char *szCommand )
{
// Now make rules happen
8 years ago
char pkey[512];
char value[512]; // use two buffers so compares
// work without stomping on each other
8 years ago
char *o;
9 years ago
8 years ago
if( *s == '\\' )
9 years ago
s++;
8 years ago
while( 1 )
9 years ago
{
o = pkey;
8 years ago
while( *s != '\\' )
9 years ago
{
if ( !*s )
return;
*o++ = *s++;
}
*o = 0;
s++;
o = value;
8 years ago
while( *s != '\\' && *s )
9 years ago
{
8 years ago
if( !*s )
9 years ago
return;
*o++ = *s++;
}
*o = 0;
strcat( szCommand, pkey );
if( value[0] != '\0' )
9 years ago
{
strcat( szCommand, " " );
strcat( szCommand, value );
}
strcat( szCommand, "\n" );
8 years ago
if( !*s )
9 years ago
return;
s++;
}
}
/*
==============
ChangeLevel
Server is changing to a new level, check mapcycle.txt for map name and setup info
==============
*/
8 years ago
void CHalfLifeMultiplay::ChangeLevel( void )
9 years ago
{
8 years ago
static char szPreviousMapCycleFile[256];
9 years ago
static mapcycle_t mapcycle;
char szNextMap[32];
char szFirstMapInList[32];
8 years ago
char szCommands[1500];
char szRules[1500];
9 years ago
int minplayers = 0, maxplayers = 0;
strcpy( szFirstMapInList, "hldm1" ); // the absolute default level is hldm1
8 years ago
int curplayers;
9 years ago
BOOL do_cycle = TRUE;
// find the map to change to
const char *mapcfile = CVAR_GET_STRING( "mapcyclefile" );
9 years ago
ASSERT( mapcfile != NULL );
8 years ago
szCommands[0] = '\0';
szRules[0] = '\0';
9 years ago
curplayers = CountPlayers();
// Has the map cycle filename changed?
8 years ago
if( stricmp( mapcfile, szPreviousMapCycleFile ) )
9 years ago
{
strcpy( szPreviousMapCycleFile, mapcfile );
DestroyMapCycle( &mapcycle );
8 years ago
if( !ReloadMapCycleFile( mapcfile, &mapcycle ) || ( !mapcycle.items ) )
9 years ago
{
ALERT( at_console, "Unable to load map cycle file %s\n", mapcfile );
do_cycle = FALSE;
}
}
8 years ago
if( do_cycle && mapcycle.items )
9 years ago
{
BOOL keeplooking = FALSE;
BOOL found = FALSE;
mapcycle_item_s *item;
// Assume current map
8 years ago
strcpy( szNextMap, STRING( gpGlobals->mapname ) );
strcpy( szFirstMapInList, STRING( gpGlobals->mapname ) );
9 years ago
// Traverse list
8 years ago
for( item = mapcycle.next_item; item->next != mapcycle.next_item; item = item->next )
9 years ago
{
keeplooking = FALSE;
ASSERT( item != NULL );
8 years ago
if( item->minplayers != 0 )
9 years ago
{
8 years ago
if( curplayers >= item->minplayers )
9 years ago
{
found = TRUE;
minplayers = item->minplayers;
}
else
{
keeplooking = TRUE;
}
}
8 years ago
if( item->maxplayers != 0 )
9 years ago
{
8 years ago
if( curplayers <= item->maxplayers )
9 years ago
{
found = TRUE;
maxplayers = item->maxplayers;
}
else
{
keeplooking = TRUE;
}
}
8 years ago
if( keeplooking )
9 years ago
continue;
found = TRUE;
break;
}
8 years ago
if( !found )
9 years ago
{
item = mapcycle.next_item;
8 years ago
}
9 years ago
// Increment next item pointer
mapcycle.next_item = item->next;
// Perform logic on current item
strcpy( szNextMap, item->mapname );
ExtractCommandString( item->rulebuffer, szCommands );
strcpy( szRules, item->rulebuffer );
}
8 years ago
if( !IS_MAP_VALID( szNextMap ) )
9 years ago
{
strcpy( szNextMap, szFirstMapInList );
}
g_fGameOver = TRUE;
ALERT( at_console, "CHANGE LEVEL: %s\n", szNextMap );
8 years ago
if( minplayers || maxplayers )
9 years ago
{
ALERT( at_console, "PLAYER COUNT: min %i max %i current %i\n", minplayers, maxplayers, curplayers );
}
5 years ago
if( szRules[0] != '\0' )
9 years ago
{
ALERT( at_console, "RULES: %s\n", szRules );
}
8 years ago
9 years ago
CHANGE_LEVEL( szNextMap, NULL );
if( szCommands[0] != '\0' )
9 years ago
{
SERVER_COMMAND( szCommands );
}
}
#define MAX_MOTD_CHUNK 60
#define MAX_MOTD_LENGTH 1536 // (MAX_MOTD_CHUNK * 4)
8 years ago
void CHalfLifeMultiplay::SendMOTDToClient( edict_t *client )
9 years ago
{
// read from the MOTD.txt file
int length, char_count = 0;
char *pFileList;
char *aFileList = pFileList = (char*)LOAD_FILE_FOR_ME( CVAR_GET_STRING( "motdfile" ), &length );
9 years ago
// send the server name
MESSAGE_BEGIN( MSG_ONE, gmsgServerName, NULL, client );
8 years ago
WRITE_STRING( CVAR_GET_STRING( "hostname" ) );
9 years ago
MESSAGE_END();
// Send the message of the day
// read it chunk-by-chunk, and send it in parts
8 years ago
while( pFileList && *pFileList && char_count < MAX_MOTD_LENGTH )
9 years ago
{
8 years ago
char chunk[MAX_MOTD_CHUNK + 1];
8 years ago
if( strlen( pFileList ) < MAX_MOTD_CHUNK )
9 years ago
{
strcpy( chunk, pFileList );
}
else
{
strncpy( chunk, pFileList, MAX_MOTD_CHUNK );
chunk[MAX_MOTD_CHUNK] = 0; // strncpy doesn't always append the null terminator
}
char_count += strlen( chunk );
8 years ago
if( char_count < MAX_MOTD_LENGTH )
9 years ago
pFileList = aFileList + char_count;
else
*pFileList = 0;
MESSAGE_BEGIN( MSG_ONE, gmsgMOTD, NULL, client );
WRITE_BYTE( *pFileList ? FALSE : TRUE ); // FALSE means there is still more message to come
WRITE_STRING( chunk );
MESSAGE_END();
}
FREE_FILE( (void*)aFileList );
9 years ago
}