Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Network.h 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*!
  2. * \file include/Network.h
  3. * \brief Networking Singleton class
  4. *
  5. * \author Mongoose
  6. */
  7. #ifndef _NETWORK_H_
  8. #define _NETWORK_H_
  9. /*!
  10. * \brief The packet holds the data for the network.
  11. *
  12. * This is encapsulated in the frame.
  13. */
  14. typedef struct network_packet_s {
  15. char send;
  16. unsigned int port;
  17. unsigned int cid;
  18. char data[32]; //!< A short (32 char) string
  19. float pos[3];
  20. float pitch;
  21. float yaw;
  22. int aframe;
  23. int bframe;
  24. int view_model;
  25. char gurantee; //!< TCP like
  26. } network_packet_t;
  27. /*!
  28. * \brief The frame holds the data for the datalink layer.
  29. *
  30. * This goes over the line.
  31. */
  32. typedef struct network_frame_s {
  33. unsigned int header; //!< The header flags
  34. unsigned int seq; //!< The sequence number
  35. unsigned int uid;
  36. network_packet_t data; //!< The packet for the NL
  37. } network_frame_t;
  38. void from_network_layer(network_packet_t *p, unsigned int *last_id);
  39. void to_network_layer(network_packet_t p);
  40. void killNetworkSingleton();
  41. #define REMOTE_HOST_STR_SZ 64
  42. #define BIND_HOST_STR_SZ 64
  43. /*!
  44. * \brief Networking Singleton class
  45. */
  46. class Network {
  47. public:
  48. /*!
  49. * \brief Get the Singleton or create it on first use
  50. * \returns Singleton of type Network
  51. */
  52. static Network *Instance();
  53. /*!
  54. * \brief Deconstructs an object of Network
  55. */
  56. ~Network();
  57. network_frame_t &getPiggyBack();
  58. unsigned int getUID();
  59. int getPort();
  60. void setDebug(bool toggle);
  61. void setPort(unsigned int port);
  62. void setBindHost(char *s);
  63. void setRemoteHost(char *s);
  64. void killServerThread();
  65. void killClientThread();
  66. void spawnServerThread();
  67. void spawnClientThread();
  68. int runServer();
  69. void runClient();
  70. protected:
  71. /*!
  72. * \brief Constructs an object of Network
  73. */
  74. Network();
  75. private:
  76. static Network *mInstance; //!< Singleton use
  77. bool mSpawnedClient;
  78. bool mSpawnedServer;
  79. int mPort;
  80. char mRemoteHost[REMOTE_HOST_STR_SZ];
  81. char mBindHost[BIND_HOST_STR_SZ];
  82. bool mPiggyBack;
  83. bool mNetworkReliable;
  84. bool mKillClient;
  85. bool mKillServer;
  86. bool mDebug;
  87. };
  88. #endif