Ejemplo n.º 1
0
        /// <summary>
        /// Parse the specified data.
        /// command부분을 읽어서 해당 객체를 생성
        /// </summary>
        /// <param name="data">Data.</param>
        public static ReceiveMessage Parse(List <byte> data)
        {
            ReceiveMessage msg = null;

            int cmd = data [0];

            switch (cmd)
            {
            case 0:                      // BindSuccess
                msg = new BindSuccessMessage(data);
                break;

            case 1:                      // Bind Failed
                msg = new BindFailedMessage(data);
                break;

            case 2:                     //Move and Rotate
                msg = new MoveAndRotateMessage(data);
                break;

            case 3:                      // Shoot
                msg = new ShootMessage(data);
                break;

            case 4:                      // game_count
                msg = new GameCountMessage(data);
                break;

            case 5:                      // game_start
                msg = new GameStartMessage(data);
                break;

            case 6:                      // game_end
                msg = new GameEndMessage(data);
                break;

            case 7:                      // attacked
                msg = new AttackedMessage(data);
                break;

            case 8:                      // map
                msg = new MapMessage(data);
                break;

            case 9:                     // player_position
                msg = new PlayerPosition(data);
                break;

            case 10:                     // death
                msg = new DeathMessage(data);
                break;

            case 11:                     // sold_out
                msg = new SoldOutMessage(data);
                break;

            case 12:                     // emergency_stop
                msg = new EmergencyStopMessage(data);
                break;

            case 13:                     // death_stop
                msg = new DeathStopMessage(data);
                break;
            }


            return(msg);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes the message.
        /// Server to Client Message.
        /// 서버로부터 온 메세지를 큐에서 꺼내 읽고 해당 이벤트 발생.
        /// </summary>
        /// <param name="msg">Message.</param>
        protected void ProcessMessage(Receive.ReceiveMessage msg)
        {
            if (msg is Receive.BindSuccessMessage)
            {
                if (OnBindSuccess != null)
                {
                    OnBindSuccess();
                }
            }
            else if (msg is Receive.BindFailedMessage)
            {
                if (OnBindFailed != null)
                {
                    OnBindFailed(((Receive.BindFailedMessage)msg).Code);
                }
            }
            else if (msg is Receive.MoveAndRotateMessage)
            {
                Receive.MoveAndRotateMessage m = (Receive.MoveAndRotateMessage)msg;

                Vector2 move   = new Vector2(m.moveX, m.moveY);
                Vector2 rotate = new Vector2(m.rotateX, m.rotateY);

                if (OnControl != null)
                {
                    OnControl(move, rotate);
                }

                if (OnControlType != null)
                {
                    OnControlType(getMoveType(move), getRotateType(rotate));
                }
            }
            else if (msg is Receive.ShootMessage)
            {
                Receive.ShootMessage m = (Receive.ShootMessage)msg;
                Vector3 position       = new Vector3(m.positionX, m.positionY, m.positionZ);
                Vector3 velocity       = new Vector3(m.velocityX, m.velocityY, m.velocityZ);
                if (OnShoot != null)
                {
                    OnShoot(position, velocity);
                }
            }
            else if (msg is Receive.GameStartMessage)
            {
                if (OnGameStart != null)
                {
                    OnGameStart();
                }
            }
            else if (msg is Receive.GameCountMessage)
            {
                if (OnGameCount != null)
                {
                    OnGameCount(((Receive.GameCountMessage)msg).value);
                }
            }
            else if (msg is Receive.GameEndMessage)
            {
                if (OnGameEnd != null)
                {
                    OnGameEnd(((Receive.GameEndMessage)msg).value);
                }
            }
            else if (msg is Receive.AttackedMessage)
            {
                if (OnAttacked != null)
                {
                    OnAttacked();
                }
            }
            else if (msg is Receive.MapMessage)
            {
                if (OnMap != null)
                {
                    OnMap();
                }
            }
            else if (msg is Receive.DeathMessage)
            {
                if (OnDeath != null)
                {
                    OnDeath(((Receive.DeathMessage)msg).uid);
                }
            }
            else if (msg is Receive.SoldOutMessage)
            {
                if (OnSoldOut != null)
                {
                    OnSoldOut(((Receive.SoldOutMessage)msg).uid, ((Receive.SoldOutMessage)msg).unitnum);
                }
            }
            else if (msg is Receive.DeathStopMessage)
            {
                if (OnDeathStop != null)
                {
                    OnDeathStop(((Receive.DeathMessage)msg).uid);
                }
            }
            else if (msg is Receive.EmergencyStopMessage)
            {
                if (OnEmergencyStop != null)
                {
                    OnEmergencyStop(((Receive.DeathMessage)msg).uid);
                }
            }
        }