| 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/dmfcpackets.cpp $ |
| 21 |
* $Revision: 1.1.1.1 $ |
| 22 |
* $Date: 2003/08/26 03:57:21 $ |
| 23 |
* $Author: kevinb $ |
| 24 |
* |
| 25 |
* DMFC Special packet handling functions |
| 26 |
* |
| 27 |
* $Log: dmfcpackets.cpp,v $ |
| 28 |
* Revision 1.1.1.1 2003/08/26 03:57:21 kevinb |
| 29 |
* initial 1.5 import |
| 30 |
* |
| 31 |
* |
| 32 |
* 29 8/21/99 12:32a Jeff |
| 33 |
* Changed the name of the GetRealGametime function to |
| 34 |
* GetRealGametimePacket since it was confusing some compilers with the |
| 35 |
* other GetRealGametime function. |
| 36 |
* |
| 37 |
* 28 7/09/99 2:54p Jeff |
| 38 |
* handle gametime better (pause it when needed) if the server is 'waiting |
| 39 |
* for players' |
| 40 |
* |
| 41 |
* 27 7/08/99 6:25p Jeff |
| 42 |
* remote admin in and working |
| 43 |
* |
| 44 |
* 26 7/08/99 2:39a Jeff |
| 45 |
* rough implementation of remote administration checked in. Still needs |
| 46 |
* some polishing, but should work basically. |
| 47 |
* |
| 48 |
* 25 5/13/99 4:55p Ardussi |
| 49 |
* changes for compiling on the Mac |
| 50 |
* |
| 51 |
* 24 5/12/99 11:05p Jeff |
| 52 |
* dmfc and multiplayer games now have endian friendly packets (*whew*) |
| 53 |
* |
| 54 |
* 23 4/07/99 9:24p Jeff |
| 55 |
* fixed bug in sending team names over |
| 56 |
* |
| 57 |
* 22 3/17/99 12:24p Jeff |
| 58 |
* converted DMFC to be COM interface |
| 59 |
* |
| 60 |
* 21 2/11/99 12:51a Jeff |
| 61 |
* changed names of exported variables |
| 62 |
* |
| 63 |
* 20 12/08/98 4:47p Jeff |
| 64 |
* umm, various changes, fixed pilot pics so that they work for everyone |
| 65 |
* now |
| 66 |
* |
| 67 |
* 19 12/08/98 12:17p Jeff |
| 68 |
* various changes that include an improved Team Control dialog (doesn't |
| 69 |
* switch teams until exit..) and spew/respawn players that change teams |
| 70 |
* |
| 71 |
* 18 11/17/98 12:36p Jeff |
| 72 |
* fixed bug in sending new team name to clients |
| 73 |
* |
| 74 |
* 17 11/16/98 5:35p Jeff |
| 75 |
* removed log functions, added support for changing team names, fixed ctf |
| 76 |
* to work better with different team names |
| 77 |
* |
| 78 |
* 16 11/11/98 7:19p Jeff |
| 79 |
* changes made so that a dedicated server's team is always -1 (team game |
| 80 |
* or not) |
| 81 |
* |
| 82 |
* 15 10/29/98 7:01p Jeff |
| 83 |
* creation of team placement dialog. Moved TranslateEvent into DMFC |
| 84 |
* |
| 85 |
* 14 10/23/98 11:22a Jeff |
| 86 |
* changes to handle mixcase, and display the client netgame info |
| 87 |
* correctly |
| 88 |
* |
| 89 |
* 13 10/20/98 12:16p Jeff |
| 90 |
* added death message filter, hud callsign filter |
| 91 |
* |
| 92 |
* 12 10/08/98 3:37p Jeff |
| 93 |
* general improvements (Netgame info things, save to registry). Changes |
| 94 |
* so it would send packets on NETSEQ_OBJECTS |
| 95 |
* |
| 96 |
* 11 9/30/98 4:21p Jeff |
| 97 |
* team changing is handled correctly |
| 98 |
* |
| 99 |
* 10 9/25/98 8:02p Jason |
| 100 |
* added checks for jeff |
| 101 |
* |
| 102 |
* 9 9/21/98 7:11p Jeff |
| 103 |
* made InputCommand interface API and moved existing input commands to |
| 104 |
* the interface. Changed mprintf/ASSERT so they are valid in DMFC |
| 105 |
* |
| 106 |
* $NoKeywords: $ |
| 107 |
*/ |
| 108 |
|
| 109 |
#include "gamedll_header.h" |
| 110 |
#include "DMFC.h" |
| 111 |
#include "dmfcinternal.h" |
| 112 |
|
| 113 |
|
| 114 |
// DMFCBase::RegisterPacketReceiver |
| 115 |
// |
| 116 |
// Sets up a handler for a Special Packet ID. When a special packet is recieved it's ID is compared |
| 117 |
// to the ID's given to this function. If any match than it calls the handler given to process |
| 118 |
// the packet. |
| 119 |
// id = ID of the packet |
| 120 |
// func = Function handler to handle the packet. Must be declared like void MyFunction(uint8_t *data); |
| 121 |
void DMFCBase::RegisterPacketReceiver(uint8_t id, void (*func)(uint8_t *)) { |
| 122 |
// go to the last handler |
| 123 |
tSPHandler *current, *last; |
| 124 |
|
| 125 |
if (!SPRoot) { |
| 126 |
// handle special case for first node being added |
| 127 |
SPRoot = (tSPHandler *)malloc(sizeof(tSPHandler)); |
| 128 |
if (!SPRoot) |
| 129 |
return; |
| 130 |
current = SPRoot; |
| 131 |
} else { |
| 132 |
last = current = SPRoot; |
| 133 |
while (current) { |
| 134 |
last = current; |
| 135 |
current = current->next; |
| 136 |
} |
| 137 |
|
| 138 |
// allocate memory for the node |
| 139 |
current = (tSPHandler *)malloc(sizeof(tSPHandler)); |
| 140 |
if (!current) |
| 141 |
return; |
| 142 |
// add it to the list |
| 143 |
last->next = current; |
| 144 |
} |
| 145 |
|
| 146 |
// fill in the struct |
| 147 |
current->next = NULL; |
| 148 |
current->ID = id; |
| 149 |
current->type = SPH_FUNC; |
| 150 |
current->func = func; |
| 151 |
} |
| 152 |
void DMFCBase::RegisterPacketReceiver(uint8_t id, void (DMFCBase::*func)(uint8_t *)) { |
| 153 |
// go to the last handler |
| 154 |
tSPHandler *current, *last; |
| 155 |
|
| 156 |
if (!SPRoot) { |
| 157 |
// handle special case for first node being added |
| 158 |
SPRoot = (tSPHandler *)malloc(sizeof(tSPHandler)); |
| 159 |
if (!SPRoot) |
| 160 |
return; |
| 161 |
current = SPRoot; |
| 162 |
} else { |
| 163 |
last = current = SPRoot; |
| 164 |
while (current) { |
| 165 |
last = current; |
| 166 |
current = current->next; |
| 167 |
} |
| 168 |
|
| 169 |
// allocate memory for the node |
| 170 |
current = (tSPHandler *)malloc(sizeof(tSPHandler)); |
| 171 |
if (!current) |
| 172 |
return; |
| 173 |
// add it to the list |
| 174 |
last->next = current; |
| 175 |
} |
| 176 |
|
| 177 |
// fill in the struct |
| 178 |
current->next = NULL; |
| 179 |
current->ID = id; |
| 180 |
current->type = SPH_DMFCFUNC; |
| 181 |
current->DMFCfunc = func; |
| 182 |
} |
| 183 |
|
| 184 |
// DMFCBase::StartPacket |
| 185 |
// |
| 186 |
// Initializes a packet so it is ready to be sent out. |
| 187 |
// data = pointer to buffer of data for packet. This buffer should be MAX_GAME_DATA_SIZE in size, even |
| 188 |
// if you don't plan on using all that data, there is header information that is added |
| 189 |
// in this function. |
| 190 |
// id = ID of the Special packet. When the packet is recieved by whomever, this is the ID that determines which |
| 191 |
// handler to |
| 192 |
// call. |
| 193 |
// count = pointer to your packet index pointer |
| 194 |
void DMFCBase::StartPacket(uint8_t *data, uint8_t id, int *count) { |
| 195 |
*count = 0; |
| 196 |
|
| 197 |
MultiAddByte(id, data, count); // set the first byte (invisible to coder) as the id |
| 198 |
} |
| 199 |
|
| 200 |
// DMFCBase::SendPacket |
| 201 |
// |
| 202 |
// Ships a Special Packet away to the destination. This call must be preceeded by a StartPacket call |
| 203 |
// data = buffer of data to be sent out (same buffer that was passed to StartPacket |
| 204 |
// size = size (in bytes) of the packet |
| 205 |
// destination = either a player number, SP_ALL for all the players or SP_SERVER to send to the server (if you are a |
| 206 |
// client) |
| 207 |
void DMFCBase::SendPacket(uint8_t *data, int size, int destination) { |
| 208 |
ASSERT(size < MAX_GAME_DATA_SIZE - 2); // allow for a header by the d3 |
| 209 |
if (size >= MAX_GAME_DATA_SIZE - 2) |
| 210 |
return; |
| 211 |
|
| 212 |
// if we are the server and are trying to send to the server then exit out |
| 213 |
if ((GetLocalRole() == LR_SERVER) && (destination == SP_SERVER)) { |
| 214 |
return; |
| 215 |
} |
| 216 |
|
| 217 |
// we can safely send this packet out to it's appropriate destination |
| 218 |
|
| 219 |
// see if we are trying to send to the server, it's specially handled |
| 220 |
if (destination == SP_SERVER) { |
| 221 |
DLLMultiClientSendSpecialPacket(data, size); |
| 222 |
return; |
| 223 |
} |
| 224 |
|
| 225 |
// server trying to send to clients |
| 226 |
if (GetLocalRole() == LR_CLIENT) { |
| 227 |
// we can't send client to client |
| 228 |
return; |
| 229 |
} |
| 230 |
|
| 231 |
// if server is trying to send to all the clients then we need to send to each individual |
| 232 |
if (destination == SP_ALL) { |
| 233 |
int pnum; |
| 234 |
for (pnum = 0; pnum < DLLMAX_PLAYERS; pnum++) { |
| 235 |
|
| 236 |
if ((pnum != GetPlayerNum()) && (PacketCheckPlayerNum(pnum))) { |
| 237 |
// ship it! |
| 238 |
DLLMultiSendSpecialPacket(pnum, data, size); |
| 239 |
} |
| 240 |
} |
| 241 |
return; |
| 242 |
} |
| 243 |
|
| 244 |
// we are only sending to one client |
| 245 |
if (destination != GetPlayerNum()) |
| 246 |
DLLMultiSendSpecialPacket(destination, data, size); |
| 247 |
} |
| 248 |
|
| 249 |
// DMFCBase::GetGameStateRequest |
| 250 |
// |
| 251 |
// Receiver for the server from a client asking for the state of the game |
| 252 |
void DMFCBase::GetGameStateRequest(uint8_t *data) { |
| 253 |
int pnum; |
| 254 |
int count = 0; |
| 255 |
pnum = MultiGetInt(data, &count); |
| 256 |
CallOnGameStateRequest(pnum); |
| 257 |
} |
| 258 |
|
| 259 |
// DMFCBase::SendTeamAssignment |
| 260 |
// |
| 261 |
// A DMFC Special Packet function, this sends a team assignment packet to all the players. Server only. |
| 262 |
// playernum = player to change teams |
| 263 |
// team = new team |
| 264 |
void DMFCBase::SendTeamAssignment(int playernum, int team, bool spew_onrespawn) { |
| 265 |
if (GetLocalRole() != LR_SERVER) |
| 266 |
return; |
| 267 |
|
| 268 |
uint8_t data[MAX_GAME_DATA_SIZE]; |
| 269 |
int count = 0; |
| 270 |
|
| 271 |
StartPacket(data, SPID_TEAMASSIGNMENT, &count); |
| 272 |
|
| 273 |
MultiAddByte((spew_onrespawn) ? 1 : 0, data, &count); |
| 274 |
MultiAddInt(playernum, data, &count); |
| 275 |
MultiAddInt(team, data, &count); |
| 276 |
|
| 277 |
SendPacket(data, count, SP_ALL); |
| 278 |
} |
| 279 |
|
| 280 |
// DMFCBase::GetTeamAssignmentPacket |
| 281 |
// |
| 282 |
// Reciever for the team assignment packet. |
| 283 |
void DMFCBase::GetTeamAssignmentPacket(uint8_t *data) { |
| 284 |
int count = 0; |
| 285 |
bool spew = MultiGetByte(data, &count) ? true : false; |
| 286 |
|
| 287 |
int pnum = MultiGetInt(data, &count); |
| 288 |
int team = MultiGetInt(data, &count); |
| 289 |
|
| 290 |
if (CheckPlayerNum(pnum)) { |
| 291 |
Players[pnum].team = team; |
| 292 |
CallOnPlayerChangeTeam(pnum, team, true, spew); |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
// DMFCBase::GetChangeTeamPacket |
| 297 |
// |
| 298 |
// Reciever for the change team packet.(Server Only) |
| 299 |
void DMFCBase::GetChangeTeamPacket(uint8_t *data) { |
| 300 |
if (GetLocalRole() != LR_SERVER) |
| 301 |
return; |
| 302 |
// We recieved a request for a player to change teams |
| 303 |
|
| 304 |
int count = 0; |
| 305 |
|
| 306 |
bool spew_on_respawn = MultiGetByte(data, &count) ? true : false; |
| 307 |
int pnum = MultiGetByte(data, &count); |
| 308 |
int newteam = MultiGetByte(data, &count); |
| 309 |
if (newteam == 255) |
| 310 |
newteam = -1; |
| 311 |
|
| 312 |
if (!AllowTeamChange()) { |
| 313 |
return; |
| 314 |
} |
| 315 |
|
| 316 |
if (!CallOnCanChangeTeam(pnum, newteam)) { |
| 317 |
return; |
| 318 |
} |
| 319 |
|
| 320 |
if (!CheckPlayerNum(pnum)) |
| 321 |
return; |
| 322 |
|
| 323 |
if ((newteam < 0) || (newteam > m_iNumTeams)) |
| 324 |
return; |
| 325 |
|
| 326 |
Players[pnum].team = newteam; |
| 327 |
CallOnPlayerChangeTeam(pnum, newteam, true, spew_on_respawn); |
| 328 |
SendTeamAssignment(pnum, newteam, spew_on_respawn); |
| 329 |
} |
| 330 |
|
| 331 |
// DMFCBase::SendChangeTeamRequest |
| 332 |
// |
| 333 |
// Sends a request to the server to change teams (Client Only) |
| 334 |
void DMFCBase::SendChangeTeamRequest(int newteam, bool spew_onrespawn) { |
| 335 |
uint8_t data[MAX_GAME_DATA_SIZE]; |
| 336 |
int count = 0; |
| 337 |
|
| 338 |
StartPacket(data, SPID_CHANGETEAM, &count); |
| 339 |
|
| 340 |
MultiAddByte((spew_onrespawn) ? 1 : 0, data, &count); |
| 341 |
MultiAddByte(GetPlayerNum(), data, &count); |
| 342 |
MultiAddByte((newteam == -1) ? 255 : newteam, data, &count); |
| 343 |
|
| 344 |
SendPacket(data, count, SP_SERVER); |
| 345 |
} |
| 346 |
|
| 347 |
// DMFCBase::GetDMFCGameInfo |
| 348 |
// |
| 349 |
// Receives information about the DMFC game |
| 350 |
void DMFCBase::GetDMFCGameInfo(uint8_t *data) { |
| 351 |
int count = 0; |
| 352 |
|
| 353 |
uint8_t level = MultiGetByte(data, &count); // server's HUD Callsign max level |
| 354 |
m_bMakeClientsWait = MultiGetByte(data, &count) ? true : false; |
| 355 |
SwitchServerHudCallsignLevel(level); |
| 356 |
|
| 357 |
int num_teams = MultiGetByte(data, &count); |
| 358 |
|
| 359 |
char buffer[256]; |
| 360 |
|
| 361 |
if (num_teams > 1) { |
| 362 |
MultiGetString(buffer, data, &count); |
| 363 |
SetTeamName(RED_TEAM, buffer, false); |
| 364 |
|
| 365 |
MultiGetString(buffer, data, &count); |
| 366 |
SetTeamName(BLUE_TEAM, buffer, false); |
| 367 |
|
| 368 |
MultiGetString(buffer, data, &count); |
| 369 |
SetTeamName(GREEN_TEAM, buffer, false); |
| 370 |
|
| 371 |
MultiGetString(buffer, data, &count); |
| 372 |
SetTeamName(YELLOW_TEAM, buffer, false); |
| 373 |
} |
| 374 |
|
| 375 |
WaitForServer(m_bMakeClientsWait); |
| 376 |
} |
| 377 |
|
| 378 |
// DMFCBase::SendDMFCGameInfo |
| 379 |
// |
| 380 |
// Sends information about the DMFC game |
| 381 |
void DMFCBase::SendDMFCGameInfo(int player) { |
| 382 |
int r_len, b_len, g_len, y_len; |
| 383 |
int count = 0; |
| 384 |
uint8_t data[MAX_GAME_DATA_SIZE]; |
| 385 |
|
| 386 |
StartPacket(data, SPID_DMFCGAMEINFO, &count); |
| 387 |
|
| 388 |
if (GetNumTeams() > 1) { |
| 389 |
// team game |
| 390 |
r_len = strlen(GetTeamString(RED_TEAM)) + 1; |
| 391 |
b_len = strlen(GetTeamString(BLUE_TEAM) + 1); |
| 392 |
g_len = strlen(GetTeamString(GREEN_TEAM) + 1); |
| 393 |
y_len = strlen(GetTeamString(YELLOW_TEAM) + 1); |
| 394 |
|
| 395 |
MultiAddByte(m_iServerHUDCallsignLevel, data, &count); |
| 396 |
MultiAddByte(m_bMakeClientsWait, data, &count); |
| 397 |
MultiAddByte(GetNumTeams(), data, &count); |
| 398 |
|
| 399 |
MultiAddString(GetTeamString(RED_TEAM), data, &count); |
| 400 |
MultiAddString(GetTeamString(BLUE_TEAM), data, &count); |
| 401 |
MultiAddString(GetTeamString(GREEN_TEAM), data, &count); |
| 402 |
MultiAddString(GetTeamString(YELLOW_TEAM), data, &count); |
| 403 |
|
| 404 |
} else { |
| 405 |
// non-team game |
| 406 |
MultiAddByte(m_iServerHUDCallsignLevel, data, &count); |
| 407 |
MultiAddByte(m_bMakeClientsWait, data, &count); |
| 408 |
MultiAddByte(GetNumTeams(), data, &count); |
| 409 |
} |
| 410 |
|
| 411 |
SendPacket(data, count, player); |
| 412 |
|
| 413 |
SendRealGametime(player); |
| 414 |
} |
| 415 |
|
| 416 |
// DMFCBase::SendRealGametime |
| 417 |
// |
| 418 |
// Updates a player about the 'real' game time |
| 419 |
void DMFCBase::SendRealGametime(int pnum) { |
| 420 |
int count = 0; |
| 421 |
uint8_t data[MAX_GAME_DATA_SIZE]; |
| 422 |
|
| 423 |
StartPacket(data, SPID_REALGAMETIME, &count); |
| 424 |
|
| 425 |
MultiAddFloat(RealGametime, data, &count); |
| 426 |
|
| 427 |
if (m_iProtectedFlags & DMFC_PRF_PAUSETIME) { |
| 428 |
// time is paused |
| 429 |
MultiAddByte(1, data, &count); |
| 430 |
} else { |
| 431 |
// time is not paused |
| 432 |
MultiAddByte(0, data, &count); |
| 433 |
} |
| 434 |
|
| 435 |
SendPacket(data, count, pnum); |
| 436 |
} |
| 437 |
|
| 438 |
// DMFCBase::GetRealGametime |
| 439 |
// |
| 440 |
// handles a packet about updating the real game time |
| 441 |
void DMFCBase::GetRealGametimePacket(uint8_t *data) { |
| 442 |
int count = 0; |
| 443 |
|
| 444 |
RealGametime = MultiGetFloat(data, &count); |
| 445 |
|
| 446 |
if (MultiGetByte(data, &count)) { |
| 447 |
// time is paused |
| 448 |
ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PAUSETIME); |
| 449 |
} else { |
| 450 |
// time is not paused |
| 451 |
DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PAUSETIME); |
| 452 |
} |
| 453 |
} |
| 454 |
|
| 455 |
// DMFCBase::SendRemoteKey |
| 456 |
// |
| 457 |
// Sends out the players remote admin key |
| 458 |
void DMFCBase::SendRemoteKey(int pnum) { |
| 459 |
// Send this user's remote admin key |
| 460 |
player_record *pr = PRec_GetPRecordByPnum(pnum); |
| 461 |
int precnum = -1; |
| 462 |
if (pr) { |
| 463 |
precnum = translate_precptr_to_index(pr); |
| 464 |
} |
| 465 |
if (precnum != -1) { |
| 466 |
int count = 0; |
| 467 |
uint8_t data[MAX_GAME_DATA_SIZE]; |
| 468 |
|
| 469 |
StartPacket(data, SPID_REMOTEKEY, &count); |
| 470 |
|
| 471 |
uint8_t *key = Remote_GetKey(precnum); |
| 472 |
memcpy(&data[count], key, 8); |
| 473 |
count += 8; |
| 474 |
|
| 475 |
SendPacket(data, count, pnum); |
| 476 |
} else { |
| 477 |
Int3(); |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
// DMFCBase::GetRemoteKey |
| 482 |
// |
| 483 |
// Handles a new remote key from the server |
| 484 |
void DMFCBase::GetRemoteKey(uint8_t *data) { |
| 485 |
int count = 0; |
| 486 |
uint8_t key[8]; |
| 487 |
memcpy(key, &data[count], 8); |
| 488 |
count += 8; |
| 489 |
Remote_SetMyKey(key); |
| 490 |
} |
| 491 |
|
| 492 |
// DMFCBase::RequestGameState |
| 493 |
// |
| 494 |
// Sends a request to the server for the game state |
| 495 |
void DMFCBase::RequestGameState(void) { |
| 496 |
if (GetLocalRole() == LR_SERVER) |
| 497 |
return; |
| 498 |
int count = 0; |
| 499 |
uint8_t data[MAX_GAME_DATA_SIZE]; |
| 500 |
StartPacket(data, SPID_REQGAMESTATE, &count); |
| 501 |
|
| 502 |
MultiAddInt(GetPlayerNum(), data, &count); |
| 503 |
|
| 504 |
SendPacket(data, count, SP_SERVER); |
| 505 |
} |
| 506 |
|
| 507 |
void DMFCBase::SendVersionToClient(int pnum) { |
| 508 |
if (GetLocalRole() != LR_SERVER) |
| 509 |
return; |
| 510 |
int count = 0; |
| 511 |
uint8_t data[MAX_GAME_DATA_SIZE]; |
| 512 |
|
| 513 |
StartPacket(data, SPID_VERSIONID, &count); |
| 514 |
|
| 515 |
MultiAddInt(DMFC_VERSION_MAJOR, data, &count); |
| 516 |
MultiAddInt(DMFC_VERSION_MINOR, data, &count); |
| 517 |
|
| 518 |
SendPacket(data, count, pnum); |
| 519 |
} |
| 520 |
|
| 521 |
void DMFCBase::GetDMFCVersionCheck(uint8_t *data) { |
| 522 |
int major, minor, count = 0; |
| 523 |
|
| 524 |
major = MultiGetInt(data, &count); |
| 525 |
minor = MultiGetInt(data, &count); |
| 526 |
|
| 527 |
if ((major != DMFC_VERSION_MAJOR) || (minor != DMFC_VERSION_MINOR)) { |
| 528 |
char buffer[200]; |
| 529 |
snprintf(buffer, sizeof(buffer), "Excpecting Version %d.%d, found %d.%d", major, minor, DMFC_VERSION_MAJOR, |
| 530 |
DMFC_VERSION_MINOR); |
| 531 |
FatalError(buffer); |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
// DMFCBase::SendRequestForPlayerRecords |
| 536 |
// |
| 537 |
// |
| 538 |
// Sends a request to the server to send the player records |
| 539 |
void DMFCBase::SendRequestForPlayerRecords(void) { |
| 540 |
if (GetLocalRole() == LR_SERVER) |
| 541 |
return; |
| 542 |
int count = 0; |
| 543 |
uint8_t data[MAX_GAME_DATA_SIZE]; |
| 544 |
StartPacket(data, SPID_PRECORDREQ, &count); |
| 545 |
|
| 546 |
MultiAddByte(GetPlayerNum(), data, &count); |
| 547 |
|
| 548 |
SendPacket(data, count, SP_SERVER); |
| 549 |
} |
| 550 |
|
| 551 |
// DMFCBase::ReceiveRequestForPlayerRecords |
| 552 |
// |
| 553 |
// |
| 554 |
// Recieves and processes a request for a player record |
| 555 |
void DMFCBase::ReceiveRequestForPlayerRecords(uint8_t *data) { |
| 556 |
if (GetLocalRole() != LR_SERVER) |
| 557 |
return; |
| 558 |
int count = 0; |
| 559 |
int pnum = MultiGetByte(data, &count); |
| 560 |
PRec_SendPRecToPlayer(pnum); |
| 561 |
|
| 562 |
// send the player his remote admin key |
| 563 |
SendRemoteKey(pnum); |
| 564 |
} |
| 565 |
|
| 566 |
// DMFCBase::SendControlMessageToPlayer |
| 567 |
// |
| 568 |
// |
| 569 |
// Sends a [1 byte] control message to a player |
| 570 |
void DMFCBase::SendControlMessageToPlayer(int pnum, uint8_t msg) { |
| 571 |
int count = 0; |
| 572 |
uint8_t data[MAX_GAME_DATA_SIZE]; |
| 573 |
StartPacket(data, SPID_CONTROLMSG, &count); |
| 574 |
|
| 575 |
MultiAddByte(msg, data, &count); |
| 576 |
MultiAddByte(GetPlayerNum(), data, &count); |
| 577 |
MultiAddByte(pnum, data, &count); |
| 578 |
|
| 579 |
if (GetLocalRole() != LR_SERVER) { |
| 580 |
// send it to the server to forward to a client |
| 581 |
SendPacket(data, count, SP_SERVER); |
| 582 |
} else |
| 583 |
SendPacket(data, count, pnum); |
| 584 |
} |
| 585 |
|
| 586 |
// DMFCBase::ReceiveControlMessage |
| 587 |
// |
| 588 |
// |
| 589 |
// Handles a control message |
| 590 |
void DMFCBase::ReceiveControlMessage(uint8_t *data) { |
| 591 |
int count = 0; |
| 592 |
uint8_t msg = MultiGetByte(data, &count); |
| 593 |
uint8_t src = MultiGetByte(data, &count); |
| 594 |
uint8_t dst = MultiGetByte(data, &count); |
| 595 |
|
| 596 |
if ((GetLocalRole() == LR_SERVER) && (dst != SP_SERVER || dst != GetPlayerNum())) { |
| 597 |
// forward this packet to the correct player |
| 598 |
uint8_t fdata[MAX_GAME_DATA_SIZE]; |
| 599 |
count = 0; |
| 600 |
|
| 601 |
StartPacket(fdata, SPID_CONTROLMSG, &count); |
| 602 |
MultiAddByte(msg, fdata, &count); |
| 603 |
MultiAddByte(src, fdata, &count); |
| 604 |
MultiAddByte(dst, fdata, &count); |
| 605 |
SendPacket(fdata, count, dst); |
| 606 |
} else { |
| 607 |
// handle the packet |
| 608 |
CallOnControlMessage(msg, src); |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
// DMFCBase::SendNetGameInfoSync |
| 613 |
// |
| 614 |
// Sends out a NetGame info sync packet to all the players |
| 615 |
void DMFCBase::SendNetGameInfoSync(int to_who) { |
| 616 |
if (GetLocalRole() != LR_SERVER) |
| 617 |
return; |
| 618 |
|
| 619 |
uint8_t data[MAX_GAME_DATA_SIZE]; |
| 620 |
int count = 0; |
| 621 |
StartPacket(data, SPID_NETGAMESYNC, &count); |
| 622 |
|
| 623 |
MultiAddByte(Netgame->packets_per_second, data, &count); |
| 624 |
MultiAddByte((Netgame->flags & NF_KILLGOAL) ? 1 : 0, data, &count); |
| 625 |
MultiAddByte((Netgame->flags & NF_TIMER) ? 1 : 0, data, &count); |
| 626 |
|
| 627 |
MultiAddUshort(Netgame->timelimit, data, &count); |
| 628 |
MultiAddUshort(Netgame->killgoal, data, &count); |
| 629 |
MultiAddUshort(Netgame->respawn_time, data, &count); |
| 630 |
MultiAddUshort(Netgame->max_players, data, &count); |
| 631 |
|
| 632 |
SendPacket(data, count, to_who); |
| 633 |
} |
| 634 |
|
| 635 |
// DMFCBase::ReceiveNetGameInfoSync |
| 636 |
// |
| 637 |
// Receives a NetGame info sync packet from the server |
| 638 |
void DMFCBase::ReceiveNetGameInfoSync(uint8_t *data) { |
| 639 |
int count = 0; |
| 640 |
|
| 641 |
Netgame->packets_per_second = MultiGetByte(data, &count); |
| 642 |
if (MultiGetByte(data, &count)) |
| 643 |
Netgame->flags |= NF_KILLGOAL; |
| 644 |
else |
| 645 |
Netgame->flags &= ~NF_KILLGOAL; |
| 646 |
if (MultiGetByte(data, &count)) |
| 647 |
Netgame->flags |= NF_TIMER; |
| 648 |
else |
| 649 |
Netgame->flags &= ~NF_TIMER; |
| 650 |
|
| 651 |
Netgame->timelimit = MultiGetUshort(data, &count); |
| 652 |
Netgame->killgoal = MultiGetUshort(data, &count); |
| 653 |
Netgame->respawn_time = MultiGetUshort(data, &count); |
| 654 |
Netgame->max_players = MultiGetUshort(data, &count); |
| 655 |
} |
| 656 |
|
| 657 |
// DMFCBase::SendNewTeamName |
| 658 |
// |
| 659 |
// Tells the clients about a team's new name |
| 660 |
void DMFCBase::SendNewTeamName(int team) { |
| 661 |
if (GetLocalRole() != LR_SERVER) |
| 662 |
return; |
| 663 |
|
| 664 |
int count = 0; |
| 665 |
uint8_t data[MAX_GAME_DATA_SIZE]; |
| 666 |
StartPacket(data, SPID_NEWTEAMNAME, &count); |
| 667 |
|
| 668 |
MultiAddByte(team, data, &count); |
| 669 |
MultiAddString(DMFC_team_names[team], data, &count); |
| 670 |
|
| 671 |
SendPacket(data, count, SP_ALL); |
| 672 |
} |
| 673 |
|
| 674 |
// DMFCBase::ReceiveNewTeamName |
| 675 |
// |
| 676 |
// The server is telling us about a new team name |
| 677 |
void DMFCBase::ReceiveNewTeamName(uint8_t *data) { |
| 678 |
int count = 0; |
| 679 |
int team = MultiGetByte(data, &count); |
| 680 |
|
| 681 |
ASSERT(team >= 0 && team < DLLMAX_TEAMS); |
| 682 |
if (team < 0 || team >= DLLMAX_TEAMS) |
| 683 |
return; // invalid team |
| 684 |
|
| 685 |
char old_teamname[MAX_TEAMNAME_LEN]; |
| 686 |
strcpy(old_teamname, DMFC_team_names[team]); |
| 687 |
|
| 688 |
MultiGetString(DMFC_team_names[team], data, &count); |
| 689 |
|
| 690 |
CallOnTeamChangeName(team, old_teamname, DMFC_team_names[team]); |
| 691 |
} |