[1168] | 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 | |
---|
[1232] | 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 | |
---|
| 50 | #include "PacketBuffer.h" |
---|
| 51 | #include "PacketManager.h" |
---|
| 52 | |
---|
| 53 | namespace std |
---|
| 54 | { |
---|
| 55 | bool operator<(ENetAddress a, ENetAddress b); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | namespace network |
---|
| 59 | { |
---|
| 60 | #define NETWORK_PORT 55556 |
---|
| 61 | #define NETWORK_MAX_CONNECTIONS 50 |
---|
| 62 | #define NETWORK_WAIT_TIMEOUT 5000 |
---|
| 63 | #define NETWORK_SEND_WAIT 5 |
---|
| 64 | |
---|
| 65 | struct ClientList{ |
---|
| 66 | ENetEvent *event; |
---|
| 67 | int ID; |
---|
| 68 | ClientList *next; |
---|
| 69 | }; |
---|
| 70 | |
---|
| 71 | class ConnectionManager{ |
---|
| 72 | public: |
---|
| 73 | ConnectionManager(); |
---|
| 74 | ConnectionManager(ClientInformation *head); |
---|
| 75 | ConnectionManager(int port, const char *address, ClientInformation *head); |
---|
| 76 | ConnectionManager(int port, std::string address, ClientInformation *head); |
---|
| 77 | ENetPacket *getPacket(ENetAddress &address); // thread1 |
---|
| 78 | ENetPacket *getPacket(int &clientID); |
---|
| 79 | bool queueEmpty(); |
---|
| 80 | void createListener(); |
---|
| 81 | bool quitListener(); |
---|
| 82 | bool addPacket(ENetPacket *packet, ENetPeer *peer); |
---|
| 83 | bool addPacket(ENetPacket *packet, int ID); |
---|
| 84 | bool addPacketAll(ENetPacket *packet); |
---|
| 85 | bool sendPackets(ENetEvent *event); |
---|
| 86 | bool sendPackets(); |
---|
| 87 | bool createClient(int clientID); |
---|
[1261] | 88 | void disconnectClient(ClientInformation *client); |
---|
[1232] | 89 | |
---|
| 90 | private: |
---|
| 91 | bool clientDisconnect(ENetPeer *peer); |
---|
[1245] | 92 | bool removeClient(int clientID); |
---|
[1232] | 93 | bool processData(ENetEvent *event); |
---|
| 94 | bool addClient(ENetEvent *event); |
---|
| 95 | void receiverThread(); |
---|
| 96 | void disconnectClients(); |
---|
| 97 | int getClientID(ENetPeer peer); |
---|
| 98 | int getClientID(ENetAddress address); |
---|
| 99 | void syncClassid(int clientID); |
---|
| 100 | ENetPeer *getClientPeer(int clientID); |
---|
| 101 | bool createShip(ClientInformation *client); |
---|
[1261] | 102 | bool removeShip(ClientInformation *client); |
---|
[1232] | 103 | bool sendWelcome(int clientID, int shipID, bool allowed); |
---|
| 104 | bool addFakeConnectRequest(ENetEvent *ev); |
---|
| 105 | PacketBuffer buffer; |
---|
| 106 | PacketGenerator packet_gen; |
---|
| 107 | |
---|
| 108 | ENetHost *server; |
---|
| 109 | ENetAddress bindAddress; |
---|
| 110 | |
---|
| 111 | bool quit; // quit-variable (communication with threads) |
---|
| 112 | ClientInformation *head_; |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | // int getNumberOfClients(); |
---|
| 116 | //functions to map what object every clients uses |
---|
| 117 | /*std::map<int, int> clientsShip; |
---|
| 118 | void addClientsObjectID( int clientID, int objectID ); |
---|
| 119 | int getClientsShipID( int clientID ); |
---|
| 120 | int getObjectsClientID( int objectID ); |
---|
| 121 | void deleteClientIDReg( int clientID ); |
---|
| 122 | void deleteObjectIDReg( int objectID );*/ |
---|
| 123 | }; |
---|
| 124 | |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | #endif /* _ConnectionManager_H__ */ |
---|