ddnet/src/game/server/gamecontext.h

356 lines
14 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. */
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"
#include "score.h"
2013-12-31 05:13:57 +00:00
#ifdef _MSC_VER
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
#include <stdint.h>
#endif
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)
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;
2014-03-23 17:56:07 +00:00
CTuningParams m_TuningList[256];
2010-05-29 07:25:38 +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 ConTuneZone(IConsole::IResult *pResult, void *pUserData);
static void ConTuneDumpZone(IConsole::IResult *pResult, void *pUserData);
static void ConTuneResetZone(IConsole::IResult *pResult, void *pUserData);
static void ConTuneSetZoneMsgEnter(IConsole::IResult *pResult, void *pUserData);
static void ConTuneSetZoneMsgLeave(IConsole::IResult *pResult, void *pUserData);
2012-01-09 23:49:31 +00:00
static void ConPause(IConsole::IResult *pResult, void *pUserData);
static void ConChangeMap(IConsole::IResult *pResult, void *pUserData);
2013-12-06 23:15:56 +00:00
static void ConRandomMap(IConsole::IResult *pResult, void *pUserData);
2014-06-20 20:40:23 +00:00
static void ConRandomUnfinishedMap(IConsole::IResult *pResult, void *pUserData);
2014-07-26 12:46:31 +00:00
static void ConSaveTeam(IConsole::IResult *pResult, void *pUserData);
static void ConLoadTeam(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 ConSwapTeams(IConsole::IResult *pResult, void *pUserData);
//static void ConShuffleTeams(IConsole::IResult *pResult, void *pUserData);
//static void ConLockTeams(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);
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; }
CTuningParams *TuningList() { return &m_TuningList[0]; }
2010-05-29 07:25:38 +00:00
CGameContext();
~CGameContext();
2010-05-29 07:25:38 +00:00
void Clear();
2010-05-29 07:25:38 +00:00
CEventHandler m_Events;
CPlayer *m_apPlayers[MAX_CLIENTS];
IGameController *m_pController;
CGameWorld m_World;
2010-05-29 07:25:38 +00:00
// helper functions
class CCharacter *GetPlayerChar(int ClientID);
//int m_LockTeams;
2010-05-29 07:25:38 +00:00
// voting
void StartVote(const char *pDesc, const char *pCommand, const char *pReason);
2010-05-29 07:25:38 +00:00
void EndVote();
void SendVoteSet(int ClientID);
void SendVoteStatus(int ClientID, int Total, int Yes, int No);
void AbortVoteKickOnDisconnect(int ClientID);
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];
int m_NumVoteOptions;
2010-05-29 07:25:38 +00:00
int m_VoteEnforce;
char m_ZoneEnterMsg[256][256]; // 0 is used for switching from or to area without tunings
char m_ZoneLeaveMsg[256][256];
2010-05-29 07:25:38 +00:00
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
2013-12-31 05:13:57 +00:00
void CreateDamageInd(vec2 Pos, float AngleMod, int Amount, int64_t Mask=-1);
void CreateExplosion(vec2 Pos, int Owner, int Weapon, bool NoDamage, int ActivatedTeam, int64_t Mask);
void CreateHammerHit(vec2 Pos, int64_t Mask=-1);
void CreatePlayerSpawn(vec2 Pos, int64_t Mask=-1);
void CreateDeath(vec2 Pos, int Who, int64_t Mask=-1);
void CreateSound(vec2 Pos, int Sound, int64_t Mask=-1);
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,
CHAT_WHISPER_SEND=2,
CHAT_WHISPER_RECV=3
2010-05-29 07:25:38 +00:00
};
// network
void CallVote(int ClientID, const char *aDesc, const char *aCmd, const char *pReason, const char *aChatmsg);
2010-05-29 07:25:38 +00:00
void SendChatTarget(int To, const char *pText);
2014-07-26 12:46:31 +00:00
void SendChatTeam(int Team, const char *pText);
void SendChat(int ClientID, int Team, const char *pText, int SpamProtectionClientID = -1);
void SendEmoticon(int ClientID, int Emoticon);
void SendWeaponPickup(int ClientID, int Weapon);
void SendBroadcast(const char *pText, int ClientID);
2013-12-31 05:13:57 +00:00
void List(int ClientID, const char* filter);
2010-05-29 07:25:38 +00:00
//
void CheckPureTuning();
2014-03-29 22:34:36 +00:00
void SendTuningParams(int ClientID, int Zone = 0);
//
//void SwapTeams();
2010-05-29 07:25:38 +00:00
// engine events
virtual void OnInit();
virtual void OnConsoleInit();
virtual void OnShutdown();
2010-05-29 07:25:38 +00:00
virtual void OnTick();
virtual void OnPreSnap();
virtual void OnSnap(int ClientID);
2010-05-29 07:25:38 +00:00
virtual void OnPostSnap();
virtual void OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID);
2010-05-29 07:25:38 +00:00
virtual void OnClientConnected(int ClientID);
virtual void OnClientEnter(int ClientID);
virtual void OnClientDrop(int ClientID, const char *pReason);
virtual void OnClientDirectInput(int ClientID, void *pInput);
virtual void OnClientPredictedInput(int ClientID, void *pInput);
virtual bool IsClientReady(int ClientID);
virtual bool IsClientPlayer(int ClientID);
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
// DDRace
int ProcessSpamProtection(int ClientID);
2011-04-19 19:44:02 +00:00
int GetDDRaceTeam(int ClientID);
2014-03-04 01:48:58 +00:00
int64 m_LastMapVote;
2011-01-29 00:59:50 +00:00
private:
bool m_VoteWillPass;
2011-01-29 00:59:50 +00:00
class IScore *m_pScore;
//DDRace Console Commands
//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);
2014-06-11 15:53:59 +00:00
static void ConUnSolo(IConsole::IResult *pResult, void *pUserData);
2014-06-13 21:49:34 +00:00
static void ConUnDeep(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);
2013-07-23 21:37:00 +00:00
static void ConToTeleporter(IConsole::IResult *pResult, void *pUserData);
2014-02-11 21:36:55 +00:00
static void ConToCheckTeleporter(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 ConToggleSpec(IConsole::IResult *pResult, void *pUserData);
static void ConForcePause(IConsole::IResult *pResult, void *pUserData);
2013-07-21 06:46:52 +00:00
static void ConTeamTop5(IConsole::IResult *pResult, void *pUserData);
static void ConTop5(IConsole::IResult *pResult, void *pUserData);
#if defined(CONF_SQL)
static void ConTimes(IConsole::IResult *pResult, void *pUserData);
static void ConPoints(IConsole::IResult *pResult, void *pUserData);
static void ConTopPoints(IConsole::IResult *pResult, void *pUserData);
#endif
2011-03-22 19:15:15 +00:00
static void ConUTF8(IConsole::IResult *pResult, void *pUserData);
2013-12-22 17:30:13 +00:00
static void ConDND(IConsole::IResult *pResult, void *pUserData);
2013-11-28 14:11:59 +00:00
static void ConMapPoints(IConsole::IResult *pResult, void *pUserData);
2014-08-09 15:25:29 +00:00
static void ConTimeout(IConsole::IResult *pResult, void *pUserData);
2014-07-26 12:46:31 +00:00
static void ConSave(IConsole::IResult *pResult, void *pUserData);
static void ConLoad(IConsole::IResult *pResult, void *pUserData);
static void ConMap(IConsole::IResult *pResult, void *pUserData);
2013-07-21 06:46:52 +00:00
static void ConTeamRank(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);
2013-11-15 23:44:49 +00:00
static void ConLockTeam(IConsole::IResult *pResult, void *pUserData);
static void ConMe(IConsole::IResult *pResult, void *pUserData);
2013-08-09 13:04:20 +00:00
static void ConWhisper(IConsole::IResult *pResult, void *pUserData);
2013-10-18 09:42:35 +00:00
static void ConConverse(IConsole::IResult *pResult, void *pUserData);
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
static void ConSetEyeEmote(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);
2014-02-02 18:56:10 +00:00
static void ConShowAll(IConsole::IResult *pResult, void *pUserData);
2014-08-09 17:53:38 +00:00
static void ConSpecTeam(IConsole::IResult *pResult, void *pUserData);
2014-01-11 12:59:20 +00:00
static void ConNinjaJetpack(IConsole::IResult *pResult, void *pUserData);
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
static void ConSayTime(IConsole::IResult *pResult, void *pUserData);
static void ConSayTimeAll(IConsole::IResult *pResult, void *pUserData);
static void ConTime(IConsole::IResult *pResult, void *pUserData);
static void ConSetTimerType(IConsole::IResult *pResult, void *pUserData);
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
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
2013-12-31 05:13:57 +00:00
static void ConList(IConsole::IResult *pResult, void *pUserData);
static void ConFreezeHammer(IConsole::IResult *pResult, void *pUserData);
static void ConUnFreezeHammer(IConsole::IResult *pResult, void *pUserData);
2013-12-31 05:13:57 +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;
void Mute(IConsole::IResult *pResult, NETADDR *Addr, int Secs, const char *pDisplayName);
2013-08-09 13:04:20 +00:00
void Whisper(int ClientID, char *pStr);
2013-10-18 09:42:35 +00:00
void WhisperID(int ClientID, int VictimID, char *pMessage);
void Converse(int ClientID, char *pStr);
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;
bool m_VoteSpec;
2011-01-29 00:59:50 +00:00
enum
{
VOTE_ENFORCE_NO_ADMIN = VOTE_ENFORCE_YES + 1,
VOTE_ENFORCE_YES_ADMIN
};
int m_VoteEnforcer;
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);
virtual void OnSetAuthed(int ClientID,int Level);
2011-01-29 00:59:50 +00:00
virtual bool PlayerCollision();
virtual bool PlayerHooking();
2013-11-13 12:25:26 +00:00
virtual float PlayerJetpack();
void ResetTuning();
2011-08-31 13:41:32 +00:00
int m_ChatResponseTargetID;
int m_ChatPrintCBIndex;
2010-05-29 07:25:38 +00:00
};
2013-12-31 05:13:57 +00:00
inline int64_t CmaskAll() { return -1LL; }
inline int64_t CmaskOne(int ClientID) { return 1LL<<ClientID; }
inline int64_t CmaskAllExceptOne(int ClientID) { return CmaskAll()^CmaskOne(ClientID); }
inline bool CmaskIsSet(int64_t Mask, int ClientID) { return (Mask&CmaskOne(ClientID)) != 0; }
2011-01-29 00:59:50 +00:00
#endif