1 /* bzflag
2  * Copyright (c) 1993-2021 Tim Riker
3  *
4  * This package is free software;  you can redistribute it and/or
5  * modify it under the terms of the license found in the file
6  * named COPYING that should have accompanied this file.
7  *
8  * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */
12 
13 #ifndef __BZFS_H__
14 #define __BZFS_H__
15 
16 // to dump score info to stdout
17 #define PRINTSCORE to include code to dump score info to stdout
18 
19 #define SERVERLOGINMSG true
20 
21 #include "common.h"
22 
23 // must be before network.h because that defines a close() macro which
24 // messes up fstreams.  luckily, we don't need to call the close() method
25 // on any fstream.
26 #include <fstream>
27 
28 // must be before windows.h
29 #include "network.h"
30 
31 // common interface headers
32 #include "Address.h"
33 #include "Flag.h"
34 #include "Ping.h"
35 
36 // bzfs specific headers
37 #include "TeamBases.h"
38 #include "CmdLineOptions.h"
39 #include "GameKeeper.h"
40 #include "FlagInfo.h"
41 #include "WorldInfo.h"
42 #include "VotingArbiter.h"
43 #include "ShotManager.h"
44 
45 #include <list>
46 class PendingChatMessages
47 {
48 public:
49     int to;
50     int from;
51     std::string text;
52     MessageType type;
53 
PendingChatMessages(int t,int f,const std::string & m,MessageType y)54     PendingChatMessages ( int t, int f, const std::string &m, MessageType y )
55     {
56         to = t;
57         from = f;
58         text = m;
59         type = y;
60     }
61 
PendingChatMessages(int t,int f,const char * m,MessageType y)62     PendingChatMessages ( int t, int f, const char* m, MessageType y )
63     {
64         to = t;
65         from = f;
66         if (m)
67             text = m;
68         type = y;
69     }
70 
PendingChatMessages(const PendingChatMessages & m)71     PendingChatMessages ( const PendingChatMessages &m )
72     {
73         to = m.to;
74         from = m.from;
75         text = m.text;
76         type = m.type;
77     }
78 };
79 
80 extern std::list<PendingChatMessages> pendingChatMessages;
81 
82 extern void sendMessage(int     playerIndex,
83                         PlayerId    dstPlayer,
84                         const char  *message,
85                         MessageType type = ChatMessage);
86 extern void removePlayer(int        playerIndex,
87                          const char *reason,
88                          bool       notify = true);
89 extern void playerKilled(int        victimIndex,
90                          int        killerIndex,
91                          int        reason,
92                          int16_t    shotIndex,
93                          const FlagType *flagType,
94                          int        phydrv,
95                          bool       respawnOnBase = false);
96 extern void doSpawns();
97 extern void grabFlag(int playerIndex, FlagInfo &flag, bool checkPos = true);
98 extern void sendPlayerMessage(GameKeeper::Player *playerData,
99                               PlayerId dstPlayer,
100                               const char *message);
101 extern char *getDirectMessageBuffer();
102 extern void  broadcastMessage(uint16_t code, int len, void *msg);
103 extern void  sendTeamUpdate(int playerIndex = -1,
104                             int teamIndex1 = -1,
105                             int teamIndex2 = -1);
106 extern void  sendFlagUpdate(FlagInfo &flag);
107 extern void  sendDrop(FlagInfo &flag);
108 extern void  sendIPUpdate(int targetPlayer = -1, int playerIndex = -1);
109 extern void  sendPlayerInfo(void);
110 extern void  directMessage(int playerIndex, uint16_t code,
111                            int len, void *msg);
112 extern int   getCurMaxPlayers();
113 extern bool  areFoes(TeamColor team1, TeamColor team2);
114 extern PingPacket getTeamCounts();
115 extern void  zapFlagByPlayer(int playerIndex);
116 extern void  resetFlag(FlagInfo &flag);
117 extern void  dropFlag(FlagInfo& flag, const float dropPos[3]);
118 extern void  publicize();
119 extern TeamColor whoseBase(float x, float y, float z);
120 bool defineWorld(void);
121 bool saveWorldCache(const char* file = NULL);
122 float getMaxWorldHeight(void);
123 
124 bool allowTeams ( void );
125 extern const std::string& getPublicOwner();
126 extern void setPublicOwner(const std::string& owner);
127 
128 void loadBadwordsList();
129 void rescanForBans(bool isOperator = false, const char* callsign = NULL, int playerID = -1);
130 
131 // initialize permission groups
132 extern void initGroups();
133 
134 extern BasesList    bases;
135 extern CmdLineOptions   *clOptions;
136 extern uint16_t     curMaxPlayers;
137 extern bool     done;
138 extern bool     gameOver;
139 extern TeamInfo     team[NumTeams];
140 extern int      numFlags;
141 extern TimeKeeper   gameStartTime;
142 extern bool     countdownActive;
143 extern int      countdownDelay;
144 extern TimeKeeper   countdownPauseStart;
145 extern int      countdownResumeDelay;
146 extern std::string  hexDigest;
147 extern WorldInfo    *world;
148 extern char     *worldDatabase;
149 extern uint32_t     worldDatabaseSize;
150 extern char     worldSettings[4 + WorldSettingsSize];
151 extern uint8_t      rabbitIndex;
152 extern float        speedTolerance;
153 extern bool     handlePings;
154 extern uint16_t     maxPlayers;
155 extern uint16_t     maxRealPlayers;
156 extern float        pluginWorldSize;
157 extern float        pluginWorldHeight;
158 extern bool     checkShotMismatch;
159 extern bool     publiclyDisconnected;
160 
161 extern Shots::Manager   ShotManager;
162 
163 extern VotingArbiter    *votingarbiter;
164 
165 bool captureFlag(int playerIndex, TeamColor teamCaptured, TeamColor teamCapped = NoTeam, bool checkCheat = true);
166 
167 void resetTeamScores(void);
168 void pauseCountdown(int pausedBy = ServerPlayer);
169 void resumeCountdown(int resumedBy = ServerPlayer);
170 void startCountdown(int delay, float limit, int playerID = ServerPlayer);
171 void cancelCountdown( int playerID = ServerPlayer);
172 
173 void dropPlayerFlag(GameKeeper::Player &playerData, const float dropPos[3]);
174 void playerAlive(int playerIndex);
175 void sendChatMessage(PlayerId srcPlayer, PlayerId dstPlayer, const char *message, MessageType type);
176 
177 void makeWalls (void);
178 
179 PlayerId getNewPlayerID();
180 void checkGameOn();
181 void cleanupGameOver();
182 void checkTeamScore(int playerIndex, int teamIndex);
183 void sendClosestFlagMessage(int playerIndex,FlagType *type, float pos[3]);
184 
185 void ApiTick(void);
186 
187 // peer list
188 struct NetConnectedPeer
189 {
190     int socket;
191     int player;
192 
193     NetHandler* netHandler;
194     bz_NonPlayerConnectionHandler* apiHandler;
195 
196     std::list<std::string> sendChunks;
197     std::string bufferedInput;
198 
199     TimeKeeper startTime;
200     TimeKeeper lastActivity;
201 
202     TimeKeeper lastSend;
203     double minSendTime;
204 
205     double inactivityTimeout;
206     bool   sent;
207     bool   deleteMe;
208     bool   deleteWhenDoneSending;
209 };
210 
211 extern std::map<int, NetConnectedPeer> netConnectedPeers;
212 
213 extern unsigned int maxNonPlayerDataChunk;
214 extern void sendBufferedNetDataForPeer(NetConnectedPeer &peer);
215 
216 // utils
217 void playerStateToAPIState(bz_PlayerUpdateState &apiState, const PlayerState &playerState);
218 void APIStateToplayerState(PlayerState &playerState, const bz_PlayerUpdateState &apiState);
219 
220 void AddPlayer(int playerIndex, GameKeeper::Player *playerData);
221 
222 void recalcAllHandicaps();
223 void broadcastHandicaps(int toPlayer = -1);
224 
225 #endif
226 
227 // Local Variables: ***
228 // mode: C++ ***
229 // tab-width: 4 ***
230 // c-basic-offset: 4 ***
231 // indent-tabs-mode: nil ***
232 // End: ***
233 // ex: shiftwidth=4 tabstop=4
234