2008-09-23 07:43:41 +00:00
# include <new>
2010-07-29 05:21:18 +00:00
# include <string.h>
2010-05-29 07:25:38 +00:00
# include <base/math.h>
# include <engine/shared/config.h>
2010-07-29 05:21:18 +00:00
# include <engine/server/server.h>
2010-05-29 07:25:38 +00:00
# include <engine/map.h>
# include <engine/console.h>
# include "gamecontext.h"
# include <game/version.h>
# include <game/collision.h>
# include <game/gamecore.h>
2010-07-29 14:53:25 +00:00
# include "gamemodes/DDRace.h"
2008-08-14 18:42:47 +00:00
2010-05-29 07:25:38 +00:00
enum
{
RESET ,
NO_RESET
} ;
2008-08-14 18:42:47 +00:00
2010-05-29 07:25:38 +00:00
void CGameContext : : Construct ( int Resetting )
2008-08-14 18:42:47 +00:00
{
2010-05-29 07:25:38 +00:00
m_Resetting = 0 ;
m_pServer = 0 ;
2008-09-23 07:43:41 +00:00
for ( int i = 0 ; i < MAX_CLIENTS ; i + + )
2010-05-29 07:25:38 +00:00
m_apPlayers [ i ] = 0 ;
2009-01-12 21:44:13 +00:00
2010-05-29 07:25:38 +00:00
m_pController = 0 ;
m_VoteCloseTime = 0 ;
m_pVoteOptionFirst = 0 ;
m_pVoteOptionLast = 0 ;
if ( Resetting = = NO_RESET )
m_pVoteOptionHeap = new CHeap ( ) ;
2010-07-29 05:21:18 +00:00
//m_Cheats = g_Config.m_SvCheats;
2010-05-29 07:25:38 +00:00
}
CGameContext : : CGameContext ( int Resetting )
{
Construct ( Resetting ) ;
}
CGameContext : : CGameContext ( )
{
Construct ( NO_RESET ) ;
2008-09-23 07:43:41 +00:00
}
2010-05-29 07:25:38 +00:00
CGameContext : : ~ CGameContext ( )
2008-09-23 07:43:41 +00:00
{
2008-09-24 09:03:49 +00:00
for ( int i = 0 ; i < MAX_CLIENTS ; i + + )
2010-05-29 07:25:38 +00:00
delete m_apPlayers [ i ] ;
if ( ! m_Resetting )
delete m_pVoteOptionHeap ;
2008-08-14 18:42:47 +00:00
}
2010-05-29 07:25:38 +00:00
void CGameContext : : Clear ( )
2008-08-14 18:42:47 +00:00
{
2010-05-29 07:25:38 +00:00
CHeap * pVoteOptionHeap = m_pVoteOptionHeap ;
CVoteOption * pVoteOptionFirst = m_pVoteOptionFirst ;
CVoteOption * pVoteOptionLast = m_pVoteOptionLast ;
CTuningParams Tuning = m_Tuning ;
2010-07-29 05:21:18 +00:00
//bool cheats = m_Cheats;
2010-05-29 07:25:38 +00:00
m_Resetting = true ;
this - > ~ CGameContext ( ) ;
2008-09-23 07:43:41 +00:00
mem_zero ( this , sizeof ( * this ) ) ;
2010-05-29 07:25:38 +00:00
new ( this ) CGameContext ( RESET ) ;
2010-07-29 05:21:18 +00:00
//this->m_Cheats = cheats;
2010-05-29 07:25:38 +00:00
m_pVoteOptionHeap = pVoteOptionHeap ;
m_pVoteOptionFirst = pVoteOptionFirst ;
m_pVoteOptionLast = pVoteOptionLast ;
m_Tuning = Tuning ;
2008-08-14 18:42:47 +00:00
}
2010-05-29 07:25:38 +00:00
class CCharacter * CGameContext : : GetPlayerChar ( int ClientId )
2008-10-20 23:00:46 +00:00
{
2010-05-29 07:25:38 +00:00
if ( ClientId < 0 | | ClientId > = MAX_CLIENTS | | ! m_apPlayers [ ClientId ] )
2008-10-20 23:00:46 +00:00
return 0 ;
2010-05-29 07:25:38 +00:00
return m_apPlayers [ ClientId ] - > GetCharacter ( ) ;
2008-10-20 23:00:46 +00:00
}
2010-05-29 07:25:38 +00:00
void CGameContext : : CreateDamageInd ( vec2 p , float Angle , int Amount )
2008-08-14 18:42:47 +00:00
{
2010-05-29 07:25:38 +00:00
float a = 3 * 3.14159f / 2 + Angle ;
2008-08-14 18:42:47 +00:00
//float a = get_angle(dir);
float s = a - pi / 3 ;
float e = a + pi / 3 ;
2010-05-29 07:25:38 +00:00
for ( int i = 0 ; i < Amount ; i + + )
2008-08-14 18:42:47 +00:00
{
2010-05-29 07:25:38 +00:00
float f = mix ( s , e , float ( i + 1 ) / float ( Amount + 2 ) ) ;
NETEVENT_DAMAGEIND * ev = ( NETEVENT_DAMAGEIND * ) m_Events . Create ( NETEVENTTYPE_DAMAGEIND , sizeof ( NETEVENT_DAMAGEIND ) ) ;
2008-08-14 18:42:47 +00:00
if ( ev )
{
2010-05-29 07:25:38 +00:00
ev - > m_X = ( int ) p . x ;
ev - > m_Y = ( int ) p . y ;
ev - > m_Angle = ( int ) ( f * 256.0f ) ;
2008-08-14 18:42:47 +00:00
}
}
}
2010-05-29 07:25:38 +00:00
void CGameContext : : CreateHammerHit ( vec2 p )
2008-10-17 11:23:21 +00:00
{
// create the event
2010-05-29 07:25:38 +00:00
NETEVENT_HAMMERHIT * ev = ( NETEVENT_HAMMERHIT * ) m_Events . Create ( NETEVENTTYPE_HAMMERHIT , sizeof ( NETEVENT_HAMMERHIT ) ) ;
2008-10-17 11:23:21 +00:00
if ( ev )
{
2010-05-29 07:25:38 +00:00
ev - > m_X = ( int ) p . x ;
ev - > m_Y = ( int ) p . y ;
2008-10-17 11:23:21 +00:00
}
}
2010-05-29 07:25:38 +00:00
void CGameContext : : CreateExplosion ( vec2 p , int Owner , int Weapon , bool NoDamage )
2008-08-14 18:42:47 +00:00
{
// create the event
2010-05-29 07:25:38 +00:00
NETEVENT_EXPLOSION * ev = ( NETEVENT_EXPLOSION * ) m_Events . Create ( NETEVENTTYPE_EXPLOSION , sizeof ( NETEVENT_EXPLOSION ) ) ;
2008-08-14 18:42:47 +00:00
if ( ev )
{
2010-05-29 07:25:38 +00:00
ev - > m_X = ( int ) p . x ;
ev - > m_Y = ( int ) p . y ;
2008-08-14 18:42:47 +00:00
}
2010-05-29 07:25:38 +00:00
if ( ! NoDamage )
2008-08-14 18:42:47 +00:00
{
// deal damage
2010-05-29 07:25:38 +00:00
CCharacter * apEnts [ 64 ] ;
float Radius = 135.0f ;
float InnerRadius = 48.0f ;
int Num = m_World . FindEntities ( p , Radius , ( CEntity * * ) apEnts , 64 , NETOBJTYPE_CHARACTER ) ;
for ( int i = 0 ; i < Num ; i + + )
2008-08-14 18:42:47 +00:00
{
2010-05-29 07:25:38 +00:00
vec2 Diff = apEnts [ i ] - > m_Pos - p ;
vec2 ForceDir ( 0 , 1 ) ;
float l = length ( Diff ) ;
2008-08-14 18:42:47 +00:00
if ( l )
2010-05-29 07:25:38 +00:00
ForceDir = normalize ( Diff ) ;
l = 1 - clamp ( ( l - InnerRadius ) / ( Radius - InnerRadius ) , 0.0f , 1.0f ) ;
float Dmg = 6 * l ;
if ( ( int ) Dmg )
2010-07-29 05:21:18 +00:00
if ( g_Config . m_SvHit | | Owner = = apEnts [ i ] - > m_pPlayer - > GetCID ( ) ) {
apEnts [ i ] - > TakeDamage ( ForceDir * Dmg * 2 , ( int ) Dmg , Owner , Weapon ) ;
if ( ! g_Config . m_SvHit ) break ;
}
2008-08-14 18:42:47 +00:00
}
}
}
/*
void create_smoke ( vec2 p )
{
// create the event
EV_EXPLOSION * ev = ( EV_EXPLOSION * ) events . create ( EVENT_SMOKE , sizeof ( EV_EXPLOSION ) ) ;
if ( ev )
{
ev - > x = ( int ) p . x ;
ev - > y = ( int ) p . y ;
}
} */
2010-05-29 07:25:38 +00:00
void CGameContext : : CreatePlayerSpawn ( vec2 p )
2008-08-14 18:42:47 +00:00
{
// create the event
2010-05-29 07:25:38 +00:00
NETEVENT_SPAWN * ev = ( NETEVENT_SPAWN * ) m_Events . Create ( NETEVENTTYPE_SPAWN , sizeof ( NETEVENT_SPAWN ) ) ;
2008-08-14 18:42:47 +00:00
if ( ev )
{
2010-05-29 07:25:38 +00:00
ev - > m_X = ( int ) p . x ;
ev - > m_Y = ( int ) p . y ;
2008-08-14 18:42:47 +00:00
}
}
2010-05-29 07:25:38 +00:00
void CGameContext : : CreateDeath ( vec2 p , int ClientId )
2008-08-14 18:42:47 +00:00
{
// create the event
2010-05-29 07:25:38 +00:00
NETEVENT_DEATH * ev = ( NETEVENT_DEATH * ) m_Events . Create ( NETEVENTTYPE_DEATH , sizeof ( NETEVENT_DEATH ) ) ;
2008-08-14 18:42:47 +00:00
if ( ev )
{
2010-05-29 07:25:38 +00:00
ev - > m_X = ( int ) p . x ;
ev - > m_Y = ( int ) p . y ;
ev - > m_ClientId = ClientId ;
2008-08-14 18:42:47 +00:00
}
}
2010-05-29 07:25:38 +00:00
void CGameContext : : CreateSound ( vec2 Pos , int Sound , int Mask )
2008-08-14 18:42:47 +00:00
{
2010-05-29 07:25:38 +00:00
if ( Sound < 0 )
2008-08-14 18:42:47 +00:00
return ;
// create a sound
2010-05-29 07:25:38 +00:00
NETEVENT_SOUNDWORLD * ev = ( NETEVENT_SOUNDWORLD * ) m_Events . Create ( NETEVENTTYPE_SOUNDWORLD , sizeof ( NETEVENT_SOUNDWORLD ) , Mask ) ;
2008-08-14 18:42:47 +00:00
if ( ev )
{
2010-05-29 07:25:38 +00:00
ev - > m_X = ( int ) Pos . x ;
ev - > m_Y = ( int ) Pos . y ;
ev - > m_SoundId = Sound ;
2008-08-14 18:42:47 +00:00
}
}
2010-05-29 07:25:38 +00:00
void CGameContext : : CreateSoundGlobal ( int Sound , int Target )
2008-08-14 18:42:47 +00:00
{
2010-05-29 07:25:38 +00:00
if ( Sound < 0 )
2008-08-14 18:42:47 +00:00
return ;
2010-05-29 07:25:38 +00:00
CNetMsg_Sv_SoundGlobal Msg ;
Msg . m_Soundid = Sound ;
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , Target ) ;
2008-08-14 18:42:47 +00:00
}
2009-01-11 14:28:35 +00:00
2010-05-29 07:25:38 +00:00
void CGameContext : : SendChatTarget ( int To , const char * pText )
2009-01-11 14:28:35 +00:00
{
2010-05-29 07:25:38 +00:00
CNetMsg_Sv_Chat Msg ;
Msg . m_Team = 0 ;
Msg . m_Cid = - 1 ;
Msg . m_pMessage = pText ;
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , To ) ;
2009-01-11 14:28:35 +00:00
}
2010-05-29 07:25:38 +00:00
void CGameContext : : SendChat ( int ChatterClientId , int Team , const char * pText )
2008-08-14 18:42:47 +00:00
{
2010-05-29 07:25:38 +00:00
if ( ChatterClientId > = 0 & & ChatterClientId < MAX_CLIENTS )
dbg_msg ( " chat " , " %d:%d:%s: %s " , ChatterClientId , Team , Server ( ) - > ClientName ( ChatterClientId ) , pText ) ;
2008-08-14 18:42:47 +00:00
else
2010-05-29 07:25:38 +00:00
dbg_msg ( " chat " , " *** %s " , pText ) ;
2008-08-14 18:42:47 +00:00
2010-05-29 07:25:38 +00:00
if ( Team = = CHAT_ALL )
2008-08-14 18:42:47 +00:00
{
2010-05-29 07:25:38 +00:00
CNetMsg_Sv_Chat Msg ;
Msg . m_Team = 0 ;
Msg . m_Cid = ChatterClientId ;
Msg . m_pMessage = pText ;
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , - 1 ) ;
2008-08-14 18:42:47 +00:00
}
else
{
2010-05-29 07:25:38 +00:00
CNetMsg_Sv_Chat Msg ;
Msg . m_Team = 1 ;
Msg . m_Cid = ChatterClientId ;
Msg . m_pMessage = pText ;
2009-06-15 13:01:04 +00:00
// pack one for the recording only
2010-05-29 07:25:38 +00:00
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL | MSGFLAG_NOSEND , - 1 ) ;
2008-08-14 18:42:47 +00:00
2009-06-15 13:01:04 +00:00
// send to the clients
2008-08-14 18:42:47 +00:00
for ( int i = 0 ; i < MAX_CLIENTS ; i + + )
{
2010-05-29 07:25:38 +00:00
if ( m_apPlayers [ i ] & & m_apPlayers [ i ] - > GetTeam ( ) = = Team )
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL | MSGFLAG_NORECORD , i ) ;
2008-08-14 18:42:47 +00:00
}
}
}
2010-05-29 07:25:38 +00:00
void CGameContext : : SendEmoticon ( int ClientId , int Emoticon )
2008-08-14 18:42:47 +00:00
{
2010-05-29 07:25:38 +00:00
CNetMsg_Sv_Emoticon Msg ;
Msg . m_Cid = ClientId ;
Msg . m_Emoticon = Emoticon ;
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , - 1 ) ;
2008-08-14 18:42:47 +00:00
}
2010-05-29 07:25:38 +00:00
void CGameContext : : SendWeaponPickup ( int ClientId , int Weapon )
2008-08-14 18:42:47 +00:00
{
2010-05-29 07:25:38 +00:00
CNetMsg_Sv_WeaponPickup Msg ;
Msg . m_Weapon = Weapon ;
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , ClientId ) ;
2008-08-14 18:42:47 +00:00
}
2010-05-29 07:25:38 +00:00
void CGameContext : : SendBroadcast ( const char * pText , int ClientId )
2008-08-14 18:42:47 +00:00
{
2010-05-29 07:25:38 +00:00
CNetMsg_Sv_Broadcast Msg ;
Msg . m_pMessage = pText ;
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , ClientId ) ;
2008-08-14 18:42:47 +00:00
}
2008-09-24 14:47:03 +00:00
//
2010-05-29 07:25:38 +00:00
void CGameContext : : StartVote ( const char * pDesc , const char * pCommand )
2008-09-24 14:47:03 +00:00
{
// check if a vote is already running
2010-05-29 07:25:38 +00:00
if ( m_VoteCloseTime )
2008-09-24 14:47:03 +00:00
return ;
// reset votes
2010-05-29 07:25:38 +00:00
m_VoteEnforce = VOTE_ENFORCE_UNKNOWN ;
2008-09-24 14:47:03 +00:00
for ( int i = 0 ; i < MAX_CLIENTS ; i + + )
{
2010-05-29 07:25:38 +00:00
if ( m_apPlayers [ i ] )
{
m_apPlayers [ i ] - > m_Vote = 0 ;
m_apPlayers [ i ] - > m_VotePos = 0 ;
}
2008-09-24 14:47:03 +00:00
}
// start vote
2010-05-29 07:25:38 +00:00
m_VoteCloseTime = time_get ( ) + time_freq ( ) * 25 ;
str_copy ( m_aVoteDescription , pDesc , sizeof ( m_aVoteDescription ) ) ;
str_copy ( m_aVoteCommand , pCommand , sizeof ( m_aVoteCommand ) ) ;
SendVoteSet ( - 1 ) ;
m_VoteUpdate = true ;
2008-09-24 14:47:03 +00:00
}
2008-09-25 12:41:37 +00:00
2010-05-29 07:25:38 +00:00
void CGameContext : : EndVote ( )
2008-09-25 12:41:37 +00:00
{
2010-05-29 07:25:38 +00:00
m_VoteCloseTime = 0 ;
SendVoteSet ( - 1 ) ;
2008-09-25 12:41:37 +00:00
}
2010-05-29 07:25:38 +00:00
void CGameContext : : SendVoteSet ( int ClientId )
2008-09-24 14:47:03 +00:00
{
2010-05-29 07:25:38 +00:00
CNetMsg_Sv_VoteSet Msg ;
if ( m_VoteCloseTime )
2008-09-24 14:47:03 +00:00
{
2010-05-29 07:25:38 +00:00
Msg . m_Timeout = ( m_VoteCloseTime - time_get ( ) ) / time_freq ( ) ;
Msg . m_pDescription = m_aVoteDescription ;
Msg . m_pCommand = " " ;
2008-09-24 14:47:03 +00:00
}
else
{
2010-05-29 07:25:38 +00:00
Msg . m_Timeout = 0 ;
Msg . m_pDescription = " " ;
Msg . m_pCommand = " " ;
2008-09-24 14:47:03 +00:00
}
2010-05-29 07:25:38 +00:00
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , ClientId ) ;
2008-09-24 14:47:03 +00:00
}
2010-05-29 07:25:38 +00:00
void CGameContext : : SendVoteStatus ( int ClientId , int Total , int Yes , int No )
2008-09-24 14:47:03 +00:00
{
2010-05-29 07:25:38 +00:00
CNetMsg_Sv_VoteStatus Msg = { 0 } ;
Msg . m_Total = Total ;
Msg . m_Yes = Yes ;
Msg . m_No = No ;
Msg . m_Pass = Total - ( Yes + No ) ;
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , ClientId ) ;
}
void CGameContext : : AbortVoteKickOnDisconnect ( int ClientId )
{
if ( m_VoteCloseTime & & ! str_comp_num ( m_aVoteCommand , " kick " , 5 ) & & str_toint ( & m_aVoteCommand [ 5 ] ) = = ClientId )
m_VoteCloseTime = - 1 ;
}
void CGameContext : : CheckPureTuning ( )
{
// might not be created yet during start up
if ( ! m_pController )
return ;
if ( str_comp ( m_pController - > m_pGameType , " DM " ) = = 0 | |
str_comp ( m_pController - > m_pGameType , " TDM " ) = = 0 | |
str_comp ( m_pController - > m_pGameType , " CTF " ) = = 0 )
2008-09-24 14:47:03 +00:00
{
2010-05-29 07:25:38 +00:00
CTuningParams p ;
if ( mem_comp ( & p , & m_Tuning , sizeof ( p ) ) ! = 0 )
2008-09-24 14:47:03 +00:00
{
2010-05-29 07:25:38 +00:00
dbg_msg ( " server " , " resetting tuning due to pure server " ) ;
m_Tuning = p ;
2008-09-24 14:47:03 +00:00
}
}
}
2010-05-29 07:25:38 +00:00
void CGameContext : : SendTuningParams ( int Cid )
2008-10-21 17:26:32 +00:00
{
2010-05-29 07:25:38 +00:00
CheckPureTuning ( ) ;
CMsgPacker Msg ( NETMSGTYPE_SV_TUNEPARAMS ) ;
int * pParams = ( int * ) & m_Tuning ;
for ( unsigned i = 0 ; i < sizeof ( m_Tuning ) / sizeof ( int ) ; i + + )
Msg . AddInt ( pParams [ i ] ) ;
Server ( ) - > SendMsg ( & Msg , MSGFLAG_VITAL , Cid ) ;
2008-10-21 17:26:32 +00:00
}
2010-05-29 07:25:38 +00:00
void CGameContext : : OnTick ( )
2008-08-14 18:42:47 +00:00
{
2010-05-29 07:25:38 +00:00
// check tuning
CheckPureTuning ( ) ;
// copy tuning
m_World . m_Core . m_Tuning = m_Tuning ;
m_World . Tick ( ) ;
2008-08-14 18:42:47 +00:00
//if(world.paused) // make sure that the game object always updates
2010-05-29 07:25:38 +00:00
m_pController - > Tick ( ) ;
2008-08-14 18:42:47 +00:00
for ( int i = 0 ; i < MAX_CLIENTS ; i + + )
{
2010-05-29 07:25:38 +00:00
if ( m_apPlayers [ i ] )
m_apPlayers [ i ] - > Tick ( ) ;
2008-08-14 18:42:47 +00:00
}
2008-09-24 14:47:03 +00:00
// update voting
2010-05-29 07:25:38 +00:00
if ( m_VoteCloseTime )
2008-09-24 14:47:03 +00:00
{
2008-10-21 17:26:32 +00:00
// abort the kick-vote on player-leave
2010-05-29 07:25:38 +00:00
if ( m_VoteCloseTime = = - 1 )
2008-09-24 14:47:03 +00:00
{
2010-05-29 07:25:38 +00:00
SendChat ( - 1 , CGameContext : : CHAT_ALL , " Vote aborted " ) ;
EndVote ( ) ;
2008-10-21 17:26:32 +00:00
}
else
{
2010-05-29 07:25:38 +00:00
int Total = 0 , Yes = 0 , No = 0 ;
if ( m_VoteUpdate )
2008-09-24 14:47:03 +00:00
{
2010-05-29 07:25:38 +00:00
// count votes
char aaBuf [ MAX_CLIENTS ] [ 64 ] = { { 0 } } ;
for ( int i = 0 ; i < MAX_CLIENTS ; i + + )
if ( m_apPlayers [ i ] )
Server ( ) - > GetClientIP ( i , aaBuf [ i ] , 64 ) ;
bool aVoteChecked [ MAX_CLIENTS ] = { 0 } ;
for ( int i = 0 ; i < MAX_CLIENTS ; i + + )
2008-10-21 17:26:32 +00:00
{
2010-05-29 07:25:38 +00:00
if ( ! m_apPlayers [ i ] | | m_apPlayers [ i ] - > GetTeam ( ) = = - 1 | | aVoteChecked [ i ] ) // don't count in votes by spectators
continue ;
int ActVote = m_apPlayers [ i ] - > m_Vote ;
int ActVotePos = m_apPlayers [ i ] - > m_VotePos ;
// check for more players with the same ip (only use the vote of the one who voted first)
for ( int j = i + 1 ; j < MAX_CLIENTS ; + + j )
{
if ( ! m_apPlayers [ j ] | | aVoteChecked [ j ] | | str_comp ( aaBuf [ j ] , aaBuf [ i ] ) )
continue ;
aVoteChecked [ j ] = true ;
if ( m_apPlayers [ j ] - > m_Vote & & ( ! ActVote | | ActVotePos > m_apPlayers [ j ] - > m_VotePos ) )
{
ActVote = m_apPlayers [ j ] - > m_Vote ;
ActVotePos = m_apPlayers [ j ] - > m_VotePos ;
}
}
Total + + ;
if ( ActVote > 0 )
Yes + + ;
else if ( ActVote < 0 )
No + + ;
2008-10-21 17:26:32 +00:00
}
2010-05-29 07:25:38 +00:00
if ( Yes > = Total / 2 + 1 )
m_VoteEnforce = VOTE_ENFORCE_YES ;
else if ( No > = Total / 2 + 1 | | Yes + No = = Total )
m_VoteEnforce = VOTE_ENFORCE_NO ;
2008-09-24 14:47:03 +00:00
}
2010-05-29 07:25:38 +00:00
if ( m_VoteEnforce = = VOTE_ENFORCE_YES )
{
2010-07-29 19:55:33 +00:00
//Console()->ExecuteLine(m_aVoteCommand, 4, -1);
//EndVote();
//SendChat(-1, CGameContext::CHAT_ALL, "Vote passed");
2010-07-30 12:50:09 +00:00
if ( m_VoteEnforce = = VOTE_ENFORCE_YES )
2010-07-29 19:55:33 +00:00
{
Console ( ) - > ExecuteLine ( m_aVoteCommand , 3 , - 1 ) ;
SendChat ( - 1 , CGameContext : : CHAT_ALL , " Vote passed (enforced by Admin) " ) ;
dbg_msg ( " Vote " , " Due to vote enforcing, vote level has been set to 3 " ) ;
EndVote ( ) ;
}
else
{
Console ( ) - > ExecuteLine ( m_aVoteCommand , 4 , - 1 ) ;
dbg_msg ( " Vote " , " vote level is set to 4 " ) ;
EndVote ( ) ;
SendChat ( - 1 , CGameContext : : CHAT_ALL , " Vote passed " ) ;
}
2010-05-29 07:25:38 +00:00
if ( m_apPlayers [ m_VoteCreator ] )
m_apPlayers [ m_VoteCreator ] - > m_Last_VoteCall = 0 ;
}
else if ( m_VoteEnforce = = VOTE_ENFORCE_NO | | time_get ( ) > m_VoteCloseTime )
{
EndVote ( ) ;
SendChat ( - 1 , CGameContext : : CHAT_ALL , " Vote failed " ) ;
}
else if ( m_VoteUpdate )
{
m_VoteUpdate = false ;
SendVoteStatus ( - 1 , Total , Yes , No ) ;
}
}
}
# ifdef CONF_DEBUG
if ( g_Config . m_DbgDummies )
{
for ( int i = 0 ; i < g_Config . m_DbgDummies ; i + + )
{
CNetObj_PlayerInput Input = { 0 } ;
Input . m_Direction = ( i & 1 ) ? - 1 : 1 ;
m_apPlayers [ MAX_CLIENTS - i - 1 ] - > OnPredictedInput ( & Input ) ;
}
}
# endif
}
// Server hooks
void CGameContext : : OnClientDirectInput ( int ClientID , void * pInput )
{
if ( ! m_World . m_Paused )
m_apPlayers [ ClientID ] - > OnDirectInput ( ( CNetObj_PlayerInput * ) pInput ) ;
}
void CGameContext : : OnClientPredictedInput ( int ClientID , void * pInput )
{
if ( ! m_World . m_Paused )
m_apPlayers [ ClientID ] - > OnPredictedInput ( ( CNetObj_PlayerInput * ) pInput ) ;
}
void CGameContext : : OnClientEnter ( int ClientId )
{
//world.insert_entity(&players[client_id]);
m_apPlayers [ ClientId ] - > Respawn ( ) ;
dbg_msg ( " game " , " join player='%d:%s' " , ClientId , Server ( ) - > ClientName ( ClientId ) ) ;
char aBuf [ 512 ] ;
str_format ( aBuf , sizeof ( aBuf ) , " %s entered and joined the %s " , Server ( ) - > ClientName ( ClientId ) , m_pController - > GetTeamName ( m_apPlayers [ ClientId ] - > GetTeam ( ) ) ) ;
SendChat ( - 1 , CGameContext : : CHAT_ALL , aBuf ) ;
2010-07-29 19:51:58 +00:00
SendChatTarget ( ClientId , " DDRace Mod. Version: " DDRACE_VERSION ) ;
SendChatTarget ( ClientId , " Official site: DDRace.info " ) ;
SendChatTarget ( ClientId , " For more Info /CMDList " ) ;
SendChatTarget ( ClientId , " Or visit DDRace.info " ) ;
SendChatTarget ( ClientId , " To see this again say /info " ) ;
if ( g_Config . m_SvWelcome [ 0 ] ! = 0 ) SendChatTarget ( ClientId , g_Config . m_SvWelcome ) ;
2010-05-29 07:25:38 +00:00
dbg_msg ( " game " , " team_join player='%d:%s' team=%d " , ClientId , Server ( ) - > ClientName ( ClientId ) , m_apPlayers [ ClientId ] - > GetTeam ( ) ) ;
m_VoteUpdate = true ;
}
2010-07-29 05:21:18 +00:00
bool compare_players ( CPlayer * pl1 , CPlayer * pl2 )
{
if ( pl1 - > m_Authed > pl2 - > m_Authed )
return true ;
else
return false ;
}
2010-08-07 18:49:57 +00:00
void CGameContext : : OnSetAuthed ( int client_id , int Level )
2010-07-29 19:55:33 +00:00
{
if ( m_apPlayers [ client_id ] )
{
2010-08-07 18:49:57 +00:00
m_apPlayers [ client_id ] - > m_Authed = Level ;
2010-07-29 19:55:33 +00:00
char buf [ 11 ] ;
str_format ( buf , sizeof ( buf ) , " ban %d %d " , client_id , g_Config . m_SvVoteKickBanTime ) ;
//dbg_msg("hooks","%d", m_aVoteCommand == buf);//???
if ( ! strcmp ( m_aVoteCommand , buf ) )
{
m_VoteEnforce = CGameContext : : VOTE_ENFORCE_NO ;
dbg_msg ( " hooks " , " Aborting vote " ) ;
}
}
2010-07-29 05:21:18 +00:00
}
2010-08-07 18:49:57 +00:00
void CGameContext : : OnSetResistent ( int client_id , int Resistent )
2010-07-29 05:21:18 +00:00
{
if ( m_apPlayers [ client_id ] )
2010-08-07 18:49:57 +00:00
m_apPlayers [ client_id ] - > m_Resistent = Resistent ;
2010-07-29 05:21:18 +00:00
}
2010-05-29 07:25:38 +00:00
void CGameContext : : OnClientConnected ( int ClientId )
{
// Check which team the player should be on
const int StartTeam = g_Config . m_SvTournamentMode ? - 1 : m_pController - > GetAutoTeam ( ClientId ) ;
m_apPlayers [ ClientId ] = new ( ClientId ) CPlayer ( this , ClientId , StartTeam ) ;
//players[client_id].init(client_id);
//players[client_id].client_id = client_id;
2010-07-29 05:21:18 +00:00
//(void)m_pController->CheckTeamBalance();
2010-05-29 07:25:38 +00:00
# ifdef CONF_DEBUG
if ( g_Config . m_DbgDummies )
{
if ( ClientId > = MAX_CLIENTS - g_Config . m_DbgDummies )
return ;
}
# endif
// send active vote
if ( m_VoteCloseTime )
SendVoteSet ( ClientId ) ;
// send motd
CNetMsg_Sv_Motd Msg ;
Msg . m_pMessage = g_Config . m_SvMotd ;
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , ClientId ) ;
}
void CGameContext : : OnClientDrop ( int ClientId )
{
AbortVoteKickOnDisconnect ( ClientId ) ;
m_apPlayers [ ClientId ] - > OnDisconnect ( ) ;
delete m_apPlayers [ ClientId ] ;
m_apPlayers [ ClientId ] = 0 ;
2010-07-29 05:21:18 +00:00
//(void)m_pController->CheckTeamBalance();
2010-05-29 07:25:38 +00:00
m_VoteUpdate = true ;
}
void CGameContext : : OnMessage ( int MsgId , CUnpacker * pUnpacker , int ClientId )
{
void * pRawMsg = m_NetObjHandler . SecureUnpackMsg ( MsgId , pUnpacker ) ;
CPlayer * p = m_apPlayers [ ClientId ] ;
if ( ! pRawMsg )
{
dbg_msg ( " server " , " dropped weird message '%s' (%d), failed on '%s' " , m_NetObjHandler . GetMsgName ( MsgId ) , MsgId , m_NetObjHandler . FailedMsgOn ( ) ) ;
return ;
}
if ( MsgId = = NETMSGTYPE_CL_SAY )
{
CNetMsg_Cl_Say * pMsg = ( CNetMsg_Cl_Say * ) pRawMsg ;
int Team = pMsg - > m_Team ;
if ( Team )
Team = p - > GetTeam ( ) ;
else
Team = CGameContext : : CHAT_ALL ;
if ( g_Config . m_SvSpamprotection & & p - > m_Last_Chat & & p - > m_Last_Chat + Server ( ) - > TickSpeed ( ) > Server ( ) - > Tick ( ) )
return ;
2010-07-30 12:50:09 +00:00
if ( str_length ( pMsg - > m_pMessage ) > 370 ) {
SendChatTarget ( ClientId , " Your Message is too long " ) ;
return ;
}
2010-05-29 07:25:38 +00:00
p - > m_Last_Chat = Server ( ) - > Tick ( ) ;
// check for invalid chars
unsigned char * pMessage = ( unsigned char * ) pMsg - > m_pMessage ;
while ( * pMessage )
{
if ( * pMessage < 32 )
* pMessage = ' ' ;
pMessage + + ;
}
2010-07-29 05:21:18 +00:00
if ( pMsg - > m_pMessage [ 0 ] = = ' / ' ) {
if ( ! str_comp_nocase ( pMsg - > m_pMessage , " /Credits " ) )
{
SendChatTarget ( ClientId , " This mod was originally Created by 3DA " ) ;
2010-07-29 14:53:25 +00:00
SendChatTarget ( ClientId , " But now maintained by GreYFoX@GTi among others: " ) ;
SendChatTarget ( ClientId , " [blacktee] den, LemonFace, noother & Fluxid " ) ;
SendChatTarget ( ClientId , " please check the changelog on DDRace.info " ) ;
SendChatTarget ( ClientId , " also the commit log on github.com/GreYFoXGTi/DDRace " ) ;
2010-07-29 05:21:18 +00:00
} else if ( ! str_comp_nocase ( pMsg - > m_pMessage , " /pause " ) )
{
if ( g_Config . m_SvPauseable & & g_Config . m_SvVoteKick )
{
CCharacter * chr = m_apPlayers [ ClientId ] - > GetCharacter ( ) ;
if ( chr )
{
if ( chr - > m_RaceState = = RACE_STARTED )
chr - > m_RaceState = RACE_PAUSE ;
else if ( chr - > m_RaceState = = RACE_PAUSE )
chr - > m_RaceState = RACE_STARTED ;
}
}
} else if ( ! str_comp_nocase ( pMsg - > m_pMessage , " /info " ) )
2010-07-29 19:51:58 +00:00
{
2010-07-29 14:53:25 +00:00
SendChatTarget ( ClientId , " DDRace Mod. Version: " DDRACE_VERSION ) ;
SendChatTarget ( ClientId , " Official site: DDRace.info " ) ;
SendChatTarget ( ClientId , " For more Info /CMDList " ) ;
SendChatTarget ( ClientId , " Or visit DDRace.info " ) ;
}
else if ( ! str_comp_nocase ( pMsg - > m_pMessage , " /flags " ) )
{
char buf [ 64 ] ;
float temp1 ;
float temp2 ;
m_Tuning . Get ( " player_collision " , & temp1 ) ;
m_Tuning . Get ( " player_hooking " , & temp2 ) ;
str_format ( buf , sizeof ( buf ) , " Flags: Cheats[%s]%s%s Player Collision[%s] PLayer Hook[%s] " ,
g_Config . m_SvCheats ? " Y " : " N " ,
( g_Config . m_SvCheats ) ? " w/Time " : " " ,
( g_Config . m_SvCheats ) ? ( g_Config . m_SvCheatTime ) ? " [Y] " : " [N] " : " " ,
temp1 ? " Y " : " N " ,
temp2 ? " Y " : " N "
) ;
SendChatTarget ( ClientId , buf ) ;
str_format ( buf , sizeof ( buf ) , " Endless Hook[%s] Weapons Effect Others[%s] " , g_Config . m_SvEndlessDrag ? " Y " : " N " , g_Config . m_SvHit ? " Y " : " N " ) ;
SendChatTarget ( ClientId , buf ) ;
}
else if ( ! str_comp_nocase ( pMsg - > m_pMessage , " /CMDList " ) )
{
char buf [ 64 ] ;
str_format ( buf , sizeof ( buf ) , " /Info /Credits %s " , g_Config . m_SvPauseable ? " /pause " : " " ) ;
SendChatTarget ( ClientId , buf ) ;
SendChatTarget ( ClientId , " /rank /top5 /top5 5 or any number " ) ;
}
else if ( ! strncmp ( pMsg - > m_pMessage , " /top5 " , 5 ) & & ! g_Config . m_SvHideScore )
{
const char * pt = pMsg - > m_pMessage ;
2010-08-20 17:45:09 +00:00
std : : list < std : : string > s ;
std : : list < std : : string > : : iterator i ;
char buf [ 64 ] ;
2010-07-29 14:53:25 +00:00
int number = 0 ;
pt + = 6 ;
while ( * pt & & * pt > = ' 0 ' & & * pt < = ' 9 ' )
2010-07-29 05:21:18 +00:00
{
2010-07-29 14:53:25 +00:00
number = number * 10 + ( * pt - ' 0 ' ) ;
pt + + ;
2010-07-29 05:21:18 +00:00
}
2010-07-29 14:53:25 +00:00
if ( number )
2010-08-20 17:45:09 +00:00
s = ( ( CGameControllerDDRace * ) m_pController ) - > m_Score . Top5Draw ( ClientId , number ) ;
2010-07-29 14:53:25 +00:00
else
2010-08-20 17:45:09 +00:00
s = ( ( CGameControllerDDRace * ) m_pController ) - > m_Score . Top5Draw ( ClientId , 0 ) ;
for ( i = s . begin ( ) ; i ! = s . end ( ) ; + + i )
{
str_format ( buf , sizeof ( buf ) , " %s " , * i ) ;
SendChatTarget ( ClientId , buf ) ;
}
2010-07-29 14:53:25 +00:00
}
else if ( ! str_comp_nocase ( pMsg - > m_pMessage , " /rank " ) )
{
char buf [ 512 ] ;
const char * name = pMsg - > m_pMessage ;
name + = 6 ;
int pos = 0 ;
CPlayerScore * pscore ;
pscore = ( ( CGameControllerDDRace * ) m_pController ) - > m_Score . SearchName ( Server ( ) - > ClientName ( ClientId ) , pos ) ;
if ( pscore & & pos > - 1 & & pscore - > m_Score ! = - 1 )
2010-07-29 05:21:18 +00:00
{
2010-07-29 14:53:25 +00:00
float time = pscore - > m_Score ;
2010-07-29 05:21:18 +00:00
2010-07-29 14:53:25 +00:00
str_format ( buf , sizeof ( buf ) , " %d. %s " , ! g_Config . m_SvHideScore ? pos : 0 , pscore - > name ) ;
if ( ! g_Config . m_SvHideScore )
SendChat ( - 1 , CGameContext : : CHAT_ALL , buf ) ;
2010-07-29 05:21:18 +00:00
else
2010-07-29 14:53:25 +00:00
SendChatTarget ( ClientId , buf ) ;
2010-07-29 05:21:18 +00:00
2010-07-29 14:53:25 +00:00
if ( ( int ) time / 60 > = 1 )
str_format ( buf , sizeof ( buf ) , " Time: %d minute%s %f seconds " , ( int ) time / 60 , ( int ) time / 60 ! = 1 ? " s " : " " , time - ( ( int ) time / 60 ) * 60 ) ;
else
str_format ( buf , sizeof ( buf ) , " Time: %f seconds " , time - ( ( int ) time / 60 ) * 60 ) ;
2010-07-29 05:21:18 +00:00
}
else
2010-07-29 14:53:25 +00:00
str_format ( buf , sizeof ( buf ) , " %s is not ranked " , Server ( ) - > ClientName ( ClientId ) ) ;
SendChatTarget ( ClientId , buf ) ;
}
else
2010-07-29 05:21:18 +00:00
SendChatTarget ( ClientId , " No such command! " ) ;
} else {
if ( m_apPlayers [ ClientId ] - > m_Muted = = 0 )
SendChat ( ClientId , Team , pMsg - > m_pMessage ) ;
else
SendChatTarget ( ClientId , " You are muted " ) ;
}
2010-05-29 07:25:38 +00:00
}
else if ( MsgId = = NETMSGTYPE_CL_CALLVOTE )
{
if ( g_Config . m_SvSpamprotection & & p - > m_Last_VoteTry & & p - > m_Last_VoteTry + Server ( ) - > TickSpeed ( ) * 3 > Server ( ) - > Tick ( ) )
return ;
int64 Now = Server ( ) - > Tick ( ) ;
p - > m_Last_VoteTry = Now ;
2010-08-06 19:03:38 +00:00
if ( p - > GetTeam ( ) = = - 1 )
{
SendChatTarget ( ClientId , " Spectators aren't allowed to start a vote. " ) ;
return ;
}
2010-05-29 07:25:38 +00:00
if ( m_VoteCloseTime )
{
SendChatTarget ( ClientId , " Wait for current vote to end before calling a new one. " ) ;
return ;
}
2008-09-24 14:47:03 +00:00
2010-05-29 07:25:38 +00:00
int Timeleft = p - > m_Last_VoteCall + Server ( ) - > TickSpeed ( ) * 60 - Now ;
if ( p - > m_Last_VoteCall & & Timeleft > 0 )
{
char aChatmsg [ 512 ] = { 0 } ;
str_format ( aChatmsg , sizeof ( aChatmsg ) , " You must wait %d seconds before making another vote " , ( Timeleft / Server ( ) - > TickSpeed ( ) ) + 1 ) ;
SendChatTarget ( ClientId , aChatmsg ) ;
return ;
}
char aChatmsg [ 512 ] = { 0 } ;
char aDesc [ 512 ] = { 0 } ;
char aCmd [ 512 ] = { 0 } ;
CNetMsg_Cl_CallVote * pMsg = ( CNetMsg_Cl_CallVote * ) pRawMsg ;
if ( str_comp_nocase ( pMsg - > m_Type , " option " ) = = 0 )
{
CVoteOption * pOption = m_pVoteOptionFirst ;
2010-07-29 19:55:33 +00:00
static int64 last_mapvote = 0 ; //floff
2010-05-29 07:25:38 +00:00
while ( pOption )
2008-10-21 17:26:32 +00:00
{
2010-05-29 07:25:38 +00:00
if ( str_comp_nocase ( pMsg - > m_Value , pOption - > m_aCommand ) = = 0 )
{
2010-07-30 12:50:09 +00:00
if ( m_apPlayers [ ClientId ] - > m_Authed = = 0 & & strncmp ( pOption - > m_aCommand , " sv_map " , 7 ) = = 0 & & time_get ( ) < last_mapvote + ( time_freq ( ) * g_Config . m_SvVoteMapTimeDelay ) )
2010-07-29 19:55:33 +00:00
{
char chatmsg [ 512 ] = { 0 } ;
2010-07-30 12:50:09 +00:00
str_format ( chatmsg , sizeof ( chatmsg ) , " There's a %d second delay between map-votes,Please wait %d Second(s) " , g_Config . m_SvVoteMapTimeDelay , ( ( last_mapvote + ( g_Config . m_SvVoteMapTimeDelay * time_freq ( ) ) ) / time_freq ( ) ) - ( time_get ( ) / time_freq ( ) ) ) ;
2010-07-29 19:55:33 +00:00
SendChatTarget ( ClientId , chatmsg ) ;
return ;
}
2010-05-29 07:25:38 +00:00
str_format ( aChatmsg , sizeof ( aChatmsg ) , " %s called vote to change server option '%s' " , Server ( ) - > ClientName ( ClientId ) , pOption - > m_aCommand ) ;
str_format ( aDesc , sizeof ( aDesc ) , " %s " , pOption - > m_aCommand ) ;
str_format ( aCmd , sizeof ( aCmd ) , " %s " , pOption - > m_aCommand ) ;
2010-07-29 19:55:33 +00:00
last_mapvote = time_get ( ) ;
2010-05-29 07:25:38 +00:00
break ;
}
pOption = pOption - > m_pNext ;
}
2008-09-25 14:04:02 +00:00
2010-05-29 07:25:38 +00:00
if ( ! pOption )
{
str_format ( aChatmsg , sizeof ( aChatmsg ) , " '%s' isn't an option on this server " , pMsg - > m_Value ) ;
SendChatTarget ( ClientId , aChatmsg ) ;
return ;
2008-10-21 17:26:32 +00:00
}
2010-07-29 19:55:33 +00:00
last_mapvote = time_get ( ) ;
2010-05-29 07:25:38 +00:00
}
else if ( str_comp_nocase ( pMsg - > m_Type , " kick " ) = = 0 )
{
2010-07-30 12:50:09 +00:00
if ( m_apPlayers [ ClientId ] - > m_Authed = = 0 & & time_get ( ) < m_apPlayers [ ClientId ] - > m_Last_KickVote + ( time_freq ( ) * 5 ) )
2010-07-29 19:55:33 +00:00
return ;
2010-07-30 12:50:09 +00:00
else if ( m_apPlayers [ ClientId ] - > m_Authed = = 0 & & time_get ( ) < m_apPlayers [ ClientId ] - > m_Last_KickVote + ( time_freq ( ) * g_Config . m_SvVoteKickTimeDelay ) )
2010-07-29 19:55:33 +00:00
{
char chatmsg [ 512 ] = { 0 } ;
str_format ( chatmsg , sizeof ( chatmsg ) , " There's a %d second waittime between kickvotes for each player please wait %d second(s) " ,
2010-07-30 12:50:09 +00:00
g_Config . m_SvVoteKickTimeDelay ,
( ( m_apPlayers [ ClientId ] - > m_Last_KickVote + ( m_apPlayers [ ClientId ] - > m_Last_KickVote * time_freq ( ) ) ) / time_freq ( ) ) - ( time_get ( ) / time_freq ( ) )
2010-07-29 19:55:33 +00:00
) ;
2010-07-30 12:50:09 +00:00
SendChatTarget ( ClientId , chatmsg ) ;
m_apPlayers [ ClientId ] - > m_Last_KickVote = time_get ( ) ;
2010-07-29 19:55:33 +00:00
return ;
}
else if ( ! g_Config . m_SvVoteKick )
2008-10-21 17:26:32 +00:00
{
2010-05-29 07:25:38 +00:00
SendChatTarget ( ClientId , " Server does not allow voting to kick players " ) ;
2010-07-30 12:50:09 +00:00
m_apPlayers [ ClientId ] - > m_Last_KickVote = time_get ( ) ;
2010-05-29 07:25:38 +00:00
return ;
2008-10-21 17:26:32 +00:00
}
2010-05-29 07:25:38 +00:00
int KickId = str_toint ( pMsg - > m_Value ) ;
if ( KickId < 0 | | KickId > = MAX_CLIENTS | | ! m_apPlayers [ KickId ] )
{
SendChatTarget ( ClientId , " Invalid client id to kick " ) ;
2010-07-30 12:50:09 +00:00
m_apPlayers [ ClientId ] - > m_Last_KickVote = time_get ( ) ;
2010-05-29 07:25:38 +00:00
return ;
}
2010-06-02 02:42:17 +00:00
if ( KickId = = ClientId )
{
SendChatTarget ( ClientId , " You cant kick yourself " ) ;
return ;
}
if ( Server ( ) - > IsAuthed ( KickId ) )
{
SendChatTarget ( ClientId , " You cant kick admins " ) ;
2010-07-30 12:50:09 +00:00
m_apPlayers [ ClientId ] - > m_Last_KickVote = time_get ( ) ;
2010-06-02 02:42:17 +00:00
char aBufKick [ 128 ] ;
str_format ( aBufKick , sizeof ( aBufKick ) , " %s called for vote to kick you " , Server ( ) - > ClientName ( ClientId ) ) ;
SendChatTarget ( KickId , aBufKick ) ;
return ;
}
2010-05-29 07:25:38 +00:00
str_format ( aChatmsg , sizeof ( aChatmsg ) , " %s called for vote to kick '%s' " , Server ( ) - > ClientName ( ClientId ) , Server ( ) - > ClientName ( KickId ) ) ;
str_format ( aDesc , sizeof ( aDesc ) , " Kick '%s' " , Server ( ) - > ClientName ( KickId ) ) ;
2010-07-30 12:50:09 +00:00
if ( ! g_Config . m_SvVoteKickBanTime )
2010-05-29 07:25:38 +00:00
str_format ( aCmd , sizeof ( aCmd ) , " kick %d " , KickId ) ;
else
{
char aBuf [ 64 ] = { 0 } ;
Server ( ) - > GetClientIP ( KickId , aBuf , sizeof ( aBuf ) ) ;
str_format ( aCmd , sizeof ( aCmd ) , " ban %s %d " , aBuf , g_Config . m_SvVoteKickBantime ) ;
}
2010-07-30 12:50:09 +00:00
m_apPlayers [ ClientId ] - > m_Last_KickVote = time_get ( ) ;
2010-05-29 07:25:38 +00:00
}
if ( aCmd [ 0 ] )
{
SendChat ( - 1 , CGameContext : : CHAT_ALL , aChatmsg ) ;
StartVote ( aDesc , aCmd ) ;
p - > m_Vote = 1 ;
p - > m_VotePos = m_VotePos = 1 ;
m_VoteCreator = ClientId ;
p - > m_Last_VoteCall = Now ;
}
}
else if ( MsgId = = NETMSGTYPE_CL_VOTE )
{
if ( ! m_VoteCloseTime )
return ;
if ( p - > m_Vote = = 0 )
{
CNetMsg_Cl_Vote * pMsg = ( CNetMsg_Cl_Vote * ) pRawMsg ;
if ( ! pMsg - > m_Vote )
return ;
p - > m_Vote = pMsg - > m_Vote ;
p - > m_VotePos = + + m_VotePos ;
m_VoteUpdate = true ;
2008-09-25 12:23:44 +00:00
}
2008-09-24 14:47:03 +00:00
}
2010-05-29 07:25:38 +00:00
else if ( MsgId = = NETMSGTYPE_CL_SETTEAM & & ! m_World . m_Paused )
{
CNetMsg_Cl_SetTeam * pMsg = ( CNetMsg_Cl_SetTeam * ) pRawMsg ;
if ( p - > GetTeam ( ) = = pMsg - > m_Team | | ( g_Config . m_SvSpamprotection & & p - > m_Last_SetTeam & & p - > m_Last_SetTeam + Server ( ) - > TickSpeed ( ) * 3 > Server ( ) - > Tick ( ) ) )
return ;
// Switch team on given client and kill/respawn him
if ( m_pController - > CanJoinTeam ( pMsg - > m_Team , ClientId ) )
{
2010-07-29 05:21:18 +00:00
//if(m_pController->CanChangeTeam(p, pMsg->m_Team))
//{
2010-05-29 07:25:38 +00:00
p - > m_Last_SetTeam = Server ( ) - > Tick ( ) ;
if ( p - > GetTeam ( ) = = - 1 | | pMsg - > m_Team = = - 1 )
m_VoteUpdate = true ;
p - > SetTeam ( pMsg - > m_Team ) ;
2010-07-29 05:21:18 +00:00
//(void)m_pController->CheckTeamBalance();
//}
//else
//SendBroadcast("Teams must be balanced, please join other team", ClientId);
2010-05-29 07:25:38 +00:00
}
else
{
char aBuf [ 128 ] ;
str_format ( aBuf , sizeof ( aBuf ) , " Only %d active players are allowed " , g_Config . m_SvMaxClients - g_Config . m_SvSpectatorSlots ) ;
SendBroadcast ( aBuf , ClientId ) ;
}
}
else if ( MsgId = = NETMSGTYPE_CL_CHANGEINFO | | MsgId = = NETMSGTYPE_CL_STARTINFO )
{
CNetMsg_Cl_ChangeInfo * pMsg = ( CNetMsg_Cl_ChangeInfo * ) pRawMsg ;
if ( g_Config . m_SvSpamprotection & & p - > m_Last_ChangeInfo & & p - > m_Last_ChangeInfo + Server ( ) - > TickSpeed ( ) * 5 > Server ( ) - > Tick ( ) )
return ;
2010-07-29 15:02:29 +00:00
p - > m_Last_ChangeInfo = time_get ( ) ;
2010-07-30 16:14:53 +00:00
if ( ! p - > m_ColorSet | | g_Config . m_SvAllowColorChange )
2010-07-29 15:02:29 +00:00
{
p - > m_TeeInfos . m_UseCustomColor = pMsg - > m_UseCustomColor ;
p - > m_TeeInfos . m_ColorBody = pMsg - > m_ColorBody ;
p - > m_TeeInfos . m_ColorFeet = pMsg - > m_ColorFeet ;
}
2010-05-29 07:25:38 +00:00
// copy old name
char aOldName [ MAX_NAME_LENGTH ] ;
str_copy ( aOldName , Server ( ) - > ClientName ( ClientId ) , MAX_NAME_LENGTH ) ;
Server ( ) - > SetClientName ( ClientId , pMsg - > m_pName ) ;
if ( MsgId = = NETMSGTYPE_CL_CHANGEINFO & & str_comp ( aOldName , Server ( ) - > ClientName ( ClientId ) ) ! = 0 )
{
char aChatText [ 256 ] ;
str_format ( aChatText , sizeof ( aChatText ) , " %s changed name to %s " , aOldName , Server ( ) - > ClientName ( ClientId ) ) ;
SendChat ( - 1 , CGameContext : : CHAT_ALL , aChatText ) ;
}
// set skin
str_copy ( p - > m_TeeInfos . m_SkinName , pMsg - > m_pSkin , sizeof ( p - > m_TeeInfos . m_SkinName ) ) ;
2010-07-29 05:21:18 +00:00
//m_pController->OnPlayerInfoChange(p);
2010-05-29 07:25:38 +00:00
if ( MsgId = = NETMSGTYPE_CL_STARTINFO )
{
// send vote options
CNetMsg_Sv_VoteClearOptions ClearMsg ;
Server ( ) - > SendPackMsg ( & ClearMsg , MSGFLAG_VITAL , ClientId ) ;
CVoteOption * pCurrent = m_pVoteOptionFirst ;
while ( pCurrent )
{
CNetMsg_Sv_VoteOption OptionMsg ;
OptionMsg . m_pCommand = pCurrent - > m_aCommand ;
Server ( ) - > SendPackMsg ( & OptionMsg , MSGFLAG_VITAL , ClientId ) ;
pCurrent = pCurrent - > m_pNext ;
}
// send tuning parameters to client
SendTuningParams ( ClientId ) ;
//
CNetMsg_Sv_ReadyToEnter m ;
Server ( ) - > SendPackMsg ( & m , MSGFLAG_VITAL | MSGFLAG_FLUSH , ClientId ) ;
}
}
else if ( MsgId = = NETMSGTYPE_CL_EMOTICON & & ! m_World . m_Paused )
{
CNetMsg_Cl_Emoticon * pMsg = ( CNetMsg_Cl_Emoticon * ) pRawMsg ;
if ( g_Config . m_SvSpamprotection & & p - > m_Last_Emote & & p - > m_Last_Emote + Server ( ) - > TickSpeed ( ) * 3 > Server ( ) - > Tick ( ) )
return ;
p - > m_Last_Emote = Server ( ) - > Tick ( ) ;
SendEmoticon ( ClientId , pMsg - > m_Emoticon ) ;
}
else if ( MsgId = = NETMSGTYPE_CL_KILL & & ! m_World . m_Paused )
{
if ( p - > m_Last_Kill & & p - > m_Last_Kill + Server ( ) - > TickSpeed ( ) * 3 > Server ( ) - > Tick ( ) )
return ;
p - > m_Last_Kill = Server ( ) - > Tick ( ) ;
p - > KillCharacter ( WEAPON_SELF ) ;
p - > m_RespawnTick = Server ( ) - > Tick ( ) + Server ( ) - > TickSpeed ( ) * 3 ;
}
}
2010-07-29 05:21:18 +00:00
void CGameContext : : ConTuneParam ( IConsole : : IResult * pResult , void * pUserData , int cid )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
const char * pParamName = pResult - > GetString ( 0 ) ;
float NewValue = pResult - > GetFloat ( 1 ) ;
if ( pSelf - > Tuning ( ) - > Set ( pParamName , NewValue ) )
{
dbg_msg ( " tuning " , " %s changed to %.2f " , pParamName , NewValue ) ;
pSelf - > SendTuningParams ( - 1 ) ;
}
else
dbg_msg ( " tuning " , " No such tuning parameter " ) ;
}
2010-07-29 05:21:18 +00:00
void CGameContext : : ConTuneReset ( IConsole : : IResult * pResult , void * pUserData , int cid )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
CTuningParams p ;
* pSelf - > Tuning ( ) = p ;
pSelf - > SendTuningParams ( - 1 ) ;
dbg_msg ( " tuning " , " Tuning reset " ) ;
}
2010-07-29 05:21:18 +00:00
void CGameContext : : ConTuneDump ( IConsole : : IResult * pResult , void * pUserData , int cid )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
for ( int i = 0 ; i < pSelf - > Tuning ( ) - > Num ( ) ; i + + )
{
float v ;
pSelf - > Tuning ( ) - > Get ( i , & v ) ;
dbg_msg ( " tuning " , " %s %.2f " , pSelf - > Tuning ( ) - > m_apNames [ i ] , v ) ;
}
}
2010-07-29 05:21:18 +00:00
void CGameContext : : ConChangeMap ( IConsole : : IResult * pResult , void * pUserData , int cid )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
pSelf - > m_pController - > ChangeMap ( pResult - > GetString ( 0 ) ) ;
}
2010-07-29 05:21:18 +00:00
void CGameContext : : ConRestart ( IConsole : : IResult * pResult , void * pUserData , int cid )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( pResult - > NumArguments ( ) )
pSelf - > m_pController - > DoWarmup ( pResult - > GetInteger ( 0 ) ) ;
else
pSelf - > m_pController - > StartRound ( ) ;
}
2010-07-29 05:21:18 +00:00
void CGameContext : : ConBroadcast ( IConsole : : IResult * pResult , void * pUserData , int cid )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
pSelf - > SendBroadcast ( pResult - > GetString ( 0 ) , - 1 ) ;
}
2010-07-29 05:21:18 +00:00
void CGameContext : : ConSay ( IConsole : : IResult * pResult , void * pUserData , int cid )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
pSelf - > SendChat ( - 1 , CGameContext : : CHAT_ALL , pResult - > GetString ( 0 ) ) ;
}
2010-07-29 05:21:18 +00:00
void CGameContext : : ConSetTeam ( IConsole : : IResult * pResult , void * pUserData , int cid )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
int ClientId = clamp ( pResult - > GetInteger ( 0 ) , 0 , ( int ) MAX_CLIENTS - 1 ) ;
int Team = clamp ( pResult - > GetInteger ( 1 ) , - 1 , 1 ) ;
2010-07-29 05:21:18 +00:00
dbg_msg ( " set_team " , " %d %d " , ClientId , Team ) ;
2010-05-29 07:25:38 +00:00
2010-07-29 05:21:18 +00:00
if ( ! pSelf - > m_apPlayers [ ClientId ] | | ! compare_players ( pSelf - > m_apPlayers [ cid ] , pSelf - > m_apPlayers [ ClientId ] ) )
2010-05-29 07:25:38 +00:00
return ;
pSelf - > m_apPlayers [ ClientId ] - > SetTeam ( Team ) ;
2010-07-29 05:21:18 +00:00
//(void)pSelf->m_pController->CheckTeamBalance();
2010-05-29 07:25:38 +00:00
}
2010-07-29 05:21:18 +00:00
void CGameContext : : ConAddVote ( IConsole : : IResult * pResult , void * pUserData , int ClientID )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
int Len = str_length ( pResult - > GetString ( 0 ) ) ;
CGameContext : : CVoteOption * pOption = ( CGameContext : : CVoteOption * ) pSelf - > m_pVoteOptionHeap - > Allocate ( sizeof ( CGameContext : : CVoteOption ) + Len ) ;
pOption - > m_pNext = 0 ;
pOption - > m_pPrev = pSelf - > m_pVoteOptionLast ;
if ( pOption - > m_pPrev )
pOption - > m_pPrev - > m_pNext = pOption ;
pSelf - > m_pVoteOptionLast = pOption ;
if ( ! pSelf - > m_pVoteOptionFirst )
pSelf - > m_pVoteOptionFirst = pOption ;
mem_copy ( pOption - > m_aCommand , pResult - > GetString ( 0 ) , Len + 1 ) ;
dbg_msg ( " server " , " added option '%s' " , pOption - > m_aCommand ) ;
CNetMsg_Sv_VoteOption OptionMsg ;
OptionMsg . m_pCommand = pOption - > m_aCommand ;
pSelf - > Server ( ) - > SendPackMsg ( & OptionMsg , MSGFLAG_VITAL , - 1 ) ;
}
2010-07-29 05:21:18 +00:00
void CGameContext : : ConVote ( IConsole : : IResult * pResult , void * pUserData , int ClientID )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( str_comp_nocase ( pResult - > GetString ( 0 ) , " yes " ) = = 0 )
pSelf - > m_VoteEnforce = CGameContext : : VOTE_ENFORCE_YES ;
else if ( str_comp_nocase ( pResult - > GetString ( 0 ) , " no " ) = = 0 )
pSelf - > m_VoteEnforce = CGameContext : : VOTE_ENFORCE_NO ;
dbg_msg ( " server " , " forcing vote %s " , pResult - > GetString ( 0 ) ) ;
}
void CGameContext : : ConchainSpecialMotdupdate ( IConsole : : IResult * pResult , void * pUserData , IConsole : : FCommandCallback pfnCallback , void * pCallbackUserData )
{
2010-07-29 05:21:18 +00:00
pfnCallback ( pResult , pCallbackUserData , - 1 ) ;
2010-05-29 07:25:38 +00:00
if ( pResult - > NumArguments ( ) )
{
CNetMsg_Sv_Motd Msg ;
Msg . m_pMessage = g_Config . m_SvMotd ;
CGameContext * pSelf = ( CGameContext * ) pUserData ;
for ( int i = 0 ; i < MAX_CLIENTS ; + + i )
if ( pSelf - > m_apPlayers [ i ] )
pSelf - > Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , i ) ;
}
}
2010-07-29 05:21:18 +00:00
bool CGameContext : : CheatsAvailable ( int cid ) {
if ( ! g_Config . m_SvCheats ) {
( ( CServer * ) Server ( ) ) - > SendRconLine ( cid , " Cheats are not available on this server. " ) ;
}
return g_Config . m_SvCheats ;
}
void CGameContext : : ConGoLeft ( IConsole : : IResult * pResult , void * pUserData , int cid ) {
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( ! pSelf - > CheatsAvailable ( cid ) )
return ;
CCharacter * chr = pSelf - > GetPlayerChar ( cid ) ;
if ( chr )
{
chr - > m_Core . m_Pos . x - = 32 ;
2010-07-29 14:53:25 +00:00
if ( ! g_Config . m_SvCheatTime )
2010-07-29 05:21:18 +00:00
chr - > m_RaceState = RACE_CHEAT ;
}
}
void CGameContext : : ConGoRight ( IConsole : : IResult * pResult , void * pUserData , int cid ) {
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( ! pSelf - > CheatsAvailable ( cid ) )
return ;
CCharacter * chr = pSelf - > GetPlayerChar ( cid ) ;
if ( chr )
{
chr - > m_Core . m_Pos . x + = 32 ;
2010-07-29 14:53:25 +00:00
if ( ! g_Config . m_SvCheatTime )
2010-07-29 05:21:18 +00:00
chr - > m_RaceState = RACE_CHEAT ;
}
}
void CGameContext : : ConGoUp ( IConsole : : IResult * pResult , void * pUserData , int cid ) {
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( ! pSelf - > CheatsAvailable ( cid ) )
return ;
CCharacter * chr = pSelf - > GetPlayerChar ( cid ) ;
if ( chr )
{
chr - > m_Core . m_Pos . y - = 32 ;
2010-07-29 14:53:25 +00:00
if ( ! g_Config . m_SvCheatTime )
2010-07-29 05:21:18 +00:00
chr - > m_RaceState = RACE_CHEAT ;
}
}
void CGameContext : : ConGoDown ( IConsole : : IResult * pResult , void * pUserData , int cid ) {
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( ! pSelf - > CheatsAvailable ( cid ) )
return ;
CCharacter * chr = pSelf - > GetPlayerChar ( cid ) ;
if ( chr )
{
chr - > m_Core . m_Pos . y + = 32 ;
2010-07-29 14:53:25 +00:00
if ( ! g_Config . m_SvCheatTime )
2010-07-29 05:21:18 +00:00
chr - > m_RaceState = RACE_CHEAT ;
}
}
void CGameContext : : ConMute ( IConsole : : IResult * pResult , void * pUserData , int cid ) {
CGameContext * pSelf = ( CGameContext * ) pUserData ;
int cid1 = clamp ( pResult - > GetInteger ( 0 ) , 0 , ( int ) MAX_CLIENTS - 1 ) ;
int Seconds = pResult - > GetInteger ( 1 ) ;
char buf [ 512 ] ;
if ( Seconds < 10 )
Seconds = 10 ;
if ( pSelf - > m_apPlayers [ cid1 ] & & ( compare_players ( pSelf - > m_apPlayers [ cid ] , pSelf - > m_apPlayers [ cid1 ] ) ) )
{
if ( pSelf - > m_apPlayers [ cid1 ] - > m_Muted < Seconds * pSelf - > Server ( ) - > TickSpeed ( ) ) {
pSelf - > m_apPlayers [ cid1 ] - > m_Muted = Seconds * pSelf - > Server ( ) - > TickSpeed ( ) ;
}
else
Seconds = pSelf - > m_apPlayers [ cid1 ] - > m_Muted / pSelf - > Server ( ) - > TickSpeed ( ) ;
str_format ( buf , sizeof ( buf ) , " %s muted by %s for %d seconds " , pSelf - > Server ( ) - > ClientName ( cid1 ) , pSelf - > Server ( ) - > ClientName ( cid ) , Seconds ) ;
pSelf - > SendChat ( - 1 , CGameContext : : CHAT_ALL , buf ) ;
}
}
void CGameContext : : ConSetlvl ( IConsole : : IResult * pResult , void * pUserData , int cid ) {
CGameContext * pSelf = ( CGameContext * ) pUserData ;
int cid1 = clamp ( pResult - > GetInteger ( 0 ) , 0 , ( int ) MAX_CLIENTS - 1 ) ;
int level = clamp ( pResult - > GetInteger ( 1 ) , 0 , 3 ) ;
if ( pSelf - > m_apPlayers [ cid1 ] & & ( pSelf - > m_apPlayers [ cid1 ] - > m_Authed > level ) & & ( compare_players ( pSelf - > m_apPlayers [ cid ] , pSelf - > m_apPlayers [ cid1 ] ) ) )
{
pSelf - > m_apPlayers [ cid1 ] - > m_Authed = level ;
}
}
void CGameContext : : ConKillPlayer ( IConsole : : IResult * pResult , void * pUserData , int cid ) {
CGameContext * pSelf = ( CGameContext * ) pUserData ;
int cid1 = clamp ( pResult - > GetInteger ( 0 ) , 0 , ( int ) MAX_CLIENTS - 1 ) ;
if ( ! pSelf - > m_apPlayers [ cid1 ] )
return ;
if ( pSelf - > m_apPlayers [ cid1 ] & & compare_players ( pSelf - > m_apPlayers [ cid ] , pSelf - > m_apPlayers [ cid1 ] ) )
{
pSelf - > m_apPlayers [ cid1 ] - > KillCharacter ( WEAPON_GAME ) ;
char buf [ 512 ] ;
str_format ( buf , sizeof ( buf ) , " %s killed by %s " , pSelf - > Server ( ) - > ClientName ( cid1 ) , pSelf - > Server ( ) - > ClientName ( cid ) ) ;
pSelf - > SendChat ( - 1 , CGameContext : : CHAT_ALL , buf ) ;
}
}
void CGameContext : : ConNinjaMe ( IConsole : : IResult * pResult , void * pUserData , int cid ) {
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( ! pSelf - > CheatsAvailable ( cid ) ) return ;
2010-08-20 17:06:49 +00:00
CCharacter * chr = pSelf - > GetPlayerChar ( cid ) ;
2010-07-29 05:21:18 +00:00
if ( chr ) {
chr - > GiveNinja ( ) ;
2010-07-29 14:53:25 +00:00
if ( ! g_Config . m_SvCheatTime )
2010-07-29 05:21:18 +00:00
chr - > m_RaceState = RACE_CHEAT ;
}
}
void CGameContext : : ConNinja ( IConsole : : IResult * pResult , void * pUserData , int cid ) {
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( ! pSelf - > CheatsAvailable ( cid ) ) return ;
int cid1 = clamp ( pResult - > GetInteger ( 0 ) , 0 , ( int ) MAX_CLIENTS - 1 ) ;
2010-08-20 17:06:49 +00:00
CCharacter * chr = pSelf - > GetPlayerChar ( cid1 ) ;
2010-07-29 05:21:18 +00:00
if ( chr ) {
chr - > GiveNinja ( ) ;
2010-07-29 14:53:25 +00:00
if ( ! g_Config . m_SvCheatTime )
2010-07-29 05:21:18 +00:00
chr - > m_RaceState = RACE_CHEAT ;
}
}
void CGameContext : : ConHammer ( IConsole : : IResult * pResult , void * pUserData , int cid )
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( ! pSelf - > CheatsAvailable ( cid ) ) return ;
char buf [ 128 ] ;
int cid1 = clamp ( pResult - > GetInteger ( 0 ) , 0 , ( int ) MAX_CLIENTS - 1 ) ;
int type = pResult - > GetInteger ( 1 ) ;
2010-08-20 17:06:49 +00:00
CCharacter * chr = pSelf - > GetPlayerChar ( cid1 ) ;
2010-07-29 05:21:18 +00:00
if ( ! chr )
return ;
CServer * serv = ( CServer * ) pSelf - > Server ( ) ;
if ( type > 3 | | type < 0 )
{
serv - > SendRconLine ( cid , " Select hammer between 0 and 3 " ) ;
}
else
{
chr - > m_HammerType = type ;
2010-07-29 14:53:25 +00:00
if ( ! g_Config . m_SvCheatTime )
2010-07-29 05:21:18 +00:00
chr - > m_RaceState = RACE_CHEAT ;
str_format ( buf , sizeof ( buf ) , " Hammer of cid=%d setted to %d " , cid1 , type ) ;
serv - > SendRconLine ( cid1 , buf ) ;
}
}
void CGameContext : : ConHammerMe ( IConsole : : IResult * pResult , void * pUserData , int cid )
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( ! pSelf - > CheatsAvailable ( cid ) ) return ;
char buf [ 128 ] ;
2010-08-20 14:57:42 +00:00
int type = pResult - > GetInteger ( 0 ) ;
2010-08-20 17:06:49 +00:00
CCharacter * chr = pSelf - > GetPlayerChar ( cid ) ;
2010-07-29 05:21:18 +00:00
if ( ! chr )
return ;
CServer * serv = ( CServer * ) pSelf - > Server ( ) ;
if ( type > 3 | | type < 0 )
{
serv - > SendRconLine ( cid , " Select hammer between 0 and 3 " ) ;
}
else
{
chr - > m_HammerType = type ;
2010-07-29 14:53:25 +00:00
if ( ! g_Config . m_SvCheatTime )
2010-07-29 05:21:18 +00:00
chr - > m_RaceState = RACE_CHEAT ;
str_format ( buf , sizeof ( buf ) , " Hammer setted to %d " , type ) ;
serv - > SendRconLine ( cid , buf ) ;
}
}
void CGameContext : : ConSuper ( IConsole : : IResult * pResult , void * pUserData , int cid )
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( ! pSelf - > CheatsAvailable ( cid ) ) return ;
int cid1 = clamp ( pResult - > GetInteger ( 0 ) , 0 , ( int ) MAX_CLIENTS - 1 ) ;
if ( pSelf - > m_apPlayers [ cid1 ] & & compare_players ( pSelf - > m_apPlayers [ cid ] , pSelf - > m_apPlayers [ cid1 ] ) )
{
2010-08-20 17:06:49 +00:00
CCharacter * chr = pSelf - > GetPlayerChar ( cid1 ) ;
2010-07-29 05:21:18 +00:00
if ( chr )
{
chr - > m_Super = true ;
2010-07-29 14:53:25 +00:00
if ( ! g_Config . m_SvCheatTime )
2010-07-29 05:21:18 +00:00
chr - > m_RaceState = RACE_CHEAT ;
}
}
}
void CGameContext : : ConUnSuper ( IConsole : : IResult * pResult , void * pUserData , int cid )
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( ! pSelf - > CheatsAvailable ( cid ) ) return ;
int cid1 = clamp ( pResult - > GetInteger ( 0 ) , 0 , ( int ) MAX_CLIENTS - 1 ) ;
if ( pSelf - > m_apPlayers [ cid1 ] & & compare_players ( pSelf - > m_apPlayers [ cid ] , pSelf - > m_apPlayers [ cid1 ] ) )
{
2010-08-20 17:06:49 +00:00
CCharacter * chr = pSelf - > GetPlayerChar ( cid1 ) ;
2010-07-29 05:21:18 +00:00
if ( chr )
{
chr - > m_Super = false ;
}
}
}
void CGameContext : : ConSuperMe ( IConsole : : IResult * pResult , void * pUserData , int cid )
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( ! pSelf - > CheatsAvailable ( cid ) ) return ;
if ( pSelf - > m_apPlayers [ cid ] )
{
2010-08-20 17:06:49 +00:00
CCharacter * chr = pSelf - > GetPlayerChar ( cid ) ;
2010-07-29 05:21:18 +00:00
if ( chr )
{
chr - > m_Super = true ;
2010-07-29 14:53:25 +00:00
if ( ! g_Config . m_SvCheatTime )
2010-07-29 05:21:18 +00:00
chr - > m_RaceState = RACE_CHEAT ;
}
}
}
void CGameContext : : ConUnSuperMe ( IConsole : : IResult * pResult , void * pUserData , int cid )
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( ! pSelf - > CheatsAvailable ( cid ) ) return ;
if ( pSelf - > m_apPlayers [ cid ] )
{
2010-08-20 17:06:49 +00:00
CCharacter * chr = pSelf - > GetPlayerChar ( cid ) ;
2010-07-29 05:21:18 +00:00
if ( chr )
{
chr - > m_Super = false ;
}
}
}
void CGameContext : : ConWeapons ( IConsole : : IResult * pResult , void * pUserData , int cid )
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( ! pSelf - > CheatsAvailable ( cid ) ) return ;
int cid1 = clamp ( pResult - > GetInteger ( 0 ) , 0 , ( int ) MAX_CLIENTS - 1 ) ;
if ( pSelf - > m_apPlayers [ cid1 ] & & compare_players ( pSelf - > m_apPlayers [ cid ] , pSelf - > m_apPlayers [ cid1 ] ) )
{
2010-08-20 17:06:49 +00:00
CCharacter * chr = pSelf - > GetPlayerChar ( cid1 ) ;
2010-07-29 05:21:18 +00:00
if ( chr )
{
chr - > GiveAllWeapons ( ) ;
2010-07-29 14:53:25 +00:00
if ( ! g_Config . m_SvCheatTime )
2010-07-29 05:21:18 +00:00
chr - > m_RaceState = RACE_CHEAT ;
}
}
}
void CGameContext : : ConWeaponsMe ( IConsole : : IResult * pResult , void * pUserData , int cid )
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( ! pSelf - > CheatsAvailable ( cid ) ) return ;
2010-08-20 17:06:49 +00:00
CCharacter * chr = pSelf - > GetPlayerChar ( cid ) ;
if ( chr )
2010-07-29 05:21:18 +00:00
{
2010-08-20 17:06:49 +00:00
chr - > GiveAllWeapons ( ) ;
if ( ! g_Config . m_SvCheatTime )
chr - > m_RaceState = RACE_CHEAT ;
2010-07-29 05:21:18 +00:00
}
}
void CGameContext : : ConTeleport ( IConsole : : IResult * pResult , void * pUserData , int cid ) {
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( ! pSelf - > CheatsAvailable ( cid ) ) return ;
int cid1 = clamp ( pResult - > GetInteger ( 0 ) , 0 , ( int ) MAX_CLIENTS - 1 ) ;
int cid2 = clamp ( pResult - > GetInteger ( 1 ) , 0 , ( int ) MAX_CLIENTS - 1 ) ;
if ( pSelf - > m_apPlayers [ cid1 ] & & pSelf - > m_apPlayers [ cid2 ] )
{
if ( cid = = cid1
| | ( compare_players ( pSelf - > m_apPlayers [ cid ] , pSelf - > m_apPlayers [ cid1 ] ) & & compare_players ( pSelf - > m_apPlayers [ cid ] , pSelf - > m_apPlayers [ cid2 ] ) )
| | ( compare_players ( pSelf - > m_apPlayers [ cid ] , pSelf - > m_apPlayers [ cid1 ] ) & & cid2 = = cid ) )
{
2010-08-20 17:06:49 +00:00
CCharacter * chr = pSelf - > GetPlayerChar ( cid1 ) ;
2010-07-29 05:21:18 +00:00
if ( chr )
{
chr - > m_Core . m_Pos = pSelf - > m_apPlayers [ cid2 ] - > m_ViewPos ;
2010-07-29 14:53:25 +00:00
if ( ! g_Config . m_SvCheatTime )
2010-07-29 05:21:18 +00:00
chr - > m_RaceState = RACE_CHEAT ;
}
}
}
}
void CGameContext : : ConTimer ( IConsole : : IResult * pResult , void * pUserData , int cid )
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
char buf [ 128 ] ;
2010-08-14 09:45:19 +00:00
CServer * serv = ( CServer * ) pSelf - > Server ( ) ;
2010-07-31 12:58:57 +00:00
if ( ! g_Config . m_SvTimer ) {
int cid1 = clamp ( pResult - > GetInteger ( 0 ) , 0 , ( int ) MAX_CLIENTS - 1 ) ;
int type = pResult - > GetInteger ( 1 ) ;
2010-08-20 17:06:49 +00:00
CCharacter * chr = pSelf - > GetPlayerChar ( cid1 ) ;
if ( ! chr )
return ;
if ( type > 1 | | type < 0 )
{
serv - > SendRconLine ( cid , " Select 0 for no time & 1 for with time " ) ;
}
else
{
if ( type )
2010-07-31 12:58:57 +00:00
{
2010-08-20 17:06:49 +00:00
chr - > m_RaceState = RACE_STARTED ;
str_format ( buf , sizeof ( buf ) , " Cid=%d Has time now " , cid1 ) ;
2010-07-31 12:58:57 +00:00
}
2010-08-20 17:06:49 +00:00
else if ( ! type )
{
chr - > m_RaceState = RACE_CHEAT ;
str_format ( buf , sizeof ( buf ) , " Cid=%d Hasn't time now " , cid1 ) ;
2010-07-31 12:58:57 +00:00
}
2010-08-20 17:06:49 +00:00
serv - > SendRconLine ( cid1 , buf ) ;
2010-07-29 05:21:18 +00:00
}
2010-07-31 12:58:57 +00:00
} else {
2010-08-14 09:45:19 +00:00
serv - > SendRconLine ( cid , " Command timer does't allowed " ) ;
2010-07-29 05:21:18 +00:00
}
}
void CGameContext : : ConTimerReset ( IConsole : : IResult * pResult , void * pUserData , int cid )
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
if ( ! pSelf - > CheatsAvailable ( cid ) ) return ;
char buf [ 128 ] ;
int cid1 = clamp ( pResult - > GetInteger ( 0 ) , 0 , ( int ) MAX_CLIENTS - 1 ) ;
2010-08-20 17:06:49 +00:00
CCharacter * chr = pSelf - > GetPlayerChar ( cid1 ) ;
2010-07-29 05:21:18 +00:00
if ( ! chr )
return ;
chr - > m_StartTime = pSelf - > Server ( ) - > Tick ( ) ;
chr - > m_RefreshTime = pSelf - > Server ( ) - > Tick ( ) ;
str_format ( buf , sizeof ( buf ) , " Cid=%d time resetted. " , cid1 ) ;
CServer * serv = ( CServer * ) pSelf - > Server ( ) ;
serv - > SendRconLine ( cid1 , buf ) ;
}
2010-05-29 07:25:38 +00:00
void CGameContext : : OnConsoleInit ( )
{
m_pServer = Kernel ( ) - > RequestInterface < IServer > ( ) ;
m_pConsole = Kernel ( ) - > RequestInterface < IConsole > ( ) ;
2010-07-29 05:21:18 +00:00
Console ( ) - > Register ( " timer " , " ii " , CFGFLAG_SERVER , ConTimer , this , " Sets the timer of player i1 to i2 0/1 on/off " , 2 ) ;
Console ( ) - > Register ( " timerreset " , " i " , CFGFLAG_SERVER , ConTimerReset , this , " resets the timer of player i (to start count again timer cid 1) " , 1 ) ;
2010-05-29 07:25:38 +00:00
2010-07-29 05:21:18 +00:00
Console ( ) - > Register ( " tele " , " ii " , CFGFLAG_SERVER , ConTeleport , this , " " , 2 ) ;
Console ( ) - > Register ( " weapons " , " i " , CFGFLAG_SERVER , ConWeapons , this , " " , 2 ) ;
Console ( ) - > Register ( " weapons_me " , " " , CFGFLAG_SERVER , ConWeaponsMe , this , " " , 1 ) ;
Console ( ) - > Register ( " super " , " i " , CFGFLAG_SERVER , ConSuper , this , " " , 2 ) ;
Console ( ) - > Register ( " unsuper " , " i " , CFGFLAG_SERVER , ConUnSuper , this , " " , 2 ) ;
Console ( ) - > Register ( " super_me " , " " , CFGFLAG_SERVER , ConSuperMe , this , " " , 1 ) ;
Console ( ) - > Register ( " unsuper_me " , " " , CFGFLAG_SERVER , ConUnSuperMe , this , " " , 1 ) ; // Mo
Console ( ) - > Register ( " hammer_me " , " i " , CFGFLAG_SERVER , ConHammerMe , this , " " , 1 ) ;
Console ( ) - > Register ( " hammer " , " ii " , CFGFLAG_SERVER , ConHammer , this , " " , 2 ) ;
Console ( ) - > Register ( " ninja " , " i " , CFGFLAG_SERVER , ConNinja , this , " " , 2 ) ;
Console ( ) - > Register ( " ninja_me " , " " , CFGFLAG_SERVER , ConNinjaMe , this , " " , 1 ) ;
Console ( ) - > Register ( " kill_pl " , " i " , CFGFLAG_SERVER , ConKillPlayer , this , " " , 2 ) ;
Console ( ) - > Register ( " auth " , " ii " , CFGFLAG_SERVER , ConSetlvl , this , " " , 3 ) ;
Console ( ) - > Register ( " mute " , " ii " , CFGFLAG_SERVER , ConMute , this , " " , 2 ) ;
Console ( ) - > Register ( " tune " , " si " , CFGFLAG_SERVER , ConTuneParam , this , " " , 4 ) ;
Console ( ) - > Register ( " tune_reset " , " " , CFGFLAG_SERVER , ConTuneReset , this , " " , 4 ) ;
Console ( ) - > Register ( " tune_dump " , " " , CFGFLAG_SERVER , ConTuneDump , this , " " , 4 ) ;
Console ( ) - > Register ( " change_map " , " r " , CFGFLAG_SERVER , ConChangeMap , this , " " , 3 ) ;
Console ( ) - > Register ( " restart " , " ?i " , CFGFLAG_SERVER , ConRestart , this , " " , 3 ) ;
Console ( ) - > Register ( " broadcast " , " r " , CFGFLAG_SERVER , ConBroadcast , this , " " , 3 ) ;
Console ( ) - > Register ( " say " , " r " , CFGFLAG_SERVER , ConSay , this , " " , 3 ) ;
Console ( ) - > Register ( " set_team " , " ii " , CFGFLAG_SERVER , ConSetTeam , this , " " , 2 ) ;
Console ( ) - > Register ( " left " , " " , CFGFLAG_SERVER , ConGoLeft , this , " " , 1 ) ;
Console ( ) - > Register ( " right " , " " , CFGFLAG_SERVER , ConGoRight , this , " " , 1 ) ;
Console ( ) - > Register ( " up " , " " , CFGFLAG_SERVER , ConGoUp , this , " " , 1 ) ;
Console ( ) - > Register ( " down " , " " , CFGFLAG_SERVER , ConGoDown , this , " " , 1 ) ;
//Console()->Register("sv_cheats", "i", CFGFLAG_SERVER, ConCheats , 0, "Turns Cheats On/Off",4);
Console ( ) - > Register ( " addvote " , " r " , CFGFLAG_SERVER , ConAddVote , this , " " , 4 ) ;
Console ( ) - > Register ( " vote " , " r " , CFGFLAG_SERVER , ConVote , this , " " , 3 ) ;
2010-05-29 07:25:38 +00:00
Console ( ) - > Chain ( " sv_motd " , ConchainSpecialMotdupdate , this ) ;
2010-07-29 05:21:18 +00:00
2010-05-29 07:25:38 +00:00
}
void CGameContext : : OnInit ( /*class IKernel *pKernel*/ )
{
m_pServer = Kernel ( ) - > RequestInterface < IServer > ( ) ;
m_pConsole = Kernel ( ) - > RequestInterface < IConsole > ( ) ;
m_World . SetGameServer ( this ) ;
m_Events . SetGameServer ( this ) ;
//if(!data) // only load once
//data = load_data_from_memory(internal_data);
for ( int i = 0 ; i < NUM_NETOBJTYPES ; i + + )
Server ( ) - > SnapSetStaticsize ( i , m_NetObjHandler . GetObjSize ( i ) ) ;
m_Layers . Init ( Kernel ( ) ) ;
m_Collision . Init ( & m_Layers ) ;
// reset everything here
//world = new GAMEWORLD;
//players = new CPlayer[MAX_CLIENTS];
2010-07-29 05:21:18 +00:00
char buf [ 512 ] ;
str_format ( buf , sizeof ( buf ) , " data/maps/%s.cfg " , g_Config . m_SvMap ) ; //
Console ( ) - > ExecuteFile ( buf ) ;
str_format ( buf , sizeof ( buf ) , " data/maps/%s.map.cfg " , g_Config . m_SvMap ) ;
Console ( ) - > ExecuteFile ( buf ) ;
// dbg_msg("Note","For map cfgs in windows and linux u need the files");
// dbg_msg("Note","in a folder i nthe same dir as teeworlds_srv");
// dbg_msg("Note","data/maps/%s.cfg", config.sv_map);
2010-05-29 07:25:38 +00:00
// select gametype
2010-07-29 14:53:25 +00:00
m_pController = new CGameControllerDDRace ( this ) ;
2010-07-29 05:21:18 +00:00
//float temp;
//m_Tuning.Get("player_hooking",&temp);
//g_Config.m_SvPhook = temp;
//m_Tuning.Get("player_collision",&temp);
//g_Config.m_SvNpc=(!temp);
2010-06-07 11:34:47 +00:00
Server ( ) - > SetBrowseInfo ( m_pController - > m_pGameType , - 1 ) ;
2010-05-29 07:25:38 +00:00
// setup core world
//for(int i = 0; i < MAX_CLIENTS; i++)
// game.players[i].core.world = &game.world.core;
// create all entities from the game layer
CMapItemLayerTilemap * pTileMap = m_Layers . GameLayer ( ) ;
CTile * pTiles = ( CTile * ) Kernel ( ) - > RequestInterface < IMap > ( ) - > GetData ( pTileMap - > m_Data ) ;
2010-08-10 04:28:17 +00:00
2010-07-29 05:21:18 +00:00
//windows usually crshes here
2010-05-29 07:25:38 +00:00
for ( int y = 0 ; y < pTileMap - > m_Height ; y + + )
{
for ( int x = 0 ; x < pTileMap - > m_Width ; x + + )
{
int Index = pTiles [ y * pTileMap - > m_Width + x ] . m_Index ;
if ( Index > = ENTITY_OFFSET )
{
2010-08-10 04:28:17 +00:00
vec2 Pos ( x * 32.0f + 16.0f , y * 32.0f + 16.0f ) ;
m_pController - > OnEntity ( Index - ENTITY_OFFSET , Pos ) ;
2010-05-29 07:25:38 +00:00
}
}
}
# ifdef CONF_DEBUG
if ( g_Config . m_DbgDummies )
{
for ( int i = 0 ; i < g_Config . m_DbgDummies ; i + + )
{
OnClientConnected ( MAX_CLIENTS - i - 1 ) ;
}
}
# endif
}
void CGameContext : : OnShutdown ( )
{
delete m_pController ;
m_pController = 0 ;
Clear ( ) ;
2008-08-14 18:42:47 +00:00
}
2010-05-29 07:25:38 +00:00
void CGameContext : : OnSnap ( int ClientId )
2008-08-14 18:42:47 +00:00
{
2010-05-29 07:25:38 +00:00
m_World . Snap ( ClientId ) ;
m_pController - > Snap ( ClientId ) ;
m_Events . Snap ( ClientId ) ;
2008-08-14 18:42:47 +00:00
for ( int i = 0 ; i < MAX_CLIENTS ; i + + )
{
2010-05-29 07:25:38 +00:00
if ( m_apPlayers [ i ] )
m_apPlayers [ i ] - > Snap ( ClientId ) ;
2008-08-14 18:42:47 +00:00
}
}
2010-05-29 07:25:38 +00:00
void CGameContext : : OnPreSnap ( ) { }
void CGameContext : : OnPostSnap ( )
{
m_Events . Clear ( ) ;
}
const char * CGameContext : : Version ( ) { return GAME_VERSION ; }
const char * CGameContext : : NetVersion ( ) { return GAME_NETVERSION ; }
IGameServer * CreateGameServer ( ) { return new CGameContext ; }