[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: ClientConnection |
---|
| 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 _ClientConnection_H__ |
---|
| 41 | #define _ClientConnection_H__ |
---|
| 42 | |
---|
| 43 | #include "NetworkPrereqs.h" |
---|
| 44 | |
---|
| 45 | #include <string> |
---|
[2756] | 46 | #ifndef WIN32_LEAN_AND_MEAN |
---|
| 47 | # define WIN32_LEAN_AND_MEAN |
---|
| 48 | #endif |
---|
| 49 | #define NOMINMAX // required to stop windows.h screwing up std::min definition |
---|
[1502] | 50 | #include <enet/enet.h> |
---|
[1755] | 51 | #include <boost/thread/recursive_mutex.hpp> |
---|
[1502] | 52 | #include "PacketBuffer.h" |
---|
| 53 | |
---|
[1755] | 54 | namespace boost { class thread; } |
---|
| 55 | |
---|
[2171] | 56 | namespace orxonox |
---|
[1502] | 57 | { |
---|
| 58 | |
---|
[1785] | 59 | const int NETWORK_PORT = 55556; |
---|
| 60 | const int NETWORK_CLIENT_MAX_CONNECTIONS = 5; |
---|
| 61 | const int NETWORK_CLIENT_WAIT_TIME = 1; |
---|
| 62 | const int NETWORK_CLIENT_CONNECT_TIMEOUT = 3000; // miliseconds |
---|
| 63 | const int NETWORK_CLIENT_CHANNELS = 2; |
---|
[1502] | 64 | |
---|
| 65 | |
---|
[2087] | 66 | class _NetworkExport ClientConnection{ |
---|
[1502] | 67 | public: |
---|
[2087] | 68 | ClientConnection(int port, const std::string& address); |
---|
[1502] | 69 | ClientConnection(int port, const char* address); |
---|
[1907] | 70 | ~ClientConnection(); |
---|
[1502] | 71 | ENetEvent *getEvent(); |
---|
| 72 | // check wheter the packet queue is empty |
---|
| 73 | bool queueEmpty(); |
---|
| 74 | // create a new listener thread |
---|
| 75 | bool createConnection(); |
---|
| 76 | bool closeConnection(); |
---|
| 77 | // add a packet to queue for the server |
---|
| 78 | bool addPacket(ENetPacket *packet); |
---|
| 79 | // send out all queued packets |
---|
| 80 | bool sendPackets(); |
---|
| 81 | // send out all queued packets and save result in event |
---|
| 82 | //bool sendPackets(ENetEvent *event); |
---|
| 83 | bool waitEstablished(int milisec); |
---|
| 84 | bool isConnected(){return established;} |
---|
| 85 | private: |
---|
| 86 | bool processData(ENetEvent *event); |
---|
| 87 | // implementation of the listener |
---|
| 88 | void receiverThread(); //thread2 |
---|
| 89 | //packetbuffer |
---|
| 90 | bool establishConnection(); |
---|
| 91 | bool disconnectConnection(); |
---|
| 92 | PacketBuffer buffer; |
---|
| 93 | // enet stuff |
---|
| 94 | ENetHost *client; |
---|
| 95 | ENetAddress serverAddress; |
---|
| 96 | // quit-variable (communication with threads) |
---|
| 97 | bool quit; |
---|
| 98 | bool established; |
---|
| 99 | // clientlist |
---|
| 100 | ENetPeer *server; |
---|
| 101 | boost::thread *receiverThread_; |
---|
[2087] | 102 | |
---|
[1502] | 103 | static boost::recursive_mutex enet_mutex_; |
---|
| 104 | }; |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | #endif /* _ClientConnection_H__ */ |
---|