Exemple #1
0
        private void OnMove(CoreMessage msg)
        {
            byte[] raw = msg.Reader.ReadBytes(16);
            int    pc  = raw[4];
            int    pl  = raw[5];
            int    cc  = raw[8];
            int    cl  = raw[9];
            int    cs  = raw[10];
            int    cp  = raw[11];

            SendToPlayer(msg, cc);
            GameServerPacket packet = new GameServerPacket(msg.Message);

            packet.Write(raw);
            if (!Convert.ToBoolean((cl & ((int)CardLocation.Grave + (int)CardLocation.Overlay))) && Convert.ToBoolean((cl & ((int)CardLocation.Deck + (int)CardLocation.Hand))) ||
                Convert.ToBoolean((cp & (int)CardPosition.FaceDown)))
            {
                packet.SetPosition(2);
                packet.Write(0);
            }
            Game.SendToAllBut(packet, cc);

            if (cl != 0 && (cl & 0x80) == 0 && (cl != pl || pc != cc))
            {
                Game.RefreshSingle(cc, cl, cs);
            }
        }
Exemple #2
0
        private void SendJoinGame(Player player)
        {
            GameServerPacket join = new GameServerPacket(StocMessage.JoinGame);

            join.Write(Banlist == null ? 0U : Banlist.Hash);
            join.Write((byte)Config.Rule);
            join.Write((byte)Config.Mode);
            join.Write(Config.EnablePriority);
            join.Write(Config.NoCheckDeck);
            join.Write(Config.NoShuffleDeck);
            // C++ padding: 5 bytes + 3 bytes = 8 bytes
            for (int i = 0; i < 3; i++)
            {
                join.Write((byte)0);
            }
            join.Write(Config.StartLp);
            join.Write((byte)Config.StartHand);
            join.Write((byte)Config.DrawCount);
            join.Write((short)Config.GameTimer);
            player.Send(join);

            if (State != GameState.Lobby)
            {
                SendDuelingPlayers(player);
            }
        }
Exemple #3
0
        public void Surrender(Player player, int reason, bool force = false)
        {
            if (!force)
            {
                if (State != GameState.Duel)
                {
                    return;
                }
            }
            if (player.Type == (int)PlayerType.Observer)
            {
                return;
            }
            GameServerPacket win = new GameServerPacket(GameMessage.Win);
            int team             = player.Type;

            if (IsTag)
            {
                team = player.Type >= 2 ? 1 : 0;
            }
            else if (State == GameState.Hand)
            {
                team = 1 - team;
            }
            win.Write((byte)(1 - team));
            win.Write((byte)reason);
            SendToAll(win);

            MatchSaveResult(1 - team);

            EndDuel(reason == 4);
        }
Exemple #4
0
 public void RemovePlayer(Player player)
 {
     if (player.Equals(HostPlayer) && State == GameState.Lobby)
     {
         _server.Stop();
     }
     else if (player.Type == (int)PlayerType.Observer)
     {
         Observers.Remove(player);
         if (State == GameState.Lobby)
         {
             GameServerPacket nwatch = new GameServerPacket(StocMessage.HsWatchChange);
             nwatch.Write((short)Observers.Count);
             SendToAll(nwatch);
         }
         player.Disconnect();
     }
     else if (State == GameState.Lobby)
     {
         Players[player.Type] = null;
         IsReady[player.Type] = false;
         GameServerPacket change = new GameServerPacket(StocMessage.HsPlayerChange);
         change.Write((byte)((player.Type << 4) + (int)PlayerChange.Leave));
         SendToAll(change);
         player.Disconnect();
     }
     else
     {
         Surrender(player, 4, true);
     }
 }
Exemple #5
0
 public void SendToObservers(GameServerPacket packet)
 {
     foreach (Player player in Observers)
     {
         player.Send(packet);
     }
 }
Exemple #6
0
 private void SendDuelingPlayers(Player player)
 {
     for (int i = 0; i < Players.Length; i++)
     {
         GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter);
         int id = i;
         if (_swapped)
         {
             if (IsTag)
             {
                 if (i == 0 || id == 1)
                 {
                     id = i + 2;
                 }
                 else
                 {
                     id = i - 2;
                 }
             }
             else
             {
                 id = 1 - i;
             }
         }
         enter.Write(Players[id].Name, 20);
         enter.Write((byte)i);
         //padding
         enter.Write((byte)0);
         player.Send(enter);
     }
 }
Exemple #7
0
        private void OnDraw(CoreMessage msg)
        {
            GameServerPacket packet = new GameServerPacket(msg.Message);
            int player = msg.Reader.ReadByte();
            int count  = msg.Reader.ReadByte();

            packet.Write((byte)player);
            packet.Write((byte)count);

            for (int i = 0; i < count; i++)
            {
                uint code = msg.Reader.ReadUInt32();
                if ((code & 0x80000000) != 0)
                {
                    packet.Write(code);
                }
                else
                {
                    packet.Write(0);
                }
            }

            SendToPlayer(msg, player);
            Game.SendToAllBut(packet, player);
        }
