Revert last not working fix

This commit is contained in:
btd 2010-09-11 13:31:36 +04:00
parent 1119432e60
commit bbe66c5f20
10 changed files with 6256 additions and 2 deletions

115
src/base/detect.h~ Normal file
View file

@ -0,0 +1,115 @@
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
#ifndef BASELIB_FILE_CONFIG_H
#define BASELIB_FILE_CONFIG_H
/*
this file detected the family, platform and architecture
to compile for.
*/
/* platforms */
/* windows Family */
#if defined(WIN64) || defined(_WIN64)
/* Hmm, is this IA64 or x86-64? */
#define CONF_FAMILY_WINDOWS 1
#define CONF_FAMILY_STRING "windows"
#define CONF_PLATFORM_WIN64 1
#define CONF_PLATFORM_STRING "win64"
#elif defined(WIN32) || defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
#define CONF_FAMILY_WINDOWS 1
#define CONF_FAMILY_STRING "windows"
#define CONF_PLATFORM_WIN32 1
#define CONF_PLATFORM_STRING "win32"
#endif
/* unix family */
#if defined(__FreeBSD__)
#define CONF_FAMILY_UNIX 1
#define CONF_FAMILY_STRING "unix"
#define CONF_PLATFORM_FREEBSD 1
#define CONF_PLATFORM_STRING "freebsd"
#endif
#if defined(__OpenBSD__)
#define CONF_FAMILY_UNIX 1
#define CONF_FAMILY_STRING "unix"
#define CONF_PLATFORM_OPENBSD 1
#define CONF_PLATFORM_STRING "openbsd"
#endif
#if defined(__LINUX__) || defined(__linux__)
#define CONF_FAMILY_UNIX 1
#define CONF_FAMILY_STRING "unix"
#define CONF_PLATFORM_LINUX 1
#define CONF_PLATFORM_STRING "linux"
#endif
#if defined(MACOSX) || defined(__APPLE__) || defined(__DARWIN__)
#define CONF_FAMILY_UNIX 1
#define CONF_FAMILY_STRING "unix"
#define CONF_PLATFORM_MACOSX 1
#define CONF_PLATFORM_STRING "macosx"
#endif
#if defined(__sun)
#define CONF_FAMILY_UNIX 1
#define CONF_FAMILY_STRING "unix"
#define CONF_PLATFROM_SOLARIS 1
#define CONF_PLATFORM_STRING "solaris"
#endif
/* beos family */
#if defined(__BeOS) || defined(__BEOS__)
#define CONF_FAMILY_BEOS 1
#define CONF_FAMILY_STRING "beos"
#define CONF_PLATFORM_BEOS 1
#define CONF_PLATFORM_STRING "beos"
#endif
/* architectures */
#if defined(i386) || defined(__i386__) || defined(__x86__) || defined(CONF_PLATFORM_WIN32)
#define CONF_ARCH_IA32 1
#define CONF_ARCH_STRING "ia32"
#define CONF_ARCH_ENDIAN_LITTLE 1
#endif
#if defined(__ia64__)
#define CONF_ARCH_IA64 1
#define CONF_ARCH_STRING "ia64"
#define CONF_ARCH_ENDIAN_LITTLE 1
#endif
#if defined(__amd64__) || defined(__x86_64__)
#define CONF_ARCH_AMD64 1
#define CONF_ARCH_STRING "amd64"
#define CONF_ARCH_ENDIAN_LITTLE 1
#endif
#if defined(__powerpc__) || defined(__ppc__)
#define CONF_ARCH_PPC 1
#define CONF_ARCH_STRING "ppc"
#define CONF_ARCH_ENDIAN_BIG 1
#endif
#if defined(__sparc__)
#define CONF_ARCH_SPARC 1
#define CONF_ARCH_STRING "sparc"
#define CONF_ARCH_ENDIAN_BIG 1
#endif
#ifndef CONF_FAMILY_STRING
#define CONF_FAMILY_STRING "unknown"
#endif
#ifndef CONF_PLATFORM_STRING
#define CONF_PLATFORM_STRING "unknown"
#endif
#ifndef CONF_ARCH_STRING
#define CONF_ARCH_STRING "unknown"
#endif
#endif

58
src/base/math.h~ Normal file
View file

