commit 052d5a2ee82d14752ba7a2a89b375de0f4b3214d Author: Chris Peterson <xethm55@yahoo.com> Date: Fri Sep 14 20:49:49 2012 -0400 Damn! - Forgot to add the Types.h file commit 8bb6f6d56279289dd0c1f118dffb390dc6538a7c Author: Chris Peterson <xethm55@yahoo.com> Date: Fri Sep 14 20:41:46 2012 -0400 Fixed a lot of the lag issues. There are still some tweaks needed, but that is going to happen with the input system changes commit 0b5fe2dd64b561d965229a8dff25575eaf5c9264 Author: Chris Peterson <xethm55@yahoo.com> Date: Fri Sep 14 20:21:31 2012 -0400 Client server stuff working. A lot of lag in the system though commit 07fac2c86d3b379fd1ac287bf3f60b778ca59508 Merge: 5cfd5b2 ac79196 Author: Chris Peterson <xethm55@yahoo.com> Date: Fri Sep 14 17:49:18 2012 -0400 Merging in changes from Holtrop commit 5cfd5b28d5e384803ef7b807849ac570e6c84e0f Author: Chris Peterson <xethm55@yahoo.com> Date: Sun Sep 9 12:23:12 2012 -0400 Building on linux now commit 470d486cdebd95099020911dee7f9290c78ee274 Merge: 842040d f072eec Author: Chris Peterson <xethm55@yahoo.com> Date: Sun Sep 9 11:58:39 2012 -0400 Merged in master with tank model commit 842040d0fee481f726b2ae5aec60787371af3923 Merge: 6866c58 9b993f2 Author: Chris Peterson <xethm55@yahoo.com> Date: Thu Aug 30 23:25:19 2012 -0400 Merged in changes from upstream (holtrop/master) commit 6866c58200cc50d3ccc886266303c1b654c89527 Author: Chris Peterson <xethm55@yahoo.com> Date: Sat Aug 18 17:07:50 2012 -0400 added server code and a simple echo server.
97 lines
2.6 KiB
C++
97 lines
2.6 KiB
C++
#ifndef _NETWORK_HPP
|
|
#define _NETWORK_HPP
|
|
|
|
#include <map>
|
|
#include <SFML/Config.hpp>
|
|
#include <SFML/Network.hpp>
|
|
#include <SFML/System/Clock.hpp>
|
|
#include <vector>
|
|
#include <queue>
|
|
|
|
#define MAX_NUM_CLIENTS 8
|
|
#define MAX_NUM_TUBES 4
|
|
|
|
#define UNIQUE_ID 0xDEADBEEF
|
|
#define RECEIVE_BUFFER_SIZE 1024
|
|
|
|
// In milliseconds
|
|
#define NETWORK_TIMEOUT 5000
|
|
|
|
|
|
|
|
// The bit indicating if the message requires a response
|
|
#define MSG_REQUIRES_RESPONSE_BIT ((sf::Uint16)1 << 15)
|
|
|
|
// The bit indicating if the message is a transmission or a response
|
|
#define MSG_TX_BIT ((sf::Uint16)1 << 14)
|
|
|
|
typedef enum{
|
|
NETWORK_NONE,
|
|
NETWORK_CONNECT,
|
|
NETWORK_DISCONNECT,
|
|
NETWORK_ACK,
|
|
NETWORK_PING,
|
|
NETWORK_NORMAL,
|
|
NETWORK_GUARANTEED
|
|
}Network_Messages_T;
|
|
|
|
|
|
typedef struct{
|
|
sf::IpAddress addr;
|
|
unsigned short port;
|
|
double ping;
|
|
std::queue<sf::Packet> receive;
|
|
}Client_t;
|
|
|
|
typedef struct{
|
|
// The packet
|
|
sf::Packet Data;
|
|
|
|
// The type of message that is to be sent.
|
|
Network_Messages_T msg_type;
|
|
|
|
// Destination client for an ACK message
|
|
// Perhaps later I will enable the ability to only send updates
|
|
// to specific clients.
|
|
Client_t * dest;
|
|
|
|
// The time at which the message was origionally sent
|
|
double TimeStarted;
|
|
|
|
// The time at which the message was last sent to each client
|
|
std::map<Client_t*, double> ClientTimeSent;
|
|
|
|
// The time at which a response was received from each client
|
|
std::map<Client_t*, double> Responses;
|
|
} Transmit_Message_t;
|
|
|
|
class Network{
|
|
private:
|
|
static sf::Uint16 numclients;
|
|
static sf::UdpSocket net_socket;
|
|
static std::map<sf::Uint32, Transmit_Message_t*> transmit_queue;
|
|
static char rxbuff[RECEIVE_BUFFER_SIZE];
|
|
static sf::Clock message_timer;
|
|
static sf::Uint32 getUniqueMessageId( void );
|
|
static int addClients(Client_t *client, sf::Uint16 *curcl);
|
|
static int findClient(Client_t *client);
|
|
static bool queueTransmitMessage(Network_Messages_T msg_type , sf::Packet p, Client_t * dest = NULL);
|
|
|
|
public:
|
|
static Client_t clients[MAX_NUM_CLIENTS];
|
|
static void Create( sf::Uint16 port, sf::IpAddress address );
|
|
static void Destroy( void );
|
|
static bool getData(sf::Packet& p);
|
|
static bool sendData(sf::Packet& p, bool guaranteed = false);
|
|
static int getNumConnected( void );
|
|
static void Transmit();
|
|
static void Receive();
|
|
static void Reset();
|
|
};
|
|
|
|
sf::Packet& operator <<(sf::Packet& Packet, const Network_Messages_T& NMT);
|
|
|
|
sf::Packet& operator >>(sf::Packet& Packet, Network_Messages_T& NMT);
|
|
|
|
#endif
|