Beispiel #1
0
        /// <summary>
        /// Start the client loop. Only call this client side.
        /// </summary>
        private void StartClientLoop()
        {
            var ping = new HackathonPacket {
                ping = "ping"
            };

            Write(ping);
        }
Beispiel #2
0
        private void Write(HackathonPacket message)
        {
            // Transform the packet into a ASCII string json-encoded.
            var sendBytes = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(message) + "\r\n");

            // Send the bytes to the client.
            _outStream.Write(sendBytes, 0, sendBytes.Length);
        }
Beispiel #3
0
        private HackathonPacket Handle(HackathonPacket packet)
        {
            var result = new HackathonPacket();

            if (packet.name != null)
            {
                if (Name == "none" && packet.name != "none")
                {
                    Name = packet.name;
                    _gameManager.ConnectionReady(this);
                }
            }
            if (packet.command != null)
            {
                _gameManager.ExecuteCommand(this, packet.command);
            }
            if (packet.speed != null)
            {
                _gameManager.ChangeSpeed(this, packet.speed.Value);
            }
            if (packet.rotation != null)
            {
                _gameManager.ChangeRotation(this, packet.rotation.Value);
            }
            if (packet.scene != null)
            {
                _gameManager.UpdateScene(packet.scene);
            }

            // Prepare output...
            if (packet.ping != null && packet.ping == "ping")
            {
                result.ping = "pong";
            }

            if (packet.ping == null && _gameManager.DoPing())
            {
                result.ping = "ping";
            }

            if (Name == "none" && "none" != _gameManager.GetName() && _gameManager.GetName() != null)
            {
                result.name = _gameManager.GetName();
                Name        = result.name;
            }

            result.command  = _gameManager.GetCommand();
            result.speed    = _gameManager.GetSpeed();
            result.rotation = _gameManager.GetRotation();
            result.scene    = _gameManager.GetScene();

            return(result);
        }