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
 public void Parse(GameClientPacket packet)
 {
     CtosMessage msg = packet.ReadCtos();
     switch (msg)
     {
         case CtosMessage.PlayerInfo:
             OnPlayerInfo(packet);
             break;
         case CtosMessage.JoinGame:
             OnJoinGame(packet);
             break;
         case CtosMessage.CreateGame:
             OnCreateGame(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;
     }
 }
Пример #3
0
        private void OnHandResult(GameClientPacket packet)
        {
            int res = packet.ReadByte();

            if (Game != null)
            {
                Game.HandResult(this, res);
            }
        }
Пример #4
0
        private void OnTpResult(GameClientPacket packet)
        {
            bool tp = packet.ReadByte() != 0;

            if (Game != null)
            {
                Game.TpResult(this, tp);
            }
        }
Пример #5
0
        private void OnKick(GameClientPacket packet)
        {
            int pos = packet.ReadByte();

            if (Game != null)
            {
                Game.KickPlayer(this, pos);
            }
        }
Пример #6
0
        private void OnPlayerInfo(GameClientPacket packet)
        {
            if (Name != null)
            {
                return;
            }
            Name = packet.ReadUnicode(20);

            if (string.IsNullOrEmpty(Name))
            {
                LobbyError("Username Required");
            }
        }
        private void NetworkReceive()
        {
            if (m_client.Available >= 2 && m_receivedLen == -1)
            {
                m_receivedLen = m_reader.ReadUInt16();
            }

            if (m_receivedLen != -1 && m_client.Available >= m_receivedLen)
            {
                GameClientPacket packet = new GameClientPacket(m_reader.ReadBytes(m_receivedLen));
                m_receivedLen = -1;
                lock (m_recvQueue)
                    m_recvQueue.Enqueue(packet);
            }
        }
Пример #8
0
        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;
        }
Пример #9
0
        private void OnChat(GameClientPacket packet)
        {
            string msg = packet.ReadUnicode(256);

            if (Game == null)
            {
                return;
            }
            if (Game.Config == null)
            {
                Game.Chat(this, msg);
            }
            else if (ChatCommand.onChat(Game.Config, this, msg))
            {
                Game.Chat(this, msg);
            }
        }
Пример #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 OnPlayerInfo(GameClientPacket packet)
        {
            if (Name != null)
            {
                return;
            }
            Name = packet.ReadUnicode(20);

            if (string.IsNullOrEmpty(Name))
            {
                LobbyError(Messages.ERR_NO_NAME);
            }
            IsAuthentified = CheckAuth();
            if (IsAuthentified)
            {
                ServerMessage(MsgSystem.getMessage(Name, 0), PlayerType.White);
            }
        }
Пример #12
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;
                Game.ServerMessage(Name + " is ready.");
                Send(new GameServerPacket(StocMessage.DuelStart));
                Game.MatchSide();
            }
        }
Пример #13
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();
 }
Пример #14
0
        private void OnCreateGame(GameClientPacket packet)
        {
            if (string.IsNullOrEmpty(Name) || Type != (int)PlayerType.Undefined)
            {
                return;
            }

            GameRoom room = null;

            room = GameManager.CreateOrGetGame(new GameConfig(packet));

            if (room == null)
            {
                LobbyError("Server Full");
                return;
            }

            Game = room.Game;
            Game.AddPlayer(this);
            IsAuthentified = true;
        }
//		public bool IsTimeOut(){
//			long t = (DateTime.Now.Ticks-logintime)/10000;
//			long all = ((long)Program.Config.Timeout * 1000);
//			return  t >= all;
//		}

        private void NetworkParse()
        {
            int count;

            lock (m_recvQueue)
                count = m_recvQueue.Count;
            while (count > 0)
            {
                GameClientPacket packet = null;
                lock (m_recvQueue)
                {
                    if (m_recvQueue.Count > 0)
                    {
                        packet = m_recvQueue.Dequeue();
                    }
                    count = m_recvQueue.Count;
                }
                if (packet != null)
                {
                    Player.Parse(packet);
                }
            }
        }
Пример #16
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();
     }
 }
Пример #17
0
        private void OnCreateGame(GameClientPacket packet)
        {
            if (string.IsNullOrEmpty(Name) || Type != (int)PlayerType.Undefined)
            {
                return;
            }
            GameRoom room = null;

            room = GameManager.CreateOrGetGame(new GameConfig(packet));

            if (room == null)
            {
                LobbyError(Messages.MSG_FULL);
                return;
            }

            Game = room.Game;
            Game.AddPlayer(this);
            //IsAuthentified = CheckAuth();
            if (!IsAuthentified)
            {
                LobbyError(Messages.ERR_AUTH_FAIL);
            }
        }
