Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/tutorialFS09/src/network/ClientConnection.h @ 8924

Last change on this file since 8924 was 2756, checked in by rgrieder, 16 years ago

Minimising problems when including windows.h because it defines macros like "min" and "max" if not explicitly specified.
There are two headers we use that include windows.h: OgreWindowEventUtilities.h and enet.h. I had to tweak a little bit there as well.

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
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>
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
50#include <enet/enet.h>
51#include <boost/thread/recursive_mutex.hpp>
52#include "PacketBuffer.h"
53
54namespace boost { class thread; }
55
56namespace orxonox
57{
58
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;
64
65
66  class _NetworkExport ClientConnection{
67  public:
68    ClientConnection(int port, const std::string& address);
69    ClientConnection(int port, const char* address);
70    ~ClientConnection();
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_;
102
103    static boost::recursive_mutex enet_mutex_;
104  };
105
106
107
108
109
110
111
112
113}
114
115#endif /* _ClientConnection_H__ */
Note: See TracBrowser for help on using the repository browser.