public static GameConfig Build(GameClientPacket packet)
        {
            GameConfig config = new GameConfig();

            config.LfList         = BanlistManager.GetIndex(packet.ReadUInt32());
            config.BanList        = BanlistManager.GetName(config.LfList);
            config.Rule           = packet.ReadByte();
            config.Mode           = packet.ReadByte();
            config.EnablePriority = Convert.ToBoolean(packet.ReadByte());
            config.NoCheckDeck    = Convert.ToBoolean(packet.ReadByte());
            config.NoShuffleDeck  = Convert.ToBoolean(packet.ReadByte());
            //C++ padding: 5 bytes + 3 bytes = 8 bytes
            for (int i = 0; i < 3; i++)
            {
                packet.ReadByte();
            }
            config.StartLp   = packet.ReadInt32();
            config.StartHand = packet.ReadByte();
            config.DrawCount = packet.ReadByte();
            config.GameTimer = packet.ReadInt16();
            packet.ReadUnicode(20);
            config.Name = packet.ReadUnicode(30);

            if (string.IsNullOrEmpty(config.Name))
            {
                config.Name = RoomManager.NewRandomRoomName();
            }
            config.RoomString = config.Name;
            return(config);
        }
コード例 #2
0
ファイル: Player.cs プロジェクト: nagyistge/YGOCore
        private void onJoinMyCardStyleGame(GameClientPacket packet)
        {
            if (string.IsNullOrEmpty(Name) || Type != (int)PlayerType.Undefined)
            {
                return;
            }
            int version = packet.ReadInt16();

            if (version < Program.Config.ClientVersion)
            {
                LobbyError("Version too low");
                return;
            }
            else if (version > Program.Config.ClientVersion)
            {
                ServerMessage("Warning: client version is higher than servers.");
            }
            packet.ReadInt32();            //gameid
            packet.ReadInt16();

            string joinCommand = packet.ReadUnicode(60);

            GameRoom room = null;

            if (GameManager.GameExists(joinCommand))
            {
                room = GameManager.GetGame(joinCommand);
            }
            else
            {
                room = GameManager.CreateOrGetGame(new MyCardStyleGameConfig(joinCommand));
            }

            if (room == null)
            {
                LobbyError("Server Full");
                return;
            }
            if (!room.IsOpen)
            {
                LobbyError("Game Finished");
                return;
            }

            Game = room.Game;
            Game.AddPlayer(this);
            IsAuthentified = true;
        }
コード例 #3
0
ファイル: GameConfig.cs プロジェクト: mx41shy/YGOCore
 public GameConfig(GameClientPacket packet)
 {
     LfList = BanlistManager.GetIndex(packet.ReadUInt32());
     Rule = packet.ReadByte();
     Mode = packet.ReadByte();
     EnablePriority = Convert.ToBoolean(packet.ReadByte());
     NoCheckDeck = Convert.ToBoolean(packet.ReadByte());
     NoShuffleDeck = Convert.ToBoolean(packet.ReadByte());
     //C++ padding: 5 bytes + 3 bytes = 8 bytes
     for (int i = 0; i < 3; i++)
         packet.ReadByte();
     StartLp = packet.ReadInt32();
     StartHand = packet.ReadByte();
     DrawCount = packet.ReadByte();
     GameTimer = packet.ReadInt16();
     packet.ReadUnicode(20);
     Name = packet.ReadUnicode(30);
     if (string.IsNullOrEmpty(Name))
         Name = GameManager.RandomRoomName();
 }
コード例 #4
0
 public GameConfig(GameClientPacket packet)
 {
     LfList         = BanlistManager.GetIndex(packet.ReadUInt32());
     Rule           = packet.ReadByte();
     Mode           = packet.ReadByte();
     EnablePriority = Convert.ToBoolean(packet.ReadByte());
     NoCheckDeck    = Convert.ToBoolean(packet.ReadByte());
     NoShuffleDeck  = Convert.ToBoolean(packet.ReadByte());
     //C++ padding: 5 bytes + 3 bytes = 8 bytes
     for (int i = 0; i < 3; i++)
     {
         packet.ReadByte();
     }
     StartLp   = packet.ReadInt32();
     StartHand = packet.ReadByte();
     DrawCount = packet.ReadByte();
     GameTimer = packet.ReadInt16();
     packet.ReadUnicode(20);
     Name = packet.ReadUnicode(30);
     if (string.IsNullOrEmpty(Name))
     {
         Name = GameManager.RandomRoomName();
     }
 }
