예제 #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;
            }
        }
예제 #2
0
 private void OnPlayerInfo(GameClientPacket packet)
 {
     if (Name != null)
     {
         return;
     }
     Name = packet.ReadUnicode(20);
 }
예제 #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);
            }
        }
예제 #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);
 }
예제 #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();
            }
        }
예제 #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;
        }
예제 #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);
                }
            }
        }
예제 #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);
            }
        }
예제 #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();
            }
        }
예제 #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);
 }
예제 #11
0
 private void OnHandResult(GameClientPacket packet) {
     int res = packet.ReadByte();
     Game.HandResult(this, res);
 }
예제 #12
0
 private void OnTpResult(GameClientPacket packet) {
     bool tp = packet.ReadByte() != 0;
     Game.TpResult(this, tp);
 }
예제 #13
0
 private void OnChat(GameClientPacket packet) {
     string msg = packet.ReadUnicode(256);
     Game.Chat(this, msg);
 }
예제 #14
0
 private void OnKick(GameClientPacket packet) {
     int pos = packet.ReadByte();
     Game.KickPlayer(this, pos);
 }
예제 #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;
        }
예제 #16
0
        private void OnChat(GameClientPacket packet)
        {
            string msg = packet.ReadUnicode(256);

            Game.Chat(this, msg);
        }
예제 #17
0
        private void OnKick(GameClientPacket packet)
        {
            int pos = packet.ReadByte();

            Game.KickPlayer(this, pos);
        }
예제 #18
0
        private void OnHandResult(GameClientPacket packet)
        {
            int res = packet.ReadByte();

            Game.HandResult(this, res);
        }
예제 #19
0
        private void OnTpResult(GameClientPacket packet)
        {
            bool tp = packet.ReadByte() != 0;

            Game.TpResult(this, tp);
        }
예제 #20
0
 private void OnPlayerInfo(GameClientPacket packet) {
     if (Name != null)
         return;
     Name = packet.ReadUnicode(20);
 }
예제 #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;
            }
        }