private void OnJoinGame(GameServerPacket packet)
        {
            uint banlist = packet.ReadUInt32();
            int  rule    = packet.ReadByte();
            int  mode    = packet.ReadByte();

            //TODO tag
            _room.IsTag = mode == 2;
            Logger.WriteLine("istag = " + _room.IsTag);

            GameClientPacket deck = new GameClientPacket(CtosMessage.UpdateDeck);

            deck.Write(Deck.Cards.Count + Deck.ExtraCards.Count);
            deck.Write(Deck.SideCards.Count);
            foreach (Card card in Deck.Cards)
            {
                deck.Write(card.Id);
            }
            foreach (Card card in Deck.ExtraCards)
            {
                deck.Write(card.Id);
            }
            foreach (Card card in Deck.SideCards)
            {
                deck.Write(card.Id);
            }
            Connection.Send(deck);
        }
예제 #2
0
        private void OnJoinGame(GameServerPacket packet)
        {
            GameClientPacket deck = new GameClientPacket(CtosMessage.UpdateDeck);

            deck.Write(Deck.Cards.Count + Deck.ExtraCards.Count);
            deck.Write(Deck.SideCards.Count);
            foreach (CardData card in Deck.Cards)
            {
                deck.Write(card.Id);
            }
            foreach (CardData card in Deck.ExtraCards)
            {
                deck.Write(card.Id);
            }
            foreach (CardData card in Deck.SideCards)
            {
                deck.Write(card.Id);
            }
            if (!Game.IsCheckmate)
            {
                Connection.Send(deck);
            }
            else
            {
                Connection.Send(CtosMessage.HsToDuelist);
                Connection.Send(deck);
                Connection.Send(CtosMessage.HsReady);
            }
        }
        private void OnSelectCounter(GameServerPacket packet)
        {
            packet.ReadByte();             // player
            int type     = packet.ReadInt16();
            int quantity = packet.ReadByte();

            IList <ClientCard> cards    = new List <ClientCard>();
            IList <int>        counters = new List <int>();
            int count = packet.ReadByte();

            for (int i = 0; i < count; ++i)
            {
                packet.ReadInt32();                 // card id
                int          player = GetLocalPlayer(packet.ReadByte());
                CardLocation loc    = (CardLocation)packet.ReadByte();
                int          seq    = packet.ReadByte();
                int          num    = packet.ReadByte();
                cards.Add(_duel.GetCard(player, loc, seq));
                counters.Add(num);
            }

            IList <int> used = _ai.OnSelectCounter(type, quantity, cards, counters);

            byte[] result = new byte[used.Count];
            for (int i = 0; i < quantity; ++i)
            {
                result[i] = (byte)used[i];
            }
            GameClientPacket reply = new GameClientPacket(CtosMessage.Response);

            reply.Write(result);
            Connection.Send(reply);
        }
예제 #4
0
        public void Chat(string message)
        {
            byte[]           content = Encoding.Unicode.GetBytes(message + "\0");
            GameClientPacket chat    = new GameClientPacket(CtosMessage.Chat);

            chat.Write(content);
            Connection.Send(chat);
        }
예제 #5
0
        public void Start()
        {
            Connection = new GameConnection(IPAddress.Parse(_serverHost), _serverPort);
            _behavior  = new GameBehavior(this);

            GameClientPacket packet = new GameClientPacket(CtosMessage.PlayerInfo);

            packet.Write(Username, 20);
            Connection.Send(packet);

            byte[] junk = { 0xCC, 0xCC, 0x00, 0x00, 0x00, 0x00 };
            packet = new GameClientPacket(CtosMessage.JoinGame);
            packet.Write(Program.ProVersion);
            packet.Write(junk);
            packet.Write(_roomInfos, 30);
            Connection.Send(packet);
        }
