Imported more code from the old engine.
[peakengine.git] / engine / include / network / NetworkHost.h
blob69100c52985a20045d425d8a976548982bdc1149
1 /*
2 Copyright (C) 2008 Mathias Gottschlag
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in the
6 Software without restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #ifndef _NETWORKHOST_H_
23 #define _NETWORKHOST_H_
25 #include <enet/enet.h>
26 #include <queue>
27 #include <vector>
29 namespace peak
31 class Connection;
32 class NetworkConnection;
35 /**
36 * \brief Network host which acts as a network server.
38 class NetworkHost
40 public:
41 NetworkHost();
42 ~NetworkHost();
44 /**
45 * \brief Initializes the host at a given port.
46 * \param port Port used for the host
48 bool init(int port);
49 /**
50 * \brief Destroys the host, disconnecting all clients.
52 bool shutdown(void);
54 /**
55 * \brief Returns a new connection if there is any.
57 Connection *getNewConnection(void);
58 /**
59 * \brief Closes the connection to a client.
60 * \param conn Connection to be closed
62 void closeConnection(Connection *conn);
64 /**
65 * \brief Receives incoming data.
67 bool doWork(void);
68 private:
69 ENetHost *host;
71 std::queue<Connection*> newconnections;
72 std::vector<Connection*> connections;
76 #endif