소스 검색

Set max connections of Start Server

It is now possible to set as many maximum connections as you want on your urho server.
Igor Segalla 6 년 전
부모
커밋
9871e71d90
2개의 변경된 파일4개의 추가작업 그리고 4개의 파일을 삭제
  1. 3 3
      Source/Urho3D/Network/Network.cpp
  2. 1 1
      Source/Urho3D/Network/Network.h

+ 3 - 3
Source/Urho3D/Network/Network.cpp

@@ -427,7 +427,7 @@ void Network::Disconnect(int waitMSec)
     serverConnection_->Disconnect(waitMSec);
     serverConnection_->Disconnect(waitMSec);
 }
 }
 
 
-bool Network::StartServer(unsigned short port)
+bool Network::StartServer(unsigned short port, unsigned int maxConnections)
 {
 {
     if (IsServerRunning())
     if (IsServerRunning())
         return true;
         return true;
@@ -438,11 +438,11 @@ bool Network::StartServer(unsigned short port)
     socket.port = port;
     socket.port = port;
     socket.socketFamily = AF_INET;
     socket.socketFamily = AF_INET;
     // Startup local connection with max 128 incoming connection(first param) and 1 socket description (third param)
     // Startup local connection with max 128 incoming connection(first param) and 1 socket description (third param)
-    SLNet::StartupResult startResult = rakPeer_->Startup(128, &socket, 1);
+    SLNet::StartupResult startResult = rakPeer_->Startup(maxConnections, &socket, 1);
     if (startResult == SLNet::RAKNET_STARTED)
     if (startResult == SLNet::RAKNET_STARTED)
     {
     {
         URHO3D_LOGINFO("Started server on port " + String(port));
         URHO3D_LOGINFO("Started server on port " + String(port));
-        rakPeer_->SetMaximumIncomingConnections(128);
+        rakPeer_->SetMaximumIncomingConnections(maxConnections);
         isServer_ = true;
         isServer_ = true;
         rakPeer_->SetOccasionalPing(true);
         rakPeer_->SetOccasionalPing(true);
         rakPeer_->SetUnreliableTimeout(1000);
         rakPeer_->SetUnreliableTimeout(1000);

+ 1 - 1
Source/Urho3D/Network/Network.h

@@ -65,7 +65,7 @@ public:
     /// Disconnect the connection to the server. If wait time is non-zero, will block while waiting for disconnect to finish.
     /// Disconnect the connection to the server. If wait time is non-zero, will block while waiting for disconnect to finish.
     void Disconnect(int waitMSec = 0);
     void Disconnect(int waitMSec = 0);
     /// Start a server on a port using UDP protocol. Return true if successful.
     /// Start a server on a port using UDP protocol. Return true if successful.
-    bool StartServer(unsigned short port);
+    bool StartServer(unsigned short port, unsigned int maxConnections = 128);
     /// Stop the server.
     /// Stop the server.
     void StopServer();
     void StopServer();
     /// Start NAT punchtrough client to allow remote connections.
     /// Start NAT punchtrough client to allow remote connections.