Ejemplo n.º 1
0
        public void Parse(GameClientPacket packet)
        {
            if (_isError)
                return;

            CtosMessage msg = packet.ReadCtos();
            switch (msg)
            {
                case CtosMessage.PlayerInfo:
                    OnPlayerInfo(packet);
                    break;
                case CtosMessage.JoinGame:
                    OnJoinGame(packet);
                    break;
            }
            if (!IsAuthentified)
                return;
            switch (msg)
            {
                case CtosMessage.Chat:
                    OnChat(packet);
                    break;
                case CtosMessage.HsToDuelist:
                    Game.MoveToDuelist(this);
                    break;
                case CtosMessage.HsToObserver:
                    Game.MoveToObserver(this);
                    break;
                case CtosMessage.LeaveGame:
                    Game.RemovePlayer(this);
                    break;
                case CtosMessage.HsReady:
                    Game.SetReady(this, true);
                    break;
                case CtosMessage.HsNotReady:
                    Game.SetReady(this, false);
                    break;
                case CtosMessage.HsKick:
                    OnKick(packet);
                    break;
                case CtosMessage.HsStart:
                    Game.StartDuel(this);
                    break;
                case CtosMessage.HandResult:
                    OnHandResult(packet);
                    break;
                case CtosMessage.TpResult:
                    OnTpResult(packet);
                    break;
                case CtosMessage.UpdateDeck:
                    OnUpdateDeck(packet);
                    break;
                case CtosMessage.Response:
                    OnResponse(packet);
                    break;
                case CtosMessage.Surrender:
                    Game.Surrender(this, 0);
                    break;
            }
        }
Ejemplo n.º 2
0
 private void OnPlayerInfo(GameClientPacket packet)
 {
     if (Name != null)
     {
         return;
     }
     Name = packet.ReadUnicode(20);
 }
Ejemplo n.º 3
0
        private void NetworkReceive()
        {
            if (_client.Available >= 2 && _receivedLen == -1)
            {
                _receivedLen = _reader.ReadUInt16();
            }

            if (_receivedLen != -1 && _client.Available >= _receivedLen)
            {
                GameClientPacket packet = new GameClientPacket(_reader.ReadBytes(_receivedLen));
                _receivedLen = -1;
                lock (_recvQueue)
                    _recvQueue.Enqueue(packet);
            }
        }
Ejemplo n.º 4
0
 private void OnResponse(GameClientPacket packet)
 {
     if (Game.State != GameState.Duel)
     {
         return;
     }
     if (State != PlayerState.Response)
     {
         return;
     }
     byte[] resp = packet.ReadToEnd();
     if (resp.Length > 64)
     {
         return;
     }
     State = PlayerState.None;
     Game.SetResponse(resp);
 }
Ejemplo n.º 5
0
        private void OnUpdateDeck(GameClientPacket packet)
        {
            if (Type == (int)PlayerType.Observer)
            {
                return;
            }
            Deck deck = new Deck();
            int  main = packet.ReadInt32();
            int  side = packet.ReadInt32();

            for (int i = 0; i < main; i++)
            {
                deck.AddMain(packet.ReadInt32());
            }
            for (int i = 0; i < side; i++)
            {
                deck.AddSide(packet.ReadInt32());
            }
            if (Game.State == GameState.Lobby)
            {
                Deck = deck;
                Game.IsReady[Type] = false;
            }
            else if (Game.State == GameState.Side)
            {
                if (Game.IsReady[Type])
                {
                    return;
                }
                if (!Deck.Check(deck))
                {
                    GameServerPacket error = new GameServerPacket(StocMessage.ErrorMsg);
                    error.Write((byte)3);
                    error.Write(0);
                    Send(error);
                    return;
                }
                Deck = deck;
                Game.IsReady[Type] = true;
                Send(new GameServerPacket(StocMessage.DuelStart));
                Game.MatchSide();
            }
        }
Ejemplo n.º 6
0
        private void OnJoinGame(GameClientPacket packet)
        {
            if (Name == null || Type != (int)PlayerType.Undefined)
            {
                return;
            }

            int version = packet.ReadInt16();

            if (version != Program.ProVersion)
            {
                return;
            }

            packet.ReadInt32();//gameid
            packet.ReadInt16();

            Game.AddPlayer(this);
            IsAuthentified = true;
        }
Ejemplo n.º 7
0
        private void NetworkParse()
        {
            int count;

            lock (_recvQueue)
                count = _recvQueue.Count;
            while (count > 0)
            {
                GameClientPacket packet = null;
                lock (_recvQueue) {
                    if (_recvQueue.Count > 0)
                    {
                        packet = _recvQueue.Dequeue();
                    }
                    count = _recvQueue.Count;
                }
                if (packet != null)
                {
                    Player.Parse(packet);
                }
            }
        }
Ejemplo n.º 8
0
        private void NetworkReceive()
        {
            if (_client.Available >= 2 && _receivedLen == -1)
                _receivedLen = _reader.ReadUInt16();

            if (_receivedLen != -1 && _client.Available >= _receivedLen)
            {
                GameClientPacket packet = new GameClientPacket(_reader.ReadBytes(_receivedLen));
                _receivedLen = -1;
                lock (_recvQueue)
                    _recvQueue.Enqueue(packet);
            }
        }
