protocol.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* Emacs style mode select -*- C++ -*-
  2. *-----------------------------------------------------------------------------
  3. *
  4. *
  5. * PrBoom: a Doom port merged with LxDoom and LSDLDoom
  6. * based on BOOM, a modified and improved DOOM engine
  7. * Copyright (C) 1999 by
  8. * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
  9. * Copyright (C) 1999-2000 by
  10. * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
  11. * Copyright 2005, 2006 by
  12. * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  27. * 02111-1307, USA.
  28. *
  29. * DESCRIPTION:
  30. * Doom Network protocol packet definitions.
  31. *-----------------------------------------------------------------------------*/
  32. #include "doomtype.h"
  33. #include "d_ticcmd.h"
  34. #include "m_swap.h"
  35. enum packet_type_e {
  36. PKT_INIT, // initial packet to server
  37. PKT_SETUP, // game information packet
  38. PKT_GO, // game has started
  39. PKT_TICC, // tics from client
  40. PKT_TICS, // tics from server
  41. PKT_RETRANS, // Request for retransmission
  42. PKT_EXTRA, // Extra info packet
  43. PKT_QUIT, // Player quit game
  44. PKT_DOWN, // Server downed
  45. PKT_WAD, // Wad file request
  46. PKT_BACKOFF, // Request for client back-off
  47. };
  48. typedef struct {
  49. byte checksum; // Simple checksum of the entire packet
  50. byte type; /* Type of packet */
  51. byte reserved[2]; /* Was random in prboom <=2.2.4, now 0 */
  52. unsigned tic; // Timestamp
  53. } PACKEDATTR packet_header_t;
  54. static inline void packet_set(packet_header_t* p, enum packet_type_e t, unsigned long tic)
  55. { p->tic = doom_htonl(tic); p->type = t; p->reserved[0] = 0; p->reserved[1] = 0; }
  56. #ifndef GAME_OPTIONS_SIZE
  57. // From g_game.h
  58. #define GAME_OPTIONS_SIZE 64
  59. #endif
  60. struct setup_packet_s {
  61. byte players, yourplayer, skill, episode, level, deathmatch, complevel, ticdup, extratic;
  62. byte game_options[GAME_OPTIONS_SIZE];
  63. byte numwads;
  64. byte wadnames[1]; // Actually longer
  65. };
  66. /* cph - convert network byte stream to usable ticcmd_t and visa-versa
  67. * - the functions are functionally identical apart from parameters
  68. * - the void* param can be unaligned. By using void* as the parameter
  69. * it means gcc won't assume alignment so won't make false assumptions
  70. * when optimising. So I'm told.
  71. */
  72. inline static void RawToTic(ticcmd_t* dst, const void* src)
  73. {
  74. memcpy(dst,src,sizeof *dst);
  75. dst->angleturn = doom_ntohs(dst->angleturn);
  76. dst->consistancy = doom_ntohs(dst->consistancy);
  77. }
  78. inline static void TicToRaw(void* dst, const ticcmd_t* src)
  79. {
  80. /* We have to make a copy of the source struct, then do byte swaps,
  81. * and fnially copy to the destination (can't do the swaps in the
  82. * destination, because it might not be aligned).
  83. */
  84. ticcmd_t tmp = *src;
  85. tmp.angleturn = doom_ntohs(tmp.angleturn);
  86. tmp.consistancy = doom_ntohs(tmp.consistancy);
  87. memcpy(dst,&tmp,sizeof tmp);
  88. }