@ -0,0 +1,58 @@
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
#ifndef BASE_MATH_H
#define BASE_MATH_H
#include <stdlib.h>
template <typename T>
inline T clamp(T val, T min, T max)
{
if(val < min)
return min;
if(val > max)
return max;
return val;
}
inline float sign(float f)
{
return f<0.0f?-1.0f:1.0f;
}
inline int round(float f)
{
if(f > 0)
return (int)(f+0.5f);
return (int)(f-0.5f);
}
template<typename T, typename TB>
inline T mix(const T a, const T b, TB amount)
{
return a + (b-a)*amount;
}
inline float frandom() { return rand()/(float)(RAND_MAX); }
// float to fixed
inline int f2fx(float v) { return (int)(v*(float)(1<<10)); }
inline float fx2f(int v) { return v*(1.0f/(1<<10)); }
class fxp
{
int value;
public:
void set(int v) { value = v; }
int get() const { return value; }
fxp &operator = (int v) { value = v<<10; return *this; }
fxp &operator = (float v) { value = (int)(v*(float)(1<<10)); return *this; }
operator float() const { return value/(float)(1<<10); }
};
const float pi = 3.1415926535897932384626433f;
template <typename T> inline T min(T a, T b) { return a<b?a:b; }
template <typename T> inline T max(T a, T b) { return a>b?a:b; }
template <typename T> inline T absolute(T a) { return a<T(0)?-a:a; }
#endif // BASE_MATH_H

247
src/base/stdint.h~ Normal file
View file

