예제 #1
0
 private void HandleGameServerHandshakeRequestTCP(GameServerHandshakeRequestTCP mess)
 {
     var net = Game.NetworkEngine;
     string clientDiff, serverDiff;
     int diffIndex;
     bool differ = MiscHelper.FirstDifference(mess.CanonicalStrings, CanonicalString.CanonicalForms, out clientDiff, out serverDiff, out diffIndex);
     var connection = net.GetGameClientConnection(mess.ConnectionID);
     if (differ)
     {
         var mismatchInfo = string.Format("First mismatch is index: {0}, client: {1}, server: {2}",
             diffIndex, clientDiff ?? "<missing>", serverDiff ?? "<missing>");
         var extraInfo = diffIndex == 0 ? "" : string.Format(", client previous: {0}, server previous: {1}",
             mess.CanonicalStrings[diffIndex - 1], CanonicalString.CanonicalForms[diffIndex - 1]);
         Log.Write("Client's CanonicalStrings don't match ours. " + mismatchInfo + extraInfo);
         var reply = new ConnectionClosingMessage { Info = "of version mismatch (canonical strings).\nPlease install the latest version from\nwww.assaultwing.com" };
         connection.Send(reply);
         net.DropClient(mess.ConnectionID);
     }
     else
     {
         connection.ConnectionStatus.ClientKey = mess.GameClientKey;
         connection.ConnectionStatus.State = ConnectionUtils.GameClientStatus.StateType.Active;
         // Send dummy UDP packets to probable UDP end points of the client to increase
         // probability of our NAT forwarding UDP packets from the client to us.
         var ping = new PingRequestMessage();
         for (int port = NetworkEngine.UDP_CONNECTION_PORT_FIRST; port <= NetworkEngine.UDP_CONNECTION_PORT_LAST; port++)
             net.UDPSocket.Send(ping.Serialize, new IPEndPoint(net.GetConnection(mess.ConnectionID).RemoteTCPEndPoint.Address, port));
     }
 }
예제 #2
0
 public void IncomingConnectionHandlerOnServer(Result<AW2.Net.Connections.Connection> result, Func<bool> allowNewConnection)
 {
     if (!result.Successful)
         Log.Write("Some client failed to connect: " + result.Error);
     else if (allowNewConnection())
     {
         Game.NetworkEngine.GameClientConnections.Add((GameClientConnection)result.Value);
         Log.Write("Server obtained {0} from {1}", result.Value.Name, result.Value.RemoteTCPEndPoint);
     }
     else
     {
         var mess = new ConnectionClosingMessage { Info = "game server refused joining" };
         result.Value.Send(mess);
         Log.Write("Server refused connection from " + result.Value.RemoteTCPEndPoint);
     }
 }
예제 #3
0
 private void HandleConnectionClosingMessage(ConnectionClosingMessage mess)
 {
     GameServerConnectionClosing(mess.Info);
 }
예제 #4
0
 /// <summary>
 /// Turns this game server into a standalone game instance and disposes of
 /// any connections to game clients.
 /// </summary>
 public void StopServer()
 {
     Log.Write("Stopping game server");
     MessageHandlers.Clear();
     UnregisterServerFromManagementServer();
     _connectionAttemptListener.StopListening();
     _connectionAttemptListener = null;
     var shutdownNotice = new ConnectionClosingMessage { Info = "server shut down" };
     foreach (var conn in GameClientConnections) conn.Send(shutdownNotice);
     DisposeGameClientConnections();
     FlushUnhandledUDPMessages();
 }