2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2008-09-23 07:43:41 +00:00
# include <new>
2010-05-29 07:25:38 +00:00
# include <base/math.h>
# include <engine/shared/config.h>
# include <engine/map.h>
# include <engine/console.h>
# include "gamecontext.h"
# include <game/version.h>
# include <game/collision.h>
2011-04-09 06:41:31 +00:00
/*#include <game/gamecore.h>
2011-01-29 00:59:50 +00:00
# include "gamemodes/dm.h"
# include "gamemodes/tdm.h"
# include "gamemodes/ctf.h"
2011-04-09 06:41:31 +00:00
# include "gamemodes/mod.h" * /
2008-08-14 18:42:47 +00:00
2011-04-09 06:41:31 +00:00
# include <stdio.h>
# include <string.h>
# include <base/tl/sorted_array.h>
# include <engine/server/server.h>
# include "gamemodes/DDRace.h"
2010-08-23 19:37:27 +00:00
# include "score.h"
# include "score/file_score.h"
2010-11-16 13:44:16 +00:00
# if defined(CONF_SQL)
2010-08-26 13:27:36 +00:00
# include "score/sql_score.h"
2010-11-16 13:25:21 +00:00
# endif
2010-08-23 19:37:27 +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 ;
2011-01-29 00:59:50 +00:00
2010-05-29 07:25:38 +00:00
m_pController = 0 ;
m_VoteCloseTime = 0 ;
m_pVoteOptionFirst = 0 ;
m_pVoteOptionLast = 0 ;
2011-03-26 21:06:29 +00:00
m_NumVoteOptions = 0 ;
2010-05-29 07:25:38 +00:00
if ( Resetting = = NO_RESET )
2011-02-03 12:02:32 +00:00
{
2010-05-29 07:25:38 +00:00
m_pVoteOptionHeap = new CHeap ( ) ;
2011-02-23 21:39:53 +00:00
m_pScore = 0 ;
m_NumMutes = 0 ;
2011-02-03 12:02:32 +00:00
}
2011-04-09 06:41:31 +00:00
// DDRace Tunes
Tuning ( ) - > Set ( " gun_speed " , 1400 ) ;
Tuning ( ) - > Set ( " gun_curvature " , 0 ) ;
Tuning ( ) - > Set ( " shotgun_speed " , 500 ) ;
Tuning ( ) - > Set ( " shotgun_speeddiff " , 0 ) ;
Tuning ( ) - > Set ( " tune shotgun_curvature " , 0 ) ;
g_Config . m_SvHit = 1 ;
g_Config . m_SvEndlessDrag = 0 ;
g_Config . m_SvOldLaser = 0 ;
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 ;
2011-03-26 16:44:34 +00:00
CVoteOptionServer * pVoteOptionFirst = m_pVoteOptionFirst ;
CVoteOptionServer * pVoteOptionLast = m_pVoteOptionLast ;
2011-03-26 21:06:29 +00:00
int NumVoteOptions = m_NumVoteOptions ;
2010-05-29 07:25:38 +00:00
CTuningParams Tuning = m_Tuning ;
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 ) ;
m_pVoteOptionHeap = pVoteOptionHeap ;
m_pVoteOptionFirst = pVoteOptionFirst ;
m_pVoteOptionLast = pVoteOptionLast ;
2011-03-26 21:06:29 +00:00
m_NumVoteOptions = NumVoteOptions ;
2010-05-29 07:25:38 +00:00
m_Tuning = Tuning ;
2008-08-14 18:42:47 +00:00
}
2011-02-12 10:40:36 +00:00
class CCharacter * CGameContext : : GetPlayerChar ( int ClientID )
2008-10-20 23:00:46 +00:00
{
2011-02-12 10:40:36 +00:00
if ( ClientID < 0 | | ClientID > = MAX_CLIENTS | | ! m_apPlayers [ ClientID ] )
2008-10-20 23:00:46 +00:00
return 0 ;
2011-02-12 10:40:36 +00:00
return m_apPlayers [ ClientID ] - > GetCharacter ( ) ;
2008-10-20 23:00:46 +00:00
}
2011-02-13 05:35:13 +00:00
void CGameContext : : CreateDamageInd ( vec2 Pos , float Angle , int Amount , int Mask )
2008-08-14 18:42:47 +00:00
{
2011-02-13 06:47:51 +00:00
float a = 3 * 3.14159f / 2 + Angle ;
2008-08-14 18:42:47 +00:00
//float a = get_angle(dir);
2011-02-13 06:47:51 +00:00
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
{
2011-02-13 06:47:51 +00:00
float f = mix ( s , e , float ( i + 1 ) / float ( Amount + 2 ) ) ;
2011-02-13 05:35:13 +00:00
NETEVENT_DAMAGEIND * pEvent = ( NETEVENT_DAMAGEIND * ) m_Events . Create ( NETEVENTTYPE_DAMAGEIND , sizeof ( NETEVENT_DAMAGEIND ) , Mask ) ;
2011-02-12 10:40:36 +00:00
if ( pEvent )
2008-08-14 18:42:47 +00:00
{
2011-02-12 10:40:36 +00:00
pEvent - > m_X = ( int ) Pos . x ;
pEvent - > m_Y = ( int ) Pos . y ;
2011-02-13 06:47:51 +00:00
pEvent - > m_Angle = ( int ) ( f * 256.0f ) ;
2008-08-14 18:42:47 +00:00
}
}
}
2011-02-13 05:35:13 +00:00
void CGameContext : : CreateHammerHit ( vec2 Pos , int Mask )
2008-10-17 11:23:21 +00:00
{
// create the event
2011-02-13 05:35:13 +00:00
NETEVENT_HAMMERHIT * pEvent = ( NETEVENT_HAMMERHIT * ) m_Events . Create ( NETEVENTTYPE_HAMMERHIT , sizeof ( NETEVENT_HAMMERHIT ) , Mask ) ;
2011-02-12 10:40:36 +00:00
if ( pEvent )
2008-10-17 11:23:21 +00:00
{
2011-02-12 10:40:36 +00:00
pEvent - > m_X = ( int ) Pos . x ;
pEvent - > m_Y = ( int ) Pos . y ;
2008-10-17 11:23:21 +00:00
}
}
2011-04-09 06:41:31 +00:00
void CGameContext : : CreateExplosion ( vec2 Pos , int Owner , int Weapon , bool NoDamage , int ActivatedTeam , int Mask )
2008-08-14 18:42:47 +00:00
{
// create the event
2011-02-13 05:35:13 +00:00
NETEVENT_EXPLOSION * pEvent = ( NETEVENT_EXPLOSION * ) m_Events . Create ( NETEVENTTYPE_EXPLOSION , sizeof ( NETEVENT_EXPLOSION ) , Mask ) ;
2011-02-12 10:40:36 +00:00
if ( pEvent )
2008-08-14 18:42:47 +00:00
{
2011-02-12 10:40:36 +00:00
pEvent - > m_X = ( int ) Pos . x ;
pEvent - > m_Y = ( int ) Pos . y ;
2008-08-14 18:42:47 +00:00
}
2011-02-23 07:43:05 +00:00
/*
2010-05-29 07:25:38 +00:00
if ( ! NoDamage )
2008-08-14 18:42:47 +00:00
{
2011-02-23 07:43:05 +00:00
*/
2008-08-14 18:42:47 +00:00
// deal damage
2011-01-19 17:27:50 +00:00
CCharacter * apEnts [ MAX_CLIENTS ] ;
2010-05-29 07:25:38 +00:00
float Radius = 135.0f ;
float InnerRadius = 48.0f ;
2011-02-12 10:40:36 +00:00
int Num = m_World . FindEntities ( Pos , Radius , ( CEntity * * ) apEnts , MAX_CLIENTS , CGameWorld : : ENTTYPE_CHARACTER ) ;
2010-05-29 07:25:38 +00:00
for ( int i = 0 ; i < Num ; i + + )
2008-08-14 18:42:47 +00:00
{
2011-02-12 10:40:36 +00:00
vec2 Diff = apEnts [ i ] - > m_Pos - Pos ;
2011-01-29 00:59:50 +00:00
vec2 ForceDir ( 0 , 1 ) ;
2010-05-29 07:25:38 +00:00
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 )
2011-01-29 00:59:50 +00:00
if ( ( g_Config . m_SvHit | | NoDamage ) | | Owner = = apEnts [ i ] - > GetPlayer ( ) - > GetCID ( ) )
2010-08-29 02:00:21 +00:00
{
2011-01-29 00:59:50 +00:00
if ( Owner ! = - 1 & & apEnts [ i ] - > IsAlive ( ) & & ! apEnts [ i ] - > CanCollide ( Owner ) ) continue ;
if ( Owner = = - 1 & & ActivatedTeam ! = - 1 & & apEnts [ i ] - > IsAlive ( ) & & apEnts [ i ] - > Team ( ) ! = ActivatedTeam ) continue ;
2010-07-29 05:21:18 +00:00
apEnts [ i ] - > TakeDamage ( ForceDir * Dmg * 2 , ( int ) Dmg , Owner , Weapon ) ;
2010-08-29 02:00:21 +00:00
if ( ! g_Config . m_SvHit | | NoDamage ) break ;
2010-07-29 05:21:18 +00:00
}
2008-08-14 18:42:47 +00:00
}
2011-02-23 07:43:05 +00:00
//}
2008-08-14 18:42:47 +00:00
}
/*
2011-02-13 06:47:51 +00:00
void create_smoke ( vec2 Pos )
2008-08-14 18:42:47 +00:00
{
// create the event
2011-02-12 10:40:36 +00:00
EV_EXPLOSION * pEvent = ( EV_EXPLOSION * ) events . create ( EVENT_SMOKE , sizeof ( EV_EXPLOSION ) ) ;
if ( pEvent )
2008-08-14 18:42:47 +00:00
{
2011-02-13 06:47:51 +00:00
pEvent - > x = ( int ) Pos . x ;
pEvent - > y = ( int ) Pos . y ;
2008-08-14 18:42:47 +00:00
}
} */
2011-02-13 05:35:13 +00:00
void CGameContext : : CreatePlayerSpawn ( vec2 Pos , int Mask )
2008-08-14 18:42:47 +00:00
{
// create the event
2011-04-09 06:41:31 +00:00
NETEVENT_SPAWN * ev = ( NETEVENT_SPAWN * ) m_Events . Create ( NETEVENTTYPE_SPAWN , sizeof ( NETEVENT_SPAWN ) , Mask ) ;
2008-08-14 18:42:47 +00:00
if ( ev )
{
2011-02-12 10:40:36 +00:00
ev - > m_X = ( int ) Pos . x ;
ev - > m_Y = ( int ) Pos . y ;
2008-08-14 18:42:47 +00:00
}
}
2011-02-13 05:35:13 +00:00
void CGameContext : : CreateDeath ( vec2 Pos , int ClientID , int Mask )
2008-08-14 18:42:47 +00:00
{
// create the event
2011-02-13 05:35:13 +00:00
NETEVENT_DEATH * pEvent = ( NETEVENT_DEATH * ) m_Events . Create ( NETEVENTTYPE_DEATH , sizeof ( NETEVENT_DEATH ) , Mask ) ;
2011-02-12 10:40:36 +00:00
if ( pEvent )
2008-08-14 18:42:47 +00:00
{
2011-02-12 10:40:36 +00:00
pEvent - > m_X = ( int ) Pos . x ;
pEvent - > m_Y = ( int ) Pos . y ;
pEvent - > 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
{
2011-01-29 00:59:50 +00:00
if ( Sound < 0 )
2008-08-14 18:42:47 +00:00
return ;
// create a sound
2011-02-12 10:40:36 +00:00
NETEVENT_SOUNDWORLD * pEvent = ( NETEVENT_SOUNDWORLD * ) m_Events . Create ( NETEVENTTYPE_SOUNDWORLD , sizeof ( NETEVENT_SOUNDWORLD ) , Mask ) ;
if ( pEvent )
2008-08-14 18:42:47 +00:00
{
2011-02-12 10:40:36 +00:00
pEvent - > m_X = ( int ) Pos . x ;
pEvent - > m_Y = ( int ) Pos . y ;
pEvent - > 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
{
2011-01-29 00:59:50 +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 ;
2011-02-12 10:40:36 +00:00
Msg . m_SoundID = Sound ;
2010-05-29 07:25:38 +00:00
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 ;
2011-02-12 10:40:36 +00:00
Msg . m_ClientID = - 1 ;
2010-05-29 07:25:38 +00:00
Msg . m_pMessage = pText ;
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , To ) ;
2009-01-11 14:28:35 +00:00
}
2011-02-13 05:35:13 +00:00
void CGameContext : : SendChat ( int ChatterClientID , int Team , const char * pText , int SpamProtectionClientID )
2008-08-14 18:42:47 +00:00
{
2011-02-13 05:35:13 +00:00
if ( SpamProtectionClientID > = 0 & & SpamProtectionClientID < MAX_CLIENTS )
2010-12-07 17:44:23 +00:00
{
2011-02-23 21:39:53 +00:00
if ( ProcessSpamProtection ( SpamProtectionClientID ) )
2011-02-27 08:07:57 +00:00
{
SendChatTarget ( SpamProtectionClientID , " Muted text: " ) ;
SendChatTarget ( SpamProtectionClientID , pText ) ;
2010-11-10 21:42:29 +00:00
return ;
2011-02-27 08:07:57 +00:00
}
2010-12-07 17:44:23 +00:00
}
2010-11-10 21:42:29 +00:00
2011-04-09 06:41:31 +00:00
char aBuf [ 256 ] , aText [ 256 ] ;
2010-11-19 16:57:53 +00:00
str_copy ( aText , pText , sizeof ( aText ) ) ;
2011-02-12 10:40:36 +00:00
if ( ChatterClientID > = 0 & & ChatterClientID < MAX_CLIENTS )
2011-02-13 05:35:13 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %d:%d:%s: %s " , ChatterClientID , Team , Server ( ) - > ClientName ( ChatterClientID ) , aText ) ;
else if ( ChatterClientID = = - 2 )
2010-11-19 16:57:53 +00:00
{
str_format ( aBuf , sizeof ( aBuf ) , " ### %s " , aText ) ;
str_copy ( aText , aBuf , sizeof ( aText ) ) ;
2011-02-13 05:35:13 +00:00
ChatterClientID = - 1 ;
2010-11-19 16:57:53 +00:00
}
2008-08-14 18:42:47 +00:00
else
2010-11-19 16:57:53 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " *** %s " , aText ) ;
2010-08-17 22:06:00 +00:00
Console ( ) - > Print ( IConsole : : OUTPUT_LEVEL_ADDINFO , " chat " , aBuf ) ;
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 ;
2011-02-12 10:40:36 +00:00
Msg . m_ClientID = ChatterClientID ;
2011-04-09 06:41:31 +00:00
Msg . m_pMessage = aText ;
2010-05-29 07:25:38 +00:00
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , - 1 ) ;
2008-08-14 18:42:47 +00:00
}
else
{
2010-10-06 20:35:19 +00:00
CTeamsCore * Teams = & ( ( CGameControllerDDRace * ) m_pController ) - > m_Teams . m_Core ;
2010-05-29 07:25:38 +00:00
CNetMsg_Sv_Chat Msg ;
Msg . m_Team = 1 ;
2011-02-12 10:40:36 +00:00
Msg . m_ClientID = ChatterClientID ;
2011-04-09 06:41:31 +00:00
Msg . m_pMessage = aText ;
2011-01-29 00:59:50 +00:00
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 ) ;
2011-01-29 00:59:50 +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-10-06 20:35:19 +00:00
if ( m_apPlayers [ i ] ! = 0 ) {
if ( Team = = CHAT_SPEC ) {
if ( m_apPlayers [ i ] - > GetTeam ( ) = = CHAT_SPEC ) {
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL | MSGFLAG_NORECORD , i ) ;
}
} else {
2011-01-17 00:01:11 +00:00
if ( Teams - > Team ( i ) = = Team & & m_apPlayers [ i ] - > GetTeam ( ) ! = CHAT_SPEC ) {
2010-10-06 20:35:19 +00:00
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL | MSGFLAG_NORECORD , i ) ;
}
}
}
2008-08-14 18:42:47 +00:00
}
}
}
2011-02-12 10:40:36 +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 ;
2011-02-12 10:40:36 +00:00
Msg . m_ClientID = ClientID ;
2010-05-29 07:25:38 +00:00
Msg . m_Emoticon = Emoticon ;
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , - 1 ) ;
2008-08-14 18:42:47 +00:00
}
2011-02-12 10:40:36 +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 ;
2011-02-12 10:40:36 +00:00
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , ClientID ) ;
2008-08-14 18:42:47 +00:00
}
2011-02-12 10:40:36 +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 ;
2011-02-12 10:40:36 +00:00
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , ClientID ) ;
2008-08-14 18:42:47 +00:00
}
2011-01-29 00:59:50 +00:00
//
2011-03-25 09:26:59 +00:00
void CGameContext : : StartVote ( const char * pDesc , const char * pCommand , const char * pReason )
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
}
2011-01-29 00:59:50 +00:00
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 ) ) ;
2011-03-25 09:26:59 +00:00
str_copy ( m_aVoteReason , pReason , sizeof ( m_aVoteReason ) ) ;
2010-05-29 07:25:38 +00:00
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
}
2011-02-12 10:40:36 +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 ;
2011-03-25 09:26:59 +00:00
Msg . m_pReason = m_aVoteReason ;
2008-09-24 14:47:03 +00:00
}
else
{
2010-05-29 07:25:38 +00:00
Msg . m_Timeout = 0 ;
Msg . m_pDescription = " " ;
2011-03-25 09:26:59 +00:00
Msg . m_pReason = " " ;
2008-09-24 14:47:03 +00:00
}
2011-02-12 10:40:36 +00:00
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , ClientID ) ;
2008-09-24 14:47:03 +00:00
}
2011-02-12 10:40:36 +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 ) ;
2011-02-12 10:40:36 +00:00
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , ClientID ) ;
2011-01-29 00:59:50 +00:00
2010-05-29 07:25:38 +00:00
}
2011-02-12 10:40:36 +00:00
void CGameContext : : AbortVoteKickOnDisconnect ( int ClientID )
2010-05-29 07:25:38 +00:00
{
2011-02-12 10:40:36 +00:00
if ( m_VoteCloseTime & & ! str_comp_num ( m_aVoteCommand , " kick " , 5 ) & & str_toint ( & m_aVoteCommand [ 5 ] ) = = ClientID )
2010-05-29 07:25:38 +00:00
m_VoteCloseTime = - 1 ;
}
void CGameContext : : CheckPureTuning ( )
{
// might not be created yet during start up
if ( ! m_pController )
return ;
2011-01-29 00:59:50 +00:00
2010-05-29 07:25:38 +00:00
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
{
2011-01-29 00:59:50 +00:00
CTuningParams p ;
if ( mem_comp ( & p , & m_Tuning , sizeof ( p ) ) ! = 0 )
2008-09-24 14:47:03 +00:00
{
2010-08-17 22:06:00 +00:00
Console ( ) - > Print ( IConsole : : OUTPUT_LEVEL_STANDARD , " server " , " resetting tuning due to pure server " ) ;
2011-01-29 00:59:50 +00:00
m_Tuning = p ;
2008-09-24 14:47:03 +00:00
}
2011-01-29 00:59:50 +00:00
}
2008-09-24 14:47:03 +00:00
}
2011-02-12 10:40:36 +00:00
void CGameContext : : SendTuningParams ( int ClientID )
2008-10-21 17:26:32 +00:00
{
2010-05-29 07:25:38 +00:00
CheckPureTuning ( ) ;
2011-01-29 00:59:50 +00:00
2010-05-29 07:25:38 +00:00
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 ] ) ;
2011-02-12 10:40:36 +00:00
Server ( ) - > SendMsg ( & Msg , MSGFLAG_VITAL , ClientID ) ;
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 ( ) ;
2011-01-29 00:59:50 +00:00
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 ] )
2011-03-10 09:08:14 +00:00
{
2010-05-29 07:25:38 +00:00
m_apPlayers [ i ] - > Tick ( ) ;
2011-03-10 09:08:14 +00:00
m_apPlayers [ i ] - > PostTick ( ) ;
}
2008-08-14 18:42:47 +00:00
}
2011-01-29 00:59:50 +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
2011-03-28 18:11:28 +00:00
char aaBuf [ MAX_CLIENTS ] [ NETADDR_MAXSTRSIZE ] = { { 0 } } ;
2010-05-29 07:25:38 +00:00
for ( int i = 0 ; i < MAX_CLIENTS ; i + + )
if ( m_apPlayers [ i ] )
2011-03-28 18:11:28 +00:00
Server ( ) - > GetClientAddr ( i , aaBuf [ i ] , NETADDR_MAXSTRSIZE ) ;
2010-05-29 07:25:38 +00:00
bool aVoteChecked [ MAX_CLIENTS ] = { 0 } ;
for ( int i = 0 ; i < MAX_CLIENTS ; i + + )
2008-10-21 17:26:32 +00:00
{
2011-04-09 06:41:31 +00:00
//if(!m_apPlayers[i] || m_apPlayers[i]->GetTeam() == TEAM_SPECTATORS || aVoteChecked[i]) // don't count in votes by spectators
if ( ! m_apPlayers [ i ] | |
( g_Config . m_SvSpectatorVotes = = 0 & &
m_apPlayers [ i ] - > GetTeam ( ) = = TEAM_SPECTATORS ) | |
aVoteChecked [ i ] ) // don't count in votes by spectators if the admin doesn't want it
2010-05-29 07:25:38 +00:00
continue ;
2011-04-09 06:41:31 +00:00
if ( m_VoteKick & &
2010-09-14 16:58:18 +00:00
GetPlayerChar ( m_VoteCreator ) & & GetPlayerChar ( i ) & &
2011-04-09 06:41:31 +00:00
GetPlayerChar ( m_VoteCreator ) - > Team ( ) ! = GetPlayerChar ( i ) - > Team ( ) )
2010-05-29 07:25:38 +00:00
continue ;
int ActVote = m_apPlayers [ i ] - > m_Vote ;
int ActVotePos = m_apPlayers [ i ] - > m_VotePos ;
2011-01-29 00:59:50 +00:00
2010-05-29 07:25:38 +00:00
// 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
2011-04-09 06:41:31 +00:00
//if(Yes >= Total/2+1)
2011-02-12 20:31:42 +00:00
if ( Yes > Total / ( 100.0 / g_Config . m_SvVoteYesPercentage ) )
2010-05-29 07:25:38 +00:00
m_VoteEnforce = VOTE_ENFORCE_YES ;
2011-04-09 06:41:31 +00:00
//else if(No >= (Total+1)/2)
2011-02-12 20:31:42 +00:00
else if ( No > = Total - Total / ( 100.0 / g_Config . m_SvVoteYesPercentage ) )
2010-05-29 07:25:38 +00:00
m_VoteEnforce = VOTE_ENFORCE_NO ;
2011-02-12 20:31:42 +00:00
m_VoteWillPass = Yes > ( Yes + No ) / ( 100.0 / g_Config . m_SvVoteYesPercentage ) ;
2008-09-24 14:47:03 +00:00
}
2011-04-09 06:41:31 +00:00
2011-02-12 20:31:42 +00:00
if ( time_get ( ) > m_VoteCloseTime & & ! g_Config . m_SvVoteMajority )
m_VoteEnforce = ( m_VoteWillPass ) ? VOTE_ENFORCE_YES : VOTE_ENFORCE_NO ;
2010-05-29 07:25:38 +00:00
if ( m_VoteEnforce = = VOTE_ENFORCE_YES )
{
2011-03-17 22:07:43 +00:00
Console ( ) - > ExecuteLine ( m_aVoteCommand , IConsole : : CONSOLELEVEL_CONFIG , - 1 , CServer : : SendRconLineAuthed , Server ( ) , SendChatResponseAll , this ) ;
2010-10-11 11:10:39 +00:00
EndVote ( ) ;
SendChat ( - 1 , CGameContext : : CHAT_ALL , " Vote passed " ) ;
2011-01-29 00:59:50 +00:00
2010-05-29 07:25:38 +00:00
if ( m_apPlayers [ m_VoteCreator ] )
2011-03-10 09:08:14 +00:00
m_apPlayers [ m_VoteCreator ] - > m_LastVoteCall = 0 ;
2010-05-29 07:25:38 +00:00
}
2010-10-11 11:10:39 +00:00
else if ( m_VoteEnforce = = VOTE_ENFORCE_YES_ADMIN )
{
char aBuf [ 64 ] ;
2011-02-12 20:31:42 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " Vote passed enforced by '%s' " , ( m_VoteEnforcer < 0 ) ? " Server Administrator " : Server ( ) - > ClientName ( m_VoteEnforcer ) ) ;
2010-10-11 11:10:39 +00:00
Console ( ) - > ExecuteLine ( m_aVoteCommand , 3 , - 1 , CServer : : SendRconLineAuthed , Server ( ) , SendChatResponseAll , this ) ;
SendChat ( - 1 , CGameContext : : CHAT_ALL , aBuf ) ;
EndVote ( ) ;
m_VoteEnforcer = - 1 ;
}
else if ( m_VoteEnforce = = VOTE_ENFORCE_NO_ADMIN )
{
char aBuf [ 64 ] ;
2011-02-12 20:31:42 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " Vote failed enforced by '%s' " , ( m_VoteEnforcer < 0 ) ? " Server Administrator " : Server ( ) - > ClientName ( m_VoteEnforcer ) ) ;
2010-10-11 11:10:39 +00:00
EndVote ( ) ;
SendChat ( - 1 , CGameContext : : CHAT_ALL , aBuf ) ;
}
2011-04-09 06:41:31 +00:00
//else if(m_VoteEnforce == VOTE_ENFORCE_NO || time_get() > m_VoteCloseTime)
2011-02-12 20:31:42 +00:00
else if ( m_VoteEnforce = = VOTE_ENFORCE_NO | | ( time_get ( ) > m_VoteCloseTime & & g_Config . m_SvVoteMajority ) )
2010-05-29 07:25:38 +00:00
{
EndVote ( ) ;
SendChat ( - 1 , CGameContext : : CHAT_ALL , " Vote failed " ) ;
}
else if ( m_VoteUpdate )
{
m_VoteUpdate = false ;
SendVoteStatus ( - 1 , Total , Yes , No ) ;
}
}
}
2011-01-29 00:59:50 +00:00
2011-02-23 21:39:53 +00:00
for ( int i = 0 ; i < m_NumMutes ; i + + )
{
if ( m_aMutes [ i ] . m_Expire < = Server ( ) - > Tick ( ) )
{
m_NumMutes - - ;
m_aMutes [ i ] = m_aMutes [ m_NumMutes ] ;
}
}
2010-11-22 20:43:22 +00:00
2011-02-23 21:39:53 +00:00
if ( Server ( ) - > Tick ( ) % ( g_Config . m_SvAnnouncementInterval * Server ( ) - > TickSpeed ( ) * 60 ) = = 0 )
2010-11-22 20:43:22 +00:00
{
2011-02-23 21:39:53 +00:00
char * Line = ( ( CServer * ) Server ( ) ) - > GetAnnouncementLine ( g_Config . m_SvAnnouncementFileName ) ;
if ( Line )
SendChat ( - 1 , CGameContext : : CHAT_ALL , Line ) ;
}
if ( Collision ( ) - > m_NumSwitchers > 0 )
for ( int i = 0 ; i < Collision ( ) - > m_NumSwitchers + 1 ; + + i )
2010-11-22 20:43:22 +00:00
{
2011-02-23 21:39:53 +00:00
for ( int j = 0 ; j < 16 ; + + j )
2010-11-22 20:43:22 +00:00
{
2011-02-23 21:39:53 +00:00
if ( Collision ( ) - > m_pSwitchers [ i ] . m_EndTick [ j ] < = Server ( ) - > Tick ( ) & & Collision ( ) - > m_pSwitchers [ i ] . m_Type [ j ] = = TILE_SWITCHTIMEDOPEN )
{
Collision ( ) - > m_pSwitchers [ i ] . m_Status [ j ] = false ;
Collision ( ) - > m_pSwitchers [ i ] . m_EndTick [ j ] = 0 ;
Collision ( ) - > m_pSwitchers [ i ] . m_Type [ j ] = TILE_SWITCHCLOSE ;
}
else if ( Collision ( ) - > m_pSwitchers [ i ] . m_EndTick [ j ] < = Server ( ) - > Tick ( ) & & Collision ( ) - > m_pSwitchers [ i ] . m_Type [ j ] = = TILE_SWITCHTIMEDCLOSE )
{
Collision ( ) - > m_pSwitchers [ i ] . m_Status [ j ] = true ;
Collision ( ) - > m_pSwitchers [ i ] . m_EndTick [ j ] = 0 ;
Collision ( ) - > m_pSwitchers [ i ] . m_Type [ j ] = TILE_SWITCHOPEN ;
}
2010-11-22 20:43:22 +00:00
}
}
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 + + )
{
CNetObj_PlayerInput Input = { 0 } ;
Input . m_Direction = ( i & 1 ) ? - 1 : 1 ;
m_apPlayers [ MAX_CLIENTS - i - 1 ] - > OnPredictedInput ( & Input ) ;
}
}
2011-01-29 00:59:50 +00:00
# endif
2010-05-29 07:25:38 +00:00
}
// 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 ) ;
}
2011-02-12 10:40:36 +00:00
void CGameContext : : OnClientEnter ( int ClientID )
2010-05-29 07:25:38 +00:00
{
//world.insert_entity(&players[client_id]);
2011-02-12 10:40:36 +00:00
m_apPlayers [ ClientID ] - > Respawn ( ) ;
2010-09-26 15:18:56 +00:00
// init the player
2011-02-13 05:35:13 +00:00
Score ( ) - > PlayerData ( ClientID ) - > Reset ( ) ;
Score ( ) - > LoadScore ( ClientID ) ;
Score ( ) - > PlayerData ( ClientID ) - > m_CurrentTime = Score ( ) - > PlayerData ( ClientID ) - > m_BestTime ;
m_apPlayers [ ClientID ] - > m_Score = ( Score ( ) - > PlayerData ( ClientID ) - > m_BestTime ) ? Score ( ) - > PlayerData ( ClientID ) - > m_BestTime : - 9999 ;
2010-09-26 21:31:33 +00:00
2011-02-13 05:35:13 +00:00
if ( ( ( CServer * ) Server ( ) ) - > m_aPrevStates [ ClientID ] < CServer : : CClient : : STATE_INGAME )
2011-01-20 20:25:09 +00:00
{
char aBuf [ 512 ] ;
2011-02-13 05:35:13 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " '%s' entered and joined the %s " , Server ( ) - > ClientName ( ClientID ) , m_pController - > GetTeamName ( m_apPlayers [ ClientID ] - > GetTeam ( ) ) ) ;
2011-04-09 06:41:31 +00:00
SendChat ( - 1 , CGameContext : : CHAT_ALL , aBuf ) ;
2011-01-20 20:25:09 +00:00
2011-02-13 05:35:13 +00:00
SendChatTarget ( ClientID , " DDRace Mod. Version: " GAME_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 " ) ;
SendChatTarget ( ClientID , " Note This is an Alpha release, just for testing, your feedback is important!! " ) ;
2011-01-20 20:25:09 +00:00
2011-02-13 05:35:13 +00:00
if ( g_Config . m_SvWelcome [ 0 ] ! = 0 ) SendChatTarget ( ClientID , g_Config . m_SvWelcome ) ;
//str_format(aBuf, sizeof(aBuf), "team_join player='%d:%s' team=%d", ClientID, Server()->ClientName(ClientID), m_apPlayers[ClientID]->GetTeam());
2010-05-29 07:25:38 +00:00
2011-01-20 20:25:09 +00:00
Console ( ) - > Print ( IConsole : : OUTPUT_LEVEL_DEBUG , " game " , aBuf ) ;
}
2010-05-29 07:25:38 +00:00
m_VoteUpdate = true ;
}
2011-02-12 10:40:36 +00:00
void CGameContext : : OnClientConnected ( int ClientID )
2010-05-29 07:25:38 +00:00
{
// Check which team the player should be on
2011-02-12 10:40:36 +00:00
const int StartTeam = g_Config . m_SvTournamentMode ? TEAM_SPECTATORS : m_pController - > GetAutoTeam ( ClientID ) ;
2010-05-29 07:25:38 +00:00
2011-02-12 10:40:36 +00:00
m_apPlayers [ ClientID ] = new ( ClientID ) CPlayer ( this , ClientID , StartTeam ) ;
2010-05-29 07:25:38 +00:00
//players[client_id].init(client_id);
//players[client_id].client_id = client_id;
2011-01-29 00:59:50 +00:00
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 )
{
2011-02-12 10:40:36 +00:00
if ( ClientID > = MAX_CLIENTS - g_Config . m_DbgDummies )
2010-05-29 07:25:38 +00:00
return ;
}
# endif
// send active vote
if ( m_VoteCloseTime )
2011-02-12 10:40:36 +00:00
SendVoteSet ( ClientID ) ;
2010-05-29 07:25:38 +00:00
// send motd
CNetMsg_Sv_Motd Msg ;
Msg . m_pMessage = g_Config . m_SvMotd ;
2011-02-12 10:40:36 +00:00
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , ClientID ) ;
2010-05-29 07:25:38 +00:00
}
2011-02-14 18:41:32 +00:00
void CGameContext : : OnClientDrop ( int ClientID , const char * pReason )
2010-05-29 07:25:38 +00:00
{
2011-02-12 10:40:36 +00:00
AbortVoteKickOnDisconnect ( ClientID ) ;
2011-02-14 18:41:32 +00:00
m_apPlayers [ ClientID ] - > OnDisconnect ( pReason ) ;
2011-02-12 10:40:36 +00:00
delete m_apPlayers [ ClientID ] ;
m_apPlayers [ ClientID ] = 0 ;
2011-01-29 00:59:50 +00:00
2010-07-29 05:21:18 +00:00
//(void)m_pController->CheckTeamBalance();
2010-05-29 07:25:38 +00:00
m_VoteUpdate = true ;
2011-03-10 09:08:14 +00:00
// update spectator modes
for ( int i = 0 ; i < MAX_CLIENTS ; + + i )
{
if ( m_apPlayers [ i ] & & m_apPlayers [ i ] - > m_SpectatorID = = ClientID )
m_apPlayers [ i ] - > m_SpectatorID = SPEC_FREEVIEW ;
}
2010-05-29 07:25:38 +00:00
}
2011-02-12 10:40:36 +00:00
void CGameContext : : OnMessage ( int MsgID , CUnpacker * pUnpacker , int ClientID )
2010-05-29 07:25:38 +00:00
{
2011-02-12 10:40:36 +00:00
void * pRawMsg = m_NetObjHandler . SecureUnpackMsg ( MsgID , pUnpacker ) ;
CPlayer * pPlayer = m_apPlayers [ ClientID ] ;
2011-01-29 00:59:50 +00:00
2010-05-29 07:25:38 +00:00
if ( ! pRawMsg )
{
2010-08-17 22:06:00 +00:00
char aBuf [ 256 ] ;
2011-02-12 10:40:36 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " dropped weird message '%s' (%d), failed on '%s' " , m_NetObjHandler . GetMsgName ( MsgID ) , MsgID , m_NetObjHandler . FailedMsgOn ( ) ) ;
2011-03-31 19:46:01 +00:00
Console ( ) - > Print ( IConsole : : OUTPUT_LEVEL_DEBUG , " server " , aBuf ) ;
2010-05-29 07:25:38 +00:00
return ;
}
2011-01-29 00:59:50 +00:00
2011-02-12 10:40:36 +00:00
if ( MsgID = = NETMSGTYPE_CL_SAY )
2010-05-29 07:25:38 +00:00
{
CNetMsg_Cl_Say * pMsg = ( CNetMsg_Cl_Say * ) pRawMsg ;
2010-10-07 12:10:49 +00:00
int Team = pMsg - > m_Team ;
2011-04-09 06:41:31 +00:00
/*if(Team)
2011-02-12 10:40:36 +00:00
Team = pPlayer - > GetTeam ( ) ;
2011-01-29 00:59:50 +00:00
else
Team = CGameContext : : CHAT_ALL ;
2011-03-10 09:08:14 +00:00
if ( g_Config . m_SvSpamprotection & & pPlayer - > m_LastChat & & pPlayer - > m_LastChat + Server ( ) - > TickSpeed ( ) > Server ( ) - > Tick ( ) )
2011-01-29 00:59:50 +00:00
return ;
2011-04-09 06:41:31 +00:00
pPlayer - > m_LastChat = Server ( ) - > Tick ( ) ; */
int GameTeam = ( ( CGameControllerDDRace * ) m_pController ) - > m_Teams . m_Core . Team ( pPlayer - > GetCID ( ) ) ;
2011-02-23 13:55:27 +00:00
if ( Team )
2011-04-09 06:41:31 +00:00
Team = ( ( pPlayer - > GetTeam ( ) = = - 1 ) ? CHAT_SPEC : GameTeam ) ;
2011-02-23 13:55:27 +00:00
else
2010-10-07 12:10:49 +00:00
Team = CHAT_ALL ;
2010-08-20 20:40:12 +00:00
2010-09-16 21:26:03 +00:00
if ( str_length ( pMsg - > m_pMessage ) > 370 )
{
2011-02-13 05:35:13 +00:00
SendChatTarget ( ClientID , " Your Message is too long " ) ;
2010-07-30 12:50:09 +00:00
return ;
}
2010-08-20 20:40:12 +00:00
2010-05-29 07:25:38 +00:00
// check for invalid chars
unsigned char * pMessage = ( unsigned char * ) pMsg - > m_pMessage ;
while ( * pMessage )
{
if ( * pMessage < 32 )
* pMessage = ' ' ;
pMessage + + ;
}
2010-09-09 13:32:14 +00:00
if ( pMsg - > m_pMessage [ 0 ] = = ' / ' )
{
2010-10-10 22:40:07 +00:00
ChatResponseInfo Info ;
Info . m_GameContext = this ;
2011-02-13 05:35:13 +00:00
Info . m_To = ClientID ;
2010-08-20 20:40:12 +00:00
2011-04-09 06:41:31 +00:00
Console ( ) - > ExecuteLine ( pMsg - > m_pMessage + 1 ,
( ( CServer * ) Server ( ) ) - > m_aClients [ ClientID ] . m_Authed ,
ClientID , CServer : : SendRconLineAuthed , Server ( ) ,
SendChatResponse , & Info ) ;
Console ( ) - > Print ( IConsole : : OUTPUT_LEVEL_ADDINFO , " chat " ,
pMsg - > m_pMessage ) ;
2010-09-09 13:32:14 +00:00
}
2010-09-16 21:26:03 +00:00
else
2011-02-13 05:35:13 +00:00
SendChat ( ClientID , Team , pMsg - > m_pMessage , ClientID ) ;
2010-09-08 16:22:11 +00:00
}
2011-02-12 10:40:36 +00:00
else if ( MsgID = = NETMSGTYPE_CL_CALLVOTE )
2010-05-29 07:25:38 +00:00
{
2011-03-10 09:08:14 +00:00
if ( g_Config . m_SvSpamprotection & & pPlayer - > m_LastVoteTry & & pPlayer - > m_LastVoteTry + Server ( ) - > TickSpeed ( ) * 3 > Server ( ) - > Tick ( ) )
2010-05-29 07:25:38 +00:00
return ;
int64 Now = Server ( ) - > Tick ( ) ;
2011-03-10 09:08:14 +00:00
pPlayer - > m_LastVoteTry = Now ;
2011-04-09 06:41:31 +00:00
//if(pPlayer->GetTeam() == TEAM_SPECTATORS)
if ( g_Config . m_SvSpectatorVotes = = 0 & & pPlayer - > GetTeam ( ) = = TEAM_SPECTATORS )
2010-08-06 19:03:38 +00:00
{
2011-02-12 10:40:36 +00:00
SendChatTarget ( ClientID , " Spectators aren't allowed to start a vote. " ) ;
2010-08-06 19:03:38 +00:00
return ;
}
2010-05-29 07:25:38 +00:00
if ( m_VoteCloseTime )
{
2011-02-12 10:40:36 +00:00
SendChatTarget ( ClientID , " Wait for current vote to end before calling a new one. " ) ;
2010-05-29 07:25:38 +00:00
return ;
}
2011-01-29 00:59:50 +00:00
2011-03-10 09:08:14 +00:00
int Timeleft = pPlayer - > m_LastVoteCall + Server ( ) - > TickSpeed ( ) * 60 - Now ;
if ( pPlayer - > m_LastVoteCall & & Timeleft > 0 )
2010-05-29 07:25:38 +00:00
{
char aChatmsg [ 512 ] = { 0 } ;
str_format ( aChatmsg , sizeof ( aChatmsg ) , " You must wait %d seconds before making another vote " , ( Timeleft / Server ( ) - > TickSpeed ( ) ) + 1 ) ;
2011-02-12 10:40:36 +00:00
SendChatTarget ( ClientID , aChatmsg ) ;
2010-05-29 07:25:38 +00:00
return ;
}
2011-01-29 00:59:50 +00:00
2010-05-29 07:25:38 +00:00
char aChatmsg [ 512 ] = { 0 } ;
2011-03-26 16:44:34 +00:00
char aDesc [ VOTE_DESC_LENGTH ] = { 0 } ;
char aCmd [ VOTE_CMD_LENGTH ] = { 0 } ;
2010-05-29 07:25:38 +00:00
CNetMsg_Cl_CallVote * pMsg = ( CNetMsg_Cl_CallVote * ) pRawMsg ;
2011-03-25 09:26:59 +00:00
const char * pReason = pMsg - > m_Reason [ 0 ] ? pMsg - > m_Reason : " No reason given " ;
2010-05-29 07:25:38 +00:00
if ( str_comp_nocase ( pMsg - > m_Type , " option " ) = = 0 )
{
2011-03-26 16:44:34 +00:00
CVoteOptionServer * pOption = m_pVoteOptionFirst ;
2011-02-23 13:55:27 +00:00
static int64 LastMapVote = 0 ;
2010-05-29 07:25:38 +00:00
while ( pOption )
2008-10-21 17:26:32 +00:00
{
2011-03-25 08:49:21 +00:00
if ( str_comp_nocase ( pMsg - > m_Value , pOption - > m_aDescription ) = = 0 )
2010-05-29 07:25:38 +00:00
{
2011-01-21 13:40:39 +00:00
if ( ! Console ( ) - > LineIsValid ( pOption - > m_aCommand ) )
{
2011-02-13 05:35:13 +00:00
SendChatTarget ( ClientID , " Invalid option " ) ;
2011-01-21 13:40:39 +00:00
return ;
}
2011-04-09 06:41:31 +00:00
if ( m_apPlayers [ ClientID ] - > m_Authed < IConsole : : CONSOLELEVEL_ADMIN & & strncmp ( pOption - > m_aCommand , " sv_map " , 7 ) = = 0 & & time_get ( ) < LastMapVote + ( time_freq ( ) * g_Config . m_SvVoteMapTimeDelay ) )
{
char chatmsg [ 512 ] = { 0 } ;
str_format ( chatmsg , sizeof ( chatmsg ) , " There's a %d second delay between map-votes,Please wait %d Second(s) " , g_Config . m_SvVoteMapTimeDelay , ( ( LastMapVote + ( g_Config . m_SvVoteMapTimeDelay * time_freq ( ) ) ) / time_freq ( ) ) - ( time_get ( ) / time_freq ( ) ) ) ;
SendChatTarget ( ClientID , chatmsg ) ;
2010-08-20 20:40:12 +00:00
2011-04-09 06:41:31 +00:00
return ;
}
2011-03-25 09:26:59 +00:00
str_format ( aChatmsg , sizeof ( aChatmsg ) , " '%s' called vote to change server option '%s' (%s) " , Server ( ) - > ClientName ( ClientID ) ,
pOption - > m_aDescription , pReason ) ;
str_format ( aDesc , sizeof ( aDesc ) , " %s " , pOption - > m_aDescription ) ;
2010-05-29 07:25:38 +00:00
str_format ( aCmd , sizeof ( aCmd ) , " %s " , pOption - > m_aCommand ) ;
2011-02-23 13:55:27 +00:00
LastMapVote = time_get ( ) ;
2010-05-29 07:25:38 +00:00
break ;
}
pOption = pOption - > m_pNext ;
}
2011-01-29 00:59:50 +00:00
2010-05-29 07:25:38 +00:00
if ( ! pOption )
{
2011-04-09 06:41:31 +00:00
if ( pPlayer - > m_Authed < IConsole : : CONSOLELEVEL_ADMIN ) // allow admins to call any vote they want
2010-10-11 09:18:44 +00:00
{
str_format ( aChatmsg , sizeof ( aChatmsg ) , " '%s' isn't an option on this server " , pMsg - > m_Value ) ;
2011-02-13 05:35:13 +00:00
SendChatTarget ( ClientID , aChatmsg ) ;
2010-10-11 09:18:44 +00:00
return ;
}
else
{
2011-02-13 05:35:13 +00:00
str_format ( aChatmsg , sizeof ( aChatmsg ) , " '%s' called vote to change server option '%s' " , Server ( ) - > ClientName ( ClientID ) , pMsg - > m_Value ) ;
2010-10-11 09:18:44 +00:00
str_format ( aDesc , sizeof ( aDesc ) , " %s " , pMsg - > m_Value ) ;
str_format ( aCmd , sizeof ( aCmd ) , " %s " , pMsg - > m_Value ) ;
}
2008-10-21 17:26:32 +00:00
}
2011-01-29 00:59:50 +00:00
2011-02-23 13:55:27 +00:00
LastMapVote = time_get ( ) ;
2010-09-08 16:22:11 +00:00
m_VoteKick = false ;
2010-05-29 07:25:38 +00:00
}
else if ( str_comp_nocase ( pMsg - > m_Type , " kick " ) = = 0 )
{
2011-04-09 06:41:31 +00:00
if ( m_apPlayers [ ClientID ] - > m_Authed = = IConsole : : CONSOLELEVEL_USER & & time_get ( ) < m_apPlayers [ ClientID ] - > m_Last_KickVote + ( time_freq ( ) * 5 ) )
2011-01-29 00:59:50 +00:00
return ;
2011-04-09 06:41:31 +00:00
else if ( m_apPlayers [ ClientID ] - > m_Authed = = IConsole : : CONSOLELEVEL_USER & & 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 } ;
2010-09-16 22:38:39 +00:00
str_format ( chatmsg , sizeof ( chatmsg ) , " There's a %d second wait time between kick votes for each player please wait %d second(s) " ,
2010-07-30 12:50:09 +00:00
g_Config . m_SvVoteKickTimeDelay ,
2011-02-13 05:35:13 +00:00
( ( 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
) ;
2011-02-13 05:35:13 +00:00
SendChatTarget ( ClientID , chatmsg ) ;
m_apPlayers [ ClientID ] - > m_Last_KickVote = time_get ( ) ;
2010-07-29 19:55:33 +00:00
return ;
}
2011-04-09 06:41:31 +00:00
//else if(!g_Config.m_SvVoteKick)
else if ( ! g_Config . m_SvVoteKick & & pPlayer - > m_Authed < IConsole : : CONSOLELEVEL_ADMIN ) // allow admins to call kick votes even if they are forbidden
2008-10-21 17:26:32 +00:00
{
2011-02-12 10:40:36 +00:00
SendChatTarget ( ClientID , " Server does not allow voting to kick players " ) ;
2011-02-13 05:35:13 +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
}
2011-03-04 16:35:50 +00:00
if ( g_Config . m_SvVoteKickMin )
{
int PlayerNum = 0 ;
for ( int i = 0 ; i < MAX_CLIENTS ; + + i )
if ( m_apPlayers [ i ] & & m_apPlayers [ i ] - > GetTeam ( ) ! = TEAM_SPECTATORS )
+ + PlayerNum ;
if ( PlayerNum < g_Config . m_SvVoteKickMin )
{
str_format ( aChatmsg , sizeof ( aChatmsg ) , " Kick voting requires %d players on the server " , g_Config . m_SvVoteKickMin ) ;
SendChatTarget ( ClientID , aChatmsg ) ;
return ;
}
}
2011-01-29 00:59:50 +00:00
2011-02-12 10:40:36 +00:00
int KickID = str_toint ( pMsg - > m_Value ) ;
if ( KickID < 0 | | KickID > = MAX_CLIENTS | | ! m_apPlayers [ KickID ] )
2010-05-29 07:25:38 +00:00
{
2011-02-12 10:40:36 +00:00
SendChatTarget ( ClientID , " Invalid client id to kick " ) ;
2010-05-29 07:25:38 +00:00
return ;
}
2011-02-12 10:40:36 +00:00
if ( KickID = = ClientID )
2010-06-02 02:42:17 +00:00
{
2011-02-12 10:40:36 +00:00
SendChatTarget ( ClientID , " You cant kick yourself " ) ;
2010-06-02 02:42:17 +00:00
return ;
}
2011-04-09 06:41:31 +00:00
//if(Server()->IsAuthed(KickID))
if ( m_apPlayers [ KickID ] - > m_Authed > 0 & & m_apPlayers [ KickID ] - > m_Authed > = pPlayer - > m_Authed )
2010-06-02 02:42:17 +00:00
{
2011-02-12 10:40:36 +00:00
SendChatTarget ( ClientID , " You cant kick admins " ) ;
2011-02-13 05:35:13 +00:00
m_apPlayers [ ClientID ] - > m_Last_KickVote = time_get ( ) ;
2010-06-02 02:42:17 +00:00
char aBufKick [ 128 ] ;
2011-02-12 10:40:36 +00:00
str_format ( aBufKick , sizeof ( aBufKick ) , " '%s' called for vote to kick you " , Server ( ) - > ClientName ( ClientID ) ) ;
SendChatTarget ( KickID , aBufKick ) ;
2010-06-02 02:42:17 +00:00
return ;
}
2011-01-29 00:59:50 +00:00
2011-04-09 06:41:31 +00:00
if ( GetPlayerChar ( ClientID ) & & GetPlayerChar ( KickID ) & & GetPlayerChar ( ClientID ) - > Team ( ) ! = GetPlayerChar ( KickID ) - > Team ( ) )
2010-09-16 21:26:03 +00:00
{
2011-02-13 05:35:13 +00:00
SendChatTarget ( ClientID , " You can kick only your team member " ) ;
m_apPlayers [ ClientID ] - > m_Last_KickVote = time_get ( ) ;
2010-09-08 16:22:11 +00:00
return ;
}
2011-04-09 06:41:31 +00:00
2011-02-12 10:40:36 +00:00
str_format ( aChatmsg , sizeof ( aChatmsg ) , " '%s' called for vote to kick '%s' (%s) " , Server ( ) - > ClientName ( ClientID ) , Server ( ) - > ClientName ( KickID ) , pReason ) ;
str_format ( aDesc , sizeof ( aDesc ) , " Kick '%s' " , Server ( ) - > ClientName ( KickID ) ) ;
2011-01-29 00:59:50 +00:00
if ( ! g_Config . m_SvVoteKickBantime )
2011-02-12 10:40:36 +00:00
str_format ( aCmd , sizeof ( aCmd ) , " kick %d Kicked by vote " , KickID ) ;
2010-05-29 07:25:38 +00:00
else
{
2011-03-28 18:11:28 +00:00
char aAddrStr [ NETADDR_MAXSTRSIZE ] = { 0 } ;
Server ( ) - > GetClientAddr ( KickID , aAddrStr , sizeof ( aAddrStr ) ) ;
str_format ( aCmd , sizeof ( aCmd ) , " ban %s %d Banned by vote " , aAddrStr , g_Config . m_SvVoteKickBantime ) ;
Console ( ) - > Print ( IConsole : : OUTPUT_LEVEL_STANDARD , " server " , aCmd ) ;
2010-05-29 07:25:38 +00:00
}
2011-02-13 05:35:13 +00:00
m_apPlayers [ ClientID ] - > m_Last_KickVote = time_get ( ) ;
2010-09-08 16:22:11 +00:00
m_VoteKick = true ;
2010-05-29 07:25:38 +00:00
}
2011-03-26 15:56:59 +00:00
else if ( str_comp_nocase ( pMsg - > m_Type , " spectate " ) = = 0 )
{
if ( ! g_Config . m_SvVoteSpectate )
{
SendChatTarget ( ClientID , " Server does not allow voting to move players to spectators " ) ;
return ;
}
int SpectateID = str_toint ( pMsg - > m_Value ) ;
if ( SpectateID < 0 | | SpectateID > = MAX_CLIENTS | | ! m_apPlayers [ SpectateID ] | | m_apPlayers [ SpectateID ] - > GetTeam ( ) = = TEAM_SPECTATORS )
{
SendChatTarget ( ClientID , " Invalid client id to move " ) ;
return ;
}
if ( SpectateID = = ClientID )
{
SendChatTarget ( ClientID , " You cant move yourself " ) ;
return ;
}
str_format ( aChatmsg , sizeof ( aChatmsg ) , " '%s' called for vote to move '%s' to spectators (%s) " , Server ( ) - > ClientName ( ClientID ) , Server ( ) - > ClientName ( SpectateID ) , pReason ) ;
str_format ( aDesc , sizeof ( aDesc ) , " move '%s' to spectators " , Server ( ) - > ClientName ( SpectateID ) ) ;
str_format ( aCmd , sizeof ( aCmd ) , " set_team %d -1 " , SpectateID ) ;
}
2011-01-29 00:59:50 +00:00
2010-05-29 07:25:38 +00:00
if ( aCmd [ 0 ] )
{
SendChat ( - 1 , CGameContext : : CHAT_ALL , aChatmsg ) ;
2011-03-25 09:26:59 +00:00
StartVote ( aDesc , aCmd , pReason ) ;
2011-02-12 10:40:36 +00:00
pPlayer - > m_Vote = 1 ;
pPlayer - > m_VotePos = m_VotePos = 1 ;
m_VoteCreator = ClientID ;
2011-03-10 09:08:14 +00:00
pPlayer - > m_LastVoteCall = Now ;
2010-05-29 07:25:38 +00:00
}
}
2011-02-12 10:40:36 +00:00
else if ( MsgID = = NETMSGTYPE_CL_VOTE )
2010-05-29 07:25:38 +00:00
{
if ( ! m_VoteCloseTime )
return ;
2011-02-12 10:40:36 +00:00
if ( pPlayer - > m_Vote = = 0 )
2010-05-29 07:25:38 +00:00
{
CNetMsg_Cl_Vote * pMsg = ( CNetMsg_Cl_Vote * ) pRawMsg ;
if ( ! pMsg - > m_Vote )
return ;
2011-02-12 10:40:36 +00:00
pPlayer - > m_Vote = pMsg - > m_Vote ;
pPlayer - > m_VotePos = + + m_VotePos ;
2010-05-29 07:25:38 +00:00
m_VoteUpdate = true ;
2008-09-25 12:23:44 +00:00
}
2008-09-24 14:47:03 +00:00
}
2011-02-12 10:40:36 +00:00
else if ( MsgID = = NETMSGTYPE_CL_SETTEAM & & ! m_World . m_Paused )
2010-05-29 07:25:38 +00:00
{
CNetMsg_Cl_SetTeam * pMsg = ( CNetMsg_Cl_SetTeam * ) pRawMsg ;
2011-01-29 00:59:50 +00:00
2011-04-09 06:41:31 +00:00
//if(pPlayer->GetTeam() == pMsg->m_Team || (g_Config.m_SvSpamprotection && pPlayer->m_LastSetTeam && pPlayer->m_LastSetTeam+Server()->TickSpeed()*3 > Server()->Tick()))
if ( pPlayer - > GetTeam ( ) = = pMsg - > m_Team | | ( g_Config . m_SvSpamprotection & & pPlayer - > m_LastSetTeam & & pPlayer - > m_LastSetTeam + Server ( ) - > TickSpeed ( ) * g_Config . m_SvTeamChangeDelay > Server ( ) - > Tick ( ) ) )
2010-05-29 07:25:38 +00:00
return ;
// Switch team on given client and kill/respawn him
2011-02-12 10:40:36 +00:00
if ( m_pController - > CanJoinTeam ( pMsg - > m_Team , ClientID ) )
2010-05-29 07:25:38 +00:00
{
2011-04-09 06:41:31 +00:00
//if(m_pController->CanChangeTeam(pPlayer, pMsg->m_Team))
if ( pPlayer - > GetTeam ( ) = = - 1 & & pPlayer - > m_InfoSaved )
2011-02-13 05:35:13 +00:00
SendChatTarget ( ClientID , " Use /pause first then you can kill " ) ;
2011-01-29 00:59:50 +00:00
{
2011-03-10 09:08:14 +00:00
pPlayer - > m_LastSetTeam = Server ( ) - > Tick ( ) ;
2011-02-12 10:40:36 +00:00
if ( pPlayer - > GetTeam ( ) = = TEAM_SPECTATORS | | pMsg - > m_Team = = TEAM_SPECTATORS )
2010-05-29 07:25:38 +00:00
m_VoteUpdate = true ;
2011-02-12 10:40:36 +00:00
pPlayer - > SetTeam ( pMsg - > m_Team ) ;
2010-07-29 05:21:18 +00:00
//(void)m_pController->CheckTeamBalance();
2011-01-29 00:59:50 +00:00
}
2010-07-29 05:21:18 +00:00
//else
2011-02-13 05:35:13 +00:00
//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 ) ;
2011-02-12 10:40:36 +00:00
SendBroadcast ( aBuf , ClientID ) ;
2010-05-29 07:25:38 +00:00
}
}
2011-04-09 06:41:31 +00:00
else if ( MsgID = = NETMSGTYPE_CL_ISDDRACE )
2010-10-23 19:26:10 +00:00
{
2011-04-09 06:41:31 +00:00
pPlayer - > m_IsUsingDDRaceClient = true ;
2010-10-24 10:47:25 +00:00
char aBuf [ 128 ] ;
2011-02-13 05:35:13 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %d use DDRace Client " , ClientID ) ;
2010-10-24 10:47:25 +00:00
dbg_msg ( " DDRace " , aBuf ) ;
2011-04-09 06:41:31 +00:00
2010-10-30 14:22:35 +00:00
//first update his teams state
2011-02-13 05:35:13 +00:00
( ( CGameControllerDDRace * ) m_pController ) - > m_Teams . SendTeamsState ( ClientID ) ;
2011-04-09 06:41:31 +00:00
2010-10-30 14:22:35 +00:00
//second give him records
2011-02-13 05:35:13 +00:00
SendRecord ( ClientID ) ;
2011-04-09 06:41:31 +00:00
2010-10-30 14:22:35 +00:00
//third give him others current time for table score
if ( g_Config . m_SvHideScore ) return ;
for ( int i = 0 ; i < MAX_CLIENTS ; i + + )
{
if ( m_apPlayers [ i ] & & Score ( ) - > PlayerData ( i ) - > m_CurrentTime > 0 )
{
CNetMsg_Sv_PlayerTime Msg ;
2010-11-07 11:03:26 +00:00
Msg . m_Time = Score ( ) - > PlayerData ( i ) - > m_CurrentTime * 100 ;
2011-02-13 05:35:13 +00:00
Msg . m_ClientID = i ;
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , ClientID ) ;
2010-11-04 18:33:51 +00:00
//also send its time to others
2011-04-09 06:41:31 +00:00
2010-10-30 14:22:35 +00:00
}
}
2010-11-04 18:33:51 +00:00
//also send its time to others
2011-02-13 05:35:13 +00:00
if ( Score ( ) - > PlayerData ( ClientID ) - > m_CurrentTime > 0 ) {
2010-11-04 18:33:51 +00:00
//TODO: make function for this fucking steps
CNetMsg_Sv_PlayerTime Msg ;
2011-02-13 05:35:13 +00:00
Msg . m_Time = Score ( ) - > PlayerData ( ClientID ) - > m_CurrentTime * 100 ;
Msg . m_ClientID = ClientID ;
2010-11-04 18:33:51 +00:00
Server ( ) - > SendPackMsg ( & Msg , MSGFLAG_VITAL , - 1 ) ;
}
2010-10-23 19:26:10 +00:00
}
2011-03-10 09:08:14 +00:00
else if ( MsgID = = NETMSGTYPE_CL_SETSPECTATORMODE & & ! m_World . m_Paused )
2010-05-29 07:25:38 +00:00
{
2011-03-10 09:08:14 +00:00
CNetMsg_Cl_SetSpectatorMode * pMsg = ( CNetMsg_Cl_SetSpectatorMode * ) pRawMsg ;
2011-01-29 00:59:50 +00:00
2011-03-10 09:08:14 +00:00
if ( pPlayer - > GetTeam ( ) ! = TEAM_SPECTATORS | | pPlayer - > m_SpectatorID = = pMsg - > m_SpectatorID | | ClientID = = pMsg - > m_SpectatorID | |
( g_Config . m_SvSpamprotection & & pPlayer - > m_LastSetSpectatorMode & & pPlayer - > m_LastSetSpectatorMode + Server ( ) - > TickSpeed ( ) * 3 > Server ( ) - > Tick ( ) ) )
2010-05-29 07:25:38 +00:00
return ;
2011-03-10 09:08:14 +00:00
pPlayer - > m_LastSetSpectatorMode = Server ( ) - > Tick ( ) ;
2011-03-28 21:45:47 +00:00
if ( pMsg - > m_SpectatorID ! = SPEC_FREEVIEW & & ( ! m_apPlayers [ pMsg - > m_SpectatorID ] | | m_apPlayers [ pMsg - > m_SpectatorID ] - > GetTeam ( ) = = TEAM_SPECTATORS ) )
2011-03-10 09:08:14 +00:00
SendChatTarget ( ClientID , " Invalid spectator id used " ) ;
else
pPlayer - > m_SpectatorID = pMsg - > m_SpectatorID ;
}
2011-03-15 08:58:57 +00:00
else if ( MsgID = = NETMSGTYPE_CL_STARTINFO )
{
if ( pPlayer - > m_IsReady )
2010-05-29 07:25:38 +00:00
return ;
2011-03-15 08:58:57 +00:00
CNetMsg_Cl_StartInfo * pMsg = ( CNetMsg_Cl_StartInfo * ) pRawMsg ;
2011-03-10 09:08:14 +00:00
pPlayer - > m_LastChangeInfo = Server ( ) - > Tick ( ) ;
2011-01-29 00:59:50 +00:00
2011-03-15 08:58:57 +00:00
// set start infos
2011-02-12 10:40:36 +00:00
Server ( ) - > SetClientName ( ClientID , pMsg - > m_pName ) ;
2011-03-15 10:23:49 +00:00
Server ( ) - > SetClientClan ( ClientID , pMsg - > m_pClan ) ;
Server ( ) - > SetClientCountry ( ClientID , pMsg - > m_Country ) ;
2011-03-15 08:58:57 +00:00
str_copy ( pPlayer - > m_TeeInfos . m_SkinName , pMsg - > m_pSkin , sizeof ( pPlayer - > m_TeeInfos . m_SkinName ) ) ;
2011-02-12 10:40:36 +00:00
pPlayer - > m_TeeInfos . m_UseCustomColor = pMsg - > m_UseCustomColor ;
pPlayer - > m_TeeInfos . m_ColorBody = pMsg - > m_ColorBody ;
pPlayer - > m_TeeInfos . m_ColorFeet = pMsg - > m_ColorFeet ;
2011-04-09 20:45:34 +00:00
//m_pController->OnPlayerInfoChange(pPlayer);
2010-05-29 07:25:38 +00:00
2011-03-15 08:58:57 +00:00
// send vote options
CNetMsg_Sv_VoteClearOptions ClearMsg ;
Server ( ) - > SendPackMsg ( & ClearMsg , MSGFLAG_VITAL , ClientID ) ;
2011-01-29 00:59:50 +00:00
2011-03-26 21:06:29 +00:00
CNetMsg_Sv_VoteOptionListAdd OptionMsg ;
int NumOptions = 0 ;
2011-04-01 15:46:20 +00:00
OptionMsg . m_pDescription0 = " " ;
2011-03-26 21:06:29 +00:00
OptionMsg . m_pDescription1 = " " ;
OptionMsg . m_pDescription2 = " " ;
OptionMsg . m_pDescription3 = " " ;
OptionMsg . m_pDescription4 = " " ;
OptionMsg . m_pDescription5 = " " ;
OptionMsg . m_pDescription6 = " " ;
OptionMsg . m_pDescription7 = " " ;
OptionMsg . m_pDescription8 = " " ;
OptionMsg . m_pDescription9 = " " ;
OptionMsg . m_pDescription10 = " " ;
OptionMsg . m_pDescription11 = " " ;
OptionMsg . m_pDescription12 = " " ;
OptionMsg . m_pDescription13 = " " ;
OptionMsg . m_pDescription14 = " " ;
2011-03-26 16:44:34 +00:00
CVoteOptionServer * pCurrent = m_pVoteOptionFirst ;
2011-03-15 08:58:57 +00:00
while ( pCurrent )
2010-05-29 07:25:38 +00:00
{
2011-03-26 21:06:29 +00:00
switch ( NumOptions + + )
2010-05-29 07:25:38 +00:00
{
2011-03-26 21:06:29 +00:00
case 0 : OptionMsg . m_pDescription0 = pCurrent - > m_aDescription ; break ;
case 1 : OptionMsg . m_pDescription1 = pCurrent - > m_aDescription ; break ;
case 2 : OptionMsg . m_pDescription2 = pCurrent - > m_aDescription ; break ;
case 3 : OptionMsg . m_pDescription3 = pCurrent - > m_aDescription ; break ;
case 4 : OptionMsg . m_pDescription4 = pCurrent - > m_aDescription ; break ;
case 5 : OptionMsg . m_pDescription5 = pCurrent - > m_aDescription ; break ;
case 6 : OptionMsg . m_pDescription6 = pCurrent - > m_aDescription ; break ;
case 7 : OptionMsg . m_pDescription7 = pCurrent - > m_aDescription ; break ;
case 8 : OptionMsg . m_pDescription8 = pCurrent - > m_aDescription ; break ;
case 9 : OptionMsg . m_pDescription9 = pCurrent - > m_aDescription ; break ;
case 10 : OptionMsg . m_pDescription10 = pCurrent - > m_aDescription ; break ;
case 11 : OptionMsg . m_pDescription11 = pCurrent - > m_aDescription ; break ;
case 12 : OptionMsg . m_pDescription12 = pCurrent - > m_aDescription ; break ;
case 13 : OptionMsg . m_pDescription13 = pCurrent - > m_aDescription ; break ;
case 14 :
{
OptionMsg . m_pDescription14 = pCurrent - > m_aDescription ;
OptionMsg . m_NumOptions = NumOptions ;
Server ( ) - > SendPackMsg ( & OptionMsg , MSGFLAG_VITAL , ClientID ) ;
OptionMsg = CNetMsg_Sv_VoteOptionListAdd ( ) ;
NumOptions = 0 ;
OptionMsg . m_pDescription1 = " " ;
OptionMsg . m_pDescription2 = " " ;
OptionMsg . m_pDescription3 = " " ;
OptionMsg . m_pDescription4 = " " ;
OptionMsg . m_pDescription5 = " " ;
OptionMsg . m_pDescription6 = " " ;
OptionMsg . m_pDescription7 = " " ;
OptionMsg . m_pDescription8 = " " ;
OptionMsg . m_pDescription9 = " " ;
OptionMsg . m_pDescription10 = " " ;
OptionMsg . m_pDescription11 = " " ;
OptionMsg . m_pDescription12 = " " ;
OptionMsg . m_pDescription13 = " " ;
OptionMsg . m_pDescription14 = " " ;
}
2010-05-29 07:25:38 +00:00
}
2011-03-15 08:58:57 +00:00
pCurrent = pCurrent - > m_pNext ;
}
2011-03-26 21:06:29 +00:00
if ( NumOptions > 0 )
{
OptionMsg . m_NumOptions = NumOptions ;
Server ( ) - > SendPackMsg ( & OptionMsg , MSGFLAG_VITAL , ClientID ) ;
NumOptions = 0 ;
}
2011-01-29 00:59:50 +00:00
2011-03-15 08:58:57 +00:00
// send tuning parameters to client
SendTuningParams ( ClientID ) ;
2010-05-29 07:25:38 +00:00
2011-03-15 08:58:57 +00:00
// client is ready to enter
pPlayer - > m_IsReady = true ;
CNetMsg_Sv_ReadyToEnter m ;
Server ( ) - > SendPackMsg ( & m , MSGFLAG_VITAL | MSGFLAG_FLUSH , ClientID ) ;
}
else if ( MsgID = = NETMSGTYPE_CL_CHANGEINFO )
{
2011-04-09 06:41:31 +00:00
if ( g_Config . m_SvSpamprotection & & pPlayer - > m_LastChangeInfo & & pPlayer - > m_LastChangeInfo + Server ( ) - > TickSpeed ( ) * g_Config . m_SvInfoChangeDelay > Server ( ) - > Tick ( ) )
2011-03-15 08:58:57 +00:00
return ;
CNetMsg_Cl_ChangeInfo * pMsg = ( CNetMsg_Cl_ChangeInfo * ) pRawMsg ;
pPlayer - > m_LastChangeInfo = Server ( ) - > Tick ( ) ;
2010-05-29 07:25:38 +00:00
2011-03-15 08:58:57 +00:00
// set infos
char aOldName [ MAX_NAME_LENGTH ] ;
str_copy ( aOldName , Server ( ) - > ClientName ( ClientID ) , sizeof ( aOldName ) ) ;
2011-02-12 10:40:36 +00:00
Server ( ) - > SetClientName ( ClientID , pMsg - > m_pName ) ;
2011-03-15 08:58:57 +00:00
if ( str_comp ( aOldName , Server ( ) - > ClientName ( ClientID ) ) ! = 0 )
2010-05-29 07:25:38 +00:00
{
char aChatText [ 256 ] ;
2011-02-12 10:40:36 +00:00
str_format ( aChatText , sizeof ( aChatText ) , " '%s' changed name to '%s' " , aOldName , Server ( ) - > ClientName ( ClientID ) ) ;
2010-05-29 07:25:38 +00:00
SendChat ( - 1 , CGameContext : : CHAT_ALL , aChatText ) ;
}
2011-03-15 10:23:49 +00:00
Server ( ) - > SetClientClan ( ClientID , pMsg - > m_pClan ) ;
Server ( ) - > SetClientCountry ( ClientID , pMsg - > m_Country ) ;
2011-02-12 10:40:36 +00:00
str_copy ( pPlayer - > m_TeeInfos . m_SkinName , pMsg - > m_pSkin , sizeof ( pPlayer - > m_TeeInfos . m_SkinName ) ) ;
2011-03-15 08:58:57 +00:00
pPlayer - > m_TeeInfos . m_UseCustomColor = pMsg - > m_UseCustomColor ;
pPlayer - > m_TeeInfos . m_ColorBody = pMsg - > m_ColorBody ;
pPlayer - > m_TeeInfos . m_ColorFeet = pMsg - > m_ColorFeet ;
2011-04-09 20:45:34 +00:00
//m_pController->OnPlayerInfoChange(pPlayer);
2010-05-29 07:25:38 +00:00
}
2011-02-12 10:40:36 +00:00
else if ( MsgID = = NETMSGTYPE_CL_EMOTICON & & ! m_World . m_Paused )
2010-05-29 07:25:38 +00:00
{
CNetMsg_Cl_Emoticon * pMsg = ( CNetMsg_Cl_Emoticon * ) pRawMsg ;
2011-01-29 00:59:50 +00:00
2011-04-09 06:41:31 +00:00
if ( g_Config . m_SvSpamprotection & & pPlayer - > m_LastEmote & & pPlayer - > m_LastEmote + Server ( ) - > TickSpeed ( ) * g_Config . m_SvEmoticonDelay > Server ( ) - > Tick ( ) )
2010-05-29 07:25:38 +00:00
return ;
2011-01-29 00:59:50 +00:00
2011-03-10 09:08:14 +00:00
pPlayer - > m_LastEmote = Server ( ) - > Tick ( ) ;
2011-01-29 00:59:50 +00:00
2011-02-12 10:40:36 +00:00
SendEmoticon ( ClientID , pMsg - > m_Emoticon ) ;
2011-04-09 06:41:31 +00:00
SendEmoticon ( ClientID , pMsg - > m_Emoticon ) ;
CCharacter * pChr = pPlayer - > GetCharacter ( ) ;
2010-10-10 22:40:07 +00:00
if ( pChr & & g_Config . m_SvEmotionalTees & & pChr - > m_EyeEmote )
2010-08-22 02:23:18 +00:00
{
switch ( pMsg - > m_Emoticon )
{
case EMOTICON_2 :
2010-08-22 12:32:52 +00:00
case EMOTICON_8 :
2011-01-29 00:59:50 +00:00
pChr - > SetEmoteType ( EMOTE_SURPRISE ) ;
2010-08-22 02:23:18 +00:00
break ;
2010-08-27 07:09:47 +00:00
case EMOTICON_1 :
case EMOTICON_4 :
2010-08-22 12:32:52 +00:00
case EMOTICON_7 :
2010-08-27 07:09:47 +00:00
case EMOTICON_13 :
2011-01-29 00:59:50 +00:00
pChr - > SetEmoteType ( EMOTE_BLINK ) ;
2010-08-22 02:23:18 +00:00
break ;
case EMOTICON_3 :
case EMOTICON_6 :
2011-01-29 00:59:50 +00:00
pChr - > SetEmoteType ( EMOTE_HAPPY ) ;
2010-08-22 02:23:18 +00:00
break ;
case EMOTICON_9 :
2010-08-22 12:32:52 +00:00
case EMOTICON_15 :
2011-01-29 00:59:50 +00:00
pChr - > SetEmoteType ( EMOTE_PAIN ) ;
2010-08-22 02:23:18 +00:00
break ;
case EMOTICON_10 :
case EMOTICON_11 :
case EMOTICON_12 :
2011-01-29 00:59:50 +00:00
pChr - > SetEmoteType ( EMOTE_ANGRY ) ;
2010-08-22 02:23:18 +00:00
break ;
default :
break ;
}
2011-01-29 00:59:50 +00:00
pChr - > SetEmoteStop ( Server ( ) - > Tick ( ) + 2 * Server ( ) - > TickSpeed ( ) ) ;
2010-08-22 02:23:18 +00:00
}
2010-05-29 07:25:38 +00:00
}
2011-02-12 10:40:36 +00:00
else if ( MsgID = = NETMSGTYPE_CL_KILL & & ! m_World . m_Paused )
2010-05-29 07:25:38 +00:00
{
2011-04-09 06:41:31 +00:00
if ( m_VoteCloseTime & & m_VoteCreator = = ClientID & & pPlayer - > GetCharacter ( ) - > Team ( ) )
{
SendChatTarget ( ClientID , " You are running a vote please try again after the vote is done! " ) ;
return ;
}
if ( pPlayer - > m_LastKill & & pPlayer - > m_LastKill + Server ( ) - > TickSpeed ( ) * g_Config . m_SvKillDelay > Server ( ) - > Tick ( ) )
2010-05-29 07:25:38 +00:00
return ;
2011-01-29 00:59:50 +00:00
2011-03-10 09:08:14 +00:00
pPlayer - > m_LastKill = Server ( ) - > Tick ( ) ;
2011-02-12 10:40:36 +00:00
pPlayer - > KillCharacter ( WEAPON_SELF ) ;
2010-05-29 07:25:38 +00:00
}
}
2011-01-29 00:59:50 +00:00
2011-02-13 05:35:13 +00:00
void CGameContext : : ConTuneParam ( IConsole : : IResult * pResult , void * pUserData , int ClientID )
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 ) )
{
2010-09-12 11:06:43 +00:00
char aBuf [ 256 ] ;
2010-08-17 22:06:00 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %s changed to %.2f " , pParamName , NewValue ) ;
2011-02-12 20:31:42 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " tuning " , aBuf ) ;
2010-05-29 07:25:38 +00:00
pSelf - > SendTuningParams ( - 1 ) ;
}
else
2011-02-12 20:31:42 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " tuning " , " No such tuning parameter " ) ;
2010-05-29 07:25:38 +00:00
}
2011-02-13 05:35:13 +00:00
void CGameContext : : ConTuneReset ( IConsole : : IResult * pResult , void * pUserData , int ClientID )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
2011-02-12 10:40:36 +00:00
CTuningParams TuningParams ;
* pSelf - > Tuning ( ) = TuningParams ;
2010-05-29 07:25:38 +00:00
pSelf - > SendTuningParams ( - 1 ) ;
2011-02-12 20:31:42 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " tuning " , " Tuning reset " ) ;
2010-05-29 07:25:38 +00:00
}
2011-02-13 05:35:13 +00:00
void CGameContext : : ConTuneDump ( IConsole : : IResult * pResult , void * pUserData , int ClientID )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
2010-08-17 22:06:00 +00:00
char aBuf [ 256 ] ;
2010-05-29 07:25:38 +00:00
for ( int i = 0 ; i < pSelf - > Tuning ( ) - > Num ( ) ; i + + )
{
float v ;
pSelf - > Tuning ( ) - > Get ( i , & v ) ;
2010-08-17 22:06:00 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %s %.2f " , pSelf - > Tuning ( ) - > m_apNames [ i ] , v ) ;
2010-11-21 22:25:30 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " tuning " , aBuf ) ;
2010-05-29 07:25:38 +00:00
}
}
2011-02-13 05:35:13 +00:00
void CGameContext : : ConChangeMap ( IConsole : : IResult * pResult , void * pUserData , int ClientID )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
2010-11-17 11:50:01 +00:00
pSelf - > m_pController - > ChangeMap ( pResult - > NumArguments ( ) ? pResult - > GetString ( 0 ) : " " ) ;
2010-05-29 07:25:38 +00:00
}
2011-02-13 05:35:13 +00:00
void CGameContext : : ConRestart ( IConsole : : IResult * pResult , void * pUserData , int ClientID )
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 ( ) ;
}
2011-02-13 05:35:13 +00:00
void CGameContext : : ConBroadcast ( IConsole : : IResult * pResult , void * pUserData , int ClientID )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
pSelf - > SendBroadcast ( pResult - > GetString ( 0 ) , - 1 ) ;
}
2011-02-13 05:35:13 +00:00
void CGameContext : : ConSay ( IConsole : : IResult * pResult , void * pUserData , int ClientID )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
pSelf - > SendChat ( - 1 , CGameContext : : CHAT_ALL , pResult - > GetString ( 0 ) ) ;
}
2011-02-13 05:35:13 +00:00
void CGameContext : : ConSetTeam ( IConsole : : IResult * pResult , void * pUserData , int ClientID )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
2011-02-13 05:35:13 +00:00
//int ClientID = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
2010-11-21 22:25:30 +00:00
int Victim = pResult - > GetVictim ( ) ;
int Team = clamp ( pResult - > GetInteger ( 0 ) , - 1 , 1 ) ;
if ( ! pSelf - > m_apPlayers [ Victim ] )
2010-05-29 07:25:38 +00:00
return ;
2010-11-21 22:25:30 +00:00
char aBuf [ 256 ] ;
str_format ( aBuf , sizeof ( aBuf ) , " moved client %d to team %d " , Victim , Team ) ;
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " server " , aBuf ) ;
2010-11-24 22:17:56 +00:00
pSelf - > m_apPlayers [ Victim ] - > SetTeam ( Team ) ;
2010-11-21 22:25:30 +00:00
//(void)pSelf->m_pController->CheckTeamBalance();
2010-05-29 07:25:38 +00:00
}
2011-01-06 21:30:28 +00:00
void CGameContext : : ConSetTeamAll ( IConsole : : IResult * pResult , void * pUserData , int ClientID )
2011-01-06 12:37:28 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
int Team = clamp ( pResult - > GetInteger ( 0 ) , - 1 , 1 ) ;
char aBuf [ 256 ] ;
str_format ( aBuf , sizeof ( aBuf ) , " moved all clients to team %d " , Team ) ;
2011-02-12 20:31:42 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " server " , aBuf ) ;
2011-01-06 12:37:28 +00:00
for ( int i = 0 ; i < MAX_CLIENTS ; + + i )
if ( pSelf - > m_apPlayers [ i ] )
pSelf - > m_apPlayers [ i ] - > SetTeam ( Team ) ;
2011-01-06 21:30:28 +00:00
//(void)pSelf->m_pController->CheckTeamBalance();
2011-01-06 12:37:28 +00:00
}
2010-11-21 22:25:30 +00:00
void CGameContext : : ConAddVote ( IConsole : : IResult * pResult , void * pUserData , int ClientID )
2010-05-29 07:25:38 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
2011-03-25 08:49:21 +00:00
const char * pDescription = pResult - > GetString ( 0 ) ;
const char * pCommand = pResult - > GetString ( 1 ) ;
2011-03-26 21:06:29 +00:00
if ( pSelf - > m_NumVoteOptions = = MAX_VOTE_OPTIONS )
{
2011-04-09 06:41:31 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " server " , " maximum number of vote options reached " ) ;
2011-03-26 21:06:29 +00:00
return ;
}
2011-01-29 00:59:50 +00:00
2010-10-25 16:30:35 +00:00
// check for valid option
2011-04-10 13:32:56 +00:00
if ( ! pSelf - > Console ( ) - > LineIsValid ( pCommand ) | | str_length ( pCommand ) > = VOTE_CMD_LENGTH )
2010-10-25 16:30:35 +00:00
{
char aBuf [ 256 ] ;
2011-03-26 16:44:34 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " skipped invalid command '%s' " , pCommand ) ;
2011-04-09 06:41:31 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " server " , aBuf ) ;
2011-03-26 16:44:34 +00:00
return ;
}
2011-04-05 18:06:41 +00:00
while ( * pDescription & & * pDescription = = ' ' )
pDescription + + ;
if ( str_length ( pDescription ) > = VOTE_DESC_LENGTH | | * pDescription = = 0 )
2011-03-26 16:44:34 +00:00
{
char aBuf [ 256 ] ;
str_format ( aBuf , sizeof ( aBuf ) , " skipped invalid option '%s' " , pDescription ) ;
2011-02-12 20:31:42 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " server " , aBuf ) ;
2010-10-25 16:30:35 +00:00
return ;
}
2011-01-29 00:59:50 +00:00
2011-03-25 08:49:21 +00:00
// check for duplicate entry
2011-03-26 16:44:34 +00:00
CVoteOptionServer * pOption = pSelf - > m_pVoteOptionFirst ;
2010-11-20 18:30:52 +00:00
while ( pOption )
{
2011-03-25 10:49:35 +00:00
if ( str_comp_nocase ( pDescription , pOption - > m_aDescription ) = = 0 )
2010-11-20 18:30:52 +00:00
{
char aBuf [ 256 ] ;
2011-03-25 08:49:21 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " option '%s' already exists " , pDescription ) ;
2011-02-12 20:31:42 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " server " , aBuf ) ;
2010-11-20 18:30:52 +00:00
return ;
}
pOption = pOption - > m_pNext ;
}
2011-01-29 00:59:50 +00:00
2011-03-25 08:49:21 +00:00
// add the option
2011-03-26 21:06:29 +00:00
+ + pSelf - > m_NumVoteOptions ;
2011-03-25 08:49:21 +00:00
int Len = str_length ( pCommand ) ;
2011-01-29 00:59:50 +00:00
2011-03-26 16:44:34 +00:00
pOption = ( CVoteOptionServer * ) pSelf - > m_pVoteOptionHeap - > Allocate ( sizeof ( CVoteOptionServer ) + Len ) ;
2010-05-29 07:25:38 +00:00
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 ;
2011-01-29 00:59:50 +00:00
2011-03-25 08:49:21 +00:00
str_copy ( pOption - > m_aDescription , pDescription , sizeof ( pOption - > m_aDescription ) ) ;
mem_copy ( pOption - > m_aCommand , pCommand , Len + 1 ) ;
2010-08-17 22:06:00 +00:00
char aBuf [ 256 ] ;
2011-03-25 08:49:21 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " added option '%s' '%s' " , pOption - > m_aDescription , pOption - > m_aCommand ) ;
2011-02-12 20:31:42 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " server " , aBuf ) ;
2010-05-29 07:25:38 +00:00
2011-03-25 10:49:35 +00:00
// inform clients about added option
CNetMsg_Sv_VoteOptionAdd OptionMsg ;
OptionMsg . m_pDescription = pOption - > m_aDescription ;
2010-05-29 07:25:38 +00:00
pSelf - > Server ( ) - > SendPackMsg ( & OptionMsg , MSGFLAG_VITAL , - 1 ) ;
}
2011-04-09 06:41:31 +00:00
void CGameContext : : ConRemoveVote ( IConsole : : IResult * pResult , void * pUserData , int ClientID )
2011-03-25 10:49:35 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
const char * pDescription = pResult - > GetString ( 0 ) ;
// check for valid option
2011-03-26 16:44:34 +00:00
CVoteOptionServer * pOption = pSelf - > m_pVoteOptionFirst ;
2011-03-25 10:49:35 +00:00
while ( pOption )
{
if ( str_comp_nocase ( pDescription , pOption - > m_aDescription ) = = 0 )
break ;
pOption = pOption - > m_pNext ;
}
if ( ! pOption )
{
char aBuf [ 256 ] ;
str_format ( aBuf , sizeof ( aBuf ) , " option '%s' does not exist " , pDescription ) ;
2011-04-09 06:41:31 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " server " , aBuf ) ;
2011-03-25 10:49:35 +00:00
return ;
}
2011-04-04 14:58:53 +00:00
// inform clients about removed option
CNetMsg_Sv_VoteOptionRemove OptionMsg ;
OptionMsg . m_pDescription = pOption - > m_aDescription ;
pSelf - > Server ( ) - > SendPackMsg ( & OptionMsg , MSGFLAG_VITAL , - 1 ) ;
2011-03-25 10:49:35 +00:00
// TODO: improve this
// remove the option
2011-03-26 21:06:29 +00:00
- - pSelf - > m_NumVoteOptions ;
2011-03-25 10:49:35 +00:00
char aBuf [ 256 ] ;
str_format ( aBuf , sizeof ( aBuf ) , " removed option '%s' '%s' " , pOption - > m_aDescription , pOption - > m_aCommand ) ;
2011-04-09 06:41:31 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " server " , aBuf ) ;
2011-03-25 10:49:35 +00:00
2011-03-25 11:06:45 +00:00
CHeap * pVoteOptionHeap = new CHeap ( ) ;
2011-03-26 16:44:34 +00:00
CVoteOptionServer * pVoteOptionFirst = 0 ;
CVoteOptionServer * pVoteOptionLast = 0 ;
2011-03-26 21:06:29 +00:00
int NumVoteOptions = pSelf - > m_NumVoteOptions ;
2011-03-26 16:44:34 +00:00
for ( CVoteOptionServer * pSrc = pSelf - > m_pVoteOptionFirst ; pSrc ; pSrc = pSrc - > m_pNext )
2011-03-25 10:49:35 +00:00
{
if ( pSrc = = pOption )
continue ;
// copy option
int Len = str_length ( pSrc - > m_aCommand ) ;
2011-03-26 16:44:34 +00:00
CVoteOptionServer * pDst = ( CVoteOptionServer * ) pVoteOptionHeap - > Allocate ( sizeof ( CVoteOptionServer ) + Len ) ;
2011-03-25 10:49:35 +00:00
pDst - > m_pNext = 0 ;
pDst - > m_pPrev = pVoteOptionLast ;
if ( pDst - > m_pPrev )
pDst - > m_pPrev - > m_pNext = pDst ;
pVoteOptionLast = pDst ;
if ( ! pVoteOptionFirst )
pVoteOptionFirst = pDst ;
str_copy ( pDst - > m_aDescription , pSrc - > m_aDescription , sizeof ( pDst - > m_aDescription ) ) ;
mem_copy ( pDst - > m_aCommand , pSrc - > m_aCommand , Len + 1 ) ;
2011-03-25 11:06:45 +00:00
}
// clean up
delete pSelf - > m_pVoteOptionHeap ;
2011-03-25 10:49:35 +00:00
pSelf - > m_pVoteOptionHeap = pVoteOptionHeap ;
pSelf - > m_pVoteOptionFirst = pVoteOptionFirst ;
pSelf - > m_pVoteOptionLast = pVoteOptionLast ;
2011-03-26 21:06:29 +00:00
pSelf - > m_NumVoteOptions = NumVoteOptions ;
2010-05-29 07:25:38 +00:00
}
2011-04-09 06:41:31 +00:00
void CGameContext : : ConForceVote ( IConsole : : IResult * pResult , void * pUserData , int ClientID )
2011-03-25 11:06:45 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
const char * pType = pResult - > GetString ( 0 ) ;
const char * pValue = pResult - > GetString ( 1 ) ;
2011-03-26 15:24:12 +00:00
const char * pReason = pResult - > NumArguments ( ) > 2 & & pResult - > GetString ( 2 ) [ 0 ] ? pResult - > GetString ( 2 ) : " No reason given " ;
2011-03-25 11:06:45 +00:00
char aBuf [ 128 ] = { 0 } ;
if ( str_comp_nocase ( pType , " option " ) = = 0 )
{
2011-03-26 16:44:34 +00:00
CVoteOptionServer * pOption = pSelf - > m_pVoteOptionFirst ;
2011-03-25 11:06:45 +00:00
while ( pOption )
{
if ( str_comp_nocase ( pValue , pOption - > m_aDescription ) = = 0 )
{
str_format ( aBuf , sizeof ( aBuf ) , " admin forced server option '%s' (%s) " , pValue , pReason ) ;
pSelf - > SendChatTarget ( - 1 , aBuf ) ;
2011-04-09 06:41:31 +00:00
pSelf - > Console ( ) - > ExecuteLine ( pOption - > m_aCommand , IConsole : : CONSOLELEVEL_ADMIN , ClientID ) ;
2011-03-25 11:06:45 +00:00
break ;
}
pOption = pOption - > m_pNext ;
}
if ( ! pOption )
{
str_format ( aBuf , sizeof ( aBuf ) , " '%s' isn't an option on this server " , pValue ) ;
2011-04-09 06:41:31 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " server " , aBuf ) ;
2011-03-25 11:06:45 +00:00
return ;
}
}
else if ( str_comp_nocase ( pType , " kick " ) = = 0 )
{
int KickID = str_toint ( pValue ) ;
if ( KickID < 0 | | KickID > = MAX_CLIENTS | | ! pSelf - > m_apPlayers [ KickID ] )
{
2011-04-09 06:41:31 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " server " , " Invalid client id to kick " ) ;
2011-03-25 11:06:45 +00:00
return ;
}
if ( ! g_Config . m_SvVoteKickBantime )
{
str_format ( aBuf , sizeof ( aBuf ) , " kick %d %s " , KickID , pReason ) ;
2011-04-09 06:41:31 +00:00
pSelf - > Console ( ) - > ExecuteLine ( aBuf , IConsole : : CONSOLELEVEL_ADMIN , ClientID ) ;
2011-03-25 11:06:45 +00:00
}
else
{
2011-03-28 18:11:28 +00:00
char aAddrStr [ NETADDR_MAXSTRSIZE ] = { 0 } ;
pSelf - > Server ( ) - > GetClientAddr ( KickID , aAddrStr , sizeof ( aAddrStr ) ) ;
str_format ( aBuf , sizeof ( aBuf ) , " ban %s %d %s " , aAddrStr , g_Config . m_SvVoteKickBantime , pReason ) ;
2011-04-09 06:41:31 +00:00
pSelf - > Console ( ) - > ExecuteLine ( aBuf , IConsole : : CONSOLELEVEL_ADMIN , ClientID ) ;
2011-03-25 11:06:45 +00:00
}
}
2011-03-26 15:56:59 +00:00
else if ( str_comp_nocase ( pType , " spectate " ) = = 0 )
{
int SpectateID = str_toint ( pValue ) ;
if ( SpectateID < 0 | | SpectateID > = MAX_CLIENTS | | ! pSelf - > m_apPlayers [ SpectateID ] | | pSelf - > m_apPlayers [ SpectateID ] - > GetTeam ( ) = = TEAM_SPECTATORS )
{
2011-04-09 06:41:31 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " server " , " Invalid client id to move " ) ;
2011-03-26 15:56:59 +00:00
return ;
}
str_format ( aBuf , sizeof ( aBuf ) , " set_team %d -1 " , SpectateID ) ;
2011-04-09 06:41:31 +00:00
pSelf - > Console ( ) - > ExecuteLine ( aBuf , IConsole : : CONSOLELEVEL_ADMIN , ClientID ) ;
2011-03-26 15:56:59 +00:00
}
2011-03-25 11:06:45 +00:00
}
2011-01-24 12:06:55 +00:00
void CGameContext : : ConClearVotes ( IConsole : : IResult * pResult , void * pUserData , int ClientID )
2011-01-21 19:46:00 +00:00
{
CGameContext * pSelf = ( CGameContext * ) pUserData ;
2011-02-12 20:31:42 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " server " , " cleared votes " ) ;
2011-01-21 19:46:00 +00:00
CNetMsg_Sv_VoteClearOptions VoteClearOptionsMsg ;
pSelf - > Server ( ) - > SendPackMsg ( & VoteClearOptionsMsg , MSGFLAG_VITAL , - 1 ) ;
pSelf - > m_pVoteOptionHeap - > Reset ( ) ;
pSelf - > m_pVoteOptionFirst = 0 ;
pSelf - > m_pVoteOptionLast = 0 ;
2011-03-26 21:06:29 +00:00
pSelf - > m_NumVoteOptions = 0 ;
2011-01-21 19:46:00 +00:00
}
2010-11-21 22:25:30 +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 )
2010-11-21 22:25:30 +00:00
pSelf - > m_VoteEnforce = CGameContext : : VOTE_ENFORCE_YES_ADMIN ;
2010-05-29 07:25:38 +00:00
else if ( str_comp_nocase ( pResult - > GetString ( 0 ) , " no " ) = = 0 )
2010-11-21 22:25:30 +00:00
pSelf - > m_VoteEnforce = CGameContext : : VOTE_ENFORCE_NO_ADMIN ;
2011-01-29 00:59:50 +00:00
char aBuf [ 256 ] ;
2010-08-17 22:06:00 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " forcing vote %s " , pResult - > GetString ( 0 ) ) ;
2011-02-12 20:31:42 +00:00
pSelf - > Console ( ) - > PrintResponse ( IConsole : : OUTPUT_LEVEL_STANDARD , " server " , aBuf ) ;
2010-05-29 07:25:38 +00:00
}
void CGameContext : : ConchainSpecialMotdupdate ( IConsole : : IResult * pResult , void * pUserData , IConsole : : FCommandCallback pfnCallback , void * pCallbackUserData )
{
2010-11-21 22:25:30 +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 ) ;
}
}
void CGameContext : : OnConsoleInit ( )
{
m_pServer = Kernel ( ) - > RequestInterface < IServer > ( ) ;
m_pConsole = Kernel ( ) - > RequestInterface < IConsole > ( ) ;
2010-09-16 22:40:44 +00:00
2011-03-16 14:27:30 +00:00
Console ( ) - > Register ( " tune " , " si " , CFGFLAG_SERVER , ConTuneParam , this , " " , IConsole : : CONSOLELEVEL_ADMIN ) ;
Console ( ) - > Register ( " tune_reset " , " " , CFGFLAG_SERVER , ConTuneReset , this , " " , IConsole : : CONSOLELEVEL_ADMIN ) ;
Console ( ) - > Register ( " tune_dump " , " " , CFGFLAG_SERVER , ConTuneDump , this , " " , IConsole : : CONSOLELEVEL_ADMIN ) ;
2010-09-16 21:22:00 +00:00
2011-03-16 14:27:30 +00:00
Console ( ) - > Register ( " change_map " , " ?r " , CFGFLAG_SERVER | CFGFLAG_STORE , ConChangeMap , this , " " , IConsole : : CONSOLELEVEL_ADMIN ) ;
Console ( ) - > Register ( " restart " , " ?i " , CFGFLAG_SERVER | CFGFLAG_STORE , ConRestart , this , " " , IConsole : : CONSOLELEVEL_ADMIN ) ;
Console ( ) - > Register ( " broadcast " , " r " , CFGFLAG_SERVER , ConBroadcast , this , " " , IConsole : : CONSOLELEVEL_ADMIN ) ;
Console ( ) - > Register ( " say " , " r " , CFGFLAG_SERVER , ConSay , this , " " , IConsole : : CONSOLELEVEL_ADMIN ) ;
2011-04-09 06:41:31 +00:00
Console ( ) - > Register ( " set_team " , " ii " , CFGFLAG_SERVER , ConSetTeam , this , " " , IConsole : : CONSOLELEVEL_ADMIN ) ;
2011-03-16 14:27:30 +00:00
Console ( ) - > Register ( " set_team_all " , " i " , CFGFLAG_SERVER , ConSetTeamAll , this , " " , IConsole : : CONSOLELEVEL_ADMIN ) ;
2010-09-16 22:40:44 +00:00
2011-04-09 06:41:31 +00:00
Console ( ) - > Register ( " add_vote " , " sr " , CFGFLAG_SERVER , ConAddVote , this , " " , IConsole : : CONSOLELEVEL_ADMIN ) ;
Console ( ) - > Register ( " remove_vote " , " s " , CFGFLAG_SERVER , ConRemoveVote , this , " " , IConsole : : CONSOLELEVEL_ADMIN ) ;
Console ( ) - > Register ( " force_vote " , " ss?r " , CFGFLAG_SERVER , ConForceVote , this , " " , IConsole : : CONSOLELEVEL_ADMIN ) ;
2011-03-16 14:27:30 +00:00
Console ( ) - > Register ( " clear_votes " , " " , CFGFLAG_SERVER , ConClearVotes , this , " " , IConsole : : CONSOLELEVEL_ADMIN ) ;
2011-04-09 06:41:31 +00:00
Console ( ) - > Register ( " vote " , " r " , CFGFLAG_SERVER , ConVote , this , " " , IConsole : : CONSOLELEVEL_ADMIN ) ;
2010-05-29 07:25:38 +00:00
Console ( ) - > Chain ( " sv_motd " , ConchainSpecialMotdupdate , this ) ;
2010-10-10 22:40:07 +00:00
2011-01-29 00:59:50 +00:00
# define CONSOLE_COMMAND(name, params, flags, callback, userdata, help, level) m_pConsole->Register(name, params, flags, callback, userdata, help, level);
# include "game/ddracecommands.h"
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 ) ;
2011-01-29 00:59:50 +00:00
2010-05-29 07:25:38 +00:00
//if(!data) // only load once
//data = load_data_from_memory(internal_data);
2011-01-29 00:59:50 +00:00
2010-05-29 07:25:38 +00:00
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-08-20 20:40:12 +00:00
char buf [ 512 ] ;
2010-10-07 13:22:03 +00:00
str_format ( buf , sizeof ( buf ) , " data/maps/%s.cfg " , g_Config . m_SvMap ) ;
2010-11-22 08:32:00 +00:00
Console ( ) - > ExecuteFile ( buf , 0 , 0 , 0 , 0 , 4 ) ;
2010-08-20 20:40:12 +00:00
str_format ( buf , sizeof ( buf ) , " data/maps/%s.map.cfg " , g_Config . m_SvMap ) ;
2010-11-22 08:32:00 +00:00
Console ( ) - > ExecuteFile ( buf , 0 , 0 , 0 , 0 , 4 ) ;
2011-01-29 00:59:50 +00:00
/* // select gametype
if ( str_comp ( g_Config . m_SvGametype , " mod " ) = = 0 )
m_pController = new CGameControllerMOD ( this ) ;
else if ( str_comp ( g_Config . m_SvGametype , " ctf " ) = = 0 )
m_pController = new CGameControllerCTF ( this ) ;
else if ( str_comp ( g_Config . m_SvGametype , " tdm " ) = = 0 )
m_pController = new CGameControllerTDM ( this ) ;
else
2011-04-09 06:41:31 +00:00
m_pController = new CGameControllerDM ( this ) ; */
2010-07-29 14:53:25 +00:00
m_pController = new CGameControllerDDRace ( this ) ;
2010-09-24 13:37:13 +00:00
( ( CGameControllerDDRace * ) m_pController ) - > m_Teams . Reset ( ) ;
2010-08-20 20:40:12 +00:00
2010-08-23 19:37:27 +00:00
// delete old score object
if ( m_pScore )
delete m_pScore ;
2011-04-09 06:41:31 +00:00
2010-08-23 19:37:27 +00:00
// create score object (add sql later)
2010-11-16 13:44:16 +00:00
# if defined(CONF_SQL)
2010-08-26 13:27:36 +00:00
if ( g_Config . m_SvUseSQL )
m_pScore = new CSqlScore ( this ) ;
else
2010-11-16 13:44:16 +00:00
# endif
2010-08-23 19:37:27 +00:00
m_pScore = new CFileScore ( this ) ;
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;
2011-01-29 00:59:50 +00:00
2010-05-29 07:25:38 +00:00
// create all entities from the game layer
CMapItemLayerTilemap * pTileMap = m_Layers . GameLayer ( ) ;
CTile * pTiles = ( CTile * ) Kernel ( ) - > RequestInterface < IMap > ( ) - > GetData ( pTileMap - > m_Data ) ;
2011-01-29 00:59:50 +00:00
/*
num_spawn_points [ 0 ] = 0 ;
num_spawn_points [ 1 ] = 0 ;
2011-04-09 06:41:31 +00:00
2011-01-29 00:59:50 +00:00
*/
2010-11-13 13:22:19 +00:00
CTile * pFront = 0 ;
CSwitchTile * pSwitch = 0 ;
2010-10-10 22:40:07 +00:00
if ( m_Layers . FrontLayer ( ) )
2010-10-04 19:17:56 +00:00
pFront = ( CTile * ) Kernel ( ) - > RequestInterface < IMap > ( ) - > GetData ( pTileMap - > m_Front ) ;
2010-11-13 13:22:19 +00:00
if ( m_Layers . SwitchLayer ( ) )
pSwitch = ( CSwitchTile * ) Kernel ( ) - > RequestInterface < IMap > ( ) - > GetData ( pTileMap - > m_Switch ) ;
2010-08-20 20:40:12 +00:00
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 ;
2011-01-29 00:59:50 +00:00
2010-12-01 22:45:04 +00:00
if ( Index = = TILE_OLDLASER )
2010-12-01 23:33:02 +00:00
{
2010-12-01 22:45:04 +00:00
g_Config . m_SvOldLaser = 1 ;
2011-01-29 00:59:50 +00:00
dbg_msg ( " Game Layer " , " Found Old Laser Tile " ) ;
2010-12-01 23:33:02 +00:00
}
2010-12-01 22:45:04 +00:00
else if ( Index = = TILE_NPC )
2010-12-01 23:33:02 +00:00
{
2011-01-29 00:59:50 +00:00
m_Tuning . Set ( " player_collision " , 0 ) ;
dbg_msg ( " Game Layer " , " Found No Collision Tile " ) ;
2010-12-01 23:33:02 +00:00
}
2010-10-10 22:40:07 +00:00
else if ( Index = = TILE_EHOOK )
2010-12-01 23:33:02 +00:00
{
2010-08-28 19:34:21 +00:00
g_Config . m_SvEndlessDrag = 1 ;
2011-01-29 00:59:50 +00:00
dbg_msg ( " Game Layer " , " Found No Unlimited hook time Tile " ) ;
2010-12-01 23:33:02 +00:00
}
2010-10-10 22:40:07 +00:00
else if ( Index = = TILE_NOHIT )
2010-12-01 23:33:02 +00:00
{
2010-08-28 19:34:21 +00:00
g_Config . m_SvHit = 0 ;
2011-01-29 00:59:50 +00:00
dbg_msg ( " Game Layer " , " Found No Weapons Hitting others Tile " ) ;
2010-12-01 23:33:02 +00:00
}
2010-10-10 22:40:07 +00:00
else if ( Index = = TILE_NPH )
2010-12-01 23:33:02 +00:00
{
2011-01-29 00:59:50 +00:00
m_Tuning . Set ( " player_hooking " , 0 ) ;
dbg_msg ( " Game Layer " , " Found No Player Hooking Tile " ) ;
2010-12-01 23:33:02 +00:00
}
2011-04-09 06:41:31 +00:00
2010-05-29 07:25:38 +00:00
if ( Index > = ENTITY_OFFSET )
{
vec2 Pos ( x * 32.0f + 16.0f , y * 32.0f + 16.0f ) ;
2011-04-09 06:41:31 +00:00
//m_pController->OnEntity(Index-ENTITY_OFFSET, Pos);
2011-01-29 00:59:50 +00:00
m_pController - > OnEntity ( Index - ENTITY_OFFSET , Pos , LAYER_GAME , pTiles [ y * pTileMap - > m_Width + x ] . m_Flags ) ;
2010-08-20 20:40:12 +00:00
}
2011-04-09 06:41:31 +00:00
2010-10-10 22:40:07 +00:00
if ( pFront )
2010-08-20 20:40:12 +00:00
{
2011-01-29 00:59:50 +00:00
Index = pFront [ y * pTileMap - > m_Width + x ] . m_Index ;
2010-12-01 22:45:04 +00:00
if ( Index = = TILE_OLDLASER )
2011-01-29 00:59:50 +00:00
{
2010-12-01 22:45:04 +00:00
g_Config . m_SvOldLaser = 1 ;
2011-01-29 00:59:50 +00:00
dbg_msg ( " Front Layer " , " Found Old Laser Tile " ) ;
}
2010-12-01 22:45:04 +00:00
else if ( Index = = TILE_NPC )
2011-01-29 00:59:50 +00:00
{
m_Tuning . Set ( " player_collision " , 0 ) ;
dbg_msg ( " Front Layer " , " Found No Collision Tile " ) ;
}
2010-10-10 22:40:07 +00:00
else if ( Index = = TILE_EHOOK )
2011-01-29 00:59:50 +00:00
{
2010-08-28 19:34:21 +00:00
g_Config . m_SvEndlessDrag = 1 ;
2011-01-29 00:59:50 +00:00
dbg_msg ( " Front Layer " , " Found No Unlimited hook time Tile " ) ;
}
2010-10-10 22:40:07 +00:00
else if ( Index = = TILE_NOHIT )
2011-01-29 00:59:50 +00:00
{
2010-08-28 19:34:21 +00:00
g_Config . m_SvHit = 0 ;
2011-01-29 00:59:50 +00:00
dbg_msg ( " Front Layer " , " Found No Weapons Hitting others Tile " ) ;
}
2010-10-10 22:40:07 +00:00
else if ( Index = = TILE_NPH )
2011-01-29 00:59:50 +00:00
{
m_Tuning . Set ( " player_hooking " , 0 ) ;
dbg_msg ( " Front Layer " , " Found No Player Hooking Tile " ) ;
}
2010-08-27 23:30:50 +00:00
if ( Index > = ENTITY_OFFSET )
2010-08-20 20:40:12 +00:00
{
vec2 Pos ( x * 32.0f + 16.0f , y * 32.0f + 16.0f ) ;
2010-11-13 13:22:19 +00:00
m_pController - > OnEntity ( Index - ENTITY_OFFSET , Pos , LAYER_FRONT , pFront [ y * pTileMap - > m_Width + x ] . m_Flags ) ;
}
}
if ( pSwitch )
{
2011-01-29 00:59:50 +00:00
Index = pSwitch [ y * pTileMap - > m_Width + x ] . m_Type ;
2010-11-13 13:22:19 +00:00
if ( Index > = ENTITY_OFFSET )
{
vec2 Pos ( x * 32.0f + 16.0f , y * 32.0f + 16.0f ) ;
2010-11-14 14:00:33 +00:00
m_pController - > OnEntity ( Index - ENTITY_OFFSET , Pos , LAYER_SWITCH , pSwitch [ y * pTileMap - > m_Width + x ] . m_Flags , pSwitch [ y * pTileMap - > m_Width + x ] . m_Number ) ;
2010-08-20 20:40:12 +00:00
}
2010-05-29 07:25:38 +00:00
}
}
}
2011-01-29 00:59:50 +00:00
//game.world.insert_entity(game.Controller);
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 ( )
{
2010-10-27 10:14:26 +00:00
Layers ( ) - > Dest ( ) ;
Collision ( ) - > Dest ( ) ;
2010-05-29 07:25:38 +00:00
delete m_pController ;
m_pController = 0 ;
Clear ( ) ;
2008-08-14 18:42:47 +00:00
}
2011-02-12 10:40:36 +00:00
void CGameContext : : OnSnap ( int ClientID )
2008-08-14 18:42:47 +00:00
{
2011-02-12 10:40:36 +00:00
m_World . Snap ( ClientID ) ;
m_pController - > Snap ( ClientID ) ;
m_Events . Snap ( ClientID ) ;
2011-01-29 00:59:50 +00:00
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 ] )
2011-02-12 10:40:36 +00:00
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 ( ) ;
}
2011-03-15 08:58:57 +00:00
bool CGameContext : : IsClientReady ( int ClientID )
{
return m_apPlayers [ ClientID ] & & m_apPlayers [ ClientID ] - > m_IsReady ? true : false ;
}
2011-03-20 14:33:49 +00:00
bool CGameContext : : IsClientPlayer ( int ClientID )
{
return m_apPlayers [ ClientID ] & & m_apPlayers [ ClientID ] - > GetTeam ( ) = = TEAM_SPECTATORS ? false : true ;
}
2011-02-16 11:31:47 +00:00
const char * CGameContext : : GameType ( ) { return m_pController & & m_pController - > m_pGameType ? m_pController - > m_pGameType : " " ; }
2010-05-29 07:25:38 +00:00
const char * CGameContext : : Version ( ) { return GAME_VERSION ; }
const char * CGameContext : : NetVersion ( ) { return GAME_NETVERSION ; }
IGameServer * CreateGameServer ( ) { return new CGameContext ; }
2010-09-17 09:34:13 +00:00
2011-01-29 00:59:50 +00:00
void CGameContext : : SendChatResponseAll ( const char * pLine , void * pUser )
{
CGameContext * pSelf = ( CGameContext * ) pUser ;
static volatile int ReentryGuard = 0 ;
if ( ReentryGuard )
return ;
ReentryGuard + + ;
if ( * pLine = = ' [ ' )
do
pLine + + ;
while ( * ( pLine - 2 ) ! = ' : ' & & * pLine ! = 0 ) ; //remove the category (e.g. [Console]: No Such Command)
pSelf - > SendChat ( - 1 , CHAT_ALL , pLine ) ;
ReentryGuard - - ;
}
void CGameContext : : SendChatResponse ( const char * pLine , void * pUser )
{
ChatResponseInfo * pInfo = ( ChatResponseInfo * ) pUser ;
static volatile int ReentryGuard = 0 ;
if ( ReentryGuard )
return ;
ReentryGuard + + ;
if ( * pLine = = ' [ ' )
do
pLine + + ;
while ( * ( pLine - 2 ) ! = ' : ' & & * pLine ! = 0 ) ; // remove the category (e.g. [Console]: No Such Command)
pInfo - > m_GameContext - > SendChatTarget ( pInfo - > m_To , pLine ) ;
ReentryGuard - - ;
}
bool CGameContext : : PlayerCollision ( )
{
float Temp ;
m_Tuning . Get ( " player_collision " , & Temp ) ;
return Temp ! = 0.0 ;
}
bool CGameContext : : PlayerHooking ( )
{
float Temp ;
m_Tuning . Get ( " player_hooking " , & Temp ) ;
return Temp ! = 0.0 ;
}
2011-02-13 05:35:13 +00:00
void CGameContext : : OnSetAuthed ( int ClientID , int Level )
2011-01-29 00:59:50 +00:00
{
2011-02-23 13:55:27 +00:00
CServer * pServ = ( CServer * ) Server ( ) ;
2011-02-13 05:35:13 +00:00
if ( m_apPlayers [ ClientID ] )
2011-01-29 00:59:50 +00:00
{
2011-02-13 05:35:13 +00:00
m_apPlayers [ ClientID ] - > m_Authed = Level ;
2011-02-23 13:55:27 +00:00
char aBuf [ 512 ] , aIP [ 20 ] ;
2011-04-09 20:45:34 +00:00
pServ - > GetClientIP ( ClientID , aIP , sizeof ( aIP ) ) ;
str_format ( aBuf , sizeof ( aBuf ) , " ban %s %d Banned by vote " , aIP , g_Config . m_SvVoteKickBantime ) ;
2011-02-23 13:55:27 +00:00
if ( ! str_comp_nocase ( m_aVoteCommand , aBuf ) & & Level > 0 )
2011-01-29 00:59:50 +00:00
{
m_VoteEnforce = CGameContext : : VOTE_ENFORCE_NO ;
2011-02-23 13:55:27 +00:00
Console ( ) - > Print ( IConsole : : OUTPUT_LEVEL_STANDARD , " CGameContext " , " Aborted vote by admin login. " ) ;
2011-01-29 00:59:50 +00:00
}
}
}
2011-02-27 08:07:57 +00:00
void CGameContext : : SendRecord ( int ClientID )
{
2011-01-29 00:59:50 +00:00
CNetMsg_Sv_Record RecordsMsg ;
2011-02-13 05:35:13 +00:00
RecordsMsg . m_PlayerTimeBest = Score ( ) - > PlayerData ( ClientID ) - > m_BestTime * 100.0f ; //
2011-01-29 00:59:50 +00:00
RecordsMsg . m_ServerTimeBest = m_pController - > m_CurrentRecord * 100.0f ; //TODO: finish this
2011-02-13 05:35:13 +00:00
Server ( ) - > SendPackMsg ( & RecordsMsg , MSGFLAG_VITAL , ClientID ) ;
2011-02-23 07:43:05 +00:00
}
2011-02-27 08:07:57 +00:00
int CGameContext : : ProcessSpamProtection ( int ClientID )
{
2011-04-09 06:41:31 +00:00
if ( g_Config . m_SvSpamprotection & & m_apPlayers [ ClientID ] - > m_LastChat
& & m_apPlayers [ ClientID ] - > m_LastChat + Server ( ) - > TickSpeed ( ) * g_Config . m_SvChatDelay > Server ( ) - > Tick ( ) )
2011-02-27 08:07:57 +00:00
return 1 ;
else
2011-04-09 06:41:31 +00:00
m_apPlayers [ ClientID ] - > m_LastChat = Server ( ) - > Tick ( ) ;
2011-02-27 08:07:57 +00:00
NETADDR Addr ;
Server ( ) - > GetClientAddr ( ClientID , & Addr ) ;
int Muted = 0 ;
for ( int i = 0 ; i < m_NumMutes & & ! Muted ; i + + )
{
if ( ! net_addr_comp ( & Addr , & m_aMutes [ i ] . m_Addr ) )
Muted = ( m_aMutes [ i ] . m_Expire - Server ( ) - > Tick ( ) ) / Server ( ) - > TickSpeed ( ) ;
}
if ( Muted > 0 )
{
char aBuf [ 128 ] ;
str_format ( aBuf , sizeof aBuf , " You are not permitted to talk for the next %d seconds. " , Muted ) ;
SendChatTarget ( ClientID , aBuf ) ;
return 1 ;
}
if ( ( m_apPlayers [ ClientID ] - > m_ChatScore + = g_Config . m_SvChatPenalty ) > g_Config . m_SvChatThreshold )
{
Mute ( & Addr , g_Config . m_SvSpamMuteDuration , Server ( ) - > ClientName ( ClientID ) ) ;
m_apPlayers [ ClientID ] - > m_ChatScore = 0 ;
return 1 ;
}
return 0 ;
}