Debian Codegraph @

Descent3/multi.cpp

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
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/multi.cpp $
21 * $Revision: 530 $
22 * $Date: 10/22/01 12:42p $
23 * $Author: Matt $
24 *
25 * Multiplayer code
26 *
27 * $Log: /DescentIII/Main/multi.cpp $
28 *
29 * 530 10/22/01 12:42p Matt
30 * Changed previous fix to use spiffy new function to test for Mercenary
31 * installed.
32 *
33 * 529 10/22/01 11:12a Matt
34 * Put up HUD message when server tells us to switch ships.
35 * If told to switch to Black Pyro but don't have Merc, bail.
36 *
37 * 528 9/29/01 5:34p Kevin
38 * hack to prevent the observermode powerup stealing cheat/bug
39 *
40 * 527 9/13/01 2:32p Matt
41 * When recording a demo, save the new player position when a player
42 * respawns.
43 *
44 * 526 7/09/01 4:21p Matt
45 * Fixed code that used AllowedShips[] instead of Ships[] to find a valid
46 * ship.
47 *
48 * 525 4/20/00 6:23p Matt
49 * Fixed a bug that caused the difficulty for games in the games list to
50 * be always set to zero or one.
51 *
52 * 524 4/19/00 5:07p Matt
53 * From Duane for 1.4
54 * Added checks, asserts, and fixes for bad return values
55 *
56 * 523 3/20/00 12:17p Matt
57 * Merge of Duane's post-1.3 changes.
58 * Check for callsign too long.
59 * Byteswap fix.
60 *
61 * 522 2/01/00 3:47a Jason
62 * made usesmoothing be a client side option only
63 *
64 * 521 1/30/00 2:11p Jason
65 * Added -usesmoothing option back in
66 *
67 * 520 1/22/00 10:43p Jason
68 * Fixed phantom napalm and vauss bugs
69 *
70 * 519 1/22/00 5:36p Jason
71 * Took out reliable secondaries. Define RELIABLE_SECONDARIES to reenable
72 * this behavior (not recommended)
73 *
74 * 518 10/20/99 5:40p Chris
75 * Added the Red Guidebot
76 *
77 * 517 10/16/99 9:56p Jeff
78 * added a way to strip all players of all weapons and energy
79 *
80 * 516 10/16/99 8:45p Jeff
81 * created multi functions to strip a player of his weapons and energy
82 *
83 * 515 9/17/99 2:43p Kevin
84 * fixed bug where pxo stats weren't written if the game quit
85 *
86 * 514 9/09/99 12:24p Kevin
87 * Fixed a bug that was causing problems in the Mac version
88 * (Game_is_master_tracker_game was defined as a uint8_t in the game, but an
89 * int in the dll)
90 *
91 * 513 9/02/99 3:34p Jason
92 * send secondary fire reliable in a C/S game
93 *
94 * 512 9/01/99 6:56p Jason
95 * fixed guided missiles and timeout missiles so they work in multiplayer
96 *
97 * 511 9/01/99 4:12p Kevin
98 * Byte ordering fixes for the macintosh
99 *
100 * 510 8/23/99 5:14p Kevin
101 * Macintosh fixes
102 *
103 * 509 7/28/99 4:05p Kevin
104 * Mac
105 *
106 * 508 7/28/99 3:58p Kevin
107 * mac
108 *
109 * 507 7/20/99 12:57p Jason
110 * added MOTD to server
111 *
112 * 506 7/12/99 4:15p Kevin
113 * Changed the way we determine if we should report stats or not in PXO
114 *
115 * 505 7/12/99 1:56p Jason
116 * fixed dumb ammo bug
117 *
118 * 504 7/08/99 5:44p Jason
119 * Fixed some cheating holes for the patch
120 *
121 * 503 7/06/99 5:52p Kevin
122 * PXO & multiplayer fixes for the patch
123 *
124 * 502 5/24/99 5:42p Jason
125 * Fixed off by one observer crash
126 *
127 * 501 5/23/99 3:04a Jason
128 * fixed bug with player rankings not being updated correctly
129 *
130 * 500 5/22/99 10:27p Jason
131 * changes for multiplayer and buildings, ai
132 *
133 * 499 5/22/99 12:33a Jason
134 * added sending of physics flags upon joining
135 *
136 * 498 5/21/99 7:07p Jason
137 * fixed some weird multiplayer rejoin anomalies
138 *
139 * 497 5/20/99 4:55p Jason
140 * added heartbeats to server
141 *
142 * 496 5/20/99 4:10p Jason
143 * added heartbeat to multiplayer so clients wouldn't time out, also
144 * various multiplayer fixes
145 *
146 * 495 5/20/99 2:52p Jason
147 * made autowaypoints work in coop
148 *
149 * 494 5/20/99 11:57a Jason
150 * took out bogus int3
151 *
152 * 493 5/20/99 2:48a Matt
153 * Auto-waypoints now stored & used per player. Manual waypoints will all
154 * players, once Jason makes it work.
155 *
156 * 492 5/19/99 9:58p Jason
157 * no collide with ghosted ships
158 *
159 * 491 5/19/99 5:39p Jason
160 * made level failing work in coop
161 *
162 * 490 5/19/99 4:58p Jason
163 * changes for ranking system
164 *
165 * 489 5/19/99 4:10p Jason
166 * fixed wacky killer problem
167 *
168 * 488 5/19/99 3:24p Jason
169 * fixed wrong ordering of InitObjectScripts and MultiSendObject
170 *
171 * 487 5/19/99 12:11p Jason
172 * fixed some issues with multiplayer
173 *
174 * 486 5/19/99 12:03p Kevin
175 * added mprintf
176 *
177 * 485 5/18/99 10:15p Kevin
178 * made it so a client who is disconnected but the server still hasn't
179 * timed him out will not see the game until the server times him out, and
180 * he won't stay connected while in the join games screen
181 *
182 * 484 5/13/99 7:19p Jason
183 * made dying objects be able to be updated
184 *
185 * 483 5/13/99 7:18p Jeff
186 * safety check in MultiDoUnattach
187 *
188 * 482 5/13/99 1:07p Jason
189 * added ASSERT for Jeff
190 *
191 * 481 5/12/99 1:57p Jason
192 * fixed yet more buggy/ugly code
193 *
194 * 480 5/11/99 9:42p Jeff
195 * send tracker id of players to other players
196 *
197 * 479 5/11/99 10:59a Kevin
198 * Ship allow/dissalow works now!
199 *
200 * 478 5/10/99 10:22p Ardussi
201 * changes to compile on Mac
202 *
203 * 477 5/10/99 5:35p Kevin
204 * New command line options for heat and scoring API enhancements
205 *
206 * 476 5/10/99 1:45a Jason
207 * took out turret and robot position counters
208 *
209 * 475 5/10/99 1:22a Jason
210 * took out object error call
211 *
212 * 474 5/09/99 1:34p Kevin
213 * Added diffuculty level system to multiplayer
214 *
215 * 473 5/08/99 5:22p Jason
216 * fix audio taunt crash in single player
217 *
218 * 472 5/08/99 4:31a Jeff
219 * fixed sequencing bug where clients never got a level end event for the
220 * multiplayer games
221 *
222 * 471 5/07/99 3:16p Jason
223 * fixed some more multiplayer issues
224 *
225 * 470 5/07/99 2:50p Jason
226 * fixed a bunch of endlevel multiplayer issues
227 *
228 * 469 5/06/99 1:04a Kevin
229 * scoring API stuff
230 *
231 * 468 5/05/99 5:41p Jason
232 * fixed various multiplayer issues, including sequencing bugs and cheat
233 * prevention
234 *
235 * 467 5/05/99 12:23p Jason
236 * fixed some problems with ending levels
237 *
238 * 466 5/05/99 10:27a Kevin
239 * fixed some more player count bugs.
240 *
241 * 465 5/05/99 10:00a Kevin
242 * fixed dedicated server 'current number of players' count
243 *
244 * 464 5/03/99 2:35p Jason
245 * change for multiplayer games
246 *
247 * 463 5/03/99 1:17p Jason
248 * hack for disappearing powerup bug
249 *
250 * 462 5/03/99 8:38a Jeff
251 * handle world states for room's with goal/special flag change
252 *
253 * 461 5/02/99 5:09a Jeff
254 * send levelgoal state to joining clients
255 *
256 * 460 4/30/99 7:49p Jason
257 * setups urgent/non urgent reliable stuff better
258 *
259 * 459 4/30/99 5:43p Jason
260 * took out some errors
261 *
262 * 458 4/30/99 5:15p Kevin
263 * possibly fixed bug related to dedicated server player count
264 *
265 * 457 4/30/99 1:10p Jason
266 * fixed sounds being sent reliably by the server
267 *
268 * 456 4/30/99 12:58p Jeff
269 * fixed inventory removed bug in multiplayer
270 *
271 * 455 4/30/99 12:01a Jason
272 * added ability to set the next level in a multiplayer game
273 *
274 * 454 4/29/99 11:02p Jeff
275 * added the ability for the server to set audio taunt delay time via
276 * command line option and/or dedicated server console
277 *
278 * 453 4/29/99 4:59p Jason
279 * fixed bug with world states and refueling centers
280 *
281 * 452 4/29/99 3:07p Jason
282 * added more cheat protection
283 *
284 * 451 4/29/99 2:09a Jason
285 * added more safechecking for powerup bug tracking
286 *
287 * 450 4/29/99 2:00a Chris
288 * Added the portal blockage support
289 *
290 * 449 4/28/99 9:16p Jeff
291 * fixed inventory use bug...was using Server_object_list instead of
292 * Local_object_list
293 *
294 * 448 4/28/99 7:37p Jason
295 * fixed killer objnum bug
296 *
297 * 447 4/28/99 5:13p Jeff
298 * fixed(?) clients using inventory items in coop
299 *
300 * 446 4/28/99 3:33a Jeff
301 * removed useless IGC variable reset (wasn't needed, although previously
302 * thought it was needed)
303 *
304 * 445 4/28/99 2:28a Jeff
305 * finished (hopefully) making guidebot multiplayer friendly
306 *
307 * 444 4/27/99 8:32p Jason
308 * fixed cinematic bug
309 *
310 * 443 4/27/99 3:46p Jeff
311 * increased audio taunt delay to 5 seconds
312 *
313 * 442 4/27/99 4:42a Jeff
314 * pass guidebot name on MyInfo
315 *
316 * 441 4/26/99 11:48p Jason
317 * removed mprintfs
318 *
319 * 440 4/26/99 10:14p Kevin
320 * Stop playing the napalm sound when a player dies in multi
321 *
322 * 439 4/26/99 7:08p Jason
323 * fixed doorway join bug
324 *
325 * 438 4/26/99 11:59a Jeff
326 * removed stupid test code that wasn't tested and broke everything
327 *
328 * 437 4/25/99 10:19p Matt
329 * Fixed multiplayer and demo problems will killing an object from script,
330 * and cleaned up the death code a bit in the process.
331 *
332 * 436 4/25/99 5:20p Jason
333 * fixed some more coop bugs
334 *
335 * 435 4/25/99 5:02p Kevin
336 * Bunches of multiplayer UI improvements
337 *
338 * 434 4/25/99 12:19p Kevin
339 * fixed max players for dedicated server
340 *
341 * 433 4/25/99 8:57a Kevin
342 * fixes for server info dialog
343 *
344 * 432 4/24/99 11:58p Kevin
345 * Game info list (hit I in the pxo game list)
346 *
347 * 431 4/24/99 6:44p Jeff
348 * added functions for theif so he can steal things other than weapons
349 *
350 * 430 4/22/99 8:29p Kevin
351 * made psrand.h come after stdlib.h
352 *
353 * 429 4/22/99 5:46p Jason
354 * made weapons work in multiplayer
355 *
356 * 428 4/22/99 3:24p Jason
357 * fixed some multisafe problems
358 *
359 * 427 4/21/99 12:05p Jason
360 * fixed sound priority bug
361 *
362 * 426 4/21/99 11:42a Kevin
363 * fixed compiler warning
364 *
365 * 425 4/21/99 11:05a Kevin
366 * new ps_rand and ps_srand to replace rand & srand
367 *
368 * 424 4/19/99 3:46a Jeff
369 * fixed min/max problem
370 *
371 * 423 4/17/99 4:33p Jason
372 * changes for robot/turret tracking
373 *
374 * 422 4/16/99 11:23p Jeff
375 * added some includes to make linux happy
376 *
377 * 421 4/16/99 11:54a Matt
378 * Took out include of directplay.h, which wasn't needed.
379 *
380 * 420 4/16/99 11:21a Kevin
381 * Added netgame flags to game info packet
382 *
383 * 419 4/15/99 2:39p Kevin
384 * Increased the amount of time the dedicated server will wait before
385 * going on to the next level (to make sure the reliable code has time to
386 * catch up on missed packets)
387 *
388 * 418 4/15/99 1:40a Jeff
389 * changes for linux compile
390 *
391 * 417 4/14/99 2:51a Jeff
392 * fixed some case mismatched #includes
393 *
394 * 416 4/11/99 1:57p Kevin
395 * Made some static memory usage reductions
396 *
397 * 415 4/08/99 3:13p Matt
398 * Finished cleaning up level sequencing code. Got rid of all the "level
399 * minus one" stuff.
400 *
401 * 414 4/07/99 12:30p Matt
402 * Added code for failed missions.
403 *
404 * 413 4/06/99 6:24p Jason
405 * various fixes for multiplayer
406 *
407 * 412 4/05/99 10:54a Matt
408 * Added auto-waypoint system
409 *
410 * 411 4/04/99 8:15p Jeff
411 * added debug graph stuff
412 *
413 * 410 4/02/99 6:30p Jason
414 * fixed multiplayer powerup/player start bugs
415 *
416 * 409 4/01/99 5:48p Kevin
417 * Put in code to make it easy to add the guidebot to multiplayer (coop)
418 * games
419 *
420 * 408 3/30/99 5:36p Matt
421 * Fixed compile warnings
422 *
423 * 407 3/29/99 7:31p Jason
424 * added better handling of non vis generic objects
425 *
426 * 406 3/27/99 2:19p Jason
427 * transmit rankings when a player joins
428 *
429 * 405 3/25/99 1:41p Jason
430 * took out debug mprintfs
431 *
432 * 404 3/25/99 1:41p Jeff
433 * I'm a moron...forgot to send over player logo stuff on client join...
434 *
435 * 403 3/25/99 11:18a Jason
436 * fixed fog state bug
437 *
438 * 402 3/22/99 6:21p Jeff
439 * added 2 more audio taunts. a mulitplayer event when someone plays an
440 * audio taunt. option to disable audio taunts.
441 *
442 * 401 3/17/99 4:08p Kevin
443 * Changed the way games appear and timeout in the game list.
444 *
445 * 400 3/15/99 3:24p Kevin
446 * Fixed some ingame file xfer stuff
447 *
448 * 399 3/12/99 7:49p Jeff
449 * save player type changes and objects set to use life left
450 *
451 * 398 3/11/99 9:10p Jeff
452 * fixed remaining known bugs in demo system (DemoWriteObjCreate being
453 * called twice and </<= problems with
454 * Highest_room_index/Highest_object_index).
455 *
456 * 397 3/11/99 6:30p Jeff
457 * numerous fixes to demo system in multiplayer games (when
458 * recording/playback a demo in a multiplayer game)
459 *
460 * 396 3/10/99 2:25p Kevin
461 * Save/Load and Demo file fixes
462 *
463 * 395 3/09/99 6:13p Jason
464 * fixed observer mode changing bug
465 *
466 * 394 3/08/99 4:00p Kevin
467 * Better handling of level-level transitions on the server
468 *
469 * 393 3/05/99 1:24p Kevin
470 * Fixed Stupid Direct serial bug where it would try to join the game
471 * again and crash
472 *
473 * 392 3/04/99 8:50p Samir
474 * AddColoredHUDMessage is formatted, so when mulitplayer messages went
475 * out, they would take the % signs and screw up the string. Now it
476 * doesn't.
477 *
478 * 391 3/04/99 3:46p Jason
479 * fixed some multisafe stuff
480 *
481 * 390 3/04/99 3:30p Kevin
482 * Fixed bug with not downloading files
483 *
484 * 389 3/02/99 5:50p Kevin
485 * Ouch. Duplicate structures existed and were conflicting.
486 *
487 * 388 3/01/99 3:15p Jason
488 * stop velocity when repositioning powerups
489 *
490 * 387 2/25/99 8:54p Jeff
491 * Inventory supports level change persistant items. Inventory supports
492 * time-out objects. Inventory Reset changed (takes a level of reset
493 * now). Quad lasers stay across level change (single player). Guidebot
494 * bug fixed (now back in ship on level start). Quads time out when
495 * spewed. Invulnerability and cloak powerups no longer use game
496 * event/callbacks, so they can be saved in game saves (moved to
497 * MakePlayerInvulnerable and MakeObjectInvisible)
498 *
499 * 386 2/25/99 12:44p Jason
500 * fixed some major multiplayer bugs
501 *
502 * 385 2/25/99 11:53a Jason
503 * fixed marker bug
504 *
505 * 384 2/25/99 10:59a Matt
506 * Added new explosion system.
507 *
508 * 383 2/25/99 10:30a Jason
509 * added nonvis generic/robot system
510 *
511 * 382 2/24/99 1:01p Jason
512 * various fixes for multiplayer
513 *
514 * 381 2/24/99 11:21a Jason
515 * Fixed bugs for OEM build
516 *
517 * 380 2/23/99 5:07p Kevin
518 * Fixed a bug in the multi-xfer
519 *
520 * 379 2/23/99 5:00p Jason
521 * took out mprintfs
522 *
523 * 378 2/23/99 4:59p Jason
524 * fixed another marker problem
525 *
526 * 377 2/23/99 3:32p Jason
527 * fixed marker bug
528 *
529 * 376 2/22/99 4:02p Kevin
530 * Checked CRC before using file in multiplayer file exchange system
531 *
532 * 375 2/21/99 10:23a Kevin
533 * Put in 32k limit for multiplayer in game file xfers
534 *
535 * 374 2/17/99 2:12p Jason
536 * fixed up some coop vis issues
537 *
538 * 373 2/17/99 2:08p Jason
539 * fixed observer mode
540 *
541 * 372 2/16/99 3:46p Jason
542 * added marker updates to multiplayer server stream
543 *
544 * 371 2/15/99 4:10p Jason
545 * made non-vis ships kill all their attached sounds/objects
546 *
547 * 370 2/15/99 11:21a Jason
548 * ripped out client side interpolation
549 *
550 * 369 2/13/99 12:35a Jeff
551 * fixed up packets to handle new inventory system (removed some compiler
552 * warnings)
553 *
554 * 368 2/12/99 5:36p Jason
555 * temp hacks for permissable client server
556 *
557 * 367 2/12/99 3:37p Jason
558 * added client-side interpolation...its not fully debugged though.
559 *
560 * 366 2/10/99 3:48p Jason
561 * table filter changes
562 *
563 * 365 2/10/99 1:47p Matt
564 * Changed object handle symbolic constants
565 *
566 * 364 2/09/99 6:52p Jeff
567 * implemented 'typing inidcator' in multiplayer...players that are typing
568 * messages have an icon on them
569 *
570 * 363 2/08/99 5:25p Jeff
571 * removed all calls to MultiSendRemoveObject, incorportated into
572 * SetObjectDeadFlag. Fixes sequencing issues in multiplayer
573 *
574 * 362 2/04/99 7:18p Jeff
575 * sounds for hud messages
576 *
577 * 361 2/04/99 12:26p Jason
578 * added spew that was better for multiplayer
579 *
580 * 360 2/04/99 11:36a Jason
581 * fixed some multi bugs
582 *
583 * 359 2/04/99 11:01a Jason
584 * added anti cheating to multiplayer
585 *
586 * 358 2/03/99 6:32p Jason
587 * more changes for world states
588 *
589 * 357 2/03/99 4:26p Jason
590 * made multiplayer coop actually work!
591 *
592 * 356 2/03/99 4:20p Kevin
593 * Got multiplayer working with .mn3 files, and setup autodownloading
594 *
595 * 355 2/02/99 8:43a Chris
596 * I made buildings with AI work correctly (ie really big robots should be
597 * buildings)
598 * anim to and from states are now shorts instead of bytes
599 *
600 * 354 2/01/99 3:47p Jason
601 * added more multisafe functionality
602 *
603 * 353 1/31/99 7:26p Matt
604 * Renamed a bunch of functions to have HUD capitalized
605 *
606 * 352 1/31/99 3:44p Matt
607 * Streamlined game sequencing
608 *
609 * 351 1/31/99 1:03a Jason
610 * made multiplayer code leaner
611 *
612 * 350 1/29/99 5:22p Jeff
613 * localization
614 *
615 * 349 1/28/99 6:17p Jason
616 * added markers
617 *
618 * 348 1/27/99 5:47p Jeff
619 * audio taunts implemented!
620 *
621 * 347 1/26/99 3:25p Jason
622 * fixed room change flag problem
623 *
624 * 346 1/22/99 4:06p Jeff
625 * added hud messages that can be sent to just teammates or individual
626 * people
627 *
628 * 345 1/21/99 11:15p Jeff
629 * pulled out some structs and defines from header files and moved them
630 * into seperate header files so that multiplayer dlls don't require major
631 * game headers, just those new headers. Side effect is a shorter build
632 * time. Also cleaned up some header file #includes that weren't needed.
633 * This affected polymodel.h, object.h, player.h, vecmat.h, room.h,
634 * manage.h and multi.h
635 *
636 * 344 1/21/99 12:38p Jason
637 * fixed vis problem
638 *
639 * 343 1/20/99 8:06p Jeff
640 * added members into DLLinfo struct for game change segment events, pass
641 * them over on execute dll packets
642 *
643 * 342 1/20/99 2:13a Chris
644 * It is now possible for robots to have special immunities, resistances,
645 * and vunerabilities
646 *
647 * 341 1/19/99 7:17p Jeff
648 * fixed powerup pickup problem (Jason)
649 *
650 * 340 1/18/99 2:46p Matt
651 * Combined flags & flags2 fields in object struct
652 *
653 * 339 1/18/99 11:10a Jason
654 * fixed packet mangling problems
655 *
656 * 338 1/17/99 11:58p Jeff
657 * removed call to the change seg event for player, since it's done in
658 * ObjSetPos(). Also send over collide data on collide event
659 * (EVT_CLIENT_GAMECOLLIDE)
660 *
661 * 337 1/17/99 10:58p Jason
662 * Took out autolag problems, plus added checksum to each packet
663 *
664 * 336 1/15/99 7:52p Chris
665 * Updated ObjSetPos() to include a f_update_attach_children flag
666 *
667 * 335 1/15/99 2:33p Jason
668 * fixed multiplayer ping bug
669 *
670 * 334 1/15/99 3:52a Jeff
671 * the Multi Do DLL Event function has more data being packed into it
672 * (point and normal from DLLInfo) for collision data
673 *
674 * 333 1/14/99 4:23p Jason
675 * fixed join bug with dead players
676 *
677 * 332 1/13/99 3:37p Jason
678 * made match collisions less likely to happen by complicating the hash
679 * generation process
680 *
681 * 331 1/13/99 2:56p Jason
682 * more work on world states
683 *
684 * 330 1/13/99 2:53p Jason
685 * added CONNECT_BAIL packet type
686 *
687 * 329 1/13/99 12:43p Jason
688 * fixed flickering exit menu screen
689 *
690 * 328 1/11/99 12:47p Jason
691 * misc changes for polishing
692 *
693 * 327 1/08/99 2:56p Samir
694 * Ripped out OSIRIS1.
695 *
696 * 326 1/06/99 12:34p Jason
697 * misc changes for multiplayer
698 *
699 * 325 1/05/99 5:09p Jason
700 * added permissable server networking (ala Quake/Unreal) to Descent3
701 *
702 * 324 1/04/99 8:11p Jason
703 * fixed packet loss tracking problem
704 *
705 * 323 1/04/99 7:58p Jason
706 * fixed packet throttling...it didn't work with the new architecture very
707 * well!
708 *
709 * 322 12/30/98 5:24p Kevin
710 * Added +name to specify a default pilot (for gamespy) fixed a gamespy
711 * bug, and improved the pxo dll game list screen
712 *
713 * 321 12/28/98 2:22p Kevin
714 * Initial mission downloading system
715 *
716 * 320 12/23/98 12:40p Jason
717 * made player invul for 1 second when respawning
718 *
719 * 319 12/21/98 4:04p Jason
720 * first pass at multisafe powerups
721 *
722 * 318 12/21/98 10:22a Jason
723 * added auto pps
724 *
725 * 317 12/18/98 11:40a Jason
726 * took out some mprintfs
727 *
728 * 316 12/16/98 5:37p Jason
729 * added new multisafe architecture
730 *
731 * 315 12/16/98 12:04p Kevin
732 * GameSpy!
733 *
734 * 314 12/15/98 4:20p Jason
735 * added triggers and door funtions to multisafe list
736 *
737 * 313 12/15/98 10:53a Jason
738 * yet more changes for 1.1
739 *
740 * 312 12/14/98 5:32p Jason
741 * added multisafe functions
742 *
743 * 311 12/14/98 11:06a Jason
744 * changes for 1.1
745 *
746 * 310 12/10/98 7:09p Jason
747 * added cloak fade
748 *
749 * 309 12/10/98 5:08p Jason
750 * more changes for autolag
751 *
752 * 308 12/10/98 10:51a Jason
753 * added autolag
754 *
755 * 307 12/08/98 4:52p Jeff
756 * changed the pilot pics packing to use Ushort instead of short just for
757 * my conscience...removed some annoying mprintf's too
758 *
759 * 306 12/07/98 6:18p Kevin
760 * Fixed writing pxo stats when ending the level via timer, etc....
761 *
762 * 305 12/07/98 3:02p Jason
763 * added multi_logo_state
764 *
765 * 304 12/04/98 7:05p Jason
766 * fixed problems with peer 2 peer
767 *
768 * 303 12/04/98 3:31p Jason
769 * fixed error in server address
770 *
771 * 302 12/03/98 3:39p Jason
772 * added peer 2 peer style damage
773 *
774 * 301 12/02/98 10:30a Jason
775 * added additional damage types for client-side multiplayer
776 *
777 * 300 12/01/98 5:48p Jeff
778 * added pilot picture id to netplayer struct
779 *
780 * 299 12/01/98 3:38p Jason
781 * send over energy for players
782 *
783 * 298 11/23/98 3:11p Kevin
784 * Demo system
785 *
786 * 297 11/23/98 1:50p Jason
787 * added thruster sounds
788 *
789 * 296 11/19/98 11:27a Jason
790 * added Multi_accept_state for Jeff
791 *
792 * 295 11/16/98 4:46p Jason
793 * changes for multiplayer (weapons load sent and deleting destroyed
794 * lightmapped objects)
795 *
796 * 294 11/13/98 4:25p Jason
797 * changes for better weapon effects
798 *
799 * 293 11/13/98 12:30p Jason
800 * changes for weapons
801 *
802 * 292 11/11/98 7:18p Jeff
803 * changes made so that a dedicated server's team is always -1 (team game
804 * or not)
805 *
806 * 291 11/11/98 12:11p Chris
807 * The attach system and weapon firing (continous and spray) are now
808 * network friendly
809 *
810 * 290 11/10/98 4:29p Kevin
811 * Added attach code for chris
812 *
813 * 289 11/10/98 11:16a Jason
814 * fixed some multiplayer bugs with powerups disappearing
815 *
816 *
817 * 288 11/06/98 5:43p Jason
818 * made pings sent not reliably
819 *
820 * 287 11/03/98 6:16p Chris
821 * Starting to make on/off and spray weapons accessable to robots
822 *
823 * 286 11/02/98 6:53p Jason
824 * made different game versions not show up in game list
825 *
826 * 285 11/02/98 6:41p Jason
827 * fixed release problems
828 *
829 * 284 10/30/98 4:24p Jason
830 * changes for multiplayer
831 *
832 * 283 10/29/98 5:08p Jason
833 * took out a couple mprintfs
834 *
835 * 282 10/28/98 5:25p Jason
836 * fixed player death problems in multiplayer
837 *
838 * 281 10/28/98 5:07p Jason
839 * more changes for cleaner multiplayer
840 *
841 * 280 10/28/98 11:51a Jason
842 * fixed some multiplayer problems, plus redid coop a bit to make it
843 * cleaner
844 *
845 * 279 10/27/98 10:19a Jason
846 * changes for new arch
847 *
848 * 278 10/22/98 12:28p Kevin
849 * Fixed pings in peer-peer
850 *
851 * 277 10/22/98 10:39a Kevin
852 * Fixed DirectPlay
853 *
854 * 276 10/21/98 7:05p Jeff
855 * removed int3
856 *
857 * 275 10/21/98 5:03p Jeff
858 * you can only go into observer mode if you are >50 shields
859 *
860 * 274 10/21/98 3:04p Kevin
861 *
862 * 273 10/21/98 9:48a Kevin
863 * took out some debugging code and mprintfs
864 *
865 * 272 10/20/98 5:46p Kevin
866 * Gunboy and other fixes
867 *
868 * 271 10/20/98 1:48p Jason
869 * fixed some reliable/unreliable problems
870 *
871 * 270 10/20/98 1:38p Kevin
872 * added mprintf's for debugging
873 *
874 * 269 10/20/98 2:53a Kevin
875 * gunboy crap
876 *
877 * 268 10/20/98 12:39a Jason
878 * took out erroneous checks
879 *
880 * 267 10/20/98 12:12a Jason
881 * fixed stupid bug
882 *
883 * 266 10/19/98 11:46p Jason
884 * changes for multiplayer debug layer
885 *
886 * 265 10/19/98 11:20p Matt
887 * Changed some bytes type ubytes, since bytes are unsigned anyway.
888 *
889 * 264 10/19/98 10:37p Jeff
890 *
891 * 263 10/19/98 7:51p Kevin
892 * performance testing
893 *
894 * 262 10/19/98 7:18p Matt
895 * Added system to support different types of damage to the player and
896 * have these different types make different sounds.
897 *
898 * 261 10/19/98 5:17p Jason
899 * fixed some vis issues (hopefully for good)
900 *
901 * 260 10/19/98 5:07p Jason
902 * put vis stuff back in
903 *
904 * 259 10/18/98 7:59p Jeff
905 * the function used to see if a player is banned has new prototype
906 *
907 * 258 10/18/98 2:59p Jason
908 * fixes for beta4
909 *
910 * 257 10/17/98 12:46p Kevin
911 * Beta 4 fixes
912 *
913 * 256 10/16/98 3:19p Jason
914 * now checks to see if persistant data is same on client/server
915 *
916 * 255 10/16/98 2:52p Jason
917 * trying to debug world states
918 *
919 * 254 10/16/98 2:24p Jason
920 * changes for the demo
921 *
922 * 253 10/16/98 1:54p Kevin
923 * Changes for Demo Beta 4
924 *
925 * 252 10/16/98 11:55a Kevin
926 * Made dlls loadable in a hog
927 *
928 * 251 10/14/98 11:23p Jeff
929 * removed hud messages on player join
930 *
931 * 250 10/14/98 1:02p Jason
932 * fixed FindSoundName issues
933 *
934 * 249 10/14/98 11:46a Jason
935 * made camera scripts work correctly
936 *
937 * 248 10/13/98 9:26p Jason
938 * trying to track down wind problems
939 *
940 * 247 10/13/98 2:16a Jeff
941 * added call to EVT_GAME_DISCONNECTED in MultiLeaveGame()
942 *
943 * 246 10/11/98 2:57a Jeff
944 * added new multiplayer event EVT_GAME_INTERVAL, which is to be called on
945 * interval, and EVT_HUD_INTERVAL is only to be called when the hud is to
946 * be rendered
947 *
948 * 245 10/08/98 7:30p Samir
949 * game sequencing changes.
950 *
951 * 244 10/08/98 3:38p Jeff
952 * removed time_left from Netgame
953 *
954 * 243 10/07/98 5:05p Jason
955 * added quaded weapons
956 *
957 * 242 10/07/98 1:06p Jason
958 * added more safety precautions
959 *
960 * 241 10/07/98 10:25a Jason
961 * Now send damage reliably
962 *
963 * 240 10/06/98 6:07p Jason
964 * added protective layer for reliable packets
965 *
966 * 239 10/06/98 4:00p Jason
967 * Reset a players ship at the beginning of a new level
968 *
969 * 238 10/05/98 7:23p Jason
970 * added protective layer onto multiplayer
971 *
972 * 237 10/05/98 11:08a Jason
973 * fixed some potential gap problems in the multiplayer sequencing code
974 *
975 * 236 10/02/98 3:26p Chris
976 * Removed the bug ridden interpolation code
977 *
978 * 235 10/01/98 4:58p Kevin
979 * fixed debug code
980 *
981 * 234 10/01/98 2:48p Kevin
982 * put in debug info for removing a powerup
983 *
984 * 233 10/01/98 2:09p Jason
985 * more fixes to object creation
986 *
987 * 232 10/01/98 2:07p Jason
988 * possible fix for script problems
989 *
990 * 231 10/01/98 12:41p Jason
991 * more world state stuff
992 *
993 * 230 10/01/98 12:16p Kevin
994 * Fixed Ping for Peer-Peer games
995 *
996 * 229 10/01/98 12:02p Kevin
997 * Fixed PXO ping time
998 *
999 * 228 10/01/98 11:36a Kevin
1000 * UI fixes and stuff
1001 *
1002 * 227 10/01/98 11:29a Jason
1003 * changes for world states in multiplayer games
1004 *
1005 * 226 10/01/98 10:21a Jason
1006 * added some testing mprintfs
1007 *
1008 * 225 9/30/98 6:56p Jason
1009 * more changes for DLLS
1010 *
1011 * 224 9/30/98 6:25p Jason
1012 * debugging info for remove object
1013 *
1014 * 223 9/30/98 5:35p Jason
1015 * added multiplayer menu bailing for samir
1016 *
1017 * 222 9/30/98 3:14p Jason
1018 * fixed some possible bugs with -1 objnums and scripts/dlls
1019 *
1020 *
1021 * 219 9/29/98 11:18a Jeff
1022 * fixed OBJ_DUMMY problems on client join objects
1023 *
1024 * 218 9/28/98 6:23p Chris
1025 * Changed multi_anim to custom_anim
1026 *
1027 * 217 9/28/98 6:23p Jason
1028 * added persistant data
1029 *
1030 * 216 9/28/98 12:56p Jason
1031 * multiplayer bug fixes
1032 *
1033 * 215 9/28/98 11:02a Kevin
1034 * added Networking defer, and fixed some UI issues
1035 *
1036 * 214 9/28/98 10:33a Jason
1037 * changed all asserts to BailOnMultiplayer for clean exits
1038 *
1039 * 213 9/28/98 10:06a Jason
1040 * fixed some multiplayer bugs
1041 *
1042 * 212 9/28/98 9:53a Kevin
1043 * Fixing misc UI problems, and fixed some bugs that VC 6 found
1044 *
1045 * 211 9/25/98 9:25p Jason
1046 * turned vis stuff back on
1047 *
1048 * 210 9/25/98 5:33p Jason
1049 * fixed parenting again
1050 *
1051 * 209 9/25/98 4:21p Jason
1052 * more multiplayer bug checking
1053 *
1054 * 208 9/25/98 3:01p Kevin
1055 * fixxed ping code
1056 *
1057 * 207 9/25/98 12:06a Jason
1058 * fixed some multiplayer scripting issues
1059 *
1060 * 206 9/24/98 4:59p Jason
1061 * fixed script bug
1062 *
1063 * 205 9/24/98 4:41p Jason
1064 * handled a multiplayer script problem
1065 *
1066 * 204 9/22/98 2:29p Kevin
1067 * moved ships allowed code out of dll and into main app. Also added
1068 * powerup exclusions
1069 *
1070 * 203 9/15/98 4:31p Jason
1071 * added more functionality for the dedicated server
1072 *
1073 * 202 9/15/98 2:44p Jason
1074 * fixed bug with my last rev
1075 *
1076 * 201 9/15/98 12:47p Jason
1077 * made spewed countermeasures work correctly
1078 *
1079 * 200 9/11/98 12:25p Jason
1080 * got energy to shield and fusion damage working in multiplayer
1081 *
1082 * 199 9/10/98 12:18p Jason
1083 * more changes to afterburner/thrust effect
1084 *
1085 * 198 9/09/98 7:09p Jason
1086 * changed afterburner effect for ships
1087 *
1088 * 197 9/04/98 3:45p Kevin
1089 * Added ping_time to Netplayers struct. It's updated in peer-peer and
1090 * client server
1091 *
1092 * 196 9/02/98 6:54p Kevin
1093 * Fixed general directplay support up, and got modem-modem working
1094 *
1095 * 195 9/01/98 11:19a Matt
1096 * Re-added wrongly-deleted ResetPlayerObject() call in
1097 * MultiStartNewLevel()
1098 *
1099 * 194 8/31/98 10:14a Kevin
1100 * Misc. multi-UI fixes
1101 *
1102 * 193 8/28/98 1:34p Matt
1103 * Added code to reset the waypoint when starting a new level, and while I
1104 * was at it cleaned up the new level start sequencing.
1105 *
1106 * 192 8/26/98 4:30p Jason
1107 * added directional lights (headlight for player)
1108 *
1109 * 191 8/24/98 2:45p Jason
1110 * added team start position stuff
1111 *
1112 * 190 8/19/98 11:49a Kevin
1113 * Got DirectPlay IPX working, and localized connection DLLs
1114 *
1115 * 189 8/15/98 5:16p Matt
1116 * Added new Base_directory variable. Got rid of D3_LOCAL check and
1117 * 'local directory' registry variable.
1118 *
1119 * 188 8/13/98 6:32p Kevin
1120 * Initial implementation of directplay API
1121 *
1122 * 187 8/13/98 6:09p Jason
1123 * addendum to my last rev....made it work with REMOVE_OBJECT packet
1124 *
1125 * 186 8/13/98 6:08p Jason
1126 * Fixed blowing up of robots
1127 *
1128 * 185 8/12/98 6:36p Jeff
1129 * converted the send link/unlink functions to handle ghosted objects.
1130 * Updated MultiSendObject to handle dummy objects
1131 *
1132 * 184 8/12/98 11:54a Jeff
1133 * added link/unlink object packets
1134 *
1135 * 183 8/10/98 5:27p Kevin
1136 * fixed coop bug with tubs
1137 *
1138 * 182 8/10/98 4:58p Kevin
1139 * Send robot orientation as 3 angles
1140 *
1141 * 181 8/10/98 2:21p Jeff
1142 * changes made due to adding flag for inventory reset
1143 *
1144 * 180 8/07/98 6:03p Jason
1145 * took out magnitude shift for player positions
1146 *
1147 * 179 8/07/98 12:27p Kevin
1148 * Added network stuff for energy/shield conversion
1149 *
1150 * 178 8/05/98 6:59p Kevin
1151 *
1152 * 177 8/05/98 2:25p Kevin
1153 * improved network address reporting
1154 *
1155 * 176 8/05/98 11:48a Kevin
1156 *
1157 * 175 8/05/98 10:46a Kevin
1158 * sound & bmp exchange fixes
1159 *
1160 * 174 8/04/98 6:13p Kevin
1161 * fixes for sound & bmp exchange
1162 *
1163 * 173 8/04/98 3:07p Kevin
1164 * sound & bmp exchange fixes for > 2 players
1165 *
1166 * 172 8/04/98 10:26a Kevin
1167 * Custom sound and bmp exchange system
1168 *
1169 * 171 8/03/98 5:56p Jason
1170 * got fusion cannon working correctly
1171 *
1172 * 170 8/03/98 4:28p Jason
1173 * added first pass of spline movement trick
1174 *
1175 * 169 7/31/98 11:51a Jason
1176 * added player ship choosing to multiplayer games
1177 *
1178 * 168 7/30/98 11:09a Jason
1179 * took out warp effect
1180 *
1181 * 167 7/29/98 6:40p Jason
1182 * fixed on/off problem
1183 *
1184 * 166 7/29/98 5:47p Jason
1185 * added warp effect again
1186 *
1187 * 165 7/29/98 5:39p Kevin
1188 * sound/bitmap exchange
1189 *
1190 * 164 7/29/98 2:29p Jason
1191 * got rid of some compiler warnings
1192 *
1193 * 163 7/29/98 2:02p Jason
1194 * implemented multiplayer positional flags to help trim bandwidth
1195 * consumption
1196 *
1197 * 162 7/29/98 12:40p Jason
1198 * more multiplayer testing for occlusion and packet sequencing
1199 *
1200 * 161 7/28/98 3:42p Jason
1201 * added positional sequencing back in
1202 *
1203 * 160 7/28/98 12:43p Jason
1204 * trying a multiplayer experiment with a compressed orientation matrix
1205 *
1206 *
1207 * 159 7/28/98 12:29p Jason
1208 * added rotational velocity to multiplayer position packets
1209 *
1210 * 158 7/27/98 5:59p Jason
1211 * added piggyback mode plus multiplayer colors
1212 *
1213 * 157 7/27/98 5:31p Kevin
1214 * Sound/Bitmap exchange system
1215 *
1216 * 156 7/24/98 4:44p Jason
1217 * added temporary multi_occluded variable
1218 *
1219 * 155 7/23/98 12:38p Jason
1220 * more tweaks for multiplayer vis stuff
1221 *
1222 * 154 7/22/98 3:16p Jason
1223 * added observer mode
1224 *
1225 * 153 7/21/98 2:59p Kevin
1226 * peer-peer fire packets
1227 *
1228 * 152 7/21/98 1:49p Kevin
1229 * IPX support and peer-peer option for multi
1230 *
1231 * 151 7/21/98 12:07p Jason
1232 * made multiplayer work with BOA vis system
1233 *
1234 * 150 7/21/98 10:27a Kevin
1235 * peer-peer fixes
1236 *
1237 * 149 7/20/98 7:23p Jeff
1238 * fixed peer-peer/client server booboo
1239 *
1240 * 148 7/20/98 6:39p Jason
1241 * first attempt at getting player visibilty stuff working in multiplayer
1242 *
1243 * 147 7/20/98 6:20p Kevin
1244 * peer-peer stuff
1245 *
1246 * 146 7/17/98 5:57p Jason
1247 * misc multiplayer changes
1248 *
1249 * 145 7/17/98 2:50p Jason
1250 * a couple fixes for multiplayer bugs
1251 *
1252 * 144 7/17/98 1:22p Kevin
1253 * Dynamic retransmission of reliable packets and stuff
1254 *
1255 * 143 7/15/98 1:22p Kevin
1256 * Updated player network address for clients
1257 *
1258 * 142 7/15/98 12:48p Jeff
1259 * sending client execute DLLs now allows a dllinfo struct to be passed
1260 *
1261 * 141 7/15/98 12:27p Kevin
1262 * Fixed bug in execscriptwithparms and references
1263 *
1264 * 140 7/15/98 11:21a Kevin
1265 * Added doors to the server object list
1266 *
1267 * 139 7/15/98 10:38a Kevin
1268 * Fixes erroneous debug warning in multidomsgwithparms
1269 *
1270 * 138 7/14/98 5:52p Kevin
1271 * Packet loss measurements and auto pps adjusting
1272 *
1273 * 137 7/13/98 11:52a Kevin
1274 * Added Callscriptwithparms
1275 *
1276 * 136 7/10/98 10:29a Kevin
1277 * Added parent handle to sendobj
1278 *
1279 * 135 7/09/98 4:50p Kevin
1280 * added render type to multisendobj
1281 *
1282 * 134 7/09/98 3:26p Jason
1283 * fixed scripting name bug
1284 *
1285 * 133 7/08/98 6:01p Jeff
1286 * added packet to remove an item from inventory
1287 *
1288 * 132 7/08/98 5:31p Kevin
1289 * Coop fixes
1290 *
1291 * 131 7/08/98 11:35a Kevin
1292 * weapon battery info
1293 *
1294 * 130 7/08/98 11:27a Jeff
1295 * removed yesterdays inventory functions, since inventory.cpp has been
1296 * rolled back...its outdated now
1297 *
1298 * 129 7/07/98 7:33p Jeff
1299 * changes made for inventory use
1300 *
1301 * 128 7/07/98 6:31p Jason
1302 * fixed jeffery thang
1303 *
1304 * 127 7/07/98 3:46p Kevin
1305 * Turrett info
1306 *
1307 * 126 7/07/98 3:26p Chris
1308 * Added changes for turret updates
1309 *
1310 * 125 7/07/98 3:16p Kevin
1311 * Added inventory parms
1312 *
1313 * 124 7/07/98 2:48p Kevin
1314 * added support for custom scripts in multisendobject
1315 *
1316 * 123 7/07/98 11:19a Kevin
1317 * Added inventory use message
1318 *
1319 * 122 7/07/98 10:10a Kevin
1320 * Added basic turret support for coop
1321 *
1322 * 121 7/06/98 6:46p Kevin
1323 * vector parameter passing in scripts
1324 *
1325 * 120 7/06/98 5:36p Kevin
1326 * Variable parameter passing
1327 *
1328 * 119 7/06/98 11:51a Jason
1329 * added accessor function for countermeasures
1330 *
1331 * 118 7/06/98 9:34a Kevin
1332 * coop
1333 *
1334 * 117 7/02/98 4:52p Kevin
1335 * coop fixes
1336 *
1337 * 116 7/02/98 12:57p Jason
1338 * various changes for multiplayer positional sequencing
1339 *
1340 * 115 7/02/98 12:19p Kevin
1341 * misc network fixes
1342 *
1343 * 114 7/02/98 10:39a Kevin
1344 * More coop stuff
1345 *
1346 * 113 7/01/98 6:30p Kevin
1347 * More coop
1348 *
1349 * 112 7/01/98 2:52p Kevin
1350 * coop -- adding sound index
1351 *
1352 * 111 7/01/98 12:55p Jason
1353 * more changes for countermeasures
1354 *
1355 * 110 7/01/98 12:46p Kevin
1356 * Coop fixes
1357 *
1358 * 109 7/01/98 12:11p Jason
1359 * added countermeasures
1360 *
1361 * 108 6/30/98 7:17p Kevin
1362 * more animation stuff
1363 *
1364 * 107 6/30/98 5:54p Kevin
1365 * Animation frame stuff
1366 *
1367 * 106 6/30/98 5:08p Kevin
1368 * coop animation frame stuff
1369 *
1370 * 105 6/30/98 4:28p Chris
1371 * Checked in some missing commas
1372 *
1373 * 104 6/30/98 3:55p Chris
1374 *
1375 * 103 6/30/98 3:22p Kevin
1376 * Improved game ping time
1377 *
1378 * 102 6/30/98 11:39a Jason
1379 * added AdditionalDamage packet type for multiplayer
1380 *
1381 * 101 6/30/98 10:10a Kevin
1382 * Fix to prevent your old games from showing up in game list
1383 *
1384 * 100 6/29/98 5:53p Kevin
1385 * Coop
1386 *
1387 * 99 6/29/98 3:08p Jason
1388 * added on/off weapons
1389 *
1390 * 98 6/29/98 12:49p Jason
1391 * temp checkin for on/off weapons
1392 *
1393 * 97 6/29/98 12:12p Kevin
1394 * Added robot damage and death packets
1395 *
1396 * 96 6/26/98 6:53p Kevin
1397 * Coop mode
1398 *
1399 * 95 6/26/98 6:20p Jason
1400 * changes for coop
1401 *
1402 * 94 6/25/98 5:22p Kevin
1403 * Req/Send gametime to clients
1404 *
1405 * 93 6/25/98 12:32p Jason
1406 * added new multiplayer functionality
1407 *
1408 * 92 6/24/98 3:24p Kevin
1409 * Updated PXO screens with chat, etc.
1410 *
1411 * 91 6/18/98 4:49p Kevin
1412 * Updated multiplayer menus
1413 *
1414 * 90 6/16/98 10:54a Jeff
1415 *
1416 * 89 6/11/98 12:48p Jason
1417 * added better spewing weapons
1418 *
1419 * 88 6/10/98 7:32p Kevin
1420 * nw_CloseSocket wasn't being called in MultiDoLeaveGame
1421 *
1422 * 87 6/09/98 6:18p Jeff
1423 * added a call to the multiplayer DLL when level ends and when a player
1424 * leaves the game
1425 *
1426 * 86 6/04/98 4:53p Jeff
1427 * Online time is kept whether or not it's a mastertracker game now
1428 *
1429 * 85 6/01/98 10:09a Kevin
1430 * Added DLL connection interface and auto update DLL
1431 *
1432 * 84 5/25/98 6:38p Matt
1433 * Added needed include.
1434 *
1435 * 83 5/22/98 11:59a Chris
1436 * Fixed improper uses of FindSoundName and made the proper static sounds
1437 *
1438 * 82 5/19/98 6:27p Jason
1439 * put in urgent packets
1440 *
1441 * 81 5/14/98 6:17p Jason
1442 * more sequencing bugs squashed
1443 *
1444 * 80 5/14/98 5:27p Jason
1445 * fixed some more sequencing bugs
1446 *
1447 * 79 5/14/98 11:07a Kevin
1448 * Made gameover packet to the tracker reliable
1449 *
1450 * 78 5/13/98 4:06p Kevin
1451 * Added more mastertracker info
1452 *
1453 * 77 5/12/98 6:11p Kevin
1454 * Added mastertracker values
1455 *
1456 * 76 5/12/98 5:49p Jason
1457 * fixed some multiplayer bugs
1458 *
1459 * 75 5/12/98 5:12p Jason
1460 * added dll callable level ending
1461 *
1462 * 74 5/12/98 4:18p Jason
1463 * added better level sequencing for multiplayer
1464 *
1465 * 73 5/12/98 12:33p Jason
1466 * got level sequencing working in multiplayer
1467 *
1468 * 72 5/11/98 4:40p Chris
1469 * AI info is now a malloc'ed pointer
1470 *
1471 * 71 5/11/98 11:31a Jason
1472 * added some events for level sequencing
1473 *
1474 * 70 5/08/98 6:23p Jason
1475 * tweaked player positioning
1476 *
1477 * 69 5/07/98 5:08p Jason
1478 * added better movement interpolation
1479 *
1480 * 68 5/05/98 3:02p Jason
1481 * attempting to add different screen resolutions
1482 *
1483 * 67 5/04/98 4:04p Chris
1484 * Minestone checkin' -- energy effect and more AI functionality
1485 *
1486 * 66 5/04/98 12:48p Jason
1487 * fixed goalface problem
1488 *
1489 * 65 5/04/98 10:55a Kevin
1490 * Mastertracker fixes/enhancements
1491 *
1492 * 64 5/02/98 5:14p Kevin
1493 * Made mastertracker games not show up on the lan search
1494 *
1495 * 63 4/30/98 3:49p Kevin
1496 * Mastertracker pilot stats
1497 *
1498 * 62 4/27/98 1:14p Jason
1499 * cleaned up afterburner stuff
1500 *
1501 * 61 4/24/98 3:50p Kevin
1502 * Added mastertracker game tracking support
1503 *
1504 * 60 4/22/98 3:39p Jason
1505 * trimmed some fat off player packets
1506 *
1507 * 59 4/22/98 3:29p Jason
1508 * reset player ship when entering a game
1509 *
1510 * 58 4/22/98 3:25p Jason
1511 * changes for multiplayer debugging
1512 *
1513 * 57 4/20/98 12:46p Jason
1514 * added level checksumming for multiplayer games
1515 *
1516 * 56 4/20/98 11:30a Jason
1517 * Added ShowProgressScreen function
1518 *
1519 * 55 4/19/98 3:21p Jason
1520 * added the transmission of teams when a player connects
1521 *
1522 * 54 4/17/98 1:59p Jason
1523 * added cool object effects
1524 *
1525 * 53 4/17/98 12:45p Jason
1526 * various changes for multiplayer
1527 *
1528 * 52 4/14/98 7:56p Matt
1529 * Moved MSN_NAMELEN from mission.h to descent,h, so multi.h didn't need
1530 * to include mission.h.
1531 *
1532 * 51 4/10/98 3:28p Jason
1533 * fixed afterburner bug
1534 *
1535 * 50 4/10/98 2:58p Chris
1536 * Redid where the buddy gets allocated, not all the way done yet.
1537 *
1538 * 49 4/10/98 2:16p Jason
1539 * fixed guided missile problems
1540 *
1541 * 48 4/09/98 5:17p Jason
1542 * got guided working in multiplayer
1543 *
1544 * 47 4/09/98 2:23p Jason
1545 * added guided/afterburner stuff
1546 *
1547 * 46 4/07/98 4:25p Chris
1548 * Added support for buddy bot
1549 *
1550 * 45 4/07/98 12:54p Jason
1551 * changes for viseffects and multiplayer dll
1552 *
1553 * 44 4/06/98 5:56p Jason
1554 * got multiplayer options working
1555 *
1556 * 43 4/06/98 2:54p Jason
1557 * yet more multiplayer changes
1558 *
1559 * 42 4/06/98 12:14p Jason
1560 * changes to multiplayer
1561 *
1562 * 41 4/03/98 4:08p Jason
1563 * fixed checksum bugs
1564 *
1565 * 40 4/03/98 12:28p Jason
1566 * fixed confusion with clients changing rooms in multiplayer
1567 *
1568 * 39 4/03/98 12:22p Jeff
1569 * fixed bug in change room event
1570 *
1571 * 38 4/03/98 11:04a Jason
1572 * added a multplayer dll hook for when a player changes a room
1573 *
1574 * 37 4/02/98 12:43p Jason
1575 * added functions to remove an object
1576 *
1577 * 36 4/01/98 6:23p Jason
1578 * added a slew of stuff for multiplayer
1579 *
1580 * 35 4/01/98 12:02p Jason
1581 * incremental checkin for rendering changes
1582 *
1583 * 34 3/30/98 5:11p Jason
1584 * more changes for game/dll integration
1585 *
1586 * 33 3/23/98 7:37p Jason
1587 * added colored hud messages
1588 *
1589 * 32 3/23/98 4:51p Jason
1590 * incremental checkin for multiplay
1591 *
1592 * 31 3/20/98 5:51p Jason
1593 * more changes for multiplayer
1594 *
1595 * 30 3/20/98 2:18p Jason
1596 * changes for multiplayer
1597 *
1598 * 29 3/19/98 7:14p Jason
1599 * more changes for multiplayer
1600 *
1601 * 28 3/18/98 5:45p Jason
1602 * more multiplayer script integration
1603 *
1604 * 27 3/18/98 11:08a Jason
1605 * more changes for script and multiplayer
1606 *
1607 * 26 3/17/98 6:17p Jason
1608 * added gamemode collide stuff
1609 *
1610 * 25 3/17/98 6:00p Jason
1611 * changes for gamemode scripts
1612 *
1613 * 24 3/16/98 6:41p Jason
1614 * added user definable messages to multiplayer
1615 *
1616 * 23 3/16/98 11:19a Jason
1617 * got scripts working with multiplayer
1618 *
1619 * 22 2/26/98 4:18p Jason
1620 * fixed player death problem for incoming players
1621 *
1622 * 21 2/18/98 1:52p Jason
1623 * made velocity a 6 byte packet
1624 *
1625 * 20 2/17/98 3:46p Matt
1626 * Revamped weapon system and got sounds for spray and fusion weapons
1627 * working. Still need to implements getting continuous & cutoff sounds
1628 * from player ship.
1629 *
1630 * 19 2/08/98 5:01p Samir
1631 * New game sequencing changes.
1632 *
1633 * 18 2/05/98 2:59p Matt
1634 * Got rid of MultiObjSetPos(). Now just using ObjSetPos()
1635 *
1636 * 17 2/05/98 11:47a Jason
1637 * changes for new roomnum system
1638 *
1639 * 16 2/04/98 6:09p Matt
1640 * Changed object room number to indicate a terrain cell via a flag. Got
1641 * rid of the object flag which used to indicate terrain.
1642 *
1643 */
1644
1645 #include "pstypes.h"
1646 #include "pserror.h"
1647 #include "player.h"
1648 #include "game.h"
1649 #include "multi.h"
1650 #include "multi_client.h"
1651 #include "multi_server.h"
1652 #include "ddio.h"
1653 #include "hud.h"
1654 #include "robotfire.h"
1655 #include "ship.h"
1656 #include "descent.h"
1657 #include "damage.h"
1658 #include "gamesequence.h"
1659 #include "objinfo.h"
1660 #include "gametexture.h"
1661 #include "room.h"
1662 #include "game2dll.h"
1663 #include "viseffect.h"
1664 #include "hlsoundlib.h"
1665 #include "soundload.h"
1666 #include "fireball.h"
1667 #include "Mission.h"
1668 #include "LoadLevel.h"
1669 #include "gamecinematics.h"
1670 #include "init.h"
1671
1672 #include "sounds.h"
1673 #include "weapon.h"
1674 #include "stringtable.h"
1675
1676 #include "dedicated_server.h"
1677 #include "demofile.h"
1678 #include "args.h"
1679
1680 #include "ui.h"
1681 #include "newui.h"
1682 #include "multi_dll_mgr.h"
1683 #include "BOA.h"
1684 #include "attach.h"
1685 #include "mission_download.h"
1686 // #include "gamespy.h"
1687 #include "multi_world_state.h"
1688 #include "ObjScript.h"
1689 #include "audiotaunts.h"
1690 #include "marker.h"
1691 #include "weather.h"
1692 #include "doorway.h"
1693 #include "object_lighting.h"
1694 #include "spew.h"
1695 #include "physics.h"
1696 #include "SmallViews.h"
1697 #include "demofile.h"
1698 #include "debuggraph.h"
1699 #include "levelgoal.h"
1700 #include "osiris_share.h"
1701 #include "cockpit.h"
1702 #include "hud.h"
1703
1704 #include <string.h>
1705 #include <memory.h>
1706 #include <stdlib.h>
1707
1708 #include "psrand.h"
1709
1710 #include "../md5/md5.h"
1711 void MultiProcessShipChecksum(MD5 *md5, int ship_index);
1712
1713
1714 #include <algorithm>
1715
1716 player_pos_suppress Player_pos_fix[MAX_PLAYERS];
1717
1718 // Define this if you want to have secondaries be sent as reliable packets
1719 //(not recommended - talk to Jason)
1720 // #define RELIABLE_SECONDARIES
1721
1722 // If this is true, PXO games won't save the kills, deaths, etc.
1723 bool Multi_no_stats_saved = false;
1724
1725 uint32_t Netgame_curr_handle = 1;
1726
1727 uint16_t Local_object_list[MAX_OBJECTS];
1728 uint16_t Server_object_list[MAX_OBJECTS];
1729 uint16_t Server_spew_list[MAX_SPEW_EFFECTS];
1730
1731 #ifndef RELEASE
1732 int Multi_packet_tracking[255];
1733 #endif
1734
1735 // This is for clearing lightmapped objects on the client/server
1736 int Num_client_lm_objects, Num_server_lm_objects;
1737 uint16_t Client_lightmap_list[MAX_OBJECTS], Server_lightmap_list[MAX_OBJECTS];
1738
1739 // This is for breakable glass
1740 uint16_t Broke_glass_rooms[MAX_BROKE_GLASS], Broke_glass_faces[MAX_BROKE_GLASS];
1741 int Num_broke_glass = 0;
1742
1743 // This is for getting out a menu if in multiplayer
1744 bool Multi_bail_ui_menu = false;
1745
1746 uint32_t Multi_generic_match_table[MAX_OBJECT_IDS];
1747 uint32_t Multi_weapon_match_table[MAX_WEAPONS];
1748 uint8_t Multi_receive_buffer[MAX_RECEIVE_SIZE];
1749
1750 uint8_t Multi_send_buffer[MAX_NET_PLAYERS][MAX_GAME_DATA_SIZE];
1751 int Multi_send_size[MAX_NET_PLAYERS];
1752
1753 player_fire_packet Player_fire_packet[MAX_NET_PLAYERS];
1754 float Multi_last_sent_time[MAX_NET_PLAYERS][MAX_NET_PLAYERS];
1755
1756 uint8_t Multi_reliable_send_buffer[MAX_NET_PLAYERS][MAX_GAME_DATA_SIZE];
1757 int Multi_reliable_send_size[MAX_NET_PLAYERS];
1758 float Multi_reliable_last_send_time[MAX_NET_PLAYERS];
1759 uint8_t Multi_reliable_sent_position[MAX_NET_PLAYERS];
1760 uint8_t Multi_reliable_urgent[MAX_NET_PLAYERS];
1761
1762 // For keeping track of buildings that have changed
1763 uint8_t Multi_building_states[MAX_OBJECTS];
1764 uint16_t Multi_num_buildings_changed = 0;
1765
1766 // For keeping track of powerup respawn points
1767 powerup_respawn Powerup_respawn[MAX_RESPAWNS];
1768 powerup_timer Powerup_timer[MAX_RESPAWNS];
1769
1770 // For keeping track of damage and shields
1771 int Multi_additional_damage_type[MAX_PLAYERS];
1772 float Multi_additional_damage[MAX_PLAYERS];
1773 int Multi_requested_damage_type = PD_NONE;
1774 float Multi_requested_damage_amount = 0;
1775 float Multi_additional_shields[MAX_SHIELD_REQUEST_TYPES];
1776
1777 int Num_powerup_respawn = 0;
1778 int Num_powerup_timer = 0;
1779
1780 // For level sequencing
1781 int Multi_next_level = -1;
1782
1783 netplayer NetPlayers[MAX_NET_PLAYERS];
1784 netgame_info Netgame;
1785
1786 int Num_network_games_known = 0;
1787 network_game Network_games[MAX_NETWORK_GAMES];
1788
1789 int Game_is_master_tracker_game = 0;
1790
1791 char Tracker_id[TRACKER_ID_LEN];
1792
1793 vmt_descent3_struct MTPilotinfo[MAX_NET_PLAYERS];
1794
1795 int16_t Multi_kills[MAX_NET_PLAYERS];
1796 int16_t Multi_deaths[MAX_NET_PLAYERS];
1797
1798 int Got_new_game_time = 0;
1799
1800 #define MAX_COOP_TURRETS 400
1801 float turret_holder[MAX_COOP_TURRETS];
1802
1803 #define DATA_CHUNK_SIZE 450
1804
1805 int Bandwidth_throttle = 0;
1806
1807 int Use_file_xfer = 1;
1808
1809 int Reliable_count = 0;
1810 int Last_reliable_count = 0;
1811
1812 float Time_last_taunt_request = 0.0f;
1813
1814 // Display logos or not?
1815 bool Multi_logo_state = true;
1816
1817 bool Multi_Expect_demo_object_flags = false;
1818
1819 // Heartbeat flag
1820 bool Got_heartbeat = false;
1821
1822 // Message of the day
1823 char Multi_message_of_the_day[HUD_MESSAGE_LENGTH * 2] = {0};
1824
1825 // Local function prototypes
1826 void SendDataChunk(int playernum);
1827 void DenyFile(int playernum, int filenum, int file_who);
1828 void MultiDoFileCancelled(uint8_t *data);
1829 void MultiDoCustomPlayerData(uint8_t *data);
1830 char *GetFileNameFromPlayerAndID(int16_t playernum, int16_t id);
1831
1832 // Multiplayer position flags
1833 #define MPF_AFTERBURNER 1 // Afterburner is on
1834 #define MPF_OUTSIDE 2 // Player is outside
1835 #define MPF_DEAD 4 // Player is dead
1836 #define MPF_FIRED 8 // Player fired
1837 #define MPF_SPRAY 16 // Player is using a spray weapon
1838 #define MPF_ON_OFF 32 // Player is using an on/off weapon
1839 #define MPF_HEADLIGHT 64 // Headlight is on for this player
1840 #define MPF_THRUSTED 128 // Player thrusted this frame
1841
1842 #define MULTI_ASSERT(x, m) \
1843 { \
1844 if ((x) == 0) { \
1845 BailOnMultiplayer((m)); \
1846 return; \
1847 } \
1848 }
1849 #define MULTI_ASSERT_NOMESSAGE(x) \
1850 { \
1851 if ((x) == 0) { \
1852 BailOnMultiplayer(NULL); \
1853 return; \
1854 } \
1855 }
1856
1857 // Gets us out of a multiplayer game in a hurry...useful for when things are screwed
1858 void BailOnMultiplayer(const char *message) {
1859 Int3(); // Get Jason
1860
1861 // Show message
1862 if (message == NULL)
1863 ShowProgressScreen(TXT_MULTI_DATACORRUPT);
1864 else
1865 ShowProgressScreen(message);
1866
1867 MultiLeaveGame();
1868 Sleep(2000);
1869 }
1870
1871 // Adds the trunctuated position data to an outgoing packet
1872 void MultiAddPositionData(vector *pos, uint8_t *data, int *count) {
1873 MultiAddUshort((pos->x * 16.0), data, count);
1874 MultiAddUshort((pos->z * 16.0), data, count);
1875 MultiAddFloat(pos->y, data, count);
1876 }
1877 void MultiExtractPositionData(vector *vec, uint8_t *data, int *count) {
1878 vec->x = ((float)MultiGetUshort(data, count)) / 16.0;
1879 vec->z = ((float)MultiGetUshort(data, count)) / 16.0;
1880 vec->y = MultiGetFloat(data, count);
1881 }
1882
1883 void MultiSendBadChecksum(int slot) {
1884 uint8_t data[MAX_GAME_DATA_SIZE];
1885 int size;
1886 int count = 0;
1887 size = START_DATA(MP_REJECTED_CHECKSUM, data, &count);
1888 END_DATA(count, data, size);
1889 nw_SendReliable(NetPlayers[slot].reliable_socket, data, count);
1890 }
1891
1892 // Puts player "slot" position info into the passed in buffer
1893 // Returns the number of bytes used
1894 int MultiStuffPosition(int slot, uint8_t *data) {
1895 int size;
1896 int count = 0;
1897 uint8_t flags = 0;
1898
1899 object *obj = &Objects[Players[slot].objnum];
1900
1901 size = START_DATA(MP_PLAYER_POS, data, &count);
1902 MultiAddByte(slot, data, &count);
1903
1904 if (slot == Player_num) {
1905 // tell the reciever to expect fire information, only if
1906 // we fired this frame and it isn't going to be a seperate packet
1907 // (like secondaries in a non-peer to peer, are sent reliably)
1908 if (Player_fire_packet[slot].fired_on_this_frame == PFP_FIRED)
1909 flags |= MPF_FIRED;
1910 }
1911
1912 // Send timestamp
1913 if (slot == Player_num)
1914 MultiAddFloat(Gametime, data, &count);
1915 else
1916 MultiAddFloat(NetPlayers[slot].packet_time, data, &count);
1917
1918 // Do position
1919 MultiAddPositionData(&obj->pos, data, &count);
1920
1921 // Do orientation
1922 angvec angs;
1923 vm_ExtractAnglesFromMatrix(&angs, &obj->orient);
1924
1925 MultiAddShort(angs.p, data, &count);
1926 MultiAddShort(angs.h, data, &count);
1927 MultiAddShort(angs.b, data, &count);
1928
1929 // Do roomnumber and terrain flag
1930
1931 MultiAddShort(CELLNUM(obj->roomnum), data, &count);
1932
1933 // Fill flags
1934 if (OBJECT_OUTSIDE(obj))
1935 flags |= MPF_OUTSIDE;
1936 if (Players[slot].flags & PLAYER_FLAGS_AFTERBURN_ON)
1937 flags |= MPF_AFTERBURNER;
1938 if (Players[slot].flags & PLAYER_FLAGS_THRUSTED)
1939 flags |= MPF_THRUSTED;
1940 if (Objects[Players[slot].objnum].weapon_fire_flags & WFF_SPRAY)
1941 flags |= MPF_SPRAY;
1942 if (Objects[Players[slot].objnum].weapon_fire_flags & WFF_ON_OFF)
1943 flags |= MPF_ON_OFF;
1944 if (Players[slot].flags & PLAYER_FLAGS_DEAD) // || Players[slot].flags & PLAYER_FLAGS_DYING)
1945 flags |= MPF_DEAD;
1946 if (Players[slot].flags & PLAYER_FLAGS_HEADLIGHT)
1947 flags |= MPF_HEADLIGHT;
1948
1949 // Do velocity
1950 vector *vel = &obj->mtype.phys_info.velocity;
1951 vector *rotvel = &obj->mtype.phys_info.rotvel;
1952
1953 // mprintf(0,"Outvel x=%f y=%f z=%f\n",vel->x,vel->y,vel->z);
1954
1955 MultiAddShort((vel->x * 128.0), data, &count);
1956 MultiAddShort((vel->y * 128.0), data, &count);
1957 MultiAddShort((vel->z * 128.0), data, &count);
1958
1959 if (Netgame.flags & NF_SENDROTVEL) {
1960 MultiAddShort(rotvel->x / 4, data, &count);
1961 MultiAddShort(rotvel->y / 4, data, &count);
1962 MultiAddShort(rotvel->z / 4, data, &count);
1963
1964 MultiAddShort(obj->mtype.phys_info.turnroll, data, &count);
1965 }
1966
1967 int weapon_indices = ((Players[slot].weapon[PW_SECONDARY].index - 10) << 4) | Players[slot].weapon[PW_PRIMARY].index;
1968 MultiAddByte(weapon_indices, data, &count);
1969
1970 MultiAddUbyte(Players[slot].energy, data, &count);
1971 MultiAddByte(flags, data, &count);
1972
1973 END_DATA(count, data, size);
1974
1975 return count;
1976 }
1977
1978 void DoNextPlayerFile(int playernum) {
1979 NetPlayers[playernum].file_xfer_flags = NETFILE_NONE;
1980 NetPlayers[playernum].custom_file_seq++;
1981 if (NetPlayers[playernum].custom_file_seq > NETFILE_ID_LAST_FILE) {
1982 NetPlayers[playernum].custom_file_seq = NETFILE_ID_DONE;
1983 mprintf(0, "Setting %s's custom ship logo to %s\n", Players[playernum].callsign, NetPlayers[playernum].ship_logo);
1984 PlayerSetCustomTexture(playernum, NetPlayers[playernum].ship_logo);
1985 // If we are the server, we need to tell everyone about this guy's custom data
1986 if ((Netgame.local_role == LR_SERVER) && (Use_file_xfer)) {
1987 for (int i = 0; i < MAX_PLAYERS; i++) {
1988 // Send custom ship info if we have it
1989 if ((NetPlayers[i].custom_file_seq == NETFILE_ID_DONE) || (i == Player_num)) {
1990 MultiSendClientCustomData(i, playernum);
1991 }
1992 }
1993 MultiSendClientCustomData(playernum);
1994 }
1995 }
1996 }
1997
1998 // Puts player "slot" position info into the passed in buffer
1999 // Returns the number of bytes used
2000 int MultiStuffRobotPosition(uint16_t objectnum, uint8_t *data) {
2001 int size;
2002 int count = 0;
2003 //@@multi_orientation mat;
2004
2005 // mprintf(0,"!");//KBTEST
2006 object *obj = &Objects[objectnum];
2007
2008 ASSERT(obj->flags & OF_CLIENT_KNOWS);
2009
2010 size = START_DATA(MP_ROBOT_POS, data, &count);
2011 MultiAddUshort(objectnum, data, &count);
2012
2013 // Do position
2014 MultiAddPositionData(&obj->pos, data, &count);
2015
2016 // Do orientation
2017
2018 // Do orientation
2019 angvec angs;
2020 vm_ExtractAnglesFromMatrix(&angs, &obj->orient);
2021
2022 MultiAddShort(angs.p, data, &count);
2023 MultiAddShort(angs.h, data, &count);
2024 MultiAddShort(angs.b, data, &count);
2025
2026 // Do roomnumber and terrain flag
2027
2028 MultiAddShort(CELLNUM(obj->roomnum), data, &count);
2029
2030 if (OBJECT_OUTSIDE(obj))
2031 MultiAddByte(1, data, &count);
2032 else
2033 MultiAddByte(0, data, &count);
2034
2035 vector *vel = &obj->mtype.phys_info.velocity;
2036 vector *rotvel = &obj->mtype.phys_info.rotvel;
2037
2038 MultiAddShort((vel->x * 128.0), data, &count);
2039 MultiAddShort((vel->y * 128.0), data, &count);
2040 MultiAddShort((vel->z * 128.0), data, &count);
2041
2042 END_DATA(count, data, size);
2043 return count;
2044 }
2045
2046 // Puts player "slot" position info into the passed in buffer
2047 // Returns the number of bytes used
2048 int MultiSendRobotFireWeapon(uint16_t objectnum, vector *pos, vector *dir, uint16_t weaponnum) {
2049 int size;
2050 int count = 0;
2051 uint8_t data[MAX_GAME_DATA_SIZE];
2052 // mprintf(0,"Sending Robot %d fired.\n",objectnum);
2053 // Check to make sure we're the server
2054 if (Netgame.local_role != LR_SERVER) {
2055 BailOnMultiplayer(NULL);
2056 return 0;
2057 }
2058
2059 // mprintf(0,"@");//KBTEST
2060 object *obj = &Objects[objectnum];
2061 ASSERT(obj->flags & OF_CLIENT_KNOWS);
2062
2063 size = START_DATA(MP_ROBOT_FIRE, data, &count);
2064 MultiAddUshort(objectnum, data, &count);
2065
2066 // Do position
2067 // memcpy (&data[count],pos,sizeof(vector));
2068 // count+=sizeof(vector);
2069 MultiAddVector(*pos, data, &count);
2070
2071 // Do orientation
2072 // memcpy (&data[count],dir,sizeof(vector));
2073 // count+=sizeof(vector);
2074 MultiAddVector(*dir, data, &count);
2075
2076 uint32_t index = MultiGetMatchChecksum(OBJ_WEAPON, weaponnum);
2077 MultiAddUint(index, data, &count);
2078
2079 END_DATA(count, data, size);
2080 // Add it to the outgoing queue. The MultiSendRobotFireSound() function will actually send it
2081 for (int i = 0; i < MAX_NET_PLAYERS; i++) {
2082 if (i == Player_num)
2083 continue;
2084
2085 if ((NetPlayers[i].flags & NPF_CONNECTED) && (NetPlayers[i].sequence == NETSEQ_PLAYING)) {
2086 if (Multi_send_size[i] + count >= MAX_GAME_DATA_SIZE)
2087 MultiSendFullPacket(i, 0);
2088
2089 memcpy(&Multi_send_buffer[i][Multi_send_size[i]], data, count);
2090 Multi_send_size[i] += count;
2091 // Don't send because we are waiting for the robot fire sound to send
2092 }
2093 }
2094 return count;
2095 }
2096
2097 void MultiDoRobotFire(uint8_t *data) {
2098 int count = 0;
2099 uint16_t obj_num;
2100 vector weapon_pos;
2101 vector weapon_dir;
2102 uint32_t weapon_num;
2103 uint32_t uniqueid;
2104
2105 if (Netgame.local_role == LR_SERVER) {
2106 Int3(); // Get Jason, a server got the multi do fire packet
2107 return;
2108 }
2109
2110 // mprintf(0,"*");
2111 SKIP_HEADER(data, &count);
2112 int serv_objnum = MultiGetUshort(data, &count);
2113 obj_num = Server_object_list[serv_objnum];
2114
2115 if (obj_num == 65535 || !(Objects[obj_num].flags & OF_SERVER_OBJECT)) {
2116 // Int3(); // Get Jason, invalid robot firing!
2117 return;
2118 }
2119
2120 // memcpy (&weapon_pos,&data[count],sizeof(vector));
2121 // count+=sizeof(vector);
2122 weapon_pos = MultiGetVector(data, &count);
2123 // memcpy (&weapon_dir,&data[count],sizeof(vector));
2124 // count+=sizeof(vector);
2125 weapon_dir = MultiGetVector(data, &count);
2126
2127 weapon_num = MultiGetUint(data, &count);
2128
2129 if (Objects[obj_num].type == 255)
2130 return;
2131 uniqueid = MultiMatchWeapon(weapon_num);
2132
2133 CreateAndFireWeapon(&weapon_pos, &weapon_dir, &Objects[obj_num], uniqueid);
2134 }
2135
2136 // Does a cool vis effect to announce a player or powerup
2137 void MultiAnnounceEffect(object *obj, float size, float time) {
2138 int visnum = VisEffectCreate(VIS_FIREBALL, BLAST_RING_INDEX, obj->roomnum, &obj->pos);
2139 if (visnum >= 0) {
2140 vector norm = {0, 1, 0};
2141 vis_effect *vis = &VisEffects[visnum];
2142 vis->size = size;
2143 vis->lifetime = time;
2144 vis->lifeleft = time;
2145 vis->custom_handle = Fireballs[BLUE_BLAST_RING_INDEX].bm_handle;
2146 vis->flags |= VF_PLANAR | VF_REVERSE;
2147 vis->end_pos = norm;
2148 }
2149 }
2150
2151 // MultiProcessIncoming reads incoming data off the unreliable and reliable ports and sends
2152 // the data to process_big_data
2153 void MultiProcessIncoming() {
2154 int size, i;
2155 uint8_t *data;
2156 network_address from_addr;
2157
2158 data = &(Multi_receive_buffer[0]);
2159
2160 // get the other net players data
2161 while ((size = nw_Receive(data, &from_addr)) > 0) {
2162 MultiProcessBigData(data, size, &from_addr);
2163 if (ServerTimeout) {
2164 LastPacketReceived = timer_GetTime();
2165 }
2166 } // end while
2167
2168 // read reliable sockets for data
2169 data = &(Multi_receive_buffer[0]);
2170 if (Netgame.local_role == LR_SERVER) {
2171 for (i = 0; i < MAX_NET_PLAYERS; i++) {
2172 if (Player_num == i)
2173 continue;
2174
2175 if ((NetPlayers[i].flags & NPF_CONNECTED) && (NetPlayers[i].reliable_socket != INVALID_SOCKET) &&
2176 (NetPlayers[i].reliable_socket != 0)) {
2177
2178 while ((size = nw_ReceiveReliable(NetPlayers[i].reliable_socket, data, MAX_RECEIVE_SIZE)) > 0) {
2179 MultiProcessBigData(data, size, &NetPlayers[i].addr);
2180 }
2181 }
2182 }
2183 } else {
2184 // if I'm not the master of the game, read reliable data from my connection with the server
2185 if ((NetPlayers[Player_num].reliable_socket != INVALID_SOCKET) && (NetPlayers[Player_num].reliable_socket != 0)) {
2186 while ((size = nw_ReceiveReliable(NetPlayers[Player_num].reliable_socket, data, MAX_RECEIVE_SIZE)) > 0) {
2187 MultiProcessBigData(data, size, &Netgame.server_address);
2188 }
2189 }
2190 }
2191 }
2192
2193 // Starts a packet of data
2194 int START_DATA(int type, uint8_t *data, int *count, uint8_t reliable) {
2195 int size_offset;
2196
2197 MultiAddByte(type, data, count);
2198
2199 // Do size
2200 size_offset = *count;
2201 MultiAddShort(0, data, count);
2202
2203 /*
2204 #ifndef RELEASE
2205
2206 if (Netgame.local_role==LR_SERVER)
2207 {
2208 MultiAddByte (reliable,data,count);
2209 if (reliable)
2210 {
2211 MultiAddInt (Reliable_count,data,count);
2212 Reliable_count++;
2213 }
2214 }
2215 else
2216 MultiAddByte (0,data,count);
2217
2218 #endif
2219 */
2220 return size_offset;
2221 }
2222
2223 // End a pakcet of data
2224 void END_DATA(int count, uint8_t *data, int offset) { MultiAddShort(count, data, &offset); }
2225
2226 // Skips the header stuff at the beginning of a packet
2227 void SKIP_HEADER(uint8_t *data, int *count) {
2228 MultiGetByte(data, count);
2229 MultiGetShort(data, count);
2230 }
2231
2232 // called once a frame on client and server. NOTE: only servers (game masters) check for
2233 // listen connections.
2234 void MultiDoFrame() {
2235 if (!(Game_mode & GM_MULTI))
2236 return;
2237
2238 ScoreAPIFrameInterval();
2239
2240 static int debug_id = -2;
2241 static float last_game_time = 99999999.9f;
2242
2243 CallGameDLL(EVT_GAME_INTERVAL, &DLLInfo);
2244
2245 if (Netgame.local_role == LR_SERVER)
2246 MultiDoServerFrame();
2247 else {
2248 if (debug_id == -2) {
2249 debug_id = DebugGraph_Add(0.0f, 10000.0f, "Ping", DGF_MULTIPLAYER);
2250 }
2251 if (debug_id >= 0) {
2252 if (last_game_time > Gametime) {
2253 // reset last_game_time, we must have started a new level
2254 last_game_time = Gametime;
2255 }
2256
2257 float next_time = last_game_time + 0.3f; // update every 1/3 second
2258 if (Gametime >= next_time) {
2259 last_game_time = Gametime;
2260 if (NetPlayers[Player_num].flags & NPF_CONNECTED && NetPlayers[Player_num].sequence == NETSEQ_PLAYING) {
2261 DebugGraph_Update(debug_id, NetPlayers[Player_num].ping_time * 1000.0f);
2262 }
2263 }
2264 }
2265
2266 MultiDoClientFrame();
2267 // Verify object list
2268 }
2269 }
2270
2271 // Returns to the slot number of the player that the passed in address belongs to
2272 int MultiMatchPlayerToAddress(network_address *from_addr) {
2273 int i;
2274 for (i = 0; i < MAX_NET_PLAYERS; i++) {
2275 if (NetPlayers[i].flags & NPF_CONNECTED) {
2276 if (!(memcmp(from_addr, &NetPlayers[i].addr, sizeof(network_address))))
2277 return i;
2278 }
2279 }
2280 // mprintf(0,"Got a packet from unconnected player?!\n");
2281 return -1;
2282 }
2283
2284 // Gets info about a player
2285 // Server only
2286 extern int Buddy_handle[MAX_PLAYERS];
2287 bool AINotify(object *obj, uint8_t notify_type, void *info);
2288 void MultiDoMyInfo(uint8_t *data) {
2289 int count = 0;
2290 char ship_name[PAGENAME_LEN];
2291 int length;
2292
2293 // Skip header stuff
2294 SKIP_HEADER(data, &count);
2295
2296 uint8_t slot = MultiGetByte(data, &count);
2297 if (!(NetPlayers[slot].flags & NPF_CONNECTED)) {
2298 mprintf(1, "ERROR! We got a MY_INFO packet from a disconnected player!\n");
2299 Int3(); // Get Jason
2300 return;
2301 }
2302
2303 // Copy the name out
2304 uint8_t len = MultiGetByte(data, &count);
2305 if (len > CALLSIGN_LEN)
2306 length = CALLSIGN_LEN;
2307 else
2308 length = len;
2309
2310 memcpy(Players[slot].callsign, &data[count], length);
2311 count += len;
2312
2313 // Copy the ship name out
2314 len = MultiGetByte(data, &count);
2315 memcpy(ship_name, &data[count], len);
2316 count += len;
2317
2318 int ship_index = FindShipName(ship_name);
2319 if (ship_index < 0)
2320 ship_index = 0;
2321
2322 if (!PlayerIsShipAllowed(slot, ship_name)) {
2323 bool found_one = false;
2324 int i;
2325
2326 // Loop through ships, looking for one that's allowed
2327 for (i = 0; i < MAX_SHIPS && !found_one; i++) {
2328 if (Ships[i].used && PlayerIsShipAllowed(Player_num, i)) {
2329 Players[Player_num].ship_index = i;
2330 MultiBashPlayerShip(slot, Ships[i].name);
2331 found_one = true;
2332 }
2333 }
2334
2335 // We should have found one
2336 ASSERT(found_one == true);
2337 }
2338
2339 PlayerChangeShip(slot, ship_index);
2340
2341 Players[slot].time_in_game = timer_GetTime();
2342 if (Game_is_master_tracker_game) {
2343 uint32_t mt_sig;
2344
2345 Players[slot].kills = 0;
2346 Players[slot].deaths = 0;
2347 Players[slot].suicides = 0;
2348 Players[slot].lateral_thrust = 0;
2349 Players[slot].rotational_thrust = 0;
2350
2351 mt_sig = MultiGetUint(data, &count);
2352
2353 if (mt_sig != MASTER_TRACKER_SIG) {
2354 NetPlayers[slot].flags &= ~NPF_CONNECTED;
2355 mprintf(0, "Invalid master tracker signature! Someone tried to join a master tracker game through the local net screen!\n");
2356 }
2357 NetPlayers[slot].flags |= NPF_MT_READING_PILOT;
2358 len = MultiGetByte(data, &count);
2359 memcpy(Players[slot].tracker_id, &data[count], len);
2360 count += len;
2361 strcpy(MTPilotinfo[slot].tracker_id, Players[slot].tracker_id);
2362 strcpy(MTPilotinfo[slot].pilot_name, Players[slot].callsign);
2363 }
2364
2365 Multi_deaths[slot] = 0;
2366 Multi_kills[slot] = 0;
2367 // Request pilot info from the mastertracker
2368 int ser = 0;
2369 ser = MultiGetInt(data, &count);
2370 if (ser) {
2371 mprintf(0, "Serialized user joining game: %d\n", ser);
2372 }
2373
2374 // Get packets per second for this player
2375 NetPlayers[slot].pps = MultiGetByte(data, &count);
2376
2377 if (NetPlayers[slot].pps < 2)
2378 NetPlayers[slot].pps = 2;
2379 if (NetPlayers[slot].pps > Netgame.packets_per_second)
2380 NetPlayers[slot].pps = Netgame.packets_per_second;
2381
2382 // pilot picture id
2383 NetPlayers[slot].pilot_pic_id = MultiGetUshort(data, &count);
2384
2385 // Copy the guidebot name out
2386 char guidebot_name[32];
2387 memset(guidebot_name, 0, 32);
2388 len = MultiGetByte(data, &count);
2389 ASSERT(len < 32);
2390 memcpy(guidebot_name, &data[count], len);
2391 count += len;
2392
2393 // Set the guidebot name
2394 if (Netgame.flags & NF_ALLOWGUIDEBOT) {
2395 gb_com command;
2396 command.action = COM_DO_ACTION;
2397 command.index = 44; // GBC_RENAME_SILENT
2398 command.ptr = (void *)guidebot_name;
2399 object *b_obj = ObjGet(Buddy_handle[slot]);
2400 ASSERT(b_obj);
2401 AINotify(b_obj, AIN_USER_DEFINED, (void *)&command);
2402 }
2403
2404 NetPlayers[slot].sequence = NETSEQ_NEED_GAMETIME;
2405
2406 mprintf(0, "Got a myinfo packet from %s len=%d!\n", Players[slot].callsign, len);
2407 }
2408
2409 // Tell a client about the players connected
2410 // Server only
2411 void MultiDoRequestPlayers(uint8_t *data) {
2412 int count = 0;
2413
2414 // Skip header stuff
2415 SKIP_HEADER(data, &count);
2416
2417 uint8_t slot = MultiGetByte(data, &count);
2418 if (!(NetPlayers[slot].flags & NPF_CONNECTED)) {
2419 mprintf(1, "ERROR! We got a MY_INFO packet from a disconnected player!\n");
2420 Int3(); // Get Jason
2421 return;
2422 }
2423
2424 NetPlayers[slot].sequence = NETSEQ_REQUEST_PLAYERS;
2425 }
2426
2427 // Tell a client about the buildings
2428 // Server only
2429 void MultiDoRequestBuildings(uint8_t *data) {
2430 int count = 0;
2431
2432 // Skip header stuff
2433 SKIP_HEADER(data, &count);
2434
2435 uint8_t slot = MultiGetByte(data, &count);
2436 if (!(NetPlayers[slot].flags & NPF_CONNECTED)) {
2437 mprintf(1, "ERROR! We got a request buildings packet from a disconnected player!\n");
2438 Int3(); // Get Jason
2439 return;
2440 }
2441
2442 NetPlayers[slot].sequence = NETSEQ_REQUEST_BUILDINGS;
2443 }
2444
2445 // Tell a client about the objects
2446 // Server only
2447 void MultiDoRequestObjects(uint8_t *data) {
2448 int count = 0;
2449
2450 // Skip header stuff
2451 SKIP_HEADER(data, &count);
2452
2453 uint8_t slot = MultiGetByte(data, &count);
2454 if (!(NetPlayers[slot].flags & NPF_CONNECTED)) {
2455 mprintf(1, "ERROR! We got a request object packet from a disconnected player!\n");
2456 Int3(); // Get Jason
2457 return;
2458 }
2459
2460 NetPlayers[slot].sequence = NETSEQ_REQUEST_OBJECTS;
2461 }
2462
2463 // Tell a client about the objects
2464 // Server only
2465 void MultiDoRequestWorldStates(uint8_t *data) {
2466 int count = 0;
2467
2468 // Skip header stuff
2469 SKIP_HEADER(data, &count);
2470 uint8_t slot = MultiGetByte(data, &count);
2471
2472 uint8_t rxdigest[16];
2473 for (int i = 0; i < 16; i++) {
2474 rxdigest[i] = MultiGetByte(data, &count);
2475 }
2476
2477 char dbgmsg[1024];
2478 char expectedstr[50] = "";
2479 char gotstr[50] = "";
2480 for (int j = 0; j < 16; j++) {
2481 char bstr[10];
2482 snprintf(bstr, sizeof(bstr), "%.2x", rxdigest[j] & 0xff);
2483 strcat(gotstr, bstr);
2484 snprintf(bstr, sizeof(bstr), "%.2x", NetPlayers[slot].digest[j] & 0xff);
2485 strcat(expectedstr, bstr);
2486 }
2487 snprintf(dbgmsg, sizeof(dbgmsg), "Expected %s for the digest, got %s for player %d\n", expectedstr, gotstr, slot);
2488
2489 for (int i = 0; i < 16; i++) {
2490 // We got the digest from the player previously. Now see if it matches.
2491 if (rxdigest[i] != NetPlayers[slot].digest[i]) {
2492 // send 'bad checksum message.'
2493 MultiSendBadChecksum(slot);
2494
2495 // Bad checksum, kick the player out.
2496 NetPlayers[slot].sequence = NETSEQ_PREGAME;
2497 NetPlayers[slot].flags |= NPF_CONNECTED;
2498 return;
2499 }
2500 }
2501 if (!(NetPlayers[slot].flags & NPF_CONNECTED)) {
2502 mprintf(1, "ERROR! We got a request world states packet from a disconnected player!\n");
2503 Int3(); // Get Jason
2504 return;
2505 }
2506
2507 NetPlayers[slot].sequence = NETSEQ_REQUEST_WORLD;
2508 }
2509
2510 // The server is telling me about a player in the game
2511 // Client only
2512 void MultiDoPlayer(uint8_t *data) {
2513 int count = 0;
2514 char ship_name[PAGENAME_LEN];
2515
2516 mprintf(0, "Got player packet!\n");
2517
2518 // Skip header stuff
2519 SKIP_HEADER(data, &count);
2520
2521 // Get slotnumber
2522 uint8_t slot = MultiGetByte(data, &count);
2523
2524 // Reset some local stuff for this player
2525 if (slot != Player_num) {
2526 InitPlayerNewShip(slot, INVRESET_ALL);
2527 InitPlayerNewGame(slot);
2528 PlayerStopSounds(slot);
2529 ResetPlayerObject(slot);
2530 InitPlayerNewLevel(slot);
2531 }
2532
2533 // Get name
2534 uint8_t len = MultiGetByte(data, &count);
2535 memcpy(Players[slot].callsign, &data[count], len);
2536 count += len;
2537
2538 // Get ship name
2539 len = MultiGetByte(data, &count);
2540 memcpy(ship_name, &data[count], len);
2541 count += len;
2542
2543 int ship_index = FindShipName(ship_name);
2544 if (ship_index < 0) {
2545 ship_index = 0; // Should we bail out here?
2546 }
2547
2548 PlayerChangeShip(slot, ship_index);
2549
2550 // Get various flags
2551 if (slot != Player_num) {
2552 Players[slot].flags = MultiGetInt(data, &count);
2553 Players[slot].weapon_flags = MultiGetInt(data, &count);
2554 } else {
2555 // Skip my own data
2556 MultiGetInt(data, &count);
2557 MultiGetInt(data, &count);
2558 }
2559
2560 NetPlayers[slot].flags = MultiGetInt(data, &count);
2561 float shields = MultiGetFloat(data, &count);
2562
2563 // Get object number, just to verify
2564 int objnum = MultiGetShort(data, &count);
2565
2566 // Make sure we have the right object number
2567 if (objnum != Players[slot].objnum) {
2568 BailOnMultiplayer(NULL);
2569 return;
2570 }
2571
2572 // Get team
2573 uint8_t temp_team = MultiGetByte(data, &count);
2574 Players[slot].team = (temp_team == 255) ? -1 : temp_team;
2575
2576 // Get team start
2577 if (slot == Player_num) {
2578 Players[slot].start_index = MultiGetShort(data, &count);
2579 PlayerMoveToStartPos(slot, Players[slot].start_index);
2580 }
2581
2582 // Get observer mode
2583 uint8_t observing = MultiGetByte(data, &count);
2584
2585 // Put in address
2586 memcpy(&NetPlayers[slot].addr, data + count, sizeof(network_address));
2587 char dbg_output[50];
2588 nw_GetNumbersFromHostAddress(&NetPlayers[slot].addr, dbg_output);
2589 mprintf(0, "Got player address of: %s\n", dbg_output);
2590
2591 count += sizeof(network_address);
2592
2593 // PPS
2594 NetPlayers[slot].pps = MultiGetByte(data, &count);
2595
2596 // pilot picture id
2597 NetPlayers[slot].pilot_pic_id = MultiGetUshort(data, &count);
2598
2599 // Get ranking
2600 Players[slot].rank = MultiGetFloat(data, &count);
2601
2602 // Get tracker id
2603 if (Game_is_master_tracker_game) {
2604 int len = MultiGetByte(data, &count);
2605 memcpy(Players[slot].tracker_id, &data[count], len);
2606 count += len;
2607 }
2608
2609 object *obj = &Objects[objnum];
2610 obj->id = slot;
2611
2612 MultiMakePlayerReal(slot);
2613
2614 if (Player_num != slot) {
2615 NetPlayers[slot].sequence = NETSEQ_PLAYING;
2616 NetPlayers[slot].flags |= NPF_CONNECTED;
2617 }
2618
2619 if (slot != Player_num) {
2620 obj->shields = shields;
2621 if (Players[slot].flags & PLAYER_FLAGS_DEAD) {
2622 mprintf(0, "Incoming %d player is dead!\n", slot);
2623 MultiMakePlayerGhost(slot);
2624 } else if (Players[slot].flags & PLAYER_FLAGS_DYING) {
2625 mprintf(0, "Incoming %d player is dying!\n", slot);
2626 int save_flags = Players[slot].flags;
2627 Players[slot].flags &= ~(PLAYER_FLAGS_DEAD | PLAYER_FLAGS_DYING);
2628 InitiatePlayerDeath(&Objects[Players[slot].objnum], false, 0);
2629 Players[slot].flags = save_flags;
2630 }
2631 }
2632
2633 obj->flags |= OF_SERVER_OBJECT;
2634
2635 if (observing) {
2636 obj->render_type = RT_NONE;
2637 obj->type = OBJ_OBSERVER;
2638 }
2639
2640 if (slot == 0) {
2641 memcpy(&NetPlayers[slot].addr, &Netgame.server_address, sizeof(network_address));
2642 }
2643 }
2644
2645 // Tells all our clients about a new player entering the game
2646 void MultiSendNewPlayer(int slot) {}
2647
2648 void MultiDoPlayerEnteredGame(uint8_t *data) {
2649 int count = 0;
2650 char ship_name[PAGENAME_LEN];
2651 int length;
2652
2653 mprintf(0, "Got player entered game packet!\n");
2654
2655 // Skip header stuff
2656 SKIP_HEADER(data, &count);
2657
2658 // Get slot number for this player
2659 uint8_t slot = MultiGetByte(data, &count);
2660
2661 if (slot > MAX_PLAYERS)
2662 return;
2663
2664 ScoreAPIPlayerJoin(slot);
2665 // get name
2666 uint8_t len = MultiGetByte(data, &count);
2667
2668 if (len > CALLSIGN_LEN)
2669 length = CALLSIGN_LEN;
2670 else
2671 length = len;
2672
2673 memcpy(Players[slot].callsign, &data[count], length);
2674 count += len;
2675
2676 // get ship name
2677 len = MultiGetByte(data, &count);
2678 memcpy(ship_name, &data[count], len);
2679 count += len;
2680
2681 int ship_index = FindShipName(ship_name);
2682 if (ship_index < 0)
2683 ship_index = 0;
2684
2685 // Get various flags
2686 Players[slot].flags = MultiGetInt(data, &count);
2687 NetPlayers[slot].flags = MultiGetInt(data, &count);
2688
2689 // Verify object number
2690 int objnum = MultiGetShort(data, &count);
2691
2692 MULTI_ASSERT(objnum == Players[slot].objnum, NULL);
2693 MULTI_ASSERT(Objects[objnum].id == slot, NULL);
2694
2695 // Get the player's network address
2696 memcpy(&NetPlayers[slot].addr, data + count, sizeof(network_address));
2697 count += sizeof(network_address);
2698
2699 // Get PPS
2700 NetPlayers[slot].pps = MultiGetByte(data, &count);
2701
2702 // pilot picture id
2703 NetPlayers[slot].pilot_pic_id = MultiGetUshort(data, &count);
2704
2705 Players[slot].start_index = MultiGetShort(data, &count);
2706
2707 // Get ranking
2708 Players[slot].rank = MultiGetFloat(data, &count);
2709
2710 // Get tracker id
2711 if (Game_is_master_tracker_game) {
2712 int len = MultiGetByte(data, &count);
2713 memcpy(Players[slot].tracker_id, &data[count], len);
2714 count += len;
2715
2716 NetPlayers[slot].flags &= ~NPF_WROTE_RANK;
2717 }
2718
2719 if (Player_num != slot && NetPlayers[Player_num].sequence == NETSEQ_PLAYING) {
2720 NetPlayers[slot].sequence = NETSEQ_PLAYING;
2721 NetPlayers[slot].flags |= NPF_CONNECTED;
2722 }
2723
2724 InitPlayerNewShip(slot, INVRESET_ALL);
2725 InitPlayerNewGame(slot);
2726 PlayerStopSounds(slot);
2727 ResetPlayerObject(slot);
2728 InitPlayerNewLevel(slot);
2729 PlayerChangeShip(slot, ship_index);
2730 PlayerMoveToStartPos(slot, Players[slot].start_index);
2731 MultiMakePlayerReal(slot);
2732 Objects[objnum].flags |= OF_SERVER_OBJECT;
2733
2734 MultiAnnounceEffect(&Objects[objnum], Objects[objnum].size * 5, 1.0);
2735 NetPlayers[slot].total_bytes_sent = 0;
2736 NetPlayers[slot].total_bytes_rcvd = 0;
2737 NetPlayers[slot].sequence = NETSEQ_PLAYING;
2738 }
2739
2740 // Sends a new player to existing players
2741 // Sends to "slot" and describes player "which"
2742 // Server only
2743 void MultiSendPlayerEnteredGame(int which) {
2744 MULTI_ASSERT(Netgame.local_role == LR_SERVER, NULL);
2745
2746 uint8_t data[MAX_GAME_DATA_SIZE];
2747 int count = 0;
2748 int size_offset;
2749
2750 size_offset = START_DATA(MP_PLAYER_ENTERED_GAME, data, &count, 1);
2751
2752 MultiAddByte(which, data, &count);
2753
2754 // Add name
2755 int len = strlen(Players[which].callsign) + 1;
2756 MultiAddByte(len, data, &count);
2757 memcpy(&data[count], Players[which].callsign, len);
2758 count += len;
2759
2760 // Add ship name
2761 len = strlen(Ships[Players[which].ship_index].name) + 1;
2762 MultiAddByte(len, data, &count);
2763 memcpy(&data[count], Ships[Players[which].ship_index].name, len);
2764 count += len;
2765
2766 // Add flags
2767 MultiAddInt(Players[which].flags, data, &count);
2768 MultiAddInt(NetPlayers[which].flags, data, &count);
2769
2770 // Just for safety sake send the object number
2771 MultiAddShort(Players[which].objnum, data, &count);
2772
2773 // Add the player's network address.
2774 memcpy(data + count, &NetPlayers[which].addr, sizeof(network_address));
2775 count += sizeof(network_address);
2776
2777 // Add pps
2778 MultiAddByte(NetPlayers[which].pps, data, &count);
2779
2780 // pilot picture id
2781 MultiAddUshort(NetPlayers[which].pilot_pic_id, data, &count);
2782
2783 // Add start position
2784 MultiAddShort(Players[which].start_index, data, &count);
2785
2786 // Send ranking
2787 MultiAddFloat(Players[which].rank, data, &count);
2788
2789 // Send tracker id
2790 if (Game_is_master_tracker_game) {
2791 int len = strlen(Players[which].tracker_id) + 1;
2792 MultiAddByte(len, data, &count);
2793 memcpy(&data[count], Players[which].tracker_id, len);
2794 count += len;
2795 }
2796
2797 END_DATA(count, data, size_offset);
2798
2799 // Send it out
2800
2801 MultiSendReliablyToAllExcept(which, data, count, NETSEQ_REQUEST_BUILDINGS);
2802 MultiDoPlayerEnteredGame(data);
2803 }
2804
2805 // Client is saying that he's entering the game
2806 // Server only
2807 void MultiDoEnteringGame(uint8_t *data) {
2808 int count = 0;
2809
2810 // Skip header stuff
2811 SKIP_HEADER(data, &count);
2812
2813 uint8_t slot = MultiGetByte(data, &count);
2814
2815 if (!(NetPlayers[slot].flags & NPF_CONNECTED)) {
2816 Int3(); // Get Jason
2817 return;
2818 }
2819
2820 mprintf(0, "Client %d (%s) entering game.\n", slot, Players[slot].callsign);
2821
2822 MultiSendPlayerEnteredGame(slot);
2823
2824 // send the player the audio taunt delay time
2825 MultiSetAudioTauntTime(taunt_DelayTime(), slot);
2826
2827 Level_goals.MultiSendChangedGoals(slot);
2828
2829 // add his guidebot (if it is a guidebot game)
2830 // NOTE: It is possible that DMFC may InitPlayerNewShip after this
2831 // so it is placed as a precaution in their also
2832 if (Netgame.flags & NF_ALLOWGUIDEBOT) {
2833 if ((!Players[slot].inventory.CheckItem(OBJ_ROBOT, ROBOT_GUIDEBOT)) &&
2834 (ObjGet(Buddy_handle[slot])->type != OBJ_ROBOT))
2835 Players[slot].inventory.Add(OBJ_ROBOT, ROBOT_GUIDEBOT);
2836 }
2837
2838 DLLInfo.me_handle = Objects[Players[slot].objnum].handle;
2839 DLLInfo.it_handle = Objects[Players[slot].objnum].handle;
2840 CallGameDLL(EVT_GAMEPLAYERENTERSGAME, &DLLInfo);
2841
2842 // Clear vis info
2843 for (int i = 0; i < MAX_OBJECTS; i++) {
2844 Objects[i].generic_nonvis_flags &= ~(1 << slot);
2845 Objects[i].generic_sent_nonvis &= ~(1 << slot);
2846 }
2847 }
2848
2849 // Tell the server I'm entering the game
2850 void MultiSendEnteringGame() {
2851 int size;
2852 uint8_t data[MAX_GAME_DATA_SIZE];
2853 int count = 0;
2854
2855 mprintf(0, "Sending entering game\n");
2856
2857 size = START_DATA(MP_ENTERING_GAME, data, &count);
2858 MultiAddByte(Player_num, data, &count);
2859 END_DATA(count, data, size);
2860
2861 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count);
2862 }
2863
2864 // Tell my clients about damage done to a player
2865 // Server only
2866 void MultiSendDamagePlayer(int slot, int weapon_id, int type, float amount) {
2867 int count = 0;
2868 uint8_t data[MAX_GAME_DATA_SIZE];
2869 int size_offset;
2870
2871 MULTI_ASSERT(Netgame.local_role == LR_SERVER, NULL);
2872
2873 size_offset = START_DATA(MP_DAMAGE_PLAYER, data, &count, 1);
2874 MultiAddByte(slot, data, &count);
2875 MultiAddByte(weapon_id, data, &count);
2876 MultiAddByte(type, data, &count);
2877 MultiAddFloat(amount, data, &count);
2878 END_DATA(count, data, size_offset);
2879
2880 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_PLAYING, true);
2881 }
2882
2883 // The server says to damage a player, so do it!
2884 void MultiDoDamagePlayer(uint8_t *data) {
2885
2886 if (Netgame.local_role != LR_CLIENT) {
2887 Int3();
2888 return;
2889 }
2890
2891 int count = 0;
2892
2893 SKIP_HEADER(data, &count);
2894 uint8_t slot = MultiGetByte(data, &count);
2895 uint8_t weapon_id = MultiGetByte(data, &count);
2896 uint8_t type = MultiGetByte(data, &count);
2897 float amount = MultiGetFloat(data, &count);
2898
2899 ApplyDamageToPlayer(&Objects[Players[slot].objnum], NULL, type, amount, 1, weapon_id);
2900 }
2901
2902 // Makes the passed in player a ghost
2903 void MultiMakePlayerGhost(int slot) {
2904 object *obj = &Objects[Players[slot].objnum];
2905
2906 MULTI_ASSERT(obj->id == slot, NULL); // Get Jason
2907
2908 obj->type = OBJ_GHOST;
2909 obj->movement_type = MT_NONE;
2910 obj->render_type = RT_NONE;
2911 obj->mtype.phys_info.flags |= PF_NO_COLLIDE;
2912 SetObjectControlType(obj, CT_NONE);
2913
2914 if (Demo_flags == DF_RECORDING) {
2915 DemoWritePlayerTypeChange(slot);
2916 }
2917
2918 // Stop sounds for this player
2919 PlayerStopSounds(slot);
2920 }
2921
2922 // Makes the passed in player real (non-ghost)
2923 void MultiMakePlayerReal(int slot) {
2924 object *obj = &Objects[Players[slot].objnum];
2925 MULTI_ASSERT(obj->id == slot, NULL); // Get Jason
2926
2927 obj->type = OBJ_PLAYER;
2928
2929 if (Demo_flags == DF_RECORDING) {
2930 DemoWritePlayerTypeChange(slot);
2931 }
2932
2933 obj->render_type = RT_POLYOBJ;
2934 obj->mtype.phys_info.flags &= ~PF_NO_COLLIDE;
2935
2936 if (slot == Player_num) {
2937 SetObjectControlType(obj, CT_FLYING);
2938 obj->movement_type = MT_PHYSICS;
2939 Viewer_object = Player_object = obj;
2940 } else {
2941 obj->movement_type = MT_PHYSICS;
2942 obj->mtype.phys_info.flags = PF_FIXED_VELOCITY;
2943 SetObjectControlType(obj, CT_NONE);
2944 }
2945 }
2946
2947 // Server is telling us that its done sending players
2948 void MultiDoDonePlayers(uint8_t *data) {
2949 int count = 0;
2950
2951 // Skip header stuff
2952 SKIP_HEADER(data, &count);
2953
2954 uint8_t num = MultiGetByte(data, &count);
2955 if (MultiCountPlayers() != num) {
2956 mprintf(1, "ERROR! We don't have the correct number of players!");
2957 Int3(); // Get Jason
2958 return;
2959 }
2960
2961 NetPlayers[Player_num].sequence = NETSEQ_REQUEST_BUILDINGS;
2962 }
2963
2964 // Server is telling us that its done sending buildings
2965 void MultiDoDoneBuildings(uint8_t *data) {
2966 MULTI_ASSERT(Netgame.local_role == LR_CLIENT, NULL);
2967
2968 int count = 0;
2969
2970 // Skip header stuff
2971 SKIP_HEADER(data, &count);
2972 NetPlayers[Player_num].sequence = NETSEQ_REQUEST_OBJECTS;
2973 }
2974
2975 // Server is telling us that its done sending objects
2976 void MultiDoDoneObjects(uint8_t *data) {
2977 MULTI_ASSERT(Netgame.local_role == LR_CLIENT, NULL);
2978
2979 int count = 0;
2980
2981 // Skip header stuff
2982 SKIP_HEADER(data, &count);
2983 // Get the salt.
2984 MD5 playermd5(*Level_md5);
2985 // Get the salt value from the server.
2986 int salt = MultiGetInt(data, &count);
2987 // process the salt through the md5
2988 playermd5.update(salt);
2989 // process the ships through the md5
2990 for (int i = 0; i < MAX_SHIPS; i++)
2991 if (Ships[i].used)
2992 MultiProcessShipChecksum(&playermd5, i);
2993 // save the digest value to send to the server
2994 playermd5.digest(NetPlayers[Player_num].digest);
2995
2996 NetPlayers[Player_num].sequence = NETSEQ_REQUEST_WORLD;
2997
2998 // Clear out all the lightmapped objects that weren't sent
2999 for (int i = 0; i < Num_client_lm_objects; i++) {
3000 int objnum = Client_lightmap_list[i];
3001 int found = 0;
3002 for (int t = 0; t < Num_server_lm_objects && !found; t++) {
3003 if (Server_lightmap_list[t] == objnum)
3004 found = 1;
3005 }
3006
3007 // If its not in the server list, delete it!
3008 if (!found) {
3009 Objects[objnum].flags |= OF_SERVER_SAYS_DELETE;
3010 ObjDelete(objnum);
3011 }
3012 }
3013 }
3014
3015 // Server is telling us that its done sending objects
3016 void MultiDoDoneWorldStates(uint8_t *data) {
3017 MULTI_ASSERT(Netgame.local_role == LR_CLIENT, NULL);
3018
3019 int count = 0;
3020
3021 // Skip header stuff
3022 SKIP_HEADER(data, &count);
3023 NetPlayers[Player_num].sequence = NETSEQ_PLAYING;
3024 NetPlayers[Player_num].total_bytes_sent = 0;
3025 NetPlayers[Player_num].total_bytes_rcvd = 0;
3026 PlayerMoveToStartPos(Player_num, Players[Player_num].start_index);
3027
3028 MultiSendEnteringGame();
3029 }
3030
3031 // Makes an abbrievated version of a matrix
3032 void MultiMakeMatrix(multi_orientation *dest, matrix *src) {
3033 dest->multi_matrix[0] = (src->rvec.x * 32767.0);
3034 dest->multi_matrix[1] = (src->rvec.y * 32767.0);
3035 dest->multi_matrix[2] = (src->rvec.z * 32767.0);
3036
3037 dest->multi_matrix[3] = (src->uvec.x * 32767.0);
3038 dest->multi_matrix[4] = (src->uvec.y * 32767.0);
3039 dest->multi_matrix[5] = (src->uvec.z * 32767.0);
3040
3041 dest->multi_matrix[6] = (src->fvec.x * 32767.0);
3042 dest->multi_matrix[7] = (src->fvec.y * 32767.0);
3043 dest->multi_matrix[8] = (src->fvec.z * 32767.0);
3044 }
3045
3046 // Extracts a matrix from an abbreviated matrix
3047 void MultiExtractMatrix(matrix *dest, multi_orientation *src) {
3048 dest->rvec.x = (float)src->multi_matrix[0] / 32767.0;
3049 dest->rvec.y = (float)src->multi_matrix[1] / 32767.0;
3050 dest->rvec.z = (float)src->multi_matrix[2] / 32767.0;
3051
3052 dest->uvec.x = (float)src->multi_matrix[3] / 32767.0;
3053 dest->uvec.y = (float)src->multi_matrix[4] / 32767.0;
3054 dest->uvec.z = (float)src->multi_matrix[5] / 32767.0;
3055
3056 dest->fvec.x = (float)src->multi_matrix[6] / 32767.0;
3057 dest->fvec.y = (float)src->multi_matrix[7] / 32767.0;
3058 dest->fvec.z = (float)src->multi_matrix[8] / 32767.0;
3059 }
3060
3061 void MultiDoPlayerPos(uint8_t *data) {
3062 int use_smoothing = (Netgame.flags & NF_USE_SMOOTHING);
3063 int count = 0;
3064
3065 // Skip header stuff
3066 SKIP_HEADER(data, &count);
3067
3068 uint8_t slot = MultiGetByte(data, &count);
3069
3070 // Make sure its not out of order
3071 float packet_time = MultiGetFloat(data, &count);
3072 if (packet_time < NetPlayers[slot].packet_time)
3073 return;
3074 NetPlayers[slot].packet_time = packet_time;
3075
3076 object *obj = &Objects[Players[slot].objnum];
3077
3078 vector pos;
3079 matrix orient;
3080 uint16_t short_roomnum;
3081 int roomnum;
3082
3083 // Get position
3084 MultiExtractPositionData(&pos, data, &count);
3085
3086 // Get orientation
3087 uint16_t p = MultiGetShort(data, &count);
3088 uint16_t h = MultiGetShort(data, &count);
3089 uint16_t b = MultiGetShort(data, &count);
3090
3091 vm_AnglesToMatrix(&orient, p, h, b);
3092
3093 // Get room and terrain flag
3094 short_roomnum = MultiGetUshort(data, &count);
3095
3096 roomnum = short_roomnum;
3097
3098 vector vel = {0, 0, 0}, rotvel;
3099 angle turnroll;
3100
3101 // float dist=vm_VectorDistance (&pos,&obj->pos);
3102
3103 // Get velocity
3104 vel.x = ((float)MultiGetShort(data, &count)) / 128.0;
3105 vel.y = ((float)MultiGetShort(data, &count)) / 128.0;
3106 vel.z = ((float)MultiGetShort(data, &count)) / 128.0;
3107
3108 // mprintf(0,"INCOMING x=%f y=%f z=%f dist=%f\n",vel.x,vel.y,vel.z,dist);
3109
3110 // Get rotational velocity
3111 if (Netgame.flags & NF_SENDROTVEL) {
3112 rotvel.x = MultiGetShort(data, &count) * 4;
3113 rotvel.y = MultiGetShort(data, &count) * 4;
3114 rotvel.z = MultiGetShort(data, &count) * 4;
3115
3116 turnroll = MultiGetShort(data, &count);
3117
3118 obj->mtype.phys_info.rotvel = rotvel;
3119 obj->mtype.phys_info.turnroll = turnroll;
3120 }
3121
3122 // obj->mtype.phys_info.velocity=vel;
3123
3124 // Get weapon states
3125 uint8_t windex = MultiGetByte(data, &count);
3126 Players[slot].weapon[PW_PRIMARY].index = windex & 0x0F;
3127 Players[slot].weapon[PW_SECONDARY].index = (windex >> 4) + 10;
3128
3129 // Get energy
3130 Players[slot].energy = MultiGetUbyte(data, &count);
3131 // Get flags
3132 uint8_t flags = MultiGetByte(data, &count);
3133
3134 // Do special stuff for non-visible objects
3135 bool visible = true;
3136 if (Objects[Players[slot].objnum].render_type == RT_NONE)
3137 visible = false;
3138
3139 if (Netgame.local_role == LR_SERVER) {
3140 // Stop cheating with on/off weapons (can't fire things you shouldn't have!)
3141 player *playp = &Players[slot];
3142 if (!(playp->weapon_flags & (1 << Players[slot].weapon[PW_PRIMARY].index)))
3143 flags &= ~(MPF_SPRAY | MPF_ON_OFF);
3144
3145 if (Player_pos_fix[slot].active) {
3146 if (Player_pos_fix[slot].expire_time <= Gametime) {
3147 Player_pos_fix[slot].active = false;
3148 // PrintDedicatedMessage("Discarded %d position updates from %s timed out
3149 // though.\n",Player_pos_fix[slot].ignored_pos,Players[slot].callsign);
3150 }
3151 }
3152 }
3153
3154 if ((flags & MPF_SPRAY) && visible)
3155 Objects[Players[slot].objnum].weapon_fire_flags |= WFF_SPRAY;
3156 else
3157 Objects[Players[slot].objnum].weapon_fire_flags &= ~WFF_SPRAY;
3158
3159 if ((flags & MPF_ON_OFF) && visible) {
3160 Objects[Players[slot].objnum].weapon_fire_flags |= WFF_ON_OFF;
3161 } else
3162 Objects[Players[slot].objnum].weapon_fire_flags &= ~WFF_ON_OFF;
3163
3164 if (Demo_flags == DF_RECORDING) {
3165 DemoWriteObjWeapFireFlagChanged(Players[slot].objnum);
3166 }
3167
3168 if ((flags & MPF_AFTERBURNER) && !(flags & MPF_DEAD) && visible) {
3169 Players[slot].flags |= PLAYER_FLAGS_AFTERBURN_ON;
3170 } else {
3171 Players[slot].flags &= ~PLAYER_FLAGS_AFTERBURN_ON;
3172 }
3173
3174 if ((flags & MPF_THRUSTED) && !(flags & MPF_DEAD) && visible) {
3175 Players[slot].flags |= PLAYER_FLAGS_THRUSTED;
3176 } else {
3177 Players[slot].flags &= ~PLAYER_FLAGS_THRUSTED;
3178 }
3179
3180 if ((flags & MPF_HEADLIGHT) && !(flags & MPF_DEAD))
3181 Players[slot].flags |= PLAYER_FLAGS_HEADLIGHT;
3182 else
3183 Players[slot].flags &= ~PLAYER_FLAGS_HEADLIGHT;
3184
3185 if (flags & MPF_OUTSIDE)
3186 roomnum = MAKE_ROOMNUM(roomnum);
3187
3188 if ((flags & MPF_DEAD)) // || (Players[slot].flags & PLAYER_FLAGS_DYING) || (Players[slot].flags & PLAYER_FLAGS_DEAD))
3189 return; // If dying, don't do positional updates
3190
3191 if (!ROOMNUM_OUTSIDE(roomnum)) {
3192 // Deal with late packets from last level
3193
3194 if (roomnum > Highest_room_index || roomnum < 0)
3195 return;
3196
3197 if (Rooms[roomnum].used == 0)
3198 return;
3199
3200 if (Rooms[roomnum].flags & RF_EXTERNAL)
3201 return;
3202 }
3203
3204 if (Netgame.local_role == LR_CLIENT && use_smoothing && !(flags & MPF_FIRED)) {
3205 // Check to see if we need to correct this ship due to error
3206 if (vm_VectorDistance(&pos, &obj->pos) < 8) {
3207 int pps_player_num;
3208 if (Netgame.local_role == LR_SERVER) {
3209 pps_player_num = slot;
3210 } else {
3211 pps_player_num = Player_num;
3212 }
3213
3214 vector dest_pos = pos + (vel * (1.0 / NetPlayers[pps_player_num].pps));
3215 vel = (dest_pos - obj->pos) / (1.0 / NetPlayers[pps_player_num].pps);
3216
3217 pos = obj->pos;
3218 }
3219 }
3220
3221 obj->mtype.phys_info.velocity = vel;
3222
3223 if ((Netgame.local_role == LR_SERVER) && (Player_pos_fix[slot].active) && (roomnum != Player_pos_fix[slot].room)) {
3224 // ignoring this position update....what should we do????
3225 Player_pos_fix[slot].ignored_pos++;
3226 } else {
3227 if (Player_pos_fix[slot].active) {
3228 Player_pos_fix[slot].active = false;
3229 // print some info to the server console...
3230 // PrintDedicatedMessage("Discarded %d position updates from
3231 // %s\n",Player_pos_fix[slot].ignored_pos,Players[slot].callsign);
3232 }
3233 ObjSetPos(obj, &pos, roomnum, &orient, true);
3234 }
3235
3236 if (Netgame.local_role == LR_SERVER) {
3237 Players[slot].oldroom = roomnum;
3238 }
3239 }
3240
3241 void MultiDoRobotPos(uint8_t *data) {
3242 int count = 0;
3243 //@@multi_orientation multi_mat;
3244 // Skip header stuff
3245 SKIP_HEADER(data, &count);
3246
3247 uint16_t server_objnum = MultiGetUshort(data, &count);
3248 uint16_t objectnum = Server_object_list[server_objnum];
3249 if (objectnum == 65535 || !(Objects[objectnum].flags & OF_SERVER_OBJECT)) {
3250 mprintf(0, "Bad robotposition object number!\n");
3251 return;
3252 }
3253 object *obj = &Objects[objectnum];
3254
3255 vector pos;
3256 matrix orient;
3257 uint16_t short_roomnum;
3258 int roomnum;
3259
3260 // Get position
3261 MultiExtractPositionData(&pos, data, &count);
3262
3263 // Get orientation
3264 uint16_t p = MultiGetShort(data, &count);
3265 uint16_t h = MultiGetShort(data, &count);
3266 uint16_t b = MultiGetShort(data, &count);
3267
3268 vm_AnglesToMatrix(&orient, p, h, b);
3269
3270 // Get room and terrain flag
3271 short_roomnum = MultiGetUshort(data, &count);
3272 uint8_t terrain = MultiGetByte(data, &count);
3273
3274 roomnum = short_roomnum;
3275 if (terrain)
3276 roomnum = MAKE_ROOMNUM(roomnum);
3277 vector vel = {0, 0, 0};
3278
3279 // Get velocity
3280 vel.x = ((float)MultiGetShort(data, &count)) / 128.0;
3281 vel.y = ((float)MultiGetShort(data, &count)) / 128.0;
3282 vel.z = ((float)MultiGetShort(data, &count)) / 128.0;
3283 obj->mtype.phys_info.velocity = vel;
3284
3285 obj->mtype.phys_info.flags &= ~PF_NO_COLLIDE;
3286 obj->render_type = RT_POLYOBJ;
3287
3288 if (!(obj->flags & (OF_DEAD)) && obj->type != OBJ_NONE) {
3289 ObjSetPos(obj, &pos, roomnum, &orient, false);
3290 }
3291 }
3292
3293 // Stuffs a players firing information into a packet
3294 int MultiStuffPlayerFire(int slot, uint8_t *data) {
3295 int size_offset;
3296 int count = 0;
3297
3298 size_offset = START_DATA(MP_PLAYER_FIRE, data, &count);
3299 MultiAddByte(slot, data, &count);
3300 MultiAddByte(Player_fire_packet[slot].wb_index, data, &count);
3301 MultiAddByte(Player_fire_packet[slot].fire_mask, data, &count);
3302 MultiAddByte(Player_fire_packet[slot].damage_scalar, data, &count);
3303 MultiAddByte(Player_fire_packet[slot].reliable, data, &count);
3304
3305 END_DATA(count, data, size_offset);
3306
3307 return count;
3308 }
3309
3310 // Returns true if there is enough ammo to allow this player to fire, else false
3311 bool MultiEnoughAmmoToFire(int slot, int wb_index) {
3312 ship *ship = &Ships[Players[slot].ship_index];
3313 otype_wb_info *wb = &ship->static_wb[wb_index];
3314
3315 if (wb->ammo_usage > 0 && Players[slot].weapon_ammo[wb_index] <= 0)
3316 return false;
3317
3318 return true;
3319 }
3320
3321 void MultiSubtractAmmoToFire(int slot, int wb_index) {
3322 ship *ship = &Ships[Players[slot].ship_index];
3323 otype_wb_info *wb = &ship->static_wb[wb_index];
3324 Players[slot].weapon_ammo[wb_index] -= wb->ammo_usage;
3325 if (Players[slot].weapon_ammo[wb_index] < 0)
3326 Players[slot].weapon_ammo[wb_index] = 0;
3327 }
3328
3329 #define MPFF_QUADED 128
3330 // Sends a fire packet from a player
3331 void MultiSendFirePlayerWB(int playernum, uint8_t wb_index, uint8_t fire_mask, uint8_t reliable, float scalar) {
3332 // Send quaded info if needed
3333 uint8_t index_to_send = wb_index;
3334
3335 if (Objects[Players[playernum].objnum].dynamic_wb[wb_index].flags & DWBF_QUAD)
3336 index_to_send |= MPFF_QUADED;
3337
3338 uint8_t damage_scalar = (scalar * 64.0);
3339
3340 Player_fire_packet[playernum].fire_mask = fire_mask;
3341 Player_fire_packet[playernum].damage_scalar = damage_scalar;
3342 Player_fire_packet[playernum].wb_index = index_to_send;
3343 Player_fire_packet[playernum].reliable = reliable;
3344
3345 // How should we send this information?
3346 // secondary fire in a non-peer to peer game should get sent reliably
3347 // except for a flage
3348 #ifdef RELIABLE_SECONDARIES
3349 if ((!(Netgame.flags & NF_PEER_PEER)) && (wb_index >= SECONDARY_INDEX) && (wb_index != FLARE_INDEX)) {
3350 Player_fire_packet[playernum].fired_on_this_frame = PFP_FIRED_RELIABLE;
3351 } else
3352 #endif
3353 {
3354 // send like normal fire
3355 Player_fire_packet[playernum].fired_on_this_frame = PFP_FIRED;
3356 }
3357 }
3358
3359 // Does player firing
3360 void MultiDoFirePlayerWB(uint8_t *data) {
3361 int count = 0, ok_to_fire = 1;
3362
3363 // Skip header stuff
3364 SKIP_HEADER(data, &count);
3365
3366 int pnum = MultiGetByte(data, &count);
3367 Player_fire_packet[pnum].wb_index = MultiGetByte(data, &count);
3368 Player_fire_packet[pnum].fire_mask = MultiGetByte(data, &count);
3369 Player_fire_packet[pnum].damage_scalar = MultiGetByte(data, &count);
3370 Player_fire_packet[pnum].reliable = MultiGetByte(data, &count);
3371
3372 // Strip out quad data
3373 int wb_index = Player_fire_packet[pnum].wb_index;
3374 int quaded = wb_index & MPFF_QUADED;
3375 wb_index &= ~MPFF_QUADED;
3376
3377 // Fire!
3378 float scalar = (float)Player_fire_packet[pnum].damage_scalar / 64.0;
3379 int ship_index = Players[pnum].ship_index;
3380 Objects[Players[pnum].objnum].dynamic_wb[wb_index].cur_firing_mask = Player_fire_packet[pnum].fire_mask;
3381
3382 if (quaded)
3383 Objects[Players[pnum].objnum].dynamic_wb[wb_index].flags |= DWBF_QUAD;
3384 else
3385 Objects[Players[pnum].objnum].dynamic_wb[wb_index].flags &= ~DWBF_QUAD;
3386
3387 if (Netgame.local_role == LR_SERVER) {
3388 // Check to see if this player is firing a weapon he doesn't have
3389 player *playp = &Players[pnum];
3390 if (!(playp->weapon_flags & (1 << wb_index))) {
3391 mprintf(0, "Can't fire client weapon...flags=%d wb_index=%d\n", playp->weapon_flags, wb_index);
3392 ok_to_fire = 0;
3393 }
3394
3395 if (!MultiEnoughAmmoToFire(pnum, wb_index))
3396 ok_to_fire = 0;
3397 }
3398
3399 if (ok_to_fire) {
3400 WBFireBattery(&Objects[Players[pnum].objnum], &Ships[ship_index].static_wb[wb_index], 0, wb_index, scalar);
3401 // Take off ammo
3402 MultiSubtractAmmoToFire(pnum, wb_index);
3403 }
3404
3405 // Play cutoff sound if there is one
3406 int cutoff_sound = Ships[ship_index].firing_release_sound[wb_index];
3407 if (cutoff_sound != -1)
3408 Sound_system.Play3dSound(cutoff_sound, &Objects[Players[pnum].objnum]);
3409
3410 if ((Netgame.local_role == LR_SERVER && ok_to_fire) &&
3411 ((!(Netgame.flags & NF_PEER_PEER)) || ((Netgame.flags & NF_PEER_PEER) && Player_fire_packet[pnum].reliable))) {
3412 #ifdef RELIABLE_SECONDARIES
3413 // How should we send this information?
3414 // secondary fire in a non-peer to peer game should get sent reliably
3415 if ((!(Netgame.flags & NF_PEER_PEER)) && (wb_index >= SECONDARY_INDEX) && (wb_index != FLARE_INDEX)) {
3416 Player_fire_packet[pnum].fired_on_this_frame = PFP_FIRED_RELIABLE;
3417 } else
3418 #endif
3419 {
3420 // send like normal fire
3421 Player_fire_packet[pnum].fired_on_this_frame = PFP_FIRED;
3422 }
3423 }
3424 }
3425
3426 // Tell everyone I'm quitting
3427 void MultiSendLeaveGame() {
3428 uint8_t data[MAX_GAME_DATA_SIZE];
3429 int count = 0;
3430 int size_offset;
3431
3432 mprintf(0, "Sending leave game!\n");
3433
3434 if (Netgame.local_role == LR_SERVER) {
3435 size_offset = START_DATA(MP_SERVER_QUIT, data, &count, 1);
3436
3437 ShowProgressScreen(TXT_MLTSHUTDOWN);
3438
3439 } else {
3440 size_offset = START_DATA(MP_LEAVE_GAME, data, &count);
3441 MultiAddByte(Player_num, data, &count);
3442 }
3443
3444 END_DATA(count, data, size_offset);
3445
3446 if (Netgame.local_role == LR_SERVER) {
3447 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_REQUEST_BUILDINGS);
3448 } else {
3449 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count);
3450 }
3451 }
3452
3453 // Called whenever I want to leave the game
3454 void MultiLeaveGame() {
3455 mprintf(0, "I'm leaving the netgame!\n");
3456
3457 CallGameDLL(EVT_GAME_DISCONNECTED, &DLLInfo);
3458
3459 if ((Players[Player_num].flags & PLAYER_FLAGS_DYING) || (Players[Player_num].flags & PLAYER_FLAGS_DEAD))
3460 EndPlayerDeath(Player_num);
3461
3462 // Cancel all incoming file transfers
3463
3464 Multi_bail_ui_menu = true;
3465 MultiSendLeaveGame();
3466
3467 CallMultiDLL(MT_EVT_GAME_OVER);
3468 MultiCloseGame();
3469
3470 SetFunctionMode(MENU_MODE);
3471 if (Netgame.local_role == LR_SERVER) {
3472 // gspy_EndGame();
3473 }
3474
3475 ScoreAPIGameOver();
3476 NetPlayers[Player_num].flags &= ~NPF_CONNECTED;
3477 }
3478
3479 // Releases a missile that belongs to a player
3480 void MultiDoReleaseTimeoutMissile(uint8_t *data) {
3481 int count = 0;
3482
3483 SKIP_HEADER(data, &count);
3484
3485 int pnum = MultiGetByte(data, &count);
3486
3487 if (Players[pnum].user_timeout_obj != NULL) {
3488 ReleaseUserTimeoutMissile(pnum);
3489 }
3490
3491 if (Netgame.local_role == LR_SERVER)
3492 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_PLAYING);
3493 }
3494
3495 // Tell everyone I'm timingout my timeout weapon
3496 void MultiSendReleaseTimeoutMissile() {
3497 uint8_t data[MAX_GAME_DATA_SIZE];
3498 int count = 0;
3499 int size_offset;
3500
3501 ASSERT(Players[Player_num].user_timeout_obj != NULL);
3502
3503 mprintf(0, "Sending timeout weapon packet!\n");
3504
3505 size_offset = START_DATA(MP_TIMEOUT_WEAPON, data, &count);
3506 MultiAddByte(Player_num, data, &count);
3507
3508 END_DATA(count, data, size_offset);
3509
3510 if (Netgame.local_role == LR_SERVER)
3511 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_REQUEST_BUILDINGS);
3512 else
3513 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count);
3514 }
3515
3516 // Tells all the clients who are trying to join to piss off until the next level
3517 void MultiSendConnectBail() {
3518 uint8_t data[MAX_GAME_DATA_SIZE];
3519 int count = 0;
3520 int size_offset;
3521 bool wait_to_send = false;
3522 int i;
3523
3524 size_offset = START_DATA(MP_CONNECT_BAIL, data, &count);
3525 END_DATA(count, data, size_offset);
3526
3527 // Tell them to stop trying to join
3528 for (i = 1; i < MAX_PLAYERS; i++) {
3529 if (NetPlayers[i].flags & NPF_CONNECTED && NetPlayers[i].sequence < NETSEQ_OBJECTS) {
3530 nw_SendReliable(NetPlayers[i].reliable_socket, data, count, true);
3531 wait_to_send = true;
3532 }
3533 }
3534
3535 // Make sure these clients get this
3536 if (wait_to_send) {
3537 for (int t = 0; t < 10; t++) {
3538 nw_DoNetworkIdle();
3539 Sleep(100);
3540 }
3541 }
3542
3543 // Now disconnect them
3544 for (i = 1; i < MAX_PLAYERS; i++) {
3545 if (NetPlayers[i].flags & NPF_CONNECTED && NetPlayers[i].sequence < NETSEQ_OBJECTS) {
3546 nw_CloseSocket(&NetPlayers[i].reliable_socket);
3547 NetPlayers[i].flags &= ~NPF_CONNECTED;
3548 }
3549 }
3550 }
3551 // Server is telling us to bail on our connection
3552 void MultiDoConnectBail() {
3553 if (Netgame.local_role != LR_CLIENT)
3554 return;
3555
3556 ShowProgressScreen(TXT_MULTI_SERVERCHANGEA, TXT_MULTI_SERVERCHANGEB);
3557 Sleep(3000);
3558 MultiLeaveGame();
3559 SetFunctionMode(MENU_MODE);
3560 }
3561
3562 // Some DLL is telling us to end the level!
3563 void MultiEndLevel() {
3564 MULTI_ASSERT(Netgame.local_role == LR_SERVER, NULL);
3565 SetGameState(GAMESTATE_LVLEND);
3566 PrintDedicatedMessage(TXT_DS_ENDINGLEVEL);
3567 Multi_bail_ui_menu = true;
3568 }
3569
3570 // server is telling us the level has ended
3571 void MultiDoLevelEnded(uint8_t *data) {
3572 int count = 0;
3573 SKIP_HEADER(data, &count);
3574
3575 int success = MultiGetByte(data, &count);
3576 Multi_next_level = MultiGetByte(data, &count);
3577
3578 // Make sure we're not being fooled
3579 if (Multi_next_level < 1 || Multi_next_level > Current_mission.num_levels)
3580 Multi_next_level = -1;
3581
3582 mprintf(0, "Doing level ended! Next level=%d\n", Multi_next_level);
3583
3584 if (success)
3585 SetGameState(GAMESTATE_LVLEND);
3586 else
3587 SetGameState(GAMESTATE_LVLFAILED);
3588
3589 NetPlayers[Player_num].sequence = NETSEQ_LEVEL_END;
3590
3591 Multi_bail_ui_menu = true;
3592
3593 CallGameDLL(EVT_CLIENT_GAMELEVELEND, &DLLInfo);
3594 CallMultiDLL(MT_EVT_GAME_OVER);
3595 ScoreAPIGameOver();
3596 }
3597
3598 // Tells all the clients to end the level
3599 void MultiSendLevelEnded(int success, int next_level) {
3600 MULTI_ASSERT(Netgame.local_role == LR_SERVER, NULL);
3601
3602 uint8_t data[MAX_GAME_DATA_SIZE];
3603 int count = 0;
3604 int size_offset;
3605
3606 mprintf(0, "Sending level ended!\n");
3607
3608 size_offset = START_DATA(MP_LEVEL_ENDED, data, &count, 1);
3609 MultiAddByte(success, data, &count);
3610 MultiAddByte(next_level, data, &count);
3611 END_DATA(count, data, size_offset);
3612
3613 // First send out to all the people who are playing
3614 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_OBJECTS, true);
3615
3616 // Now send a connect bail on all the ones who are connecting
3617 MultiSendConnectBail();
3618
3619 NetPlayers[Player_num].sequence = NETSEQ_LEVEL_END;
3620
3621 if (success)
3622 SetGameState(GAMESTATE_LVLEND);
3623 else
3624 SetGameState(GAMESTATE_LVLFAILED);
3625
3626 if (Netgame.local_role == LR_SERVER) {
3627 for (int i = 0; i < MAX_PLAYERS; i++) {
3628 if (NetPlayers[i].flags & NPF_CONNECTED && NetPlayers[i].sequence == NETSEQ_PLAYING)
3629 NetPlayers[i].sequence = NETSEQ_WAITING_FOR_LEVEL;
3630 }
3631 }
3632 // Do this so it gets sent off now.
3633 for (int t = 0; t < 10; t++) {
3634 nw_DoNetworkIdle();
3635 Sleep(100);
3636 }
3637 }
3638
3639 extern void MultiClearPlayerMarkers(int slot);
3640 // Do leave game stuff
3641 void MultiDoLeaveGame(uint8_t *data) {
3642 int count = 0;
3643
3644 mprintf(0, "In MultiDoLeaveGame!\n");
3645
3646 // Skip header stuff
3647 SKIP_HEADER(data, &count);
3648
3649 uint8_t slot = MultiGetByte(data, &count);
3650
3651 if (NetPlayers[slot].flags & NPF_CONNECTED) {
3652 if (NetPlayers[slot].sequence == NETSEQ_PLAYING) {
3653 AddHUDMessage(TXT_MLTLEAVEGAME, Players[slot].callsign);
3654 MultiMakePlayerGhost(slot);
3655 Players[slot].flags = 0;
3656 }
3657 NetPlayers[slot].flags &= ~NPF_CONNECTED;
3658 NetPlayers[slot].secret_net_id = 0;
3659 } else
3660 mprintf(0, "Got a leave game from a non-connected player!\n");
3661
3662 // Now clear any files this guy might be receiving
3663 if (NetPlayers[slot].file_xfer_flags != NETFILE_NONE) {
3664 if (NetPlayers[slot].file_xfer_cfile) {
3665 char delfile[_MAX_PATH * 2];
3666 strcpy(delfile, NetPlayers[slot].file_xfer_cfile->name);
3667 cfclose(NetPlayers[slot].file_xfer_cfile);
3668 NetPlayers[slot].file_xfer_cfile = NULL;
3669 if (NetPlayers[slot].file_xfer_flags == NETFILE_RECEIVING)
3670 ddio_DeleteFile(delfile);
3671 }
3672 NetPlayers[slot].file_xfer_flags = NETFILE_NONE;
3673 NetPlayers[slot].custom_file_seq++;
3674 NetPlayers[slot].custom_file_seq = NETFILE_ID_NOFILE;
3675 }
3676
3677 // If this is the server, do any cleanup on this slot
3678 if (Netgame.local_role == LR_SERVER) {
3679 MultiClearGuidebot(slot);
3680 MultiClearPlayerMarkers(slot);
3681 DLLInfo.me_handle = DLLInfo.it_handle = Objects[Players[slot].objnum].handle;
3682 CallGameDLL(EVT_GAMEPLAYERDISCONNECT, &DLLInfo);
3683
3684 if (NetPlayers[slot].sequence == NETSEQ_PLAYING)
3685 PlayerSpewInventory(&Objects[Players[slot].objnum], true, true);
3686 MultiSendReliablyToAllExcept(slot, data, count, NETSEQ_REQUEST_BUILDINGS);
3687 if (NetPlayers[slot].file_xfer_flags != NETFILE_NONE) {
3688 MultiCancelFile(slot, NetPlayers[slot].custom_file_seq, NetPlayers[slot].file_xfer_who);
3689 }
3690 nw_CloseSocket(&NetPlayers[slot].reliable_socket);
3691 if (Game_is_master_tracker_game) {
3692 NetPlayers[slot].flags |= NPF_MT_WRITING_PILOT;
3693 }
3694 }
3695 ScoreAPIPlayerLeft(slot);
3696 }
3697
3698 void MultiDoServerQuit(uint8_t *data) {
3699 ShowProgressScreen(TXT_MLTSERVERQUIT);
3700 // Abort all file transfers
3701 // ddio_DeleteFile(NetPlayers[filewho].file_xfer_cfile->name);
3702 for (int i = 0; i < MAX_NET_PLAYERS; i++) {
3703 if (NetPlayers[i].file_xfer_flags != NETFILE_NONE) {
3704 if (NetPlayers[i].file_xfer_cfile) {
3705 char delfile[_MAX_PATH * 2];
3706 strcpy(delfile, NetPlayers[i].file_xfer_cfile->name);
3707 cfclose(NetPlayers[i].file_xfer_cfile);
3708 NetPlayers[i].file_xfer_cfile = NULL;
3709 if (NetPlayers[i].file_xfer_flags == NETFILE_RECEIVING)
3710 ddio_DeleteFile(delfile);
3711 }
3712 NetPlayers[i].file_xfer_flags = NETFILE_NONE;
3713 NetPlayers[i].custom_file_seq++;
3714 NetPlayers[i].custom_file_seq = NETFILE_ID_NOFILE;
3715 }
3716 }
3717 mprintf(0, "Server quitting!\n");
3718 MultiLeaveGame();
3719 Sleep(2000);
3720 }
3721
3722 void MultiDoDisconnect(uint8_t *data) {
3723 int count = 0;
3724
3725 // Skip header stuff
3726 SKIP_HEADER(data, &count);
3727
3728 uint8_t slot = MultiGetByte(data, &count);
3729
3730 if (NetPlayers[slot].flags & NPF_CONNECTED) {
3731 if (NetPlayers[slot].file_xfer_flags != NETFILE_NONE) {
3732 if (NetPlayers[slot].file_xfer_cfile) {
3733 char delfile[_MAX_PATH * 2];
3734 strcpy(delfile, NetPlayers[slot].file_xfer_cfile->name);
3735 cfclose(NetPlayers[slot].file_xfer_cfile);
3736 NetPlayers[slot].file_xfer_cfile = NULL;
3737 if (NetPlayers[slot].file_xfer_flags == NETFILE_RECEIVING)
3738 ddio_DeleteFile(delfile);
3739 }
3740 NetPlayers[slot].file_xfer_flags = NETFILE_NONE;
3741 NetPlayers[slot].custom_file_seq++;
3742 NetPlayers[slot].custom_file_seq = NETFILE_ID_NOFILE;
3743 }
3744 if (NetPlayers[slot].sequence == NETSEQ_PLAYING) {
3745 AddHUDMessage(TXT_MLTDISCONNECT, Players[slot].callsign);
3746 MultiMakePlayerGhost(slot);
3747 }
3748 NetPlayers[slot].flags &= ~NPF_CONNECTED;
3749 NetPlayers[slot].secret_net_id = 0;
3750 } else
3751 mprintf(0, "Got a disconnect from a non-connected player!\n");
3752
3753 ScoreAPIPlayerLeft(slot);
3754 }
3755
3756 void MultiDoServerRejectedChecksum(uint8_t *data) {
3757 int count = 0;
3758
3759 MULTI_ASSERT(Netgame.local_role == LR_CLIENT, NULL);
3760
3761 SKIP_HEADER(data, &count);
3762 ShowProgressScreen(TXT_MLTLEVELNOMATCH);
3763 MultiLeaveGame();
3764 Sleep(2000);
3765 }
3766
3767 // Lets us know if the server says its ok to join
3768 void MultiDoJoinResponse(uint8_t *data) {
3769 int count = 0;
3770
3771 MULTI_ASSERT(Netgame.local_role == LR_CLIENT, NULL);
3772
3773 SKIP_HEADER(data, &count);
3774
3775 Ok_to_join = MultiGetByte(data, &count);
3776 }
3777
3778 // Returns an index of a unconnected slot
3779 // Returns -1 if there are none
3780 int MultiFindFreeSlot() {
3781 if (Netgame.local_role != LR_SERVER) {
3782 return -1;
3783 }
3784
3785 for (int i = 0; i < MAX_PLAYERS; i++) {
3786 if ((NetPlayers[i].flags & (NPF_CONNECTED | NPF_MT_READING_PILOT | NPF_MT_WRITING_PILOT)) == 0)
3787 return i;
3788 //(!(NetPlayers[i].flags & NPF_CONNECTED))
3789 }
3790
3791 return -1;
3792 }
3793
3794 // Someone is asking to join our game
3795 // Tell them if its ok
3796 void MultiDoAskToJoin(uint8_t *data, network_address *from_addr) {
3797 uint8_t outdata[MAX_GAME_DATA_SIZE];
3798 int count = 0;
3799 int incount = 0;
3800 int size;
3801
3802 size = START_DATA(MP_JOIN_RESPONSE, outdata, &count);
3803
3804 if (Netgame.local_role == LR_SERVER && Multi_accept_state) {
3805 // First see if this guy is banned
3806 if (GameDLLIsAddressBanned(from_addr, NULL)) {
3807 MultiAddByte(JOIN_ANSWER_REJECTED, outdata, &count);
3808
3809 } else {
3810 if (MultiCountPlayers() < Netgame.max_players) {
3811 int slot = MultiFindFreeSlot();
3812 MULTI_ASSERT(slot > 0, "FindFreeSlot returned -1!");
3813
3814 if (Players[slot].start_roomnum != -1) {
3815 mprintf(0, "Sending OK to join!\n");
3816 MultiAddByte(JOIN_ANSWER_OK, outdata, &count);
3817 } else {
3818 MultiAddByte(JOIN_ANSWER_NO_ROOM, outdata, &count);
3819 }
3820 } else {
3821 MultiAddByte(JOIN_ANSWER_FULL, outdata, &count);
3822 }
3823 }
3824 } else
3825 MultiAddByte(JOIN_ANSWER_NOT_SERVER, outdata, &count);
3826
3827 END_DATA(count, outdata, size);
3828
3829 nw_Send(from_addr, outdata, count, 0);
3830 }
3831
3832 // Someone is asking about our game
3833 void MultiDoGetGameInfo(uint8_t *data, network_address *from_addr) {
3834 uint8_t outdata[MAX_GAME_DATA_SIZE];
3835 int count = 0;
3836 int size_offset;
3837 network_address my_addr;
3838 float ping_time;
3839
3840 // mprintf(0,"Got a request for knowledge about my game!\n");
3841
3842 // Get the time and stuff it back in the packet
3843 SKIP_HEADER(data, &count);
3844 ping_time = MultiGetFloat(data, &count);
3845 int version = MultiGetInt(data, &count);
3846
3847 if (version != MULTI_VERSION)
3848 return; // Versions don't match, so just return
3849
3850 count = 0;
3851
3852 if (Game_is_master_tracker_game)
3853 return;
3854
3855 if (!Multi_accept_state)
3856 return;
3857
3858 if ((Netgame.local_role == LR_SERVER) && (Game_mode & GM_MULTI)) {
3859 size_offset = START_DATA(MP_GAME_INFO, outdata, &count);
3860 // Copies my address into the passed argument
3861 nw_GetMyAddress(&my_addr);
3862 memcpy(&outdata[count], &my_addr, sizeof(network_address));
3863 count += sizeof(network_address);
3864
3865 int len = strlen(Netgame.name) + 1;
3866 MultiAddByte(len, outdata, &count);
3867 memcpy(&outdata[count], Netgame.name, len);
3868 count += len;
3869
3870 len = strlen(Netgame.mission) + 1;
3871
3872 MultiAddByte(len, outdata, &count);
3873 memcpy(&outdata[count], Netgame.mission, len);
3874 count += len;
3875
3876 len = strlen(Netgame.mission_name) + 1;
3877
3878 MultiAddByte(len, outdata, &count);
3879 memcpy(&outdata[count], Netgame.mission_name, len);
3880 count += len;
3881
3882 len = strlen(Netgame.scriptname) + 1;
3883
3884 MultiAddByte(len, outdata, &count);
3885 memcpy(&outdata[count], Netgame.scriptname, len);
3886 count += len;
3887
3888 MultiAddShort(Current_mission.cur_level, outdata, &count);
3889 uint16_t icurrplayers = 0;
3890 for (int i = 0; i < MAX_NET_PLAYERS; i++) {
3891 if (Dedicated_server) {
3892 if (i == Player_num)
3893 continue;
3894 }
3895 if ((NetPlayers[i].flags & NPF_CONNECTED) && (Players[i].callsign[0]))
3896 icurrplayers++;
3897 }
3898 // Adjust the players count because the server isn't a player
3899
3900 int maxplayers = Netgame.max_players;
3901 if (Dedicated_server) {
3902 // icurrplayers--;
3903 maxplayers--;
3904 }
3905
3906 MultiAddShort(icurrplayers, outdata, &count);
3907 MultiAddShort(maxplayers, outdata, &count);
3908 MultiAddFloat(ping_time, outdata, &count);
3909
3910 MultiAddInt(Netgame.flags, outdata, &count);
3911 MultiAddByte(Dedicated_server ? 1 : 0, outdata, &count);
3912 MultiAddByte(Netgame.difficulty, outdata, &count);
3913
3914 END_DATA(count, outdata, size_offset);
3915 nw_Send(from_addr, outdata, count, 0);
3916 }
3917 }
3918
3919 // Someone is asking about our PXO game
3920 void MultiDoGetPXOGameInfo(uint8_t *data, network_address *from_addr) {
3921 uint8_t outdata[MAX_GAME_DATA_SIZE];
3922 int count = 0;
3923 int size_offset;
3924 float ping_time;
3925 network_address my_addr;
3926
3927 // mprintf(0,"Got a request for knowledge about my game!\n");
3928
3929 if (!Game_is_master_tracker_game) {
3930 return;
3931 }
3932 // Get the time and stuff it back in the packet
3933 SKIP_HEADER(data, &count);
3934 ping_time = MultiGetFloat(data, &count);
3935 int version = MultiGetInt(data, &count);
3936
3937 if (version != MULTI_VERSION)
3938 return; // Versions don't match, so just return
3939
3940 count = 0;
3941
3942 if ((Netgame.local_role == LR_SERVER) && (Game_mode & GM_MULTI)) {
3943 size_offset = START_DATA(MP_GAME_INFO, outdata, &count);
3944 // Copies my address into the passed argument
3945 nw_GetMyAddress(&my_addr);
3946 memcpy(&outdata[count], &my_addr, sizeof(network_address));
3947 count += sizeof(network_address);
3948
3949 int len = strlen(Netgame.name) + 1;
3950 MultiAddByte(len, outdata, &count);
3951 memcpy(&outdata[count], Netgame.name, len);
3952 count += len;
3953
3954 len = strlen(Netgame.mission) + 1;
3955
3956 MultiAddByte(len, outdata, &count);
3957 memcpy(&outdata[count], Netgame.mission, len);
3958 count += len;
3959
3960 len = strlen(Netgame.mission_name) + 1;
3961
3962 MultiAddByte(len, outdata, &count);
3963 memcpy(&outdata[count], Netgame.mission_name, len);
3964 count += len;
3965
3966 len = strlen(Netgame.scriptname) + 1;
3967
3968 MultiAddByte(len, outdata, &count);
3969 memcpy(&outdata[count], Netgame.scriptname, len);
3970 count += len;
3971
3972 MultiAddShort(Current_mission.cur_level, outdata, &count);
3973 uint16_t icurrplayers = 0;
3974 int i = 0;
3975
3976 for (i = 0; i < MAX_NET_PLAYERS; i++) {
3977 if (Dedicated_server) {
3978 if (i == Player_num)
3979 continue;
3980 }
3981 if (NetPlayers[i].flags & NPF_CONNECTED)
3982 icurrplayers++;
3983 }
3984
3985 // Adjust the players count because the server isn't a player
3986
3987 int maxplayers = Netgame.max_players;
3988 if (Dedicated_server) {
3989 maxplayers--;
3990 }
3991
3992 MultiAddShort(icurrplayers, outdata, &count);
3993 MultiAddShort(maxplayers, outdata, &count);
3994 MultiAddFloat(ping_time, outdata, &count);
3995
3996 MultiAddInt(Netgame.flags, outdata, &count);
3997 MultiAddByte(Dedicated_server ? 1 : 0, outdata, &count);
3998 MultiAddByte(Netgame.difficulty, outdata, &count);
3999
4000 END_DATA(count, outdata, size_offset);
4001 nw_Send(from_addr, outdata, count, 0);
4002 }
4003 }
4004
4005 bool Multi_Gamelist_changed = false;
4006
4007 // A server is telling us about a game we've requested
4008 void MultiDoGameInfo(uint8_t *data, network_address *from_addr) {
4009 int count = 0;
4010
4011 char name[NETGAME_NAME_LEN];
4012 char mission[MSN_NAMELEN];
4013 char mission_name[MISSION_NAME_LEN];
4014 char scriptname[NETGAME_SCRIPT_LEN];
4015 int level;
4016 int maxplayers;
4017 int currplayers;
4018 network_address incoming_addr;
4019 int len, mission_len, script_len, mission_name_len;
4020 float ping_time;
4021 int i;
4022 int fixed_len;
4023
4024 if (Num_network_games_known >= MAX_NETWORK_GAMES)
4025 return;
4026
4027 // mprintf(0,"Got game info packet!!\n");
4028
4029 SKIP_HEADER(data, &count);
4030
4031 // memcpy (&incoming_addr,&data[count],sizeof(network_address));
4032 // Get the network_address from the packet header, not the packet data
4033 memcpy(&incoming_addr, from_addr, sizeof(network_address));
4034 count += sizeof(network_address);
4035
4036 len = MultiGetByte(data, &count);
4037
4038 fixed_len = std::min(NETGAME_NAME_LEN, len);
4039
4040 memcpy(name, &data[count], fixed_len);
4041 name[fixed_len - 1] = 0;
4042 count += len;
4043
4044 mission_len = MultiGetByte(data, &count);
4045
4046 fixed_len = std::min(MSN_NAMELEN, mission_len);
4047
4048 memcpy(mission, &data[count], fixed_len);
4049 mission[fixed_len - 1] = 0;
4050 count += mission_len;
4051
4052 mission_name_len = MultiGetByte(data, &count);
4053
4054 fixed_len = std::min(MISSION_NAME_LEN, mission_name_len);
4055
4056 memcpy(mission_name, &data[count], fixed_len);
4057 mission_name[fixed_len - 1] = 0;
4058 count += mission_name_len;
4059
4060 script_len = MultiGetByte(data, &count);
4061
4062 fixed_len = std::min(NETGAME_SCRIPT_LEN, script_len);
4063
4064 memcpy(scriptname, &data[count], fixed_len);
4065 scriptname[fixed_len - 1] = 0;
4066 count += script_len;
4067
4068 level = MultiGetShort(data, &count);
4069 currplayers = MultiGetShort(data, &count);
4070 maxplayers = MultiGetShort(data, &count);
4071
4072 ping_time = MultiGetFloat(data, &count);
4073
4074 uint32_t flags = MultiGetInt(data, &count);
4075 bool dedicated = MultiGetByte(data, &count) ? true : false;
4076
4077 int diff = MultiGetByte(data, &count);
4078
4079 // Now go through and see if this is game we don't already have in our list
4080 for (i = 0; i < Num_network_games_known; i++) {
4081 if ((!memcmp(&incoming_addr, &Network_games[i].addr, sizeof(network_address)))) {
4082 Multi_Gamelist_changed = true;
4083 Network_games[i].server_response_time = timer_GetTime() - ping_time;
4084 Network_games[i].last_update = timer_GetTime();
4085 Network_games[i].level_num = level;
4086 Network_games[i].curr_num_players = currplayers;
4087 return;
4088 }
4089 }
4090
4091 if (i == Num_network_games_known) {
4092 Multi_Gamelist_changed = true;
4093 // We found a new one!
4094 int n = Num_network_games_known;
4095 Network_games[n].last_update = timer_GetTime();
4096 memcpy(&Network_games[n].addr, &incoming_addr, sizeof(network_address));
4097 strcpy(Network_games[n].name, name);
4098 strcpy(Network_games[n].mission, mission);
4099 strcpy(Network_games[n].mission_name, mission_name);
4100 strcpy(Network_games[n].scriptname, scriptname);
4101 Network_games[n].level_num = level;
4102 Network_games[n].curr_num_players = currplayers;
4103 Network_games[n].max_num_players = maxplayers;
4104 Network_games[n].server_response_time = timer_GetTime() - ping_time;
4105 Network_games[n].flags = flags;
4106 Network_games[n].dedicated_server = dedicated;
4107 Network_games[n].difficulty = diff;
4108 // This handle is used to make the game list update nicely
4109 Network_games[n].handle = Netgame_curr_handle++;
4110 // mprintf(0,"Got new game called %s!\n",name);
4111
4112 Num_network_games_known++;
4113
4114 } else
4115 Int3(); // How'd we get here?
4116 }
4117
4118 // Tells our clients that building exploded
4119 // Server only
4120 void MultiSendBlowupBuilding(int hit_objnum, int killer_objnum, float damage) {
4121 MULTI_ASSERT(Netgame.local_role == LR_SERVER, "Client in SendBlowupBuilding!");
4122
4123 int count = 0;
4124 int size_offset = 0;
4125 uint8_t data[MAX_GAME_DATA_SIZE];
4126
4127 uint16_t short_damage = damage;
4128
4129 size_offset = START_DATA(MP_BLOWUP_BUILDING, data, &count, 1);
4130 MultiAddShort(hit_objnum, data, &count);
4131 MultiAddShort(killer_objnum, data, &count);
4132 MultiAddShort(damage, data, &count);
4133
4134 END_DATA(count, data, size_offset);
4135
4136 if (!Multi_building_states[hit_objnum]) {
4137 Multi_building_states[hit_objnum] = 1;
4138 Multi_num_buildings_changed++;
4139 }
4140
4141 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_REQUEST_OBJECTS);
4142 }
4143
4144 // Blowup a building because the server told us so
4145 void MultiDoBlowupBuilding(uint8_t *data) {
4146 int count = 0;
4147
4148 SKIP_HEADER(data, &count);
4149
4150 uint16_t hit_objnum = MultiGetUshort(data, &count);
4151 uint16_t killer_objnum = MultiGetUshort(data, &count);
4152 uint16_t damage = MultiGetUshort(data, &count);
4153 uint16_t seed = MultiGetUshort(data, &count);
4154
4155 if (Objects[hit_objnum].type != OBJ_BUILDING) {
4156 Int3(); // Get Jason, trying to blowup a non-building
4157 return;
4158 }
4159
4160 ps_srand(seed);
4161 KillObject(&Objects[hit_objnum], &Objects[killer_objnum], damage);
4162
4163 if (!Multi_building_states[hit_objnum]) {
4164 Multi_building_states[hit_objnum] = 1;
4165 Multi_num_buildings_changed++;
4166 }
4167 }
4168
4169 // Server is telling us about buildings to get rid of
4170 void MultiDoBuilding(uint8_t *data) {
4171 int count = 0;
4172
4173 SKIP_HEADER(data, &count);
4174 uint8_t num = MultiGetByte(data, &count);
4175 for (int i = 0; i < num; i++) {
4176 uint16_t objnum = MultiGetUshort(data, &count);
4177 if (Objects[objnum].type != OBJ_BUILDING) {
4178 mprintf(0, "Error! Server says objnum %d is a building and its not!\n", objnum);
4179 } else {
4180 Multi_building_states[objnum] = 1;
4181
4182 object *obj = &Objects[objnum];
4183
4184 if (Object_info[obj->id].lo_render_handle != -1) {
4185 obj->flags |= OF_USE_DESTROYED_POLYMODEL;
4186 obj->lighting_render_type = LRT_GOURAUD;
4187
4188 // make parent object only draw center part
4189 obj->rtype.pobj_info.subobj_flags = 1;
4190 } else
4191 ObjDelete(objnum);
4192 }
4193 }
4194
4195 Multi_num_buildings_changed = num;
4196 }
4197
4198 doorway *GetDoorwayFromObject(int door_obj_handle);
4199 // Server is telling us the world state
4200 void MultiDoWorldStates(uint8_t *data) {
4201 int count = 0;
4202 uint8_t world_type;
4203
4204 SKIP_HEADER(data, &count);
4205
4206 mprintf(0, "Got a world state packet!\n");
4207
4208 while ((world_type = MultiGetByte(data, &count)) != WS_END) {
4209 switch (world_type) {
4210 case WS_ROOM_WIND: {
4211 // Room wind
4212
4213 int16_t roomnum = MultiGetShort(data, &count);
4214 Rooms[roomnum].wind.x = MultiGetFloat(data, &count);
4215 Rooms[roomnum].wind.y = MultiGetFloat(data, &count);
4216 Rooms[roomnum].wind.z = MultiGetFloat(data, &count);
4217
4218 mprintf(0, "Got room wind packet! Room=%d wind=%f %f %f\n",
4219 roomnum,
4220 Rooms[roomnum].wind.x,
4221 Rooms[roomnum].wind.y,
4222 Rooms[roomnum].wind.z);
4223 break;
4224 }
4225 case WS_ROOM_FOG: {
4226 // Room wind
4227 int16_t roomnum = MultiGetShort(data, &count);
4228 Rooms[roomnum].fog_depth = MultiGetFloat(data, &count);
4229 Rooms[roomnum].fog_r = ((float)MultiGetUbyte(data, &count)) / 255.0;
4230 Rooms[roomnum].fog_g = ((float)MultiGetUbyte(data, &count)) / 255.0;
4231 Rooms[roomnum].fog_b = ((float)MultiGetUbyte(data, &count)) / 255.0;
4232 uint8_t state = MultiGetUbyte(data, &count);
4233 if (state)
4234 Rooms[roomnum].flags |= RF_FOG;
4235 else
4236 Rooms[roomnum].flags &= ~RF_FOG;
4237
4238 break;
4239 }
4240
4241 case WS_ROOM_LIGHTING: {
4242 // Room lighting
4243 uint8_t state;
4244 int16_t roomnum = MultiGetShort(data, &count);
4245 Rooms[roomnum].pulse_time = MultiGetUbyte(data, &count);
4246 Rooms[roomnum].pulse_offset = MultiGetUbyte(data, &count);
4247 state = MultiGetUbyte(data, &count);
4248 if (state)
4249 Rooms[roomnum].flags |= RF_FLICKER;
4250 else
4251 Rooms[roomnum].flags &= ~RF_FLICKER;
4252
4253 state = MultiGetUbyte(data, &count);
4254 if (state)
4255 Rooms[roomnum].flags |= RF_STROBE;
4256 else
4257 Rooms[roomnum].flags &= ~RF_STROBE;
4258
4259 break;
4260 }
4261 case WS_ROOM_REFUEL: {
4262 // Room fueling
4263 int16_t roomnum = MultiGetShort(data, &count);
4264 uint8_t state = MultiGetUbyte(data, &count);
4265 if (state)
4266 Rooms[roomnum].flags |= RF_FUELCEN;
4267 else
4268 Rooms[roomnum].flags &= ~RF_FUELCEN;
4269
4270 break;
4271 }
4272 case WS_ROOM_TEXTURE: {
4273 int16_t roomnum = MultiGetShort(data, &count);
4274 int16_t facenum = MultiGetShort(data, &count);
4275 char str[255];
4276 MultiGetString(str, data, &count);
4277 ChangeRoomFaceTexture(roomnum, facenum, FindTextureName(IGNORE_TABLE(str)));
4278 break;
4279 }
4280 case WS_ROOM_GLASS: {
4281 int16_t roomnum = MultiGetShort(data, &count);
4282 int16_t facenum = MultiGetShort(data, &count);
4283 BreakGlassFace(&Rooms[roomnum], facenum);
4284 break;
4285 }
4286 case WS_ROOM_PORTAL_RENDER: {
4287 int16_t roomnum = MultiGetShort(data, &count);
4288 int16_t portalnum = MultiGetShort(data, &count);
4289 uint8_t flags = MultiGetByte(data, &count);
4290 Rooms[roomnum].portals[portalnum].flags = flags;
4291 break;
4292 }
4293 case WS_ROOM_PORTAL_BLOCK: {
4294 int16_t roomnum = MultiGetShort(data, &count);
4295 int16_t portalnum = MultiGetShort(data, &count);
4296 uint8_t flags = MultiGetByte(data, &count);
4297 Rooms[roomnum].portals[portalnum].flags = flags;
4298 break;
4299 }
4300 case WS_ROOM_DAMAGE: {
4301 // Room wind
4302 int16_t roomnum = MultiGetShort(data, &count);
4303 Rooms[roomnum].damage = MultiGetFloat(data, &count);
4304 Rooms[roomnum].damage_type = MultiGetUbyte(data, &count);
4305 break;
4306 }
4307 case WS_ROOM_GOALSPECFLAG: {
4308 // goals & special flags
4309 int16_t roomnum = MultiGetShort(data, &count);
4310 int mask = (RF_SPECIAL1 | RF_SPECIAL2 | RF_SPECIAL3 | RF_SPECIAL4 | RF_SPECIAL5 | RF_SPECIAL6 | RF_GOAL1 |
4311 RF_GOAL2 | RF_GOAL3 | RF_GOAL4);
4312 int change_mask = MultiGetInt(data, &count);
4313
4314 Rooms[roomnum].flags &= ~mask;
4315 Rooms[roomnum].flags |= change_mask;
4316
4317 break;
4318 }
4319 case WS_WAYPOINT: {
4320 Current_waypoint = MultiGetByte(data, &count);
4321 break;
4322 }
4323 case WS_BUDDYBOTS: {
4324 int b_index = MultiGetByte(data, &count);
4325 uint16_t serv_objnum = MultiGetUshort(data, &count);
4326 int local_objnum = Server_object_list[serv_objnum];
4327
4328 ASSERT(Objects[local_objnum].type != OBJ_NONE);
4329
4330 Buddy_handle[b_index] = Objects[local_objnum].handle;
4331
4332 // now add the guide to that player's inventory (if we need to)
4333 if ((!Players[b_index].inventory.CheckItem(OBJ_ROBOT, ROBOT_GUIDEBOT)) &&
4334 (ObjGet(Buddy_handle[b_index])->type != OBJ_ROBOT))
4335 Players[b_index].inventory.Add(OBJ_ROBOT, ROBOT_GUIDEBOT);
4336 break;
4337 }
4338 case WS_BUDDYBOTUPDATE: {
4339 int b_index = MultiGetByte(data, &count);
4340 uint16_t serv_objnum = MultiGetUshort(data, &count);
4341 int local_objnum = Server_object_list[serv_objnum];
4342
4343 ASSERT(Objects[local_objnum].type != OBJ_NONE);
4344
4345 Buddy_handle[b_index] = Objects[local_objnum].handle;
4346
4347 break;
4348 }
4349 case WS_PLAYERBF: {
4350 Players_typing = MultiGetUint(data, &count);
4351 break;
4352 }
4353 case WS_MOTD: {
4354 MultiGetString(Multi_message_of_the_day, data, &count);
4355 AddPersistentHUDMessage(GR_RGB(255, 255, 255), HUD_MSG_PERSISTENT_CENTER,
4356 Game_window_y + (Game_window_h / 2) - 20, 10, HPF_FADEOUT + HPF_FREESPACE_DRAW,
4357 SOUND_GOAL_COMPLETE, Multi_message_of_the_day);
4358 break;
4359 }
4360 case WS_WEATHER: {
4361 Weather.flags = MultiGetByte(data, &count);
4362 Weather.rain_intensity_scalar = MultiGetFloat(data, &count);
4363 Weather.snow_intensity_scalar = MultiGetFloat(data, &count);
4364 Weather.lightning_interval_time = MultiGetFloat(data, &count);
4365 Weather.lightning_rand_value = MultiGetShort(data, &count);
4366 break;
4367 }
4368 case WS_DOOR: {
4369 doorway *dp;
4370 int objnum = MultiGetShort(data, &count);
4371 objnum = Server_object_list[objnum];
4372 ASSERT(Objects[objnum].type == OBJ_DOOR);
4373 dp = GetDoorwayFromObject(Objects[objnum].handle);
4374
4375 int state = MultiGetByte(data, &count);
4376 uint8_t locked = MultiGetByte(data, &count);
4377 if (locked)
4378 dp->flags |= DF_LOCKED;
4379 else
4380 dp->flags &= ~DF_LOCKED;
4381
4382 if (state == DOORWAY_OPENING || state == DOORWAY_WAITING || dp->state == DOORWAY_OPENING_AUTO)
4383 DoorwayActivate(Objects[objnum].handle);
4384
4385 DoorwaySetPosition(Objects[objnum].handle, MultiGetFloat(data, &count));
4386
4387 break;
4388 }
4389 case WS_LIGHT_DISTANCE: {
4390 int objnum = MultiGetShort(data, &count);
4391 float val = MultiGetFloat(data, &count);
4392 objnum = Server_object_list[objnum];
4393
4394 if (objnum == 65535)
4395 break;
4396
4397 light_info *li = ObjGetLightInfo(&Objects[objnum]);
4398 if (li)
4399 li->light_distance = val;
4400
4401 break;
4402 }
4403 case WS_LIGHT_COLOR: {
4404 int objnum = MultiGetShort(data, &count);
4405 objnum = Server_object_list[objnum];
4406
4407 if (objnum == 65535)
4408 break;
4409
4410 light_info *li = ObjGetLightInfo(&Objects[objnum]);
4411 if (li) {
4412 li->red_light1 = MultiGetFloat(data, &count);
4413 li->green_light1 = MultiGetFloat(data, &count);
4414 li->blue_light1 = MultiGetFloat(data, &count);
4415 } else {
4416 MultiGetFloat(data, &count);
4417 MultiGetFloat(data, &count);
4418 MultiGetFloat(data, &count);
4419 }
4420
4421 break;
4422 }
4423 case WS_LEVELGOAL: {
4424 char name[256];
4425 int goal_index = MultiGetUshort(data, &count);
4426 int priority = MultiGetInt(data, &count);
4427
4428 uint8_t len = MultiGetByte(data, &count);
4429 memcpy(name, &data[count], len);
4430 count += len;
4431
4432 int flags = MultiGetInt(data, &count);
4433 int temp = 0xFFFFFFFF;
4434
4435 mprintf(0, "Recieved Level Goal World State: %d\n", goal_index);
4436 Level_goals.GoalSetName(goal_index, name);
4437 Level_goals.GoalStatus(goal_index, LO_CLEAR_SPECIFIED, &temp);
4438 Level_goals.GoalStatus(goal_index, LO_SET_SPECIFIED, &flags, false);
4439 Level_goals.GoalPriority(goal_index, LO_SET_SPECIFIED, &priority);
4440
4441 break;
4442 }
4443 case WS_SPEW: {
4444 spewinfo spew;
4445 mprintf(0, "Got a spew packet!\n");
4446
4447 uint16_t spewnum = MultiGetShort(data, &count);
4448
4449 if (MultiGetByte(data, &count))
4450 spew.use_gunpoint = true;
4451 else
4452 spew.use_gunpoint = false;
4453
4454 if (spew.use_gunpoint) {
4455 int objnum = MultiGetUshort(data, &count);
4456 objnum = Server_object_list[objnum];
4457 ASSERT(objnum != 65535);
4458 ASSERT(Objects[objnum].flags & OF_SERVER_OBJECT);
4459
4460 spew.gp.obj_handle = Objects[objnum].handle;
4461 spew.gp.gunpoint = MultiGetByte(data, &count);
4462 } else {
4463 // memcpy (&spew.pt.normal,&data[count],sizeof(vector));
4464 // count+=sizeof(vector);
4465 spew.pt.normal = MultiGetVector(data, &count);
4466 // memcpy (&spew.pt.origin,&data[count],sizeof(vector));
4467 // count+=sizeof(vector);
4468 spew.pt.origin = MultiGetVector(data, &count);
4469
4470 spew.pt.room_num = MultiGetInt(data, &count);
4471 }
4472
4473 spew.random = MultiGetByte(data, &count);
4474 if (MultiGetByte(data, &count))
4475 spew.real_obj = true;
4476 else
4477 spew.real_obj = false;
4478
4479 spew.effect_type = MultiGetByte(data, &count);
4480 spew.phys_info = MultiGetByte(data, &count);
4481 spew.drag = MultiGetFloat(data, &count);
4482 spew.mass = MultiGetFloat(data, &count);
4483
4484 spew.time_int = MultiGetFloat(data, &count);
4485 spew.longevity = MultiGetFloat(data, &count);
4486 spew.lifetime = MultiGetFloat(data, &count);
4487 spew.size = MultiGetFloat(data, &count);
4488 spew.speed = MultiGetFloat(data, &count);
4489
4490 uint16_t local_spewnum = SpewCreate(&spew);
4491 ASSERT(local_spewnum != -1); // DAJ -1FIX
4492 local_spewnum &= 0xFF; // Adjust for handle
4493 Server_spew_list[spewnum] = local_spewnum;
4494 mprintf(0, "Got spew of type %d. Server=%d local=%d\n", spew.effect_type, spewnum, local_spewnum);
4495
4496 break;
4497 }
4498 case WS_NO_RENDER: {
4499 int objnum = MultiGetShort(data, &count);
4500 objnum = Server_object_list[objnum];
4501
4502 if (objnum == 65535)
4503 break;
4504
4505 Objects[objnum].render_type = RT_NONE;
4506 break;
4507 }
4508
4509 case WS_OBJECT_PHYS_FLAGS: {
4510 int objnum = MultiGetShort(data, &count);
4511 int flags = MultiGetInt(data, &count);
4512 objnum = Server_object_list[objnum];
4513
4514 if (objnum == 65535)
4515 break;
4516 Objects[objnum].mtype.phys_info.flags = flags;
4517 break;
4518 }
4519
4520 case WS_OBJECT_ATTACH: {
4521 int parent_objnum = MultiGetUshort(data, &count);
4522 int n_attach = MultiGetByte(data, &count);
4523
4524 for (int i = 0; i < n_attach; i++) {
4525 int child_objnum = MultiGetUshort(data, &count);
4526 if (child_objnum != 65535) {
4527 float rad;
4528
4529 int attach_index = MultiGetByte(data, &count);
4530 int attach_type = MultiGetByte(data, &count);
4531
4532 if (attach_type == AT_RAD)
4533 rad = MultiGetFloat(data, &count);
4534
4535 child_objnum = Server_object_list[child_objnum];
4536 int local_objnum = Server_object_list[parent_objnum];
4537
4538 if (child_objnum != 65535 && local_objnum != 65535) {
4539 if (attach_type == AT_RAD) {
4540 AttachObject(&Objects[local_objnum], i, &Objects[child_objnum], rad);
4541 } else {
4542 bool aligned = (attach_type == AT_ALIGNED) ? true : false;
4543 AttachObject(&Objects[local_objnum], i, &Objects[child_objnum], attach_index, aligned);
4544 }
4545 }
4546 }
4547 }
4548 } break;
4549
4550 default:
4551 Int3(); // Unrecognized world state type, get Jason!
4552 break;
4553 }
4554 }
4555 }
4556
4557 void MultiDoJoinDemoObjects(uint8_t *data) {
4558 int count = 0;
4559
4560 SKIP_HEADER(data, &count);
4561
4562 int num_demo_objects = MultiGetUshort(data, &count);
4563 int objnum;
4564 int local_objnum;
4565
4566 Multi_Expect_demo_object_flags = true;
4567 mprintf(0, "Processing DoJoinDemoObjects...\n");
4568
4569 for (int i = 0; i < num_demo_objects; i++) {
4570 objnum = MultiGetUshort(data, &count);
4571
4572 ASSERT(objnum >= 0 && objnum < MAX_OBJECTS);
4573
4574 local_objnum = Server_object_list[objnum];
4575
4576 ASSERT(local_objnum >= 0 && local_objnum < MAX_OBJECTS);
4577 ASSERT(Objects[local_objnum].type != OBJ_NONE);
4578
4579 Objects[local_objnum].flags |= OF_CLIENTDEMOOBJECT;
4580 }
4581 }
4582
4583 // Server is telling us about objects in the game
4584 void MultiDoJoinObjects(uint8_t *data) {
4585 int count = 0;
4586
4587 SKIP_HEADER(data, &count);
4588 uint8_t num_objects = MultiGetByte(data, &count);
4589
4590 mprintf(0, "Got join object packet. Num objects=%d\n", num_objects);
4591
4592 for (int i = 0; i < num_objects; i++) {
4593 bool obj_is_dummy = false;
4594
4595 // Extract info about this object
4596 uint16_t server_objnum = MultiGetUshort(data, &count);
4597 uint8_t type = MultiGetByte(data, &count);
4598
4599 //@@mprintf(0,"Got join objnum %d from server. Type=%d\n",server_objnum,type);
4600
4601 if (type == OBJ_DUMMY) {
4602 obj_is_dummy = true;
4603 type = MultiGetByte(data, &count);
4604 }
4605
4606 uint32_t checksum;
4607 matrix orient;
4608 uint8_t name_len = 0;
4609 uint8_t num_persist_vars = 0;
4610
4611 vm_MakeIdentity(&orient);
4612
4613 if (type != OBJ_CAMERA && type != OBJ_DOOR) {
4614 // Get checksum
4615 checksum = MultiGetUint(data, &count);
4616 }
4617
4618 if (type != OBJ_POWERUP && type != OBJ_DOOR) {
4619 multi_orientation multi_mat;
4620
4621 // Get orientation
4622 memcpy(&multi_mat, &data[count], sizeof(multi_orientation));
4623 MultiMatrixMakeEndianFriendly(&multi_mat);
4624 MultiExtractMatrix(&orient, &multi_mat);
4625 count += sizeof(multi_orientation);
4626 }
4627
4628 int id;
4629
4630 if (type != OBJ_CAMERA && type != OBJ_MARKER && type != OBJ_DOOR) {
4631 id = MultiMatchGeneric(checksum);
4632
4633 if (id == -1) {
4634 mprintf(0, "Server data doesn't match client data!\n");
4635 ASSERT(1);
4636 // Error ("Server data doesn't match client data!");
4637 MultiMatchGeneric(checksum);
4638 } else {
4639 MULTI_ASSERT(Object_info[id].type == type, "DoJoinObjects type mismatch!"); // Get Jason!
4640 }
4641 } else if (type == OBJ_MARKER) {
4642 id = checksum;
4643 } else // camera
4644 id = 0;
4645
4646 vector pos;
4647 uint16_t short_roomnum;
4648 uint8_t terrain = 0;
4649 uint8_t lifeleft = 255;
4650 int roomnum;
4651
4652 if (type != OBJ_DOOR) {
4653 // memcpy (&pos,&data[count],sizeof(vector));
4654 // count+=sizeof(vector);
4655 pos = MultiGetVector(data, &count);
4656
4657 short_roomnum = MultiGetUshort(data, &count);
4658 terrain = MultiGetByte(data, &count);
4659 lifeleft = MultiGetUbyte(data, &count);
4660
4661 roomnum = short_roomnum;
4662 }
4663
4664 if (type == OBJ_MARKER) {
4665 // Get message if marker
4666 uint8_t len = MultiGetByte(data, &count);
4667 memcpy(MarkerMessages[id], &data[count], len);
4668 count += len;
4669 }
4670
4671 if (terrain)
4672 roomnum = MAKE_ROOMNUM(roomnum);
4673
4674 int local_objnum;
4675
4676 // Don't recreate lightmap objects
4677 if (type != OBJ_DOOR && (type == OBJ_CAMERA || type == OBJ_MARKER ||
4678 Object_info[id].lighting_info.lighting_render_type != LRT_LIGHTMAPS)) {
4679 local_objnum = ObjCreate(type, id, roomnum, &pos, &orient);
4680 } else {
4681
4682 ASSERT(type == Objects[server_objnum].type);
4683 if (type != OBJ_DOOR)
4684 ObjSetPos(&Objects[server_objnum], &pos, roomnum, &orient, false);
4685 local_objnum = server_objnum;
4686
4687 if (type == OBJ_DOOR ||
4688 (type != OBJ_CAMERA && Object_info[id].lighting_info.lighting_render_type == LRT_LIGHTMAPS)) {
4689 Server_lightmap_list[Num_server_lm_objects] = server_objnum;
4690 Num_server_lm_objects++;
4691 }
4692 }
4693
4694 if (local_objnum < 0) {
4695 Error("Ran out of objects!");
4696 return;
4697 }
4698
4699 if (lifeleft != 255) {
4700 Objects[local_objnum].flags |= OF_USES_LIFELEFT;
4701 Objects[local_objnum].lifeleft = lifeleft;
4702 }
4703
4704 // Put it in our lists
4705 Local_object_list[local_objnum] = server_objnum;
4706 Server_object_list[server_objnum] = local_objnum;
4707
4708 //?? InitObjectScripts (&Objects[local_objnum],false);
4709
4710 // Ghost the object if it is a dummy
4711 if (obj_is_dummy) {
4712 ObjGhostObject(local_objnum);
4713 }
4714
4715 Objects[local_objnum].flags |= OF_SERVER_OBJECT;
4716 }
4717 }
4718
4719 // Starts a death sequence of a player
4720 void MultiDoPlayerDead(uint8_t *data) {
4721 int count = 0;
4722
4723 SKIP_HEADER(data, &count);
4724 int slot = MultiGetByte(data, &count);
4725 int fate = MultiGetByte(data, &count);
4726
4727 Players[slot].damage_magnitude = 0;
4728 Players[slot].edrain_magnitude = 0;
4729
4730 InitiatePlayerDeath(&Objects[Players[slot].objnum], false, fate);
4731 if (Objects[Players[slot].objnum].effect_info->sound_handle != SOUND_NONE_INDEX) {
4732 Sound_system.StopSoundLooping(Objects[Players[slot].objnum].effect_info->sound_handle);
4733 Objects[Players[slot].objnum].effect_info->sound_handle = SOUND_NONE_INDEX;
4734 }
4735 }
4736
4737 // The server sends to everyone that the player is dead
4738 void MultiSendPlayerDead(int slot, uint8_t fate) {
4739 MULTI_ASSERT(Netgame.local_role == LR_SERVER, "Client in SendPlayerDead!");
4740 uint8_t data[MAX_GAME_DATA_SIZE];
4741 int count = 0;
4742 int size_offset;
4743
4744 size_offset = START_DATA(MP_PLAYER_DEAD, data, &count, 1);
4745 MultiAddByte(slot, data, &count);
4746 MultiAddByte(fate, data, &count);
4747 END_DATA(count, data, size_offset);
4748
4749 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_PLAYERS);
4750 MultiDoPlayerDead(data);
4751 if (Game_is_master_tracker_game) {
4752 mprintf(0, "Adding kill and death to player stats. Killer = %d Killee = %d\n",
4753 Objects[Players[slot].killer_objnum].id,
4754 slot);
4755 if (Objects[Players[slot].killer_objnum].id == slot) {
4756 Players[slot].suicides++;
4757 } else {
4758 Players[Objects[Players[slot].killer_objnum].id].kills++;
4759 Players[slot].deaths++;
4760 }
4761 }
4762 if (Objects[Players[slot].killer_objnum].id == slot) {
4763 Multi_deaths[slot]++;
4764 } else {
4765 Multi_kills[Objects[Players[slot].killer_objnum].id]++;
4766 Multi_deaths[slot]++;
4767 }
4768 ScoreAPIPlayerKilled(Objects[Players[slot].killer_objnum].id, slot);
4769 }
4770
4771 // A player is coming back from the dead...restore his ship!
4772 void MultiDoRenewPlayer(uint8_t *data) {
4773 int count = 0;
4774 bool add_guidebot = false;
4775
4776 SKIP_HEADER(data, &count);
4777 uint8_t slot = MultiGetByte(data, &count);
4778 int start_slot = MultiGetShort(data, &count);
4779
4780 if (MultiGetByte(data, &count)) {
4781 add_guidebot = true;
4782 }
4783
4784 EndPlayerDeath(slot);
4785
4786 PlayerMoveToStartPos(slot, start_slot);
4787 MultiAnnounceEffect(&Objects[Players[slot].objnum], Objects[Players[slot].objnum].size * 5, 1.0);
4788
4789 // Make him invul for 2 seconds
4790 MakePlayerInvulnerable(slot, 2.0);
4791
4792 // add guidebot if needed
4793 if (add_guidebot) {
4794 mprintf(0, "MULTI: Adding guidebot to respawned player (%s)\n", Players[slot].callsign);
4795 if (!Players[slot].inventory.CheckItem(OBJ_ROBOT, ROBOT_GUIDEBOT))
4796 Players[slot].inventory.Add(OBJ_ROBOT, ROBOT_GUIDEBOT);
4797 }
4798
4799 // Update player position in demo
4800 if (Demo_flags == DF_RECORDING) {
4801 DemoWriteChangedObj(&Objects[Players[slot].objnum]);
4802 }
4803 }
4804
4805 // Tell everyone that a player is coming back from the dead
4806 void MultiSendRenewPlayer(int slot) {
4807 MULTI_ASSERT(Netgame.local_role == LR_SERVER, "Client in SendRenewPlayer!");
4808
4809 uint8_t data[MAX_GAME_DATA_SIZE];
4810 int count = 0;
4811 int size_offset;
4812
4813 size_offset = START_DATA(MP_RENEW_PLAYER, data, &count, 1);
4814 MultiAddByte(slot, data, &count);
4815
4816 // Get random start slot
4817 int start_slot = PlayerGetRandomStartPosition(slot);
4818 MultiAddShort(start_slot, data, &count);
4819
4820 Player_pos_fix[slot].active = true;
4821 Player_pos_fix[slot].expire_time = Gametime + PLAYER_POS_HACK_TIME;
4822 Player_pos_fix[slot].room = Players[start_slot].start_roomnum;
4823 Player_pos_fix[slot].ignored_pos = 0;
4824
4825 // check to see if they need to add a guidebot to the player's inventory
4826 if (Netgame.flags & NF_ALLOWGUIDEBOT) {
4827 if ((!Players[slot].inventory.CheckItem(OBJ_ROBOT, ROBOT_GUIDEBOT)) &&
4828 (ObjGet(Buddy_handle[slot])->type != OBJ_ROBOT)) {
4829 MultiAddByte(1, data, &count);
4830 } else {
4831 MultiAddByte(0, data, &count);
4832 }
4833 } else {
4834 MultiAddByte(0, data, &count);
4835 }
4836
4837 END_DATA(count, data, size_offset);
4838
4839 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_PLAYERS, false);
4840
4841 MultiDoRenewPlayer(data);
4842 }
4843
4844 // This player says he's done dying
4845 void MultiDoEndPlayerDeath(uint8_t *data) {
4846 MULTI_ASSERT(Netgame.local_role == LR_SERVER, "Client in DoEndPlayerDeath!");
4847
4848 int count = 0;
4849
4850 SKIP_HEADER(data, &count);
4851 uint8_t slot = MultiGetByte(data, &count);
4852
4853 if (Players[slot].flags & PLAYER_FLAGS_DEAD || Players[slot].flags & PLAYER_FLAGS_DYING)
4854 MultiSendRenewPlayer(slot);
4855 }
4856 void GetServerGameTime() {
4857 MULTI_ASSERT(Netgame.local_role != LR_SERVER, "Server in GetServerGameTime!");
4858 uint8_t outdata[MAX_GAME_DATA_SIZE];
4859 int count = 0;
4860 int size;
4861 mprintf(0, "Requesting gametime from server\n");
4862 Got_new_game_time = 0;
4863 size = START_DATA(MP_GET_GAMETIME, outdata, &count);
4864 MultiAddFloat(timer_GetTime(), outdata, &count);
4865 END_DATA(count, outdata, size);
4866 nw_Send(&Netgame.server_address, outdata, count, 0);
4867 }
4868 void MultiDoGameTimeReq(uint8_t *data, network_address *from_addr) {
4869 uint8_t outdata[MAX_GAME_DATA_SIZE];
4870 int count = 0;
4871 int incount = 0;
4872 int size;
4873
4874 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
4875 mprintf(0, "Processing request for gametime\n");
4876 SKIP_HEADER(data, &incount);
4877 float client_time = MultiGetFloat(data, &incount);
4878
4879 size = START_DATA(MP_HERE_IS_GAMETIME, outdata, &count);
4880 MultiAddFloat(client_time, outdata, &count);
4881 MultiAddFloat(Gametime, outdata, &count);
4882
4883 END_DATA(count, outdata, size);
4884
4885 nw_Send(from_addr, outdata, count, 0);
4886 }
4887
4888 void MultiDoSetGameTime(uint8_t *data) {
4889 float req_time;
4890 float server_latency;
4891 float server_game_time;
4892 int count = 0;
4893 mprintf(0, "Processing and setting new for gametime\n");
4894 MULTI_ASSERT_NOMESSAGE(Netgame.local_role != LR_SERVER);
4895 // Now get the latency. We calculate this by comparing the current timer to the time we got back
4896 // Which was the time that we sent the request.
4897 SKIP_HEADER(data, &count);
4898 req_time = MultiGetFloat(data, &count);
4899 server_game_time = MultiGetFloat(data, &count);
4900
4901 // Half of the ping time is the latency
4902 server_latency = (timer_GetTime() - req_time) / 2;
4903 mprintf(0, "Server Latency = %f\n", server_latency);
4904
4905 Gametime = (server_game_time + server_latency);
4906 mprintf(0, "New gametime = %f\n", Gametime);
4907 Got_new_game_time = 1;
4908 }
4909
4910 // Tell the server that I'm done dying
4911 void MultiSendEndPlayerDeath() {
4912 int count = 0;
4913 uint8_t data[MAX_GAME_DATA_SIZE];
4914 int size_offset;
4915
4916 mprintf(0, "Sending end player death packet!\n");
4917
4918 size_offset = START_DATA(MP_END_PLAYER_DEATH, data, &count);
4919
4920 MultiAddByte(Player_num, data, &count);
4921 END_DATA(count, data, size_offset);
4922
4923 if (Netgame.local_role == LR_CLIENT)
4924 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count, false);
4925 else
4926 MultiDoEndPlayerDeath(data);
4927 }
4928
4929 // Prints out a message we got from the server
4930 void MultiDoMessageFromServer(uint8_t *data) {
4931 static int sound_id = -2;
4932 int count = 0;
4933 char message[255];
4934
4935 SKIP_HEADER(data, &count);
4936
4937 ddgr_color color = MultiGetInt(data, &count);
4938 uint8_t len = MultiGetByte(data, &count);
4939
4940 memcpy(message, &data[count], len);
4941 count += len;
4942
4943 // Play the player hud message sound
4944 if (sound_id == -2) {
4945 sound_id = FindSoundName("Hudmessage");
4946 }
4947
4948 if (sound_id > -1) {
4949 Sound_system.Play2dSound(sound_id);
4950 }
4951
4952 AddColoredHUDMessage(color, "%s", message); // added "%s" because message could have % signs, formatting issue.
4953 }
4954
4955 // Sends a message from the server to the client
4956 void MultiSendMessageFromServer(int color, char *message, int to) {
4957 int count = 0;
4958 uint8_t data[MAX_GAME_DATA_SIZE];
4959 int size_offset;
4960
4961 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
4962
4963 size_offset = START_DATA(MP_MESSAGE_FROM_SERVER, data, &count, 1);
4964 MultiAddInt(color, data, &count);
4965
4966 uint8_t len = strlen(message) + 1;
4967
4968 MultiAddByte(len, data, &count);
4969
4970 memcpy(&data[count], message, len);
4971
4972 count += len;
4973
4974 END_DATA(count, data, size_offset);
4975
4976 if (to == MULTI_SEND_MESSAGE_ALL) {
4977 MultiSendReliablyToAllExcept(Player_num, data, count, false);
4978 MultiDoMessageFromServer(data);
4979 } else {
4980 int team = -1;
4981
4982 switch (to) {
4983 case MULTI_SEND_MESSAGE_RED_TEAM:
4984 team = 0;
4985 break;
4986 case MULTI_SEND_MESSAGE_BLUE_TEAM:
4987 team = 1;
4988 break;
4989 case MULTI_SEND_MESSAGE_GREEN_TEAM:
4990 team = 2;
4991 break;
4992 case MULTI_SEND_MESSAGE_YELLOW_TEAM:
4993 team = 3;
4994 break;
4995 }
4996
4997 if (team == -1) {
4998 // send it off to one person
4999 if (to >= 0 && to < MAX_PLAYERS) {
5000 if (NetPlayers[to].flags & NPF_CONNECTED && NetPlayers[to].sequence == NETSEQ_PLAYING && to != Player_num) {
5001 nw_SendReliable(NetPlayers[to].reliable_socket, data, count, false);
5002 }
5003 }
5004 if (to == Player_num)
5005 MultiDoMessageFromServer(data);
5006 } else {
5007 // send it off only to teammates
5008 for (int p = 0; p < MAX_PLAYERS; p++) {
5009 if (NetPlayers[p].flags & NPF_CONNECTED && NetPlayers[p].sequence == NETSEQ_PLAYING &&
5010 Players[p].team == team && p != Player_num) {
5011
5012 nw_SendReliable(NetPlayers[p].reliable_socket, data, count, false);
5013 }
5014 }
5015 if (team == Players[Player_num].team)
5016 MultiDoMessageFromServer(data);
5017 }
5018 }
5019 }
5020
5021 // Prints out a message we got from the server
5022 void MultiDoMessageToServer(uint8_t *data) {
5023 int count = 0;
5024 char message[255];
5025
5026 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
5027 SKIP_HEADER(data, &count);
5028
5029 uint8_t slot = MultiGetByte(data, &count);
5030 int towho = (int8_t)MultiGetByte(data, &count);
5031 uint8_t len = MultiGetByte(data, &count);
5032
5033 memcpy(message, &data[count], len);
5034 count += len;
5035
5036 MultiSendMessageFromServer(GR_RGB(0, 128, 255), message, towho);
5037 }
5038
5039 // Sends a message from the server to the client
5040 void MultiSendMessageToServer(int color, char *message, int to_who) {
5041 int count = 0;
5042 uint8_t data[MAX_GAME_DATA_SIZE];
5043 int size_offset;
5044
5045 size_offset = START_DATA(MP_MESSAGE_TO_SERVER, data, &count);
5046 MultiAddByte(Player_num, data, &count);
5047 MultiAddByte(to_who, data, &count);
5048
5049 uint8_t len = strlen(message) + 1;
5050
5051 MultiAddByte(len, data, &count);
5052
5053 memcpy(&data[count], message, len);
5054
5055 count += len;
5056
5057 END_DATA(count, data, size_offset);
5058
5059 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count, false);
5060 }
5061
5062 // Executes a dll that the server says to
5063 void MultiDoExecuteDLL(uint8_t *data) {
5064 int count = 0;
5065 float fParam = 0;
5066 ptrdiff_t iParam = 0;
5067
5068 SKIP_HEADER(data, &count);
5069
5070 uint16_t eventnum = MultiGetShort(data, &count);
5071 int16_t me_objnum = MultiGetShort(data, &count);
5072 int16_t it_objnum = MultiGetShort(data, &count);
5073
5074 if (MultiGetByte(data, &count)) {
5075 // we need to extract out parameters
5076 fParam = MultiGetFloat(data, &count);
5077 iParam = MultiGetInt(data, &count);
5078
5079 switch (eventnum) {
5080 case EVT_CLIENT_GAMEWALLCOLLIDE:
5081 case EVT_GAMEWALLCOLLIDE:
5082 DLLInfo.collide_info.point.x = MultiGetFloat(data, &count);
5083 DLLInfo.collide_info.point.y = MultiGetFloat(data, &count);
5084 DLLInfo.collide_info.point.z = MultiGetFloat(data, &count);
5085 DLLInfo.collide_info.normal.x = MultiGetFloat(data, &count);
5086 DLLInfo.collide_info.normal.y = MultiGetFloat(data, &count);
5087 DLLInfo.collide_info.normal.z = MultiGetFloat(data, &count);
5088 DLLInfo.collide_info.hitspeed = MultiGetFloat(data, &count);
5089 DLLInfo.collide_info.hit_dot = MultiGetFloat(data, &count);
5090 DLLInfo.collide_info.hitseg = MultiGetInt(data, &count);
5091 DLLInfo.collide_info.hitwall = MultiGetInt(data, &count);
5092 break;
5093 case EVT_CLIENT_GAMECOLLIDE:
5094 case EVT_GAMECOLLIDE:
5095 DLLInfo.collide_info.point.x = MultiGetFloat(data, &count);
5096 DLLInfo.collide_info.point.y = MultiGetFloat(data, &count);
5097 DLLInfo.collide_info.point.z = MultiGetFloat(data, &count);
5098 DLLInfo.collide_info.normal.x = MultiGetFloat(data, &count);
5099 DLLInfo.collide_info.normal.y = MultiGetFloat(data, &count);
5100 DLLInfo.collide_info.normal.z = MultiGetFloat(data, &count);
5101 break;
5102 case EVT_GAMEOBJCHANGESEG:
5103 case EVT_CLIENT_GAMEOBJCHANGESEG:
5104 case EVT_GAMEPLAYERCHANGESEG:
5105 case EVT_CLIENT_GAMEPLAYERCHANGESEG:
5106 DLLInfo.newseg = MultiGetInt(data, &count);
5107 DLLInfo.oldseg = MultiGetInt(data, &count);
5108 break;
5109 }
5110 }
5111
5112 int16_t local_me_objnum;
5113 int16_t local_it_objnum;
5114
5115 if (me_objnum == -1)
5116 local_me_objnum = -1;
5117 else {
5118 local_me_objnum = Server_object_list[me_objnum];
5119 if (local_me_objnum == 65535) {
5120 mprintf(0, "Invalid object in DoExecuteDLL!\n");
5121 Int3();
5122 return;
5123 }
5124 }
5125
5126 if (it_objnum == -1)
5127 local_it_objnum = -1;
5128 else {
5129 local_it_objnum = Server_object_list[it_objnum];
5130 if (local_it_objnum == 65535) {
5131 mprintf(0, "Invalid object in DoExecuteDLL!\n");
5132 Int3();
5133 return;
5134 }
5135 }
5136
5137 // mprintf(0,"Received MP_EXECUTE_DLL packet! type=%d
5138 // id=%d\n",Objects[local_me_objnum].type,Objects[local_me_objnum].id);
5139
5140 int mehandle;
5141 int ithandle;
5142
5143 if (local_me_objnum == -1)
5144 mehandle = OBJECT_HANDLE_NONE;
5145 else
5146 mehandle = Objects[local_me_objnum].handle;
5147
5148 if (local_it_objnum == -1)
5149 ithandle = OBJECT_HANDLE_NONE;
5150 else
5151 ithandle = Objects[local_it_objnum].handle;
5152
5153 DLLInfo.me_handle = mehandle;
5154 DLLInfo.it_handle = ithandle;
5155 DLLInfo.fParam = fParam;
5156 DLLInfo.iParam = iParam;
5157
5158 CallGameDLL(eventnum, &DLLInfo);
5159 }
5160
5161 // Server is telling us to create an object
5162 void MultiDoObject(uint8_t *data) {
5163 int count = 0;
5164 int parent_handle;
5165 bool self_parent = false;
5166
5167 SKIP_HEADER(data, &count);
5168
5169 // Extract info about this object
5170 uint8_t announce = MultiGetByte(data, &count);
5171 int server_objnum = MultiGetUshort(data, &count);
5172 int parent_objnum = MultiGetUshort(data, &count);
5173
5174 if (parent_objnum == server_objnum)
5175 self_parent = true;
5176 /*
5177 mprintf(0,"MultiDoObject() got a new object. Server's objnum = %d Parent objnum = %d\n",
5178 server_objnum,
5179 parent_objnum);
5180 */
5181 if (self_parent || parent_objnum == 65535)
5182 parent_handle = OBJECT_HANDLE_NONE;
5183 else {
5184 int local_parent = Server_object_list[parent_objnum];
5185
5186 if (local_parent == 65535) // || !(Objects[local_parent].flags2 & OF2_SERVER_OBJECT))
5187 {
5188 MULTI_ASSERT(1, "Invalid parent for object!");
5189 return;
5190 }
5191
5192 parent_handle = Objects[local_parent].handle;
5193 }
5194
5195 uint8_t type = MultiGetByte(data, &count);
5196 uint32_t checksum = MultiGetUint(data, &count);
5197 uint8_t dummy_type = OBJ_NONE;
5198 if (type == OBJ_DUMMY) // we need to get the original type
5199 dummy_type = MultiGetByte(data, &count);
5200
5201 /*char name[255];
5202 uint8_t len=MultiGetByte (data,&count);
5203 memcpy (name,&data[count],len);*/
5204
5205 int id;
5206 if (type == OBJ_WEAPON)
5207 id = MultiMatchWeapon(checksum);
5208 else if (type == OBJ_MARKER)
5209 id = checksum;
5210 else
5211 id = MultiMatchGeneric(checksum);
5212
5213 if (id == -1) {
5214 mprintf(0, "Server data doesn't match!\n");
5215 MULTI_ASSERT(id != -1, "Server data doesn't match!");
5216
5217 if (type == OBJ_WEAPON)
5218 MultiMatchWeapon(checksum);
5219 else if (type != OBJ_MARKER)
5220 MultiMatchGeneric(checksum);
5221
5222 return;
5223 } else {
5224 if (type != OBJ_WEAPON && type != OBJ_MARKER) {
5225 if (Object_info[id].type != type) {
5226 BailOnMultiplayer(TXT_MULTI_CORRUPTOBJ);
5227 return;
5228 }
5229 }
5230 }
5231
5232 vector pos, vel;
5233 matrix orient, *orientp = NULL;
5234
5235 // Extract position
5236 // memcpy (&pos,&data[count],sizeof(vector));
5237 // count+=sizeof(vector);
5238 pos = MultiGetVector(data, &count);
5239
5240 // Extract velocity
5241 // memcpy (&vel,&data[count],sizeof(vector));
5242 // count+=sizeof(vector);
5243 vel = MultiGetVector(data, &count);
5244
5245 if (type != OBJ_POWERUP && type != OBJ_DUMMY) {
5246 // Extract orientation
5247 uint16_t p = MultiGetShort(data, &count);
5248 uint16_t h = MultiGetShort(data, &count);
5249 uint16_t b = MultiGetShort(data, &count);
5250
5251 vm_AnglesToMatrix(&orient, p, h, b);
5252 orientp = &orient;
5253 }
5254
5255 // Get movement type
5256 uint8_t mtype = MultiGetByte(data, &count);
5257
5258 // Get room/cell stuff
5259 uint16_t short_roomnum = MultiGetUshort(data, &count);
5260 uint8_t terrain = MultiGetByte(data, &count);
5261 uint8_t lifeleft = MultiGetUbyte(data, &count);
5262 int roomnum = short_roomnum;
5263
5264 if (terrain)
5265 roomnum = MAKE_ROOMNUM(roomnum);
5266
5267 int local_objnum;
5268
5269 if (type != OBJ_DUMMY)
5270 local_objnum = ObjCreate(type, id, roomnum, &pos, orientp, parent_handle);
5271 else {
5272 MULTI_ASSERT_NOMESSAGE(dummy_type != OBJ_NONE && dummy_type != OBJ_DUMMY);
5273 local_objnum = ObjCreate(dummy_type, id, roomnum, &pos, orientp, parent_handle);
5274 if (local_objnum >= 0)
5275 ObjGhostObject(local_objnum);
5276 }
5277
5278 if (local_objnum < 0) {
5279 mprintf(0, "Ran out of objects!\n");
5280 Int3(); // Get Jason
5281 return;
5282 }
5283
5284 object *obj = &Objects[local_objnum];
5285
5286 if (obj->type != OBJ_WEAPON)
5287 obj->flags |= OF_SERVER_OBJECT;
5288 obj->movement_type = mtype;
5289 obj->mtype.phys_info.velocity = vel;
5290 if (lifeleft != 255) {
5291 obj->flags |= OF_USES_LIFELEFT;
5292 obj->lifeleft = lifeleft;
5293 }
5294 DemoWriteObjLifeLeft(obj);
5295
5296 obj->render_type = MultiGetByte(data, &count);
5297
5298 if (obj->type == OBJ_MARKER) {
5299 // Get message if marker
5300 uint8_t len = MultiGetByte(data, &count);
5301 memcpy(MarkerMessages[obj->id], &data[count], len);
5302 count += len;
5303 }
5304 bool demo_record = false;
5305
5306 if (Multi_Expect_demo_object_flags) {
5307 // if Multi_Expect_demo_object_flags is false that means that
5308 // OEM 1.0 is the server and so it won't be packing this data at
5309 // the end
5310 demo_record = (MultiGetByte(data, &count) == 0xBE) ? true : false;
5311 }
5312
5313 // Put it in our lists
5314 if (obj->type != OBJ_WEAPON) {
5315 Local_object_list[local_objnum] = server_objnum;
5316 Server_object_list[server_objnum] = local_objnum;
5317 }
5318
5319 if (announce) // Do effect to announce
5320 {
5321 Sound_system.Play3dSound(SOUND_WALL_FADE, obj);
5322 CreateRandomSparks(20, &obj->pos, obj->roomnum);
5323
5324 MultiAnnounceEffect(obj, obj->size * 3, .7f);
5325 }
5326
5327 // Create the scripts for it
5328 InitObjectScripts(&Objects[local_objnum]);
5329
5330 if (type == OBJ_MARKER) {
5331 if (parent_handle == Objects[Players[Player_num].objnum].handle)
5332 Players[Player_num].num_markers++;
5333 }
5334
5335 if (demo_record) {
5336 obj->flags |= OF_CLIENTDEMOOBJECT;
5337
5338 if (Demo_flags == DF_RECORDING) {
5339 mprintf(0, "Recording object created on server\n");
5340 // DemoWriteObjCreate(obj->type,obj->id,obj->roomnum,&obj->pos,&obj->orient,obj->parent_handle,obj);
5341 }
5342 }
5343
5344 // mprintf(0,"MultiDoObject() Local objnum = %d\n",Server_object_list[server_objnum]);
5345 }
5346
5347 // Sends an object from the server to the client
5348 void MultiSendObject(object *obj, uint8_t announce, uint8_t demo_record) {
5349 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
5350
5351 int count = 0;
5352 uint8_t data[MAX_GAME_DATA_SIZE];
5353 int size_offset;
5354
5355 if (obj->type != OBJ_WEAPON)
5356 obj->flags |= OF_CLIENT_KNOWS;
5357
5358 if (demo_record)
5359 obj->flags |= OF_CLIENTDEMOOBJECT;
5360
5361 // mprintf(0,"Telling clients to CREATE object %d type=%d\n",obj-Objects,obj->type);
5362
5363 object *parent_obj = ObjGetUltimateParent(obj);
5364
5365 size_offset = START_DATA(MP_OBJECT, data, &count, 1);
5366
5367 uint32_t index = MultiGetMatchChecksum(obj->type, obj->id);
5368
5369 // Send server object number
5370 MultiAddByte(announce, data, &count);
5371 MultiAddUshort(obj - Objects, data, &count);
5372
5373 // Add parent
5374 if (obj->parent_handle == OBJECT_HANDLE_NONE)
5375 MultiAddUshort(65535, data, &count);
5376 else
5377 MultiAddUshort((obj->parent_handle & HANDLE_OBJNUM_MASK), data, &count); // Add parent
5378
5379 MultiAddByte(obj->type, data, &count);
5380 MultiAddUint(index, data, &count);
5381 // If it's a ghost object (type==OBJ_DUMMY) send it's old type
5382 if (obj->type == OBJ_DUMMY)
5383 MultiAddByte(obj->dummy_type, data, &count);
5384
5385 // Send position
5386 // memcpy (&data[count],&obj->pos,sizeof(vector));
5387 // count+=sizeof(vector);
5388 MultiAddVector(obj->pos, data, &count);
5389
5390 // Send velocity
5391 // memcpy (&data[count],&obj->mtype.phys_info.velocity,sizeof(vector));
5392 // count+=sizeof(vector);
5393 MultiAddVector(obj->mtype.phys_info.velocity, data, &count);
5394
5395 if (obj->type != OBJ_POWERUP && obj->type != OBJ_DUMMY) {
5396 // Send over orientation
5397 angvec angs;
5398 vm_ExtractAnglesFromMatrix(&angs, &obj->orient);
5399
5400 MultiAddShort(angs.p, data, &count);
5401 MultiAddShort(angs.h, data, &count);
5402 MultiAddShort(angs.b, data, &count);
5403 }
5404
5405 // Send movement type
5406 MultiAddByte(obj->movement_type, data, &count);
5407
5408 // Send room number and terrain flag
5409 MultiAddUshort(CELLNUM(obj->roomnum), data, &count);
5410
5411 if (OBJECT_OUTSIDE(obj))
5412 MultiAddByte(1, data, &count);
5413 else
5414 MultiAddByte(0, data, &count);
5415
5416 if (obj->flags & OF_USES_LIFELEFT) {
5417 MULTI_ASSERT_NOMESSAGE(obj->lifeleft < 255);
5418 MultiAddUbyte(obj->lifeleft, data, &count);
5419 } else
5420 MultiAddByte(255, data, &count);
5421
5422 MultiAddByte(obj->render_type, data, &count);
5423
5424 if (obj->type == OBJ_MARKER) {
5425 // Add marker message to the end of this
5426 uint8_t len = strlen(MarkerMessages[obj->id]) + 1;
5427 MultiAddByte(len, data, &count);
5428 memcpy(data + count, MarkerMessages[obj->id], len);
5429 count += len;
5430 }
5431
5432 MultiAddByte((demo_record) ? 0xBE : 0, data, &count);
5433
5434 END_DATA(count, data, size_offset);
5435
5436 if (announce) // Do effect to announce
5437 {
5438 Sound_system.Play3dSound(SOUND_WALL_FADE, obj);
5439 CreateRandomSparks(20, &obj->pos, obj->roomnum);
5440
5441 MultiAnnounceEffect(obj, obj->size * 3, .7f);
5442 }
5443 // mprintf(0,"Sending object %d to clients.\n",OBJNUM(obj));
5444 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_OBJECTS, true);
5445 }
5446
5447 void MultiDoGuidedInfo(uint8_t *data) {
5448 int count = 0;
5449
5450 // Skip header stuff
5451 SKIP_HEADER(data, &count);
5452
5453 uint8_t slot = MultiGetByte(data, &count);
5454 uint8_t release = MultiGetByte(data, &count);
5455
5456 if (Players[slot].guided_obj == NULL)
5457 return;
5458
5459 object *obj = Players[slot].guided_obj;
5460
5461 vector pos;
5462 matrix orient;
5463 uint16_t short_roomnum;
5464 int roomnum;
5465
5466 MultiExtractPositionData(&pos, data, &count);
5467
5468 // Get orientation
5469 uint16_t p = MultiGetShort(data, &count);
5470 uint16_t h = MultiGetShort(data, &count);
5471 uint16_t b = MultiGetShort(data, &count);
5472
5473 vm_AnglesToMatrix(&orient, p, h, b);
5474
5475 // Get room and terrain flag
5476 short_roomnum = MultiGetUshort(data, &count);
5477 uint8_t terrain = MultiGetByte(data, &count);
5478
5479 roomnum = short_roomnum;
5480 if (terrain)
5481 roomnum = MAKE_ROOMNUM(roomnum);
5482
5483 // Get velocity
5484 vector vel;
5485 vel.x = ((float)MultiGetShort(data, &count)) / 128.0;
5486 vel.y = ((float)MultiGetShort(data, &count)) / 128.0;
5487 vel.z = ((float)MultiGetShort(data, &count)) / 128.0;
5488
5489 obj->mtype.phys_info.velocity = vel;
5490
5491 ObjSetPos(obj, &pos, roomnum, &orient, false);
5492
5493 if (release)
5494 ReleaseGuidedMissile(slot);
5495 }
5496
5497 // Stuff info for a guided missile
5498 int MultiStuffGuidedInfo(int slot, uint8_t *data) {
5499 int count = 0;
5500 int size_offset;
5501 object *obj = Players[slot].guided_obj;
5502
5503 if (Players[slot].guided_obj == NULL)
5504 return 0;
5505
5506 size_offset = START_DATA(MP_GUIDED_INFO, data, &count);
5507
5508 MultiAddByte(slot, data, &count);
5509 MultiAddByte(0, data, &count);
5510
5511 // Do position
5512 MultiAddPositionData(&obj->pos, data, &count);
5513
5514 // Do orientation
5515 angvec angs;
5516 vm_ExtractAnglesFromMatrix(&angs, &obj->orient);
5517
5518 MultiAddShort(angs.p, data, &count);
5519 MultiAddShort(angs.h, data, &count);
5520 MultiAddShort(angs.b, data, &count);
5521
5522 // Do roomnumber and terrain flag
5523
5524 MultiAddShort(CELLNUM(obj->roomnum), data, &count);
5525
5526 if (OBJECT_OUTSIDE(obj))
5527 MultiAddByte(1, data, &count);
5528 else
5529 MultiAddByte(0, data, &count);
5530
5531 // Do velocity
5532 vector *vel = &obj->mtype.phys_info.velocity;
5533 vector *rotvel = &obj->mtype.phys_info.rotvel;
5534
5535 MultiAddShort(vel->x * 128.0, data, &count);
5536 MultiAddShort(vel->y * 128.0, data, &count);
5537 MultiAddShort(vel->z * 128.0, data, &count);
5538
5539 END_DATA(count, data, size_offset);
5540
5541 return count;
5542 }
5543
5544 // Guided missile release
5545 void MultiDoMissileRelease(int slot, uint8_t *data) {
5546 // if we are the server, we'll have to forward this packet to the clients
5547 int count = 0;
5548 uint8_t pnum_release;
5549
5550 SKIP_HEADER(data, &count);
5551
5552 bool is_guided = false;
5553 pnum_release = MultiGetUbyte(data, &count);
5554 if (pnum_release & 0x80) {
5555 pnum_release &= ~0x80;
5556 is_guided = true;
5557 }
5558
5559 if (Netgame.local_role == LR_SERVER) {
5560 // verify that slot and player match up
5561 if (pnum_release != slot) {
5562 mprintf(0, "%s Release: Packet pnum does not match real pnum\n", (is_guided) ? "Guided" : "Timeout");
5563 return;
5564 }
5565
5566 // relay the packet to the clients
5567 MultiSendMissileRelease(pnum_release, is_guided);
5568
5569 // actually perform the guided release
5570 if (is_guided)
5571 ReleaseGuidedMissile(pnum_release);
5572 else
5573 ReleaseUserTimeoutMissile(pnum_release);
5574 } else {
5575 // make sure we got this packet from the server
5576 if (slot != 0) {
5577 mprintf(0, "%s Release: got packet from non-server!?!\n", (is_guided) ? "Guided" : "Timeout");
5578 return;
5579 }
5580
5581 // actually perform the guided release
5582 if (is_guided)
5583 ReleaseGuidedMissile(pnum_release);
5584 else
5585 ReleaseUserTimeoutMissile(pnum_release);
5586 }
5587 }
5588
5589 void MultiSendMissileRelease(int slot, bool is_guided) {
5590 ASSERT(slot >= 0 && slot < MAX_PLAYERS);
5591
5592 if (!(NetPlayers[slot].flags & NPF_CONNECTED) || NetPlayers[slot].sequence != NETSEQ_PLAYING)
5593 return; // hey this player isn't in the game
5594
5595 if (is_guided && Players[slot].guided_obj == NULL)
5596 return; // no guided missile for this player
5597 if (!is_guided && Players[slot].user_timeout_obj == NULL)
5598 return; // no user timeout object
5599
5600 // everything looks ok, fire off this packet
5601 int count = 0;
5602 uint8_t data[MAX_GAME_DATA_SIZE];
5603 int size_offset;
5604
5605 uint8_t byte_to_send;
5606 byte_to_send = slot;
5607 if (is_guided)
5608 byte_to_send |= 0x80;
5609
5610 size_offset = START_DATA(MP_MISSILE_RELEASE, data, &count, 1);
5611 MultiAddUbyte(byte_to_send, data, &count);
5612 END_DATA(count, data, size_offset);
5613
5614 if (Netgame.local_role == LR_SERVER) {
5615 int i;
5616
5617 // tell all the clients (except the player who is releasing)
5618 for (i = 0; i < MAX_NET_PLAYERS; i++) {
5619 if (i == Player_num)
5620 continue;
5621 if (i == slot)
5622 continue;
5623
5624 if ((NetPlayers[i].flags & NPF_CONNECTED) && (NetPlayers[i].sequence == NETSEQ_PLAYING)) {
5625 nw_SendReliable(NetPlayers[i].reliable_socket, data, count, true);
5626 }
5627 }
5628 } else {
5629 // tell the server
5630 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count, true);
5631 }
5632 }
5633
5634 // Calls the scripts packet extractor code
5635 void MultiDoSpecialPacket(uint8_t *data) {
5636 int count = 0;
5637 uint8_t indata[MAX_GAME_DATA_SIZE];
5638
5639 SKIP_HEADER(data, &count);
5640 int size = MultiGetInt(data, &count);
5641
5642 MULTI_ASSERT_NOMESSAGE(size < MAX_GAME_DATA_SIZE);
5643 memcpy(indata, &data[count], size);
5644
5645 DLLInfo.special_data = indata;
5646 CallGameDLL(EVT_CLIENT_GAMESPECIALPACKET, &DLLInfo);
5647 }
5648
5649 // Sends the special script packet to a player
5650 void MultiSendSpecialPacket(int slot, uint8_t *outdata, int size) {
5651 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
5652
5653 int count = 0;
5654 uint8_t data[MAX_GAME_DATA_SIZE];
5655 int size_offset;
5656
5657 size_offset = START_DATA(MP_SPECIAL_PACKET, data, &count, 1);
5658
5659 MultiAddInt(size, data, &count);
5660
5661 // Send special packet data
5662 memcpy(&data[count], outdata, size);
5663 count += size;
5664
5665 END_DATA(count, data, size_offset);
5666
5667 nw_SendReliable(NetPlayers[slot].reliable_socket, data, count, true);
5668 }
5669
5670 // Sends the special script packet to the server
5671 void MultiClientSendSpecialPacket(uint8_t *outdata, int size) {
5672 MULTI_ASSERT_NOMESSAGE(Netgame.local_role != LR_SERVER);
5673
5674 int count = 0;
5675 uint8_t data[MAX_GAME_DATA_SIZE];
5676 int size_offset;
5677
5678 size_offset = START_DATA(MP_SPECIAL_PACKET, data, &count);
5679
5680 MultiAddInt(size, data, &count);
5681
5682 // Send special packet data
5683 memcpy(&data[count], outdata, size);
5684 count += size;
5685
5686 END_DATA(count, data, size_offset);
5687
5688 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count, false);
5689 }
5690
5691 // Server is telling us to remove an object
5692 void MultiDoRemoveObject(uint8_t *data) {
5693 int count = 0;
5694
5695 SKIP_HEADER(data, &count);
5696
5697 uint16_t server_objnum = MultiGetUshort(data, &count);
5698 uint8_t type = MultiGetByte(data, &count);
5699
5700 uint8_t sound = MultiGetByte(data, &count);
5701
5702 // Get name to help track down bug
5703 /*#ifndef RELEASE
5704 char name[255];
5705 uint8_t len=MultiGetByte (data,&count);
5706 memcpy (name,&data[count],len);
5707 count+=len;
5708 #endif*/
5709
5710 // mprintf(0,"Server says to remove object %d\n",server_objnum);
5711
5712 int local_objnum = Server_object_list[server_objnum];
5713 if (local_objnum == 65535) {
5714 mprintf(0, "Client/Server object lists don't match. Something is wrong!\n");
5715 // Error ("Bad object 1");
5716 return;
5717 }
5718
5719 if (!(Objects[local_objnum].flags & OF_SERVER_OBJECT)) {
5720 mprintf(0, "Client/Server object lists don't match. Something is wrong!\n");
5721 ASSERT(1);
5722 Objects[local_objnum].flags |= OF_SERVER_OBJECT;
5723 }
5724 /*
5725 if (Objects[local_objnum].type != type) {
5726 mprintf(0, "Client/Server object types don't match. Something is wrong!\n");
5727 // mprintf (0,"Object to be removed was type %d, I thought it was %d name:
5728 // %s\n",type,Objects[local_objnum].type,name)); Error ("Bad object 2"); ASSERT (1); return;
5729 }
5730 */
5731 if (sound)
5732 Sound_system.Play3dSound(SOUND_POWERUP_PICKUP, &Objects[local_objnum]);
5733
5734 if (Objects[local_objnum].flags & OF_CLIENTDEMOOBJECT) {
5735 if (Demo_flags == DF_RECORDING) {
5736 mprintf(0, "Recording object deleted on server\n");
5737 DemoWriteSetObjDead(&Objects[local_objnum]);
5738 }
5739 }
5740
5741 Objects[local_objnum].flags |= OF_SERVER_SAYS_DELETE;
5742 SetObjectDeadFlag(&Objects[local_objnum]);
5743
5744 // Clear our lists
5745 int this_server_objnum = Local_object_list[local_objnum];
5746 if (this_server_objnum != server_objnum)
5747 ASSERT(1); // Error ("Client object doesn't match remove object!");
5748
5749 Server_object_list[server_objnum] = 65535;
5750 Local_object_list[local_objnum] = 65535;
5751
5752 if (Objects[local_objnum].type == OBJ_MARKER) {
5753 if (Objects[local_objnum].parent_handle == Objects[Players[Player_num].objnum].handle)
5754 Players[Player_num].num_markers--;
5755 }
5756 }
5757
5758 // Tells all clients to remove a specified object
5759 void MultiSendRemoveObject(object *obj, uint8_t playsound) {
5760 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
5761
5762 int count = 0;
5763 uint8_t data[MAX_GAME_DATA_SIZE];
5764 int size_offset;
5765
5766 size_offset = START_DATA(MP_REMOVE_OBJECT, data, &count, 1);
5767
5768 // mprintf(0,"Telling clients to remove object %d type=%d
5769 // name=%s\n",obj-Objects,obj->type,Object_info[obj->id].name);
5770
5771 ASSERT(obj->flags & OF_CLIENT_KNOWS);
5772
5773 MultiAddUshort(obj - Objects, data, &count);
5774 MultiAddByte(obj->type, data, &count);
5775 MultiAddByte(playsound, data, &count);
5776
5777 /*#ifndef RELEASE
5778 uint8_t len = strlen(Object_info[obj->id].name)+1;
5779 MultiAddByte (len,data,&count);
5780 memcpy (data+count,Object_info[obj->id].name,len);
5781 count+=len;
5782 #endif*/
5783 END_DATA(count, data, size_offset);
5784
5785 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_OBJECTS, false);
5786 }
5787
5788 // Repositions a powerup to be where it should be
5789 void MultiDoPowerupReposition(uint8_t *data) {
5790 int count = 0;
5791
5792 SKIP_HEADER(data, &count);
5793
5794 int server_objnum = MultiGetUshort(data, &count);
5795
5796 int local_objnum = Server_object_list[server_objnum];
5797 if (local_objnum == 65535) {
5798 return; // Powerup hasn't been born yet
5799 }
5800 MULTI_ASSERT_NOMESSAGE(Objects[local_objnum].type == OBJ_POWERUP);
5801 object *obj = &Objects[local_objnum];
5802 vector pos;
5803
5804 // memcpy (&pos,&data[count],sizeof(vector));
5805 // count+=sizeof(vector);
5806 pos = MultiGetVector(data, &count);
5807
5808 uint16_t short_roomnum = MultiGetUshort(data, &count);
5809 uint8_t terrain = MultiGetByte(data, &count);
5810
5811 int roomnum = short_roomnum;
5812 if (terrain)
5813 roomnum = MAKE_ROOMNUM(roomnum);
5814
5815 obj->mtype.phys_info.velocity = Zero_vector;
5816
5817 ObjSetPos(obj, &pos, roomnum, &obj->orient, true);
5818 }
5819
5820 // Client is telling us about weapons and energy he has
5821 void MultiDoWeaponsLoad(uint8_t *data) {
5822 int count = 0;
5823
5824 SKIP_HEADER(data, &count);
5825
5826 int slot = MultiGetByte(data, &count);
5827
5828 for (int i = 0; i < MAX_SECONDARY_WEAPONS; i++) {
5829 int num = MultiGetUbyte(data, &count);
5830
5831 if (num < Players[slot].weapon_ammo[MAX_PRIMARY_WEAPONS + i])
5832 Players[slot].weapon_ammo[MAX_PRIMARY_WEAPONS + i] = num;
5833 }
5834
5835 // Now get small views
5836 int objnum = MultiGetShort(data, &count);
5837 if (objnum == -1)
5838 Players[slot].small_left_obj = -1;
5839 else
5840 Players[slot].small_left_obj = objnum;
5841
5842 objnum = MultiGetShort(data, &count);
5843
5844 if (objnum == -1)
5845 Players[slot].small_right_obj = -1;
5846 else
5847 Players[slot].small_right_obj = objnum;
5848
5849 Players[slot].small_dll_obj = MultiGetShort(data, &count);
5850 }
5851
5852 // Tells the server about the weapons we're carrying
5853 // Plus about the viewers we're looking at
5854 void MultiSendWeaponsLoad() {
5855 int count = 0;
5856 uint8_t data[MAX_GAME_DATA_SIZE];
5857
5858 int size_offset = START_DATA(MP_WEAPONS_LOAD, data, &count);
5859
5860 MultiAddByte(Player_num, data, &count);
5861
5862 for (int i = 0; i < (MAX_SECONDARY_WEAPONS); i++) {
5863 int num = Players[Player_num].weapon_ammo[MAX_PRIMARY_WEAPONS + i];
5864 num = std::min(num, 255);
5865
5866 MultiAddUbyte(num, data, &count);
5867 }
5868
5869 // Add small view objnums in case we're looking through someone elses eyes
5870 object *obj = ObjGet(GetSmallViewer(SVW_LEFT));
5871 if (!obj || obj->type == OBJ_WEAPON)
5872 MultiAddShort(-1, data, &count);
5873 else
5874 MultiAddShort(Local_object_list[GetSmallViewer(SVW_LEFT) & HANDLE_OBJNUM_MASK], data, &count);
5875
5876 obj = ObjGet(GetSmallViewer(SVW_RIGHT));
5877 if (!obj || obj->type == OBJ_WEAPON)
5878 MultiAddShort(-1, data, &count);
5879 else
5880 MultiAddShort(Local_object_list[GetSmallViewer(SVW_RIGHT) & HANDLE_OBJNUM_MASK], data, &count);
5881
5882 if (Players[Player_num].small_dll_obj == -1)
5883 MultiAddShort(-1, data, &count);
5884 else
5885 MultiAddShort(Local_object_list[Players[Player_num].small_dll_obj], data, &count);
5886
5887 END_DATA(count, data, size_offset);
5888
5889 nw_Send(&Netgame.server_address, data, count, 0);
5890 }
5891
5892 // Tells the other players that a slot is starting/stopping its on/off weapon
5893 void MultiSendOnOff(object *obj, uint8_t on, uint8_t wb_index, uint8_t fire_mask) {
5894 int count = 0;
5895 uint8_t data[MAX_GAME_DATA_SIZE];
5896 int size_offset;
5897 int slot = obj->id;
5898
5899 size_offset = START_DATA(MP_ON_OFF, data, &count);
5900
5901 MultiAddByte(slot, data, &count);
5902 MultiAddByte(on, data, &count);
5903 MultiAddByte(wb_index, data, &count);
5904 MultiAddByte(fire_mask, data, &count);
5905
5906 END_DATA(count, data, size_offset);
5907
5908 if (Netgame.local_role == LR_SERVER)
5909 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_PLAYING, false);
5910 }
5911
5912 // Server is telling us to start/stop and on/off weapon
5913 void MultiDoOnOff(uint8_t *data) {
5914 int count = 0;
5915
5916 SKIP_HEADER(data, &count);
5917
5918 uint8_t slot = MultiGetByte(data, &count);
5919 uint8_t on = MultiGetByte(data, &count);
5920 uint8_t wb_index = MultiGetByte(data, &count);
5921 uint8_t fire_mask = MultiGetByte(data, &count);
5922
5923 if (on) {
5924 Objects[Players[slot].objnum].weapon_fire_flags |= WFF_ON_OFF;
5925
5926 // Clear out firing mask
5927 dynamic_wb_info *p_dwb = &Objects[Players[slot].objnum].dynamic_wb[wb_index];
5928 p_dwb->cur_firing_mask = 0;
5929
5930 Players[slot].weapon[PW_PRIMARY].index = wb_index;
5931 } else
5932 Objects[Players[slot].objnum].weapon_fire_flags &= ~WFF_ON_OFF;
5933
5934 if (Netgame.local_role == LR_SERVER)
5935 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_PLAYING, false);
5936 if (Demo_flags == DF_RECORDING) {
5937 DemoWriteObjWeapFireFlagChanged(Players[slot].objnum);
5938 }
5939 }
5940
5941 // Tells all the clients to apply damage to a player
5942 void MultiSendAdditionalDamage(int slot, int type, float amount) {
5943 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
5944 int count = 0;
5945 uint8_t data[MAX_GAME_DATA_SIZE];
5946 int size_offset;
5947
5948 size_offset = START_DATA(MP_ADDITIONAL_DAMAGE, data, &count, 1);
5949
5950 MultiAddByte(slot, data, &count);
5951 MultiAddByte(type, data, &count);
5952 MultiAddFloat(amount, data, &count);
5953
5954 END_DATA(count, data, size_offset);
5955
5956 mprintf(0, "Sending additional damage packet of type=%d amount=%f!\n", type, amount);
5957
5958 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_PLAYING, false);
5959 }
5960
5961 // Server is telling us to apply damage to a player
5962 void MultiDoAdditionalDamage(uint8_t *data) {
5963 int count = 0;
5964
5965 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_CLIENT);
5966
5967 // mprintf(0,"Got additional damage packet!\n");
5968
5969 SKIP_HEADER(data, &count);
5970
5971 uint8_t slot = MultiGetByte(data, &count);
5972 uint8_t type = MultiGetByte(data, &count);
5973 float amount = MultiGetFloat(data, &count);
5974
5975 if (amount < 0) // add to shields
5976 {
5977 Objects[Players[slot].objnum].shields += (-amount);
5978 if (Objects[Players[slot].objnum].shields > MAX_SHIELDS)
5979 Objects[Players[slot].objnum].shields = MAX_SHIELDS;
5980 } else // take damage
5981 {
5982 ApplyDamageToPlayer(&Objects[Players[slot].objnum], NULL, type, amount, 1);
5983 }
5984 }
5985
5986 // Asks the server for shields based on frametime "amount" x the type of shields requested
5987 void MultiSendRequestShields(int type, float amount) {
5988 if (Netgame.local_role != LR_CLIENT)
5989 return;
5990
5991 int count = 0;
5992 uint8_t data[MAX_GAME_DATA_SIZE];
5993 int size_offset;
5994
5995 size_offset = START_DATA(MP_REQUEST_SHIELDS, data, &count);
5996
5997 MultiAddByte(Player_num, data, &count);
5998 MultiAddByte(type, data, &count);
5999 MultiAddFloat(amount, data, &count);
6000
6001 END_DATA(count, data, size_offset);
6002
6003 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count, false);
6004 }
6005
6006 // Someone wants us to give them shields
6007 void MultiDoRequestShields(uint8_t *data) {
6008 if (Netgame.local_role != LR_SERVER)
6009 return;
6010
6011 int count = 0;
6012
6013 SKIP_HEADER(data, &count);
6014
6015 uint8_t pnum = MultiGetByte(data, &count);
6016 uint8_t type = MultiGetByte(data, &count);
6017 float amount = MultiGetFloat(data, &count);
6018
6019 if (type == SHIELD_REQUEST_ENERGY_TO_SHIELD) {
6020 // This guys wants to use the energy to shield converter
6021
6022 float amount_to_give;
6023
6024 amount_to_give = (amount * CONVERTER_RATE) / CONVERTER_SCALE;
6025
6026 if (Objects[Players[pnum].objnum].shields + amount_to_give > INITIAL_SHIELDS)
6027 amount_to_give = INITIAL_SHIELDS - Objects[Players[pnum].objnum].shields;
6028
6029 if (amount_to_give > 0) {
6030 Multi_additional_damage[pnum] = -amount_to_give;
6031 Multi_additional_damage_type[pnum] = PD_NONE;
6032 }
6033 }
6034 }
6035
6036 // We're asking the server to damage us
6037 void MultiSendRequestDamage(int type, float amount) {
6038 if (Netgame.local_role != LR_CLIENT)
6039 return;
6040
6041 int count = 0;
6042 uint8_t data[MAX_GAME_DATA_SIZE];
6043 int size_offset;
6044
6045 size_offset = START_DATA(MP_REQUEST_DAMAGE, data, &count);
6046
6047 MultiAddByte(Player_num, data, &count);
6048 MultiAddByte(type, data, &count);
6049 MultiAddFloat(amount, data, &count);
6050
6051 END_DATA(count, data, size_offset);
6052
6053 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count, false);
6054 }
6055
6056 // Someone wants us to damage them
6057 void MultiDoRequestDamage(uint8_t *data) {
6058 if (Netgame.local_role != LR_SERVER)
6059 return;
6060
6061 int count = 0;
6062
6063 SKIP_HEADER(data, &count);
6064
6065 uint8_t pnum = MultiGetByte(data, &count);
6066 uint8_t type = MultiGetByte(data, &count);
6067 float amount = MultiGetFloat(data, &count);
6068
6069 ApplyDamageToPlayer(&Objects[Players[pnum].objnum], &Objects[Players[pnum].objnum], type, amount);
6070 }
6071
6072 // Server is telling us to create a countermeasure
6073 void MultiDoRequestCountermeasure(uint8_t *data) {
6074 int count = 0;
6075
6076 mprintf(0, "Got request for countermeasure!\n");
6077
6078 SKIP_HEADER(data, &count);
6079
6080 uint16_t parent_objnum = MultiGetShort(data, &count);
6081
6082 if (Netgame.local_role != LR_SERVER) {
6083 parent_objnum = Server_object_list[parent_objnum];
6084 MULTI_ASSERT_NOMESSAGE(parent_objnum != 65535);
6085 }
6086
6087 uint32_t checksum = MultiGetUint(data, &count);
6088
6089 int id = MultiMatchWeapon(checksum);
6090
6091 if (id == -1) {
6092 mprintf(0, "Server data doesn't match!\n");
6093 Int3();
6094 MultiMatchWeapon(checksum);
6095
6096 return;
6097 }
6098
6099 int objnum = FireWeaponFromObject(&Objects[parent_objnum], id, 5);
6100
6101 if (objnum >= 0) {
6102 if (Netgame.local_role == LR_SERVER)
6103 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_PLAYERS, false);
6104 }
6105 }
6106
6107 // We're asking the server to create a countermeasure for us
6108 void MultiSendRequestCountermeasure(int16_t objnum, int weapon_index) {
6109 int count = 0;
6110 uint8_t data[MAX_GAME_DATA_SIZE];
6111 int size_offset;
6112
6113 size_offset = START_DATA(MP_REQUEST_COUNTERMEASURE, data, &count);
6114
6115 MultiAddShort(objnum, data, &count);
6116
6117 uint32_t index = MultiGetMatchChecksum(OBJ_WEAPON, weapon_index);
6118 MultiAddUint(index, data, &count);
6119
6120 END_DATA(count, data, size_offset);
6121
6122 if (Netgame.local_role == LR_CLIENT)
6123 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count, false);
6124 else
6125 MultiDoRequestCountermeasure(data);
6126
6127 mprintf(0, "Sending out request for countermeasure!\n");
6128 }
6129
6130 // Server is telling us about a player who is changing his observer mode
6131 void MultiDoObserverChange(uint8_t *data) {
6132 int count = 0;
6133 int objnum = -1;
6134
6135 SKIP_HEADER(data, &count);
6136
6137 int slot = MultiGetByte(data, &count);
6138 uint8_t mode = MultiGetByte(data, &count);
6139 uint8_t on = MultiGetByte(data, &count);
6140 int restart_slot = MultiGetShort(data, &count);
6141 if (mode == OBSERVER_MODE_PIGGYBACK) {
6142 if (Netgame.local_role == LR_SERVER)
6143 objnum = MultiGetInt(data, &count);
6144 else {
6145 objnum = Server_object_list[MultiGetInt(data, &count)];
6146 MULTI_ASSERT_NOMESSAGE(objnum != 65535);
6147 }
6148 }
6149
6150 if (on)
6151 PlayerSwitchToObserver(slot, mode, objnum);
6152 else {
6153 Player_pos_fix[slot].active = true;
6154 Player_pos_fix[slot].expire_time = Gametime + PLAYER_POS_HACK_TIME;
6155 Player_pos_fix[slot].room = Players[restart_slot].start_roomnum;
6156 Player_pos_fix[slot].ignored_pos = 0;
6157 PlayerStopObserving(slot);
6158 PlayerMoveToStartPos(slot, restart_slot);
6159 }
6160 }
6161
6162 // Someone is asking us for permission to enter observer mode
6163 void MultiDoRequestToObserve(uint8_t *data) {
6164 int count = 0;
6165 int objnum;
6166
6167 mprintf(0, "Got request to observe!\n");
6168
6169 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
6170
6171 SKIP_HEADER(data, &count);
6172
6173 uint8_t slot = MultiGetByte(data, &count);
6174 uint8_t mode = MultiGetByte(data, &count);
6175 uint8_t on = MultiGetByte(data, &count);
6176
6177 if (mode == OBSERVER_MODE_PIGGYBACK)
6178 objnum = MultiGetInt(data, &count);
6179
6180 if ((Objects[Players[slot].objnum].type == OBJ_PLAYER && on) ||
6181 (Objects[Players[slot].objnum].type == OBJ_OBSERVER && !on)) {
6182 int newcount = 0;
6183 uint8_t newdata[MAX_GAME_DATA_SIZE];
6184 int size_offset;
6185
6186 size_offset = START_DATA(MP_OBSERVER_CHANGE, newdata, &newcount);
6187
6188 MultiAddByte(slot, newdata, &newcount);
6189 MultiAddByte(mode, newdata, &newcount);
6190 MultiAddByte(on, newdata, &newcount);
6191
6192 if (!on) {
6193 int start_slot = PlayerGetRandomStartPosition(slot);
6194 MultiAddShort(start_slot, newdata, &newcount);
6195 } else
6196 MultiAddShort(0, newdata, &newcount);
6197
6198 if (mode == OBSERVER_MODE_PIGGYBACK) {
6199 MultiAddInt(objnum, newdata, &newcount);
6200 }
6201
6202 END_DATA(newcount, newdata, size_offset);
6203
6204 MultiSendReliablyToAllExcept(Player_num, newdata, newcount, NETSEQ_PLAYERS, false);
6205 MultiDoObserverChange(newdata);
6206 }
6207 }
6208
6209 // We're asking to enter observer mode
6210 void MultiSendRequestToObserve(int mode, int on, int objnum) {
6211 int count = 0;
6212 uint8_t data[MAX_GAME_DATA_SIZE];
6213 int size_offset;
6214
6215 // Check to see if the player has enough shields to enter
6216 if (on && Objects[Players[Player_num].objnum].shields < (INITIAL_SHIELDS / 2)) {
6217 AddHUDMessage(TXT_NOTENOUGHSHIELDSFOROBS);
6218 return;
6219 }
6220
6221 size_offset = START_DATA(MP_REQUEST_TO_OBSERVE, data, &count);
6222
6223 MultiAddByte(Player_num, data, &count);
6224 MultiAddByte(mode, data, &count);
6225 MultiAddByte(on, data, &count);
6226
6227 if (mode == OBSERVER_MODE_PIGGYBACK) {
6228 if (Netgame.local_role == LR_SERVER)
6229 MultiAddInt(objnum, data, &count);
6230 else
6231 MultiAddInt(Local_object_list[objnum], data, &count);
6232 }
6233
6234 END_DATA(count, data, size_offset);
6235
6236 if (Netgame.local_role == LR_SERVER) {
6237 MultiDoRequestToObserve(data);
6238 return;
6239 } else
6240 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count, false);
6241 }
6242
6243 // Server is telling us about players that we can see
6244 void MultiDoVisiblePlayers(uint8_t *data) {
6245 int count = 0;
6246 int i;
6247
6248 if (Netgame.local_role == LR_SERVER)
6249 return;
6250
6251 SKIP_HEADER(data, &count);
6252
6253 int bitmask = MultiGetUint(data, &count);
6254
6255 MULTI_ASSERT_NOMESSAGE(MAX_NET_PLAYERS <= 32);
6256
6257 for (i = 0; i < MAX_NET_PLAYERS; i++) {
6258 int hide_it = 0;
6259
6260 if (i == Player_num)
6261 continue;
6262
6263 if (!(NetPlayers[i].flags & NPF_CONNECTED) || NetPlayers[i].sequence != NETSEQ_PLAYING)
6264 hide_it = 1;
6265
6266 if (!(bitmask & (1 << i)) || hide_it) {
6267 if (Objects[Players[i].objnum].type == OBJ_PLAYER || hide_it) {
6268 // Kill all the sounds, render types, etc.
6269 Objects[Players[i].objnum].render_type = RT_NONE;
6270 Objects[Players[i].objnum].movement_type = MT_NONE;
6271 Objects[Players[i].objnum].mtype.phys_info.flags |= PF_NO_COLLIDE;
6272 Objects[Players[i].objnum].weapon_fire_flags &= ~(WFF_ON_OFF | WFF_SPRAY);
6273 Players[i].flags &= ~(PLAYER_FLAGS_AFTERBURN_ON | PLAYER_FLAGS_THRUSTED);
6274 PlayerStopSounds(i);
6275 }
6276 } else {
6277 if (Objects[Players[i].objnum].type == OBJ_PLAYER) {
6278 Objects[Players[i].objnum].render_type = RT_POLYOBJ;
6279 Objects[Players[i].objnum].movement_type = MT_PHYSICS;
6280 Objects[Players[i].objnum].mtype.phys_info.flags &= ~PF_NO_COLLIDE;
6281 }
6282 }
6283 }
6284 }
6285
6286 // Sends all the visible players to another player
6287 void MultiSendVisiblePlayers(int to_slot) {
6288 int count = 0;
6289 uint8_t data[MAX_GAME_DATA_SIZE];
6290 int size_offset;
6291
6292 size_offset = START_DATA(MP_VISIBLE_PLAYERS, data, &count);
6293
6294 // Always mark server as visible
6295 Multi_visible_players[to_slot] |= (1 << Player_num);
6296
6297 MultiAddUint(Multi_visible_players[to_slot], data, &count);
6298
6299 END_DATA(count, data, size_offset);
6300
6301 nw_Send(&NetPlayers[to_slot].addr, data, count, 0);
6302 }
6303
6304 void MultiDoRequestPeerDamage(uint8_t *data, network_address *from_addr) {
6305 int count = 0;
6306
6307 if (Netgame.local_role != LR_SERVER)
6308 return;
6309
6310 SKIP_HEADER(data, &count);
6311
6312 int pnum = MultiGetByte(data, &count);
6313 uint16_t killer_objnum = MultiGetUshort(data, &count);
6314 uint8_t weapon_id = MultiGetUbyte(data, &count);
6315 uint8_t damage_type = MultiGetUbyte(data, &count);
6316 float amount = MultiGetFloat(data, &count);
6317
6318 if (killer_objnum == 65535 || Objects[killer_objnum].type == OBJ_NONE)
6319 ApplyDamageToPlayer(&Objects[Players[pnum].objnum], &Objects[Players[pnum].objnum], damage_type, amount, 1,
6320 weapon_id);
6321 else
6322 ApplyDamageToPlayer(&Objects[Players[pnum].objnum], &Objects[killer_objnum], damage_type, amount, 1, weapon_id);
6323 }
6324
6325 // Tell the server to damage us
6326 void MultiSendRequestPeerDamage(object *killer, int weapon_id, int damage_type, float amount) {
6327 int size;
6328 uint8_t data[MAX_GAME_DATA_SIZE];
6329 int count = 0;
6330
6331 if (Netgame.local_role == LR_SERVER)
6332 return;
6333
6334 mprintf(0, "Sending request peer damage of %f\n", amount);
6335
6336 size = START_DATA(MP_REQUEST_PEER_DAMAGE, data, &count);
6337 MultiAddByte(Player_num, data, &count);
6338
6339 // Add killer info
6340 if (killer == NULL || Local_object_list[killer - Objects] == 65535 || killer == &Objects[Players[Player_num].objnum])
6341 MultiAddUshort(65535, data, &count);
6342 else
6343 MultiAddUshort(Local_object_list[killer - Objects], data, &count);
6344
6345 MultiAddUbyte(weapon_id, data, &count);
6346 MultiAddUbyte(damage_type, data, &count);
6347 MultiAddFloat(amount, data, &count);
6348
6349 END_DATA(count, data, size);
6350
6351 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count);
6352 }
6353
6354 // Starts a new multiplayer game
6355 void StartNewMultiplayerGame() { SetGameState(GAMESTATE_LVLSTART); }
6356
6357 // Deletes all the objects in the level except for players
6358 // Makes all the players ghosts
6359 void MultiMassageAllObjects(int kill_powerups, int kill_robots) {
6360 int i;
6361 Num_powerup_respawn = 0;
6362 Num_powerup_timer = 0;
6363 Num_client_lm_objects = 0;
6364 Num_server_lm_objects = 0;
6365 mprintf(0, "Massaging all objects!\n");
6366
6367 for (i = 0; i <= Highest_object_index; i++) {
6368 // If client, delete all robots and powerups
6369 if (Netgame.local_role == LR_CLIENT) {
6370 if (IS_GENERIC(Objects[i].type) || Objects[i].type == OBJ_DOOR) {
6371 if (IS_GENERIC(Objects[i].type)) {
6372 if (Object_info[Objects[i].id].lighting_info.lighting_render_type != LRT_LIGHTMAPS) {
6373 Objects[i].flags |= OF_SERVER_SAYS_DELETE;
6374 ObjDelete(i);
6375 } else {
6376 // Add it to our lightmap list
6377 Client_lightmap_list[Num_client_lm_objects] = i;
6378 Num_client_lm_objects++;
6379 }
6380 } else {
6381 // Add this door to our lightmap list
6382 Client_lightmap_list[Num_client_lm_objects] = i;
6383 Num_client_lm_objects++;
6384 }
6385 }
6386 }
6387
6388 // If Server, then only delete the types we're supposed to
6389 if (Netgame.local_role == LR_SERVER) {
6390 if ((Objects[i].type == OBJ_ROBOT || (Objects[i].type == OBJ_BUILDING && Objects[i].ai_info)) && kill_robots) {
6391 ObjDelete(i);
6392 } else if (Objects[i].type == OBJ_POWERUP) {
6393 if ((kill_powerups) || (!(Object_info[Objects[i].id].multi_allowed)))
6394 ObjDelete(i);
6395 else {
6396 if (Num_powerup_respawn < MAX_RESPAWNS) {
6397 Powerup_respawn[Num_powerup_respawn].pos = Objects[i].pos;
6398 Powerup_respawn[Num_powerup_respawn].roomnum = Objects[i].roomnum;
6399 Powerup_respawn[Num_powerup_respawn].objnum = i;
6400 Powerup_respawn[Num_powerup_respawn].used = 1;
6401 Powerup_respawn[Num_powerup_respawn].original_id = Objects[i].id;
6402 Num_powerup_respawn++;
6403 }
6404 }
6405 }
6406 Objects[i].flags |= OF_CLIENT_KNOWS;
6407 }
6408
6409 if (Objects[i].type == OBJ_PLAYER) {
6410 if (Netgame.local_role == LR_CLIENT || (Netgame.local_role == LR_SERVER && Objects[i].id != Player_num)) {
6411 MultiMakePlayerGhost(Objects[i].id);
6412 }
6413 }
6414 }
6415 }
6416
6417 int MultiGetShipChecksum(int ship_index);
6418 // Starts multiplayer-specific stuff for a new level
6419 // Anything not specific to multiplayer should be in StartNewLevel()
6420 bool MultiStartNewLevel(int level) {
6421 Time_last_taunt_request = 0;
6422
6423 // Figure the ships into the checksum
6424 for (int i = 0; i < MAX_SHIPS; i++)
6425 if (Ships[i].used)
6426 MultiGetShipChecksum(i);
6427
6428 Reliable_count = 0;
6429 Last_reliable_count = -1;
6430 Multi_next_level = -1;
6431
6432 #ifndef RELEASE
6433 // Clear our packet tracking
6434 for (int i = 0; i < 255; i++)
6435 Multi_packet_tracking[i] = 0;
6436
6437 #endif
6438
6439 memset(Player_pos_fix, 0, sizeof(Player_pos_fix));
6440
6441 memset(Multi_building_states, 0, MAX_OBJECTS);
6442 Multi_num_buildings_changed = 0;
6443
6444 memset(Multi_additional_damage, 0, MAX_PLAYERS * 4);
6445 memset(Multi_additional_shields, 0, MAX_SHIELD_REQUEST_TYPES * 4);
6446 Multi_requested_damage_amount = 0;
6447
6448 for (int i = 0; i < MAX_OBJECTS; i++) {
6449 Server_object_list[i] = 65535;
6450 Local_object_list[i] = 65535;
6451 Objects[i].generic_nonvis_flags = 0;
6452 }
6453
6454 for (int i = 0; i < MAX_SPEW_EFFECTS; i++)
6455 Server_spew_list[i] = 65535;
6456
6457 // SCRIPT POINT!!!
6458 MultiMassageAllObjects(0, (Netgame.flags & NF_USE_ROBOTS) ? 0 : 1);
6459 MultiBuildMatchTables();
6460 Num_broke_glass = 0;
6461
6462 // Fill in player object numbers
6463 for (int i = 0; i < MAX_PLAYERS; i++) {
6464 if (Players[i].start_roomnum != -1) {
6465 int objnum = Players[i].objnum;
6466
6467 Server_object_list[objnum] = objnum;
6468 Local_object_list[objnum] = objnum;
6469 Objects[objnum].flags |= (OF_SERVER_OBJECT | OF_CLIENT_KNOWS);
6470 }
6471
6472 InitPlayerNewLevel(i);
6473
6474 // Inititialize all other players besides myself
6475 if (Netgame.local_role == LR_CLIENT && i != Player_num && !(NetPlayers[i].flags & NPF_SERVER))
6476 NetPlayers[i].flags &= ~NPF_CONNECTED;
6477 }
6478
6479 if (Netgame.local_role == LR_CLIENT)
6480 NetPlayers[Player_num].sequence = NETSEQ_LEVEL_START;
6481 else {
6482 NetPlayers[Player_num].sequence = NETSEQ_PREGAME;
6483 }
6484
6485 ResetTeamScores();
6486
6487 InitPlayerNewShip(Player_num, INVRESET_ALL);
6488
6489 if (Netgame.local_role == LR_SERVER && Netgame.flags & NF_ALLOWGUIDEBOT) {
6490 // add the guidebot for the server here
6491 ASSERT(Buddy_handle[Player_num] != OBJECT_HANDLE_NONE);
6492 if ((!Players[Player_num].inventory.CheckItem(OBJ_ROBOT, ROBOT_GUIDEBOT)) &&
6493 (ObjGet(Buddy_handle[Player_num])->type != OBJ_ROBOT))
6494 Players[Player_num].inventory.Add(OBJ_ROBOT, ROBOT_GUIDEBOT);
6495 }
6496
6497 CallGameDLL(EVT_GAMELEVELSTART, &DLLInfo);
6498
6499 return true;
6500 }
6501
6502 // Returns the number of players in a game
6503 int MultiCountPlayers() {
6504 int i;
6505 int count = 0;
6506
6507 for (i = 0; i < MAX_NET_PLAYERS; i++) {
6508 if (NetPlayers[i].flags & NPF_CONNECTED)
6509 count++;
6510 }
6511
6512 return count;
6513 }
6514
6515 // Sends a full packet out the the server
6516 // Resets the send_size variable
6517 // Server only
6518 void MultiSendFullPacket(int slot, int flags) {
6519 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
6520
6521 if (Multi_send_size[slot] < 1)
6522 return;
6523
6524 MULTI_ASSERT_NOMESSAGE(NetPlayers[slot].flags & NPF_CONNECTED);
6525 nw_Send(&NetPlayers[slot].addr, Multi_send_buffer[slot], Multi_send_size[slot], flags);
6526 Multi_send_size[slot] = 0;
6527 }
6528
6529 // Sends a full packet out the the server
6530 // Resets the send_size variable
6531 // Client and Server
6532 void MultiSendFullReliablePacket(int slot, int flags) {
6533 if (slot == SERVER_PLAYER)
6534 MULTI_ASSERT_NOMESSAGE(Netgame.local_role != LR_SERVER);
6535
6536 // We're sending to the server
6537 if (slot == SERVER_PLAYER) {
6538 // mprintf(0,"Sending full packet of size %d to slot%d!\n",Multi_cur_send_size,slot);
6539 nw_SendReliable(NetPlayers[Player_num].reliable_socket, Multi_reliable_send_buffer[Player_num],
6540 Multi_reliable_send_size[Player_num], false);
6541 Multi_reliable_send_size[Player_num] = 0;
6542 Multi_reliable_sent_position[Player_num] = 0;
6543 Multi_reliable_last_send_time[Player_num] = 0;
6544 Multi_reliable_urgent[Player_num] = 0;
6545 } else // We are the server and we're sending to "slot"
6546 {
6547 MULTI_ASSERT_NOMESSAGE(NetPlayers[slot].flags & NPF_CONNECTED);
6548 nw_SendReliable(NetPlayers[slot].reliable_socket, Multi_reliable_send_buffer[slot], Multi_reliable_send_size[slot],
6549 true);
6550 Multi_reliable_send_size[slot] = 0;
6551 Multi_reliable_sent_position[slot] = 0;
6552 Multi_reliable_last_send_time[slot] = 0;
6553 Multi_reliable_urgent[slot] = 0;
6554 }
6555 }
6556
6557 // Given a string, returns a unique integer for that string
6558 uint32_t MultiGetUniqueIDFromString(char *plainstring) {
6559 int i, t, len;
6560 uint32_t ret;
6561 uint8_t cryptstring[PAGENAME_LEN];
6562 uint32_t vals[4];
6563
6564 len = strlen(plainstring);
6565
6566 if (len < 4) {
6567 for (i = len; i < 4; i++)
6568 plainstring[i] = ('g' + i);
6569
6570 len = 4;
6571 }
6572
6573 for (i = 0; i < 4; i++) {
6574 cryptstring[i] = 0;
6575 uint8_t backbyte;
6576
6577 if (i == 0)
6578 backbyte = 0x9a;
6579 else
6580 backbyte = plainstring[i - 1];
6581
6582 for (t = 0; t < len; t++) {
6583 uint8_t a = plainstring[t];
6584 uint8_t b = plainstring[i % (t + 1)];
6585
6586 a *= a;
6587 b *= b * b;
6588
6589 cryptstring[i] += a ^ b ^ (backbyte + t);
6590 }
6591
6592 vals[i] = cryptstring[i];
6593 }
6594
6595 ret = (vals[0] << 24) | (vals[1] << 16) | (vals[2] << 8) | (vals[3]);
6596
6597 if (ret == 0) {
6598 Int3(); // Get Jason, no match at all
6599 return 0;
6600 }
6601
6602 return ret;
6603 }
6604
6605 // Returns the unique id of a given object type/id
6606 uint32_t MultiGetMatchChecksum(int type, int id) {
6607 switch (type) {
6608 case OBJ_POWERUP:
6609 case OBJ_ROBOT:
6610 case OBJ_CLUTTER:
6611 case OBJ_BUILDING:
6612 return Multi_generic_match_table[id];
6613 break;
6614 case OBJ_WEAPON:
6615 return Multi_weapon_match_table[id];
6616 break;
6617 case OBJ_MARKER:
6618 return id;
6619 break;
6620 default:
6621 Int3(); // Get Jason
6622 }
6623
6624 Error("Invalid type/id combo in MultiGetMatchChecksum");
6625 return -1;
6626 }
6627
6628 // Return index of generic that has matching table entry
6629 int MultiMatchGeneric(uint32_t unique_id) {
6630 for (int i = 0; i < MAX_OBJECT_IDS; i++)
6631 if (Multi_generic_match_table[i] == unique_id)
6632 return i;
6633
6634 return -1;
6635 }
6636
6637 // Return index of generic that has matching table entry
6638 int MultiMatchWeapon(uint32_t unique_id) {
6639 for (int i = 0; i < MAX_WEAPONS; i++)
6640 if (Multi_weapon_match_table[i] == unique_id)
6641 return i;
6642
6643 return -1;
6644 }
6645
6646 // Builds the tables for uniquely identifying powerups and robots
6647 void MultiBuildMatchTables() {
6648 int i;
6649
6650 mprintf(0, "Building match tables for multiplayer.\n");
6651
6652 memset(Multi_generic_match_table, 0, MAX_OBJECT_IDS * sizeof(int));
6653 memset(Multi_weapon_match_table, 0, MAX_WEAPONS * sizeof(int));
6654
6655 // Build generic tables
6656 for (i = 0; i < MAX_OBJECT_IDS; i++) {
6657 if (Object_info[i].type != OBJ_NONE) {
6658 uint32_t val = MultiGetUniqueIDFromString(Object_info[i].name);
6659 val += Object_info[i].type;
6660
6661 // See if there is a hash collision. If so, increment the value and retry
6662 while ((MultiMatchGeneric(val)) != -1) {
6663
6664 mprintf(0, "Match collision!\n");
6665 Int3();
6666 val++;
6667 }
6668
6669 Multi_generic_match_table[i] = val;
6670 } else
6671 Multi_generic_match_table[i] = 0;
6672 }
6673
6674 // Build weapon tables
6675 for (i = 0; i < MAX_WEAPONS; i++) {
6676 if (Weapons[i].used) {
6677 uint32_t val = MultiGetUniqueIDFromString(Weapons[i].name);
6678
6679 // See if there is a hash collision. If so, increment the value and retry
6680 while ((MultiMatchWeapon(val)) != -1) {
6681 mprintf(0, "Match collision!\n");
6682 Int3();
6683 val++;
6684 }
6685
6686 Multi_weapon_match_table[i] = val;
6687 } else
6688 Multi_weapon_match_table[i] = 0;
6689 }
6690 }
6691
6692 // Paints all the goal rooms in a level with their colors
6693 void MultiPaintGoalRooms(int *texcolors) {
6694 int i;
6695 /*
6696 $$TABLE_TEXTURE "Redbase"
6697 $$TABLE_TEXTURE "Bluebase"
6698 $$TABLE_TEXTURE "Greenbase"
6699 $$TABLE_TEXTURE "Yellowbase"
6700 */
6701
6702 const char *tnames[] = {"RedBase", "BlueBase", "GreenBase", "YellowBase"};
6703
6704 for (i = 0; i < MAX_TEAMS; i++) {
6705 int roomnum = GetGoalRoomForTeam(i);
6706 if (roomnum != -1) {
6707 Rooms[roomnum].room_change_flags |= RCF_TEXTURE;
6708
6709 int tex;
6710 if (texcolors == NULL) {
6711 tex = FindTextureName(IGNORE_TABLE(tnames[i]));
6712 if (tex == -1)
6713 tex = 0;
6714 } else {
6715 tex = texcolors[i];
6716 if (tex == -1)
6717 continue;
6718 }
6719
6720 int goalfaces = 0;
6721 int t;
6722
6723 for (t = 0; t < Rooms[roomnum].num_faces && !goalfaces; t++) {
6724 if (Rooms[roomnum].faces[t].flags & FF_GOALFACE) {
6725 goalfaces = 1;
6726 }
6727 }
6728
6729 for (t = 0; t < Rooms[roomnum].num_faces; t++) {
6730 texture *texp = &GameTextures[Rooms[roomnum].faces[t].tmap];
6731 if ((!(texp->flags & TF_ALPHA)) && texp->r < .01 && texp->g < .01 && texp->b < .01) {
6732 if (!goalfaces || (goalfaces && Rooms[roomnum].faces[t].flags & FF_GOALFACE)) {
6733 Rooms[roomnum].faces[t].tmap = tex;
6734 Rooms[roomnum].faces[t].flags |= FF_TEXTURE_CHANGED;
6735 }
6736 }
6737 }
6738 }
6739 }
6740 }
6741
6742 void MultiSendKillObject(object *hit_obj, object *killer, float damage, int death_flags, float delay, int16_t seed) {
6743 int size;
6744 int count = 0;
6745 uint8_t data[MAX_GAME_DATA_SIZE];
6746 uint16_t hit_objnum, killer_objnum;
6747
6748 // mprintf(0,"MultiSendExplodeObject Hit obj:%d Killer Obj: %d\n",OBJNUM(hit_obj),OBJNUM(killer));
6749 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
6750
6751 ASSERT(hit_obj->flags & OF_CLIENT_KNOWS);
6752
6753 size = START_DATA(MP_ROBOT_EXPLODE, data, &count, 1);
6754 // Get the dying objnum
6755 hit_objnum = OBJNUM(hit_obj);
6756 // Get the killer objnum
6757
6758 if (killer != NULL)
6759 killer_objnum = OBJNUM(killer);
6760 else
6761 killer_objnum = 65535;
6762
6763 MultiAddUshort(hit_objnum, data, &count);
6764 MultiAddUshort(killer_objnum, data, &count);
6765 MultiAddFloat(damage, data, &count);
6766 MultiAddUint(death_flags, data, &count);
6767 MultiAddFloat(delay, data, &count);
6768 MultiAddUshort(seed, data, &count);
6769
6770 END_DATA(count, data, size);
6771 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_OBJECTS, false);
6772 }
6773
6774 void MultiDoRobotExplode(uint8_t *data) {
6775 int count = 0;
6776 float damage, delay;
6777 uint16_t hit_objnum, killer_objnum, seed;
6778 int death_flags;
6779
6780 MULTI_ASSERT_NOMESSAGE(Netgame.local_role != LR_SERVER);
6781
6782 SKIP_HEADER(data, &count);
6783 hit_objnum = Server_object_list[MultiGetUshort(data, &count)];
6784
6785 if (hit_objnum == 65535) {
6786 mprintf(0, "Bad hit_objnum(%d) MultiDoRobotExplode\n", hit_objnum);
6787 ASSERT(1);
6788 return;
6789 }
6790
6791 killer_objnum = MultiGetUshort(data, &count);
6792
6793 if (killer_objnum != 65535) {
6794 killer_objnum = Server_object_list[killer_objnum];
6795
6796 if (killer_objnum == 65535) {
6797 mprintf(0, "Bad killer_objnum(%d) in MultiDoRobotExplode()\n", killer_objnum);
6798 }
6799 }
6800
6801 damage = MultiGetFloat(data, &count);
6802 death_flags = MultiGetInt(data, &count);
6803 delay = MultiGetFloat(data, &count);
6804 seed = MultiGetUshort(data, &count);
6805 if (killer_objnum != 65535) {
6806 if ((Objects[killer_objnum].type != OBJ_NONE) && (Objects[hit_objnum].type != OBJ_NONE)) {
6807 Objects[hit_objnum].flags |= OF_SERVER_SAYS_DELETE;
6808 ps_srand(seed);
6809 KillObject(&Objects[hit_objnum], &Objects[killer_objnum], damage, death_flags, delay);
6810 }
6811 } else {
6812 if ((Objects[hit_objnum].type != OBJ_NONE)) {
6813 Objects[hit_objnum].flags |= OF_SERVER_SAYS_DELETE;
6814 ps_srand(seed);
6815 KillObject(&Objects[hit_objnum], NULL, damage, death_flags, delay);
6816 }
6817 }
6818 }
6819
6820 void MultiSendDamageObject(object *hit_obj, object *killer, float damage, int weaponid) {
6821 int size;
6822 int count = 0;
6823 uint8_t data[MAX_GAME_DATA_SIZE];
6824 uint16_t hit_objnum, killer_objnum;
6825
6826 // mprintf(0,"MultiSendDamageObject Hit obj:%d Killer Obj: %d\n",OBJNUM(hit_obj),OBJNUM(killer));
6827 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
6828 ASSERT(hit_obj->flags & OF_CLIENT_KNOWS);
6829 // mprintf(0,"$");//KBTEST
6830 size = START_DATA(MP_ROBOT_DAMAGE, data, &count, 1);
6831 // Get the dying objnum
6832 hit_objnum = OBJNUM(hit_obj);
6833 // Get the killer objnum
6834 killer_objnum = OBJNUM(killer);
6835 MultiAddUshort(hit_objnum, data, &count);
6836 MultiAddUshort(killer_objnum, data, &count);
6837 MultiAddFloat(damage, data, &count);
6838 MultiAddInt(weaponid, data, &count);
6839
6840 END_DATA(count, data, size);
6841 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_PLAYING, false);
6842 }
6843
6844 void MultiDoRobotDamage(uint8_t *data) {
6845 int count = 0;
6846 float damage;
6847 int weaponid;
6848 uint16_t hit_objnum, killer_objnum;
6849
6850 MULTI_ASSERT_NOMESSAGE(Netgame.local_role != LR_SERVER);
6851 SKIP_HEADER(data, &count);
6852 hit_objnum = Server_object_list[MultiGetUshort(data, &count)];
6853 killer_objnum = Server_object_list[MultiGetUshort(data, &count)];
6854
6855 if (hit_objnum == 65535 || killer_objnum == 65535 || !(Objects[hit_objnum].flags & OF_SERVER_OBJECT) ||
6856 !(Objects[killer_objnum].flags & OF_SERVER_OBJECT)) {
6857 mprintf(0, "Bad hit_objnum(%d) or killer_objnum(%d) in MultiDoRobotDamage()\n", hit_objnum, killer_objnum);
6858 // Int3(); // Get Jason, bad object number
6859 return;
6860 }
6861
6862 damage = MultiGetFloat(data, &count);
6863 weaponid = MultiGetInt(data, &count);
6864 if ((!((Objects[hit_objnum].flags & OF_DYING) || (Objects[hit_objnum].flags & OF_DEAD))) &&
6865 Objects[hit_objnum].type != 255)
6866 if ((!((Objects[killer_objnum].flags & OF_DYING) || (Objects[killer_objnum].flags & OF_DEAD))) &&
6867 Objects[killer_objnum].type != 255) {
6868 // The damage type doesn't matter on the client side (only server side) -- so, this one is bogus
6869 ApplyDamageToGeneric(&Objects[hit_objnum], &Objects[killer_objnum], GD_PHYSICS, damage, 1, weaponid);
6870 }
6871 }
6872
6873 void MultiAddObjAnimUpdate(int objnum) {
6874 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
6875 ASSERT(Objects[objnum].flags & OF_CLIENT_KNOWS);
6876 // mprintf(0,"D`");
6877 for (int i = 0; i < MAX_NET_PLAYERS; i++) {
6878 if (i == Player_num)
6879 continue;
6880 bool skip_this_obj = false;
6881 if ((NetPlayers[i].flags & NPF_CONNECTED) && (NetPlayers[i].sequence == NETSEQ_PLAYING)) {
6882 skip_this_obj = false;
6883 // Check to see if this robot is on the list already
6884 for (int b = 0; b < Num_changed_anim[i]; b++) {
6885 if (Changed_anim[b][i] == Objects[objnum].handle) {
6886 skip_this_obj = true;
6887 break;
6888 }
6889 }
6890 if (skip_this_obj == false) {
6891 if (Num_changed_anim[i] < MAX_CHANGED_OBJECTS) {
6892 Changed_anim[Num_changed_anim[i]][i] = Objects[objnum].handle;
6893 Num_changed_anim[i]++;
6894 }
6895 }
6896 }
6897 }
6898 }
6899
6900 int MultiStuffObjAnimUpdate(uint16_t objnum, uint8_t *data) {
6901 custom_anim multi_anim_info;
6902 int count = 0;
6903 int size = 0;
6904
6905 if (Netgame.local_role != LR_SERVER) {
6906 BailOnMultiplayer(NULL);
6907 return 0;
6908 }
6909
6910 // mprintf(0,"MultiStuffObjAnimUpdate Sending object %d\n",objnum);
6911 if (ObjGetAnimUpdate(objnum, &multi_anim_info)) // Checks if obj is still alive and all
6912 {
6913 ASSERT(Objects[objnum].flags & OF_CLIENT_KNOWS);
6914 size = START_DATA(MP_ANIM_UPDATE, data, &count);
6915 MultiAddUshort(objnum, data, &count);
6916 MultiAddFloat(multi_anim_info.server_time, data, &count);
6917 MultiAddUshort(multi_anim_info.server_anim_frame, data, &count);
6918 MultiAddByte(multi_anim_info.anim_start_frame, data, &count);
6919 MultiAddByte(multi_anim_info.anim_end_frame, data, &count);
6920 MultiAddFloat(multi_anim_info.anim_time, data, &count);
6921 MultiAddFloat(multi_anim_info.max_speed, data, &count);
6922 MultiAddByte(multi_anim_info.flags, data, &count);
6923 MultiAddShort(multi_anim_info.anim_sound_index, data, &count);
6924 END_DATA(count, data, size);
6925 return count;
6926 }
6927 return 0;
6928 }
6929
6930 void MultiDoObjAnimUpdate(uint8_t *data) {
6931 custom_anim multi_anim_info;
6932 int objnum;
6933 int count = 0;
6934 MULTI_ASSERT_NOMESSAGE(Netgame.local_role != LR_SERVER);
6935 // mprintf(0,"R`");
6936 SKIP_HEADER(data, &count);
6937 int serverobjnum = MultiGetUshort(data, &count);
6938 objnum = Server_object_list[serverobjnum];
6939 multi_anim_info.server_time = MultiGetFloat(data, &count);
6940 multi_anim_info.server_anim_frame = MultiGetUshort(data, &count);
6941 multi_anim_info.anim_start_frame = MultiGetByte(data, &count);
6942 multi_anim_info.anim_end_frame = MultiGetByte(data, &count);
6943 multi_anim_info.anim_time = MultiGetFloat(data, &count);
6944 multi_anim_info.max_speed = MultiGetFloat(data, &count);
6945 multi_anim_info.flags = MultiGetByte(data, &count);
6946 multi_anim_info.anim_sound_index = MultiGetShort(data, &count);
6947
6948 if (objnum == 65535) {
6949 mprintf(0, "bad objnum in MultiDoObjAnimUpdate() server=%d\n", serverobjnum);
6950 // Int3(); // Get Jason, bad object number
6951 return;
6952 }
6953
6954 if (Objects[objnum].type != 255) {
6955 ObjSetAnimUpdate(objnum, &multi_anim_info);
6956 }
6957 }
6958
6959 void MultiDoPlay3dSound(uint8_t *data) {
6960 int objnum;
6961 int16_t soundidx;
6962 int count = 0;
6963 MULTI_ASSERT_NOMESSAGE(Netgame.local_role != LR_SERVER);
6964
6965 SKIP_HEADER(data, &count);
6966 int serverobjnum = MultiGetUshort(data, &count);
6967 objnum = Server_object_list[serverobjnum];
6968
6969 soundidx = MultiGetShort(data, &count);
6970 uint8_t priority = MultiGetByte(data, &count);
6971
6972 if (objnum == 65535 || !(Objects[objnum].flags & OF_SERVER_OBJECT)) {
6973 mprintf(0, "Bad server objnum(%d) in MultiDoPlay3dSound().\n", serverobjnum);
6974 // Int3(); // Get Jason, bad object number
6975 return;
6976 }
6977
6978 Sound_system.Play3dSound(soundidx, &Objects[objnum], priority);
6979 }
6980
6981 void MultiPlay3dSound(int16_t soundidx, uint16_t objnum, int priority) {
6982 uint8_t data[MAX_GAME_DATA_SIZE];
6983 int count = 0;
6984 int size = 0;
6985 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
6986 ASSERT(Objects[objnum].flags & OF_CLIENT_KNOWS);
6987 // mprintf(0,"^");//KBTEST
6988 size = START_DATA(MP_PLAY_3D_SOUND_FROM_OBJ, data, &count);
6989 MultiAddUshort(objnum, data, &count);
6990 MultiAddShort(soundidx, data, &count);
6991 MultiAddByte(priority, data, &count);
6992 END_DATA(count, data, size);
6993
6994 // Add it to the outgoing queue. The MultiSendRobotFireSound() function will actually send it
6995 for (int i = 0; i < MAX_NET_PLAYERS; i++) {
6996 if (i == Player_num)
6997 continue;
6998
6999 if ((NetPlayers[i].flags & NPF_CONNECTED) && (NetPlayers[i].sequence == NETSEQ_PLAYING)) {
7000 if (Multi_send_size[i] + count >= MAX_GAME_DATA_SIZE)
7001 MultiSendFullPacket(i, 0);
7002
7003 memcpy(&Multi_send_buffer[i][Multi_send_size[i]], data, count);
7004 Multi_send_size[i] += count;
7005 MultiSendFullPacket(i, 0);
7006 }
7007 }
7008 }
7009
7010 void MultiSendRobotFireSound(int16_t soundidx, uint16_t objnum) {
7011 int size;
7012 int count = 0;
7013 uint8_t data[MAX_GAME_DATA_SIZE];
7014 // mprintf(0,"&");//KBTEST
7015 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
7016 // mprintf(0,"Sending Robot %d fire sound.\n",objnum);
7017 object *obj = &Objects[objnum];
7018
7019 ASSERT(obj->flags & OF_CLIENT_KNOWS);
7020
7021 size = START_DATA(MP_ROBOT_FIRE_SOUND, data, &count);
7022 MultiAddUshort(objnum, data, &count);
7023
7024 MultiAddShort(soundidx, data, &count);
7025
7026 END_DATA(count, data, size);
7027
7028 // Add it to the outgoing queue. The MultiSendRobotFireSound() function will actually send it
7029 for (int i = 0; i < MAX_NET_PLAYERS; i++) {
7030 if (i == Player_num)
7031 continue;
7032
7033 if ((NetPlayers[i].flags & NPF_CONNECTED) && (NetPlayers[i].sequence == NETSEQ_PLAYING)) {
7034 if (Multi_send_size[i] + count >= MAX_GAME_DATA_SIZE)
7035 MultiSendFullPacket(i, 0);
7036
7037 memcpy(&Multi_send_buffer[i][Multi_send_size[i]], data, count);
7038 Multi_send_size[i] += count;
7039 MultiSendFullPacket(i, 0);
7040 }
7041 }
7042 }
7043
7044 void MultiDoRobotFireSound(uint8_t *data) {
7045 int objnum;
7046 int16_t soundidx;
7047 int count = 0;
7048 MULTI_ASSERT_NOMESSAGE(Netgame.local_role != LR_SERVER);
7049 SKIP_HEADER(data, &count);
7050
7051 int serverobjnum = MultiGetUshort(data, &count);
7052 objnum = Server_object_list[serverobjnum];
7053 soundidx = MultiGetShort(data, &count);
7054
7055 if (objnum == 65535 || !(Objects[objnum].flags & OF_SERVER_OBJECT)) {
7056 mprintf(0, "Bad server objnum(%d) in MultiDoRobotFireSound().Objnum = %d\n", serverobjnum, objnum);
7057 // Int3(); // Get Jason, bad object number
7058 return;
7059 }
7060 Sound_system.Play3dSound(soundidx, &Objects[objnum]);
7061 }
7062
7063 void MultiAddObjTurretUpdate(int objnum) {
7064
7065 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
7066 ASSERT(Objects[objnum].flags & OF_CLIENT_KNOWS);
7067
7068 for (int i = 0; i < MAX_NET_PLAYERS; i++) {
7069 if (i == Player_num)
7070 continue;
7071 bool skip_this_obj = false;
7072 if ((NetPlayers[i].flags & NPF_CONNECTED) && (NetPlayers[i].sequence == NETSEQ_PLAYING)) {
7073 skip_this_obj = false;
7074 // Check to see if this robot is on the list already
7075 for (int b = 0; b < Num_changed_turret[i]; b++) {
7076 if (Changed_turret[b][i] == Objects[objnum].handle) {
7077 skip_this_obj = true;
7078 break;
7079 }
7080 }
7081 if (skip_this_obj == false) {
7082 if (Num_changed_turret[i] < MAX_CHANGED_OBJECTS) {
7083 Changed_turret[Num_changed_turret[i]][i] = Objects[objnum].handle;
7084 Num_changed_turret[i]++;
7085 }
7086 }
7087 }
7088 }
7089 }
7090
7091 int MultiStuffTurretUpdate(uint16_t objnum, uint8_t *data) {
7092 int count = 0;
7093 int size = 0;
7094 multi_turret multi_turret_info;
7095 // mprintf(0,"MultiStuffTurretUpdate Sending object %d\n",objnum);
7096 if (Netgame.local_role != LR_SERVER) {
7097 BailOnMultiplayer(NULL);
7098 return 0;
7099 }
7100
7101 object *obj = &Objects[objnum];
7102 polyobj_info *p_info = &obj->rtype.pobj_info;
7103 if ((objnum >= 0) && (obj->type != OBJ_NONE) && (obj->type != OBJ_WEAPON) && (obj->flags & OF_POLYGON_OBJECT) &&
7104 (p_info->multi_turret_info.num_turrets)) {
7105 int i;
7106 ASSERT(Objects[objnum].flags & OF_CLIENT_KNOWS);
7107 size = START_DATA(MP_TURRET_UPDATE, data, &count);
7108 MultiAddUshort(objnum, data, &count);
7109
7110 multi_turret_info.keyframes = (float *)&turret_holder;
7111 ObjGetTurretUpdate(objnum, &multi_turret_info);
7112
7113 MultiAddFloat(multi_turret_info.time, data, &count);
7114 MultiAddUshort(multi_turret_info.num_turrets, data, &count);
7115
7116 for (i = 0; i < multi_turret_info.num_turrets; i++) {
7117 if (MAX_COOP_TURRETS > i)
7118 MultiAddFloat(multi_turret_info.keyframes[i], data, &count);
7119 }
7120 END_DATA(count, data, size);
7121 }
7122
7123 return count;
7124 }
7125
7126 void MultiDoTurretUpdate(uint8_t *data) {
7127
7128 multi_turret multi_turret_info;
7129 int objnum;
7130 uint16_t num_turrets;
7131 float turr_time;
7132 int count = 0;
7133 MULTI_ASSERT_NOMESSAGE(Netgame.local_role != LR_SERVER);
7134
7135 SKIP_HEADER(data, &count);
7136
7137 int serverobjnum = MultiGetUshort(data, &count);
7138 objnum = Server_object_list[serverobjnum];
7139
7140 if (objnum == 65535 || !(Objects[objnum].flags & OF_SERVER_OBJECT)) {
7141 mprintf(0, "Bad server objnum(%d) in MultiDoTurretUpdate().\n", serverobjnum);
7142 // Int3(); // Get Jason , bad object number
7143 return;
7144 }
7145
7146 turr_time = MultiGetFloat(data, &count);
7147 num_turrets = MultiGetUshort(data, &count);
7148 multi_turret_info.keyframes = (float *)&turret_holder;
7149 multi_turret_info.num_turrets = num_turrets;
7150 for (int i = 0; i < num_turrets; i++) {
7151 if (MAX_COOP_TURRETS > i)
7152 multi_turret_info.keyframes[i] = MultiGetFloat(data, &count);
7153 }
7154
7155 if (Objects[objnum].type != 255) {
7156 ObjSetTurretUpdate(objnum, &multi_turret_info);
7157 }
7158 }
7159
7160 void MultiSendClientInventoryUseItem(int type, int id) {
7161 if (id == -1) {
7162 mprintf(0, "Asking server to use objnum %d\n", OBJNUM(ObjGet(type)));
7163 } else {
7164 mprintf(0, "Asking server to use T=%d ID=%d\n", type, id);
7165 }
7166
7167 int size = 0;
7168 uint8_t data[MAX_GAME_DATA_SIZE];
7169 int count = 0;
7170 // Client sends this only
7171 MULTI_ASSERT_NOMESSAGE(Netgame.local_role != LR_SERVER);
7172
7173 if (id != -1) {
7174 // type/id use
7175 size = START_DATA(MP_CLIENT_USE_INVENTORY_ITEM, data, &count, 1);
7176 MultiAddUshort(type, data, &count);
7177 MultiAddUint(MultiGetMatchChecksum(type, id), data, &count);
7178 END_DATA(count, data, size);
7179 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count, false);
7180
7181 } else {
7182 // object use
7183 int local_objhandle = type;
7184 object *local_obj = ObjGet(local_objhandle);
7185 ASSERT(local_obj);
7186 ASSERT(local_obj->type != OBJ_NONE);
7187
7188 if (local_obj) {
7189 int server_objnum = Local_object_list[OBJNUM(local_obj)];
7190 ASSERT(server_objnum != 65535);
7191
7192 mprintf(0, "Inven Use: Requesting to use server objnum %d. T=%d i=%d\n",
7193 server_objnum,
7194 local_obj->type,
7195 local_obj->id);
7196
7197 size = START_DATA(MP_CLIENT_USE_INVENTORY_ITEM, data, &count, 1);
7198 MultiAddUshort(server_objnum, data, &count);
7199 MultiAddUint(0xFFFFFFFF, data, &count);
7200 END_DATA(count, data, size);
7201 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count, false);
7202 }
7203 }
7204 }
7205
7206 void MultiDoClientInventoryUseItem(int slot, uint8_t *data) {
7207 int count = 0;
7208 int type;
7209 int id;
7210 uint32_t hash;
7211
7212 // Only the server receives this
7213 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
7214 SKIP_HEADER(data, &count);
7215
7216 type = MultiGetUshort(data, &count);
7217 hash = MultiGetUint(data, &count);
7218
7219 bool is_counter_measure = false;
7220
7221 if (hash == 0xFFFFFFFF) {
7222 // object use
7223 int server_objnum;
7224 server_objnum = type;
7225
7226 mprintf(0, "Inven: use request objnum %d\n", server_objnum);
7227
7228 // the objnum coming in better be in our object list
7229 ASSERT(server_objnum >= 0 && server_objnum < MAX_OBJECTS);
7230 ASSERT(Objects[server_objnum].type != OBJ_NONE);
7231
7232 mprintf(0, "Client is asking me to use objnum %d\n", server_objnum);
7233
7234 // convert type to objhandle
7235 type = Objects[server_objnum].handle;
7236 id = -1;
7237 } else {
7238 // type/id use
7239 if (type == OBJ_WEAPON) {
7240 id = MultiMatchWeapon(hash);
7241 is_counter_measure = true;
7242 } else {
7243 id = MultiMatchGeneric(hash);
7244 }
7245
7246 mprintf(0, "Client is asking me to use T=%d ID=%d\n", type, id);
7247 }
7248
7249 if (is_counter_measure) {
7250 if (Players[slot].counter_measures.FindPos(type, id)) {
7251 mprintf(0, "I found it, so I'm going to use it\n");
7252 if (Players[slot].counter_measures.UsePos(&Objects[Players[slot].objnum])) {
7253 // Tell clients to remove this item
7254 MultiSendInventoryRemoveItem(slot, type, id);
7255 }
7256 } else {
7257 mprintf(0, "But I couldn't find it in my copy of his inventory\n");
7258 }
7259 } else {
7260 if (Players[slot].inventory.FindPos(type, id)) {
7261 if (id == -1) {
7262 mprintf(0, "I found it, so I'm going to use it, type=%d id=%d\n", type, id);
7263 } else {
7264 mprintf(0, "I found it, so I'm going to use it, handle=0x%x id=%d\n", type, id);
7265 }
7266
7267 if (Players[slot].inventory.UsePos(&Objects[Players[slot].objnum])) {
7268 // Tell clients to remove this item
7269 MultiSendInventoryRemoveItem(slot, type, id);
7270 }
7271 } else {
7272 mprintf(0, "But I couldn't find it in my copy of his inventory\n");
7273 }
7274 }
7275 }
7276
7277 // Handle a remove item from inventory
7278 void MultiDoClientInventoryRemoveItem(int slot, uint8_t *data) {
7279 int count = 0;
7280 int type;
7281 int id;
7282 uint32_t hash;
7283 int pnum;
7284
7285 // Only the server receives this
7286 MULTI_ASSERT_NOMESSAGE(Netgame.local_role != LR_SERVER);
7287 SKIP_HEADER(data, &count);
7288
7289 type = MultiGetUshort(data, &count);
7290 hash = MultiGetUint(data, &count);
7291 pnum = MultiGetByte(data, &count);
7292
7293 if (hash == 0xFFFFFFFF) {
7294 // object given
7295 id = -1;
7296
7297 // convert server objnum to a local objnum
7298 type = Server_object_list[type];
7299
7300 // the objnum coming in better be in our object list
7301 ASSERT(type >= 0 && type < MAX_OBJECTS);
7302 ASSERT(Objects[type].type != OBJ_NONE);
7303
7304 mprintf(0, "Server is telling me to remove objnum %d\n", type);
7305
7306 // convert type to objhandle
7307 type = Objects[type].handle;
7308
7309 Players[pnum].inventory.Remove(type, id);
7310
7311 } else {
7312
7313 if (type == OBJ_WEAPON) {
7314 id = MultiMatchWeapon(hash);
7315 mprintf(0, "Server is telling me to remove T=%d ID=%d from %d\n", type, id, pnum);
7316 Players[pnum].counter_measures.Remove(type, id);
7317 } else {
7318 id = MultiMatchGeneric(hash);
7319 mprintf(0, "Server is telling me to remove T=%d ID=%d from %d\n", type, id, pnum);
7320 Players[pnum].inventory.Remove(type, id);
7321 }
7322 }
7323 }
7324
7325 // Tell the clients to remove an item from a player's inventory
7326 void MultiSendInventoryRemoveItem(int slot, int type, int id) {
7327 if (id == -1) {
7328 mprintf(0, "Telling clients to remove objnum %d from %d\n", OBJNUM(ObjGet(type)), slot);
7329 } else {
7330 mprintf(0, "Telling clients to remove inven item T=%d ID=%d from %d\n", type, id, slot);
7331 }
7332
7333 int size = 0;
7334 uint8_t data[MAX_GAME_DATA_SIZE];
7335 int count = 0;
7336
7337 if (id == -1) {
7338 object *o = ObjGet(type);
7339 ASSERT(o);
7340 if (o) {
7341 int objnum = OBJNUM(o);
7342
7343 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
7344 size = START_DATA(MP_REMOVE_INVENTORY_ITEM, data, &count, 1);
7345 MultiAddUshort(objnum, data, &count);
7346 MultiAddUint(0xFFFFFFFF, data, &count);
7347 MultiAddByte(slot, data, &count);
7348 END_DATA(count, data, size);
7349 MultiSendReliablyToAllExcept(Player_num, data, count, false);
7350 }
7351
7352 } else {
7353 // type/id
7354 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
7355 size = START_DATA(MP_REMOVE_INVENTORY_ITEM, data, &count, 1);
7356 MultiAddUshort((uint16_t)type, data, &count);
7357 MultiAddUint(MultiGetMatchChecksum(type, id), data, &count);
7358 MultiAddByte(slot, data, &count);
7359 END_DATA(count, data, size);
7360 MultiSendReliablyToAllExcept(Player_num, data, count, false);
7361 }
7362 }
7363
7364 void MultiSetAudioTauntTime(float time, int to_who) {
7365 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
7366
7367 taunt_SetDelayTime(time);
7368 time = taunt_DelayTime(); // make sure it is valid
7369
7370 int size = 0;
7371 uint8_t data[MAX_GAME_DATA_SIZE];
7372 int count = 0;
7373
7374 size = START_DATA(MP_SERVER_AUDIOTAUNT_TIME, data, &count, 1);
7375 MultiAddFloat(time, data, &count);
7376 END_DATA(count, data, size);
7377
7378 if (to_who == -1) {
7379 MultiSendReliablyToAllExcept(Player_num, data, count);
7380 } else {
7381 MULTI_ASSERT_NOMESSAGE(to_who >= 0 && to_who < MAX_NET_PLAYERS);
7382 MULTI_ASSERT_NOMESSAGE((NetPlayers[to_who].flags & NPF_CONNECTED) &&
7383 (NetPlayers[to_who].sequence == NETSEQ_PLAYING));
7384 nw_SendReliable(NetPlayers[to_who].reliable_socket, data, count);
7385 }
7386 }
7387
7388 void MultiDoAudioTauntTime(uint8_t *data) {
7389 int count = 0;
7390 MULTI_ASSERT_NOMESSAGE(Netgame.local_role != LR_SERVER);
7391
7392 SKIP_HEADER(data, &count);
7393
7394 float time = MultiGetFloat(data, &count);
7395 taunt_SetDelayTime(time);
7396 }
7397
7398 void MultiAddObjWBAnimUpdate(int objnum) {
7399 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
7400 ASSERT(Objects[objnum].flags & OF_CLIENT_KNOWS);
7401 // mprintf(0,"D`");
7402 for (int i = 0; i < MAX_NET_PLAYERS; i++) {
7403 if (i == Player_num)
7404 continue;
7405 bool skip_this_obj = false;
7406 if ((NetPlayers[i].flags & NPF_CONNECTED) && (NetPlayers[i].sequence == NETSEQ_PLAYING)) {
7407 skip_this_obj = false;
7408 // Check to see if this robot is on the list already
7409 for (int b = 0; b < Num_changed_wb_anim[i]; b++) {
7410 if (Changed_wb_anim[b][i] == Objects[objnum].handle) {
7411 skip_this_obj = true;
7412 break;
7413 }
7414 }
7415 if (skip_this_obj == false) {
7416 if (Num_changed_wb_anim[i] < MAX_CHANGED_OBJECTS) {
7417 Changed_wb_anim[Num_changed_wb_anim[i]][i] = Objects[objnum].handle;
7418 Num_changed_wb_anim[i]++;
7419 }
7420 }
7421 }
7422 }
7423 }
7424
7425 int MultiStuffObjWBAnimUpdate(uint16_t objnum, uint8_t *data) {
7426 // multi_anim multi_anim_info;
7427 int count = 0;
7428 int size = 0;
7429
7430 if (Netgame.local_role != LR_SERVER) {
7431 BailOnMultiplayer(NULL);
7432 return 0;
7433 }
7434
7435 ASSERT(Objects[objnum].flags & OF_CLIENT_KNOWS);
7436 // mprintf(0,"%");//KBTEST
7437 /*
7438 if(ObjGetAnimUpdate(objnum, &multi_anim_info)) // Checks if obj is still alive and all
7439 {
7440 size=START_DATA (MP_ANIM_UPDATE,data,&count);
7441 MultiAddUshort(objnum,data,&count);
7442 MultiAddFloat (multi_anim_info.server_time,data,&count);
7443 MultiAddUshort(multi_anim_info.server_anim_frame,data,&count);
7444 MultiAddByte(multi_anim_info.anim_start_frame,data,&count);
7445 MultiAddByte(multi_anim_info.anim_end_frame,data,&count);
7446 MultiAddFloat (multi_anim_info.anim_time,data,&count);
7447 MultiAddFloat (multi_anim_info.max_speed,data,&count);
7448 MultiAddByte(multi_anim_info.flags,data,&count);
7449 MultiAddShort(multi_anim_info.anim_sound_index,data,&count);
7450 END_DATA (count,data,size);
7451 return count;
7452 }
7453 */
7454 return 0;
7455 }
7456
7457 void MultiDoObjWBAnimUpdate(uint8_t *data) {
7458 // multi_anim multi_anim_info;
7459 // int objnum;
7460 int count = 0;
7461 MULTI_ASSERT_NOMESSAGE(Netgame.local_role != LR_SERVER);
7462 // mprintf(0,"R`");
7463 SKIP_HEADER(data, &count);
7464 /*
7465 objnum = Server_object_list[MultiGetUshort (data,&count)];
7466 multi_anim_info.server_time = MultiGetFloat (data,&count);
7467 multi_anim_info.server_anim_frame = MultiGetUshort (data,&count);
7468 multi_anim_info.anim_start_frame = MultiGetByte (data,&count);
7469 multi_anim_info.anim_end_frame = MultiGetByte (data,&count);
7470 multi_anim_info.anim_time = MultiGetFloat (data,&count);
7471 multi_anim_info.max_speed = MultiGetFloat (data,&count);
7472 multi_anim_info.flags = MultiGetByte (data,&count);
7473 multi_anim_info.anim_sound_index = MultiGetShort (data,&count);
7474 if(Objects[objnum].type!=255)
7475 {
7476 ObjSetWBAnimUpdate(objnum, &multi_anim_info);
7477 }
7478 */
7479 }
7480
7481 void MultiSendBytesSent(int slot) {
7482 int size = 0;
7483 uint8_t data[MAX_GAME_DATA_SIZE];
7484 int count = 0;
7485 // Server sends this only
7486 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
7487 size = START_DATA(MP_SERVER_SENT_COUNT, data, &count, 1);
7488 MultiAddUint(NetPlayers[slot].total_bytes_sent, data, &count);
7489 END_DATA(count, data, size);
7490 NetPlayers[slot].total_bytes_sent = 0;
7491 NetPlayers[slot].total_bytes_rcvd = 0;
7492 nw_SendReliable(NetPlayers[slot].reliable_socket, data, count, false);
7493 }
7494
7495 #define PPS_MAX 10
7496 #define PPS_MIN 2
7497 #define PING_FALLOFF 3.0
7498
7499 #define MIN(a, b) ((a < b) ? a : b)
7500
7501 void MultiDoBytesSent(uint8_t *data) {
7502 int count = 0;
7503 uint32_t server_sent;
7504 float drop_ratio;
7505 SKIP_HEADER(data, &count);
7506 server_sent = MultiGetUint(data, &count);
7507 int dropped = server_sent - NetPlayers[Player_num].total_bytes_rcvd;
7508 if (dropped > 0) {
7509 drop_ratio = (float)NetPlayers[Player_num].total_bytes_rcvd / (float)server_sent;
7510 float loss = 1 - drop_ratio;
7511 int pct_loss = loss * 100;
7512 NetPlayers[Player_num].percent_loss = pct_loss;
7513
7514 if (pct_loss > 15) {
7515 if (Bandwidth_throttle >= 0)
7516 Bandwidth_throttle++;
7517 else
7518 Bandwidth_throttle = 0;
7519 } else if (pct_loss < 5) {
7520 if (Bandwidth_throttle <= 0)
7521 Bandwidth_throttle--;
7522 else
7523 Bandwidth_throttle = 0;
7524 }
7525 if (NetPlayers[Player_num].ping_time >= PING_FALLOFF) {
7526 Bandwidth_throttle--;
7527 Bandwidth_throttle--;
7528 }
7529 // mprintf_at(2,1,0,"Packet Loss: %d%% ",pct_loss);
7530 } else {
7531 // mprintf_at(2,1,0,"Packet Loss: 0%% ");
7532 NetPlayers[Player_num].percent_loss = 0;
7533 Bandwidth_throttle--;
7534 }
7535 if (Bandwidth_throttle >= 3) {
7536 // Time to lower the pps setting!
7537 if (NetPlayers[Player_num].pps > PPS_MIN) {
7538 NetPlayers[Player_num].pps--;
7539 MultiSendPPSSet(NetPlayers[Player_num].pps);
7540 Bandwidth_throttle = 0;
7541 }
7542 } else if (Bandwidth_throttle <= -2) {
7543 // Time to up the pps setting!
7544 if (NetPlayers[Player_num].pps < MIN(nw_ReccomendPPS(), Netgame.packets_per_second)) {
7545 NetPlayers[Player_num].pps++;
7546 MultiSendPPSSet(NetPlayers[Player_num].pps);
7547 Bandwidth_throttle = 0;
7548 }
7549 }
7550 NetPlayers[Player_num].total_bytes_rcvd = 0;
7551 }
7552
7553 void MultiSendPPSSet(int pps) {
7554 int size = 0;
7555 uint8_t data[MAX_GAME_DATA_SIZE];
7556 int count = 0;
7557 // Client sends this only
7558 MULTI_ASSERT_NOMESSAGE(Netgame.local_role != LR_SERVER);
7559 size = START_DATA(MP_CLIENT_SET_PPS, data, &count, 1);
7560 MultiAddByte(pps, data, &count);
7561 mprintf(0, "Telling the server we want a PPS of %d\n", pps);
7562 END_DATA(count, data, size);
7563 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count, false);
7564 }
7565
7566 void MultiDoPPSSet(uint8_t *data, int slot) {
7567 int count = 0;
7568 SKIP_HEADER(data, &count);
7569 NetPlayers[slot].pps = MultiGetByte(data, &count);
7570 mprintf(0, "%s changed his PPS to %d\n", Players[slot].callsign, NetPlayers[slot].pps);
7571 }
7572
7573 void MultiSendGreetings(uint32_t id) {
7574 int size = 0;
7575 uint8_t data[MAX_GAME_DATA_SIZE];
7576 int count = 0;
7577 // Client sends this only
7578 MULTI_ASSERT_NOMESSAGE(Netgame.local_role != LR_SERVER);
7579 size = START_DATA(MP_GREETINGS_FROM_CLIENT, data, &count);
7580 MultiAddUint(id, data, &count);
7581 mprintf(0, "Saying hello to the server\n");
7582 END_DATA(count, data, size);
7583 nw_Send(&Netgame.server_address, data, count, 0);
7584 }
7585
7586 void MultiDoGreetings(uint8_t *data, network_address *addr) {
7587 int count = 0;
7588 SKIP_HEADER(data, &count);
7589 uint32_t id = MultiGetUint(data, &count);
7590 int i;
7591 // mprintf(0,"Got a greeting packet with an id of %d\n");
7592 for (i = 0; i < MAX_NET_PLAYERS; i++) {
7593 // mprintf(0,"Netplayer[%d] has an id of %d\n",i,NetPlayers[i].secret_net_id);
7594 if (NetPlayers[i].secret_net_id == id) {
7595 // Get the address
7596 memcpy(&NetPlayers[i].addr, addr, sizeof(network_address));
7597 return;
7598 }
7599 }
7600 }
7601
7602 // Ask for a file from the client if you are the server
7603 // Or, if you are the server, ask a client
7604 // file_id = NETFILE_ID_???? type
7605 // file_who = If you are the client who's file you want from the server
7606 // who = player number of who you are asking for the file
7607 void MultiAskForFile(uint16_t file_id, uint16_t file_who, uint16_t who) {
7608 int size = 0;
7609 uint8_t data[MAX_GAME_DATA_SIZE];
7610 int count = 0;
7611 //@@mprintf(0,"Asking player %d for a file (%d) from player %d\n",who,file_id,file_who);
7612 if (NetPlayers[who].file_xfer_flags != NETFILE_NONE) {
7613 mprintf(0, "File already in progress, can't start another one!\n");
7614 Int3();
7615 return; // Make sure a file isn't in progress
7616 }
7617 if (who == Player_num) {
7618 mprintf(0, "Can't send a file to myself!\n");
7619 return;
7620 }
7621 // Check to see if this file exists already
7622 char *p = GetFileNameFromPlayerAndID(file_who, file_id);
7623 if (*p) {
7624 if (CFES_ON_DISK == cfexist(p)) {
7625 char szcrc[_MAX_PATH];
7626 char path[_MAX_PATH];
7627 char ext[_MAX_PATH];
7628 char file[_MAX_PATH];
7629
7630 ddio_SplitPath(p, path, file, ext);
7631 snprintf(szcrc, sizeof(szcrc), "_%.8x", cf_GetfileCRC(p));
7632 // See if the the CRC is already in the filename
7633 if (strnicmp(szcrc, file + (strlen(file) - 9), 9) != 0) {
7634 mprintf(0, "Bad CRC on file %s! It must be corrupt! File will not be used, and is being deleted!\n", p);
7635 ddio_DeleteFile(p);
7636 } else {
7637 // Hey hey, we already have this file
7638 mprintf(0, "Using existing file: %s\n", p);
7639 DoNextPlayerFile(file_who);
7640 return;
7641 }
7642 }
7643 } else {
7644 // No file
7645 mprintf(0, "No custom file %d for player %d\n", file_id, file_who);
7646 DoNextPlayerFile(file_who);
7647 return;
7648 }
7649
7650 size = START_DATA(MP_FILE_REQ, data, &count);
7651 MultiAddUshort(file_id, data, &count);
7652 MultiAddUshort(file_who, data, &count);
7653 MultiAddUshort(Player_num, data, &count);
7654 END_DATA(count, data, size);
7655 if (Netgame.local_role == LR_SERVER) {
7656 // If we are a server, send a request to the client asking for a file of theirs
7657 mprintf(0, "Asking client %d for a file.\n", who);
7658 nw_SendReliable(NetPlayers[who].reliable_socket, data, count);
7659 NetPlayers[who].file_xfer_flags = NETFILE_ASKING;
7660 NetPlayers[who].file_xfer_pos = 0;
7661 NetPlayers[who].file_xfer_cfile = NULL;
7662 NetPlayers[who].file_xfer_who = file_who;
7663 } else {
7664 // If we are a client, ask the server for a file
7665 mprintf(0, "Asking server for a file.\n");
7666 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count);
7667 NetPlayers[file_who].file_xfer_flags = NETFILE_ASKING;
7668 NetPlayers[file_who].file_xfer_pos = 0;
7669 NetPlayers[file_who].file_xfer_cfile = NULL;
7670 NetPlayers[file_who].file_xfer_who = file_who;
7671 }
7672 }
7673
7674 void MultiDoFileReq(uint8_t *data) {
7675 int count = 0;
7676 SKIP_HEADER(data, &count);
7677 uint16_t filenum = MultiGetUshort(data, &count);
7678 uint16_t filewho = MultiGetUshort(data, &count);
7679 uint16_t playernum = MultiGetUshort(data, &count);
7680 // If we are the server, someone want's a file. Either start sending it to them, or deny the request
7681 if (NetPlayers[playernum].file_xfer_flags == NETFILE_NONE) {
7682 // FIXME!! Figure out what file to open
7683 CFILE *cfp;
7684 // char filename[_MAX_PATH];
7685 char filewithpath[_MAX_PATH * 2];
7686 strcpy(filewithpath, GetFileNameFromPlayerAndID(filewho, filenum));
7687 if (filewithpath[0] == 0) {
7688 mprintf(0, "Got a file request for a file that doesn't exist (%s).\n", filewithpath);
7689 DenyFile(playernum, filenum, NetPlayers[playernum].file_xfer_who);
7690 } else {
7691 cfp = cfopen(filewithpath, "rb");
7692 if (!cfp) {
7693 mprintf(0, "Couldn't open a file (%s) for transfer.\n", filewithpath);
7694 DenyFile(playernum, filenum, NetPlayers[playernum].file_xfer_who);
7695 return;
7696 // We couldn't create the file, so cancel the attempt to transfer it.
7697 }
7698 mprintf(0, "Sending first data chunk!\n");
7699 NetPlayers[playernum].file_xfer_who = filewho;
7700 NetPlayers[playernum].file_xfer_cfile = cfp;
7701 NetPlayers[playernum].file_xfer_pos = 0;
7702 NetPlayers[playernum].file_xfer_flags = NETFILE_SENDING;
7703 NetPlayers[playernum].file_xfer_total_len = cfp->size;
7704 NetPlayers[playernum].file_xfer_id = filenum;
7705 mprintf(0, "File size = %d\n", cfp->size);
7706 SendDataChunk(playernum);
7707 }
7708 } else {
7709 mprintf(0, "Got a file request while one was already in progress!\n");
7710 DenyFile(playernum, filenum, NetPlayers[playernum].file_xfer_who);
7711 }
7712 }
7713
7714 void DenyFile(int playernum, int filenum, int file_who) {
7715 int size = 0;
7716 uint8_t outdata[MAX_GAME_DATA_SIZE];
7717 int count = 0;
7718 size = START_DATA(MP_FILE_DENIED, outdata, &count);
7719 MultiAddUshort(filenum, outdata, &count);
7720 MultiAddUshort(Player_num, outdata, &count);
7721 MultiAddUshort(file_who, outdata, &count);
7722 END_DATA(count, outdata, size);
7723 NetPlayers[playernum].file_xfer_cfile = NULL;
7724 if (Netgame.local_role == LR_SERVER) {
7725 nw_SendReliable(NetPlayers[playernum].reliable_socket, outdata, count);
7726 } else {
7727 nw_SendReliable(NetPlayers[Player_num].reliable_socket, outdata, count);
7728 }
7729 }
7730
7731 void MultiCancelFile(int playernum, int filenum, int file_who) {
7732 int size = 0;
7733 uint8_t outdata[MAX_GAME_DATA_SIZE];
7734 int count = 0;
7735 // Send message to our peer and abort the xfer
7736 if (NetPlayers[playernum].file_xfer_cfile) {
7737 cfclose(NetPlayers[playernum].file_xfer_cfile);
7738 }
7739
7740 size = START_DATA(MP_FILE_CANCEL, outdata, &count);
7741 MultiAddUshort(playernum, outdata, &count);
7742 MultiAddUshort(filenum, outdata, &count);
7743 MultiAddUshort(file_who, outdata, &count);
7744 END_DATA(count, outdata, size);
7745 NetPlayers[playernum].file_xfer_cfile = NULL;
7746 NetPlayers[playernum].file_xfer_pos = 0;
7747 NetPlayers[playernum].file_xfer_flags = NETFILE_NONE;
7748 if (Netgame.local_role == LR_SERVER) {
7749 nw_SendReliable(NetPlayers[playernum].reliable_socket, outdata, count);
7750 } else {
7751 nw_SendReliable(NetPlayers[Player_num].reliable_socket, outdata, count);
7752 }
7753 }
7754 void MultiDoFileDenied(uint8_t *data) {
7755 // We asked for a file, but the request was denied for some reason
7756 int count = 0;
7757 SKIP_HEADER(data, &count);
7758 uint16_t filenum = MultiGetUshort(data, &count);
7759 uint16_t playernum = MultiGetUshort(data, &count);
7760 uint16_t filewho = MultiGetUshort(data, &count);
7761 mprintf(0, "Got a file denied packet from %d\n", playernum);
7762
7763 DoNextPlayerFile(filewho);
7764 }
7765
7766 void MultiDoFileData(uint8_t *data) {
7767 // File data. We asked for it, now the server is sending it to us.
7768 uint32_t total_len; // Length of the entire file
7769 uint32_t curr_len; // Length of file sent so far
7770 uint16_t file_id; // Defines which file this is
7771 uint16_t playernum; // Who is sending us the file
7772 uint16_t data_len; // between 1-450 bytes
7773 // uint16_t file_who;
7774 int count = 0;
7775 uint8_t outdata[MAX_GAME_DATA_SIZE];
7776 int outcount = 0;
7777 int size;
7778
7779 SKIP_HEADER(data, &count);
7780 total_len = MultiGetUint(data, &count);
7781 curr_len = MultiGetUint(data, &count); // Length of the file after before this data chunk
7782 file_id = MultiGetUshort(data, &count);
7783 playernum = MultiGetUshort(data, &count);
7784 // file_who = MultiGetUshort (data,&count);
7785 data_len = MultiGetUshort(data, &count);
7786 // mprintf(0,"Got a data packet from %d\n",playernum);
7787 if ((NetPlayers[playernum].file_xfer_flags == NETFILE_RECEIVING) ||
7788 (NetPlayers[playernum].file_xfer_flags == NETFILE_ASKING)) {
7789
7790 // Find out if this is the first packet of this file. if so, create and open the file
7791 if (NetPlayers[playernum].file_xfer_pos == 0) {
7792 mprintf(0, "Creating file...\n");
7793 CFILE *cfp;
7794 // char filename[_MAX_PATH];
7795 char filewithpath[_MAX_PATH * 2];
7796 strcpy(filewithpath, GetFileNameFromPlayerAndID(playernum, file_id));
7797
7798 cfp = cfopen(filewithpath, "wb");
7799 if (!cfp) {
7800 mprintf(0, "Can't create file %s\n", filewithpath);
7801 // We couldn't create the file, so cancel the attempt to transfer it.
7802 MultiCancelFile(playernum, file_id, NetPlayers[playernum].file_xfer_who);
7803 return;
7804 }
7805 NetPlayers[playernum].file_xfer_cfile = cfp;
7806 NetPlayers[playernum].file_xfer_flags = NETFILE_RECEIVING;
7807 }
7808
7809 MULTI_ASSERT_NOMESSAGE(NetPlayers[playernum].file_xfer_cfile);
7810 // Write the data to the file
7811 int data_wrote = cf_WriteBytes(data + count, data_len, NetPlayers[playernum].file_xfer_cfile);
7812 if (data_wrote != data_len) {
7813 mprintf(0, "cf_WriteBytes() should have written %d bytes, but only wrote %d!\n", data_len, data_wrote);
7814 Int3();
7815 }
7816
7817 NetPlayers[playernum].file_xfer_pos += data_len;
7818 // See if this is the last data chunk
7819 if (NetPlayers[playernum].file_xfer_pos >= total_len) {
7820 // We got the whole thing baby!
7821 cfclose(NetPlayers[playernum].file_xfer_cfile);
7822 NetPlayers[playernum].file_xfer_cfile = NULL;
7823 NetPlayers[playernum].file_xfer_pos = 0;
7824 DoNextPlayerFile(playernum);
7825 mprintf(0, "Finished downloading file!\n");
7826 return; // Don't ack the last packet
7827 }
7828 // Ack the sender
7829 size = START_DATA(MP_FILE_ACK, outdata, &outcount);
7830 MultiAddUshort(Player_num, outdata, &outcount);
7831 MultiAddUint(NetPlayers[playernum].file_xfer_pos, outdata, &outcount);
7832 END_DATA(outcount, outdata, size);
7833 if (Netgame.local_role == LR_SERVER) {
7834 nw_SendReliable(NetPlayers[playernum].reliable_socket, outdata, outcount, true);
7835 } else {
7836 nw_SendReliable(NetPlayers[Player_num].reliable_socket, outdata, outcount, true);
7837 }
7838 } else {
7839 mprintf(0, "Received file transfer data from someone who we aren't expecting data from!\n");
7840 }
7841 }
7842
7843 void MultiDoFileAck(uint8_t *data) {
7844 // If we are transferring a file, and someone ACK's us, simply send them the next bit of data they are waiting for
7845 uint8_t playernum; // Who is acking us
7846 uint32_t len_recvd; // Total number of bytes received so far
7847 int count = 0;
7848
7849 SKIP_HEADER(data, &count);
7850 playernum = MultiGetUshort(data, &count);
7851 len_recvd = MultiGetUint(data, &count);
7852 // mprintf(0,"Got a ACK packet from %d\n",playernum);
7853 if (NetPlayers[playernum].file_xfer_flags == NETFILE_SENDING) {
7854 if (NetPlayers[playernum].file_xfer_pos == len_recvd) {
7855 SendDataChunk(playernum);
7856 } else {
7857 Int3(); // This shouldn't happen because the reliable network code should handle it
7858 }
7859 } else {
7860 mprintf(0, "Received an ACK from someone we weren't sending a file to!\n");
7861 }
7862 }
7863
7864 void SendDataChunk(int playernum) {
7865 int outcount = 0;
7866 static uint8_t outdata[MAX_PACKET_SIZE];
7867 static uint8_t readbuf[MAX_PACKET_SIZE];
7868 int size;
7869 int dataread;
7870 int done = 0;
7871 // mprintf(0,"Sending a data chunk to %d.\n",playernum);
7872 // Read the next chunk of the file and send it!
7873 if ((DATA_CHUNK_SIZE + NetPlayers[playernum].file_xfer_pos) >
7874 (uint32_t)NetPlayers[playernum].file_xfer_cfile->size) {
7875 dataread = NetPlayers[playernum].file_xfer_cfile->size - NetPlayers[playernum].file_xfer_pos;
7876 // This is the end of the file
7877 mprintf(0, "End of file detected!\n");
7878 done = 1;
7879 } else {
7880 dataread = DATA_CHUNK_SIZE;
7881 }
7882
7883 try {
7884 cf_ReadBytes(readbuf, dataread, NetPlayers[playernum].file_xfer_cfile);
7885 } catch (cfile_error *cfe) {
7886 int t = cfe->read_write; // this is is here to fix compile warning
7887 // Woops, can't read the file, better error out!
7888 MultiCancelFile(playernum, NetPlayers[playernum].file_xfer_id, NetPlayers[playernum].file_xfer_who);
7889 Int3();
7890 return;
7891 }
7892
7893 if (done) {
7894 cfclose(NetPlayers[playernum].file_xfer_cfile);
7895 NetPlayers[playernum].file_xfer_cfile = NULL;
7896 NetPlayers[playernum].file_xfer_pos = 0;
7897 NetPlayers[playernum].file_xfer_flags = NETFILE_NONE;
7898 }
7899 // Send them the next chunk
7900 size = START_DATA(MP_FILE_DATA, outdata, &outcount);
7901 MultiAddUint(NetPlayers[playernum].file_xfer_total_len, outdata, &outcount);
7902 MultiAddUint(NetPlayers[playernum].file_xfer_pos, outdata, &outcount);
7903 MultiAddUshort(NetPlayers[playernum].file_xfer_id, outdata, &outcount);
7904 if (Netgame.local_role == LR_SERVER)
7905 MultiAddUshort(NetPlayers[playernum].file_xfer_who, outdata, &outcount);
7906 else
7907 MultiAddUshort(Player_num, outdata, &outcount);
7908 // MultiAddUshort (NetPlayers[playernum].file_xfer_who,outdata,&outcount);
7909 MultiAddUshort(dataread, outdata, &outcount);
7910 memcpy(outdata + outcount, readbuf, dataread);
7911 outcount += dataread;
7912 END_DATA(outcount, outdata, size);
7913 if (Netgame.local_role == LR_SERVER) {
7914 nw_SendReliable(NetPlayers[playernum].reliable_socket, outdata, outcount, true);
7915 } else {
7916 nw_SendReliable(NetPlayers[Player_num].reliable_socket, outdata, outcount, true);
7917 }
7918 NetPlayers[playernum].file_xfer_pos += dataread;
7919 }
7920
7921 void MultiDoFileCancelled(uint8_t *data) {
7922 uint16_t playernum; // Who is telling us the file is cancelled
7923 uint16_t filewho; // Who's file is being cancelled
7924 int count = 0;
7925
7926 SKIP_HEADER(data, &count);
7927 playernum = MultiGetUshort(data, &count);
7928 filewho = MultiGetUshort(data, &count);
7929 mprintf(0, "Got a cancelled packet from %d for %d\n", playernum, filewho);
7930 if (NetPlayers[filewho].file_xfer_cfile) {
7931 char delfile[_MAX_PATH * 2];
7932 strcpy(delfile, NetPlayers[filewho].file_xfer_cfile->name);
7933 cfclose(NetPlayers[filewho].file_xfer_cfile);
7934 NetPlayers[filewho].file_xfer_cfile = NULL;
7935 ddio_DeleteFile(delfile);
7936 }
7937 NetPlayers[filewho].file_xfer_cfile = NULL;
7938 NetPlayers[filewho].file_xfer_pos = 0;
7939 DoNextPlayerFile(filewho);
7940 }
7941
7942 // ddio_splitpath
7943 void MultiSendClientCustomData(int slot, int whoto) {
7944 uint8_t data[MAX_GAME_DATA_SIZE];
7945 char csum_filename[(_MAX_PATH * 2) + 64];
7946 char path[_MAX_PATH];
7947 char ext[_MAX_PATH];
7948 char file[_MAX_PATH];
7949 int count = 0;
7950 int size_offset;
7951
7952 //@@mprintf(0,"Sending player %d's data to %d.\n",slot,whoto);
7953
7954 size_offset = START_DATA(MP_PLAYER_CUSTOM_DATA, data, &count);
7955 // Who we are talking about
7956 MultiAddShort(slot, data, &count);
7957
7958 // Send custom logo filename (all 0's if none)
7959 csum_filename[0] = '\0';
7960 if (NetPlayers[slot].ship_logo[0]) {
7961 if (slot == Player_num) {
7962 char szcrc[_MAX_PATH];
7963 ddio_SplitPath(NetPlayers[slot].ship_logo, path, file, ext);
7964 snprintf(szcrc, sizeof(szcrc), "_%.8x", cf_GetfileCRC(NetPlayers[slot].ship_logo));
7965 // See if the the CRC is already in the filename
7966 if (strnicmp(szcrc, file + (strlen(file) - 9), 9) == 0) {
7967 snprintf(csum_filename, sizeof(csum_filename), "%s%s", file, ext);
7968 } else {
7969 snprintf(csum_filename, sizeof(csum_filename), "%s_%.8x%s", file, cf_GetfileCRC(NetPlayers[slot].ship_logo),
7970 ext);
7971 }
7972 } else {
7973 strcpy(csum_filename, NetPlayers[slot].ship_logo);
7974 }
7975 }
7976 uint16_t logo_len = strlen(csum_filename) + 1;
7977 MultiAddUshort(logo_len, data, &count);
7978 memcpy(data + count, csum_filename, logo_len);
7979 count += logo_len;
7980
7981 for (int t = 0; t < 4; t++) {
7982 // Send custom voice taunts (all 0's if none)
7983 csum_filename[0] = '\0';
7984 char *filename;
7985
7986 switch (t) {
7987 case 0:
7988 filename = NetPlayers[slot].voice_taunt1;
7989 break;
7990 case 1:
7991 filename = NetPlayers[slot].voice_taunt2;
7992 break;
7993 case 2:
7994 filename = NetPlayers[slot].voice_taunt3;
7995 break;
7996 case 3:
7997 filename = NetPlayers[slot].voice_taunt4;
7998 break;
7999 }
8000
8001 if (filename[0]) {
8002 if (slot == Player_num) {
8003 char szcrc[_MAX_PATH];
8004 ddio_SplitPath(filename, path, file, ext);
8005 snprintf(szcrc, sizeof(szcrc), "_%.8x", cf_GetfileCRC(filename));
8006 // See if the the CRC is already in the filename
8007 if (strnicmp(szcrc, file + (strlen(file) - 9), 9) == 0) {
8008 snprintf(csum_filename, sizeof(csum_filename), "%s%s", file, ext);
8009 } else {
8010 snprintf(csum_filename, sizeof(csum_filename), "%s_%.8x%s", file, cf_GetfileCRC(filename), ext);
8011 }
8012 } else {
8013 strcpy(csum_filename, filename);
8014 }
8015 }
8016 uint16_t vt_len = strlen(csum_filename) + 1;
8017 MultiAddUshort(vt_len, data, &count);
8018 memcpy(data + count, csum_filename, vt_len);
8019 count += vt_len;
8020 }
8021
8022 END_DATA(count, data, size_offset);
8023
8024 if (Netgame.local_role == LR_SERVER) {
8025 if (whoto == -1) {
8026 // Send to all clients
8027 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_PLAYING);
8028 } else {
8029 nw_SendReliable(NetPlayers[whoto].reliable_socket, data, count, true);
8030 }
8031 } else {
8032 // Send to the server
8033 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count, true);
8034 }
8035 }
8036
8037 void MultiDoCustomPlayerData(uint8_t *data) {
8038 uint16_t playernum; // Who has data we are interested in
8039 int count = 0;
8040
8041 SKIP_HEADER(data, &count);
8042 playernum = MultiGetUshort(data, &count);
8043 if (playernum == Player_num)
8044 return;
8045 mprintf(0, "Got custom data in MultiDoCustomPlayerData()\n");
8046 NetPlayers[playernum].custom_file_seq = NETFILE_ID_SHIP_TEX; // First in the sequence of files we will request
8047 int16_t logo_len = MultiGetUshort(data, &count);
8048 memcpy(NetPlayers[playernum].ship_logo, data + count, logo_len);
8049 count += logo_len;
8050 mprintf(0, "%s uses custom ship logo %s\n", Players[playernum].callsign, NetPlayers[playernum].ship_logo);
8051
8052 for (int t = 0; t < 4; t++) {
8053 char *filename;
8054 int16_t vt_len;
8055
8056 switch (t) {
8057 case 0:
8058 filename = NetPlayers[playernum].voice_taunt1;
8059 break;
8060 case 1:
8061 filename = NetPlayers[playernum].voice_taunt2;
8062 break;
8063 case 2:
8064 filename = NetPlayers[playernum].voice_taunt3;
8065 break;
8066 case 3:
8067 filename = NetPlayers[playernum].voice_taunt4;
8068 break;
8069 }
8070
8071 vt_len = MultiGetUshort(data, &count);
8072 memcpy(filename, data + count, vt_len);
8073 count += vt_len;
8074 }
8075 }
8076
8077 char *GetFileNameFromPlayerAndID(int16_t playernum, int16_t id) {
8078 static char rval[_MAX_PATH * 2];
8079
8080 rval[0] = '\0';
8081
8082 if (playernum >= MAX_NET_PLAYERS) {
8083 mprintf(0, "Invalid playernum (%d) passed to GetFileNameFromPlayerAndID()\n", playernum);
8084 return rval;
8085 }
8086 if (id > NETFILE_ID_LAST_FILE) {
8087 mprintf(0, "Invalid file id (%d) passed to GetFileNameFromPlayerAndID()\n", id);
8088 return rval;
8089 }
8090 switch (id) {
8091
8092 case NETFILE_ID_NOFILE:
8093 break;
8094 case NETFILE_ID_SHIP_TEX:
8095 if (NetPlayers[playernum].ship_logo[0])
8096 ddio_MakePath(rval, Base_directory_write, "custom", "graphics", NetPlayers[playernum].ship_logo, NULL);
8097 break;
8098 case NETFILE_ID_VOICE_TAUNT1:
8099 if (NetPlayers[playernum].voice_taunt1[0])
8100 ddio_MakePath(rval, Base_directory_write, "custom", "sounds", NetPlayers[playernum].voice_taunt1, NULL);
8101 break;
8102 case NETFILE_ID_VOICE_TAUNT2:
8103 if (NetPlayers[playernum].voice_taunt2[0])
8104 ddio_MakePath(rval, Base_directory_write, "custom", "sounds", NetPlayers[playernum].voice_taunt2, NULL);
8105 break;
8106 case NETFILE_ID_VOICE_TAUNT3:
8107 if (NetPlayers[playernum].voice_taunt3[0])
8108 ddio_MakePath(rval, Base_directory_write, "custom", "sounds", NetPlayers[playernum].voice_taunt3, NULL);
8109 break;
8110 case NETFILE_ID_VOICE_TAUNT4:
8111 if (NetPlayers[playernum].voice_taunt4[0])
8112 ddio_MakePath(rval, Base_directory_write, "custom", "sounds", NetPlayers[playernum].voice_taunt4, NULL);
8113 break;
8114 default:
8115 mprintf(0, "Unknown id (%d) passed to GetFileNameFromPlayerAndID()\n", id);
8116 Int3();
8117 break;
8118 }
8119 if (*rval) {
8120 CFILE *cfp;
8121 cfp = cfopen(rval, "rb");
8122 if (!cfp) {
8123 mprintf(0, "Multiplayer file xfer File does not exist, not using file %d for player %d!\n", id, playernum);
8124 // rval[0] = '\0';
8125 } else if (32768 < cfilelength(cfp)) {
8126 mprintf(0, "Multiplayer file xfer File to long, not using file %d for player %d!\n", id, playernum);
8127 rval[0] = '\0';
8128 }
8129 if (cfp)
8130 cfclose(cfp);
8131 }
8132
8133 return rval;
8134 }
8135
8136 // Tells the clients to ghost or unghost an object
8137 void MultiSendGhostObject(object *obj, bool ghost) {
8138 MULTI_ASSERT_NOMESSAGE(obj);
8139
8140 int count = 0;
8141 uint16_t objnum;
8142 uint8_t data[MAX_GAME_DATA_SIZE];
8143 int size_offset;
8144
8145 size_offset = START_DATA(MP_GHOST_OBJECT, data, &count, 1);
8146
8147 objnum = obj - Objects;
8148
8149 MultiAddUshort(objnum, data, &count);
8150 MultiAddByte((ghost) ? 1 : 0, data, &count);
8151
8152 END_DATA(count, data, size_offset);
8153
8154 if (Netgame.local_role == LR_SERVER)
8155 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_OBJECTS, false);
8156 }
8157
8158 void MultiDoGhostObject(uint8_t *data) {
8159 int count = 0;
8160 SKIP_HEADER(data, &count);
8161
8162 uint16_t server_objnum, objnum;
8163 bool ghost;
8164
8165 server_objnum = MultiGetUshort(data, &count);
8166 ghost = (MultiGetByte(data, &count)) ? true : false;
8167
8168 objnum = Server_object_list[server_objnum];
8169
8170 if (objnum == 65535) {
8171 Int3(); // Get Jason, bad object number
8172 return;
8173 }
8174
8175 MULTI_ASSERT_NOMESSAGE(objnum != -1);
8176 MULTI_ASSERT_NOMESSAGE(Objects[objnum].type != OBJ_NONE);
8177
8178 if (ghost) {
8179 ObjGhostObject(objnum);
8180 } else {
8181 ObjUnGhostObject(objnum);
8182 }
8183 }
8184
8185 // Sends a ping request to a player
8186 void MultiSendPing(int slot) {
8187 int count = 0;
8188 uint8_t data[MAX_GAME_DATA_SIZE];
8189 int size_offset;
8190
8191 if (slot == Player_num)
8192 return;
8193 NetPlayers[slot].last_ping_time = timer_GetTime();
8194 size_offset = START_DATA(MP_PLAYER_PING, data, &count);
8195
8196 MultiAddByte(Player_num, data, &count);
8197 MultiAddFloat(NetPlayers[slot].last_ping_time, data, &count);
8198 END_DATA(count, data, size_offset);
8199 nw_Send(&NetPlayers[slot].addr, data, count, 0);
8200 }
8201
8202 void MultiDoPing(uint8_t *data, network_address *addr) {
8203 uint8_t outdata[MAX_GAME_DATA_SIZE];
8204 int outcount = 0;
8205 int count = 0;
8206 int size_offset;
8207
8208 SKIP_HEADER(data, &count);
8209 uint8_t slot = MultiGetByte(data, &count);
8210 float pingtime = MultiGetFloat(data, &count);
8211
8212 // Now send a response
8213 size_offset = START_DATA(MP_PLAYER_PONG, outdata, &outcount);
8214 MultiAddByte(Player_num, outdata, &outcount);
8215 MultiAddFloat(pingtime, outdata, &outcount);
8216 END_DATA(outcount, outdata, size_offset);
8217
8218 nw_Send(addr, outdata, outcount, 0);
8219 }
8220
8221 void MultiDoPong(uint8_t *data) {
8222 uint8_t outdata[MAX_GAME_DATA_SIZE];
8223 int outcount = 0;
8224 int count = 0;
8225 int size_offset;
8226
8227 SKIP_HEADER(data, &count);
8228 uint8_t slot = MultiGetByte(data, &count);
8229 float pingtime = MultiGetFloat(data, &count);
8230 NetPlayers[slot].ping_time = timer_GetTime() - pingtime;
8231
8232 // If we are the server and this is a client server game, send the lag info to other clients
8233 if ((Netgame.local_role == LR_SERVER) && (!(Netgame.flags & NF_PEER_PEER))) {
8234 size_offset = START_DATA(MP_PLAYER_LAG_INFO, outdata, &outcount);
8235 MultiAddByte(slot, outdata, &outcount);
8236 MultiAddFloat(NetPlayers[slot].ping_time, outdata, &outcount);
8237 END_DATA(outcount, outdata, size_offset);
8238 MultiSendToAllExcept(Player_num, outdata, outcount, 0);
8239 }
8240 }
8241
8242 void MultiDoLagInfo(uint8_t *data) {
8243 int count = 0;
8244 SKIP_HEADER(data, &count);
8245 uint8_t slot = MultiGetByte(data, &count);
8246 NetPlayers[slot].ping_time = MultiGetFloat(data, &count);
8247 }
8248
8249 // the server is telling us to play an audio taunt
8250 void MultiDoPlayTaunt(uint8_t *data) {
8251 int count = 0;
8252 SKIP_HEADER(data, &count);
8253 int pnum = MultiGetByte(data, &count);
8254 int index = MultiGetByte(data, &count);
8255 if (!Dedicated_server)
8256 taunt_PlayPlayerTaunt(pnum, index);
8257 }
8258
8259 // tell the clients to play an audio taunt
8260 void MultiSendPlayTaunt(int pnum, int index) {
8261 if (Netgame.local_role != LR_SERVER)
8262 return;
8263
8264 int count = 0;
8265 uint8_t data[MAX_GAME_DATA_SIZE];
8266 int size_offset;
8267 size_offset = START_DATA(MP_SERVER_PLAY_TAUNT, data, &count);
8268 MultiAddByte(pnum, data, &count);
8269 MultiAddByte(index, data, &count);
8270 END_DATA(count, data, size_offset);
8271 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_PLAYERS, false);
8272 MultiDoPlayTaunt(data);
8273 }
8274
8275 // process a request by a client to play an audio taunt
8276 void MultiDoRequestPlayTaunt(uint8_t *data) {
8277 int count = 0;
8278 SKIP_HEADER(data, &count);
8279
8280 int pnum = MultiGetByte(data, &count);
8281 int index = MultiGetByte(data, &count);
8282
8283 MultiSendPlayTaunt(pnum, index);
8284 }
8285
8286 // Client is asking the server to play an audio taunt
8287 void MultiSendRequestPlayTaunt(int index) {
8288
8289 if (!(Game_mode & GM_MULTI))
8290 return;
8291
8292 if (index < 0 || index > 3)
8293 return;
8294
8295 if (!taunt_AreEnabled())
8296 return;
8297
8298 // make sure an audio file exists there
8299 char audio_file[_MAX_PATH];
8300
8301 switch (index) {
8302 case 0:
8303 ddio_MakePath(audio_file, LocalCustomSoundsDir, NetPlayers[Player_num].voice_taunt1, NULL);
8304 break;
8305 case 1:
8306 ddio_MakePath(audio_file, LocalCustomSoundsDir, NetPlayers[Player_num].voice_taunt2, NULL);
8307 break;
8308 case 2:
8309 ddio_MakePath(audio_file, LocalCustomSoundsDir, NetPlayers[Player_num].voice_taunt3, NULL);
8310 break;
8311 case 3:
8312 ddio_MakePath(audio_file, LocalCustomSoundsDir, NetPlayers[Player_num].voice_taunt4, NULL);
8313 break;
8314 }
8315
8316 if (!cfexist(audio_file)) {
8317 mprintf(0, "Ignoring request to play audio taunt...it does not exist\n");
8318 return;
8319 }
8320
8321 float t = Gametime;
8322 if ((t - Time_last_taunt_request) < taunt_DelayTime()) {
8323 // too soon since last request
8324 return;
8325 }
8326 Time_last_taunt_request = t;
8327
8328 int count = 0;
8329 uint8_t data[MAX_GAME_DATA_SIZE];
8330 int size_offset = START_DATA(MP_CLIENT_PLAY_TAUNT, data, &count);
8331
8332 MultiAddByte(Player_num, data, &count);
8333 MultiAddByte(index, data, &count);
8334
8335 END_DATA(count, data, size_offset);
8336
8337 if (Netgame.local_role == LR_SERVER) {
8338 MultiDoRequestPlayTaunt(data);
8339 } else {
8340 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count);
8341 }
8342 }
8343
8344 // the server is telling us that about a player's message-type state (is [not] typing a message)
8345 void MultiDoTypeIcon(uint8_t *data) {
8346 int count = 0;
8347 SKIP_HEADER(data, &count);
8348 int pnum = MultiGetByte(data, &count);
8349 bool typing = (MultiGetByte(data, &count)) ? true : false;
8350
8351 ASSERT(pnum >= 0 && pnum < MAX_PLAYERS);
8352
8353 uint32_t bit = 0x01;
8354 bit = bit << pnum;
8355
8356 if (typing) {
8357 mprintf(0, "%s is typing\n", Players[pnum].callsign);
8358 Players_typing |= bit;
8359 } else {
8360 mprintf(0, "%s is done typing\n", Players[pnum].callsign);
8361 Players_typing &= ~bit;
8362 }
8363 }
8364
8365 // tell the clients that a player is [not] typing a message
8366 void MultiSendTypeIcon(int pnum, bool typing_message) {
8367 int count = 0;
8368 uint8_t data[MAX_GAME_DATA_SIZE];
8369 int size_offset;
8370 size_offset = START_DATA(MP_SEND_TYPE_ICON, data, &count);
8371 MultiAddByte(pnum, data, &count);
8372 MultiAddByte((typing_message) ? 1 : 0, data, &count);
8373 END_DATA(count, data, size_offset);
8374 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_PLAYERS, false);
8375 MultiDoTypeIcon(data);
8376 }
8377
8378 // process a request by a client that he is [not] typing a message
8379 void MultiDoRequestTypeIcon(uint8_t *data) {
8380 int count = 0;
8381 SKIP_HEADER(data, &count);
8382
8383 int pnum = MultiGetByte(data, &count);
8384 bool typing = (MultiGetByte(data, &count)) ? true : false;
8385
8386 MultiSendTypeIcon(pnum, typing);
8387 }
8388
8389 // Client is telling the server that he is [not] typing a hud message
8390 void MultiSendRequestTypeIcon(bool typing_message) {
8391 uint32_t bit = (0x01 << Player_num);
8392
8393 if (typing_message && (bit & Players_typing))
8394 return; // already typing no need to request
8395
8396 int count = 0;
8397 uint8_t data[MAX_GAME_DATA_SIZE];
8398 int size_offset = START_DATA(MP_REQUEST_TYPE_ICON, data, &count);
8399
8400 MultiAddByte(Player_num, data, &count);
8401 MultiAddByte((typing_message) ? 1 : 0, data, &count);
8402
8403 END_DATA(count, data, size_offset);
8404
8405 if (Netgame.local_role == LR_SERVER) {
8406 MultiDoRequestTypeIcon(data);
8407 } else {
8408 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count, false);
8409 }
8410 }
8411
8412 void MultiSendAiWeaponFlags(object *obj, int flags, int wb_index) {
8413 int count = 0;
8414 uint8_t data[MAX_GAME_DATA_SIZE];
8415 int size_offset;
8416 size_offset = START_DATA(MP_AIWEAP_FLAGS, data, &count);
8417 MultiAddUshort(OBJNUM(obj), data, &count);
8418 MultiAddInt(flags, data, &count);
8419 MultiAddByte(wb_index, data, &count);
8420 END_DATA(count, data, size_offset);
8421 MultiSendToAllExcept(Player_num, data, count, NETSEQ_OBJECTS);
8422 }
8423
8424 void MultiDoAiWeaponFlags(uint8_t *data) {
8425 int count = 0;
8426 SKIP_HEADER(data, &count);
8427
8428 int flags;
8429 int wb_index;
8430 int16_t obj_num = Server_object_list[MultiGetUshort(data, &count)];
8431 flags = MultiGetInt(data, &count);
8432 wb_index = MultiGetByte(data, &count);
8433 if (obj_num == 65535) {
8434 mprintf(0, "Client/Server object lists don't match! (Server num %d)\n", obj_num);
8435 Int3();
8436 return;
8437 }
8438
8439 ASSERT(Objects[obj_num].ai_info);
8440 ASSERT(Objects[obj_num].type != OBJ_NONE);
8441
8442 Objects[obj_num].ai_info->last_special_wb_firing = wb_index;
8443 Objects[obj_num].weapon_fire_flags = flags;
8444 if (Demo_flags == DF_RECORDING) {
8445 DemoWriteObjWeapFireFlagChanged(obj_num);
8446 }
8447 }
8448
8449 void MultiSendAttach(object *parent, char parent_ap, object *child, char child_ap, bool f_aligned) {
8450 int count = 0;
8451 uint8_t data[MAX_GAME_DATA_SIZE];
8452 int size_offset;
8453 size_offset = START_DATA(MP_ATTACH_OBJ, data, &count);
8454 MultiAddUshort(OBJNUM(parent), data, &count);
8455 MultiAddByte(parent_ap, data, &count);
8456 MultiAddUshort(OBJNUM(child), data, &count);
8457 MultiAddByte(child_ap, data, &count);
8458 MultiAddByte(f_aligned ? 1 : 0, data, &count);
8459 END_DATA(count, data, size_offset);
8460 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_WORLD, false);
8461 }
8462
8463 void MultiDoAttach(uint8_t *data) {
8464
8465 object *parent;
8466 char parent_ap;
8467 object *child;
8468 char child_ap;
8469 bool f_aligned;
8470
8471 int count = 0;
8472 SKIP_HEADER(data, &count);
8473
8474 uint16_t parent_num = Server_object_list[MultiGetUshort(data, &count)];
8475 parent_ap = MultiGetByte(data, &count);
8476 parent = &Objects[parent_num];
8477 uint16_t child_num = Server_object_list[MultiGetUshort(data, &count)];
8478 child_ap = MultiGetByte(data, &count);
8479 child = &Objects[child_num];
8480 f_aligned = MultiGetByte(data, &count) ? true : false;
8481
8482 if (parent_num == 65535) {
8483 mprintf(0, "Client/Server object lists don't match! (Server num %d)\n", parent_num);
8484 Int3();
8485 return;
8486 }
8487 if (child_num == 65535) {
8488 mprintf(0, "Client/Server object lists don't match! (Server num %d)\n", child_num);
8489 Int3();
8490 return;
8491 }
8492
8493 ASSERT(child >= Objects && parent >= Objects);
8494 ASSERT(child->type != OBJ_NONE && parent->type != OBJ_NONE);
8495
8496 AttachObject(parent, parent_ap, child, child_ap, f_aligned);
8497 }
8498
8499 void MultiSendAttachRad(object *parent, char parent_ap, object *child, float rad) {
8500 int count = 0;
8501 uint8_t data[MAX_GAME_DATA_SIZE];
8502 int size_offset;
8503 size_offset = START_DATA(MP_ATTACH_RAD_OBJ, data, &count);
8504 MultiAddUshort(OBJNUM(parent), data, &count);
8505 MultiAddByte(parent_ap, data, &count);
8506 MultiAddUshort(OBJNUM(child), data, &count);
8507 MultiAddFloat(rad, data, &count);
8508 END_DATA(count, data, size_offset);
8509 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_WORLD, false);
8510 }
8511
8512 void MultiDoAttachRad(uint8_t *data) {
8513
8514 object *parent;
8515 char parent_ap;
8516 object *child;
8517 float rad;
8518
8519 int count = 0;
8520 SKIP_HEADER(data, &count);
8521
8522 uint16_t parent_num = Server_object_list[MultiGetUshort(data, &count)];
8523 parent_ap = MultiGetByte(data, &count);
8524 parent = &Objects[parent_num];
8525 uint16_t child_num = Server_object_list[MultiGetUshort(data, &count)];
8526 rad = MultiGetFloat(data, &count);
8527 child = &Objects[child_num];
8528
8529 if (parent_num == 65535) {
8530 mprintf(0, "Client/Server object lists don't match! (Server num %d)\n", parent_num);
8531 Int3();
8532 return;
8533 }
8534 if (child_num == 65535) {
8535 mprintf(0, "Client/Server object lists don't match! (Server num %d)\n", child_num);
8536 Int3();
8537 return;
8538 }
8539
8540 ASSERT(child >= Objects && parent >= Objects);
8541 ASSERT(child->type != OBJ_NONE && parent->type != OBJ_NONE);
8542
8543 AttachObject(parent, parent_ap, child, rad);
8544 }
8545
8546 void MultiSendUnattach(object *child) {
8547 int count = 0;
8548 uint8_t data[MAX_GAME_DATA_SIZE];
8549 int size_offset;
8550
8551 ASSERT(Objects[OBJNUM(child)].flags & OF_CLIENT_KNOWS);
8552
8553 size_offset = START_DATA(MP_UNATTACH_OBJ, data, &count);
8554 MultiAddUshort(OBJNUM(child), data, &count);
8555 END_DATA(count, data, size_offset);
8556 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_OBJECTS, false);
8557 }
8558
8559 void MultiDoUnattach(uint8_t *data) {
8560 object *child;
8561
8562 int count = 0;
8563 SKIP_HEADER(data, &count);
8564 int server_objnum = MultiGetUshort(data, &count);
8565 ASSERT(server_objnum >= 0 && server_objnum < MAX_OBJECTS);
8566 uint16_t child_num = Server_object_list[server_objnum];
8567 child = &Objects[child_num];
8568 if (child_num == 65535) {
8569 mprintf(0, "Client/Server object lists don't match! (Server num %d)\n", child_num);
8570 Int3();
8571 return;
8572 }
8573
8574 UnattachFromParent(child);
8575 }
8576
8577 void MultiSendThiefSteal(int player, int item) {
8578 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
8579 MULTI_ASSERT_NOMESSAGE(player >= 0 && player < MAX_PLAYERS);
8580
8581 int count = 0;
8582 uint8_t data[MAX_GAME_DATA_SIZE];
8583 int size_offset;
8584 size_offset = START_DATA(MP_THIEF_STEAL, data, &count);
8585 MultiAddInt(item, data, &count);
8586 MultiAddInt(player, data, &count);
8587 END_DATA(count, data, size_offset);
8588
8589 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_OBJECTS, false);
8590 }
8591
8592 void MultiDoThiefSteal(uint8_t *data) {
8593 int count = 0;
8594 SKIP_HEADER(data, &count);
8595 int item = MultiGetInt(data, &count);
8596 int player = MultiGetInt(data, &count);
8597 ThiefStealItem(Objects[Players[player].objnum].handle, item);
8598 }
8599
8600 // Sets whether or not we want the logos to be displayed on ships
8601 void MultiSetLogoState(bool state) {
8602 Multi_logo_state = state;
8603 mprintf(0, "Setting multi_logo_state to %d\n", state);
8604 }
8605
8606 void MultiDoPermissionToFire(uint8_t *data) {
8607 int count = 0;
8608 SKIP_HEADER(data, &count);
8609
8610 int pnum = MultiGetByte(data, &count);
8611 Player_fire_packet[pnum].wb_index = MultiGetByte(data, &count);
8612 Player_fire_packet[pnum].fire_mask = MultiGetByte(data, &count);
8613 Player_fire_packet[pnum].damage_scalar = MultiGetByte(data, &count);
8614
8615 // Get positional info
8616 vector pos;
8617 matrix orient;
8618
8619 // memcpy (&pos,&data[count],sizeof(vector));
8620 // count+=sizeof(vector);
8621 pos = MultiGetVector(data, &count);
8622
8623 // Get orientation
8624 uint16_t p = MultiGetShort(data, &count);
8625 uint16_t h = MultiGetShort(data, &count);
8626 uint16_t b = MultiGetShort(data, &count);
8627
8628 vm_AnglesToMatrix(&orient, p, h, b);
8629
8630 // Get room and terrain flag
8631 uint16_t short_roomnum = MultiGetUshort(data, &count);
8632 uint8_t outside = MultiGetByte(data, &count);
8633 int roomnum;
8634
8635 if (outside)
8636 roomnum = MAKE_ROOMNUM(short_roomnum);
8637 else
8638 roomnum = short_roomnum;
8639
8640 // Strip out quad data
8641 int wb_index = Player_fire_packet[pnum].wb_index;
8642 int quaded = wb_index & MPFF_QUADED;
8643 wb_index &= ~MPFF_QUADED;
8644
8645 // Fire!
8646 float scalar = (float)Player_fire_packet[pnum].damage_scalar / 64.0;
8647 int ship_index = Players[pnum].ship_index;
8648 object *obj = &Objects[Players[pnum].objnum];
8649
8650 int save_mask = obj->dynamic_wb[wb_index].cur_firing_mask;
8651 int save_flags = obj->dynamic_wb[wb_index].flags;
8652 int save_roomnum = obj->roomnum;
8653 matrix save_orient = obj->orient;
8654 vector save_pos = obj->pos;
8655
8656 obj->dynamic_wb[wb_index].cur_firing_mask = Player_fire_packet[pnum].fire_mask;
8657
8658 if (quaded)
8659 obj->dynamic_wb[wb_index].flags |= DWBF_QUAD;
8660 else
8661 obj->dynamic_wb[wb_index].flags &= ~DWBF_QUAD;
8662
8663 // Move the player into the temp position just for this firing
8664 ObjSetPos(obj, &pos, roomnum, &orient, false);
8665
8666 WBFireBattery(obj, &Ships[ship_index].static_wb[wb_index], 0, wb_index, scalar);
8667
8668 obj->dynamic_wb[wb_index].cur_firing_mask = save_mask;
8669 obj->dynamic_wb[wb_index].flags = save_flags;
8670
8671 ObjSetPos(obj, &save_pos, save_roomnum, &save_orient, false);
8672
8673 // Play cutoff sound if there is one
8674 int cutoff_sound = Ships[ship_index].firing_release_sound[wb_index];
8675 if (cutoff_sound != -1)
8676 Sound_system.Play3dSound(cutoff_sound, &Objects[Players[pnum].objnum]);
8677 }
8678
8679 void MultiSendPermissionToFire(int pnum) {
8680 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
8681
8682 object *obj = &Objects[Players[pnum].objnum];
8683
8684 int count = 0;
8685 uint8_t data[MAX_GAME_DATA_SIZE];
8686 int size_offset;
8687 size_offset = START_DATA(MP_PERMISSION_TO_FIRE, data, &count);
8688 MultiAddByte(pnum, data, &count);
8689 MultiAddUbyte(Player_fire_packet[pnum].wb_index, data, &count);
8690 MultiAddUbyte(Player_fire_packet[pnum].fire_mask, data, &count);
8691 MultiAddUbyte(Player_fire_packet[pnum].damage_scalar, data, &count);
8692
8693 // Do position
8694 // memcpy (&data[count],&obj->pos,sizeof(vector));
8695 // count+=sizeof(vector);
8696 MultiAddVector(obj->pos, data, &count);
8697
8698 // Do orientation
8699 angvec angs;
8700 vm_ExtractAnglesFromMatrix(&angs, &obj->orient);
8701
8702 MultiAddShort(angs.p, data, &count);
8703 MultiAddShort(angs.h, data, &count);
8704 MultiAddShort(angs.b, data, &count);
8705
8706 // Do roomnumber and terrain flag
8707 MultiAddShort(CELLNUM(obj->roomnum), data, &count);
8708
8709 // Fill flags
8710 if (OBJECT_OUTSIDE(obj))
8711 MultiAddByte(1, data, &count);
8712 else
8713 MultiAddByte(0, data, &count);
8714
8715 END_DATA(count, data, size_offset);
8716
8717 #ifdef RELIABLE_SECONDARIES
8718 if ((Player_fire_packet[pnum].wb_index >= SECONDARY_INDEX) && (Player_fire_packet[pnum].wb_index != FLARE_INDEX)) {
8719 // send reliably
8720 // mprintf(0,"PCS: SENDING RELIABLE FIRE FOR %d\n",pnum);
8721 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_PLAYING, true);
8722 } else
8723 #endif
8724 {
8725 MultiSendToAllExcept(Player_num, data, count, NETSEQ_PLAYING);
8726 }
8727 MultiDoPermissionToFire(data);
8728 }
8729
8730 // A client is asking for permission to fire
8731 void MultiDoRequestToFire(uint8_t *data) {
8732 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
8733
8734 int count = 0;
8735 SKIP_HEADER(data, &count);
8736
8737 int pnum = MultiGetByte(data, &count);
8738 Player_fire_packet[pnum].wb_index = MultiGetUbyte(data, &count);
8739 Player_fire_packet[pnum].fire_mask = MultiGetUbyte(data, &count);
8740 Player_fire_packet[pnum].damage_scalar = MultiGetUbyte(data, &count);
8741
8742 // Check to see if this player is firing a weapon he doesn't have
8743 player *playp = &Players[pnum];
8744 if ((playp->weapon_flags & (1 << Player_fire_packet[pnum].wb_index))) {
8745 if (MultiEnoughAmmoToFire(pnum, Player_fire_packet[pnum].wb_index)) {
8746 MultiSendPermissionToFire(pnum);
8747 // Take off ammo
8748 MultiSubtractAmmoToFire(pnum, Player_fire_packet[pnum].wb_index);
8749 }
8750 }
8751 }
8752
8753 // We're asking the servers permission to fire
8754 void MultiSendRequestToFire(int wb_index, int fire_mask, float scalar) {
8755 // Send quaded info if needed
8756 uint8_t index_to_send = wb_index;
8757
8758 if (Objects[Players[Player_num].objnum].dynamic_wb[wb_index].flags & DWBF_QUAD)
8759 index_to_send |= MPFF_QUADED;
8760
8761 uint8_t damage_scalar = (scalar * 64.0);
8762
8763 int count = 0;
8764 uint8_t data[MAX_GAME_DATA_SIZE];
8765 int size_offset;
8766 size_offset = START_DATA(MP_REQUEST_TO_FIRE, data, &count);
8767
8768 MultiAddByte(Player_num, data, &count);
8769 MultiAddUbyte(index_to_send, data, &count);
8770 MultiAddUbyte(fire_mask, data, &count);
8771 MultiAddUbyte(damage_scalar, data, &count);
8772
8773 END_DATA(count, data, size_offset);
8774
8775 if (Netgame.local_role == LR_SERVER) {
8776 MultiDoRequestToFire(data);
8777 } else {
8778 #ifdef RELIABLE_SECONDARIES
8779 // should we send reliably? (secondaries)
8780 if ((wb_index >= SECONDARY_INDEX) && (wb_index != FLARE_INDEX)) {
8781 // send reliably
8782 // mprintf(0,"PCS: Sending fire request reliably\n");
8783 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count, true);
8784 } else
8785 #endif
8786 {
8787 nw_Send(&Netgame.server_address, data, count, 0);
8788 }
8789 }
8790 }
8791
8792 // Server is processing a request for a marker
8793 void MultiDoRequestMarker(uint8_t *data) {
8794 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
8795
8796 int count = 0;
8797 char message[100];
8798 SKIP_HEADER(data, &count);
8799
8800 int pnum = MultiGetByte(data, &count);
8801 uint8_t len = MultiGetByte(data, &count);
8802 memcpy(message, &data[count], len);
8803 count += len;
8804
8805 int limit = 2;
8806 int cur_marker_num;
8807
8808 object *pobj = &Objects[Players[pnum].objnum];
8809
8810 if (Players[pnum].num_markers >= limit) {
8811 // Delete the oldest marker
8812 int found = -1;
8813 float low_time = 999999999.0f;
8814 for (int i = 0; i <= Highest_object_index; i++) {
8815 if (Objects[i].type == OBJ_MARKER && Objects[i].parent_handle == pobj->handle &&
8816 Objects[i].creation_time < low_time) {
8817 found = i;
8818 low_time = Objects[i].creation_time;
8819 }
8820 }
8821
8822 ASSERT(found != -1);
8823
8824 SetObjectDeadFlag(&Objects[found], true, false);
8825
8826 cur_marker_num = Objects[found].id;
8827 } else {
8828 cur_marker_num = pnum * 2 + Players[pnum].num_markers;
8829 Players[pnum].num_markers++;
8830 }
8831
8832 int objnum = ObjCreate(OBJ_MARKER, cur_marker_num, pobj->roomnum, &pobj->pos, &pobj->orient, pobj->handle);
8833
8834 if (objnum >= 0) {
8835 strcpy(MarkerMessages[cur_marker_num], message);
8836 MultiSendObject(&Objects[objnum], 0);
8837 }
8838 }
8839
8840 // Client is asking for a marker
8841 void MultiSendRequestForMarker(char *message) {
8842 int count = 0;
8843 uint8_t data[MAX_GAME_DATA_SIZE];
8844 int size_offset;
8845 size_offset = START_DATA(MP_REQUEST_MARKER, data, &count);
8846
8847 MultiAddByte(Player_num, data, &count);
8848
8849 uint8_t len = strlen(message) + 1;
8850 MultiAddByte(len, data, &count);
8851 memcpy(data + count, message, len);
8852 count += len;
8853
8854 END_DATA(count, data, size_offset);
8855
8856 if (Netgame.local_role == LR_SERVER)
8857 MultiDoRequestMarker(data);
8858 else
8859 nw_SendReliable(NetPlayers[Player_num].reliable_socket, data, count, false);
8860 }
8861
8862 // The server is telling me to adjust my position
8863 void MultiDoAdjustPosition(uint8_t *data) {
8864 int count = 0;
8865 SKIP_HEADER(data, &count);
8866
8867 float timestamp = MultiGetFloat(data, &count);
8868
8869 vector newpos, newvel;
8870
8871 // memcpy (&newpos,&data[count],sizeof(vector));
8872 // count+=sizeof(vector);
8873 newpos = MultiGetVector(data, &count);
8874 // memcpy (&newvel,&data[count],sizeof(vector));
8875 // count+=sizeof(vector);
8876 newvel = MultiGetVector(data, &count);
8877
8878 int roomnum = MultiGetInt(data, &count);
8879
8880 object *obj = &Objects[Players[Player_num].objnum];
8881
8882 ObjSetPos(obj, &newpos, roomnum, &obj->orient, true);
8883 obj->mtype.phys_info.velocity = newvel;
8884
8885 float save_frametime = Frametime;
8886 int start_move = -1, end_move = -1;
8887
8888 // Now go through and adjust our position based on our saved moves
8889 for (int i = 0; i < MAX_SAVED_MOVES; i++) {
8890 int next = i + 1;
8891 int prev = i - 1;
8892
8893 if (next == MAX_SAVED_MOVES)
8894 next = 0;
8895 if (prev == -1)
8896 prev = MAX_SAVED_MOVES - 1;
8897
8898 if (start_move == -1 && SavedMoves[prev].timestamp < timestamp && SavedMoves[i].timestamp >= timestamp)
8899 start_move = i;
8900 if (end_move == -1 && SavedMoves[i].timestamp >= timestamp && SavedMoves[next].timestamp < timestamp)
8901 end_move = i;
8902 }
8903
8904 ASSERT(start_move != -1); // HUH? We don't have a copy of this move in our list
8905 ASSERT(end_move != -1);
8906
8907 int cur_move = start_move;
8908 int done = 0;
8909
8910 vector save_thrust, save_rotthrust;
8911 save_thrust = obj->mtype.phys_info.thrust;
8912 save_rotthrust = obj->mtype.phys_info.rotthrust;
8913
8914 while (!done) {
8915 int next = cur_move + 1;
8916 int next_end = end_move + 1;
8917
8918 if (next == MAX_SAVED_MOVES)
8919 next = 0;
8920
8921 if (next_end == MAX_SAVED_MOVES)
8922 next_end = 0;
8923
8924 float delta;
8925
8926 if (next == next_end)
8927 delta = 0.1f;
8928 else
8929 delta = SavedMoves[next].timestamp - SavedMoves[cur_move].timestamp;
8930
8931 ASSERT(delta >= 0);
8932
8933 Frametime = delta;
8934 obj->mtype.phys_info.thrust = SavedMoves[cur_move].thrust;
8935 obj->mtype.phys_info.rotthrust = SavedMoves[cur_move].rotthrust;
8936
8937 do_physics_sim(obj);
8938
8939 if (cur_move == end_move)
8940 done = 1;
8941 cur_move = next;
8942 }
8943
8944 obj->mtype.phys_info.rotthrust = save_rotthrust;
8945 obj->mtype.phys_info.thrust = save_thrust;
8946 Frametime = save_frametime;
8947 }
8948
8949 // Server is telling the client to update his position
8950 void MultiSendAdjustPosition(int slot, float timestamp) {
8951 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
8952
8953 int size_offset;
8954 int count = 0;
8955 uint8_t data[MAX_GAME_DATA_SIZE];
8956
8957 object *obj = &Objects[Players[slot].objnum];
8958
8959 size_offset = START_DATA(MP_ADJUST_POSITION, data, &count);
8960 MultiAddFloat(timestamp, data, &count);
8961
8962 MultiAddFloat(obj->pos.x, data, &count);
8963 MultiAddFloat(obj->pos.y, data, &count);
8964 MultiAddFloat(obj->pos.z, data, &count);
8965
8966 MultiAddFloat(obj->mtype.phys_info.velocity.x, data, &count);
8967 MultiAddFloat(obj->mtype.phys_info.velocity.y, data, &count);
8968 MultiAddFloat(obj->mtype.phys_info.velocity.z, data, &count);
8969
8970 MultiAddInt(obj->roomnum, data, &count);
8971
8972 END_DATA(count, data, size_offset);
8973
8974 nw_Send(&NetPlayers[slot].addr, data, count, 0);
8975 }
8976
8977 float Last_update_time[MAX_PLAYERS];
8978 // Client is asking permission to move
8979 void MultiDoRequestToMove(uint8_t *data) {
8980 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
8981
8982 int count = 0;
8983 SKIP_HEADER(data, &count);
8984
8985 vector thrust, rotthrust, pos;
8986 matrix orient;
8987
8988 int slot = MultiGetByte(data, &count);
8989 object *obj = &Objects[Players[slot].objnum];
8990
8991 float timestamp = MultiGetFloat(data, &count);
8992
8993 if (timestamp < NetPlayers[slot].packet_time)
8994 return; // Got out of order packet
8995
8996 if (Players[slot].flags & (PLAYER_FLAGS_DEAD | PLAYER_FLAGS_DYING))
8997 return;
8998
8999 // Get pos
9000 // memcpy (&pos,&data[count],sizeof(vector));
9001 // count+=sizeof(vector);
9002 pos = MultiGetVector(data, &count);
9003
9004 // Get thrust
9005 // memcpy (&thrust,&data[count],sizeof(vector));
9006 // count+=sizeof(vector);
9007 thrust = MultiGetVector(data, &count);
9008
9009 // Get rotational thrust
9010 // memcpy (&rotthrust,&data[count],sizeof(vector));
9011 // count+=sizeof(vector);
9012 rotthrust = MultiGetVector(data, &count);
9013
9014 // Get orientation
9015 uint16_t p = MultiGetShort(data, &count);
9016 uint16_t h = MultiGetShort(data, &count);
9017 uint16_t b = MultiGetShort(data, &count);
9018
9019 vm_AnglesToMatrix(&orient, p, h, b);
9020
9021 float delta_time = Gametime - NetPlayers[slot].packet_time;
9022 NetPlayers[slot].packet_time = Gametime;
9023
9024 obj->mtype.phys_info.thrust = thrust;
9025 obj->mtype.phys_info.rotthrust = rotthrust;
9026
9027 // Perform autonomous movement
9028 float save_frametime = Frametime;
9029
9030 obj->movement_type = MT_PHYSICS;
9031 obj->mtype.phys_info.flags |= PF_USES_THRUST;
9032 obj->mtype.phys_info.flags &= ~PF_FIXED_VELOCITY;
9033
9034 obj->mtype.phys_info.thrust = thrust;
9035 obj->mtype.phys_info.rotthrust = rotthrust;
9036 Frametime = delta_time;
9037
9038 do_physics_sim(obj);
9039
9040 obj->mtype.phys_info.thrust = Zero_vector;
9041 obj->mtype.phys_info.rotthrust = Zero_vector;
9042 obj->orient = orient;
9043
9044 bool client_error = 0;
9045 if (vm_VectorDistance(&pos, &obj->pos) > 5)
9046 client_error = true;
9047
9048 if (Gametime - Last_update_time[slot] > .15)
9049 client_error = true;
9050
9051 // If there is too much client error then adjust
9052 if (client_error) {
9053 mprintf(0, "Correcting, deltatime=%f dist=%f\n", delta_time, vm_VectorDistance(&pos, &obj->pos));
9054 MultiSendAdjustPosition(slot, timestamp);
9055 Last_update_time[slot] = Gametime;
9056 }
9057
9058 Frametime = save_frametime;
9059 }
9060
9061 // Sets up a packet so that we can request to move from server
9062 int MultiStuffRequestToMove(uint8_t *data) {
9063 int size_offset;
9064 int count = 0;
9065
9066 object *obj = &Objects[Players[Player_num].objnum];
9067
9068 size_offset = START_DATA(MP_REQUEST_TO_MOVE, data, &count);
9069 MultiAddByte(Player_num, data, &count);
9070
9071 // Add timestamp
9072 MultiAddFloat(Gametime, data, &count);
9073
9074 MultiAddFloat(obj->pos.x, data, &count);
9075 MultiAddFloat(obj->pos.y, data, &count);
9076 MultiAddFloat(obj->pos.z, data, &count);
9077
9078 // Do acceleration
9079 MultiAddFloat(obj->mtype.phys_info.thrust.x, data, &count);
9080 MultiAddFloat(obj->mtype.phys_info.thrust.y, data, &count);
9081 MultiAddFloat(obj->mtype.phys_info.thrust.z, data, &count);
9082
9083 // Do rotational acceleration
9084 MultiAddFloat(obj->mtype.phys_info.rotthrust.x, data, &count);
9085 MultiAddFloat(obj->mtype.phys_info.rotthrust.y, data, &count);
9086 MultiAddFloat(obj->mtype.phys_info.rotthrust.z, data, &count);
9087
9088 // Do orientation
9089 angvec angs;
9090 vm_ExtractAnglesFromMatrix(&angs, &obj->orient);
9091
9092 MultiAddShort(angs.p, data, &count);
9093 MultiAddShort(angs.h, data, &count);
9094 MultiAddShort(angs.b, data, &count);
9095
9096 END_DATA(count, data, size_offset);
9097
9098 return count;
9099 }
9100
9101 // Server is giving us a list of objects that aren't visible
9102 void MultiDoGenericNonVis(uint8_t *data) {
9103 int count = 0;
9104 SKIP_HEADER(data, &count);
9105
9106 int num = MultiGetShort(data, &count);
9107 for (int i = 0; i < num; i++) {
9108 uint16_t objnum = MultiGetUshort(data, &count);
9109
9110 objnum = Server_object_list[objnum];
9111 if (objnum == 65535 || !(Objects[objnum].flags & OF_SERVER_OBJECT)) {
9112 Int3(); // Get Jason, invalid object received!
9113 continue;
9114 }
9115
9116 ASSERT(IS_GENERIC(Objects[objnum].type));
9117
9118 Objects[objnum].render_type = RT_NONE;
9119 Objects[objnum].mtype.phys_info.flags |= PF_NO_COLLIDE;
9120 }
9121 }
9122
9123 // Tell clients to break some glass
9124 void MultiSendBreakGlass(room *rp, int facenum) {
9125 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
9126
9127 int count = 0;
9128 uint8_t data[MAX_GAME_DATA_SIZE];
9129 int size_offset;
9130 size_offset = START_DATA(MP_BREAK_GLASS, data, &count);
9131
9132 MultiAddUshort(rp - Rooms, data, &count);
9133 MultiAddUshort(facenum, data, &count);
9134
9135 END_DATA(count, data, size_offset);
9136
9137 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_PLAYING, false);
9138 }
9139
9140 // Server is telling us to break some glass
9141 void MultiDoBreakGlass(uint8_t *data) {
9142 int count = 0;
9143 SKIP_HEADER(data, &count);
9144
9145 int roomnum = MultiGetUshort(data, &count);
9146 int facenum = MultiGetUshort(data, &count);
9147
9148 BreakGlassFace(&Rooms[roomnum], facenum);
9149 }
9150
9151 // Server says a player has changed rank!
9152 void MultiDoChangeRank(uint8_t *data) {
9153 int count = 0;
9154 char str[255];
9155 SKIP_HEADER(data, &count);
9156
9157 int pnum = MultiGetByte(data, &count);
9158 MultiGetString(str, data, &count);
9159 int goodnews = MultiGetByte(data, &count);
9160 float newrank = MultiGetFloat(data, &count);
9161
9162 AddBlinkingHUDMessage(str);
9163
9164 // Play a sound
9165 if (goodnews) {
9166 int soundnum = FindSoundName("CTFScore1");
9167 if (soundnum > 0)
9168 Sound_system.Play2dSound(soundnum);
9169 } else {
9170 int soundnum = FindSoundName("CTFLostFlag1");
9171 if (soundnum > 0)
9172 Sound_system.Play2dSound(soundnum);
9173 }
9174
9175 Players[pnum].rank = newrank;
9176 }
9177
9178 // Server is telling me to strip bare!
9179 void MultiDoStripPlayer(int slot, uint8_t *data) {
9180 if (slot != 0) {
9181 // server didnt send this to us?!
9182 Int3();
9183 return;
9184 }
9185
9186 int count = 0;
9187 SKIP_HEADER(data, &count);
9188 slot = MultiGetByte(data, &count);
9189 if (Game_mode & GM_MULTI && Netgame.local_role != LR_SERVER && (slot != Player_num)) {
9190 Int3();
9191 return;
9192 }
9193
9194 mprintf(0, "I'm stripping %d bare! (of weapons)\n", slot);
9195
9196 object *pobj = &Objects[Players[slot].objnum];
9197
9198 // take quad fire
9199 static int quad_id = -2;
9200 if (pobj->dynamic_wb[LASER_INDEX].flags & DWBF_QUAD || pobj->dynamic_wb[SUPER_LASER_INDEX].flags & DWBF_QUAD) {
9201 pobj->dynamic_wb[LASER_INDEX].flags &= ~DWBF_QUAD;
9202 pobj->dynamic_wb[SUPER_LASER_INDEX].flags &= ~DWBF_QUAD;
9203
9204 if (quad_id == -2)
9205 quad_id = FindObjectIDName("QuadLaser");
9206
9207 if (quad_id > -1) {
9208 Players[slot].inventory.Remove(OBJ_POWERUP, quad_id);
9209 }
9210 }
9211
9212 int i;
9213
9214 // remove weapons
9215 for (i = 0; i < MAX_PLAYER_WEAPONS; i++) {
9216 Players[slot].weapon_ammo[i] = 0;
9217 Players[slot].weapon_flags &= ~HAS_FLAG(i);
9218 }
9219
9220 // reset lasers back on
9221 Players[slot].weapon_flags = HAS_FLAG(LASER_INDEX) + HAS_FLAG(FLARE_INDEX) + HAS_FLAG(CONCUSSION_INDEX);
9222 Players[slot].weapon[PW_PRIMARY].index = LASER_INDEX;
9223 Players[slot].weapon[PW_PRIMARY].firing_time = 0;
9224 Players[slot].weapon[PW_PRIMARY].sound_handle = -1;
9225 Players[slot].weapon[PW_SECONDARY].index = CONCUSSION_INDEX;
9226 Players[slot].weapon[PW_SECONDARY].firing_time = 0;
9227 Players[slot].weapon[PW_SECONDARY].sound_handle = -1;
9228
9229 // set energy to 0
9230 Players[slot].energy = 0;
9231
9232 // remove counter measures
9233 Players[slot].counter_measures.Reset(true, INVRESET_DEATHSPEW);
9234 }
9235
9236 // Strips a player bare of weapons
9237 void MultiSendStripPlayer(int slot) {
9238 if (Game_mode & GM_MULTI) {
9239 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
9240 } else {
9241 if (slot == -1) {
9242 // it's not a multiplayer game, bash to just us
9243 slot = Player_num;
9244 }
9245 }
9246
9247 int count = 0, save_count;
9248 uint8_t data[MAX_GAME_DATA_SIZE];
9249 int size_offset;
9250 size_offset = START_DATA(MP_STRIP_PLAYER, data, &count);
9251 save_count = count;
9252 MultiAddByte(slot, data, &count);
9253 END_DATA(count, data, size_offset);
9254
9255 if (slot != -1) {
9256 MultiDoStripPlayer(Player_num, data);
9257 if (slot != Player_num)
9258 nw_SendReliable(NetPlayers[slot].reliable_socket, data, count, false);
9259 } else {
9260 // strip all the players
9261 int i;
9262 for (i = 0; i < MAX_PLAYERS; i++) {
9263 if ((NetPlayers[i].flags & NPF_CONNECTED) && (NetPlayers[i].sequence != NETSEQ_PLAYING)) {
9264 MultiAddByte(i, data, &save_count); // change the value in the packet
9265 MultiDoStripPlayer(Player_num, data);
9266 if (i != Player_num)
9267 nw_SendReliable(NetPlayers[i].reliable_socket, data, count, false);
9268 }
9269 }
9270 }
9271 }
9272
9273 // Server is telling me about a player rank
9274 void MultiDoInitialRank(uint8_t *data) {
9275 int count = 0;
9276 SKIP_HEADER(data, &count);
9277
9278 int pnum = MultiGetByte(data, &count);
9279 float rank = MultiGetFloat(data, &count);
9280
9281 mprintf(0, "Got initial rank for player %d (%f)\n", pnum, rank);
9282
9283 Players[pnum].rank = rank;
9284 }
9285
9286 // Tell all the clients about this players rank
9287 void MultiSendInitialRank(int pnum) {
9288 MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER);
9289
9290 int count = 0;
9291 uint8_t data[MAX_GAME_DATA_SIZE];
9292 int size_offset;
9293 size_offset = START_DATA(MP_INITIAL_RANK, data, &count);
9294 MultiAddByte(pnum, data, &count);
9295 MultiAddFloat(Players[pnum].rank, data, &count);
9296
9297 mprintf(0, "Sending initial rank for player %d\n", pnum);
9298
9299 END_DATA(count, data, size_offset);
9300
9301 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_PLAYERS, false);
9302 }
9303
9304 // Server only function to clear a Guidebot for a disconnected player
9305 void MultiClearGuidebot(int slot) {
9306 if (!(Game_mode & GM_MULTI))
9307 return;
9308 if (Netgame.local_role != LR_SERVER)
9309 return;
9310 if (!(Netgame.flags & NF_ALLOWGUIDEBOT))
9311 return;
9312
9313 // Kill off the old buddy bot
9314 object *buddy = ObjGet(Buddy_handle[slot]);
9315 if (buddy) {
9316 SetObjectDeadFlag(buddy, true, false);
9317 }
9318 Buddy_handle[slot] = OBJECT_HANDLE_NONE;
9319
9320 // Recreate a buddy bot
9321 int parent_handle;
9322 if (Players[slot].objnum < 0 || Players[slot].objnum > Highest_object_index ||
9323 Objects[Players[slot].objnum].type == OBJ_NONE) {
9324 parent_handle = OBJECT_HANDLE_NONE;
9325 } else {
9326 parent_handle = Objects[Players[slot].objnum].handle;
9327 }
9328
9329 // BLACKPYRO
9330 int objnum = ObjCreate(OBJ_ROBOT, ROBOT_GUIDEBOT, Player_object->roomnum, &Player_object->pos, NULL, parent_handle);
9331
9332 ASSERT(objnum != -1);
9333 if (objnum == -1)
9334 return;
9335
9336 // tell the client about the new buddy
9337 MultiSendObject(&Objects[objnum], 0);
9338
9339 InitObjectScripts(&Objects[objnum], true);
9340
9341 Buddy_handle[slot] = Objects[objnum].handle;
9342 ObjGhostObject(objnum);
9343
9344 MultiSendGhostObject(&Objects[objnum], true);
9345
9346 // now update the buddy handle list of the clients
9347 int count = 0;
9348 int size_offset;
9349 uint8_t data[MAX_GAME_DATA_SIZE];
9350
9351 mprintf(0, "Sending Buddy_handle update to clients for Buddy#%d\n", slot);
9352
9353 size_offset = START_DATA(MP_WORLD_STATES, data, &count);
9354
9355 MultiAddByte(WS_BUDDYBOTUPDATE, data, &count);
9356 MultiAddByte(slot, data, &count);
9357 MultiAddUshort(Buddy_handle[slot] & HANDLE_OBJNUM_MASK, data, &count);
9358
9359 MultiAddByte(WS_END, data, &count);
9360 END_DATA(count, data, size_offset);
9361
9362 // Send it out
9363 MultiSendReliablyToAllExcept(Player_num, data, count, NETSEQ_OBJECTS, false);
9364 }
9365
9366 void RequestPlayerList(network_address *addr) {
9367 uint8_t outdata[10];
9368 int count = 0;
9369 int size;
9370
9371 size = START_DATA(MP_REQUEST_PLAYERLIST, outdata, &count);
9372 END_DATA(count, outdata, size);
9373 nw_Send(addr, outdata, count, 0);
9374 }
9375
9376 // a client is requesting a list of players... so give it to em!
9377 void DoReqPlayerList(network_address *addr) {
9378 uint8_t outdata[((CALLSIGN_LEN + 1) * MAX_NET_PLAYERS) + 1];
9379 int count = 0;
9380 int size;
9381
9382 memset(outdata, 0, sizeof(outdata));
9383 size = START_DATA(MP_PLAYERLIST_DATA, outdata, &count);
9384
9385 uint16_t icurrplayers = 0;
9386 int i = 0;
9387 if (Dedicated_server) {
9388 // Skip the server player
9389 i = 1;
9390 }
9391
9392 for (; i < MAX_NET_PLAYERS; i++) {
9393 if ((NetPlayers[i].flags & NPF_CONNECTED) && (Players[i].callsign[0])) {
9394 memcpy(outdata + count, Players[i].callsign, strlen(Players[i].callsign) + 1);
9395 count += strlen(Players[i].callsign) + 1;
9396 }
9397 }
9398 // Add one last 0 to signal the end of the player list
9399 count++;
9400 outdata[count] = 0;
9401
9402 END_DATA(count, outdata, size);
9403
9404 nw_Send(addr, outdata, count, 0);
9405 }
9406
9407 char *Multi_recieved_player_list = NULL;
9408 bool Multi_got_player_list = false;
9409
9410 void DoPlayerListData(uint8_t *data, int len) {
9411 int count = 0;
9412 if (Multi_recieved_player_list == NULL) {
9413 mprintf(0, "Received a player list packet when we weren't expecting one. Ignoring.\n");
9414 return;
9415 }
9416 SKIP_HEADER(data, &count);
9417 memcpy(Multi_recieved_player_list, data + count, len);
9418 Multi_got_player_list = true;
9419 }
9420
9421 // Tell a player what ship they are supposed to switch to
9422 // if the one they chose isn't allowed.
9423 void MultiBashPlayerShip(int slot, char *ship) {
9424 uint8_t outdata[100];
9425 int count = 0;
9426 int size;
9427
9428 size = START_DATA(MP_BASHPLAYER_SHIP, outdata, &count);
9429 strcpy((char *)outdata + count, ship);
9430 count += strlen(ship) + 1;
9431 END_DATA(count, outdata, size);
9432 nw_SendReliable(NetPlayers[slot].reliable_socket, outdata, count, true);
9433 }
9434
9435 int ObjInitTypeSpecific(object *objp, bool reinitializing);
9436
9437 void MultiDoBashPlayerShip(uint8_t *data) {
9438 int count = 0;
9439
9440 SKIP_HEADER(data, &count);
9441 int ship_index = FindShipName((const char *)data + count);
9442 if (ship_index < 0)
9443 ship_index = 0;
9444
9445 // If told to switch to the Black Pyro, make sure it's allowed
9446 if (!stricmp(Ships[ship_index].name, "Black Pyro")) {
9447 extern bool MercInstalled();
9448 if (!MercInstalled()) {
9449 BailOnMultiplayer("Exiting: Game requires Black Pyro");
9450 }
9451 }
9452
9453 AddHUDMessage("%s not allowed", Ships[Players[Player_num].ship_index].name);
9454 AddHUDMessage("Switching to %s", Ships[ship_index].name);
9455
9456 PlayerChangeShip(Player_num, ship_index);
9457 mprintf(0, "Server told us to switch ships to the %s\n", (char *)data + count);
9458
9459 FreeCockpit();
9460 CloseShipHUD();
9461
9462 // ObjInitTypeSpecific(Player_object,0); //reset physics, model, etc.
9463 InitShipHUD(Players[Player_num].ship_index);
9464 InitCockpit(Players[Player_num].ship_index);
9465
9466 if (GetHUDMode() == HUD_COCKPIT)
9467 SetHUDMode(HUD_COCKPIT);
9468 else if (GetHUDMode() == HUD_FULLSCREEN)
9469 SetHUDMode(HUD_FULLSCREEN);
9470 }
9471
9472 // If its been x seconds since we've sent a heartbeat, send another!
9473
9474 #define HEARTBEAT_INTERVAL 10.0f
9475 void MultiSendHeartbeat() {
9476 static float last_heartbeat = timer_GetTime();
9477
9478 float time_scalar = 1;
9479
9480 if (Netgame.local_role == LR_SERVER)
9481 time_scalar = .5; // Server sends out twice as fast
9482
9483 if ((timer_GetTime() - last_heartbeat) > (HEARTBEAT_INTERVAL * time_scalar)) {
9484 uint8_t outdata[100];
9485 int count = 0;
9486 int size;
9487
9488 size = START_DATA(MP_HEARTBEAT, outdata, &count);
9489 END_DATA(count, outdata, size);
9490
9491 if (Netgame.local_role == LR_SERVER) {
9492
9493 mprintf(0, "Server sending heartbeat.\n");
9494 MultiSendToAllExcept(Player_num, outdata, count, -1);
9495 } else {
9496 mprintf(0, "Client sending heartbeat.\n");
9497 nw_Send(&Netgame.server_address, outdata, count, 0);
9498 }
9499
9500 // Reset interval
9501 last_heartbeat = timer_GetTime();
9502 }
9503 }
9504
9505 //-----------------------------------------------
9506 void MultiDoMSafeFunction(uint8_t *data);
9507 void MultiDoMSafePowerup(uint8_t *data);
9508
9509 // This allows us to specify under what sequences certain packets are accepted
9510 #define ACCEPT_CONDITION(s, e) \
9511 { \
9512 if (sequence < s || sequence > e) \
9513 return; \
9514 }
9515 // #define ACCEPT_CONDITION(s,e)
9516
9517 // Takes the individual packet types and passes their data to the appropriate routines
9518 void MultiProcessData(uint8_t *data, int len, int slot, network_address *from_addr) {
9519 uint8_t type = data[0];
9520 len = len;
9521 int sequence = -1;
9522
9523 // HEY!!!!! These packets are the only ones that are accepted by non-connected machines
9524 // (ie people on the netgame join screen)
9525 // This will go away once I fill out all the ACCEPT_CONDITION types
9526 if (!(NetPlayers[Player_num].flags & NPF_CONNECTED)) {
9527 if (type != MP_CONNECTION_ACCEPTED && type != MP_JOIN_RESPONSE && type != MP_GAME_INFO &&
9528 type != MP_PLAYERLIST_DATA && type != MP_ASK_FOR_URL && type != MP_CUR_MSN_URLS)
9529 return;
9530 } else {
9531 // Setup our sequences for accept conditions
9532 if (Netgame.local_role == LR_SERVER) {
9533 if (NetPlayers[Player_num].sequence != NETSEQ_PLAYING)
9534 return;
9535 if (slot == -1)
9536 sequence = -1;
9537 else
9538 sequence = NetPlayers[slot].sequence;
9539 } else {
9540 sequence = NetPlayers[Player_num].sequence;
9541 }
9542 }
9543
9544 #ifndef RELEASE
9545 Multi_packet_tracking[type]++;
9546 #endif
9547
9548 switch (type) {
9549 case MP_CONNECTION_ACCEPTED:
9550 ACCEPT_CONDITION(-1, -1);
9551 MultiDoConnectionAccepted(data);
9552 break;
9553 case MP_REQUEST_PLAYERS:
9554 MultiDoRequestPlayers(data);
9555 break;
9556 case MP_REQUEST_BUILDINGS:
9557 MultiDoRequestBuildings(data);
9558 break;
9559 case MP_REQUEST_OBJECTS:
9560 MultiDoRequestObjects(data);
9561 break;
9562 case MP_REQUEST_WORLD_STATES:
9563 MultiDoRequestWorldStates(data);
9564 break;
9565 case MP_PLAYER_POS:
9566 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9567 NetPlayers[Player_num].total_bytes_rcvd += len;
9568 MultiDoPlayerPos(data);
9569 break;
9570 case MP_DONE_PLAYERS:
9571 MultiDoDonePlayers(data);
9572 break;
9573 case MP_DONE_BUILDINGS:
9574 MultiDoDoneBuildings(data);
9575 break;
9576 case MP_DONE_OBJECTS:
9577 MultiDoDoneObjects(data);
9578 break;
9579 case MP_DONE_WORLD_STATES:
9580 MultiDoDoneWorldStates(data);
9581 break;
9582 case MP_ENTERING_GAME:
9583 MultiDoEnteringGame(data);
9584 break;
9585 case MP_PLAYER:
9586 MultiDoPlayer(data);
9587 break;
9588 case MP_BUILDING:
9589 MultiDoBuilding(data);
9590 break;
9591 case MP_WORLD_STATES:
9592 MultiDoWorldStates(data);
9593 break;
9594 case MP_JOIN_OBJECTS:
9595 MultiDoJoinObjects(data);
9596 break;
9597 case MP_SEND_DEMO_OBJECT_FLAGS:
9598 MultiDoJoinDemoObjects(data);
9599 break;
9600 case MP_MY_INFO:
9601 ACCEPT_CONDITION(NETSEQ_LEVEL_START, NETSEQ_LEVEL_START);
9602 MultiDoMyInfo(data);
9603 break;
9604 case MP_DISCONNECT:
9605 ACCEPT_CONDITION(-1, 255);
9606 MultiDoDisconnect(data);
9607 break;
9608 case MP_PLAYER_FIRE:
9609 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9610 MultiDoFirePlayerWB(data);
9611 break;
9612 case MP_ASK_TO_JOIN:
9613 ACCEPT_CONDITION(-1, -1);
9614 MultiDoAskToJoin(data, from_addr);
9615 break;
9616 case MP_JOIN_RESPONSE:
9617 ACCEPT_CONDITION(-1, -1);
9618 MultiDoJoinResponse(data);
9619 break;
9620 case MP_SERVER_QUIT:
9621 ACCEPT_CONDITION(NETSEQ_WAITING_FOR_LEVEL, 255);
9622 MultiDoServerQuit(data);
9623 break;
9624 case MP_LEAVE_GAME:
9625 MultiDoLeaveGame(data);
9626 break;
9627 case MP_BLOWUP_BUILDING:
9628 ACCEPT_CONDITION(NETSEQ_REQUEST_OBJECTS, 255);
9629 MultiDoBlowupBuilding(data);
9630 break;
9631 case MP_PLAYER_DEAD:
9632 ACCEPT_CONDITION(NETSEQ_PLAYERS, NETSEQ_PLAYING);
9633 MultiDoPlayerDead(data);
9634 break;
9635 case MP_PLAYER_ENTERED_GAME:
9636 ACCEPT_CONDITION(NETSEQ_REQUEST_BUILDINGS, 255);
9637 MultiDoPlayerEnteredGame(data);
9638 break;
9639 case MP_DAMAGE_PLAYER:
9640 ACCEPT_CONDITION(NETSEQ_PLAYERS, NETSEQ_PLAYING);
9641 MultiDoDamagePlayer(data);
9642 break;
9643 case MP_MESSAGE_FROM_SERVER:
9644 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9645 MultiDoMessageFromServer(data);
9646 break;
9647 case MP_MESSAGE_TO_SERVER:
9648 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9649 MultiDoMessageToServer(data);
9650 break;
9651 case MP_END_PLAYER_DEATH:
9652 MultiDoEndPlayerDeath(data);
9653 break;
9654 case MP_RENEW_PLAYER:
9655 ACCEPT_CONDITION(NETSEQ_PLAYERS, NETSEQ_PLAYING);
9656 MultiDoRenewPlayer(data);
9657 break;
9658 case MP_GET_GAME_INFO:
9659 ACCEPT_CONDITION(-1, -1);
9660 MultiDoGetGameInfo(data, from_addr);
9661 break;
9662 case MP_GET_PXO_GAME_INFO:
9663 ACCEPT_CONDITION(-1, -1);
9664 MultiDoGetPXOGameInfo(data, from_addr);
9665 break;
9666 case MP_GAME_INFO:
9667 ACCEPT_CONDITION(-1, -1);
9668 MultiDoGameInfo(data, from_addr);
9669 break;
9670 case MP_OBJECT:
9671 ACCEPT_CONDITION(NETSEQ_OBJECTS, NETSEQ_PLAYING);
9672 MultiDoObject(data);
9673 break;
9674 case MP_SPECIAL_PACKET:
9675 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9676 MultiDoSpecialPacket(data);
9677 break;
9678 case MP_EXECUTE_DLL:
9679 MultiDoExecuteDLL(data);
9680 break;
9681 case MP_REMOVE_OBJECT:
9682 MultiDoRemoveObject(data);
9683 break;
9684 case MP_GUIDED_INFO:
9685 MultiDoGuidedInfo(data);
9686 break;
9687 case MP_LEVEL_INFO:
9688 ACCEPT_CONDITION(NETSEQ_WAITING_FOR_LEVEL, NETSEQ_WAITING_FOR_LEVEL);
9689 MultiDoLevelInfo(data);
9690 break;
9691 case MP_READY_FOR_LEVEL:
9692 ACCEPT_CONDITION(NETSEQ_WAITING_FOR_LEVEL, NETSEQ_WAITING_FOR_LEVEL);
9693 MultiDoReadyForLevel(data);
9694 break;
9695 case MP_LEVEL_ENDED:
9696 MultiDoLevelEnded(data);
9697 break;
9698 case MP_GET_GAMETIME:
9699 ACCEPT_CONDITION(NETSEQ_NEED_GAMETIME, NETSEQ_NEED_GAMETIME);
9700 MultiDoGameTimeReq(data, from_addr);
9701 break;
9702 case MP_HERE_IS_GAMETIME:
9703 ACCEPT_CONDITION(NETSEQ_NEED_GAMETIME, NETSEQ_WAIT_GAMETIME);
9704 MultiDoSetGameTime(data);
9705 break;
9706 case MP_POWERUP_REPOSITION:
9707 ACCEPT_CONDITION(NETSEQ_OBJECTS, NETSEQ_PLAYING);
9708 MultiDoPowerupReposition(data);
9709 break;
9710 case MP_ROBOT_POS:
9711 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9712 MultiDoRobotPos(data);
9713 break;
9714 case MP_ROBOT_FIRE:
9715 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9716 MultiDoRobotFire(data);
9717 break;
9718 case MP_ON_OFF:
9719 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9720 MultiDoOnOff(data);
9721 break;
9722 case MP_ROBOT_DAMAGE:
9723 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9724 MultiDoRobotDamage(data);
9725 break;
9726 case MP_ROBOT_EXPLODE:
9727 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9728 MultiDoRobotExplode(data);
9729 break;
9730 case MP_ADDITIONAL_DAMAGE:
9731 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9732 MultiDoAdditionalDamage(data);
9733 break;
9734 case MP_ANIM_UPDATE:
9735 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9736 MultiDoObjAnimUpdate(data);
9737 break;
9738 case MP_PLAY_3D_SOUND_FROM_OBJ:
9739 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9740 MultiDoPlay3dSound(data);
9741 break;
9742 case MP_ROBOT_FIRE_SOUND:
9743 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9744 MultiDoRobotFireSound(data);
9745 break;
9746 case MP_TURRET_UPDATE:
9747 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9748 MultiDoTurretUpdate(data);
9749 break;
9750 case MP_CLIENT_USE_INVENTORY_ITEM:
9751 MultiDoClientInventoryUseItem(slot, data);
9752 break;
9753 case MP_REMOVE_INVENTORY_ITEM:
9754 MultiDoClientInventoryRemoveItem(slot, data);
9755 break;
9756 case MP_REQUEST_COUNTERMEASURE:
9757 MultiDoRequestCountermeasure(data);
9758 break;
9759 case MP_SERVER_SENT_COUNT:
9760 MultiDoBytesSent(data);
9761 break;
9762 case MP_CLIENT_SET_PPS:
9763 MultiDoPPSSet(data, slot);
9764 break;
9765 case MP_GREETINGS_FROM_CLIENT:
9766 MultiDoGreetings(data, from_addr);
9767 break;
9768 case MP_REQUEST_TO_OBSERVE:
9769 MultiDoRequestToObserve(data);
9770 break;
9771 case MP_OBSERVER_CHANGE:
9772 MultiDoObserverChange(data);
9773 break;
9774 case MP_VISIBLE_PLAYERS:
9775 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9776 MultiDoVisiblePlayers(data);
9777 break;
9778 case MP_FILE_REQ:
9779 MultiDoFileReq(data);
9780 break;
9781 case MP_FILE_DENIED:
9782 MultiDoFileDenied(data);
9783 break;
9784 case MP_FILE_DATA:
9785 MultiDoFileData(data);
9786 break;
9787 case MP_FILE_ACK:
9788 MultiDoFileAck(data);
9789 break;
9790 case MP_FILE_CANCEL:
9791 MultiDoFileCancelled(data);
9792 break;
9793 case MP_PLAYER_CUSTOM_DATA:
9794 MultiDoCustomPlayerData(data);
9795 break;
9796 case MP_GHOST_OBJECT:
9797 MultiDoGhostObject(data);
9798 break;
9799 case MP_PLAYER_PING:
9800 MultiDoPing(data, from_addr);
9801 break;
9802 case MP_PLAYER_PONG:
9803 MultiDoPong(data);
9804 break;
9805 case MP_PLAYER_LAG_INFO:
9806 MultiDoLagInfo(data);
9807 break;
9808 case MP_REQUEST_SHIELDS:
9809 MultiDoRequestShields(data);
9810 break;
9811 case MP_REQUEST_DAMAGE:
9812 MultiDoRequestDamage(data);
9813 break;
9814 case MP_ATTACH_OBJ:
9815 MultiDoAttach(data);
9816 break;
9817 case MP_UNATTACH_OBJ:
9818 MultiDoUnattach(data);
9819 break;
9820 case MP_AIWEAP_FLAGS:
9821 MultiDoAiWeaponFlags(data);
9822 break;
9823 case MP_ATTACH_RAD_OBJ:
9824 MultiDoAttachRad(data);
9825 break;
9826 case MP_TIMEOUT_WEAPON:
9827 MultiDoReleaseTimeoutMissile(data);
9828 break;
9829 case MP_WEAPONS_LOAD:
9830 MultiDoWeaponsLoad(data);
9831 break;
9832 case MP_REQUEST_PEER_DAMAGE:
9833 MultiDoRequestPeerDamage(data, from_addr);
9834 break;
9835 case MP_MSAFE_FUNCTION:
9836 MultiDoMSafeFunction(data);
9837 break;
9838 case MP_MSAFE_POWERUP:
9839 MultiDoMSafePowerup(data);
9840 break;
9841 case MP_ASK_FOR_URL:
9842 msn_DoAskForURL(data, from_addr);
9843 break;
9844 case MP_CUR_MSN_URLS:
9845 msn_DoCurrMsnURLs(data, from_addr);
9846 break;
9847 case MP_REQUEST_TO_FIRE:
9848 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9849 MultiDoRequestToFire(data);
9850 break;
9851 case MP_PERMISSION_TO_FIRE:
9852 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9853 MultiDoPermissionToFire(data);
9854 break;
9855 case MP_CONNECT_BAIL:
9856 MultiDoConnectBail();
9857 break;
9858 case MP_CLIENT_PLAY_TAUNT:
9859 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9860 MultiDoRequestPlayTaunt(data);
9861 break;
9862 case MP_SERVER_PLAY_TAUNT:
9863 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9864 MultiDoPlayTaunt(data);
9865 break;
9866 case MP_REQUEST_MARKER:
9867 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9868 MultiDoRequestMarker(data);
9869 break;
9870 case MP_REQUEST_TYPE_ICON:
9871 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9872 MultiDoRequestTypeIcon(data);
9873 break;
9874 case MP_SEND_TYPE_ICON:
9875 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9876 MultiDoTypeIcon(data);
9877 break;
9878 case MP_REQUEST_TO_MOVE:
9879 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9880 MultiDoRequestToMove(data);
9881 break;
9882 case MP_ADJUST_POSITION:
9883 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9884 MultiDoAdjustPosition(data);
9885 break;
9886 case MP_GENERIC_NONVIS:
9887 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9888 MultiDoGenericNonVis(data);
9889 break;
9890 case MP_GUIDEBOTMENU_REQUEST:
9891 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9892 MultiDoGuidebotMenuRequest(data, slot);
9893 break;
9894 case MP_GUIDEBOTMENU_DATA:
9895 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9896 MultiDoGuidebotMenuData(data);
9897 break;
9898 case MP_BREAK_GLASS:
9899 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9900 MultiDoBreakGlass(data);
9901 break;
9902 case MP_THIEF_STEAL:
9903 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9904 MultiDoThiefSteal(data);
9905 break;
9906 case MP_REQUEST_PLAYERLIST:
9907 ACCEPT_CONDITION(-1, -1);
9908 DoReqPlayerList(from_addr);
9909 break;
9910 case MP_PLAYERLIST_DATA:
9911 ACCEPT_CONDITION(-1, -1);
9912 DoPlayerListData(data, len);
9913 break;
9914 case MP_SERVER_AUDIOTAUNT_TIME:
9915 MultiDoAudioTauntTime(data);
9916 break;
9917 case MP_CHANGE_RANK:
9918 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9919 MultiDoChangeRank(data);
9920 break;
9921 case MP_BASHPLAYER_SHIP:
9922 ACCEPT_CONDITION(NETSEQ_LEVEL_START, NETSEQ_PLAYING);
9923 MultiDoBashPlayerShip(data);
9924 break;
9925 case MP_HEARTBEAT:
9926 if (Netgame.local_role == LR_CLIENT) {
9927 Got_heartbeat = true;
9928 mprintf(0, "Got heartbeat from server.\n");
9929 } else
9930 mprintf(0, "Got heartbeat from slot %d.\n", slot);
9931 break;
9932 case MP_INITIAL_RANK:
9933 MultiDoInitialRank(data);
9934 break;
9935 case MP_MISSILE_RELEASE:
9936 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9937 MultiDoMissileRelease(slot, data);
9938 break;
9939 case MP_STRIP_PLAYER:
9940 ACCEPT_CONDITION(NETSEQ_PLAYING, NETSEQ_PLAYING);
9941 MultiDoStripPlayer(slot, data);
9942 break;
9943 case MP_REJECTED_CHECKSUM:
9944 ACCEPT_CONDITION(-1, -1);
9945 MultiDoServerRejectedChecksum(data);
9946 default:
9947 mprintf(0, "Invalid packet type %d!\n", type);
9948 Int3(); // Invalid packet type!!!!
9949 break;
9950 }
9951 }
9952
9953 // Takes a bunch of messages, check them for validity,
9954 // and pass them to multi_process_data.
9955 void MultiProcessBigData(uint8_t *buf, int len, network_address *from_addr) {
9956 int type, bytes_processed = 0;
9957 int16_t sub_len;
9958 int slot = 0;
9959 int last_type = -1, last_len = -1;
9960
9961 // Update timer stuff so we don't disconnect due to timeout
9962 if (Netgame.local_role == LR_CLIENT) {
9963 Netgame.last_server_time = timer_GetTime();
9964 } else {
9965 slot = MultiMatchPlayerToAddress(from_addr);
9966 if (slot >= 0) {
9967 // This is to prevent clients who have disconnected on the client side
9968 // but not the server side from being credited with a recent packet
9969 // just because they are looking for a game
9970 if ((buf[0] != MP_GET_PXO_GAME_INFO) && (buf[0] != MP_GET_GAME_INFO)) {
9971 NetPlayers[slot].last_packet_time = timer_GetTime();
9972 } else {
9973 // Someone who we think is still connected is looking for game info!
9974 // We aren't going to process this packet because otherwise they
9975 // might try to join which wouldn't work and they would be credited
9976 // with sending a packet and the server wouldn't disconnect them.
9977 mprintf(0, "Ignoring game info request from a currently connected user (%s)\n", Players[slot].callsign);
9978 return;
9979 }
9980 }
9981 }
9982
9983 while (bytes_processed < len) {
9984 type = buf[bytes_processed];
9985 sub_len = INTEL_SHORT((*(int16_t *)(buf + bytes_processed + 1)));
9986
9987 if (sub_len < 3 || type == 0 || (len - bytes_processed) < 2) {
9988 mprintf(0, "Got a corrupted packet!\n");
9989 Int3();
9990 return; // just throw the rest out
9991 }
9992
9993 if ((bytes_processed + sub_len) > len) {
9994 mprintf(1, "multi_process_bigdata: packet type %d too int16_t (%d>%d)!\n", type, (bytes_processed + sub_len), len);
9995 Int3();
9996 return;
9997 }
9998
9999 MultiProcessData(&buf[bytes_processed], sub_len, slot, from_addr);
10000 bytes_processed += sub_len;
10001 last_type = type;
10002 last_len = sub_len;
10003 }
10004 }