Ejemplo n.º 9
0
        private void OnUpdateDeck(GameClientPacket packet) {
            if (Type == (int)PlayerType.Observer)
                return;
            Deck deck = new Deck();
            int main = packet.ReadInt32();
            int side = packet.ReadInt32();

            for (int i = 0; i < main; i++)
                deck.AddMain(packet.ReadInt32());
            for (int i = 0; i < side; i++)
                deck.AddSide(packet.ReadInt32());
            if (Game.State == GameState.Lobby) {
                Deck = deck;
                Game.IsReady[Type] = false;
            } else if (Game.State == GameState.Side) {
                if (Game.IsReady[Type])
                    return;
                if (!Deck.Check(deck)) {
                    GameServerPacket error = new GameServerPacket(StocMessage.ErrorMsg);
                    error.Write((byte)3);
                    error.Write(0);
                    Send(error);
                    return;
                }
                Deck = deck;
                Game.IsReady[Type] = true;
                Send(new GameServerPacket(StocMessage.DuelStart));
                Game.MatchSide();
            }
        }
Ejemplo n.º 10
0
 private void OnResponse(GameClientPacket packet) {
     if (Game.State != GameState.Duel)
         return;
     if (State != PlayerState.Response)
         return;
     byte[] resp = packet.ReadToEnd();
     if (resp.Length > 64)
         return;
     State = PlayerState.None;
     Game.SetResponse(resp);
 }
Ejemplo n.º 11
0
 private void OnHandResult(GameClientPacket packet) {
     int res = packet.ReadByte();
     Game.HandResult(this, res);
 }
Ejemplo n.º 12
0
 private void OnTpResult(GameClientPacket packet) {
     bool tp = packet.ReadByte() != 0;
     Game.TpResult(this, tp);
 }
Ejemplo n.º 13
0
 private void OnChat(GameClientPacket packet) {
     string msg = packet.ReadUnicode(256);
     Game.Chat(this, msg);
 }
Ejemplo n.º 14
0
 private void OnKick(GameClientPacket packet) {
     int pos = packet.ReadByte();
     Game.KickPlayer(this, pos);
 }
Ejemplo n.º 15
0
        private void OnJoinGame(GameClientPacket packet) {
            if (Name == null || Type != (int)PlayerType.Undefined)
                return;

            int version = packet.ReadInt16();
            if (version != Program.ProVersion)
                return;

            packet.ReadInt32();//gameid
            packet.ReadInt16();

            Game.AddPlayer(this);
            IsAuthentified = true;
        }
Ejemplo n.º 16
0
        private void OnChat(GameClientPacket packet)
        {
            string msg = packet.ReadUnicode(256);

            Game.Chat(this, msg);
        }
Ejemplo n.º 17
0
        private void OnKick(GameClientPacket packet)
        {
            int pos = packet.ReadByte();

            Game.KickPlayer(this, pos);
        }
Ejemplo n.º 18
0
        private void OnHandResult(GameClientPacket packet)
        {
            int res = packet.ReadByte();

            Game.HandResult(this, res);
        }
Ejemplo n.º 19
0
        private void OnTpResult(GameClientPacket packet)
        {
            bool tp = packet.ReadByte() != 0;

            Game.TpResult(this, tp);
        }
Ejemplo n.º 20
0
 private void OnPlayerInfo(GameClientPacket packet) {
     if (Name != null)
         return;
     Name = packet.ReadUnicode(20);
 }
Ejemplo n.º 21
0
        public void Parse(GameClientPacket packet)
        {
            if (_isError)
            {
                return;
            }

            CtosMessage msg = packet.ReadCtos();

            switch (msg)
            {
            case CtosMessage.PlayerInfo:
                OnPlayerInfo(packet);
                break;

            case CtosMessage.JoinGame:
                OnJoinGame(packet);
                break;
            }
            if (!IsAuthentified)
            {
                return;
            }
            switch (msg)
            {
            case CtosMessage.Chat:
                OnChat(packet);
                break;

            case CtosMessage.HsToDuelist:
                Game.MoveToDuelist(this);
                break;

            case CtosMessage.HsToObserver:
                Game.MoveToObserver(this);
                break;

            case CtosMessage.LeaveGame:
                Game.RemovePlayer(this);
                break;

            case CtosMessage.HsReady:
                Game.SetReady(this, true);
                break;

            case CtosMessage.HsNotReady:
                Game.SetReady(this, false);
                break;

            case CtosMessage.HsKick:
                OnKick(packet);
                break;

            case CtosMessage.HsStart:
                Game.StartDuel(this);
                break;

            case CtosMessage.HandResult:
                OnHandResult(packet);
                break;

            case CtosMessage.TpResult:
                OnTpResult(packet);
                break;

            case CtosMessage.UpdateDeck:
                OnUpdateDeck(packet);
                break;

            case CtosMessage.Response:
                OnResponse(packet);
                break;

            case CtosMessage.Surrender:
                Game.Surrender(this, 0);
                break;
            }
        }