Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #pragma once
00015
00019 #include <list>
00020
00021 #include "SharedPtr.h"
00022
00023 #include "Socket.h"
00024 #include "MessageConnection.h"
00025 #include "Datagram.h"
00026 #include "INetworkServerListener.h"
00027 #include "Lockable.h"
00028
00029 namespace kNet
00030 {
00031
00032 class Network;
00033
00037 class NetworkServer : public RefCountable
00038 {
00039 public:
00041 ~NetworkServer();
00042
00044 void RunModalServer();
00045
00047 void SetAcceptNewConnections(bool acceptNewConnections);
00048
00049
00050 bool AcceptsNewConnections() const { return acceptNewConnections; }
00051
00054 void SetStealthMode(bool stealthModeEnabled);
00055
00058 void ReadUDPSocketData(Socket *listenSocket);
00059
00062 void Process();
00063
00070 void BroadcastMessage(const NetworkMessage &msg, MessageConnection *exclude = 0);
00071
00074 void BroadcastMessage(unsigned long id, bool reliable, bool inOrder, unsigned long priority,
00075 unsigned long contentID, const char *data, size_t numBytes,
00076 MessageConnection *exclude = 0);
00077
00079 void SendMessage(const NetworkMessage &msg, MessageConnection &destination);
00080
00085 void DisconnectAllClients();
00086
00093 void Close(int disconnectWaitMilliseconds);
00094
00096 void ConnectionClosed(MessageConnection *connection);
00097
00099 std::vector<Socket *> &ListenSockets();
00100
00101 typedef std::map<EndPoint, Ptr(MessageConnection)> ConnectionMap;
00102
00104 ConnectionMap GetConnections();
00105
00107 std::string ToString() const;
00108
00109 private:
00111 NetworkServer(Network *owner, std::vector<Socket *> listenSockets);
00112
00116 std::vector<Socket *> listenSockets;
00117
00119 Lockable<ConnectionMap> clients;
00120
00122 Network *owner;
00123
00125 bool acceptNewConnections;
00126
00127 INetworkServerListener *networkServerListener;
00128
00129 void RegisterServerListener(INetworkServerListener *listener);
00130
00134 void CloseListenSockets();
00135
00136 void CleanupDeadConnections();
00137
00138 Socket *AcceptConnections(Socket *listenSocket);
00139
00140 struct ConnectionAttemptDescriptor
00141 {
00142 Socket *listenSocket;
00143 EndPoint peer;
00144 Datagram data;
00145 };
00146
00147 WaitFreeQueue<ConnectionAttemptDescriptor> udpConnectionAttempts;
00148
00150 void EnqueueNewUDPConnectionAttempt(Socket *listenSocket, const EndPoint &endPoint, const char *data, size_t numBytes);
00151
00152 bool ProcessNewUDPConnectionAttempt(Socket *listenSocket, const EndPoint &endPoint, const char *data, size_t numBytes);
00153
00154 friend class Network;
00155 };
00156
00157 }