Exemple #8
0
        public void SendTypeChange()
        {
            GameServerPacket packet = new GameServerPacket(StocMessage.TypeChange);

            packet.Write((byte)(Type + (Game.HostPlayer.Equals(this) ? (int)PlayerType.Host : 0)));
            Send(packet);
        }
Exemple #9
0
        public void SendErrorMessage(string message) {
            _isError = true;

            GameServerPacket join = new GameServerPacket(StocMessage.JoinGame);
            join.Write(0U);
            join.Write((byte)0);
            join.Write((byte)0);
            join.Write(false);
            join.Write(false);
            join.Write(false);
            // C++ padding: 5 bytes + 3 bytes = 8 bytes
            for (int i = 0; i < 3; i++)
                join.Write((byte)0);
            join.Write(8000);
            join.Write(5);
            join.Write(1);
            join.Write(0);
            Send(join);

            GameServerPacket packet = new GameServerPacket(StocMessage.TypeChange);
            packet.Write((byte)(0));
            Send(packet);

            GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter);
            enter.Write("[Error occurred]:", 20);
            enter.Write((byte)0);
            Send(enter);

            enter = new GameServerPacket(StocMessage.HsPlayerEnter);
            enter.Write(message, 20);
            enter.Write((byte)1);
            Send(enter);
        }
Exemple #10
0
        public void MoveToObserver(Player player)
        {
            if (State != GameState.Lobby)
            {
                return;
            }
            if (player.Type == (int)PlayerType.Observer)
            {
                return;
            }
            if (IsReady[player.Type])
            {
                return;
            }
            Players[player.Type] = null;
            IsReady[player.Type] = false;
            Observers.Add(player);

            GameServerPacket change = new GameServerPacket(StocMessage.HsPlayerChange);

            change.Write((byte)((player.Type << 4) + (int)PlayerChange.Observe));
            SendToAll(change);

            player.Type = (int)PlayerType.Observer;
            player.SendTypeChange();
        }
Exemple #11
0
        private void OnSelectCard(CoreMessage msg)
        {
            GameServerPacket packet = new GameServerPacket(msg.Message);

            int player = msg.Reader.ReadByte();

            packet.Write((byte)player);
            packet.Write(msg.Reader.ReadBytes(3));

            int count = msg.Reader.ReadByte();

            packet.Write((byte)count);

            for (int i = 0; i < count; i++)
            {
                int code = msg.Reader.ReadInt32();
                int pl   = msg.Reader.ReadByte();
                int loc  = msg.Reader.ReadByte();
                int seq  = msg.Reader.ReadByte();
                int pos  = msg.Reader.ReadByte();
                packet.Write(pl == player ? code : 0);
                packet.Write((byte)pl);
                packet.Write((byte)loc);
                packet.Write((byte)seq);
                packet.Write((byte)pos);
            }

            Game.WaitForResponse(player);
            Game.CurPlayers[player].Send(packet);
        }
Exemple #12
0
 public void SendToAllBut(GameServerPacket packet, Player except) {
     foreach (Player player in Players)
         if (player != null && !player.Equals(except))
             player.Send(packet);
     foreach (Player player in Observers)
         if (!player.Equals(except))
             player.Send(packet);
 }
Exemple #13
0
        private void SendToAll(CoreMessage msg)
        {
            byte[]           buffer = msg.CreateBuffer();
            GameServerPacket packet = new GameServerPacket(msg.Message);

            packet.Write(buffer);
            Game.SendToAll(packet);
        }
Exemple #14
0
        public void CustomMessage(Player player, string msg)
        {
            string           finalmsg = msg;
            GameServerPacket packet   = new GameServerPacket(StocMessage.Chat);

            packet.Write((short)PlayerType.Yellow);
            packet.Write(finalmsg, finalmsg.Length + 1);
            SendToAllBut(packet, player);
        }
Exemple #15
0
 public void SendToPlayers(GameServerPacket packet)
 {
     foreach (Player player in Players)
     {
         if (player != null)
         {
             player.Send(packet);
         }
     }
 }
Exemple #16
0
        private void HandleError(string error)
        {
            GameServerPacket packet = new GameServerPacket(StocMessage.Chat);

            packet.Write((short)PlayerType.Observer);
            packet.Write(error, error.Length + 1);
            SendToAll(packet);

            File.WriteAllText("lua_" + DateTime.UtcNow.ToString("yyyy-MM-dd_HH-mm-ss") + ".txt", error);
        }
