| 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"cxx . . $ `<file>/netgames/includes/gamedll_header.h`/ |
| 102 | #include "DMFC.h"cxx . . $ `<file>/netgames/includes/DMFC.h`/ |
| 103 | #include "dmfcinternal.h"cxx . . $ `<file>/netgames/dmfc/dmfcinternal.h`/ |
| 104 | #include "d3events.h"cxx . . $ `<file>/lib/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 DMFCBasecxx . . $ DMFCBase#::OnServerPlayerKilledcxx . . $ DMFCBase#OnServerPlayerKilled(766a1b7183ffa4b4).(objectcxx . . $ object# *killer_obj, int victim_pnum) { |
| 114 | if (Datacxx . . $ DMFCBase#Data.->iParamcxx . . $ dllinfo#iParam. == 255) |
| 115 | Datacxx . . $ DMFCBase#Data.->iParamcxx . . $ dllinfo#iParam. = -1; |
| 116 | else { |
| 117 | Datacxx . . $ DMFCBase#Data.->iParamcxx . . $ dllinfo#iParam. = (int)DLLMultiGetMatchChecksum(OBJ_WEAPONcxx . . $ `Descent3/object_external.h:165:9`!, Datacxx . . $ DMFCBase#Data.->iParamcxx . . $ dllinfo#iParam.); |
| 118 | if (Datacxx . . $ DMFCBase#Data.->iParamcxx . . $ dllinfo#iParam. == -1) { |
| 119 | mprintfcxx . . $ `netgames/dmfc/dmfcinternal.h:275:9`!(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 | CallClientEventcxx . . $ DMFCBase#CallClientEvent(d7a7761809021567).(EVT_CLIENT_GAMEPLAYERKILLEDcxx . . $ `lib/d3events.h:93:9`!, GetMeObjNumcxx . . $ DMFCBase#GetMeObjNum(b126dc7c1de90089).(), GetItObjNumcxx . . $ DMFCBase#GetItObjNum(b126dc7c1de90089).(), -1, true); |
| 125 | CallOnClientPlayerKilledcxx . . $ DMFCBase#CallOnClientPlayerKilled(766a1b7183ffa4b4).(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 DMFCBasecxx . . $ DMFCBase#::OnServerPlayerExplodedcxx . . $ DMFCBase#OnServerPlayerExploded(d4f767463ce0a6b3).(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 DMFCBasecxx . . $ DMFCBase#::OnServerCollidecxx . . $ DMFCBase#OnServerCollide(6273fa812ac58a8).(objectcxx . . $ object# *me_obj, objectcxx . . $ object# *it_obj) {} |
| 142 | void DMFCBasecxx . . $ DMFCBase#::OnServerCollidecxx . . $ DMFCBase#OnServerCollide(584c77d2760d8df8).(objectcxx . . $ object# *me_obj, objectcxx . . $ object# *it_obj, vectorcxx . . $ vector# *point, vectorcxx . . $ 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 DMFCBasecxx . . $ DMFCBase#::OnServerPlayerChangeSegmentcxx . . $ DMFCBase#OnServerPlayerChangeSegment(b1146eedae1e1d0b).(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 DMFCBasecxx . . $ DMFCBase#::OnServerObjectChangeSegmentcxx . . $ DMFCBase#OnServerObjectChangeSegment(a7790401ac9fc765).(objectcxx . . $ 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 DMFCBasecxx . . $ DMFCBase#::OnServerPlayerEntersGamecxx . . $ DMFCBase#OnServerPlayerEntersGame(d4f767463ce0a6b3).(int player_num) { |
| 167 | if (player_num == -1) |
| 168 | return; |
| 169 | |
| 170 | VersionCheckcxx . . $ DMFCBase#VersionCheck(d4f767463ce0a6b3).(player_num); |
| 171 | |
| 172 | // see if they are banned, if so, give em the boot |
| 173 | if (IsPlayerBannedcxx . . $ DMFCBase#IsPlayerBanned(83c267b20bac841a).(player_num)) { |
| 174 | SendControlMessageToPlayercxx . . $ DMFCBase#SendControlMessageToPlayer(9633529ce3c4ff50).(player_num, CM_BANNEDcxx . . $ `netgames/dmfc/dmfcinternal.h:282:9`!); |
| 175 | DLLMultiDisconnectPlayer(player_num); |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | SendDMFCGameInfocxx . . $ DMFCBase#SendDMFCGameInfo(d4f767463ce0a6b3).(player_num); |
| 180 | |
| 181 | SendNetGameInfoSynccxx . . $ DMFCBase#SendNetGameInfoSync(d4f767463ce0a6b3).(player_num); |
| 182 | |
| 183 | // Since clients won't ever get the OnClientLevelStart, send it here so they get it before PlayerEntersGame |
| 184 | CallClientEventcxx . . $ DMFCBase#CallClientEvent(d7a7761809021567).(EVT_CLIENT_GAMELEVELSTARTcxx . . $ `lib/d3events.h:107:9`!, GetMeObjNumcxx . . $ DMFCBase#GetMeObjNum(b126dc7c1de90089).(), GetItObjNumcxx . . $ DMFCBase#GetItObjNum(b126dc7c1de90089).(), player_num); |
| 185 | |
| 186 | CallClientEventcxx . . $ DMFCBase#CallClientEvent(d7a7761809021567).(EVT_CLIENT_GAMEPLAYERENTERSGAMEcxx . . $ `lib/d3events.h:99:9`!, GetMeObjNumcxx . . $ DMFCBase#GetMeObjNum(b126dc7c1de90089).(), GetItObjNumcxx . . $ DMFCBase#GetItObjNum(b126dc7c1de90089).(), -1); |
| 187 | CallOnClientPlayerEntersGamecxx . . $ DMFCBase#CallOnClientPlayerEntersGame(d4f767463ce0a6b3).(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 DMFCBasecxx . . $ DMFCBase#::OnServerPlayerDisconnectcxx . . $ DMFCBase#OnServerPlayerDisconnect(d4f767463ce0a6b3).(int player_num) { |
| 195 | if (player_num == -1) |
| 196 | return; |
| 197 | |
| 198 | // send this event to the clients so they can handle it |
| 199 | CallClientEventcxx . . $ DMFCBase#CallClientEvent(d7a7761809021567).(EVT_CLIENT_GAMEPLAYERDISCONNECTcxx . . $ `lib/d3events.h:100:9`!, GetMeObjNumcxx . . $ DMFCBase#GetMeObjNum(b126dc7c1de90089).(), GetItObjNumcxx . . $ DMFCBase#GetItObjNum(b126dc7c1de90089).(), -1); |
| 200 | CallOnClientPlayerDisconnectcxx . . $ DMFCBase#CallOnClientPlayerDisconnect(d4f767463ce0a6b3).(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 DMFCBasecxx . . $ DMFCBase#::OnServerGameCreatedcxx . . $ DMFCBase#OnServerGameCreated(49f6e7a06ebc5aa8).(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 DMFCBasecxx . . $ DMFCBase#::OnServerLevelChangecxx . . $ DMFCBase#OnServerLevelChange(49f6e7a06ebc5aa8).(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 DMFCBasecxx . . $ DMFCBase#::OnServerLevelStartcxx . . $ DMFCBase#OnServerLevelStart(49f6e7a06ebc5aa8).(void) { |
| 220 | RealGametimecxx . . $ DMFCBase#RealGametime. = 0.0f; // zero out real gametime |
| 221 | |
| 222 | // Let the server get the OnLevelStart |
| 223 | CallOnClientLevelStartcxx . . $ DMFCBase#CallOnClientLevelStart(49f6e7a06ebc5aa8).(); |
| 224 | |
| 225 | // send a fake EVT_GAMEPLAYERENTERSGAME to the server so he gets that event |
| 226 | Datacxx . . $ DMFCBase#Data.->me_handlecxx . . $ dllinfo#me_handle. = Datacxx . . $ DMFCBase#Data.->it_handlecxx . . $ dllinfo#it_handle. = Objectscxx . . $ DMFCBase#Objects.[Playerscxx . . $ DMFCBase#Players.[GetPlayerNumcxx . . $ DMFCBase#GetPlayerNum(b126dc7c1de90089).()].objnumcxx . . $ player#objnum.].handlecxx . . $ object#handle.; |
| 227 | Datacxx . . $ DMFCBase#Data.->it_handlecxx . . $ dllinfo#it_handle. = Datacxx . . $ DMFCBase#Data.->me_handlecxx . . $ dllinfo#me_handle.; |
| 228 | CallOnServerPlayerEntersGamecxx . . $ DMFCBase#CallOnServerPlayerEntersGame(d4f767463ce0a6b3).(GetPlayerNumcxx . . $ DMFCBase#GetPlayerNum(b126dc7c1de90089).()); |
| 229 | |
| 230 | DisplayTauntIndicatorcxx . . $ DMFCBase#DisplayTauntIndicator. = false; |
| 231 | |
| 232 | // If we are a dedicated server, and there is a wait time make everyone wait |
| 233 | if (GetLocalRolecxx . . $ DMFCBase#GetLocalRole(b126dc7c1de90089).() == LR_SERVERcxx . . $ `Descent3/multi_external.h:129:9`! && IAmDedicatedServercxx . . $ DMFCBase#IAmDedicatedServer(c9857a73d68e59ba).()) { |
| 234 | if (DedicatedLevelWaitcxx . . $ DMFCBase#DedicatedLevelWait. > 0) { |
| 235 | // time to stop waiting! |
| 236 | mprintfcxx . . $ `netgames/dmfc/dmfcinternal.h:275:9`!(0, "Telling clients to wait\n"); |
| 237 | DPrintf("\nMaking Clients Wait %.2f seconds\n", DedicatedLevelWaitcxx . . $ DMFCBase#DedicatedLevelWait.); |
| 238 | PauseRealGameTimecxx . . $ DMFCBase#PauseRealGameTime(b45ddcbc8423892c).(true); |
| 239 | MakeClientsWaitcxx . . $ DMFCBase#MakeClientsWait(b45ddcbc8423892c).(true); |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | // DMFCBase::OnServerLevelEnd |
| 245 | // |
| 246 | // Event handler for when a multiplayer level is ending. |
| 247 | void DMFCBasecxx . . $ DMFCBase#::OnServerLevelEndcxx . . $ DMFCBase#OnServerLevelEnd(49f6e7a06ebc5aa8).(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 DMFCBasecxx . . $ DMFCBase#::OnServerObjectShieldsChangedcxx . . $ DMFCBase#OnServerObjectShieldsChanged(4ebbd0c3cbf1b78a).(objectcxx . . $ 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 DMFCBasecxx . . $ DMFCBase#::OnServerIsAddressBannedcxx . . $ DMFCBase#OnServerIsAddressBanned(46e1c72e52d9c94a).(network_addresscxx . . $ network_address# *addr, const char *tracker_id) { |
| 264 | return IsAddressBannedcxx . . $ DMFCBase#IsAddressBanned(46e1c72e52d9c94a).(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 DMFCBasecxx . . $ DMFCBase#::OnServerWallCollidecxx . . $ DMFCBase#OnServerWallCollide(cd5bbf25e955f730).(objectcxx . . $ object# *obj, float hitspeed, int hitseg, int hitwall, vectorcxx . . $ vector# *hitpt, |
| 271 | vectorcxx . . $ 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 DMFCBasecxx . . $ DMFCBase#::OnServerObjectKilledcxx . . $ DMFCBase#OnServerObjectKilled(6273fa812ac58a8).(objectcxx . . $ object# *obj, objectcxx . . $ 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 DMFCBasecxx . . $ DMFCBase#::OnServerObjectDestroyedcxx . . $ DMFCBase#OnServerObjectDestroyed(419c470199a90a97).(objectcxx . . $ object# *obj) {} |