private bool TryConnectToGameServer() { Game.WebData.UpdatePilotRanking(Game.DataEngine.LocalPlayer); var gameServerEndPoints = new AWEndPoint[0]; try { gameServerEndPoints = _options.GameServerEndPoints.Select(str => AWEndPoint.Parse(str)).ToArray(); } catch { ShowInfoDialog("Error in game server address."); return false; } Game.StartClient(gameServerEndPoints); Game.ShowConnectingToGameServerDialog(_options.GameServerName); return true; }
/// <summary> /// Turns this game instance into a game client by connecting to a game server. /// </summary> public void StartClient(AWEndPoint[] serverEndPoints) { if (NetworkMode != NetworkMode.Standalone) throw new InvalidOperationException("Cannot start client while in mode " + NetworkMode); NetworkMode = NetworkMode.Client; // Note: Clients are supposed to create teams only with local IDs (negative). // Remove existing teams because they have global IDs (positive). foreach (var spec in DataEngine.Spectators) spec.AssignTeam(null); DataEngine.RemoveEmptyTeams(); RefreshGameSettings(); IsClientAllowedToStartArena = false; try { NetworkEngine.StartClient(this, serverEndPoints, ConnectionResultOnClientCallback); foreach (var spectator in DataEngine.Spectators) spectator.ResetForClient(); } catch (System.Net.Sockets.SocketException e) { Log.Write("Could not start client: " + e.Message); StopClient(null); } }
/// <summary> /// Turns this game instance into a game client by connecting to a game server. /// Poll <c>Connection.ConnectionResults</c> to find out when and if /// the connection was successfully estblished. /// </summary> public void StartClient(AssaultWing game, AWEndPoint[] serverEndPoints, Action<Result<Connection>> connectionHandler) { Log.Write("Client starts connecting"); _startClientConnectionHandler = connectionHandler; Connection.Connect(game, serverEndPoints); }