Exemple #17
0
        public void RefreshExtra(int player, int flag = 0x81fff, bool useCache = true)
        {
            byte[]           result = _duel.QueryFieldCard(player, CardLocation.Extra, flag, useCache);
            GameServerPacket update = new GameServerPacket(GameMessage.UpdateData);

            update.Write((byte)player);
            update.Write((byte)CardLocation.Extra);
            update.Write(result);
            CurPlayers[player].Send(update);
        }
Exemple #18
0
        public void RefreshGrave(int player, int flag = 0x81fff, bool useCache = true)
        {
            byte[]           result = _duel.QueryFieldCard(player, CardLocation.Grave, flag, useCache);
            GameServerPacket update = new GameServerPacket(GameMessage.UpdateData);

            update.Write((byte)player);
            update.Write((byte)CardLocation.Grave);
            update.Write(result);
            SendToAll(update);
        }
Exemple #19
0
        private void OnSet(CoreMessage msg)
        {
            msg.Reader.ReadBytes(4);
            byte[]           raw    = msg.Reader.ReadBytes(4);
            GameServerPacket packet = new GameServerPacket(GameMessage.Set);

            packet.Write(0);
            packet.Write(raw);
            Game.SendToAll(packet);
        }
Exemple #20
0
        private void InitNewSpectator(Player player)
        {
            int deck1 = _duel.QueryFieldCount(0, CardLocation.Deck);
            int deck2 = _duel.QueryFieldCount(1, CardLocation.Deck);

            int hand1 = _duel.QueryFieldCount(0, CardLocation.Hand);
            int hand2 = _duel.QueryFieldCount(1, CardLocation.Hand);

            GameServerPacket packet = new GameServerPacket(GameMessage.Start);

            packet.Write((byte)(_swapped ? 0x11 : 0x10));
            packet.Write(LifePoints[0]);
            packet.Write(LifePoints[1]);
            packet.Write((short)(deck1 + hand1));
            packet.Write((short)_duel.QueryFieldCount(0, CardLocation.Extra));
            packet.Write((short)(deck2 + hand2));
            packet.Write((short)_duel.QueryFieldCount(1, CardLocation.Extra));
            player.Send(packet);

            GameServerPacket draw = new GameServerPacket(GameMessage.Draw);

            draw.Write((byte)0);
            draw.Write((byte)hand1);
            for (int i = 0; i < hand1; i++)
            {
                draw.Write(0);
            }
            player.Send(draw);

            draw = new GameServerPacket(GameMessage.Draw);
            draw.Write((byte)1);
            draw.Write((byte)hand2);
            for (int i = 0; i < hand2; i++)
            {
                draw.Write(0);
            }
            player.Send(draw);

            GameServerPacket turn = new GameServerPacket(GameMessage.NewTurn);

            turn.Write((byte)0);
            player.Send(turn);
            if (CurrentPlayer == 1)
            {
                turn = new GameServerPacket(GameMessage.NewTurn);
                turn.Write((byte)0);
                player.Send(turn);
            }

            InitSpectatorLocation(player, CardLocation.MonsterZone);
            InitSpectatorLocation(player, CardLocation.SpellZone);
            InitSpectatorLocation(player, CardLocation.Grave);
            InitSpectatorLocation(player, CardLocation.Removed);
        }
Exemple #21
0
        public void MoveToDuelist(Player player)
        {
            if (State != GameState.Lobby)
            {
                return;
            }
            int pos = GetAvailablePlayerPos();

            if (pos == -1)
            {
                return;
            }
            if (player.Type != (int)PlayerType.Observer)
            {
                if (!IsTag || IsReady[player.Type])
                {
                    return;
                }

                pos = (player.Type + 1) % 4;
                while (Players[pos] != null)
                {
                    pos = (pos + 1) % 4;
                }

                GameServerPacket change = new GameServerPacket(StocMessage.HsPlayerChange);
                change.Write((byte)((player.Type << 4) + pos));
                SendToAll(change);

                Players[player.Type] = null;
                Players[pos]         = player;
                player.Type          = pos;
                player.SendTypeChange();
            }
            else
            {
                Observers.Remove(player);
                Players[pos] = player;
                player.Type  = pos;

                GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter);
                enter.Write(player.Name, 20);
                enter.Write((byte)pos);
                //padding
                enter.Write((byte)0);
                SendToAll(enter);

                GameServerPacket nwatch = new GameServerPacket(StocMessage.HsWatchChange);
                nwatch.Write((short)Observers.Count);
                SendToAll(nwatch);

                player.SendTypeChange();
            }
        }
Exemple #22
0
 public void SendToAllBut(GameServerPacket packet, int except)
 {
     if (except < CurPlayers.Length)
     {
         SendToAllBut(packet, CurPlayers[except]);
     }
     else
     {
         SendToAll(packet);
     }
 }
