| [1502] | 1 | /* |
|---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
|---|
| 3 | * > www.orxonox.net < |
|---|
| 4 | * |
|---|
| 5 | * |
|---|
| 6 | * License notice: |
|---|
| 7 | * |
|---|
| 8 | * This program is free software; you can redistribute it and/or |
|---|
| 9 | * modify it under the terms of the GNU General Public License |
|---|
| 10 | * as published by the Free Software Foundation; either version 2 |
|---|
| 11 | * of the License, or (at your option) any later version. |
|---|
| 12 | * |
|---|
| 13 | * This program is distributed in the hope that it will be useful, |
|---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | * GNU General Public License for more details. |
|---|
| 17 | * |
|---|
| 18 | * You should have received a copy of the GNU General Public License |
|---|
| 19 | * along with this program; if not, write to the Free Software |
|---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|---|
| 21 | * |
|---|
| 22 | * Author: |
|---|
| 23 | * Oliver Scheuss, (C) 2007 |
|---|
| 24 | * Co-authors: |
|---|
| 25 | * ... |
|---|
| 26 | * |
|---|
| 27 | */ |
|---|
| 28 | |
|---|
| 29 | // |
|---|
| 30 | // C++ Interface: ConnectionManager |
|---|
| 31 | // |
|---|
| 32 | // Description: |
|---|
| 33 | // |
|---|
| 34 | // |
|---|
| 35 | // Author: Oliver Scheuss, (C) 2007 |
|---|
| 36 | // |
|---|
| 37 | // Copyright: See COPYING file that comes with this distribution |
|---|
| 38 | // |
|---|
| 39 | // |
|---|
| 40 | #ifndef _ConnectionManager_H__ |
|---|
| 41 | #define _ConnectionManager_H__ |
|---|
| 42 | |
|---|
| 43 | #include "NetworkPrereqs.h" |
|---|
| 44 | |
|---|
| 45 | #include <string> |
|---|
| 46 | #include <map> |
|---|
| 47 | // enet library for networking support |
|---|
| 48 | #include <enet/enet.h> |
|---|
| 49 | #include <boost/thread/recursive_mutex.hpp> |
|---|
| 50 | |
|---|
| 51 | #include "PacketBuffer.h" |
|---|
| [1735] | 52 | #include "packet/Packet.h" |
|---|
| [1502] | 53 | |
|---|
| [1755] | 54 | namespace boost { class thread; } |
|---|
| 55 | |
|---|
| [1502] | 56 | namespace std |
|---|
| 57 | { |
|---|
| 58 | bool operator<(ENetAddress a, ENetAddress b); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| [2171] | 61 | namespace orxonox |
|---|
| [1502] | 62 | { |
|---|
| [1785] | 63 | const int NETWORK_PORT = 55556; |
|---|
| 64 | const int NETWORK_MAX_CONNECTIONS = 50; |
|---|
| 65 | const int NETWORK_WAIT_TIMEOUT = 1; |
|---|
| 66 | const int NETWORK_DEFAULT_CHANNEL = 0; |
|---|
| [1502] | 67 | |
|---|
| [2087] | 68 | struct _NetworkExport ClientList{ |
|---|
| [1502] | 69 | ENetEvent *event; |
|---|
| 70 | int ID; |
|---|
| 71 | ClientList *next; |
|---|
| 72 | }; |
|---|
| 73 | |
|---|
| [2087] | 74 | class _NetworkExport ConnectionManager{ |
|---|
| [1735] | 75 | public: |
|---|
| 76 | static boost::recursive_mutex enet_mutex; |
|---|
| [1502] | 77 | ConnectionManager(); |
|---|
| [1735] | 78 | //ConnectionManager(ClientInformation *head); |
|---|
| 79 | ConnectionManager(int port); |
|---|
| 80 | ConnectionManager(int port, const char *address); |
|---|
| [2087] | 81 | ConnectionManager(int port, const std::string& address); |
|---|
| [1735] | 82 | ~ConnectionManager(); |
|---|
| [1502] | 83 | //ENetPacket *getPacket(ENetAddress &address); // thread1 |
|---|
| 84 | //ENetPacket *getPacket(int &clientID); |
|---|
| 85 | ENetEvent *getEvent(); |
|---|
| 86 | bool queueEmpty(); |
|---|
| 87 | void createListener(); |
|---|
| 88 | bool quitListener(); |
|---|
| [1735] | 89 | // bool addPacket(Packet::Packet *packet); |
|---|
| 90 | static bool addPacket(ENetPacket *packet, ENetPeer *peer); |
|---|
| 91 | static bool addPacket(ENetPacket *packet, int ID); |
|---|
| 92 | static bool addPacketAll(ENetPacket *packet); |
|---|
| [1502] | 93 | // bool sendPackets(ENetEvent *event); |
|---|
| 94 | bool sendPackets(); |
|---|
| 95 | //bool createClient(int clientID); |
|---|
| 96 | void disconnectClient(ClientInformation *client); |
|---|
| [1735] | 97 | void syncClassid(unsigned int clientID); |
|---|
| [1502] | 98 | |
|---|
| 99 | private: |
|---|
| 100 | // bool clientDisconnect(ENetPeer *peer); |
|---|
| 101 | // bool removeClient(int clientID); |
|---|
| 102 | bool processData(ENetEvent *event); |
|---|
| 103 | //bool addClient(ENetEvent *event); |
|---|
| 104 | void receiverThread(); |
|---|
| 105 | void disconnectClients(); |
|---|
| 106 | int getClientID(ENetPeer peer); |
|---|
| 107 | int getClientID(ENetAddress address); |
|---|
| 108 | ENetPeer *getClientPeer(int clientID); |
|---|
| 109 | PacketBuffer buffer; |
|---|
| 110 | |
|---|
| 111 | ENetHost *server; |
|---|
| 112 | ENetAddress bindAddress; |
|---|
| 113 | |
|---|
| 114 | bool quit; // quit-variable (communication with threads) |
|---|
| 115 | |
|---|
| 116 | boost::thread *receiverThread_; |
|---|
| [1735] | 117 | static ConnectionManager *instance_; |
|---|
| 118 | |
|---|
| [1502] | 119 | }; |
|---|
| 120 | |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | #endif /* _ConnectionManager_H__ */ |
|---|