예제 #6
0
        public void Start()
        {
            Connection = new GameConnection(IPAddress.Parse(m_server.ServerAddress), m_server.ServerPort);
            m_behavior = new GameBehavior(this);

            GameClientPacket packet = new GameClientPacket(CtosMessage.PlayerInfo);

            packet.Write(Program.Config.Username + "$" + (IsCheckmate ? Program.Config.Password : DevClient.Token.ToString()), 20);
            Connection.Send(packet);

            byte[] junk = { 0xCC, 0xCC, 0x00, 0x00, 0x00, 0x00 };
            packet = new GameClientPacket(CtosMessage.JoinGame);
            packet.Write(Version);
            packet.Write(junk);
            packet.Write(m_roomInfos, 30);
            Connection.Send(packet);
        }
        private void OnSelectSum(GameServerPacket packet)
        {
            packet.ReadByte();             // mode
            packet.ReadByte();             // player
            int sumval = packet.ReadInt32();
            int min    = packet.ReadByte();
            int max    = packet.ReadByte();

            IList <ClientCard> cards = new List <ClientCard>();
            int count = packet.ReadByte();

            for (int i = 0; i < count; ++i)
            {
                int          cardId = packet.ReadInt32();
                int          player = GetLocalPlayer(packet.ReadByte());
                CardLocation loc    = (CardLocation)packet.ReadByte();
                int          seq    = packet.ReadByte();
                ClientCard   card   = _duel.GetCard(player, loc, seq);
                if (card != null)
                {
                    if (cardId != 0 && card.Id != cardId)
                    {
                        card.SetId(cardId);
                    }
                    cards.Add(card);
                }
                packet.ReadInt32();
            }

            IList <ClientCard> selected = _ai.OnSelectSum(cards, sumval, min, max);

            byte[] result = new byte[selected.Count + 1];
            result[0] = (byte)selected.Count;
            for (int i = 0; i < selected.Count; ++i)
            {
                int id = 0;
                for (int j = 0; j < count; ++j)
                {
                    if (cards[j] == null)
                    {
                        continue;
                    }
                    if (cards[j].Equals(selected[i]))
                    {
                        id = j;
                        break;
                    }
                }
                result[i + 1] = (byte)id;
            }

            GameClientPacket reply = new GameClientPacket(CtosMessage.Response);

            reply.Write(result);
            Connection.Send(reply);
        }
예제 #8
0
        private void OnJoinGame(GameServerPacket packet)
        {
            GameClientPacket deck = new GameClientPacket(CtosMessage.UpdateDeck);

            deck.Write(Deck.Cards.Count + Deck.ExtraCards.Count);
            deck.Write(Deck.SideCards.Count);
            foreach (CardData card in Deck.Cards)
            {
                deck.Write(card.Id);
            }
            foreach (CardData card in Deck.ExtraCards)
            {
                deck.Write(card.Id);
            }
            foreach (CardData card in Deck.SideCards)
            {
                deck.Write(card.Id);
            }
            Connection.Send(deck);
        }