Exemple #23
0
        private void SendToPlayer(CoreMessage msg, int player)
        {
            if (player != 0 && player != 1)
            {
                return;
            }
            byte[]           buffer = msg.CreateBuffer();
            GameServerPacket packet = new GameServerPacket(msg.Message);

            packet.Write(buffer);
            Game.CurPlayers[player].Send(packet);
        }
Exemple #24
0
        public void WaitForResponse(int player)
        {
            _lastresponse            = player;
            CurPlayers[player].State = PlayerState.Response;
            SendToAllBut(new GameServerPacket(GameMessage.Waiting), player);
            TimeStart();
            GameServerPacket packet = new GameServerPacket(StocMessage.TimeLimit);

            packet.Write((byte)player);
            packet.Write((byte)0); // C++ padding
            packet.Write((short)_timelimit[player]);
            SendToPlayers(packet);
        }
Exemple #25
0
        public void SetReady(Player player, bool ready)
        {
            if (State != GameState.Lobby)
            {
                return;
            }
            if (player.Type == (int)PlayerType.Observer)
            {
                return;
            }
            if (IsReady[player.Type] == ready)
            {
                return;
            }

            if (ready)
            {
                bool ocg    = Config.Rule == 0 || Config.Rule == 2;
                bool tcg    = Config.Rule == 1 || Config.Rule == 2;
                int  result = 1;
                if (player.Deck != null)
                {
                    result = Config.NoCheckDeck ? 0 : player.Deck.Check(Banlist, ocg, tcg);
                }
                if (result != 0)
                {
                    GameServerPacket rechange = new GameServerPacket(StocMessage.HsPlayerChange);
                    rechange.Write((byte)((player.Type << 4) + (int)(PlayerChange.NotReady)));
                    player.Send(rechange);
                    GameServerPacket error = new GameServerPacket(StocMessage.ErrorMsg);
                    error.Write((byte)2); // ErrorMsg.DeckError
                    // C++ padding: 1 byte + 3 bytes = 4 bytes
                    for (int i = 0; i < 3; i++)
                    {
                        error.Write((byte)0);
                    }
                    error.Write(result);
                    player.Send(error);
                    return;
                }
            }

            IsReady[player.Type] = ready;

            GameServerPacket change = new GameServerPacket(StocMessage.HsPlayerChange);

            change.Write((byte)((player.Type << 4) + (int)(ready ? PlayerChange.Ready : PlayerChange.NotReady)));
            SendToAll(change);
        }
Exemple #26
0
        private void SendHand()
        {
            RpsTimer = DateTime.UtcNow;
            GameServerPacket hand = new GameServerPacket(StocMessage.SelectHand);

            if (IsTag)
            {
                Players[0].Send(hand);
                Players[2].Send(hand);
            }
            else
            {
                SendToPlayers(hand);
            }
        }
Exemple #27
0
        public void Chat(Player player, string msg)
        {
            GameServerPacket packet = new GameServerPacket(StocMessage.Chat);

            packet.Write((short)player.Type);
            if (player.Type == (int)PlayerType.Observer)
            {
                msg = "[" + player.Name + "]: " + msg;
                CustomMessage(player, msg);
            }
            else
            {
                packet.Write(msg, msg.Length + 1);
                SendToAllBut(packet, player);
            }
        }
Exemple #28
0
 public void SendToAllBut(GameServerPacket packet, Player except)
 {
     foreach (Player player in Players)
     {
         if (player != null && !player.Equals(except))
         {
             player.Send(packet);
         }
     }
     foreach (Player player in Observers)
     {
         if (!player.Equals(except))
         {
             player.Send(packet);
         }
     }
 }
Exemple #29
0
 public void SendToTeam(GameServerPacket packet, int team)
 {
     if (!IsTag)
     {
         Players[team].Send(packet);
     }
     else if (team == 0)
     {
         Players[0].Send(packet);
         Players[1].Send(packet);
     }
     else
     {
         Players[2].Send(packet);
         Players[3].Send(packet);
     }
 }
Exemple #30
0
        public void RefreshSingle(int player, int location, int sequence, int flag = 0x781fff)
        {
            byte[] result = _duel.QueryCard(player, location, sequence, flag);

            if (location == (int)CardLocation.Removed && (result[15] & (int)CardPosition.FaceDown) != 0)
            {
                return;
            }

            GameServerPacket update = new GameServerPacket(GameMessage.UpdateCard);

            update.Write((byte)player);
            update.Write((byte)location);
            update.Write((byte)sequence);
            update.Write(result);
            CurPlayers[player].Send(update);

            if (IsTag)
            {
                if ((location & (int)CardLocation.Onfield) != 0)
                {
                    SendToTeam(update, player);
                    if ((result[15] & (int)CardPosition.FaceUp) != 0)
                    {
                        SendToTeam(update, 1 - player);
                    }
                }
                else
                {
                    CurPlayers[player].Send(update);
                    if ((location & 0x90) != 0)
                    {
                        SendToAllBut(update, player);
                    }
                }
            }
            else
            {
                if ((location & 0x90) != 0 || ((location & 0x2c) != 0 && (result[15] & (int)CardPosition.FaceUp) != 0))
                {
                    SendToAllBut(update, player);
                }
            }
        }
