コード例 #1
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();
        }
コード例 #2
0
        /// <summary>
        /// Open a connection to an instance of Theater.
        /// </summary>
        /// <param name="server">Game server to join.</param>
        /// <param name="timeout">Timeout in milliseconds.</param>
        public static void ConnectToTheater(GameServerInfo server, long timeout)
        {
            if (Echelon == null)
            {
                throw new Exception("You must connect to Echelon first.");
            }

            if (Theater == null)
            {
                try
                {
                    Theater = new GameCommunicator(
                        server.Host, server.Port, server.UseGlacier2, timeout);
                    if (!Theater.Connect())
                    {
                        Theater.Disconnect();
                        Theater = null;

                        throw new Exception("Unable to connect to " + server.Host + ".");
                    }
                }
                catch (Exception)
                {
                    Theater = null;
                    throw;
                }
            }
            else
            {
                throw new Exception("The communicator has already been created.");
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            var config = GetConfig();
            var communicationBridge = new Bridge();
            var conn = new Connection()
            {
                CommunicationBridge = communicationBridge
            };

            conn.Connect(config.Channel, config.Username, config.Password);
            var listener = new Task(conn.Listen);

            listener.Start();
            var game = new GameCommunicator()
            {
                CommunicationBridge = communicationBridge
            };

            game.Listen();
            //System.Threading.Thread.Sleep(60 * 1000);
        }
コード例 #4
0
ファイル: VTankBot.cs プロジェクト: summer-of-software/vtank
        /// <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();
        }
コード例 #5
0
        /// <summary>
        /// Stop all services and dispose of them. This should be called once before the game
        /// exits. It can be called repeatedly to destroy re-created resources.
        /// </summary>
        public static void StopAllServices()
        {
            try
            {
                Game.Dispose();
            }
            catch (Exception) { }
            finally
            {
                Game = null;
            }

            try
            {
                Resources.Dispose();
            }
            catch (Exception) { }
            finally
            {
                Resources = null;
            }

            StateManager = null;
            try
            {
                Echelon.Dispose();
            }
            catch (Exception) { }
            finally
            {
                Echelon = null;
            }

            try
            {
                Theater.Dispose();
            }
            catch (Exception) { }
            finally
            {
                Theater = null;
            }

            try
            {
                AudioManager.Dispose();
            }
            catch (Exception) { }
            finally
            {
                AudioManager = null;
            }

            try
            {
                MP3Player.Dispose();
            }
            catch (Exception) { }
            finally
            {
                MP3Player = null;
            }

            try
            {
                Logger.Close();
            }
            catch (Exception) { }
            finally
            {
                Logger = null;
            }
        }
コード例 #6
0
 /// <summary>
 /// Disconnect from Theater, enabling ConnectToTheater to be called again.
 /// </summary>
 public static void DestroyTheaterCommunicator()
 {
     if (Theater != null)
     {
         Theater.Disconnect();
         Theater.Dispose();
         Theater = null;
     }
 }
コード例 #7
0
        /// <summary>
        /// Open a connection to an instance of Theater.
        /// </summary>
        /// <param name="server">Game server to join.</param>
        /// <param name="timeout">Timeout in milliseconds.</param>
        public static void ConnectToTheater(GameServerInfo server, long timeout)
        {
            if (Echelon == null)
            {
                throw new Exception("You must connect to Echelon first.");
            }

            if (Theater == null)
            {
                try
                {
                    Theater = new GameCommunicator(
                        server.Host, server.Port, server.UseGlacier2, timeout);
                    if (!Theater.Connect())
                    {
                        Theater.Disconnect();
                        Theater = null;

                        throw new Exception("Unable to connect to " + server.Host + ".");
                    }
                }
                catch (Exception)
                {
                    Theater = null;
                    throw;
                }
            }
            else
            {
                throw new Exception("The communicator has already been created.");
            }
        }