zgameinfo.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #include "pch.h"
  2. #if 1 // #ifdef LITTLEENDIAN
  3. #if 0 //defined(_M_IX86)
  4. #define _ZEnd32( pData ) \
  5. __asm { \
  6. mov eax, *pData \
  7. bswap eax \
  8. mov *pData, eax \
  9. }
  10. #else
  11. #define _ZEnd32( pData ) \
  12. { \
  13. char *c; \
  14. char temp; \
  15. \
  16. c = (char *) pData; \
  17. temp = c[0]; \
  18. c[0] = c[3]; \
  19. c[3] = temp; \
  20. temp = c[1]; \
  21. c[1] = c[2]; \
  22. c[2] = temp; \
  23. }
  24. #endif
  25. #define _ZEnd16( pData ) \
  26. { \
  27. char *c; \
  28. char temp; \
  29. \
  30. c = (char *) pData; \
  31. temp = c[0]; \
  32. c[0] = c[1]; \
  33. c[1] = temp; \
  34. }
  35. #else // not LITTLEENDIAN
  36. #define _ZEnd32(pData)
  37. #define _ZEnd16(pData)
  38. #endif // not LITTLEENDIAN
  39. #define ZEnd32(pData) _ZEnd32(pData)
  40. #define ZEnd16(pData) _ZEnd16(pData)
  41. UdpSocket g_Broadcast;
  42. void ZGameServerInfoMsgEndian(ZGameServerInfoMsg* msg)
  43. {
  44. ZEnd32(&msg->protocolSignature);
  45. ZEnd32(&msg->protocolVersion); /* Protocol version */
  46. ZEnd16(&msg->numEntries);
  47. }
  48. void ZGameInstanceInfoMsgEndian(ZGameInstanceInfoMsg* msg)
  49. {
  50. ZEnd32(&msg->gameAddr);
  51. ZEnd16(&msg->gamePort);
  52. ZEnd16(&msg->serviceType);
  53. // order is a byte
  54. // game state is a byte
  55. ZEnd32(&msg->gameVersion);
  56. ZEnd32(&msg->numPlayers);
  57. ZEnd32(&msg->numGamesServed);
  58. ZEnd16(&msg->numTables);
  59. ZEnd16(&msg->numTablesInUse);
  60. ZEnd16(&msg->blobsize);
  61. ZEnd32(&msg->numSysops);
  62. ZEnd32(&msg->numNotPlaying);
  63. ZEnd32(&msg->maxPopulation);
  64. }
  65. void ZGameInstanceInfoMsgZ5Endian(ZGameInstanceInfoMsgZ5* msg)
  66. {
  67. ZEnd32(&msg->gameAddr);
  68. ZEnd16(&msg->gamePort);
  69. ZEnd16(&msg->serviceType);
  70. // order is a byte
  71. // game state is a byte
  72. ZEnd32(&msg->gameVersion);
  73. ZEnd32(&msg->numPlayers);
  74. ZEnd32(&msg->numGamesServed);
  75. ZEnd16(&msg->numTables);
  76. ZEnd16(&msg->numTablesInUse);
  77. ZEnd16(&msg->blobsize);
  78. ZEnd32(&msg->numSysops);
  79. ZEnd32(&msg->numNotPlaying);
  80. ZEnd32(&msg->maxPopulation);
  81. }
  82. void ZGameInstanceInfoMsgZ3Endian(ZGameInstanceInfoMsgZ3* msg)
  83. {
  84. ZEnd32(&msg->gameAddr);
  85. ZEnd16(&msg->gamePort);
  86. // game state is a byte
  87. ZEnd32(&msg->gameVersion);
  88. ZEnd32(&msg->numPlayers);
  89. ZEnd32(&msg->numGamesServed);
  90. ZEnd16(&msg->serviceType);
  91. }
  92. void ZGameServerInfoMsgZ2Endian(ZGameServerInfoMsgZ2* msg)
  93. {
  94. ZEnd32(&msg->protocolSignature);
  95. ZEnd32(&msg->protocolVersion); /* Protocol version */
  96. ZEnd32(&msg->gameVersion);
  97. ZEnd32(&msg->gameID);
  98. ZEnd32(&msg->gameAddr);
  99. ZEnd16(&msg->gamePort);
  100. ZEnd16(&msg->gameState);
  101. ZEnd32(&msg->numPlayers);
  102. ZEnd32(&msg->numGamesServed);
  103. }
  104. int ZGameInfoInit(uint16 port)
  105. {
  106. if (SOCKET_ERROR==g_Broadcast.BindExcludePort(port)) {
  107. return -1;
  108. }
  109. return 0;
  110. }
  111. int ZGameInfoClose()
  112. {
  113. if (SOCKET_ERROR==g_Broadcast.Close()) {
  114. return -1;
  115. }
  116. return 0;
  117. }
  118. int ZGameInfoSendTo(uint32 addr, uint16 port, ZGameServerInfoMsg* msg, uint16 size )
  119. {
  120. int ret = 0;
  121. ret = g_Broadcast.SendTo(msg, size, port, addr);
  122. return ret;
  123. };