Exemple #31
0
        private void OnShuffleHand(CoreMessage msg)
        {
            GameServerPacket packet = new GameServerPacket(msg.Message);
            int player = msg.Reader.ReadByte();
            int count  = msg.Reader.ReadByte();

            packet.Write((byte)player);
            packet.Write((byte)count);

            msg.Reader.ReadBytes(count * 4);
            for (int i = 0; i < count; i++)
            {
                packet.Write(0);
            }

            SendToPlayer(msg, player);
            Game.SendToAllBut(packet, player);
            Game.RefreshHand(player, 0x181fff, false);
        }
Exemple #32
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();
            }
        }
Exemple #33
0
 public void Send(GameServerPacket packet) {
     _client.Send(packet.GetContent());
 }
Exemple #34
0
 public void SendToPlayers(GameServerPacket packet) {
     foreach (Player player in Players)
         if (player != null)
             player.Send(packet);
 }
Exemple #35
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();
            }
        }
Exemple #36
0
 private void SendDuelingPlayers(Player player) {
     for (int i = 0; i < Players.Length; i++) {
         GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter);
         int id = i;
         if (_swapped) {
             if (IsTag) {
                 if (i == 0 || id == 1)
                     id = i + 2;
                 else
                     id = i - 2;
             } else
                 id = 1 - i;
         }
         enter.Write(Players[id].Name, 20);
         enter.Write((byte)i);
         //padding
         enter.Write((byte)0);
         player.Send(enter);
     }
 }
Exemple #37
0
        private void InitNewSpectator(Player player) {
            int deck1 = _duel.QueryFieldCount(0, CardLocation.Deck);
            int deck2 = _duel.QueryFieldCount(1, CardLocation.Deck);

            int hand1 = _duel.QueryFieldCount(0, CardLocation.Hand);
            int hand2 = _duel.QueryFieldCount(1, CardLocation.Hand);

            GameServerPacket packet = new GameServerPacket(GameMessage.Start);
            packet.Write((byte)(_swapped ? 0x11 : 0x10));
            packet.Write(LifePoints[0]);
            packet.Write(LifePoints[1]);
            packet.Write((short)(deck1 + hand1));
            packet.Write((short)_duel.QueryFieldCount(0, CardLocation.Extra));
            packet.Write((short)(deck2 + hand2));
            packet.Write((short)_duel.QueryFieldCount(1, CardLocation.Extra));
            player.Send(packet);

            GameServerPacket draw = new GameServerPacket(GameMessage.Draw);
            draw.Write((byte)0);
            draw.Write((byte)hand1);
            for (int i = 0; i < hand1; i++)
                draw.Write(0);
            player.Send(draw);

            draw = new GameServerPacket(GameMessage.Draw);
            draw.Write((byte)1);
            draw.Write((byte)hand2);
            for (int i = 0; i < hand2; i++)
                draw.Write(0);
            player.Send(draw);

            GameServerPacket turn = new GameServerPacket(GameMessage.NewTurn);
            turn.Write((byte)0);
            player.Send(turn);
            if (CurrentPlayer == 1) {
                turn = new GameServerPacket(GameMessage.NewTurn);
                turn.Write((byte)0);
                player.Send(turn);
            }

            InitSpectatorLocation(player, CardLocation.MonsterZone);
            InitSpectatorLocation(player, CardLocation.SpellZone);
            InitSpectatorLocation(player, CardLocation.Grave);
            InitSpectatorLocation(player, CardLocation.Removed);
        }
Exemple #38
0
 public void RefreshGrave(int player, int flag = 0x81fff, bool useCache = true) {
     byte[] result = _duel.QueryFieldCard(player, CardLocation.Grave, flag, useCache);
     GameServerPacket update = new GameServerPacket(GameMessage.UpdateData);
     update.Write((byte)player);
     update.Write((byte)CardLocation.Grave);
     update.Write(result);
     SendToAll(update);
 }