예제 #9
0
        public void Start()
        {
            Connection = new AIGameConnection(IPAddress.Parse(_serverHost), _serverPort);
            _behavior  = new GameBehavior(this);

            GameClientPacket packet = new GameClientPacket(CtosMessage.PlayerInfo);

            packet.Write(Username, 20);
            Connection.Send(packet);

            byte[] junk = { 0xCC, 0xCC, 0x00, 0x00, 0x00, 0x00 };
            packet = new GameClientPacket(CtosMessage.JoinGame);
            packet.Write((short)Program.ProVersion);
            packet.Write(junk);

            packet.Write(_roomInfos, 30);


            Deck deck = Deck.Load(Deck_);

            if (deck == null)
            {
                Logger.WriteLine("read deck fail.");
                Connection.Close();
                return;
            }

            packet.Write((byte)CtosMessage.UpdateDeck);

            packet.Write(deck.Cards.Count);
            packet.Write(deck.SideCards.Count);

            foreach (var k in deck.Cards)
            {
                packet.Write(k.Id);
            }

            foreach (var k in deck.SideCards)
            {
                packet.Write(k.Id);
            }

            packet.Write((byte)CtosMessage.HsReady);
            Connection.Send(packet);
            Logger.WriteLine("send deck");
        }
        private void OnChangeSide(GameServerPacket packet)
        {
            GameClientPacket deck = new GameClientPacket(CtosMessage.UpdateDeck);

            deck.Write(Deck.Cards.Count + Deck.ExtraCards.Count);
            deck.Write(Deck.SideCards.Count);
            foreach (Card card in Deck.Cards)
            {
                deck.Write(card.Id);
            }
            foreach (Card card in Deck.ExtraCards)
            {
                deck.Write(card.Id);
            }
            foreach (Card card in Deck.SideCards)
            {
                deck.Write(card.Id);
            }
            Connection.Send(deck);
            Logger.WriteLine("onChangeSide");
        }
        private void OnSelectPlace(GameServerPacket packet)
        {
            packet.ReadByte();             // player
            packet.ReadByte();             // min
            int field = ~packet.ReadInt32();

            byte[] resp = new byte[3];

            bool pendulumZone = false;

            int filter;

            if ((field & 0x1f) != 0)
            {
                resp[0] = (byte)GetLocalPlayer(0);
                resp[1] = 0x4;
                filter  = field & 0x1f;
            }
            else if ((field & 0x1f00) != 0)
            {
                resp[0] = (byte)GetLocalPlayer(0);
                resp[1] = 0x8;
                filter  = (field >> 8) & 0x1f;
            }
            else if ((field & 0xc000) != 0)
            {
                resp[0]      = (byte)GetLocalPlayer(0);
                resp[1]      = 0x8;
                filter       = (field >> 14) & 0x3;
                pendulumZone = true;
            }
            else if ((field & 0x1f0000) != 0)
            {
                resp[0] = (byte)GetLocalPlayer(1);
                resp[1] = 0x4;
                filter  = (field >> 16) & 0x1f;
            }
            else if ((field & 0x1f000000) != 0)
            {
                resp[0] = (byte)GetLocalPlayer(1);
                resp[1] = 0x8;
                filter  = (field >> 24) & 0x1f;
            }
            else
            {
                resp[0]      = (byte)GetLocalPlayer(1);
                resp[1]      = 0x8;
                filter       = (field >> 30) & 0x3;
                pendulumZone = true;
            }

            if (!pendulumZone)
            {
                if ((filter & 0x4) != 0)
                {
                    resp[2] = 2;
                }
                else if ((filter & 0x2) != 0)
                {
                    resp[2] = 1;
                }
                else if ((filter & 0x8) != 0)
                {
                    resp[2] = 3;
                }
                else if ((filter & 0x1) != 0)
                {
                    resp[2] = 0;
                }
                else if ((filter & 0x10) != 0)
                {
                    resp[2] = 4;
                }
            }
            else
            {
                if ((filter & 0x1) != 0)
                {
                    resp[2] = 6;
                }
                if ((filter & 0x2) != 0)
                {
                    resp[2] = 7;
                }
            }

            GameClientPacket reply = new GameClientPacket(CtosMessage.Response);

            reply.Write(resp);
            Connection.Send(reply);
        }
        private void InternalOnSelectCard(GameServerPacket packet, Func <IList <ClientCard>, int, int, bool, IList <ClientCard> > func)
        {
            packet.ReadByte();             // player
            bool cancelable = packet.ReadByte() != 0;
            int  min        = packet.ReadByte();
            int  max        = packet.ReadByte();

            IList <ClientCard> cards = new List <ClientCard>();
            int count = packet.ReadByte();

            for (int i = 0; i < count; ++i)
            {
                int          id     = packet.ReadInt32();
                int          player = GetLocalPlayer(packet.ReadByte());
                CardLocation loc    = (CardLocation)packet.ReadByte();
                int          seq    = packet.ReadByte();
                packet.ReadByte();                 // pos
                ClientCard card;
                if (((int)loc & (int)CardLocation.Overlay) != 0)
                {
                    card = new ClientCard(id, CardLocation.Overlay);
                }
                else
                {
                    card = _duel.GetCard(player, loc, seq);
                }
                if (card == null)
                {
                    continue;
                }
                if (card.Id == 0)
                {
                    card.SetId(id);
                }
                cards.Add(card);
            }

            IList <ClientCard> selected = func(cards, min, max, cancelable);

            if (selected.Count == 0 && cancelable)
            {
                Connection.Send(CtosMessage.Response, -1);
                return;
            }

            byte[] result = new byte[selected.Count + 1];
            result[0] = (byte)selected.Count;
            for (int i = 0; i < selected.Count; ++i)
            {
                int id = 0;
                for (int j = 0; j < count; ++j)
                {
                    if (cards[j] == null)
                    {
                        continue;
                    }
                    if (cards[j].Equals(selected[i]))
                    {
                        id = j;
                        break;
                    }
                }
                result[i + 1] = (byte)id;
            }

            GameClientPacket reply = new GameClientPacket(CtosMessage.Response);

            reply.Write(result);
            Connection.Send(reply);
        }