@ -0,0 +1,247 @@
// ISO C9x compliant stdint.h for Microsoft Visual Studio
// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
//
// Copyright (c) 2006-2008 Alexander Chemeris
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. The name of the author may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef _MSC_VER // [
#error "Use this header only with Microsoft Visual C++ compilers!"
#endif // _MSC_VER ]
#ifndef _MSC_STDINT_H_ // [
#define _MSC_STDINT_H_
#if _MSC_VER > 1000
#pragma once
#endif
#include <limits.h>
// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
// or compiler give many errors like this:
// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
#ifdef __cplusplus
extern "C" {
#endif
# include <wchar.h>
#ifdef __cplusplus
}
#endif
// Define _W64 macros to mark types changing their size, like intptr_t.
#ifndef _W64
# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
# define _W64 __w64
# else
# define _W64
# endif
#endif
// 7.18.1 Integer types
// 7.18.1.1 Exact-width integer types
// Visual Studio 6 and Embedded Visual C++ 4 doesn't
// realize that, e.g. char has the same size as __int8
// so we give up on __intX for them.
#if (_MSC_VER < 1300)
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#else
typedef signed __int8 int8_t;
typedef signed __int16 int16_t;
typedef signed __int32 int32_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
#endif
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
// 7.18.1.2 Minimum-width integer types
typedef int8_t int_least8_t;
typedef int16_t int_least16_t;
typedef int32_t int_least32_t;
typedef int64_t int_least64_t;
typedef uint8_t uint_least8_t;
typedef uint16_t uint_least16_t;
typedef uint32_t uint_least32_t;
typedef uint64_t uint_least64_t;
// 7.18.1.3 Fastest minimum-width integer types
typedef int8_t int_fast8_t;
typedef int16_t int_fast16_t;
typedef int32_t int_fast32_t;
typedef int64_t int_fast64_t;
typedef uint8_t uint_fast8_t;
typedef uint16_t uint_fast16_t;
typedef uint32_t uint_fast32_t;
typedef uint64_t uint_fast64_t;
// 7.18.1.4 Integer types capable of holding object pointers
#ifdef _WIN64 // [
typedef signed __int64 intptr_t;
typedef unsigned __int64 uintptr_t;
#else // _WIN64 ][
typedef _W64 signed int intptr_t;
typedef _W64 unsigned int uintptr_t;
#endif // _WIN64 ]
// 7.18.1.5 Greatest-width integer types
typedef int64_t intmax_t;
typedef uint64_t uintmax_t;
// 7.18.2 Limits of specified-width integer types
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
// 7.18.2.1 Limits of exact-width integer types
#define INT8_MIN ((int8_t)_I8_MIN)
#define INT8_MAX _I8_MAX
#define INT16_MIN ((int16_t)_I16_MIN)
#define INT16_MAX _I16_MAX
#define INT32_MIN ((int32_t)_I32_MIN)
#define INT32_MAX _I32_MAX
#define INT64_MIN ((int64_t)_I64_MIN)
#define INT64_MAX _I64_MAX
#define UINT8_MAX _UI8_MAX
#define UINT16_MAX _UI16_MAX
#define UINT32_MAX _UI32_MAX
#define UINT64_MAX _UI64_MAX
// 7.18.2.2 Limits of minimum-width integer types
#define INT_LEAST8_MIN INT8_MIN
#define INT_LEAST8_MAX INT8_MAX
#define INT_LEAST16_MIN INT16_MIN
#define INT_LEAST16_MAX INT16_MAX
#define INT_LEAST32_MIN INT32_MIN
#define INT_LEAST32_MAX INT32_MAX
#define INT_LEAST64_MIN INT64_MIN
#define INT_LEAST64_MAX INT64_MAX
#define UINT_LEAST8_MAX UINT8_MAX
#define UINT_LEAST16_MAX UINT16_MAX
#define UINT_LEAST32_MAX UINT32_MAX
#define UINT_LEAST64_MAX UINT64_MAX
// 7.18.2.3 Limits of fastest minimum-width integer types
#define INT_FAST8_MIN INT8_MIN
#define INT_FAST8_MAX INT8_MAX
#define INT_FAST16_MIN INT16_MIN
#define INT_FAST16_MAX INT16_MAX
#define INT_FAST32_MIN INT32_MIN
#define INT_FAST32_MAX INT32_MAX
#define INT_FAST64_MIN INT64_MIN
#define INT_FAST64_MAX INT64_MAX
#define UINT_FAST8_MAX UINT8_MAX
#define UINT_FAST16_MAX UINT16_MAX
#define UINT_FAST32_MAX UINT32_MAX
#define UINT_FAST64_MAX UINT64_MAX
// 7.18.2.4 Limits of integer types capable of holding object pointers
#ifdef _WIN64 // [
# define INTPTR_MIN INT64_MIN
# define INTPTR_MAX INT64_MAX
# define UINTPTR_MAX UINT64_MAX
#else // _WIN64 ][
# define INTPTR_MIN INT32_MIN
# define INTPTR_MAX INT32_MAX
# define UINTPTR_MAX UINT32_MAX
#endif // _WIN64 ]
// 7.18.2.5 Limits of greatest-width integer types
#define INTMAX_MIN INT64_MIN
#define INTMAX_MAX INT64_MAX
#define UINTMAX_MAX UINT64_MAX
// 7.18.3 Limits of other integer types
#ifdef _WIN64 // [
# define PTRDIFF_MIN _I64_MIN
# define PTRDIFF_MAX _I64_MAX
#else // _WIN64 ][
# define PTRDIFF_MIN _I32_MIN
# define PTRDIFF_MAX _I32_MAX
#endif // _WIN64 ]
#define SIG_ATOMIC_MIN INT_MIN
#define SIG_ATOMIC_MAX INT_MAX
#ifndef SIZE_MAX // [
# ifdef _WIN64 // [
# define SIZE_MAX _UI64_MAX
# else // _WIN64 ][
# define SIZE_MAX _UI32_MAX
# endif // _WIN64 ]
#endif // SIZE_MAX ]
// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
#ifndef WCHAR_MIN // [
# define WCHAR_MIN 0
#endif // WCHAR_MIN ]
#ifndef WCHAR_MAX // [
# define WCHAR_MAX _UI16_MAX
#endif // WCHAR_MAX ]
#define WINT_MIN 0
#define WINT_MAX _UI16_MAX
#endif // __STDC_LIMIT_MACROS ]
// 7.18.4 Limits of other integer types
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
// 7.18.4.1 Macros for minimum-width integer constants
#define INT8_C(val) val##i8
#define INT16_C(val) val##i16
#define INT32_C(val) val##i32
#define INT64_C(val) val##i64
#define UINT8_C(val) val##ui8
#define UINT16_C(val) val##ui16
#define UINT32_C(val) val##ui32
#define UINT64_C(val) val##ui64
// 7.18.4.2 Macros for greatest-width integer constants
#define INTMAX_C INT64_C
#define UINTMAX_C UINT64_C
#endif // __STDC_CONSTANT_MACROS ]
#endif // _MSC_STDINT_H_ ]

1595
src/base/system.c~ Normal file

File diff suppressed because it is too large Load diff

