Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/network/ConnectionManager.h @ 474

Last change on this file since 474 was 436, checked in by scheusso, 17 years ago

extended gamestatehandling for diffed and not diffed gamestates (initial states, etc)

File size: 2.2 KB
Line 
1//
2// C++ Interface: ConnectionManager
3//
4// Description:
5//
6//
7// Author:  Oliver Scheuss, (C) 2007
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#ifndef NETWORK_CONNECTIONMANAGER_H
13#define NETWORK_CONNECTIONMANAGER_H
14
15#include <iostream>
16#include <string>
17#include <map>
18#include <vector>
19// enet library for networking support
20#include <enet/enet.h>
21// boost.thread library for multithreading support
22#include <boost/thread/thread.hpp>
23#include <boost/bind.hpp>
24// headerfiles
25#include "ClientInformation.h"
26#include "ConnectionManager.h"
27#include "PacketBuffer.h"
28#include "PacketManager.h"
29#include "orxonox/core/IdentifierIncludes.h"
30
31namespace std{
32  bool operator<(ENetAddress a, ENetAddress b);
33}
34
35namespace network{
36  //
37#define NETWORK_PORT 55556
38#define NETWORK_MAX_CONNECTIONS 50
39#define NETWORK_WAIT_TIMEOUT 5000
40#define NETWORK_SEND_WAIT 5
41
42  struct ClientList{
43    ENetEvent *event;
44    int ID;
45    ClientList *next;
46  };
47 
48  class ConnectionManager{
49    public:
50    ConnectionManager(ClientInformation *head);
51    ConnectionManager(int port, const char *address, ClientInformation *head);
52    ConnectionManager(int port, std::string address, ClientInformation *head);
53    ENetPacket *getPacket(ENetAddress &address); // thread1
54    ENetPacket *getPacket(int &clientID);
55    bool queueEmpty();
56    void createListener();
57    bool quitListener();
58    bool addPacket(ENetPacket *packet, ENetPeer *peer);
59    bool addPacket(ENetPacket *packet, int ID);
60    bool addPacketAll(ENetPacket *packet);
61    bool sendPackets(ENetEvent *event);
62    bool sendPackets();
63  private:
64    bool clientDisconnect(ENetPeer *peer);
65    //bool clientDisconnect(ENetPeer peer);
66    bool processData(ENetEvent *event);
67    bool addClient(ENetEvent *event);
68    void receiverThread();
69    void disconnectClients();
70    int getClientID(ENetPeer peer);
71    int getClientID(ENetAddress address);
72    void syncClassid(int clientID);
73    ENetPeer *getClientPeer(int clientID);
74    PacketBuffer buffer;
75    PacketGenerator packet_gen;
76   
77    ENetHost *server;
78    ENetAddress bindAddress;
79   
80    bool quit; // quit-variable (communication with threads)
81    ClientInformation *head_;
82  };
83
84
85
86
87
88
89
90
91}
92
93#endif
Note: See TracBrowser for help on using the repository browser.