Пример #18
0
 private void OnKick(GameClientPacket packet)
 {
     int pos = packet.ReadByte();
     Game.KickPlayer(this, pos);
 }
Пример #19
0
		private void OnPlayerInfo(GameClientPacket packet)
		{
			if (Name != null)
				return;
			Name = packet.ReadUnicode(20);

			if (string.IsNullOrEmpty(Name)){
				LobbyError(Messages.ERR_NO_NAME);
			}
			IsAuthentified = CheckAuth();
			if(IsAuthentified){
				ServerMessage(MsgSystem.getMessage(Name, 0), PlayerType.White);
			}
		}
Пример #20
0
		private void NetworkReceive()
		{
			if (m_client.Available >= 2 && m_receivedLen == -1)
				m_receivedLen = m_reader.ReadUInt16();

			if (m_receivedLen != -1 && m_client.Available >= m_receivedLen)
			{
				GameClientPacket packet = new GameClientPacket(m_reader.ReadBytes(m_receivedLen));
				m_receivedLen = -1;
				lock (m_recvQueue)
					m_recvQueue.Enqueue(packet);
			}
		}
Пример #21
0
		private void OnCreateGame(GameClientPacket packet)
		{
			if (string.IsNullOrEmpty(Name) || Type != (int)PlayerType.Undefined)
				return;
			GameRoom room = null;
			
			room = GameManager.CreateOrGetGame(new GameConfig(packet));

			if (room == null)
			{
				LobbyError(Messages.MSG_FULL);
				return;
			}

			Game = room.Game;
			Game.AddPlayer(this);
			//IsAuthentified = CheckAuth();
			if(!IsAuthentified){
				LobbyError(Messages.ERR_AUTH_FAIL);
			}
		}
Пример #22
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;
         Game.ServerMessage(Name + " is ready.");
         Send(new GameServerPacket(StocMessage.DuelStart));
         Game.MatchSide();
     }
 }
Пример #23
0
 private void OnTpResult(GameClientPacket packet)
 {
     bool tp = packet.ReadByte() != 0;
     Game.TpResult(this, tp);
 }
Пример #24
0
		private void OnChat(GameClientPacket packet)
		{
			string msg = packet.ReadUnicode(256);
			if(Game==null){
				return;
			}
			if(Game.Config==null){
				Game.Chat(this, msg);
			}
			else if(ChatCommand.onChat(Game.Config, this, msg)){
				Game.Chat(this, msg);
			}
		}
Пример #25
0
        private void OnChat(GameClientPacket packet)
        {
            string msg = packet.ReadUnicode(256);

            Game.Chat(this, msg);
        }
Пример #26
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);
        }
Пример #27
0
        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;
        }
Пример #28
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("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;
        }
Пример #29
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);
		}
Пример #30
0
 private void OnChat(GameClientPacket packet)
 {
     string msg = packet.ReadUnicode(256);
     Game.Chat(this, msg);
 }
Пример #31
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("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;
        }
Пример #32
0
        private void OnPlayerInfo(GameClientPacket packet)
        {
            if (Name != null)
                return;
            Name = packet.ReadUnicode(20);

            if (string.IsNullOrEmpty(Name))
                LobbyError("Username Required");
        }
Пример #33
0
        private void OnCreateGame(GameClientPacket packet)
        {
            if (string.IsNullOrEmpty(Name) || Type != (int)PlayerType.Undefined)
                return;

            GameRoom room = null;

            room = GameManager.CreateOrGetGame(new GameConfig(packet));

            if (room == null)
            {
                LobbyError("Server Full");
                return;
            }

            Game = room.Game;
            Game.AddPlayer(this);
            IsAuthentified = true;
        }
Пример #34
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);
 }
Пример #35
0
        public void Parse(GameClientPacket packet)
        {
            CtosMessage msg = packet.ReadCtos();

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

            case CtosMessage.JoinGame:
                if (Program.Config.MyCard)
                {
                    onJoinMyCardStyleGame(packet);
                }
                else
                {
                    OnJoinGame(packet);
                }
                break;

            case CtosMessage.CreateGame:
                OnCreateGame(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;
            }
        }
Пример #36
0
 private void OnHandResult(GameClientPacket packet)
 {
     int res = packet.ReadByte();
     Game.HandResult(this, res);
 }