Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 401 was 400, checked in by scheusso, 17 years ago

CLient, Server

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