Exemplo n.º 1
0
		public static void OnPlayerEnter(GameSession player, GameRoom room){
            if (player.Name==null||player.Name.StartsWith("[AI]")) return;
			using(PacketWriter writer=new PacketWriter(2)){
				writer.Write((byte)RoomMessage.PlayerEnter);
				writer.WriteUnicode(player.Name, 20);
				writer.WriteUnicode(room.Config.Name, 20);
				Send(writer.Content);
			}
			string tip = Messages.RandomMessage();
			if(!string.IsNullOrEmpty(tip))
				player.ServerMessage(Messages.RandomMessage());
		}
 public static bool CheckAuth(this GameSession client, string namepassword)
 {
     if (namepassword == null)
     {
         return(true);
     }
     if (!RoomManager.CheckPlayerBan(namepassword))
     {
         client.ServerMessage(Messages.MSG_PLAYER_BAN);
         return(false);
     }
     if (Program.Config.isNeedAuth || namepassword.StartsWith("[AI]"))
     {
         string[] _names = namepassword.Split(new char[] { '$' }, 2);
         if (_names.Length == 1)
         {
             client.ServerMessage(Messages.ERR_NO_PASS);
             return(false);
         }
         else
         {
             if (!RoomManager.OnLogin(_names[0].Trim(), _names[1]))
             {
                 //LobbyError("Auth Fail");
                 if (Encoding.Default.GetBytes(namepassword).Length >= 20)
                 {
                     client.ServerMessage(Messages.ERR_NAME_PASSWORD_LONG);
                 }
                 else
                 {
                     client.ServerMessage(Messages.ERR_NAME_PASSWORD);
                 }
                 return(false);
             }
         }
     }
     return(true);
 }
        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);
            }
        }
Exemplo n.º 4
0
		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);
            }
		}
Exemplo n.º 5
0
        public void AddPlayer(GameSession player)
        {
            //			if(IsJoin(player)){
            ////				/玩家已经在游戏
            //				player.LobbyError(Messages.MSG_PLAYER_INGAME);
            //				return;
            //			}
            Logger.Debug("add " + player.Name + " to " + Name);
            if (State != GameState.Lobby)
            {
                if (State == GameState.End)
                    return;
                player.Type = (int)PlayerType.Observer;
                SendJoinGame(player);
                player.SendTypeChange();
                player.Send(GameServerPacket.EmtryMessage(StocMessage.DuelStart));
                lock (Observers)
                    Observers.Add(player);
                if (State == GameState.Duel)
                {
                    //中途观战
                    InitNewSpectator(player);
                }
                else if (State == GameState.Side)
                {
                    player.ServerMessage(Messages.MSG_WATCH_SIDE);
                }
                ServerApi.OnPlayerEnter(player, this);
                return;
            }
            if (HostPlayer == null)
                HostPlayer = player;
            int pos = GetAvailablePlayerPos();
            if (pos != -1)
            {
                Players[pos] = player;
                IsReady[pos] = false;

                player.Type = pos;
                using (GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter))
                {
                    enter.WriteUnicode(player.Name, 20);
                    enter.Write((byte)pos);
                    SendToAll(enter);
                }
                //	Server.OnPlayEvent(PlayerStatu.PlayerReady, player);
            }
            else
            {
                using (GameServerPacket watch = new GameServerPacket(StocMessage.HsWatchChange))
                {
                    watch.Write((short)(Observers.Count + 1));
                    SendToAll(watch);
                }
                player.Type = (int)PlayerType.Observer;
                lock (Observers)
                    Observers.Add(player);
                //				if(player.IsAuthentified){
                //					ServerMessage("[Server] "+player.Name+" watch game.", PlayerType.White);
                //				}
            }
            SendJoinGame(player);
            player.SendTypeChange();

            for (int i = 0; i < Players.Length; i++)
            {
                if (Players[i] != null)
                {
                    using (GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter))
                    {
                        enter.WriteUnicode(Players[i].Name, 20);
                        enter.Write((byte)i);
                        player.Send(enter, false);
                    }
                    if (IsReady[i])
                    {
                        using (GameServerPacket change = new GameServerPacket(StocMessage.HsPlayerChange))
                        {
                            change.Write((byte)((i << 4) + (int)PlayerChange.Ready));
                            player.Send(change, false);
                        }
                    }
                }
            }
            bool _watch = false;
            lock (Observers)
            {
                _watch = Observers.Count > 0;
            }
            if (_watch)
            {
                using (GameServerPacket nwatch = new GameServerPacket(StocMessage.HsWatchChange))
                {
                    nwatch.Write((short)Observers.Count);
                    player.Send(nwatch, false);
                }
            }
            player.PeekSend();
            ServerApi.OnPlayerEnter(player, this);
        }