Exemple #39
0
        private void SendJoinGame(Player player) {
            GameServerPacket join = new GameServerPacket(StocMessage.JoinGame);
            join.Write(Banlist == null ? 0U : Banlist.Hash);
            join.Write((byte)Config.Rule);
            join.Write((byte)Config.Mode);
            join.Write(Config.EnablePriority);
            join.Write(Config.NoCheckDeck);
            join.Write(Config.NoShuffleDeck);
            // C++ padding: 5 bytes + 3 bytes = 8 bytes
            for (int i = 0; i < 3; i++)
                join.Write((byte)0);
            join.Write(Config.StartLp);
            join.Write((byte)Config.StartHand);
            join.Write((byte)Config.DrawCount);
            join.Write((short)Config.GameTimer);
            player.Send(join);

            if (State != GameState.Lobby)
                SendDuelingPlayers(player);
        }
        private void OnConfirmCards(CoreMessage msg)
        {
            int player = msg.Reader.ReadByte();
            int count = msg.Reader.ReadByte();
            msg.Reader.ReadBytes(count * 7);

            byte[] buffer = msg.CreateBuffer();
            GameServerPacket packet = new GameServerPacket(msg.Message);
            packet.Write(buffer);
            if ((CardLocation)buffer[7] == CardLocation.Hand)
                Game.SendToAll(packet);
            else
                Game.CurPlayers[player].Send(packet);
        }
Exemple #41
0
        public void RefreshSpells(int player, int flag = 0x681fff, bool useCache = true) {
            byte[] result = _duel.QueryFieldCard(player, CardLocation.SpellZone, flag, useCache);
            GameServerPacket update = new GameServerPacket(GameMessage.UpdateData);
            update.Write((byte)player);
            update.Write((byte)CardLocation.SpellZone);
            update.Write(result);
            SendToTeam(update, player);

            update = new GameServerPacket(GameMessage.UpdateData);
            update.Write((byte)player);
            update.Write((byte)CardLocation.SpellZone);

            MemoryStream ms = new MemoryStream(result);
            BinaryReader reader = new BinaryReader(ms);
            BinaryWriter writer = new BinaryWriter(ms);
            for (int i = 0; i < 8; i++) {
                int len = reader.ReadInt32();
                if (len == 4)
                    continue;
                long pos = ms.Position;
                byte[] raw = reader.ReadBytes(len - 4);
                if ((raw[11] & (int)CardPosition.FaceDown) != 0) {
                    ms.Position = pos;
                    writer.Write(new byte[len - 4]);
                }
            }
            update.Write(result);

            SendToTeam(update, 1 - player);
            SendToObservers(update);
        }
Exemple #42
0
        public void EndDuel(bool force) {
            if (State == GameState.Duel) {
                if (!Replay.Disabled) {
                    Replay.End();
                    byte[] replayData = Replay.GetContent();
                    GameServerPacket packet = new GameServerPacket(StocMessage.Replay);
                    packet.Write(replayData);
                    SendToAll(packet);
                }

                State = GameState.End;
                _duel.End();
            }

            if (_swapped) {
                _swapped = false;
                if (IsTag) {
                    Player temp = Players[0];
                    Players[0] = Players[2];
                    Players[2] = temp;

                    temp = Players[1];
                    Players[1] = Players[3];
                    Players[3] = temp;

                    Players[0].Type = 0;
                    Players[1].Type = 1;
                    Players[2].Type = 2;
                    Players[3].Type = 3;
                } else {
                    Player temp = Players[0];
                    Players[0] = Players[1];
                    Players[1] = temp;
                    Players[0].Type = 0;
                    Players[1].Type = 1;
                }
            }

            if (IsMatch && !force && !MatchIsEnd()) {
                IsReady[0] = false;
                IsReady[1] = false;
                State = GameState.Side;
                SideTimer = DateTime.UtcNow;
                SendToPlayers(new GameServerPacket(StocMessage.ChangeSide));
                SendToObservers(new GameServerPacket(StocMessage.WaitingSide));
            } else {
                if (State == GameState.Hand) {
                    State = GameState.End;
                    End();
                } else {
                    ApplyRanking();
                    End();
                }
            }
        }
        private void OnHint(CoreMessage msg)
        {
            int type = msg.Reader.ReadByte();
            int player = msg.Reader.ReadByte();
            msg.Reader.ReadInt32();

            byte[] buffer = msg.CreateBuffer();
            GameServerPacket packet = new GameServerPacket(msg.Message);
            packet.Write(buffer);

            switch (type)
            {
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                    Game.CurPlayers[player].Send(packet);
                    break;
                case 6:
                case 7:
                case 8:
                case 9:
                    Game.SendToAllBut(packet, player);
                    break;
                case 10:
                    if (Game.IsTag)
                        Game.CurPlayers[player].Send(packet);
                    else
                        Game.SendToAll(packet);
                    break;
            }
        }
Exemple #44
0
 public void WaitForResponse(int player) {
     _lastresponse = player;
     CurPlayers[player].State = PlayerState.Response;
     SendToAllBut(new GameServerPacket(GameMessage.Waiting), player);
     TimeStart();
     GameServerPacket packet = new GameServerPacket(StocMessage.TimeLimit);
     packet.Write((byte)player);
     packet.Write((byte)0); // C++ padding
     packet.Write((short)_timelimit[player]);
     SendToPlayers(packet);
 }