コード例 #5
0
ファイル: Player.cs プロジェクト: nagyistge/YGOCore
        private void OnJoinGame(GameClientPacket packet)
        {
            if (string.IsNullOrEmpty(Name) || Type != (int)PlayerType.Undefined)
            {
                return;
            }

            int version = packet.ReadInt16();

            if (version < Program.Config.ClientVersion)
            {
                LobbyError("Version too low");
                return;
            }
            else if (version > Program.Config.ClientVersion)
            {
                ServerMessage("Warning: client version is higher than servers.");
            }


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

            string joinCommand = packet.ReadUnicode(60);

            GameRoom room = null;

            if (GameManager.GameExists(joinCommand))
            {
                room = GameManager.GetGame(joinCommand);
            }
            else if (joinCommand.ToLower() == "random")
            {
                room = GameManager.GetRandomGame();

                if (room == null)
                {
                    LobbyError("No Games");
                    return;
                }
            }
            else if (joinCommand.ToLower() == "spectate")
            {
                room = GameManager.SpectateRandomGame();

                if (room == null)
                {
                    LobbyError("No Games");
                    return;
                }
            }
            else if (string.IsNullOrEmpty(joinCommand) || joinCommand.ToLower() == "tcg" || joinCommand.ToLower() == "ocg" ||
                     joinCommand.ToLower() == "ocg/tcg" || joinCommand.ToLower() == "tcg/ocg")
            {
                int filter = string.IsNullOrEmpty(joinCommand) ? -1 :
                             (joinCommand.ToLower() == "ocg/tcg" || joinCommand.ToLower() == "tcg/ocg") ? 2 :
                             joinCommand.ToLower() == "tcg" ? 1 : 0;

                room = GameManager.GetRandomGame(filter);
                if (room == null) //if no games just make a new one!!
                {
                    room = GameManager.CreateOrGetGame(new GameConfig(joinCommand));
                }
            }
            else
            {
                room = GameManager.CreateOrGetGame(new GameConfig(joinCommand));
            }

            if (room == null)
            {
                LobbyError("Server Full");
                return;
            }
            if (!room.IsOpen)
            {
                LobbyError("Game Finished");
                return;
            }

            Game = room.Game;
            Game.AddPlayer(this);
            IsAuthentified = true;
        }
コード例 #6
0
ファイル: Player.cs プロジェクト: InvisibleMoon/YGOCore
 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;
         Game.ServerMessage(Name + " is ready.");
         Send(new GameServerPacket(StocMessage.DuelStart));
         Game.MatchSide();
     }
 }
コード例 #7
0
ファイル: Player.cs プロジェクト: InvisibleMoon/YGOCore
        private void onJoinMyCardStyleGame(GameClientPacket packet)
        {
            if (string.IsNullOrEmpty(Name) || Type != (int)PlayerType.Undefined)
                return;
            int version = packet.ReadInt16();
            if (version < Program.Config.ClientVersion)
            {
                LobbyError("Version too low");
                return;
            }
            else if (version > Program.Config.ClientVersion)
                ServerMessage("Warning: client version is higher than servers.");
            packet.ReadInt32();//gameid
            packet.ReadInt16();

            string joinCommand = packet.ReadUnicode(60);

            GameRoom room = null;

            if (GameManager.GameExists(joinCommand))
                room = GameManager.GetGame(joinCommand);
            else
                room = GameManager.CreateOrGetGame(new MyCardStyleGameConfig(joinCommand));

            if (room == null)
            {
                LobbyError("Server Full");
                return;
            }
            if (!room.IsOpen)
            {
                LobbyError("Game Finished");
                return;
            }

            Game = room.Game;
            Game.AddPlayer(this);
            IsAuthentified = true;
        }
