public void Connect(ConnectionToken token) { var connectionString = String.Format(ConnectionStringTemplate, token.Key, StormFrontVersion, Environment.OSVersion.Platform); _asyncSocket = _services.Get<IAsyncSocket>(); _asyncSocket.ReceiveMessage += HandleReceiveMessage; _asyncSocket.Connect(token.GameHost, token.GamePort); _asyncSocket.SendMessage(connectionString); }
/// <summary> /// Awaits a message from the client containing a sessionId. /// If the sessionId matches any we have given out. Assign the found PlayerEndPoint /// to the client. We write back the sessionId again as a signal that the client should /// begin attempting to "connect" with UDP. /// </summary> /// <param name="socket"> The TCP socket for the client. </param> /// <returns> true if the client succesfully verified through TCP. false otherwise. </returns> private async Task<bool> AddTCPTarget(IAsyncSocket socket) { ReadResult result = await socket.ReceiveAsync(); if (result.BytesRead != SESSIONID_LENGTH) { return false; } string sessionId = Convert.ToBase64String(result.Buffer); PlayerEndPoint playerEndPoint; if (!_playerSessionTokens.TryGetValue(sessionId, out playerEndPoint)) { return false; } if (sessionId != playerEndPoint.SessionId) return false; playerEndPoint.TCPSocket = socket; await socket.SendMessage(result.Buffer); return _playerEndPoints.TryAdd(socket.IpEndPoint, playerEndPoint); }