1143
src/base/system.h~ Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -78,6 +78,7 @@ bool CCharacter::Spawn(CPlayer *pPlayer, vec2 Pos)
CGameControllerDDRace* Controller = (CGameControllerDDRace*)GameServer()->m_pController;
m_Core.Init(&GameServer()->m_World.m_Core, GameServer()->Collision(), &Controller->m_Teams.m_Core);
m_Core.m_Pos = m_Pos;
m_Core.m_Id = GetPlayer()->GetCID();
GameServer()->m_World.m_Core.m_apCharacters[m_pPlayer->GetCID()] = &m_Core;
m_ReckoningTick = 0;
@ -1327,4 +1328,4 @@ void CCharacter::Snap(int SnappingClient)
}
Character->m_PlayerState = m_PlayerState;
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
// copyright (c) 2007 magnus auvinen, see licence.txt for more info/*
#include <game/mapitems.h>
/*#include <game/mapitems.h>
#include <game/server/entities/character.h>
#include <game/server/entities/flag.h>
#include <game/server/player.h>

422
src/game/server/player.cpp~ Normal file
View file

@ -0,0 +1,422 @@
#include <new>
#include <stdio.h>
#include <engine/server.h>
#include <engine/server/server.h>
#include <engine/shared/config.h>
#include "player.h"
#include "gamecontext.h"
#include <game/gamecore.h>
#include "gamemodes/DDRace.h"
MACRO_ALLOC_POOL_ID_IMPL (CPlayer, MAX_CLIENTS)
IServer *CPlayer::Server () const const
{
return m_pGameServer->Server ();
}
CPlayer::CPlayer (CGameContext * pGameServer, int CID, int Team)
{
m_pGameServer = pGameServer;
m_RespawnTick = Server ()->Tick ();
m_DieTick = Server ()->Tick ();
m_ScoreStartTick = Server ()->Tick ();
Character = 0;
m_Muted = 0;
this->m_ClientID = CID;
m_Team = GameServer ()->m_pController->ClampTeam (Team);
m_LastPlaytime = time_get ();
m_LastTarget_x = 0;
m_LastTarget_y = 0;
m_SentAfkWarning = 0; // afk timer's 1st warning after 50% of sv_max_afk_time
m_SentAfkWarning2 = 0;
m_PauseInfo.m_Respawn = false;
if (!g_Config.m_SvShowOthers)
m_ShowOthers = false;
else
m_ShowOthers = true;
m_IsUsingRaceClient = false;
m_LastSentTime = 0;
GameServer ()->Score ()->PlayerData (CID)->Reset ();
}
CPlayer::~CPlayer ()
{
delete Character;
Character = 0;
}
void
CPlayer::Tick ()
{
Server ()->SetClientAuthed (m_ClientID, m_Authed);
Server ()->SetClientScore (m_ClientID, m_Score);
if (m_Muted > 0)
m_Muted--;
// do latency stuff
{
IServer::CClientInfo Info;
if (Server ()->GetClientInfo (m_ClientID, &Info))
{
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);
}
// each second
if (Server ()->Tick () % Server ()->TickSpeed () == 0)
{
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;
}
}
if (!Character
&& m_DieTick + Server ()->TickSpeed () * 3 <= Server ()->Tick ())
m_Spawning = true;
if (Character)
{
if (Character->IsAlive ())
{
m_ViewPos = Character->m_Pos;
}
else
{
delete Character;
Character = 0;
}
}
else if (m_Spawning && m_RespawnTick <= Server ()->Tick ())
TryRespawn ();
// send best time
if (m_IsUsingRaceClient)
{
if (m_LastSentTime > GameServer ()->m_pController->m_CurrentRecord
|| (m_LastSentTime == 0
&& GameServer ()->m_pController->m_CurrentRecord > 0))
{
//dbg_msg("player", "Record message sended");
char aBuf[16];
str_format (aBuf, sizeof (aBuf), "%.0f", GameServer ()->m_pController->m_CurrentRecord * 100.0f); // damn ugly but the only way i know to do it
int TimeToSend;
sscanf (aBuf, "%d", &TimeToSend);
CNetMsg_Sv_Record Msg;
Msg.m_Time = TimeToSend;
Server ()->SendPackMsg (&Msg, MSGFLAG_VITAL, m_ClientID);
m_LastSentTime = GameServer ()->m_pController->m_CurrentRecord;
}
}
}
void
CPlayer::Snap (int SnappingClient)
{
CNetObj_ClientInfo *ClientInfo =
static_cast <
CNetObj_ClientInfo *
>(Server ()->
SnapNewItem (NETOBJTYPE_CLIENTINFO, m_ClientID,
sizeof (CNetObj_ClientInfo)));
StrToInts (&ClientInfo->m_Name0, 6, Server ()->ClientName (m_ClientID));
StrToInts (&ClientInfo->m_Skin0, 6, m_TeeInfos.m_SkinName);
ClientInfo->m_UseCustomColor = m_TeeInfos.m_UseCustomColor;
ClientInfo->m_ColorBody = m_TeeInfos.m_ColorBody;
ClientInfo->m_ColorFeet = m_TeeInfos.m_ColorFeet;
CNetObj_PlayerInfo *Info =
static_cast <
CNetObj_PlayerInfo *
>(Server ()->
SnapNewItem (NETOBJTYPE_PLAYERINFO, m_ClientID,
sizeof (CNetObj_PlayerInfo)));
Info->m_Latency = m_Latency.m_Min;
Info->m_LatencyFlux = m_Latency.m_Max - m_Latency.m_Min;
Info->m_Local = 0;
Info->m_ClientId = m_ClientID;
if (m_ClientID == SnappingClient)
Info->m_Local = 1;
// send 0 if times of otheres are not shown
if (SnappingClient != m_ClientID)
Info->m_Score = 0;
else
Info->m_Score = m_Score;
Info->m_Team = m_Team;
}
void
CPlayer::OnDisconnect ()
{
KillCharacter ();
if (Server ()->ClientIngame (m_ClientID))
{
char aBuf[512];
str_format (aBuf, sizeof (aBuf), "%s has left the game",
Server ()->ClientName (m_ClientID));
GameServer ()->SendChat (-1, CGameContext::CHAT_ALL, aBuf);
char Cmd[64];
str_format (aBuf, sizeof (aBuf), "leave player='%d:%s'", m_ClientID,
Server ()->ClientName (m_ClientID));
GameServer ()->Console ()->Print (IConsole::OUTPUT_LEVEL_STANDARD,
"game", aBuf);
if (m_Muted > 0)
{
str_format (Cmd, sizeof (Cmd), "ban %d %d '%s'", m_ClientID,
m_Muted / Server ()->TickSpeed (), "ppc");
GameServer ()->Console ()->ExecuteLine (Cmd, 3, -1);
}
}
}
void
CPlayer::OnPredictedInput (CNetObj_PlayerInput * NewInput)
{
if (Character)
Character->OnPredictedInput (NewInput);
}
void
CPlayer::OnDirectInput (CNetObj_PlayerInput * NewInput)
{
if (Character)
Character->OnDirectInput (NewInput);
if (!Character && m_Team >= 0 && (NewInput->m_Fire & 1))
m_Spawning = true;
if (!Character && m_Team == -1)
m_ViewPos = vec2 (NewInput->m_TargetX, NewInput->m_TargetY);
AfkTimer (NewInput->m_TargetX, NewInput->m_TargetY);
}
CCharacter *
CPlayer::GetCharacter ()
{
if (Character && Character->IsAlive ())
return Character;
return 0;
}
void
CPlayer::KillCharacter (int Weapon)
{
if (Character)
{
Character->Die (m_ClientID, Weapon);
delete Character;
Character = 0;
}
}
void
CPlayer::Respawn ()
{
if (m_Team > -1)
m_Spawning = true;
}
void
CPlayer::SetTeam (int Team)
{
// clamp the team
Team = GameServer ()->m_pController->ClampTeam (Team);
if (m_Team == Team)
return;
char aBuf[512];
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);
KillCharacter ();
m_Team = Team;
// 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]);
}
void
CPlayer::TryRespawn ()
{
if (m_PauseInfo.m_Respawn)
{
Character = new (m_ClientID) CCharacter (&GameServer ()->m_World);
Character->Spawn (this, m_PauseInfo.m_Core.m_Pos);
GameServer ()->CreatePlayerSpawn (m_PauseInfo.m_Core.m_Pos);
LoadCharacter ();
}
else
{
vec2 SpawnPos = vec2 (100.0f, -60.0f);
if (!GameServer ()->m_pController->CanSpawn (this, &SpawnPos))
return;
// check if the position is occupado
CEntity *apEnts[2] = { 0 };
int NumEnts =
GameServer ()->m_World.FindEntities (SpawnPos, 64, apEnts, 2,
NETOBJTYPE_CHARACTER);
if (NumEnts < 3)
{
m_Spawning = false;
Character = new (m_ClientID) CCharacter (&GameServer ()->m_World);
Character->Spawn (this, SpawnPos);
GameServer ()->CreatePlayerSpawn (SpawnPos);
}
}
}
void
CPlayer::LoadCharacter ()
{
Character->m_Core = m_PauseInfo.m_Core;
if (g_Config.m_SvPauseTime)
Character->m_StartTime =
Server ()->Tick () - (m_PauseInfo.m_PauseTime -
m_PauseInfo.m_StartTime);
Character->m_RaceState = m_PauseInfo.m_RaceState;
Character->m_RefreshTime = Server ()->Tick ();
for (int i = 0; i < NUM_WEAPONS; ++i)
{
if (m_PauseInfo.m_aHasWeapon[i])
{
if (!m_PauseInfo.m_FreezeTime)
{
Character->GiveWeapon (i, -1);
}
else
{
Character->GiveWeapon (i, 0);
}
}
}
Character->m_FreezeTime = m_PauseInfo.m_FreezeTime;
Character->m_Doored = m_PauseInfo.m_Doored;
Character->m_OldPos = m_PauseInfo.m_OldPos;
Character->m_OlderPos = m_PauseInfo.m_OlderPos;
Character->m_LastAction = m_PauseInfo.m_LastAction;
Character->m_Jumped = m_PauseInfo.m_Jumped;
Character->m_Health = m_PauseInfo.m_Health;
Character->m_Armor = m_PauseInfo.m_Armor;
Character->m_PlayerState = m_PauseInfo.m_PlayerState;
Character->m_LastMove = m_PauseInfo.m_LastMove;
Character->m_PrevPos = m_PauseInfo.m_PrevPos;
Character->m_ActiveWeapon = m_PauseInfo.m_ActiveWeapon;
Character->m_LastWeapon = m_PauseInfo.m_LastWeapon;
Character->m_HammerType = m_PauseInfo.m_HammerType;
Character->m_Super = m_PauseInfo.m_Super;
m_PauseInfo.m_Respawn = false;
}
void
CPlayer::SaveCharacter ()
{
m_PauseInfo.m_Core = Character->m_Core;
m_PauseInfo.m_StartTime = Character->m_StartTime;
m_PauseInfo.m_RaceState = Character->m_RaceState;
for (int i = 0; i < WEAPON_NINJA; ++i)
{
m_PauseInfo.m_aHasWeapon[i] = Character->m_aWeapons[i].m_Got;
}
m_PauseInfo.m_FreezeTime = Character->m_FreezeTime;
m_PauseInfo.m_Doored = Character->m_Doored;
m_PauseInfo.m_OldPos = Character->m_OldPos;
m_PauseInfo.m_OlderPos = Character->m_OlderPos;
m_PauseInfo.m_LastAction = Character->m_LastAction;
m_PauseInfo.m_Jumped = Character->m_Jumped;
m_PauseInfo.m_Health = Character->m_Health;
m_PauseInfo.m_Armor = Character->m_Armor;
m_PauseInfo.m_PlayerState = Character->m_PlayerState;
m_PauseInfo.m_LastMove = Character->m_LastMove;
m_PauseInfo.m_PrevPos = Character->m_PrevPos;
m_PauseInfo.m_ActiveWeapon = Character->m_ActiveWeapon;
m_PauseInfo.m_LastWeapon = Character->m_LastWeapon;
m_PauseInfo.m_HammerType = Character->m_HammerType;
m_PauseInfo.m_Super = Character->m_Super;
m_PauseInfo.m_PauseTime = Server ()->Tick ();
//m_PauseInfo.m_RefreshTime = Character->m_RefreshTime;
}
void
CPlayer::AfkTimer (int new_target_x, int new_target_y)
{
/*
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.
*/
if (m_Authed)
return; // don't kick admins
if (g_Config.m_SvMaxAfkTime == 0)
return; // 0 = disabled
if (new_target_x != m_LastTarget_x || new_target_y != m_LastTarget_y)
{
m_LastPlaytime = time_get ();
m_LastTarget_x = new_target_x;
m_LastTarget_y = new_target_y;
m_SentAfkWarning = 0; // afk timer's 1st warning after 50% of sv_max_afk_time
m_SentAfkWarning2 = 0;
}
else
{
// not playing, check how long
if (m_SentAfkWarning == 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_SentAfkWarning = 1;
}
else if (m_SentAfkWarning2 == 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_SentAfkWarning = 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");
}
}
}