示例#1
0
        private void ConnectionResultOnClientCallback(Result<Connection> result)
        {
            Logic.HideDialog("Connecting to server");
            if (NetworkEngine.IsConnectedToGameServer)
            {
                // Silently ignore extra server connection attempts.
                if (result.Successful) result.Value.Dispose();
                return;
            }

            if (!result.Successful)
            {
                Log.Write("Failed to connect to server: " + result.Error);
                StopClient("Failed to connect to server.");
            }
            else
            {
                MessageHandlers.DeactivateHandlers(MessageHandlers.GetStandaloneMenuHandlers(null));
                NetworkEngine.GameServerConnection = result.Value;
                MessageHandlers.ActivateHandlers(MessageHandlers.GetClientMenuHandlers());
                var joinRequest = new GameServerHandshakeRequestTCP
                {
                    CanonicalStrings = CanonicalString.CanonicalForms,
                    GameClientKey = NetworkEngine.GetAssaultWingInstanceKey(),
                };
                NetworkEngine.GameServerConnection.Send(joinRequest);
            }
        }
示例#2
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));
     }
 }