123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
- /*================================================================
- *
- * Project : UnRaider
- * Author : Terry 'Mongoose' Hendrix II
- * Website : http://www.westga.edu/~stu7440/
- * Email : stu7440@westga.edu
- * Object : Network
- * License : No use w/o permission (C) 2002 Mongoose
- * Comments:
- *
- *
- * This file was generated using Mongoose's C++
- * template generator script. <stu7440@westga.edu>
- *
- *-- History ------------------------------------------------
- *
- * 2002.06.21:
- * Mongoose - Created
- ================================================================*/
-
-
- #ifndef _NETWORK_H_
- #define _NETWORK_H_
-
- /*----------------------------------------------
- * The packet holds the data for the network
- * layer. This is encapsulated in the frame.
- *
- * data - a short (32 char) string
- ---------------------------------------------*/
- typedef struct network_packet_s
- {
- char send;
- unsigned int port;
- unsigned int cid;
- char data[32];
- float pos[3];
- float pitch;
- float yaw;
- int aframe;
- int bframe;
- int view_model;
-
- char gurantee; // TCP like
-
- } network_packet_t;
-
-
- /*----------------------------------------------
- * The frame holds the data for the datalink
- * layer. This goes over the line.
- *
- * header - The header flags
- * seq - The sequence number
- * data - The packet for the NL
- ---------------------------------------------*/
- typedef struct network_frame_s
- {
- unsigned int header;
- unsigned int seq;
- unsigned int uid;
-
- network_packet_t data;
-
- } network_frame_t;
-
-
- void from_network_layer(network_packet_t *p, unsigned int *last_id);
- void to_network_layer(network_packet_t p);
-
-
- void killNetworkSingleton();
-
- #define REMOTE_HOST_STR_SZ 64
- #define BIND_HOST_STR_SZ 64
-
-
- class Network
- {
- public:
-
- ////////////////////////////////////////////////////////////
- // Constructors ( Singleton )
- ////////////////////////////////////////////////////////////
-
- static Network *Instance();
- /*------------------------------------------------------
- * Pre :
- * Post : Constructs the object of Network or
- * returns pointer to it if previously allocated
- *
- *-- History ------------------------------------------
- *
- * 2001.08.24:
- * Mongoose - Created
- ------------------------------------------------------*/
-
- ~Network();
- /*------------------------------------------------------
- * Pre : Network object is allocated
- * Post : Deconstructs an object of Network
- *
- *-- History ------------------------------------------
- *
- * 2002.06.21:
- * Mongoose - Created
- ------------------------------------------------------*/
-
- ////////////////////////////////////////////////////////////
- // Public Accessors
- ////////////////////////////////////////////////////////////
-
- network_frame_t &getPiggyBack();
- /*------------------------------------------------------
- * Pre :
- * Post :
- *
- *-- History ------------------------------------------
- *
- * 2002.09.03:
- * Mongoose - Created
- ------------------------------------------------------*/
-
- unsigned int getUID();
- /*------------------------------------------------------
- * Pre :
- * Post :
- *
- *-- History ------------------------------------------
- *
- * 2002.09.03:
- * Mongoose - Created
- ------------------------------------------------------*/
-
- float getRandom(float from, float to);
- /*------------------------------------------------------
- * Pre :
- * Post :
- *
- *-- History ------------------------------------------
- *
- * 2002.09.03:
- * Mongoose - Created
- ------------------------------------------------------*/
-
- int getPort();
- /*------------------------------------------------------
- * Pre :
- * Post :
- *
- *-- History ------------------------------------------
- *
- * 2002.09.03:
- * Mongoose - Created
- ------------------------------------------------------*/
-
- ////////////////////////////////////////////////////////////
- // Public Mutators
- ////////////////////////////////////////////////////////////
-
- void setDebug(bool toggle);
- /*------------------------------------------------------
- * Pre :
- * Post :
- *
- *-- History ------------------------------------------
- *
- * 2002.12.15:
- * Mongoose - Created
- ------------------------------------------------------*/
-
- void setPort(unsigned int port);
- /*------------------------------------------------------
- * Pre :
- * Post :
- *
- *-- History ------------------------------------------
- *
- * 2002.09.03:
- * Mongoose - Created
- ------------------------------------------------------*/
-
- void setBindHost(char *s);
- /*------------------------------------------------------
- * Pre :
- * Post :
- *
- *-- History ------------------------------------------
- *
- * 2002.09.10:
- * Mongoose - Created
- ------------------------------------------------------*/
-
- void setRemoteHost(char *s);
- /*------------------------------------------------------
- * Pre :
- * Post :
- *
- *-- History ------------------------------------------
- *
- * 2002.09.03:
- * Mongoose - Created
- ------------------------------------------------------*/
-
- void killServerThread();
- /*------------------------------------------------------
- * Pre :
- * Post :
- *
- *-- History ------------------------------------------
- *
- * 2002.09.03:
- * Mongoose - Created
- ------------------------------------------------------*/
-
- void killClientThread();
- /*------------------------------------------------------
- * Pre :
- * Post :
- *
- *-- History ------------------------------------------
- *
- * 2002.09.03:
- * Mongoose - Created
- ------------------------------------------------------*/
-
- void spawnServerThread();
- /*------------------------------------------------------
- * Pre :
- * Post :
- *
- *-- History ------------------------------------------
- *
- * 2002.09.03:
- * Mongoose - Created
- ------------------------------------------------------*/
-
- void spawnClientThread();
- /*------------------------------------------------------
- * Pre :
- * Post :
- *
- *-- History ------------------------------------------
- *
- * 2002.09.03:
- * Mongoose - Created
- ------------------------------------------------------*/
-
- int runServer();
- /*------------------------------------------------------
- * Pre :
- * Post :
- *
- *-- History ------------------------------------------
- *
- * 2002.09.03:
- * Mongoose - Created
- ------------------------------------------------------*/
-
- void runClient();
- /*------------------------------------------------------
- * Pre :
- * Post :
- *
- *-- History ------------------------------------------
- *
- * 2002.09.03:
- * Mongoose - Created
- ------------------------------------------------------*/
-
- protected:
-
- ////////////////////////////////////////////////////////////
- // Constructors ( Singleton )
- ////////////////////////////////////////////////////////////
-
- Network();
- /*------------------------------------------------------
- * Pre :
- * Post : Constructs an object of Network
- *
- *-- History ------------------------------------------
- *
- * 2002.06.21:
- * Mongoose - Created
- ------------------------------------------------------*/
-
-
- ////////////////////////////////////////////////////////////
- // Protected Mutators
- ////////////////////////////////////////////////////////////
-
- private:
-
- ////////////////////////////////////////////////////////////
- // Private Accessors
- ////////////////////////////////////////////////////////////
-
-
- ////////////////////////////////////////////////////////////
- // Private Mutators
- ////////////////////////////////////////////////////////////
-
-
- static Network *mInstance; /* Singleton use */
-
- bool mSpawnedClient;
-
- bool mSpawnedServer;
-
- int mPort;
-
- char mRemoteHost[REMOTE_HOST_STR_SZ];
-
- char mBindHost[BIND_HOST_STR_SZ];
-
- bool mPiggyBack;
-
- bool mNetworkReliable;
-
- bool mKillClient;
-
- bool mKillServer;
-
- bool mDebug;
- };
-
- #endif
|