Open Source Tomb Raider Engine
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Network.h 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
  2. /*================================================================
  3. *
  4. * Project : UnRaider
  5. * Author : Terry 'Mongoose' Hendrix II
  6. * Website : http://www.westga.edu/~stu7440/
  7. * Email : stu7440@westga.edu
  8. * Object : Network
  9. * License : No use w/o permission (C) 2002 Mongoose
  10. * Comments:
  11. *
  12. *
  13. * This file was generated using Mongoose's C++
  14. * template generator script. <stu7440@westga.edu>
  15. *
  16. *-- History ------------------------------------------------
  17. *
  18. * 2002.06.21:
  19. * Mongoose - Created
  20. ================================================================*/
  21. #ifndef __UNRAIDER_MONGOOSE_NETWORK_H_
  22. #define __UNRAIDER_MONGOOSE_NETWORK_H_
  23. /*----------------------------------------------
  24. * The packet holds the data for the network
  25. * layer. This is encapsulated in the frame.
  26. *
  27. * data - a short (32 char) string
  28. ---------------------------------------------*/
  29. typedef struct network_packet_s
  30. {
  31. char send;
  32. unsigned int port;
  33. unsigned int cid;
  34. char data[32];
  35. float pos[3];
  36. float pitch;
  37. float yaw;
  38. int aframe;
  39. int bframe;
  40. int view_model;
  41. char gurantee; // TCP like
  42. } network_packet_t;
  43. /*----------------------------------------------
  44. * The frame holds the data for the datalink
  45. * layer. This goes over the line.
  46. *
  47. * header - The header flags
  48. * seq - The sequence number
  49. * data - The packet for the NL
  50. ---------------------------------------------*/
  51. typedef struct network_frame_s
  52. {
  53. unsigned int header;
  54. unsigned int seq;
  55. unsigned int uid;
  56. network_packet_t data;
  57. } network_frame_t;
  58. void from_network_layer(network_packet_t *p, unsigned int *last_id);
  59. void to_network_layer(network_packet_t p);
  60. void killNetworkSingleton();
  61. #define REMOTE_HOST_STR_SZ 64
  62. #define BIND_HOST_STR_SZ 64
  63. class Network
  64. {
  65. public:
  66. ////////////////////////////////////////////////////////////
  67. // Constructors ( Singleton )
  68. ////////////////////////////////////////////////////////////
  69. static Network *Instance();
  70. /*------------------------------------------------------
  71. * Pre :
  72. * Post : Constructs the object of Network or
  73. * returns pointer to it if previously allocated
  74. *
  75. *-- History ------------------------------------------
  76. *
  77. * 2001.08.24:
  78. * Mongoose - Created
  79. ------------------------------------------------------*/
  80. ~Network();
  81. /*------------------------------------------------------
  82. * Pre : Network object is allocated
  83. * Post : Deconstructs an object of Network
  84. *
  85. *-- History ------------------------------------------
  86. *
  87. * 2002.06.21:
  88. * Mongoose - Created
  89. ------------------------------------------------------*/
  90. ////////////////////////////////////////////////////////////
  91. // Public Accessors
  92. ////////////////////////////////////////////////////////////
  93. network_frame_t &getPiggyBack();
  94. /*------------------------------------------------------
  95. * Pre :
  96. * Post :
  97. *
  98. *-- History ------------------------------------------
  99. *
  100. * 2002.09.03:
  101. * Mongoose - Created
  102. ------------------------------------------------------*/
  103. unsigned int getUID();
  104. /*------------------------------------------------------
  105. * Pre :
  106. * Post :
  107. *
  108. *-- History ------------------------------------------
  109. *
  110. * 2002.09.03:
  111. * Mongoose - Created
  112. ------------------------------------------------------*/
  113. float getRandom(float from, float to);
  114. /*------------------------------------------------------
  115. * Pre :
  116. * Post :
  117. *
  118. *-- History ------------------------------------------
  119. *
  120. * 2002.09.03:
  121. * Mongoose - Created
  122. ------------------------------------------------------*/
  123. int getPort();
  124. /*------------------------------------------------------
  125. * Pre :
  126. * Post :
  127. *
  128. *-- History ------------------------------------------
  129. *
  130. * 2002.09.03:
  131. * Mongoose - Created
  132. ------------------------------------------------------*/
  133. ////////////////////////////////////////////////////////////
  134. // Public Mutators
  135. ////////////////////////////////////////////////////////////
  136. void setDebug(bool toggle);
  137. /*------------------------------------------------------
  138. * Pre :
  139. * Post :
  140. *
  141. *-- History ------------------------------------------
  142. *
  143. * 2002.12.15:
  144. * Mongoose - Created
  145. ------------------------------------------------------*/
  146. void setPort(unsigned int port);
  147. /*------------------------------------------------------
  148. * Pre :
  149. * Post :
  150. *
  151. *-- History ------------------------------------------
  152. *
  153. * 2002.09.03:
  154. * Mongoose - Created
  155. ------------------------------------------------------*/
  156. void setBindHost(char *s);
  157. /*------------------------------------------------------
  158. * Pre :
  159. * Post :
  160. *
  161. *-- History ------------------------------------------
  162. *
  163. * 2002.09.10:
  164. * Mongoose - Created
  165. ------------------------------------------------------*/
  166. void setRemoteHost(char *s);
  167. /*------------------------------------------------------
  168. * Pre :
  169. * Post :
  170. *
  171. *-- History ------------------------------------------
  172. *
  173. * 2002.09.03:
  174. * Mongoose - Created
  175. ------------------------------------------------------*/
  176. void killServerThread();
  177. /*------------------------------------------------------
  178. * Pre :
  179. * Post :
  180. *
  181. *-- History ------------------------------------------
  182. *
  183. * 2002.09.03:
  184. * Mongoose - Created
  185. ------------------------------------------------------*/
  186. void killClientThread();
  187. /*------------------------------------------------------
  188. * Pre :
  189. * Post :
  190. *
  191. *-- History ------------------------------------------
  192. *
  193. * 2002.09.03:
  194. * Mongoose - Created
  195. ------------------------------------------------------*/
  196. void spawnServerThread();
  197. /*------------------------------------------------------
  198. * Pre :
  199. * Post :
  200. *
  201. *-- History ------------------------------------------
  202. *
  203. * 2002.09.03:
  204. * Mongoose - Created
  205. ------------------------------------------------------*/
  206. void spawnClientThread();
  207. /*------------------------------------------------------
  208. * Pre :
  209. * Post :
  210. *
  211. *-- History ------------------------------------------
  212. *
  213. * 2002.09.03:
  214. * Mongoose - Created
  215. ------------------------------------------------------*/
  216. int runServer();
  217. /*------------------------------------------------------
  218. * Pre :
  219. * Post :
  220. *
  221. *-- History ------------------------------------------
  222. *
  223. * 2002.09.03:
  224. * Mongoose - Created
  225. ------------------------------------------------------*/
  226. void runClient();
  227. /*------------------------------------------------------
  228. * Pre :
  229. * Post :
  230. *
  231. *-- History ------------------------------------------
  232. *
  233. * 2002.09.03:
  234. * Mongoose - Created
  235. ------------------------------------------------------*/
  236. protected:
  237. ////////////////////////////////////////////////////////////
  238. // Constructors ( Singleton )
  239. ////////////////////////////////////////////////////////////
  240. Network();
  241. /*------------------------------------------------------
  242. * Pre :
  243. * Post : Constructs an object of Network
  244. *
  245. *-- History ------------------------------------------
  246. *
  247. * 2002.06.21:
  248. * Mongoose - Created
  249. ------------------------------------------------------*/
  250. ////////////////////////////////////////////////////////////
  251. // Protected Mutators
  252. ////////////////////////////////////////////////////////////
  253. private:
  254. ////////////////////////////////////////////////////////////
  255. // Private Accessors
  256. ////////////////////////////////////////////////////////////
  257. ////////////////////////////////////////////////////////////
  258. // Private Mutators
  259. ////////////////////////////////////////////////////////////
  260. static Network *mInstance; /* Singleton use */
  261. bool mSpawnedClient;
  262. bool mSpawnedServer;
  263. int mPort;
  264. char mRemoteHost[REMOTE_HOST_STR_SZ];
  265. char mBindHost[BIND_HOST_STR_SZ];
  266. bool mPiggyBack;
  267. bool mNetworkReliable;
  268. bool mKillClient;
  269. bool mKillServer;
  270. bool mDebug;
  271. };
  272. #endif