예제 #1
0
        public KSObject RecvMessage()
        {
            var data = network.RecvData();

            if (data == null || data.Length == 0)
            {
                return(null);
            }
            KSObject msg = parser.Decode(data);

            return(msg);
        }
예제 #2
0
        private KSObject RecvMessage()
        {
            KSObject tmp = protocol.RecvMessage();

            if (tmp != null)
            {
                return(tmp);
            }

            Logger.Log("Connection closed");
            Quit();
            Environment.Exit(0);
            return(null);
        }
예제 #3
0
        public void SendCommandThread()
        {
            while (true)
            {
                KSObject msg = commandSendQueue.Take();

                if (msg == null)
                {
                    break;
                }

                if (gameRunning)
                {
                    SendMessage(msg);
                }
            }
        }
예제 #4
0
        public bool Join()
        {
            KSObject joinMessage;

            if (Config.GetInstance().Configuration.Value("general").Value <bool>("offline_mode"))
            {
                joinMessage = new JoinOfflineGame
                {
                    TeamNickname = Config.GetInstance().Configuration.Value("ai").Value <string>("team_nickname"),
                    AgentName    = Config.GetInstance().Configuration.Value("ai").Value <string>("agent_name")
                };
            }
            else
            {
                joinMessage = new JoinOnlineGame
                {
                    Token     = Config.GetInstance().Configuration.Value("ai").Value <string>("token"),
                    AgentName = Config.GetInstance().Configuration.Value("ai").Value <string>("agent_name")
                };
            }

            SendMessage(joinMessage);
            ClientJoined clientJoinedMessage;

            while (true)
            {
                KSObject tmp = RecvMessage();
                if (tmp.Name() == ClientJoined.NameStatic)
                {
                    clientJoinedMessage = (ClientJoined)tmp;
                    break;
                }
            }

            if ((bool)clientJoinedMessage.Joined)
            {
                ai.SetSides(clientJoinedMessage.Sides, clientJoinedMessage.SideName);
                Logger.Log("Joined the game successfully");
                Logger.Log("Side: " + clientJoinedMessage.SideName);
                return(true);
            }

            Logger.Log("Failed to join the game");
            return(false);
        }
예제 #5
0
        public void Loop()
        {
            while (true)
            {
                KSObject msg = RecvMessage();

                if (msg is BaseSnapshot)
                {
                    HandleSnapshot((BaseSnapshot)msg);
                }
                else if (msg.Name() == StartGame.NameStatic)
                {
                    HandleStartGame(msg);
                }
                else if (msg.Name() == EndGame.NameStatic)
                {
                    HandleEndGame((EndGame)msg);
                    break;
                }
            }
        }
예제 #6
0
        public void SendMessage(KSObject msg)
        {
            var data = parser.Encode(msg);

            network.SendData(data);
        }
예제 #7
0
 private void SendMessage(KSObject msg)
 {
     protocol.SendMessage(msg);
 }
예제 #8
0
 private void HandleStartGame(KSObject gamestart)
 {
     new Thread(() => SendCommandThread()).Start();
 }