net_vcr.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. // net_vcr.c
  16. #include "quakedef.h"
  17. #include "net_vcr.h"
  18. extern int vcrFile;
  19. // This is the playback portion of the VCR. It reads the file produced
  20. // by the recorder and plays it back to the host. The recording contains
  21. // everything necessary (events, timestamps, and data) to duplicate the game
  22. // from the viewpoint of everything above the network layer.
  23. static struct
  24. {
  25. double time;
  26. int op;
  27. long session;
  28. } next;
  29. int VCR_Init (void)
  30. {
  31. net_drivers[0].Init = VCR_Init;
  32. net_drivers[0].SearchForHosts = VCR_SearchForHosts;
  33. net_drivers[0].Connect = VCR_Connect;
  34. net_drivers[0].CheckNewConnections = VCR_CheckNewConnections;
  35. net_drivers[0].QGetMessage = VCR_GetMessage;
  36. net_drivers[0].QSendMessage = VCR_SendMessage;
  37. net_drivers[0].CanSendMessage = VCR_CanSendMessage;
  38. net_drivers[0].Close = VCR_Close;
  39. net_drivers[0].Shutdown = VCR_Shutdown;
  40. Sys_FileRead(vcrFile, &next, sizeof(next));
  41. return 0;
  42. }
  43. void VCR_ReadNext (void)
  44. {
  45. if (Sys_FileRead(vcrFile, &next, sizeof(next)) == 0)
  46. {
  47. next.op = 255;
  48. Sys_Error ("=== END OF PLAYBACK===\n");
  49. }
  50. if (next.op < 1 || next.op > VCR_MAX_MESSAGE)
  51. Sys_Error ("VCR_ReadNext: bad op");
  52. }
  53. void VCR_Listen (qboolean state)
  54. {
  55. }
  56. void VCR_Shutdown (void)
  57. {
  58. }
  59. int VCR_GetMessage (qsocket_t *sock)
  60. {
  61. int ret;
  62. if (host_time != next.time || next.op != VCR_OP_GETMESSAGE || next.session != *(long *)(&sock->driverdata))
  63. Sys_Error ("VCR missmatch");
  64. Sys_FileRead(vcrFile, &ret, sizeof(int));
  65. if (ret != 1)
  66. {
  67. VCR_ReadNext ();
  68. return ret;
  69. }
  70. Sys_FileRead(vcrFile, &net_message.cursize, sizeof(int));
  71. Sys_FileRead(vcrFile, net_message.data, net_message.cursize);
  72. VCR_ReadNext ();
  73. return 1;
  74. }
  75. int VCR_SendMessage (qsocket_t *sock, sizebuf_t *data)
  76. {
  77. int ret;
  78. if (host_time != next.time || next.op != VCR_OP_SENDMESSAGE || next.session != *(long *)(&sock->driverdata))
  79. Sys_Error ("VCR missmatch");
  80. Sys_FileRead(vcrFile, &ret, sizeof(int));
  81. VCR_ReadNext ();
  82. return ret;
  83. }
  84. qboolean VCR_CanSendMessage (qsocket_t *sock)
  85. {
  86. qboolean ret;
  87. if (host_time != next.time || next.op != VCR_OP_CANSENDMESSAGE || next.session != *(long *)(&sock->driverdata))
  88. Sys_Error ("VCR missmatch");
  89. Sys_FileRead(vcrFile, &ret, sizeof(int));
  90. VCR_ReadNext ();
  91. return ret;
  92. }
  93. void VCR_Close (qsocket_t *sock)
  94. {
  95. }
  96. void VCR_SearchForHosts (qboolean xmit)
  97. {
  98. }
  99. qsocket_t *VCR_Connect (char *host)
  100. {
  101. return NULL;
  102. }
  103. qsocket_t *VCR_CheckNewConnections (void)
  104. {
  105. qsocket_t *sock;
  106. if (host_time != next.time || next.op != VCR_OP_CONNECT)
  107. Sys_Error ("VCR missmatch");
  108. if (!next.session)
  109. {
  110. VCR_ReadNext ();
  111. return NULL;
  112. }
  113. sock = NET_NewQSocket ();
  114. *(long *)(&sock->driverdata) = next.session;
  115. Sys_FileRead (vcrFile, sock->address, NET_NAMELEN);
  116. VCR_ReadNext ();
  117. return sock;
  118. }