Exemple #45
0
        public void RefreshSingle(int player, int location, int sequence, int flag = 0x781fff) {
            byte[] result = _duel.QueryCard(player, location, sequence, flag);

            if (location == (int)CardLocation.Removed && (result[15] & (int)CardPosition.FaceDown) != 0)
                return;

            GameServerPacket update = new GameServerPacket(GameMessage.UpdateCard);
            update.Write((byte)player);
            update.Write((byte)location);
            update.Write((byte)sequence);
            update.Write(result);
            CurPlayers[player].Send(update);

            if (IsTag) {
                if ((location & (int)CardLocation.Onfield) != 0) {
                    SendToTeam(update, player);
                    if ((result[15] & (int)CardPosition.FaceUp) != 0)
                        SendToTeam(update, 1 - player);
                } else {
                    CurPlayers[player].Send(update);
                    if ((location & 0x90) != 0)
                        SendToAllBut(update, player);
                }
            } else {
                if ((location & 0x90) != 0 || ((location & 0x2c) != 0 && (result[15] & (int)CardPosition.FaceUp) != 0))
                    SendToAllBut(update, player);
            }
        }
Exemple #46
0
 public void RefreshExtra(int player, int flag = 0x81fff, bool useCache = true) {
     byte[] result = _duel.QueryFieldCard(player, CardLocation.Extra, flag, useCache);
     GameServerPacket update = new GameServerPacket(GameMessage.UpdateData);
     update.Write((byte)player);
     update.Write((byte)CardLocation.Extra);
     update.Write(result);
     CurPlayers[player].Send(update);
 }
Exemple #47
0
 public void SendTypeChange() {
     GameServerPacket packet = new GameServerPacket(StocMessage.TypeChange);
     packet.Write((byte)(Type + (Game.HostPlayer.Equals(this) ? (int)PlayerType.Host : 0)));
     Send(packet);
 }
 private void SendToAll(CoreMessage msg)
 {
     byte[] buffer = msg.CreateBuffer();
     GameServerPacket packet = new GameServerPacket(msg.Message);
     packet.Write(buffer);
     Game.SendToAll(packet);
 }
Exemple #49
0
 public void SendToAll(GameServerPacket packet) {
     SendToPlayers(packet);
     SendToObservers(packet);
 }
Exemple #50
0
        public void RefreshHand(int player, int flag = 0x181fff, bool useCache = true) {
            byte[] result = _duel.QueryFieldCard(player, CardLocation.Hand, flag | 0x100000, useCache);
            GameServerPacket update = new GameServerPacket(GameMessage.UpdateData);
            update.Write((byte)player);
            update.Write((byte)CardLocation.Hand);
            update.Write(result);
            CurPlayers[player].Send(update);

            update = new GameServerPacket(GameMessage.UpdateData);
            update.Write((byte)player);
            update.Write((byte)CardLocation.Hand);

            MemoryStream ms = new MemoryStream(result);
            BinaryReader reader = new BinaryReader(ms);
            BinaryWriter writer = new BinaryWriter(ms);
            while (ms.Position < ms.Length) {
                int len = reader.ReadInt32();
                if (len == 4)
                    continue;
                long pos = ms.Position;
                byte[] raw = reader.ReadBytes(len - 4);
                if (raw[len - 8] == 0) {
                    ms.Position = pos;
                    writer.Write(new byte[len - 4]);
                }
            }
            update.Write(result);

            SendToAllBut(update, player);
        }
        private void OnSelectCard(CoreMessage msg)
        {
            GameServerPacket packet = new GameServerPacket(msg.Message);

            int player = msg.Reader.ReadByte();
            packet.Write((byte)player);
            packet.Write(msg.Reader.ReadBytes(3));

            int count = msg.Reader.ReadByte();
            packet.Write((byte)count);

            for (int i = 0; i < count; i++)
            {
                int code = msg.Reader.ReadInt32();
                int pl = msg.Reader.ReadByte();
                int loc = msg.Reader.ReadByte();
                int seq = msg.Reader.ReadByte();
                int pos = msg.Reader.ReadByte();
                packet.Write(pl == player ? code : 0);
                packet.Write((byte)pl);
                packet.Write((byte)loc);
                packet.Write((byte)seq);
                packet.Write((byte)pos);
            }

            Game.WaitForResponse(player);
            Game.CurPlayers[player].Send(packet);
        }
        private void OnMove(CoreMessage msg)
        {
            byte[] raw = msg.Reader.ReadBytes(16);
            int pc = raw[4];
            int pl = raw[5];
            int cc = raw[8];
            int cl = raw[9];
            int cs = raw[10];
            int cp = raw[11];

            SendToPlayer(msg, cc);
            GameServerPacket packet = new GameServerPacket(msg.Message);
            packet.Write(raw);
            if (!Convert.ToBoolean((cl & ((int)CardLocation.Grave + (int)CardLocation.Overlay))) && Convert.ToBoolean((cl & ((int)CardLocation.Deck + (int)CardLocation.Hand)))
                || Convert.ToBoolean((cp & (int)CardPosition.FaceDown)))
            {
                packet.SetPosition(2);
                packet.Write(0);
            }
            Game.SendToAllBut(packet, cc);

            if (cl != 0 && (cl & 0x80) == 0 && (cl != pl || pc != cc))
                Game.RefreshSingle(cc, cl, cs);
        }
        private void OnShuffleHand(CoreMessage msg)
        {
            GameServerPacket packet = new GameServerPacket(msg.Message);
            int player = msg.Reader.ReadByte();
            int count = msg.Reader.ReadByte();
            packet.Write((byte)player);
            packet.Write((byte)count);

            msg.Reader.ReadBytes(count * 4);
            for (int i = 0; i < count; i++)
                packet.Write(0);

            SendToPlayer(msg, player);
            Game.SendToAllBut(packet, player);
            Game.RefreshHand(player, 0x181fff, false);
        }
        private void OnDraw(CoreMessage msg)
        {
            GameServerPacket packet = new GameServerPacket(msg.Message);
            int player = msg.Reader.ReadByte();
            int count = msg.Reader.ReadByte();
            packet.Write((byte)player);
            packet.Write((byte)count);

            for (int i = 0; i < count; i++)
            {
                uint code = msg.Reader.ReadUInt32();
                if ((code & 0x80000000) != 0)
                    packet.Write(code);
                else
                    packet.Write(0);
            }

            SendToPlayer(msg, player);
            Game.SendToAllBut(packet, player);
        }
 private void OnSet(CoreMessage msg)
 {
     msg.Reader.ReadBytes(4);
     byte[] raw = msg.Reader.ReadBytes(4);
     GameServerPacket packet = new GameServerPacket(GameMessage.Set);
     packet.Write(0);
     packet.Write(raw);
     Game.SendToAll(packet);
 }