コード例 #8
0
ファイル: Player.cs プロジェクト: InvisibleMoon/YGOCore
        private void OnJoinGame(GameClientPacket packet)
        {
            if (string.IsNullOrEmpty(Name) || Type != (int)PlayerType.Undefined)
                return;

            int version = packet.ReadInt16();
            if (version < Program.Config.ClientVersion)
            {
                LobbyError("Version too low");
                return;
            }
            else if (version > Program.Config.ClientVersion)
                ServerMessage("Warning: client version is higher than servers.");

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

            string joinCommand = packet.ReadUnicode(60);

            GameRoom room = null;

            if (GameManager.GameExists(joinCommand))
                room = GameManager.GetGame(joinCommand);
            else if (joinCommand.ToLower() == "random")
            {
                room = GameManager.GetRandomGame();

                if (room == null)
                {
                    LobbyError("No Games");
                    return;
                }

            }
            else if (joinCommand.ToLower() == "spectate")
            {
                room = GameManager.SpectateRandomGame();

                if (room == null)
                {
                    LobbyError("No Games");
                    return;
                }
            }
            else if (string.IsNullOrEmpty(joinCommand) || joinCommand.ToLower() == "tcg" || joinCommand.ToLower() == "ocg"
                || joinCommand.ToLower() == "ocg/tcg" || joinCommand.ToLower() == "tcg/ocg")
            {
                int filter = string.IsNullOrEmpty(joinCommand) ? -1 :
                    (joinCommand.ToLower() == "ocg/tcg" || joinCommand.ToLower() == "tcg/ocg") ? 2 :
                    joinCommand.ToLower() == "tcg" ? 1 : 0;

                room = GameManager.GetRandomGame(filter);
                if (room == null) //if no games just make a new one!!
                    room = GameManager.CreateOrGetGame(new GameConfig(joinCommand));
            }
            else
                room = GameManager.CreateOrGetGame(new GameConfig(joinCommand));

            if (room == null)
            {
                LobbyError("Server Full");
                return;
            }
            if (!room.IsOpen)
            {
                LobbyError("Game Finished");
                return;
            }

            Game = room.Game;
            Game.AddPlayer(this);
            IsAuthentified = true;
        }
コード例 #9
0
ファイル: GameEvent.cs プロジェクト: 247321453/YgoServer
		public static void OnUpdateDeck(GameSession client, GameClientPacket packet){
			if (client.Game==null||client.Type == (int)PlayerType.Observer||client.Type == (int)PlayerType.Undefined)
				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 (client.Game.State == GameState.Lobby)
			{
				client.Deck = deck;
				client.Game.IsReady[client.Type] = false;
			}
			else if (client.Game.State == GameState.Side)
			{
				if (client.Game.IsReady[client.Type])
					return;
				if (!client.Deck.Check(deck))
				{
					using(GameServerPacket error = new GameServerPacket(StocMessage.ErrorMsg)){
						error.Write((byte)3);
						error.Write(0);
						client.Send(error);
					}
					return;
				}
				client.Deck = deck;
				client.Game.IsReady[client.Type] = true;
				client.Game.ServerMessage(string.Format(Messages.MSG_READY, client.Name));
				client.Send(GameServerPacket.EmtryMessage(StocMessage.DuelStart));
				client.Game.MatchSide();
			}
		}
コード例 #10
0
ファイル: GameEvent.cs プロジェクト: 247321453/YgoServer
		public static void OnJoinGame(GameSession client, GameClientPacket packet){
			if (string.IsNullOrEmpty(client.Name) || client.Type != (int)PlayerType.Undefined){
				Logger.Debug("join room fail:"+client.Name);
				return;
			}
			int version = packet.ReadInt16();
			if (version < Program.Config.ClientVersion)
			{
				client.LobbyError(Messages.ERR_LOW_VERSION);
				return;
			}
			else if (version > Program.Config.ClientVersion){
				client.ServerMessage(Messages.MSG_HIGH_VERSION);
			}
			int gameid = packet.ReadInt32();//gameid
			packet.ReadInt16();

			string joinCommand = packet.ReadUnicode(60);
			
			GameRoom room = null;
			//IsAuthentified = CheckAuth();
			if(!client.IsAuthentified){
				client.LobbyError(Messages.ERR_AUTH_FAIL);
				return;
			}
			if(!RoomManager.CheckRoomPassword(joinCommand)){
				client.LobbyError(Messages.ERR_PASSWORD);
				return;
			}
			GameConfig config = GameConfigBuilder.Build(joinCommand);
			room =  RoomManager.CreateOrGetGame(config);
			if (room == null){
				client.LobbyError(Messages.MSG_FULL);
				return;
			}
			if (!room.IsOpen)
			{
				client.LobbyError(Messages.MSG_GAMEOVER);
				return;
			}
			if(room!=null && room.Config!=null){
				if(room.Config.NoCheckDeck){
					client.ServerMessage(Messages.MSG_NOCHECKDECK);
				}
				if(room.Config.NoShuffleDeck){
					client.ServerMessage(Messages.MSG_NOSHUFFLEDECK);
				}
				if(room.Config.EnablePriority){
					client.ServerMessage(Messages.MSG_ENABLE_PROIORITY);
				}
			}
			client.Game = room;
            lock (room.AsyncRoot)
            {
                room.AddPlayer(client);
            }
		}
