added a limit for the number of votes that can be added to the server and send option...
[twcon.git] / src / game / server / gamecontext.h
blob38100a067fd967e854817106e52327bf64ed5db9
1 /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2 /* If you are missing that file, acquire a complete release at teeworlds.com. */
3 #ifndef GAME_SERVER_GAMECONTEXT_H
4 #define GAME_SERVER_GAMECONTEXT_H
6 #include <engine/server.h>
7 #include <engine/console.h>
8 #include <engine/shared/memheap.h>
10 #include <game/layers.h>
11 #include <game/voting.h>
13 #include "eventhandler.h"
14 #include "gamecontroller.h"
15 #include "gameworld.h"
16 #include "player.h"
19 Tick
20 Game Context (CGameContext::tick)
21 Game World (GAMEWORLD::tick)
22 Reset world if requested (GAMEWORLD::reset)
23 All entities in the world (ENTITY::tick)
24 All entities in the world (ENTITY::tick_defered)
25 Remove entities marked for deletion (GAMEWORLD::remove_entities)
26 Game Controller (GAMECONTROLLER::tick)
27 All players (CPlayer::tick)
30 Snap
31 Game Context (CGameContext::snap)
32 Game World (GAMEWORLD::snap)
33 All entities in the world (ENTITY::snap)
34 Game Controller (GAMECONTROLLER::snap)
35 Events handler (EVENT_HANDLER::snap)
36 All players (CPlayer::snap)
39 class CGameContext : public IGameServer
41 IServer *m_pServer;
42 class IConsole *m_pConsole;
43 CLayers m_Layers;
44 CCollision m_Collision;
45 CNetObjHandler m_NetObjHandler;
46 CTuningParams m_Tuning;
48 static void ConTuneParam(IConsole::IResult *pResult, void *pUserData);
49 static void ConTuneReset(IConsole::IResult *pResult, void *pUserData);
50 static void ConTuneDump(IConsole::IResult *pResult, void *pUserData);
51 static void ConChangeMap(IConsole::IResult *pResult, void *pUserData);
52 static void ConRestart(IConsole::IResult *pResult, void *pUserData);
53 static void ConBroadcast(IConsole::IResult *pResult, void *pUserData);
54 static void ConSay(IConsole::IResult *pResult, void *pUserData);
55 static void ConSetTeam(IConsole::IResult *pResult, void *pUserData);
56 static void ConSetTeamAll(IConsole::IResult *pResult, void *pUserData);
57 static void ConAddVote(IConsole::IResult *pResult, void *pUserData);
58 static void ConRemoveVote(IConsole::IResult *pResult, void *pUserData);
59 static void ConForceVote(IConsole::IResult *pResult, void *pUserData);
60 static void ConClearVotes(IConsole::IResult *pResult, void *pUserData);
61 static void ConVote(IConsole::IResult *pResult, void *pUserData);
62 static void ConchainSpecialMotdupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
64 CGameContext(int Resetting);
65 void Construct(int Resetting);
67 bool m_Resetting;
68 public:
69 IServer *Server() const { return m_pServer; }
70 class IConsole *Console() { return m_pConsole; }
71 CCollision *Collision() { return &m_Collision; }
72 CTuningParams *Tuning() { return &m_Tuning; }
74 CGameContext();
75 ~CGameContext();
77 void Clear();
79 CEventHandler m_Events;
80 CPlayer *m_apPlayers[MAX_CLIENTS];
82 IGameController *m_pController;
83 CGameWorld m_World;
85 // helper functions
86 class CCharacter *GetPlayerChar(int ClientID);
88 // voting
89 void StartVote(const char *pDesc, const char *pCommand, const char *pReason);
90 void EndVote();
91 void SendVoteSet(int ClientID);
92 void SendVoteStatus(int ClientID, int Total, int Yes, int No);
93 void AbortVoteKickOnDisconnect(int ClientID);
95 int m_VoteCreator;
96 int64 m_VoteCloseTime;
97 bool m_VoteUpdate;
98 int m_VotePos;
99 char m_aVoteDescription[VOTE_DESC_LENGTH];
100 char m_aVoteCommand[VOTE_CMD_LENGTH];
101 char m_aVoteReason[VOTE_REASON_LENGTH];
102 int m_NumVoteOptions;
103 int m_VoteEnforce;
104 enum
106 VOTE_ENFORCE_UNKNOWN=0,
107 VOTE_ENFORCE_NO,
108 VOTE_ENFORCE_YES,
110 CHeap *m_pVoteOptionHeap;
111 CVoteOptionServer *m_pVoteOptionFirst;
112 CVoteOptionServer *m_pVoteOptionLast;
114 // helper functions
115 void CreateDamageInd(vec2 Pos, float AngleMod, int Amount);
116 void CreateExplosion(vec2 Pos, int Owner, int Weapon, bool NoDamage);
117 void CreateSmoke(vec2 Pos);
118 void CreateHammerHit(vec2 Pos);
119 void CreatePlayerSpawn(vec2 Pos);
120 void CreateDeath(vec2 Pos, int Who);
121 void CreateSound(vec2 Pos, int Sound, int Mask=-1);
122 void CreateSoundGlobal(int Sound, int Target=-1);
125 enum
127 CHAT_ALL=-2,
128 CHAT_SPEC=-1,
129 CHAT_RED=0,
130 CHAT_BLUE=1
133 // network
134 void SendChatTarget(int To, const char *pText);
135 void SendChat(int ClientID, int Team, const char *pText);
136 void SendEmoticon(int ClientID, int Emoticon);
137 void SendWeaponPickup(int ClientID, int Weapon);
138 void SendBroadcast(const char *pText, int ClientID);
142 void CheckPureTuning();
143 void SendTuningParams(int ClientID);
145 // engine events
146 virtual void OnInit();
147 virtual void OnConsoleInit();
148 virtual void OnShutdown();
150 virtual void OnTick();
151 virtual void OnPreSnap();
152 virtual void OnSnap(int ClientID);
153 virtual void OnPostSnap();
155 virtual void OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID);
157 virtual void OnClientConnected(int ClientID);
158 virtual void OnClientEnter(int ClientID);
159 virtual void OnClientDrop(int ClientID);
160 virtual void OnClientDirectInput(int ClientID, void *pInput);
161 virtual void OnClientPredictedInput(int ClientID, void *pInput);
163 virtual bool IsClientReady(int ClientID);
164 virtual bool IsClientPlayer(int ClientID);
166 virtual const char *GameType();
167 virtual const char *Version();
168 virtual const char *NetVersion();
171 inline int CmaskAll() { return -1; }
172 inline int CmaskOne(int ClientID) { return 1<<ClientID; }
173 inline int CmaskAllExceptOne(int ClientID) { return 0x7fffffff^CmaskOne(ClientID); }
174 inline bool CmaskIsSet(int Mask, int ClientID) { return (Mask&CmaskOne(ClientID)) != 0; }
175 #endif