Debian Codegraph @

netgames/dmfc/dmfcserver.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/Dmfc/dmfcserver.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003/08/26 03:57:21 $
23 * $Author: kevinb $
24 *
25 * DMFC Server event handlers
26 *
27 * $Log: dmfcserver.cpp,v $
28 * Revision 1.1.1.1 2003/08/26 03:57:21 kevinb
29 * initial 1.5 import
30 *
31 *
32 * 29 7/09/99 6:18p Jeff
33 * added $remoteadminlogout and $wait commands
34 *
35 * 28 7/09/99 2:54p Jeff
36 * handle gametime better (pause it when needed) if the server is 'waiting
37 * for players'
38 *
39 * 27 7/08/99 6:25p Jeff
40 * remote admin in and working
41 *
42 * 26 5/08/99 4:31a Jeff
43 * fixed sequencing bug where clients never got a level end event for the
44 * multiplayer games
45 *
46 * 25 5/04/99 8:46p Jeff
47 * display icon when someone plays an audio taunt
48 *
49 * 24 3/22/99 5:51p Matt
50 * Removed some includes from one file and added some to other files, to
51 * reduce the amount of rebuilding when headers change.
52 *
53 * 23 3/17/99 12:25p Jeff
54 * converted DMFC to be COM interface
55 *
56 * 22 2/11/99 12:51a Jeff
57 * changed names of exported variables
58 *
59 * 21 2/07/99 1:20a Jeff
60 * added new multiplayer game events EVT_GAMEOBJKILLED and
61 * EVT_GAMEOBJDESTROYED
62 *
63 * 20 1/17/99 11:52p Jeff
64 * added some new events, and changed a couple event handlers
65 *
66 * 19 1/15/99 3:54a Jeff
67 * exported a couple more functions. Added event handlers for Weapon
68 * collide event
69 *
70 * 18 11/16/98 5:35p Jeff
71 * removed log functions, added support for changing team names, fixed ctf
72 * to work better with different team names
73 *
74 * 17 10/23/98 11:22a Jeff
75 * changes to handle mixcase, and display the client netgame info
76 * correctly
77 *
78 * 16 10/18/98 7:59p Jeff
79 * functions added to dmfc for client->server objnum matching. Banning
80 * now uses tracker id when available.
81 *
82 * 15 10/15/98 6:18p Jeff
83 * created the is player banned event, removed prejoin event
84 *
85 * 14 10/15/98 1:34p Jeff
86 * added scrollable onscreen menu. Remove ban in dmfc. prejoin event
87 *
88 * 13 10/01/98 11:30a Jeff
89 * made the observer mode events into just a client event
90 *
91 * 12 9/30/98 3:50p Jeff
92 * general improvements (many)
93 *
94 * 11 9/21/98 7:11p Jeff
95 * made InputCommand interface API and moved existing input commands to
96 * the interface. Changed mprintf/ASSERT so they are valid in DMFC
97 *
98 * $NoKeywords: $
99 */
100
101 #include "gamedll_header.h"
102 #include "DMFC.h"
103 #include "dmfcinternal.h"
104 #include "d3events.h"
105
106 // ###################Server Only functions################################
107
108 // DMFCBase::OnServerPlayerKilled
109 //
110 // Event handler for when a player gets killed, either by another player or some other way
111 // killer_obj = object pointer to the object that killed the player
112 // victim_pnum = player number of the player that got killed
113 void DMFCBase::OnServerPlayerKilled(object *killer_obj, int victim_pnum) {
114 if (Data->iParam == 255)
115 Data->iParam = -1;
116 else {
117 Data->iParam = (int)DLLMultiGetMatchChecksum(OBJ_WEAPON, Data->iParam);
118 if (Data->iParam == -1) {
119 mprintf(0, "Unable to generate checksum for weapon id\n");
120 }
121 }
122
123 // send this event to the clients so they can handle it
124 CallClientEvent(EVT_CLIENT_GAMEPLAYERKILLED, GetMeObjNum(), GetItObjNum(), -1, true);
125 CallOnClientPlayerKilled(killer_obj, victim_pnum);
126 }
127
128 // DMFCBase::OnServerPlayerExploded
129 //
130 // Event handler for when a player explodes. Gets called after a EVT_GAMEPLAYERKILLED event.
131 // player_num = player number of the player exploding
132 void DMFCBase::OnServerPlayerExploded(int player_num) {}
133
134 // DMFCBase::OnServerCollide
135 //
136 // Event handler for when two objects collide. At least one of the two objects is a player or a robot.
137 // Be aware that this event will be called twice per collision, the second time it is called the me and
138 // it objects will be flipped.
139 // me_obj = object pointer to the me object
140 // it_obj = object pointer to the it object
141 void DMFCBase::OnServerCollide(object *me_obj, object *it_obj) {}
142 void DMFCBase::OnServerCollide(object *me_obj, object *it_obj, vector *point, vector *normal) {}
143
144 // DMFCBase::OnServerPlayerChangeSegment
145 //
146 // Event handler for when a player changes rooms or a "large" terrain cell
147 // (8x8 Terrain block).
148 // player_num = player number of the player who just changed the room/segment
149 // newseg = New room/cell location
150 void DMFCBase::OnServerPlayerChangeSegment(int player_num, int newseg, int oldseg) {}
151
152 // DMFCBase::OnServerObjectChangeSegment (Only called if server tells client to execute)
153 //
154 // Event handler for when a player changes rooms or a "large" terrain cell
155 // (8x8 Terrain block).
156 // obj = Object pointer of the object who just changed the room/segment
157 // newseg = New room/cell location
158 // oldseg = Old room/cell location
159 void DMFCBase::OnServerObjectChangeSegment(object *obj, int newseg, int oldseg) {}
160
161 // DMFCBase::OnServerPlayerEntersGame
162 //
163 // Event handler for when a player enters the game. This will only get called once per
164 // player, it usually gets called right after they connect to the server to start playing.
165 // player_num = player number of the player entering the game
166 void DMFCBase::OnServerPlayerEntersGame(int player_num) {
167 if (player_num == -1)
168 return;
169
170 VersionCheck(player_num);
171
172 // see if they are banned, if so, give em the boot
173 if (IsPlayerBanned(player_num)) {
174 SendControlMessageToPlayer(player_num, CM_BANNED);
175 DLLMultiDisconnectPlayer(player_num);
176 return;
177 }
178
179 SendDMFCGameInfo(player_num);
180
181 SendNetGameInfoSync(player_num);
182
183 // Since clients won't ever get the OnClientLevelStart, send it here so they get it before PlayerEntersGame
184 CallClientEvent(EVT_CLIENT_GAMELEVELSTART, GetMeObjNum(), GetItObjNum(), player_num);
185
186 CallClientEvent(EVT_CLIENT_GAMEPLAYERENTERSGAME, GetMeObjNum(), GetItObjNum(), -1);
187 CallOnClientPlayerEntersGame(player_num);
188 }
189
190 // DMFCBase::OnServerPlayerDisconnect
191 //
192 // Event handler for when a player disconnects from the server.
193 // player_num = player number of the player that just disconnected
194 void DMFCBase::OnServerPlayerDisconnect(int player_num) {
195 if (player_num == -1)
196 return;
197
198 // send this event to the clients so they can handle it
199 CallClientEvent(EVT_CLIENT_GAMEPLAYERDISCONNECT, GetMeObjNum(), GetItObjNum(), -1);
200 CallOnClientPlayerDisconnect(player_num);
201 }
202
203 // DMFCBase::OnServerGameCreated
204 //
205 // Event handler when the server's game first gets started. This will only be called once
206 // while the server is running, and that is when the server first starts up.
207 void DMFCBase::OnServerGameCreated(void) {}
208
209 // DMFCBase::OnServerLevelChange
210 //
211 // Event handler when the server changes levels. This will get called after a level ends and a server
212 // is starting a new level.
213 void DMFCBase::OnServerLevelChange(void) {}
214
215 // DMFCBase::OnServerLevelStart
216 //
217 // Event handler for when a multiplayer level is starting up. This will get called right before the level
218 // starts.
219 void DMFCBase::OnServerLevelStart(void) {
220 RealGametime = 0.0f; // zero out real gametime
221
222 // Let the server get the OnLevelStart
223 CallOnClientLevelStart();
224
225 // send a fake EVT_GAMEPLAYERENTERSGAME to the server so he gets that event
226 Data->me_handle = Data->it_handle = Objects[Players[GetPlayerNum()].objnum].handle;
227 Data->it_handle = Data->me_handle;
228 CallOnServerPlayerEntersGame(GetPlayerNum());
229
230 DisplayTauntIndicator = false;
231
232 // If we are a dedicated server, and there is a wait time make everyone wait
233 if (GetLocalRole() == LR_SERVER && IAmDedicatedServer()) {
234 if (DedicatedLevelWait > 0) {
235 // time to stop waiting!
236 mprintf(0, "Telling clients to wait\n");
237 DPrintf("\nMaking Clients Wait %.2f seconds\n", DedicatedLevelWait);
238 PauseRealGameTime(true);
239 MakeClientsWait(true);
240 }
241 }
242 }
243
244 // DMFCBase::OnServerLevelEnd
245 //
246 // Event handler for when a multiplayer level is ending.
247 void DMFCBase::OnServerLevelEnd(void) {
248 // send this event to the clients so they can handle it
249 // JEFF - since Jason mucked with sequencing, all clients at this point are
250 // at some weird sequence, so we can't send packets to them
251 // CallClientEvent(EVT_CLIENT_GAMELEVELEND,GetMeObjNum(),GetItObjNum(),-1);
252 // CallOnClientLevelEnd();
253 }
254
255 // DMFCBase::OnServerObjectShieldsChanged
256 //
257 // Event handler for when an objects shield's change
258 void DMFCBase::OnServerObjectShieldsChanged(object *obj, float amount) {}
259
260 // DMFCBase::OnServerIsAddressBanned
261 //
262 // Called by the game to determine if the given network address is banned from the game
263 bool DMFCBase::OnServerIsAddressBanned(network_address *addr, const char *tracker_id) {
264 return IsAddressBanned(addr, tracker_id);
265 }
266
267 // DMFCBase::OnServerWallCollide
268 //
269 // Called by the game when their is a collision between an object and a wall
270 void DMFCBase::OnServerWallCollide(object *obj, float hitspeed, int hitseg, int hitwall, vector *hitpt,
271 vector *wall_normal, float hit_dot) {}
272
273 // DMFCBase::OnServerObjectKilled
274 //
275 // Called when an object is being killed
276 // Not automatically sent to clients (OnClientObjectKilled)
277 // killer might not be valid (NULL)
278 void DMFCBase::OnServerObjectKilled(object *obj, object *killer) {}
279
280 // DMFCBase::OnServerObjectDestroyed
281 //
282 // Called when an object is about to be deleted
283 // Not automatically sent to clients
284 void DMFCBase::OnServerObjectDestroyed(object *obj) {}