コード例 #11
0
ファイル: Player.cs プロジェクト: 247321453/YgoServer
		private void OnJoinGame(GameClientPacket packet)
		{
			if (string.IsNullOrEmpty(Name) || Type != (int)PlayerType.Undefined)
				return;
			int version = packet.ReadInt16();
			if (version < Program.Config.ClientVersion)
			{
				LobbyError(Messages.ERR_LOW_VERSION);
				return;
			}
			else if (version > Program.Config.ClientVersion)
				ServerMessage(Messages.MSG_HIGH_VERSION);
			

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

			string joinCommand = packet.ReadUnicode(60);

			GameRoom room = null;
			
			//IsAuthentified = CheckAuth();
			if(!IsAuthentified){
				LobbyError(Messages.ERR_AUTH_FAIL);
				return;
			}
			if(!GameManager.CheckPassword(joinCommand)){
				LobbyError(Messages.ERR_PASSWORD);
				return;
			}
			if(string.IsNullOrEmpty(joinCommand) ||joinCommand.ToLower()=="random"){
				room = GameManager.GetRandomGame();
				if (room == null){
					room =  GameManager.CreateOrGetGame(new GameConfig(joinCommand));
				}
			}
			#region old
//			else if (GameManager.GameExists(joinCommand)){
//				room = GameManager.GetGame(joinCommand);
//			}
//			else if (joinCommand.ToLower() == "random")
//			{
//				room = GameManager.GetRandomGame();
//
//				if (room == null)
//				{
//					LobbyError("No Games");
//					return;
//				}
//			}
//			else if (joinCommand.ToLower() == "spectate")
//			{
//				room = GameManager.SpectateRandomGame();
//
//				if (room == null)
//				{
//					LobbyError("No Games");
//					return;
//				}
//			}
//			else if (string.IsNullOrEmpty(joinCommand) || joinCommand.ToLower() == "tcg" || joinCommand.ToLower() == "ocg"
//			         || joinCommand.ToLower() == "ocg/tcg" || joinCommand.ToLower() == "tcg/ocg")
//			{
//				int filter = string.IsNullOrEmpty(joinCommand) ? -1 :
//					(joinCommand.ToLower() == "ocg/tcg" || joinCommand.ToLower() == "tcg/ocg") ? 2 :
//					joinCommand.ToLower() == "tcg" ? 1 : 0;
//
//				room = GameManager.GetRandomGame(filter);
//				if (room == null) //if no games just make a new one!!
//					room = GameManager.CreateOrGetGame(new GameConfig(joinCommand));
//			}
			#endregion
			else{
				room = GameManager.CreateOrGetGame(new GameConfig(joinCommand));
				//Logger.WriteLine("join "+room.Game.Config.Name);
			}

			if (room == null)
			{
				LobbyError(Messages.MSG_FULL);
				return;
			}
			if (!room.IsOpen)
			{
				LobbyError(Messages.MSG_GAMEOVER);
				return;
			}
			if(room.Game!=null && room.Game.Config!=null){
				//TODO: tips
				if(room.Game.Config.NoCheckDeck){
					ServerMessage(Messages.MSG_NOCHECKDECK);
				}
				
				if(room.Game.Config.NoShuffleDeck){
					ServerMessage(Messages.MSG_NOSHUFFLEDECK);
				}
				
				if(room.Game.Config.EnablePriority){
					ServerMessage(Messages.MSG_ENABLE_PROIORITY);
				}
			}
			Game = room.Game;
			Game.AddPlayer(this);
		}
コード例 #12
0
 public static GameConfig Build(GameClientPacket packet)
 {
     GameConfig config = new GameConfig();
     config.LfList = BanlistManager.GetIndex(packet.ReadUInt32());
     config.BanList = BanlistManager.GetName(config.LfList);
     config.Rule = packet.ReadByte();
     config.Mode = packet.ReadByte();
     config.EnablePriority = Convert.ToBoolean(packet.ReadByte());
     config.NoCheckDeck = Convert.ToBoolean(packet.ReadByte());
     config.NoShuffleDeck = Convert.ToBoolean(packet.ReadByte());
     //C++ padding: 5 bytes + 3 bytes = 8 bytes
     for (int i = 0; i < 3; i++)
         packet.ReadByte();
     config.StartLp = packet.ReadInt32();
     config.StartHand = packet.ReadByte();
     config.DrawCount = packet.ReadByte();
     config.GameTimer = packet.ReadInt16();
     packet.ReadUnicode(20);
     config.Name = packet.ReadUnicode(30);
     
     if (string.IsNullOrEmpty(config.Name))
         config.Name = RoomManager.NewRandomRoomName();
     config.RoomString = config.Name;
     return config;
 }
コード例 #13
0
        private void OnJoinGame(GameClientPacket packet)
        {
            if (string.IsNullOrEmpty(Name) || Type != (int)PlayerType.Undefined)
            {
                return;
            }
            int version = packet.ReadInt16();

            if (version < Program.Config.ClientVersion)
            {
                LobbyError(Messages.ERR_LOW_VERSION);
                return;
            }
            else if (version > Program.Config.ClientVersion)
            {
                ServerMessage(Messages.MSG_HIGH_VERSION);
            }


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

            string joinCommand = packet.ReadUnicode(60);

            GameRoom room = null;

            //IsAuthentified = CheckAuth();
            if (!IsAuthentified)
            {
                LobbyError(Messages.ERR_AUTH_FAIL);
                return;
            }
            if (!GameManager.CheckPassword(joinCommand))
            {
                LobbyError(Messages.ERR_PASSWORD);
                return;
            }
            if (string.IsNullOrEmpty(joinCommand) || joinCommand.ToLower() == "random")
            {
                room = GameManager.GetRandomGame();
                if (room == null)
                {
                    room = GameManager.CreateOrGetGame(new GameConfig(joinCommand));
                }
            }
            #region old
//			else if (GameManager.GameExists(joinCommand)){
//				room = GameManager.GetGame(joinCommand);
//			}
//			else if (joinCommand.ToLower() == "random")
//			{
//				room = GameManager.GetRandomGame();
//
//				if (room == null)
//				{
//					LobbyError("No Games");
//					return;
//				}
//			}
//			else if (joinCommand.ToLower() == "spectate")
//			{
//				room = GameManager.SpectateRandomGame();
//
//				if (room == null)
//				{
//					LobbyError("No Games");
//					return;
//				}
//			}
//			else if (string.IsNullOrEmpty(joinCommand) || joinCommand.ToLower() == "tcg" || joinCommand.ToLower() == "ocg"
//			         || joinCommand.ToLower() == "ocg/tcg" || joinCommand.ToLower() == "tcg/ocg")
//			{
//				int filter = string.IsNullOrEmpty(joinCommand) ? -1 :
//					(joinCommand.ToLower() == "ocg/tcg" || joinCommand.ToLower() == "tcg/ocg") ? 2 :
//					joinCommand.ToLower() == "tcg" ? 1 : 0;
//
//				room = GameManager.GetRandomGame(filter);
//				if (room == null) //if no games just make a new one!!
//					room = GameManager.CreateOrGetGame(new GameConfig(joinCommand));
//			}
            #endregion
            else
            {
                room = GameManager.CreateOrGetGame(new GameConfig(joinCommand));
                //Logger.WriteLine("join "+room.Game.Config.Name);
            }

            if (room == null)
            {
                LobbyError(Messages.MSG_FULL);
                return;
            }
            if (!room.IsOpen)
            {
                LobbyError(Messages.MSG_GAMEOVER);
                return;
            }
            if (room.Game != null && room.Game.Config != null)
            {
                //TODO: tips
                if (room.Game.Config.NoCheckDeck)
                {
                    ServerMessage(Messages.MSG_NOCHECKDECK);
                }

                if (room.Game.Config.NoShuffleDeck)
                {
                    ServerMessage(Messages.MSG_NOSHUFFLEDECK);
                }

                if (room.Game.Config.EnablePriority)
                {
                    ServerMessage(Messages.MSG_ENABLE_PROIORITY);
                }
            }
            Game = room.Game;
            Game.AddPlayer(this);
        }