Network.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "../Precompiled.h"
  23. #include "../Core/Context.h"
  24. #include "../Core/CoreEvents.h"
  25. #include "../Core/Profiler.h"
  26. #include "../Engine/EngineEvents.h"
  27. #include "../IO/FileSystem.h"
  28. #include "../Input/InputEvents.h"
  29. #include "../IO/IOEvents.h"
  30. #include "../IO/Log.h"
  31. #include "../IO/MemoryBuffer.h"
  32. #include "../Network/HttpRequest.h"
  33. #include "../Network/Network.h"
  34. #include "../Network/NetworkEvents.h"
  35. #include "../Network/NetworkPriority.h"
  36. #include "../Network/Protocol.h"
  37. #include "../Scene/Scene.h"
  38. #include <kNet/kNet.h>
  39. #include "../DebugNew.h"
  40. namespace Urho3D
  41. {
  42. static const int DEFAULT_UPDATE_FPS = 30;
  43. Network::Network(Context* context) :
  44. Object(context),
  45. updateFps_(DEFAULT_UPDATE_FPS),
  46. simulatedLatency_(0),
  47. simulatedPacketLoss_(0.0f),
  48. updateInterval_(1.0f / (float)DEFAULT_UPDATE_FPS),
  49. updateAcc_(0.0f)
  50. {
  51. network_ = new kNet::Network();
  52. // Register Network library object factories
  53. RegisterNetworkLibrary(context_);
  54. SubscribeToEvent(E_BEGINFRAME, URHO3D_HANDLER(Network, HandleBeginFrame));
  55. SubscribeToEvent(E_RENDERUPDATE, URHO3D_HANDLER(Network, HandleRenderUpdate));
  56. // Blacklist remote events which are not to be allowed to be registered in any case
  57. blacklistedRemoteEvents_.Insert(E_CONSOLECOMMAND);
  58. blacklistedRemoteEvents_.Insert(E_LOGMESSAGE);
  59. blacklistedRemoteEvents_.Insert(E_BEGINFRAME);
  60. blacklistedRemoteEvents_.Insert(E_UPDATE);
  61. blacklistedRemoteEvents_.Insert(E_POSTUPDATE);
  62. blacklistedRemoteEvents_.Insert(E_RENDERUPDATE);
  63. blacklistedRemoteEvents_.Insert(E_ENDFRAME);
  64. blacklistedRemoteEvents_.Insert(E_MOUSEBUTTONDOWN);
  65. blacklistedRemoteEvents_.Insert(E_MOUSEBUTTONUP);
  66. blacklistedRemoteEvents_.Insert(E_MOUSEMOVE);
  67. blacklistedRemoteEvents_.Insert(E_MOUSEWHEEL);
  68. blacklistedRemoteEvents_.Insert(E_KEYDOWN);
  69. blacklistedRemoteEvents_.Insert(E_KEYUP);
  70. blacklistedRemoteEvents_.Insert(E_TEXTINPUT);
  71. blacklistedRemoteEvents_.Insert(E_JOYSTICKCONNECTED);
  72. blacklistedRemoteEvents_.Insert(E_JOYSTICKDISCONNECTED);
  73. blacklistedRemoteEvents_.Insert(E_JOYSTICKBUTTONDOWN);
  74. blacklistedRemoteEvents_.Insert(E_JOYSTICKBUTTONUP);
  75. blacklistedRemoteEvents_.Insert(E_JOYSTICKAXISMOVE);
  76. blacklistedRemoteEvents_.Insert(E_JOYSTICKHATMOVE);
  77. blacklistedRemoteEvents_.Insert(E_TOUCHBEGIN);
  78. blacklistedRemoteEvents_.Insert(E_TOUCHEND);
  79. blacklistedRemoteEvents_.Insert(E_TOUCHMOVE);
  80. blacklistedRemoteEvents_.Insert(E_GESTURERECORDED);
  81. blacklistedRemoteEvents_.Insert(E_GESTUREINPUT);
  82. blacklistedRemoteEvents_.Insert(E_MULTIGESTURE);
  83. blacklistedRemoteEvents_.Insert(E_DROPFILE);
  84. blacklistedRemoteEvents_.Insert(E_INPUTFOCUS);
  85. blacklistedRemoteEvents_.Insert(E_MOUSEVISIBLECHANGED);
  86. blacklistedRemoteEvents_.Insert(E_EXITREQUESTED);
  87. blacklistedRemoteEvents_.Insert(E_SERVERCONNECTED);
  88. blacklistedRemoteEvents_.Insert(E_SERVERDISCONNECTED);
  89. blacklistedRemoteEvents_.Insert(E_CONNECTFAILED);
  90. blacklistedRemoteEvents_.Insert(E_CLIENTCONNECTED);
  91. blacklistedRemoteEvents_.Insert(E_CLIENTDISCONNECTED);
  92. blacklistedRemoteEvents_.Insert(E_CLIENTIDENTITY);
  93. blacklistedRemoteEvents_.Insert(E_CLIENTSCENELOADED);
  94. blacklistedRemoteEvents_.Insert(E_NETWORKMESSAGE);
  95. blacklistedRemoteEvents_.Insert(E_NETWORKUPDATE);
  96. blacklistedRemoteEvents_.Insert(E_NETWORKUPDATESENT);
  97. blacklistedRemoteEvents_.Insert(E_NETWORKSCENELOADFAILED);
  98. }
  99. Network::~Network()
  100. {
  101. // If server connection exists, disconnect, but do not send an event because we are shutting down
  102. Disconnect(100);
  103. serverConnection_.Reset();
  104. clientConnections_.Clear();
  105. }
  106. void Network::HandleMessage(kNet::MessageConnection* source, kNet::packet_id_t packetId, kNet::message_id_t msgId, const char* data,
  107. size_t numBytes)
  108. {
  109. // Only process messages from known sources
  110. Connection* connection = GetConnection(source);
  111. if (connection)
  112. {
  113. MemoryBuffer msg(data, (unsigned)numBytes);
  114. if (connection->ProcessMessage((int)msgId, msg))
  115. return;
  116. // If message was not handled internally, forward as an event
  117. using namespace NetworkMessage;
  118. VariantMap& eventData = GetEventDataMap();
  119. eventData[P_CONNECTION] = connection;
  120. eventData[P_MESSAGEID] = (int)msgId;
  121. eventData[P_DATA].SetBuffer(msg.GetData(), msg.GetSize());
  122. connection->SendEvent(E_NETWORKMESSAGE, eventData);
  123. }
  124. else
  125. URHO3D_LOGWARNING("Discarding message from unknown MessageConnection " + ToString((void*)source));
  126. }
  127. u32 Network::ComputeContentID(kNet::message_id_t msgId, const char* data, size_t numBytes)
  128. {
  129. switch (msgId)
  130. {
  131. case MSG_CONTROLS:
  132. // Return fixed content ID for controls
  133. return CONTROLS_CONTENT_ID;
  134. case MSG_NODELATESTDATA:
  135. case MSG_COMPONENTLATESTDATA:
  136. {
  137. // Return the node or component ID, which is first in the message
  138. MemoryBuffer msg(data, (unsigned)numBytes);
  139. return msg.ReadNetID();
  140. }
  141. default:
  142. // By default return no content ID
  143. return 0;
  144. }
  145. }
  146. void Network::NewConnectionEstablished(kNet::MessageConnection* connection)
  147. {
  148. connection->RegisterInboundMessageHandler(this);
  149. // Create a new client connection corresponding to this MessageConnection
  150. SharedPtr<Connection> newConnection(new Connection(context_, true, kNet::SharedPtr<kNet::MessageConnection>(connection)));
  151. newConnection->ConfigureNetworkSimulator(simulatedLatency_, simulatedPacketLoss_);
  152. clientConnections_[connection] = newConnection;
  153. URHO3D_LOGINFO("Client " + newConnection->ToString() + " connected");
  154. using namespace ClientConnected;
  155. VariantMap& eventData = GetEventDataMap();
  156. eventData[P_CONNECTION] = newConnection;
  157. newConnection->SendEvent(E_CLIENTCONNECTED, eventData);
  158. }
  159. void Network::ClientDisconnected(kNet::MessageConnection* connection)
  160. {
  161. connection->Disconnect(0);
  162. // Remove the client connection that corresponds to this MessageConnection
  163. HashMap<kNet::MessageConnection*, SharedPtr<Connection> >::Iterator i = clientConnections_.Find(connection);
  164. if (i != clientConnections_.End())
  165. {
  166. Connection* connection = i->second_;
  167. URHO3D_LOGINFO("Client " + connection->ToString() + " disconnected");
  168. using namespace ClientDisconnected;
  169. VariantMap& eventData = GetEventDataMap();
  170. eventData[P_CONNECTION] = connection;
  171. connection->SendEvent(E_CLIENTDISCONNECTED, eventData);
  172. clientConnections_.Erase(i);
  173. }
  174. }
  175. bool Network::Connect(const String& address, unsigned short port, Scene* scene, const VariantMap& identity)
  176. {
  177. URHO3D_PROFILE(Connect);
  178. // If a previous connection already exists, disconnect it and wait for some time for the connection to terminate
  179. if (serverConnection_)
  180. {
  181. serverConnection_->Disconnect(100);
  182. OnServerDisconnected();
  183. }
  184. kNet::SharedPtr<kNet::MessageConnection> connection = network_->Connect(address.CString(), port, kNet::SocketOverUDP, this);
  185. if (connection)
  186. {
  187. serverConnection_ = new Connection(context_, false, connection);
  188. serverConnection_->SetScene(scene);
  189. serverConnection_->SetIdentity(identity);
  190. serverConnection_->SetConnectPending(true);
  191. serverConnection_->ConfigureNetworkSimulator(simulatedLatency_, simulatedPacketLoss_);
  192. URHO3D_LOGINFO("Connecting to server " + serverConnection_->ToString());
  193. return true;
  194. }
  195. else
  196. {
  197. URHO3D_LOGERROR("Failed to connect to server " + address + ":" + String(port));
  198. SendEvent(E_CONNECTFAILED);
  199. return false;
  200. }
  201. }
  202. void Network::Disconnect(int waitMSec)
  203. {
  204. if (!serverConnection_)
  205. return;
  206. URHO3D_PROFILE(Disconnect);
  207. serverConnection_->Disconnect(waitMSec);
  208. }
  209. bool Network::StartServer(unsigned short port)
  210. {
  211. if (IsServerRunning())
  212. return true;
  213. URHO3D_PROFILE(StartServer);
  214. if (network_->StartServer(port, kNet::SocketOverUDP, this, true) != 0)
  215. {
  216. URHO3D_LOGINFO("Started server on port " + String(port));
  217. return true;
  218. }
  219. else
  220. {
  221. URHO3D_LOGERROR("Failed to start server on port " + String(port));
  222. return false;
  223. }
  224. }
  225. void Network::StopServer()
  226. {
  227. if (!IsServerRunning())
  228. return;
  229. URHO3D_PROFILE(StopServer);
  230. clientConnections_.Clear();
  231. network_->StopServer();
  232. URHO3D_LOGINFO("Stopped server");
  233. }
  234. void Network::BroadcastMessage(int msgID, bool reliable, bool inOrder, const VectorBuffer& msg, unsigned contentID)
  235. {
  236. BroadcastMessage(msgID, reliable, inOrder, msg.GetData(), msg.GetSize(), contentID);
  237. }
  238. void Network::BroadcastMessage(int msgID, bool reliable, bool inOrder, const unsigned char* data, unsigned numBytes,
  239. unsigned contentID)
  240. {
  241. // Make sure not to use kNet internal message ID's
  242. if (msgID <= 0x4 || msgID >= 0x3ffffffe)
  243. {
  244. URHO3D_LOGERROR("Can not send message with reserved ID");
  245. return;
  246. }
  247. kNet::NetworkServer* server = network_->GetServer();
  248. if (server)
  249. server->BroadcastMessage((unsigned long)msgID, reliable, inOrder, 0, contentID, (const char*)data, numBytes);
  250. else
  251. URHO3D_LOGERROR("Server not running, can not broadcast messages");
  252. }
  253. void Network::BroadcastRemoteEvent(StringHash eventType, bool inOrder, const VariantMap& eventData)
  254. {
  255. for (HashMap<kNet::MessageConnection*, SharedPtr<Connection> >::Iterator i = clientConnections_.Begin();
  256. i != clientConnections_.End(); ++i)
  257. i->second_->SendRemoteEvent(eventType, inOrder, eventData);
  258. }
  259. void Network::BroadcastRemoteEvent(Scene* scene, StringHash eventType, bool inOrder, const VariantMap& eventData)
  260. {
  261. for (HashMap<kNet::MessageConnection*, SharedPtr<Connection> >::Iterator i = clientConnections_.Begin();
  262. i != clientConnections_.End(); ++i)
  263. {
  264. if (i->second_->GetScene() == scene)
  265. i->second_->SendRemoteEvent(eventType, inOrder, eventData);
  266. }
  267. }
  268. void Network::BroadcastRemoteEvent(Node* node, StringHash eventType, bool inOrder, const VariantMap& eventData)
  269. {
  270. if (!node)
  271. {
  272. URHO3D_LOGERROR("Null sender node for remote node event");
  273. return;
  274. }
  275. if (node->GetID() >= FIRST_LOCAL_ID)
  276. {
  277. URHO3D_LOGERROR("Sender node has a local ID, can not send remote node event");
  278. return;
  279. }
  280. Scene* scene = node->GetScene();
  281. for (HashMap<kNet::MessageConnection*, SharedPtr<Connection> >::Iterator i = clientConnections_.Begin();
  282. i != clientConnections_.End(); ++i)
  283. {
  284. if (i->second_->GetScene() == scene)
  285. i->second_->SendRemoteEvent(node, eventType, inOrder, eventData);
  286. }
  287. }
  288. void Network::SetUpdateFps(int fps)
  289. {
  290. updateFps_ = Max(fps, 1);
  291. updateInterval_ = 1.0f / (float)updateFps_;
  292. updateAcc_ = 0.0f;
  293. }
  294. void Network::SetSimulatedLatency(int ms)
  295. {
  296. simulatedLatency_ = Max(ms, 0);
  297. ConfigureNetworkSimulator();
  298. }
  299. void Network::SetSimulatedPacketLoss(float loss)
  300. {
  301. simulatedPacketLoss_ = Clamp(loss, 0.0f, 1.0f);
  302. ConfigureNetworkSimulator();
  303. }
  304. void Network::RegisterRemoteEvent(StringHash eventType)
  305. {
  306. if (blacklistedRemoteEvents_.Find(eventType) != blacklistedRemoteEvents_.End())
  307. {
  308. URHO3D_LOGERROR("Attempted to register blacklisted remote event type " + String(eventType));
  309. return;
  310. }
  311. allowedRemoteEvents_.Insert(eventType);
  312. }
  313. void Network::UnregisterRemoteEvent(StringHash eventType)
  314. {
  315. allowedRemoteEvents_.Erase(eventType);
  316. }
  317. void Network::UnregisterAllRemoteEvents()
  318. {
  319. allowedRemoteEvents_.Clear();
  320. }
  321. void Network::SetPackageCacheDir(const String& path)
  322. {
  323. packageCacheDir_ = AddTrailingSlash(path);
  324. }
  325. void Network::SendPackageToClients(Scene* scene, PackageFile* package)
  326. {
  327. if (!scene)
  328. {
  329. URHO3D_LOGERROR("Null scene specified for SendPackageToClients");
  330. return;
  331. }
  332. if (!package)
  333. {
  334. URHO3D_LOGERROR("Null package specified for SendPackageToClients");
  335. return;
  336. }
  337. for (HashMap<kNet::MessageConnection*, SharedPtr<Connection> >::Iterator i = clientConnections_.Begin();
  338. i != clientConnections_.End(); ++i)
  339. {
  340. if (i->second_->GetScene() == scene)
  341. i->second_->SendPackageToClient(package);
  342. }
  343. }
  344. SharedPtr<HttpRequest> Network::MakeHttpRequest(const String& url, const String& verb, const Vector<String>& headers,
  345. const String& postData)
  346. {
  347. URHO3D_PROFILE(MakeHttpRequest);
  348. // The initialization of the request will take time, can not know at this point if it has an error or not
  349. SharedPtr<HttpRequest> request(new HttpRequest(url, verb, headers, postData));
  350. return request;
  351. }
  352. Connection* Network::GetConnection(kNet::MessageConnection* connection) const
  353. {
  354. if (serverConnection_ && serverConnection_->GetMessageConnection() == connection)
  355. return serverConnection_;
  356. else
  357. {
  358. HashMap<kNet::MessageConnection*, SharedPtr<Connection> >::ConstIterator i = clientConnections_.Find(connection);
  359. if (i != clientConnections_.End())
  360. return i->second_;
  361. else
  362. return 0;
  363. }
  364. }
  365. Connection* Network::GetServerConnection() const
  366. {
  367. return serverConnection_;
  368. }
  369. Vector<SharedPtr<Connection> > Network::GetClientConnections() const
  370. {
  371. Vector<SharedPtr<Connection> > ret;
  372. for (HashMap<kNet::MessageConnection*, SharedPtr<Connection> >::ConstIterator i = clientConnections_.Begin();
  373. i != clientConnections_.End(); ++i)
  374. ret.Push(i->second_);
  375. return ret;
  376. }
  377. bool Network::IsServerRunning() const
  378. {
  379. return network_->GetServer();
  380. }
  381. bool Network::CheckRemoteEvent(StringHash eventType) const
  382. {
  383. return allowedRemoteEvents_.Contains(eventType);
  384. }
  385. void Network::Update(float timeStep)
  386. {
  387. URHO3D_PROFILE(UpdateNetwork);
  388. // Process server connection if it exists
  389. if (serverConnection_)
  390. {
  391. kNet::MessageConnection* connection = serverConnection_->GetMessageConnection();
  392. // Receive new messages
  393. connection->Process();
  394. // Process latest data messages waiting for the correct nodes or components to be created
  395. serverConnection_->ProcessPendingLatestData();
  396. // Check for state transitions
  397. kNet::ConnectionState state = connection->GetConnectionState();
  398. if (serverConnection_->IsConnectPending() && state == kNet::ConnectionOK)
  399. OnServerConnected();
  400. else if (state == kNet::ConnectionPeerClosed)
  401. serverConnection_->Disconnect();
  402. else if (state == kNet::ConnectionClosed)
  403. OnServerDisconnected();
  404. }
  405. // Process the network server if started
  406. kNet::SharedPtr<kNet::NetworkServer> server = network_->GetServer();
  407. if (server)
  408. server->Process();
  409. }
  410. void Network::PostUpdate(float timeStep)
  411. {
  412. URHO3D_PROFILE(PostUpdateNetwork);
  413. // Check if periodic update should happen now
  414. updateAcc_ += timeStep;
  415. bool updateNow = updateAcc_ >= updateInterval_;
  416. if (updateNow)
  417. {
  418. // Notify of the impending update to allow for example updated client controls to be set
  419. SendEvent(E_NETWORKUPDATE);
  420. updateAcc_ = fmodf(updateAcc_, updateInterval_);
  421. if (IsServerRunning())
  422. {
  423. // Collect and prepare all networked scenes
  424. {
  425. URHO3D_PROFILE(PrepareServerUpdate);
  426. networkScenes_.Clear();
  427. for (HashMap<kNet::MessageConnection*, SharedPtr<Connection> >::Iterator i = clientConnections_.Begin();
  428. i != clientConnections_.End(); ++i)
  429. {
  430. Scene* scene = i->second_->GetScene();
  431. if (scene)
  432. networkScenes_.Insert(scene);
  433. }
  434. for (HashSet<Scene*>::ConstIterator i = networkScenes_.Begin(); i != networkScenes_.End(); ++i)
  435. (*i)->PrepareNetworkUpdate();
  436. }
  437. {
  438. URHO3D_PROFILE(SendServerUpdate);
  439. // Then send server updates for each client connection
  440. for (HashMap<kNet::MessageConnection*, SharedPtr<Connection> >::Iterator i = clientConnections_.Begin();
  441. i != clientConnections_.End(); ++i)
  442. {
  443. i->second_->SendServerUpdate();
  444. i->second_->SendRemoteEvents();
  445. i->second_->SendPackages();
  446. }
  447. }
  448. }
  449. if (serverConnection_)
  450. {
  451. // Send the client update
  452. serverConnection_->SendClientUpdate();
  453. serverConnection_->SendRemoteEvents();
  454. }
  455. // Notify that the update was sent
  456. SendEvent(E_NETWORKUPDATESENT);
  457. }
  458. }
  459. void Network::HandleBeginFrame(StringHash eventType, VariantMap& eventData)
  460. {
  461. using namespace BeginFrame;
  462. Update(eventData[P_TIMESTEP].GetFloat());
  463. }
  464. void Network::HandleRenderUpdate(StringHash eventType, VariantMap& eventData)
  465. {
  466. using namespace RenderUpdate;
  467. PostUpdate(eventData[P_TIMESTEP].GetFloat());
  468. }
  469. void Network::OnServerConnected()
  470. {
  471. serverConnection_->SetConnectPending(false);
  472. URHO3D_LOGINFO("Connected to server");
  473. // Send the identity map now
  474. VectorBuffer msg;
  475. msg.WriteVariantMap(serverConnection_->GetIdentity());
  476. serverConnection_->SendMessage(MSG_IDENTITY, true, true, msg);
  477. SendEvent(E_SERVERCONNECTED);
  478. }
  479. void Network::OnServerDisconnected()
  480. {
  481. // Differentiate between failed connection, and disconnection
  482. bool failedConnect = serverConnection_ && serverConnection_->IsConnectPending();
  483. serverConnection_.Reset();
  484. if (!failedConnect)
  485. {
  486. URHO3D_LOGINFO("Disconnected from server");
  487. SendEvent(E_SERVERDISCONNECTED);
  488. }
  489. else
  490. {
  491. URHO3D_LOGERROR("Failed to connect to server");
  492. SendEvent(E_CONNECTFAILED);
  493. }
  494. }
  495. void Network::ConfigureNetworkSimulator()
  496. {
  497. if (serverConnection_)
  498. serverConnection_->ConfigureNetworkSimulator(simulatedLatency_, simulatedPacketLoss_);
  499. for (HashMap<kNet::MessageConnection*, SharedPtr<Connection> >::Iterator i = clientConnections_.Begin();
  500. i != clientConnections_.End(); ++i)
  501. i->second_->ConfigureNetworkSimulator(simulatedLatency_, simulatedPacketLoss_);
  502. }
  503. void RegisterNetworkLibrary(Context* context)
  504. {
  505. NetworkPriority::RegisterObject(context);
  506. }
  507. }