Advertisement
Guest User

Untitled

a guest
May 15th, 2010
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.36 KB | None | 0 0
  1. #ifndef _H_SOLDATINFOX_
  2. #define _H_SOLDATINFOX_
  3. // Comment out this line if you want to compile for 1.5.1
  4. #define OLDSOLDAT
  5. // soldatinfo.h originally by ramirez
  6. // modified constructor to 'default'
  7. // defined REFRESH parsing as a method (for multiple acc)
  8.  
  9. #include <vector>
  10. #include <string>
  11. #include <sstream>
  12. #include <stdexcept>
  13. #ifndef OLDSOLDAT
  14. #define REFRESHX_PACKET_SIZE 1960
  15. #else
  16. #define REFRESHX_PACKET_SIZE 1608
  17. #endif
  18. struct playerX
  19. {
  20.     unsigned char namelen; // 1
  21.     char name[25]; // 24
  22.     unsigned char tagidlen; // 1
  23.     char tagid[11]; // 10
  24.     unsigned char team; // 1
  25.     unsigned short kills; // 2
  26.     unsigned char caps; // 1
  27.     unsigned short deaths; // 2
  28.     signed long ping; // 4
  29.     unsigned char id; // 1
  30.     unsigned char ip[4]; // 4
  31.     float x; // 4
  32.     float y; // 4
  33.     // 1 + 24 + 1 + 2 + 1 + 2 + 4 + 1 + 4 + 4 + 4 = 48
  34. };
  35. struct refreshX
  36. {
  37.     struct playerX players[32];
  38.     float redflagx;
  39.     float redflagy;
  40.     float blueflagx;
  41.     float blueflagy;
  42.     unsigned short alphascore;
  43.     unsigned short bravoscore;
  44.     unsigned short charliescore;
  45.     unsigned short deltascore;
  46.     unsigned char currentmaplen;
  47.     char currentmap[17];
  48.     unsigned long timelimit;
  49.     unsigned long timeleft;  
  50.     unsigned char limit;
  51.     unsigned char gamestyle;    
  52.     unsigned char maxplayers;
  53.     unsigned char maxspectators;
  54.     unsigned char password;
  55.     unsigned char nextmaplen;
  56.     char nextmap[17];
  57. };
  58. // players * 32
  59. /*
  60. #  Player (1856 Bytes)
  61.     * Names (32*25 Bytes; first Byte (unsigned char) indicates length of the nick)
  62.     * Tagid (32*10 Bytes; char)
  63.     * Teams (32*1 Byte; 0=DM Team, 1..4=Alpha..Delta, 5=Spectator)
  64.     * Kills (32*2 Bytes; unsigned short)
  65.     * Caps (32*1 Byte; unsigned char)
  66.     * Deaths (32*2 Bytes; unsigned short)
  67.     * Pings (32*4 Bytes; signed long)
  68.     * IDs (32*1 Byte; unsigned char)
  69.     * IPs (32*4 Bytes; each byte can be decoded as unsigned char then put together in the given order to a 0.0.0.0 format; or unpack as unsigned long (big endian) and use long2ip())
  70.     * X Locations (32*4 Bytes; float)
  71.     * Y Locations (32*4 Bytes; float)                  
  72. */
  73. #ifndef OLDSOLDAT
  74. #define XNAMELEN_OFFSET 0
  75. #define XNAMELEN_SIZE 1
  76. #define XNAME_OFFSET 1
  77. #define XNAME_SIZE 24
  78. #define XTAGIDLEN_OFFSET 25*32
  79. #define XTAGIDLEN_SIZE 1
  80. #define XTAGID_OFFSET 26*32
  81. #define XTAGID_SIZE 10
  82. #define XTEAM_OFFSET 36*32
  83. #define XTEAM_SIZE 1
  84. #define XKILLS_OFFSET 37*32
  85. #define XKILLS_SIZE 2
  86. #define XCAPS_OFFSET 39*32
  87. #define XCAPS_SIZE 1
  88. #define XDEATHS_OFFSET 40*32
  89. #define XDEATHS_SIZE 2
  90. #define XPINGS_OFFSET 42*32
  91. #define XPINGS_SIZE 4
  92. #define XID_OFFSET 46*32
  93. #define XID_SIZE 1
  94. #define XIP_OFFSET 47*32
  95. #define XIP_SIZE 4
  96. #define XLOCX_OFFSET 51*32
  97. #define XLOCX_SIZE 4
  98. #define XLOCY_OFFSET 55*32
  99. #define XLOCY_SIZE 4
  100. // Rest
  101. /*
  102. # Red Flag X Location (4 Bytes; float)
  103. # Red Flag Y Location (4 Bytes; float)
  104. # Blue Flag X Location (4 Bytes; float)
  105. # Blue Flag Y Location (4 Bytes; float)
  106. # Team Scores (4*2 Bytes; unsigned short)
  107. # Map Name (17 Bytes; first Byte (unsigned char) indicates length)
  108. # Time Limit (4 Bytes; unsigned long; in Ticks)
  109. # Time Left (4 Bytes; unsigned long; in Ticks)
  110. # Cap/Kill Limit (2 Bytes; unsigned short)
  111. # Gamestyle (1 Byte; unsigned char; 0=DM, 1=PM, 2=TM, 3=CTF, 4=RM, 5=INF, 6=HTF)
  112. # Max Players (1 Byte; unsigned char)
  113. # Max Spectators (1 Byte; unsigned char)
  114. # Game Passworded? (1 Byte; boolean)
  115. # Next Map (17 Bytes; first Byte (unsigned char) indicates length)
  116. */
  117.  
  118. #define XREDFLAGX_OFFSET 1888
  119. #define XREDFLAGX_SIZE 4
  120. #define XREDFLAGY_OFFSET 1892
  121. #define XREDFLAGY_SIZE 4
  122. #define XBLUEFLAGX_OFFSET 1864
  123. #define XBLUEFLAGX_SIZE 4
  124. #define XBLUEFLAGY_OFFSET 1900
  125. #define XBLUEFLAGY_SIZE 4
  126. #define XALPHATEAMSCORE_OFFSET 1904
  127. #define XALPHATEAMSCORE_SIZE 2
  128. #define XBRAVOTEAMSCORE_OFFSET 1906
  129. #define XBRAVOTEAMSCORE_SIZE 2
  130. #define XCHARLIETEAMSCORE_OFFSET 1908
  131. #define XCHARLIETEAMSCORE_SIZE 2
  132. #define XDELTATEAMSCORE_OFFSET 1910
  133. #define XDELTATEAMSCORE_SIZE 2
  134. #define XCURRENTMAPLEN_OFFSET 1912
  135. #define XCURRENTMAPLEN_SIZE 1
  136. #define XCURRENTMAP_OFFSET 1913
  137. #define XCURRENTMAP_SIZE 16
  138. #define XTIMELIMIT_OFFSET 1929
  139. #define XTIMELIMIT_SIZE 4
  140. #define XTIMELEFT_OFFSET 1933
  141. #define XTIMELEFT_SIZE 4
  142. #define XLIMIT_OFFSET 1937
  143. #define XLIMIT_SIZE 2
  144. #define XGAMESTYLE_OFFSET 1939
  145. #define XGAMESTYLE_SIZE 1
  146. #define XMAXPLAYERS_OFFSET 1940
  147. #define XMAXPLAYERS_SIZE 1
  148. #define XMAXSPECTATORS_OFFSET 1941
  149. #define XMAXSPECTATORS_SIZE 1
  150. #define XPASSWORD_OFFSET 1942
  151. #define XPASSWORD_SIZE 1
  152. #define XNEXTMAPLEN_OFFSET 1943
  153. #define XNEXTMAPLEN_SIZE 1
  154. #define XNEXTMAP_OFFSET 1944
  155. #define XNEXTMAP_SIZE 16
  156. #else
  157. // players * 32
  158. /*
  159. #  Player (1536 Bytes)
  160.     * Names (32*25 Bytes; first Byte (unsigned char) indicates length of the nick)
  161.     * Teams (32*1 Byte; 0=DM Team, 1..4=Alpha..Delta, 5=Spectator)
  162.     * Kills (32*2 Bytes; unsigned short)
  163.     * Caps (32*1 Byte; unsigned char)
  164.     * Deaths (32*2 Bytes; unsigned short)
  165.     * Pings (32*4 Bytes; signed long)
  166.     * IDs (32*1 Byte; unsigned char)
  167.     * IPs (32*4 Bytes; each byte can be decoded as unsigned char then put together in the given order to a 0.0.0.0 format; or unpack as unsigned long (big endian) and use long2ip())
  168.     * X Locations (32*4 Bytes; float)
  169.     * Y Locations (32*4 Bytes; float)                  
  170. */
  171. #define XNAMELEN_OFFSET 0
  172. #define XNAMELEN_SIZE 1
  173. #define XNAME_OFFSET 1
  174. #define XNAME_SIZE 24
  175. #define XTEAM_OFFSET 25*32
  176. #define XTEAM_SIZE 1
  177. #define XKILLS_OFFSET 26*32
  178. #define XKILLS_SIZE 2
  179. #define XCAPS_OFFSET 28*32
  180. #define XCAPS_SIZE 1
  181. #define XDEATHS_OFFSET 29*32
  182. #define XDEATHS_SIZE 2
  183. #define XPINGS_OFFSET 31*32
  184. #define XPINGS_SIZE 4
  185. #define XID_OFFSET 35*32
  186. #define XID_SIZE 1
  187. #define XIP_OFFSET 36*32
  188. #define XIP_SIZE 4
  189. #define XLOCX_OFFSET 40*32
  190. #define XLOCX_SIZE 4
  191. #define XLOCY_OFFSET 44*32
  192. #define XLOCY_SIZE 4
  193. // Rest
  194. /*
  195. # Red Flag X Location (4 Bytes; float)
  196. # Red Flag Y Location (4 Bytes; float)
  197. # Blue Flag X Location (4 Bytes; float)
  198. # Blue Flag Y Location (4 Bytes; float)
  199. # Team Scores (4*2 Bytes; unsigned short)
  200. # Map Name (17 Bytes; first Byte (unsigned char) indicates length)
  201. # Time Limit (4 Bytes; unsigned long; in Ticks)
  202. # Time Left (4 Bytes; unsigned long; in Ticks)
  203. # Cap/Kill Limit (2 Bytes; unsigned short)
  204. # Gamestyle (1 Byte; unsigned char; 0=DM, 1=PM, 2=TM, 3=CTF, 4=RM, 5=INF, 6=HTF)
  205. # Max Players (1 Byte; unsigned char)
  206. # Max Spectators (1 Byte; unsigned char)
  207. # Game Passworded? (1 Byte; boolean)
  208. # Next Map (17 Bytes; first Byte (unsigned char) indicates length)
  209. */
  210. #define XREDFLAGX_OFFSET 1536
  211. #define XREDFLAGX_SIZE 4
  212. #define XREDFLAGY_OFFSET 1540
  213. #define XREDFLAGY_SIZE 4
  214. #define XBLUEFLAGX_OFFSET 1544
  215. #define XBLUEFLAGX_SIZE 4
  216. #define XBLUEFLAGY_OFFSET 1548
  217. #define XBLUEFLAGY_SIZE 4
  218. #define XALPHATEAMSCORE_OFFSET 1552
  219. #define XALPHATEAMSCORE_SIZE 2
  220. #define XBRAVOTEAMSCORE_OFFSET 1554
  221. #define XBRAVOTEAMSCORE_SIZE 2
  222. #define XCHARLIETEAMSCORE_OFFSET 1556
  223. #define XCHARLIETEAMSCORE_SIZE 2
  224. #define XDELTATEAMSCORE_OFFSET 1558
  225. #define XDELTATEAMSCORE_SIZE 2
  226. #define XCURRENTMAPLEN_OFFSET 1560
  227. #define XCURRENTMAPLEN_SIZE 1
  228. #define XCURRENTMAP_OFFSET 1561
  229. #define XCURRENTMAP_SIZE 16
  230. #define XTIMELIMIT_OFFSET 1577
  231. #define XTIMELIMIT_SIZE 4
  232. #define XTIMELEFT_OFFSET 1581
  233. #define XTIMELEFT_SIZE 4
  234. #define XLIMIT_OFFSET 1585
  235. #define XLIMIT_SIZE 2
  236. #define XGAMESTYLE_OFFSET 1587
  237. #define XGAMESTYLE_SIZE 1
  238. #define XMAXPLAYERS_OFFSET 1588
  239. #define XMAXPLAYERS_SIZE 1
  240. #define XMAXSPECTATORS_OFFSET 1589
  241. #define XMAXSPECTATORS_SIZE 1
  242. #define XPASSWORD_OFFSET 1590
  243. #define XPASSWORD_SIZE 1
  244. #define XNEXTMAPLEN_OFFSET 1591
  245. #define XNEXTMAPLEN_SIZE 1
  246. #define XNEXTMAP_OFFSET 1592
  247. #define XNEXTMAP_SIZE 16
  248.  
  249. #endif
  250. class SoldatInfoX
  251. {
  252.     public:
  253.     struct refreshX packet;
  254.     SoldatInfoX(void)
  255.     {
  256.         memset(&packet, '\0', sizeof(struct refreshX));
  257.    
  258.     }
  259.     SoldatInfoX(char * buffer)
  260.     {
  261.         memset(&packet, '\0', sizeof(struct refreshX));
  262.         int loop=0;
  263.         for(loop=0;loop < 32;loop++)
  264.         {
  265.             // name length
  266.             memcpy(&packet.players[loop].namelen,buffer+(loop*(XNAME_SIZE+XNAMELEN_SIZE)+XNAMELEN_OFFSET), XNAMELEN_SIZE);
  267.             // name
  268.             memcpy(&packet.players[loop].name,buffer+(loop*(XNAME_SIZE+XNAMELEN_SIZE)+XNAME_OFFSET), XNAME_SIZE);
  269. #ifndef OLDSOLDAT          
  270.             // tagid length
  271.             memcpy(&packet.players[loop].tagid,buffer+(loop*XTAGIDLEN_SIZE+XTAGIDLEN_OFFSET), XTAGIDLEN_SIZE);
  272.             // tagid
  273.             memcpy(&packet.players[loop].tagid,buffer+(loop*XTAGID_SIZE+XTAGID_OFFSET), XTAGID_SIZE);
  274. #endif
  275.             // team
  276.             memcpy(&packet.players[loop].team,buffer+(loop*XTEAM_SIZE+XTEAM_OFFSET), XTEAM_SIZE);
  277.             // kills
  278.             memcpy(&packet.players[loop].kills,buffer+(loop*XKILLS_SIZE+XKILLS_OFFSET), XKILLS_SIZE);
  279.             // caps
  280.             memcpy(&packet.players[loop].caps,buffer+(loop*XCAPS_SIZE+XCAPS_OFFSET), XCAPS_SIZE);
  281.             // Deaths
  282.             memcpy(&packet.players[loop].deaths,buffer+(loop*XDEATHS_SIZE+XDEATHS_OFFSET), XDEATHS_SIZE);
  283.             // ping
  284.             memcpy(&packet.players[loop].ping,buffer+(loop*XPINGS_SIZE+XPINGS_OFFSET), XPINGS_SIZE);
  285.             // id
  286.             memcpy(&packet.players[loop].id,buffer+(loop*XID_SIZE+XID_OFFSET), XID_SIZE);
  287.             // ip
  288.             memcpy(&packet.players[loop].ip,buffer+(loop*XIP_SIZE+XIP_OFFSET), XIP_SIZE);
  289.             // X location
  290.             memcpy(&packet.players[loop].x,buffer+(loop*XLOCX_SIZE+XLOCX_OFFSET), XLOCX_SIZE);
  291.             // y location
  292.             memcpy(&packet.players[loop].y,buffer+(loop*XLOCY_SIZE+XLOCY_OFFSET), XLOCY_SIZE);
  293.         }
  294.         // red flag x
  295.         memcpy(&packet.redflagx,buffer+(XREDFLAGX_OFFSET), XREDFLAGX_SIZE);
  296.         // red flag y
  297.         memcpy(&packet.redflagx,buffer+(XREDFLAGY_OFFSET), XREDFLAGY_SIZE);
  298.         // blue flag x
  299.         memcpy(&packet.blueflagx,buffer+(XBLUEFLAGX_OFFSET), XBLUEFLAGX_SIZE);
  300.         // blue flag y
  301.         memcpy(&packet.blueflagx,buffer+(XBLUEFLAGY_OFFSET), XBLUEFLAGY_SIZE);
  302.         // Alpha team score
  303.         memcpy(&packet.alphascore,buffer+(XALPHATEAMSCORE_OFFSET), XALPHATEAMSCORE_SIZE);
  304.         // Bravo team score
  305.         memcpy(&packet.bravoscore,buffer+(XBRAVOTEAMSCORE_OFFSET), XBRAVOTEAMSCORE_SIZE);
  306.         // Charlie team score
  307.         memcpy(&packet.charliescore,buffer+(XCHARLIETEAMSCORE_OFFSET), XCHARLIETEAMSCORE_SIZE);
  308.         // Delta team score
  309.         memcpy(&packet.deltascore,buffer+(XDELTATEAMSCORE_OFFSET), XDELTATEAMSCORE_SIZE);
  310.         // Current map length
  311.         memcpy(&packet.currentmaplen,buffer+(XCURRENTMAPLEN_OFFSET), XCURRENTMAPLEN_SIZE);
  312.         // Current map
  313.         memcpy(&packet.currentmap,buffer+(XCURRENTMAP_OFFSET), XCURRENTMAP_SIZE);
  314.         // Time limit
  315.         memcpy(&packet.timelimit,buffer+(XTIMELIMIT_OFFSET), XTIMELIMIT_SIZE);
  316.         // Time left
  317.         memcpy(&packet.timeleft,buffer+(XTIMELEFT_OFFSET), XTIMELEFT_SIZE);
  318.         // Cap/kill limit
  319.         memcpy(&packet.limit,buffer+(XLIMIT_OFFSET), XLIMIT_SIZE);
  320.         // Game style
  321.         memcpy(&packet.gamestyle,buffer+(XGAMESTYLE_OFFSET), XGAMESTYLE_SIZE);
  322.         // Max Players
  323.         memcpy(&packet.maxplayers,buffer+(XMAXPLAYERS_OFFSET), XMAXPLAYERS_SIZE);
  324.         // Max Spectators
  325.         memcpy(&packet.maxspectators,buffer+(XMAXSPECTATORS_OFFSET), XMAXSPECTATORS_SIZE);     
  326.         // Password ?
  327.         memcpy(&packet.password,buffer+(XPASSWORD_OFFSET), XPASSWORD_SIZE);
  328.         // Next map length
  329.         memcpy(&packet.nextmaplen,buffer+(XNEXTMAPLEN_OFFSET), XNEXTMAPLEN_SIZE);
  330.         // Next map
  331.         memcpy(&packet.nextmap,buffer+(XNEXTMAP_OFFSET), XNEXTMAP_SIZE);
  332.    
  333.    
  334.     }    
  335. };
  336.  
  337. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement