Example #1
0
        public void Dispose()
        {
            Shutdown();

            if (buffer != null)
            {
                IEvent[] events = buffer.PopAll();
                if (events != null && events.Length > 0)
                {
                    foreach (IEvent evt in events)
                    {
                        evt.Dispose();
                    }
                }
            }

            BotRunner = null;
            clientCallback = null;
            clockCallback = null;
            buffer = null;
            Game = null;
            Player = null;
        }
Example #2
0
        /// <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();
        }