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. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#ifndef GAME_SERVER_GAMECONTEXT_H
|
|
|
|
#define GAME_SERVER_GAMECONTEXT_H
|
|
|
|
|
|
|
|
#include <engine/server.h>
|
|
|
|
#include <engine/console.h>
|
|
|
|
#include <engine/shared/memheap.h>
|
|
|
|
|
|
|
|
#include <game/layers.h>
|
2011-03-26 16:44:34 +00:00
|
|
|
#include <game/voting.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
#include "eventhandler.h"
|
|
|
|
#include "gamecontroller.h"
|
|
|
|
#include "gameworld.h"
|
|
|
|
#include "player.h"
|
|
|
|
|
2011-04-09 06:41:31 +00:00
|
|
|
#include "score.h"
|
2010-05-29 07:25:38 +00:00
|
|
|
/*
|
|
|
|
Tick
|
|
|
|
Game Context (CGameContext::tick)
|
|
|
|
Game World (GAMEWORLD::tick)
|
|
|
|
Reset world if requested (GAMEWORLD::reset)
|
|
|
|
All entities in the world (ENTITY::tick)
|
|
|
|
All entities in the world (ENTITY::tick_defered)
|
|
|
|
Remove entities marked for deletion (GAMEWORLD::remove_entities)
|
|
|
|
Game Controller (GAMECONTROLLER::tick)
|
|
|
|
All players (CPlayer::tick)
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
Snap
|
|
|
|
Game Context (CGameContext::snap)
|
|
|
|
Game World (GAMEWORLD::snap)
|
|
|
|
All entities in the world (ENTITY::snap)
|
|
|
|
Game Controller (GAMECONTROLLER::snap)
|
|
|
|
Events handler (EVENT_HANDLER::snap)
|
|
|
|
All players (CPlayer::snap)
|
|
|
|
|
|
|
|
*/
|
|
|
|
class CGameContext : public IGameServer
|
|
|
|
{
|
|
|
|
IServer *m_pServer;
|
|
|
|
class IConsole *m_pConsole;
|
|
|
|
CLayers m_Layers;
|
|
|
|
CCollision m_Collision;
|
|
|
|
CNetObjHandler m_NetObjHandler;
|
|
|
|
CTuningParams m_Tuning;
|
|
|
|
|
2011-08-13 00:11:06 +00:00
|
|
|
static void ConTuneParam(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConTuneReset(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConTuneDump(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConChangeMap(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConRestart(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConBroadcast(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConSay(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConSetTeam(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConSetTeamAll(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConAddVote(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConRemoveVote(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConForceVote(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConClearVotes(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConVote(IConsole::IResult *pResult, void *pUserData);
|
2010-05-29 07:25:38 +00:00
|
|
|
static void ConchainSpecialMotdupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CGameContext(int Resetting);
|
|
|
|
void Construct(int Resetting);
|
|
|
|
|
|
|
|
bool m_Resetting;
|
|
|
|
public:
|
|
|
|
IServer *Server() const { return m_pServer; }
|
|
|
|
class IConsole *Console() { return m_pConsole; }
|
|
|
|
CCollision *Collision() { return &m_Collision; }
|
|
|
|
CTuningParams *Tuning() { return &m_Tuning; }
|
|
|
|
|
|
|
|
CGameContext();
|
|
|
|
~CGameContext();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void Clear();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CEventHandler m_Events;
|
|
|
|
CPlayer *m_apPlayers[MAX_CLIENTS];
|
|
|
|
|
|
|
|
IGameController *m_pController;
|
|
|
|
CGameWorld m_World;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// helper functions
|
2011-02-12 10:40:36 +00:00
|
|
|
class CCharacter *GetPlayerChar(int ClientID);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// voting
|
2011-03-25 09:26:59 +00:00
|
|
|
void StartVote(const char *pDesc, const char *pCommand, const char *pReason);
|
2010-05-29 07:25:38 +00:00
|
|
|
void EndVote();
|
2011-02-12 10:40:36 +00:00
|
|
|
void SendVoteSet(int ClientID);
|
|
|
|
void SendVoteStatus(int ClientID, int Total, int Yes, int No);
|
|
|
|
void AbortVoteKickOnDisconnect(int ClientID);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_VoteCreator;
|
|
|
|
int64 m_VoteCloseTime;
|
|
|
|
bool m_VoteUpdate;
|
|
|
|
int m_VotePos;
|
2011-03-26 16:44:34 +00:00
|
|
|
char m_aVoteDescription[VOTE_DESC_LENGTH];
|
|
|
|
char m_aVoteCommand[VOTE_CMD_LENGTH];
|
|
|
|
char m_aVoteReason[VOTE_REASON_LENGTH];
|
2011-03-26 21:06:29 +00:00
|
|
|
int m_NumVoteOptions;
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_VoteEnforce;
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
VOTE_ENFORCE_UNKNOWN=0,
|
|
|
|
VOTE_ENFORCE_NO,
|
|
|
|
VOTE_ENFORCE_YES,
|
|
|
|
};
|
|
|
|
CHeap *m_pVoteOptionHeap;
|
2011-03-26 16:44:34 +00:00
|
|
|
CVoteOptionServer *m_pVoteOptionFirst;
|
|
|
|
CVoteOptionServer *m_pVoteOptionLast;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
// helper functions
|
2010-09-08 16:22:11 +00:00
|
|
|
void CreateDamageInd(vec2 Pos, float AngleMod, int Amount, int Mask=-1);
|
2010-11-11 09:12:03 +00:00
|
|
|
void CreateExplosion(vec2 Pos, int Owner, int Weapon, bool NoDamage, int ActivatedTeam, int Mask);
|
2010-09-08 16:22:11 +00:00
|
|
|
void CreateHammerHit(vec2 Pos, int Mask=-1);
|
|
|
|
void CreatePlayerSpawn(vec2 Pos, int Mask=-1);
|
|
|
|
void CreateDeath(vec2 Pos, int Who, int Mask=-1);
|
2010-05-29 07:25:38 +00:00
|
|
|
void CreateSound(vec2 Pos, int Sound, int Mask=-1);
|
2011-04-13 18:37:12 +00:00
|
|
|
void CreateSoundGlobal(int Sound, int Target=-1);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2011-01-29 00:59:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CHAT_ALL=-2,
|
|
|
|
CHAT_SPEC=-1,
|
|
|
|
CHAT_RED=0,
|
|
|
|
CHAT_BLUE=1
|
|
|
|
};
|
|
|
|
|
|
|
|
// network
|
|
|
|
void SendChatTarget(int To, const char *pText);
|
2011-02-13 05:35:13 +00:00
|
|
|
void SendChat(int ClientID, int Team, const char *pText, int SpamProtectionClientID = -1);
|
2011-02-12 10:40:36 +00:00
|
|
|
void SendEmoticon(int ClientID, int Emoticon);
|
|
|
|
void SendWeaponPickup(int ClientID, int Weapon);
|
|
|
|
void SendBroadcast(const char *pText, int ClientID);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
//
|
|
|
|
void CheckPureTuning();
|
2011-02-12 10:40:36 +00:00
|
|
|
void SendTuningParams(int ClientID);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// engine events
|
|
|
|
virtual void OnInit();
|
|
|
|
virtual void OnConsoleInit();
|
|
|
|
virtual void OnShutdown();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void OnTick();
|
|
|
|
virtual void OnPreSnap();
|
2011-02-12 10:40:36 +00:00
|
|
|
virtual void OnSnap(int ClientID);
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void OnPostSnap();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-02-12 10:40:36 +00:00
|
|
|
virtual void OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2011-02-12 10:40:36 +00:00
|
|
|
virtual void OnClientConnected(int ClientID);
|
|
|
|
virtual void OnClientEnter(int ClientID);
|
2011-02-14 18:41:32 +00:00
|
|
|
virtual void OnClientDrop(int ClientID, const char *pReason);
|
2011-02-12 10:40:36 +00:00
|
|
|
virtual void OnClientDirectInput(int ClientID, void *pInput);
|
|
|
|
virtual void OnClientPredictedInput(int ClientID, void *pInput);
|
2010-12-19 13:11:14 +00:00
|
|
|
|
2011-03-15 08:58:57 +00:00
|
|
|
virtual bool IsClientReady(int ClientID);
|
2011-03-20 14:33:49 +00:00
|
|
|
virtual bool IsClientPlayer(int ClientID);
|
2011-03-15 08:58:57 +00:00
|
|
|
|
2011-02-16 11:31:47 +00:00
|
|
|
virtual const char *GameType();
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual const char *Version();
|
|
|
|
virtual const char *NetVersion();
|
2011-01-29 00:59:50 +00:00
|
|
|
|
2011-04-09 06:41:31 +00:00
|
|
|
// DDRace
|
|
|
|
|
|
|
|
int ProcessSpamProtection(int ClientID);
|
2011-04-19 19:44:02 +00:00
|
|
|
int GetDDRaceTeam(int ClientID);
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2011-01-29 00:59:50 +00:00
|
|
|
private:
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2011-08-27 15:11:39 +00:00
|
|
|
IConsole* m_pChatCommands;
|
2011-04-09 06:41:31 +00:00
|
|
|
bool m_VoteWillPass;
|
2011-01-29 00:59:50 +00:00
|
|
|
class IScore *m_pScore;
|
|
|
|
|
|
|
|
//DDRace Console Commands
|
|
|
|
|
2011-08-13 00:11:06 +00:00
|
|
|
//static void ConMute(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
//static void ConUnmute(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConKillPlayer(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
|
|
|
|
static void ConNinja(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConUnSuper(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConSuper(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConShotgun(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConGrenade(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConRifle(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConWeapons(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConUnShotgun(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConUnGrenade(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConUnRifle(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConUnWeapons(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConAddWeapon(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConRemoveWeapon(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
|
|
|
|
void ModifyWeapons(IConsole::IResult *pResult, void *pUserData, int Weapon, bool Remove);
|
|
|
|
void MoveCharacter(int ClientID, int X, int Y, bool Raw = false);
|
|
|
|
static void ConGoLeft(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConGoRight(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConGoUp(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConGoDown(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConMove(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConMoveRaw(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
|
|
|
|
static void ConTeleport(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
|
|
|
|
static void ConCredits(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConInfo(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConHelp(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConSettings(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConRules(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConKill(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConTogglePause(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConForcePause(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConTop5(IConsole::IResult *pResult, void *pUserData);
|
2011-02-13 18:45:17 +00:00
|
|
|
#if defined(CONF_SQL)
|
2011-08-13 00:11:06 +00:00
|
|
|
static void ConTimes(IConsole::IResult *pResult, void *pUserData);
|
2011-02-13 18:45:17 +00:00
|
|
|
#endif
|
2011-03-22 19:15:15 +00:00
|
|
|
|
2011-08-13 00:11:06 +00:00
|
|
|
static void ConUTF8(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConRank(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConBroadTime(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConJoinTeam(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConMe(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConToggleEyeEmote(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConToggleBroadcast(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConEyeEmote(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConShowOthers(IConsole::IResult *pResult, void *pUserData);
|
2011-08-27 15:11:39 +00:00
|
|
|
static void ConShowOthersChat(IConsole::IResult *pResult, void *pUserData);
|
2011-08-13 00:11:06 +00:00
|
|
|
|
|
|
|
static void ConMute(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConMuteID(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConMuteIP(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConUnmute(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConMutes(IConsole::IResult *pResult, void *pUserData);
|
2011-02-08 12:44:59 +00:00
|
|
|
|
2011-02-23 21:39:53 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
MAX_MUTES=32,
|
|
|
|
};
|
|
|
|
struct CMute
|
|
|
|
{
|
|
|
|
NETADDR m_Addr;
|
|
|
|
int m_Expire;
|
|
|
|
};
|
|
|
|
|
|
|
|
CMute m_aMutes[MAX_MUTES];
|
|
|
|
int m_NumMutes;
|
2011-04-12 20:18:15 +00:00
|
|
|
void Mute(IConsole::IResult *pResult, NETADDR *Addr, int Secs, const char *pDisplayName);
|
2011-02-23 21:39:53 +00:00
|
|
|
|
2011-01-29 00:59:50 +00:00
|
|
|
public:
|
|
|
|
CLayers *Layers() { return &m_Layers; }
|
|
|
|
class IScore *Score() { return m_pScore; }
|
|
|
|
bool m_VoteKick;
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
VOTE_ENFORCE_NO_ADMIN = VOTE_ENFORCE_YES + 1,
|
|
|
|
VOTE_ENFORCE_YES_ADMIN
|
|
|
|
};
|
2011-02-13 05:35:13 +00:00
|
|
|
void SendRecord(int ClientID);
|
2011-01-29 00:59:50 +00:00
|
|
|
static void SendChatResponse(const char *pLine, void *pUser);
|
|
|
|
static void SendChatResponseAll(const char *pLine, void *pUser);
|
|
|
|
struct ChatResponseInfo
|
|
|
|
{
|
|
|
|
CGameContext *m_GameContext;
|
|
|
|
int m_To;
|
|
|
|
};
|
2011-02-13 05:35:13 +00:00
|
|
|
virtual void OnSetAuthed(int ClientID,int Level);
|
2011-01-29 00:59:50 +00:00
|
|
|
virtual bool PlayerCollision();
|
|
|
|
virtual bool PlayerHooking();
|
2011-05-30 20:05:28 +00:00
|
|
|
|
|
|
|
void ResetTuning();
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
2011-02-02 10:49:19 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
inline int CmaskAll() { return -1; }
|
2011-02-12 10:40:36 +00:00
|
|
|
inline int CmaskOne(int ClientID) { return 1<<ClientID; }
|
|
|
|
inline int CmaskAllExceptOne(int ClientID) { return 0x7fffffff^CmaskOne(ClientID); }
|
|
|
|
inline bool CmaskIsSet(int Mask, int ClientID) { return (Mask&CmaskOne(ClientID)) != 0; }
|
2011-01-29 00:59:50 +00:00
|
|
|
#endif
|