Exemple #56
0
 private void SendHand() {
     RpsTimer = DateTime.UtcNow;
     GameServerPacket hand = new GameServerPacket(StocMessage.SelectHand);
     if (IsTag) {
         Players[0].Send(hand);
         Players[2].Send(hand);
     } else
         SendToPlayers(hand);
 }
        private void OnTagSwap(CoreMessage msg)
        {
            GameServerPacket packet = new GameServerPacket(GameMessage.TagSwap);

            int player = msg.Reader.ReadByte();
            packet.Write((byte)player);
            packet.Write(msg.Reader.ReadBytes(2));
            int count = msg.Reader.ReadByte();
            packet.Write((byte)count);
            packet.Write(msg.Reader.ReadBytes(4));

            for (int i = 0; i < count; i++)
            {
                uint code = msg.Reader.ReadUInt32();
                if ((code & 0x80000000) != 0)
                    packet.Write(code);
                else
                    packet.Write(0);
            }

            SendToPlayer(msg, player);
            Game.SendToAllBut(packet, player);

            Game.RefreshExtra(player);
            Game.RefreshMonsters(0, 0x81fff, false);
            Game.RefreshMonsters(1, 0x81fff, false);
            Game.RefreshSpells(0, 0x681fff, false);
            Game.RefreshSpells(1, 0x681fff, false);
            Game.RefreshHand(0, 0x181fff, false);
            Game.RefreshHand(1, 0x181fff, false);
        }
Exemple #58
0
 public void SendToAllBut(GameServerPacket packet, int except) {
     if (except < CurPlayers.Length)
         SendToAllBut(packet, CurPlayers[except]);
     else
         SendToAll(packet);
 }
 private void SendToPlayer(CoreMessage msg, int player)
 {
     if (player != 0 && player != 1)
         return;
     byte[] buffer = msg.CreateBuffer();
     GameServerPacket packet = new GameServerPacket(msg.Message);
     packet.Write(buffer);
     Game.CurPlayers[player].Send(packet);
 }
Exemple #60
0
        public void Surrender(Player player, int reason, bool force = false) {
            if (!force)
                if (State != GameState.Duel)
                    return;
            if (player.Type == (int)PlayerType.Observer)
                return;
            GameServerPacket win = new GameServerPacket(GameMessage.Win);
            int team = player.Type;
            if (IsTag)
                team = player.Type >= 2 ? 1 : 0;
            else if (State == GameState.Hand)
                team = 1 - team;
            win.Write((byte)(1 - team));
            win.Write((byte)reason);
            SendToAll(win);

            MatchSaveResult(1 - team);

            EndDuel(reason == 4);
        }