ddnet/src/game/server/player.cpp

621 lines
18 KiB
C++
Raw Normal View History

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. */
#include <new>
2011-01-18 18:09:53 +00:00
#include <engine/shared/config.h>
2010-05-29 07:25:38 +00:00
#include "player.h"
#include <engine/server.h>
#include <engine/server/server.h>
#include "gamecontext.h"
#include <game/gamecore.h>
2013-11-15 23:44:49 +00:00
#include <game/server/teams.h>
#include "gamemodes/DDRace.h"
2011-03-22 19:56:52 +00:00
#include <stdio.h>
#include <time.h>
2011-01-29 00:59:50 +00:00
2010-05-29 07:25:38 +00:00
MACRO_ALLOC_POOL_ID_IMPL(CPlayer, MAX_CLIENTS)
2010-05-29 07:25:38 +00:00
IServer *CPlayer::Server() const { return m_pGameServer->Server(); }
CPlayer::CPlayer(CGameContext *pGameServer, int ClientID, int Team)
{
2010-05-29 07:25:38 +00:00
m_pGameServer = pGameServer;
m_RespawnTick = Server()->Tick();
m_DieTick = Server()->Tick();
m_ScoreStartTick = Server()->Tick();
2011-04-19 08:42:48 +00:00
m_pCharacter = 0;
m_ClientID = ClientID;
2010-05-29 07:25:38 +00:00
m_Team = GameServer()->m_pController->ClampTeam(Team);
m_SpectatorID = SPEC_FREEVIEW;
m_LastActionTick = Server()->Tick();
m_TeamChangeTick = Server()->Tick();
2013-12-31 05:13:57 +00:00
int* idMap = Server()->GetIdMap(ClientID);
for (int i = 1;i < VANILLA_MAX_CLIENTS;i++)
{
2014-02-12 12:28:07 +00:00
idMap[i] = -1;
2013-12-31 05:13:57 +00:00
}
idMap[0] = ClientID;
// DDRace
2013-08-10 02:21:20 +00:00
m_LastCommandPos = 0;
m_LastPlaytime = time_get();
m_Sent1stAfkWarning = 0;
m_Sent2ndAfkWarning = 0;
2011-02-03 13:39:00 +00:00
m_ChatScore = 0;
Added the following settings to Close #123. sv_time_in_broadcast, 1, 0, 1, CFGFLAG_SERVER, "Whether to display time in broadcast every interval or not by default, later the choice can be changed by players via chat commands" sv_time_in_broadcast_interval, 1, 0, 60, CFGFLAG_SERVER, "How often to update the broadcast time" sv_time_in_gametimer, 0, 0, 1, CFGFLAG_SERVER, "Whether to display time in the round/game timer or not by default, later the choice can be changed by players via chat commands" Added the following Chat commands to give the player the choice over their settings: "saytime", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConSayTime, this, "Privately messages you your current time in this current running race" "saytimeall", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConSayTimeAll, this, "Publicly messages everyone your current time in this current running race" "time", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTime, this, "Privately shows you your current time in this current running race in the broadcast message" "broadcasttime", "?s", CFGFLAG_CHAT|CFGFLAG_SERVER, ConSetBroadcastTime, this, "Personal Setting of showing time in the broadcast, broadcasttime s, where s = on for on, off for off, toggle for toggle and nothing to show current status" "servergametime", "?s", CFGFLAG_CHAT|CFGFLAG_SERVER, ConSetServerGameTime, this, "Personal Setting of showing time in the round/game timer, servergametime s, where s = on for on off for off, toggle for toggle and nothing to show current status" Fixed Chat Command "eyeemote" and made it a set + toggle instead of just toggle for better bin techneques Moved some vars from CCharacter to CPlayer to keep their status evern after death but not after disconnect. So now players have the choice to see which timer they wanna see if any. Note: These changes are all untested Stay away from this update on your main server until they are tested, i don't even know if they will compile propperly
2011-12-29 12:17:34 +00:00
m_EyeEmote = true;
m_TimerType = g_Config.m_SvDefaultTimerType;
m_DefEmote = EMOTE_NORMAL;
2013-08-18 01:27:30 +00:00
m_Afk = false;
2013-10-18 09:42:35 +00:00
m_LastWhisperTo = -1;
2014-03-12 23:56:39 +00:00
m_TuneZone = 0;
m_TuneZoneOld = m_TuneZone;
//New Year
2012-12-23 17:36:13 +00:00
if (g_Config.m_SvEvents)
{
time_t rawtime;
struct tm* timeinfo;
char d[16], m[16], y[16];
2013-11-14 15:26:25 +00:00
int dd, mm;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (d,sizeof(y),"%d",timeinfo);
strftime (m,sizeof(m),"%m",timeinfo);
strftime (y,sizeof(y),"%Y",timeinfo);
dd = atoi(d);
mm = atoi(m);
m_DefEmote = ((mm == 12 && dd == 31) || (mm == 1 && dd == 1)) ? EMOTE_HAPPY : EMOTE_NORMAL;
2012-12-23 17:36:13 +00:00
}
Added the following settings to Close #123. sv_time_in_broadcast, 1, 0, 1, CFGFLAG_SERVER, "Whether to display time in broadcast every interval or not by default, later the choice can be changed by players via chat commands" sv_time_in_broadcast_interval, 1, 0, 60, CFGFLAG_SERVER, "How often to update the broadcast time" sv_time_in_gametimer, 0, 0, 1, CFGFLAG_SERVER, "Whether to display time in the round/game timer or not by default, later the choice can be changed by players via chat commands" Added the following Chat commands to give the player the choice over their settings: "saytime", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConSayTime, this, "Privately messages you your current time in this current running race" "saytimeall", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConSayTimeAll, this, "Publicly messages everyone your current time in this current running race" "time", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTime, this, "Privately shows you your current time in this current running race in the broadcast message" "broadcasttime", "?s", CFGFLAG_CHAT|CFGFLAG_SERVER, ConSetBroadcastTime, this, "Personal Setting of showing time in the broadcast, broadcasttime s, where s = on for on, off for off, toggle for toggle and nothing to show current status" "servergametime", "?s", CFGFLAG_CHAT|CFGFLAG_SERVER, ConSetServerGameTime, this, "Personal Setting of showing time in the round/game timer, servergametime s, where s = on for on off for off, toggle for toggle and nothing to show current status" Fixed Chat Command "eyeemote" and made it a set + toggle instead of just toggle for better bin techneques Moved some vars from CCharacter to CPlayer to keep their status evern after death but not after disconnect. So now players have the choice to see which timer they wanna see if any. Note: These changes are all untested Stay away from this update on your main server until they are tested, i don't even know if they will compile propperly
2011-12-29 12:17:34 +00:00
m_DefEmoteReset = -1;
GameServer()->Score()->PlayerData(ClientID)->Reset();
m_ClientVersion = VERSION_VANILLA;
2013-10-22 15:04:54 +00:00
m_ShowOthers = g_Config.m_SvShowOthersDefault;
2014-02-02 18:56:10 +00:00
m_ShowAll = g_Config.m_SvShowAllDefault;
2014-01-11 12:59:20 +00:00
m_NinjaJetpack = false;
m_Paused = PAUSED_NONE;
2013-12-22 17:30:13 +00:00
m_DND = false;
m_NextPauseTick = 0;
// Variable initialized:
2011-01-24 20:22:04 +00:00
m_Last_Team = 0;
2011-09-07 22:51:55 +00:00
#if defined(CONF_SQL)
m_LastSQLQuery = 0;
#endif
}
2010-05-29 07:25:38 +00:00
CPlayer::~CPlayer()
{
2011-04-19 08:42:48 +00:00
delete m_pCharacter;
m_pCharacter = 0;
}
2010-05-29 07:25:38 +00:00
void CPlayer::Tick()
{
2011-01-18 18:09:53 +00:00
#ifdef CONF_DEBUG
if(!g_Config.m_DbgDummies || m_ClientID < MAX_CLIENTS-g_Config.m_DbgDummies)
#endif
if(!Server()->ClientIngame(m_ClientID))
return;
2011-02-03 13:39:00 +00:00
if (m_ChatScore > 0)
m_ChatScore--;
if (m_ForcePauseTime > 0)
m_ForcePauseTime--;
2010-05-29 07:25:38 +00:00
Server()->SetClientScore(m_ClientID, m_Score);
// do latency stuff
{
2010-05-29 07:25:38 +00:00
IServer::CClientInfo Info;
if(Server()->GetClientInfo(m_ClientID, &Info))
{
2010-05-29 07:25:38 +00:00
m_Latency.m_Accum += Info.m_Latency;
m_Latency.m_AccumMax = max(m_Latency.m_AccumMax, Info.m_Latency);
m_Latency.m_AccumMin = min(m_Latency.m_AccumMin, Info.m_Latency);
}
2010-05-29 07:25:38 +00:00
// each second
if(Server()->Tick()%Server()->TickSpeed() == 0)
{
2010-05-29 07:25:38 +00:00
m_Latency.m_Avg = m_Latency.m_Accum/Server()->TickSpeed();
m_Latency.m_Max = m_Latency.m_AccumMax;
m_Latency.m_Min = m_Latency.m_AccumMin;
m_Latency.m_Accum = 0;
m_Latency.m_AccumMin = 1000;
m_Latency.m_AccumMax = 0;
}
}
2012-01-09 23:49:31 +00:00
if(!GameServer()->m_World.m_Paused)
2008-09-24 14:54:51 +00:00
{
2012-01-09 23:49:31 +00:00
if(!m_pCharacter && m_Team == TEAM_SPECTATORS && m_SpectatorID == SPEC_FREEVIEW)
m_ViewPos -= vec2(clamp(m_ViewPos.x-m_LatestActivity.m_TargetX, -500.0f, 500.0f), clamp(m_ViewPos.y-m_LatestActivity.m_TargetY, -400.0f, 400.0f));
2012-01-09 23:49:31 +00:00
if(!m_pCharacter && m_DieTick+Server()->TickSpeed()*3 <= Server()->Tick())
m_Spawning = true;
2008-09-24 14:54:51 +00:00
2012-01-09 23:49:31 +00:00
if(m_pCharacter)
2008-09-24 14:54:51 +00:00
{
2012-01-09 23:49:31 +00:00
if(m_pCharacter->IsAlive())
{
if(m_Paused >= PAUSED_FORCE)
{
if(m_ForcePauseTime == 0)
m_Paused = PAUSED_NONE;
ProcessPause();
}
else if(m_Paused == PAUSED_PAUSED && m_NextPauseTick < Server()->Tick())
{
if((!m_pCharacter->GetWeaponGot(WEAPON_NINJA) || m_pCharacter->m_FreezeTime) && m_pCharacter->IsGrounded() && m_pCharacter->m_Pos == m_pCharacter->m_PrevPos)
ProcessPause();
}
else if(m_NextPauseTick < Server()->Tick())
{
ProcessPause();
}
if(!m_Paused)
m_ViewPos = m_pCharacter->m_Pos;
}
else if(!m_pCharacter->IsPaused())
{
2012-01-09 23:49:31 +00:00
delete m_pCharacter;
m_pCharacter = 0;
}
2008-09-24 14:54:51 +00:00
}
2012-01-09 23:49:31 +00:00
else if(m_Spawning && m_RespawnTick <= Server()->Tick())
TryRespawn();
2008-09-24 14:54:51 +00:00
}
2012-01-09 23:49:31 +00:00
else
{
++m_RespawnTick;
++m_DieTick;
++m_ScoreStartTick;
++m_LastActionTick;
++m_TeamChangeTick;
2014-04-18 12:50:15 +00:00
}
m_TuneZoneOld = m_TuneZone; // determine needed tunings with viewpos
int CurrentIndex = GameServer()->Collision()->GetMapIndex(m_ViewPos);
m_TuneZone = GameServer()->Collision()->IsTune(CurrentIndex);
2014-04-18 12:50:15 +00:00
if (m_TuneZone != m_TuneZoneOld) // dont send tunigs all the time
{
GameServer()->SendTuningParams(m_ClientID, m_TuneZone);
}
}
void CPlayer::PostTick()
{
// update latency value
if(m_PlayerFlags&PLAYERFLAG_SCOREBOARD)
{
for(int i = 0; i < MAX_CLIENTS; ++i)
{
if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS)
m_aActLatency[i] = GameServer()->m_apPlayers[i]->m_Latency.m_Min;
}
}
// update view pos for spectators
if((m_Team == TEAM_SPECTATORS || m_Paused) && m_SpectatorID != SPEC_FREEVIEW && GameServer()->m_apPlayers[m_SpectatorID] && GameServer()->m_apPlayers[m_SpectatorID]->GetCharacter())
m_ViewPos = GameServer()->m_apPlayers[m_SpectatorID]->GetCharacter()->m_Pos;
}
2010-05-29 07:25:38 +00:00
void CPlayer::Snap(int SnappingClient)
{
2011-01-18 18:09:53 +00:00
#ifdef CONF_DEBUG
if(!g_Config.m_DbgDummies || m_ClientID < MAX_CLIENTS-g_Config.m_DbgDummies)
#endif
if(!Server()->ClientIngame(m_ClientID))
return;
2013-12-31 05:13:57 +00:00
int id = m_ClientID;
if (!Server()->Translate(id, SnappingClient)) return;
CNetObj_ClientInfo *pClientInfo = static_cast<CNetObj_ClientInfo *>(Server()->SnapNewItem(NETOBJTYPE_CLIENTINFO, id, sizeof(CNetObj_ClientInfo)));
if(!pClientInfo)
return;
2010-05-29 07:25:38 +00:00
StrToInts(&pClientInfo->m_Name0, 4, Server()->ClientName(m_ClientID));
StrToInts(&pClientInfo->m_Clan0, 3, Server()->ClientClan(m_ClientID));
pClientInfo->m_Country = Server()->ClientCountry(m_ClientID);
2013-12-31 05:13:57 +00:00
if (m_StolenSkin && SnappingClient != m_ClientID && g_Config.m_SvSkinStealAction == 1)
{
StrToInts(&pClientInfo->m_Skin0, 6, "pinky");
pClientInfo->m_UseCustomColor = 0;
pClientInfo->m_ColorBody = m_TeeInfos.m_ColorBody;
pClientInfo->m_ColorFeet = m_TeeInfos.m_ColorFeet;
} else
{
StrToInts(&pClientInfo->m_Skin0, 6, m_TeeInfos.m_SkinName);
pClientInfo->m_UseCustomColor = m_TeeInfos.m_UseCustomColor;
pClientInfo->m_ColorBody = m_TeeInfos.m_ColorBody;
pClientInfo->m_ColorFeet = m_TeeInfos.m_ColorFeet;
}
2013-12-31 05:13:57 +00:00
CNetObj_PlayerInfo *pPlayerInfo = static_cast<CNetObj_PlayerInfo *>(Server()->SnapNewItem(NETOBJTYPE_PLAYERINFO, id, sizeof(CNetObj_PlayerInfo)));
if(!pPlayerInfo)
return;
2010-05-29 07:25:38 +00:00
pPlayerInfo->m_Latency = SnappingClient == -1 ? m_Latency.m_Min : GameServer()->m_apPlayers[SnappingClient]->m_aActLatency[m_ClientID];
pPlayerInfo->m_Local = 0;
2013-12-31 05:13:57 +00:00
pPlayerInfo->m_ClientID = id;
pPlayerInfo->m_Score = abs(m_Score) * -1;
pPlayerInfo->m_Team = (m_Paused != PAUSED_SPEC || m_ClientID != SnappingClient) && m_Paused < PAUSED_PAUSED ? m_Team : TEAM_SPECTATORS;
2010-05-29 07:25:38 +00:00
if(m_ClientID == SnappingClient)
pPlayerInfo->m_Local = 1;
if(m_ClientID == SnappingClient && (m_Team == TEAM_SPECTATORS || m_Paused))
{
CNetObj_SpectatorInfo *pSpectatorInfo = static_cast<CNetObj_SpectatorInfo *>(Server()->SnapNewItem(NETOBJTYPE_SPECTATORINFO, m_ClientID, sizeof(CNetObj_SpectatorInfo)));
if(!pSpectatorInfo)
return;
pSpectatorInfo->m_SpectatorID = m_SpectatorID;
pSpectatorInfo->m_X = m_ViewPos.x;
pSpectatorInfo->m_Y = m_ViewPos.y;
}
// send 0 if times of others are not shown
if(SnappingClient != m_ClientID && g_Config.m_SvHideScore)
pPlayerInfo->m_Score = -9999;
else
pPlayerInfo->m_Score = abs(m_Score) * -1;
}
2013-12-31 05:13:57 +00:00
void CPlayer::FakeSnap(int SnappingClient)
{
2014-02-13 18:53:30 +00:00
// This is problematic when it's sent before we know whether it's a non-64-player-client
// Then we can't spectate players at the start
2013-12-31 05:13:57 +00:00
IServer::CClientInfo info;
Server()->GetClientInfo(SnappingClient, &info);
2014-01-30 15:54:58 +00:00
CGameContext *GameContext = (CGameContext *) GameServer();
if (GameContext->m_apPlayers[SnappingClient] && GameContext->m_apPlayers[SnappingClient]->m_ClientVersion >= VERSION_DDNET_OLD)
2013-12-31 05:13:57 +00:00
return;
int id = VANILLA_MAX_CLIENTS - 1;
CNetObj_ClientInfo *pClientInfo = static_cast<CNetObj_ClientInfo *>(Server()->SnapNewItem(NETOBJTYPE_CLIENTINFO, id, sizeof(CNetObj_ClientInfo)));
if(!pClientInfo)
return;
StrToInts(&pClientInfo->m_Name0, 4, " ");
StrToInts(&pClientInfo->m_Clan0, 3, Server()->ClientClan(m_ClientID));
StrToInts(&pClientInfo->m_Skin0, 6, m_TeeInfos.m_SkinName);
}
void CPlayer::OnDisconnect(const char *pReason)
{
2010-05-29 07:25:38 +00:00
KillCharacter();
if(Server()->ClientIngame(m_ClientID))
{
2010-12-23 05:57:26 +00:00
char aBuf[512];
if(pReason && *pReason)
str_format(aBuf, sizeof(aBuf), "'%s' has left the game (%s)", Server()->ClientName(m_ClientID), pReason);
else
str_format(aBuf, sizeof(aBuf), "'%s' has left the game", Server()->ClientName(m_ClientID));
2010-12-23 05:57:26 +00:00
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
2011-01-29 00:59:50 +00:00
2010-12-23 05:57:26 +00:00
str_format(aBuf, sizeof(aBuf), "leave player='%d:%s'", m_ClientID, Server()->ClientName(m_ClientID));
GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "game", aBuf);
2010-05-29 07:25:38 +00:00
}
2011-02-14 21:34:46 +00:00
CGameControllerDDRace* Controller = (CGameControllerDDRace*)GameServer()->m_pController;
Controller->m_Teams.SetForceCharacterTeam(m_ClientID, 0);
}
2010-05-29 07:25:38 +00:00
void CPlayer::OnPredictedInput(CNetObj_PlayerInput *NewInput)
{
// skip the input if chat is active
if((m_PlayerFlags&PLAYERFLAG_CHATTING) && (NewInput->m_PlayerFlags&PLAYERFLAG_CHATTING))
return;
2014-02-21 17:27:00 +00:00
AfkVoteTimer(NewInput);
if(m_pCharacter && !m_Paused)
2011-04-19 08:42:48 +00:00
m_pCharacter->OnPredictedInput(NewInput);
}
2010-05-29 07:25:38 +00:00
void CPlayer::OnDirectInput(CNetObj_PlayerInput *NewInput)
{
if (AfkTimer(NewInput->m_TargetX, NewInput->m_TargetY))
return; // we must return if kicked, as player struct is already deleted
2014-02-21 17:27:00 +00:00
AfkVoteTimer(NewInput);
2013-08-18 01:27:30 +00:00
if(NewInput->m_PlayerFlags&PLAYERFLAG_CHATTING)
{
// skip the input if chat is active
if(m_PlayerFlags&PLAYERFLAG_CHATTING)
return;
// reset input
if(m_pCharacter)
m_pCharacter->ResetInput();
m_PlayerFlags = NewInput->m_PlayerFlags;
return;
}
m_PlayerFlags = NewInput->m_PlayerFlags;
2011-04-19 08:42:48 +00:00
if(m_pCharacter)
{
if(!m_Paused)
m_pCharacter->OnDirectInput(NewInput);
else
m_pCharacter->ResetInput();
}
2011-04-19 08:42:48 +00:00
if(!m_pCharacter && m_Team != TEAM_SPECTATORS && (NewInput->m_Fire&1))
2010-05-29 07:25:38 +00:00
m_Spawning = true;
if(((!m_pCharacter && m_Team == TEAM_SPECTATORS) || m_Paused) && m_SpectatorID == SPEC_FREEVIEW)
m_ViewPos = vec2(NewInput->m_TargetX, NewInput->m_TargetY);
// check for activity
if(NewInput->m_Direction || m_LatestActivity.m_TargetX != NewInput->m_TargetX ||
m_LatestActivity.m_TargetY != NewInput->m_TargetY || NewInput->m_Jump ||
NewInput->m_Fire&1 || NewInput->m_Hook)
{
m_LatestActivity.m_TargetX = NewInput->m_TargetX;
m_LatestActivity.m_TargetY = NewInput->m_TargetY;
m_LastActionTick = Server()->Tick();
}
}
2010-05-29 07:25:38 +00:00
CCharacter *CPlayer::GetCharacter()
{
2011-04-19 08:42:48 +00:00
if(m_pCharacter && m_pCharacter->IsAlive())
return m_pCharacter;
return 0;
}
2010-05-29 07:25:38 +00:00
void CPlayer::KillCharacter(int Weapon)
{
2011-04-19 08:42:48 +00:00
if(m_pCharacter)
{
2013-11-15 23:44:49 +00:00
if (m_RespawnTick > Server()->Tick())
return;
2011-04-19 08:42:48 +00:00
m_pCharacter->Die(m_ClientID, Weapon);
2013-11-15 23:44:49 +00:00
2011-04-19 08:42:48 +00:00
delete m_pCharacter;
m_pCharacter = 0;
}
}
2010-05-29 07:25:38 +00:00
void CPlayer::Respawn()
{
2011-01-03 11:50:38 +00:00
if(m_Team != TEAM_SPECTATORS)
2010-05-29 07:25:38 +00:00
m_Spawning = true;
}
void CPlayer::SetTeam(int Team, bool DoChatMsg)
{
// clamp the team
2010-05-29 07:25:38 +00:00
Team = GameServer()->m_pController->ClampTeam(Team);
if(m_Team == Team)
return;
char aBuf[512];
if(DoChatMsg)
{
str_format(aBuf, sizeof(aBuf), "'%s' joined the %s", Server()->ClientName(m_ClientID), GameServer()->m_pController->GetTeamName(Team));
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
}
2013-11-15 23:44:49 +00:00
if(Team == TEAM_SPECTATORS)
2013-11-16 01:36:04 +00:00
{
CGameControllerDDRace* Controller = (CGameControllerDDRace*)GameServer()->m_pController;
Controller->m_Teams.SetForceCharacterTeam(m_ClientID, 0);
2013-11-16 01:36:04 +00:00
}
2013-11-15 23:44:49 +00:00
2010-05-29 07:25:38 +00:00
KillCharacter();
2010-05-29 07:25:38 +00:00
m_Team = Team;
m_LastSetTeam = Server()->Tick();
m_LastActionTick = Server()->Tick();
2013-02-24 16:24:12 +00:00
m_SpectatorID = SPEC_FREEVIEW;
2010-05-29 07:25:38 +00:00
// we got to wait 0.5 secs before respawning
m_RespawnTick = Server()->Tick()+Server()->TickSpeed()/2;
str_format(aBuf, sizeof(aBuf), "team_join player='%d:%s' m_Team=%d", m_ClientID, Server()->ClientName(m_ClientID), m_Team);
GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf);
//GameServer()->m_pController->OnPlayerInfoChange(GameServer()->m_apPlayers[m_ClientID]);
if(Team == TEAM_SPECTATORS)
{
// update spectator modes
for(int i = 0; i < MAX_CLIENTS; ++i)
{
if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->m_SpectatorID == m_ClientID)
GameServer()->m_apPlayers[i]->m_SpectatorID = SPEC_FREEVIEW;
}
}
}
2010-05-29 07:25:38 +00:00
void CPlayer::TryRespawn()
{
vec2 SpawnPos;
if(!GameServer()->m_pController->CanSpawn(m_Team, &SpawnPos))
return;
CGameControllerDDRace* Controller = (CGameControllerDDRace*)GameServer()->m_pController;
m_Spawning = false;
m_pCharacter = new(m_ClientID) CCharacter(&GameServer()->m_World);
m_pCharacter->Spawn(this, SpawnPos);
GameServer()->CreatePlayerSpawn(SpawnPos, m_pCharacter->Teams()->TeamMask(m_pCharacter->Team(), -1, m_ClientID));
if(g_Config.m_SvTeam == 3)
{
2013-12-28 15:27:47 +00:00
int NewTeam = 0;
for(; NewTeam < TEAM_SUPER; NewTeam++)
if(Controller->m_Teams.Count(NewTeam) == 0)
break;
2013-12-28 15:27:47 +00:00
if(NewTeam == TEAM_SUPER)
NewTeam = 0;
Controller->m_Teams.SetForceCharacterTeam(GetCID(), NewTeam);
}
}
bool CPlayer::AfkTimer(int NewTargetX, int NewTargetY)
{
/*
afk timer (x, y = mouse coordinates)
Since a player has to move the mouse to play, this is a better method than checking
the player's position in the game world, because it can easily be bypassed by just locking a key.
Frozen players could be kicked as well, because they can't move.
It also works for spectators.
returns true if kicked
*/
if(m_Authed)
return false; // don't kick admins
if(g_Config.m_SvMaxAfkTime == 0)
return false; // 0 = disabled
if(NewTargetX != m_LastTarget_x || NewTargetY != m_LastTarget_y)
{
m_LastPlaytime = time_get();
m_LastTarget_x = NewTargetX;
m_LastTarget_y = NewTargetY;
m_Sent1stAfkWarning = 0; // afk timer's 1st warning after 50% of sv_max_afk_time
m_Sent2ndAfkWarning = 0;
}
else
{
if(!m_Paused)
{
// not playing, check how long
if(m_Sent1stAfkWarning == 0 && m_LastPlaytime < time_get()-time_freq()*(int)(g_Config.m_SvMaxAfkTime*0.5))
{
sprintf(
m_pAfkMsg,
"You have been afk for %d seconds now. Please note that you get kicked after not playing for %d seconds.",
(int)(g_Config.m_SvMaxAfkTime*0.5),
g_Config.m_SvMaxAfkTime
);
m_pGameServer->SendChatTarget(m_ClientID, m_pAfkMsg);
m_Sent1stAfkWarning = 1;
}
else if(m_Sent2ndAfkWarning == 0 && m_LastPlaytime < time_get()-time_freq()*(int)(g_Config.m_SvMaxAfkTime*0.9))
{
sprintf(
m_pAfkMsg,
"You have been afk for %d seconds now. Please note that you get kicked after not playing for %d seconds.",
(int)(g_Config.m_SvMaxAfkTime*0.9),
g_Config.m_SvMaxAfkTime
);
m_pGameServer->SendChatTarget(m_ClientID, m_pAfkMsg);
m_Sent2ndAfkWarning = 1;
}
else if(m_LastPlaytime < time_get()-time_freq()*g_Config.m_SvMaxAfkTime)
{
CServer* serv = (CServer*)m_pGameServer->Server();
serv->Kick(m_ClientID,"Away from keyboard");
return true;
}
}
}
return false;
}
2014-02-21 17:27:00 +00:00
void CPlayer::AfkVoteTimer(CNetObj_PlayerInput *NewTarget)
2013-08-18 01:27:30 +00:00
{
if(g_Config.m_SvMaxAfkVoteTime == 0)
return;
2014-02-21 17:27:00 +00:00
if(mem_comp(NewTarget, &m_LastTarget, sizeof(CNetObj_PlayerInput)) != 0)
2013-08-18 01:27:30 +00:00
{
m_LastPlaytime = time_get();
2014-02-21 17:27:00 +00:00
mem_copy(&m_LastTarget, NewTarget, sizeof(CNetObj_PlayerInput));
2013-08-18 01:27:30 +00:00
}
else if(m_LastPlaytime < time_get()-time_freq()*g_Config.m_SvMaxAfkVoteTime)
{
m_Afk = true;
return;
}
m_Afk = false;
}
void CPlayer::ProcessPause()
{
char aBuf[128];
if(m_Paused >= PAUSED_PAUSED)
{
if(!m_pCharacter->IsPaused())
{
m_pCharacter->Pause(true);
2014-03-26 13:21:49 +00:00
if(g_Config.m_SvPauseMessages)
{
str_format(aBuf, sizeof(aBuf), (m_Paused == PAUSED_PAUSED) ? "'%s' paused" : "'%s' was force-paused for %ds", Server()->ClientName(m_ClientID), m_ForcePauseTime/Server()->TickSpeed());
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
}
GameServer()->CreateDeath(m_pCharacter->m_Pos, m_ClientID, m_pCharacter->Teams()->TeamMask(m_pCharacter->Team(), -1, m_ClientID));
GameServer()->CreateSound(m_pCharacter->m_Pos, SOUND_PLAYER_DIE, m_pCharacter->Teams()->TeamMask(m_pCharacter->Team(), -1, m_ClientID));
m_NextPauseTick = Server()->Tick() + g_Config.m_SvPauseFrequency * Server()->TickSpeed();
}
}
else
{
if(m_pCharacter->IsPaused())
{
m_pCharacter->Pause(false);
2014-03-26 13:21:49 +00:00
if(g_Config.m_SvPauseMessages)
{
str_format(aBuf, sizeof(aBuf), "'%s' resumed", Server()->ClientName(m_ClientID));
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
}
GameServer()->CreatePlayerSpawn(m_pCharacter->m_Pos, m_pCharacter->Teams()->TeamMask(m_pCharacter->Team(), -1, m_ClientID));
m_NextPauseTick = Server()->Tick() + g_Config.m_SvPauseFrequency * Server()->TickSpeed();
}
}
}
bool CPlayer::IsPlaying()
{
if(m_pCharacter && m_pCharacter->IsAlive())
return true;
return false;
}
2013-12-31 05:13:57 +00:00
void CPlayer::FindDuplicateSkins()
{
if (m_TeeInfos.m_UseCustomColor == 0 && !m_StolenSkin) return;
m_StolenSkin = 0;
for (int i = 0; i < MAX_CLIENTS; ++i)
{
if (i == m_ClientID) continue;
if(GameServer()->m_apPlayers[i])
{
if (GameServer()->m_apPlayers[i]->m_StolenSkin) continue;
if ((GameServer()->m_apPlayers[i]->m_TeeInfos.m_UseCustomColor == m_TeeInfos.m_UseCustomColor) &&
(GameServer()->m_apPlayers[i]->m_TeeInfos.m_ColorFeet == m_TeeInfos.m_ColorFeet) &&
(GameServer()->m_apPlayers[i]->m_TeeInfos.m_ColorBody == m_TeeInfos.m_ColorBody) &&
!str_comp(GameServer()->m_apPlayers[i]->m_TeeInfos.m_SkinName, m_TeeInfos.m_SkinName))
{
m_StolenSkin = 1;
return;
}
}
}
}