/// <summary> /// Connect to a target game server. Throws an exception if something goes /// wrong. /// </summary> /// <param name="server">Game server to connect to.</param> public void ConnectToGameServer(GameServerInfo server) { string key = MainServer.RequestJoinGameServer(server); GameServer = new GameCommunicator( server.Host, server.Port, server.UseGlacier2); GameServer.LogFile = AuthInfo.Username + "GameLog.log"; if (!GameServer.Connect()) { HandleError("Could not connect to the game server: reason unknown."); } clientCallback = new ClientI(BotRunner, this, buffer); clockCallback = new ClockSync(); GameServer.RegisterCallback(clientCallback); GameServer.RegisterCallback(clockCallback); if (!GameServer.JoinServer(key)) { HandleError("Could not join the game server: invalid key."); } Thread.Sleep(100); Debugger.Write("{0}: Connected to the game server! Ping: {1}", AuthInfo.Username, server.GetFormattedAverageLatency()); RefreshPlayerList(); DownloadAndLoadMap(); Game.GameModeHandler = CreateGameHandler(GameMode); GameServer.Ready(); }