Exemple #1
0
        public static GameConfig Build(this CtosCreateGame roomconfig)
        {
            GameConfig config = new GameConfig();
            config.Parse(roomconfig.info);
            config.Name = new string(roomconfig.name).Split('\0')[0];
            config.RoomString = config.Name;
            try
            {
                char[] chs = new char[roomconfig.pass.Length];
                for(int i = 0; i < roomconfig.pass.Length; i++)
                {
                    chs[i] = (char)roomconfig.pass[i];
                }
                string pwd = new string(chs).Split('\0')[0];
                if (!string.IsNullOrEmpty(pwd))
                {
                    config.RoomString = config.Name + '$' + pwd;
                }
            }
            catch
            {

            }
            return config;
        }
 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;
 }
Exemple #3
0
 public GameRoom(GameConfig config)
 {
     Config = config;
     IsRandom = config.IsRandom;
     State = GameState.Lobby;
     CurrentPlayer = 0;
     LifePoints = new int[2];
     Players = new GameSession[IsTag ? 4 : 2];
     CurPlayers = new GameSession[2];
     IsReady = new bool[IsTag ? 4 : 2];
     m_handResult = new int[2];
     m_timelimit = new int[2];
     m_bonustime = new int[2];
     m_matchResult = new int[3];
     AutoEndTrun = Program.Config.AutoEndTurn;
     Banlist = BanlistManager.GetBanlist(config.LfList);
     m_analyser = new GameAnalyser(this);
     StartTime = DateTime.Now;
     IsOpen = true;
     GameTimer = new GameTimer(this);
     DuleTimer = new System.Timers.Timer(10 * 1000);
     DuleTimer.AutoReset = true;
     DuleTimer.Enabled = true;
     DuleTimer.Elapsed += new System.Timers.ElapsedEventHandler(DuleTimer_Elapsed);
 }
Exemple #4
0
 private static GameRoom CreateRoom(GameConfig config)
 {
     GameRoom room = new GameRoom(config);
     m_rooms.Add(config.Name, room);
     Logger.WriteLine("Game++");
     return room;
 }
Exemple #5
0
		/// <summary>
		/// 是否允许断线重连
		/// </summary>
	//	private bool CanPause = false;
		
		public Game(GameRoom room, GameConfig config)
		{
			Config = config;
			State = GameState.Lobby;
			IsMatch = config.Mode == 1;
			IsTag = config.Mode == 2;
			CurrentPlayer = 0;
			LifePoints = new int[2];
			Players = new Player[IsTag ? 4 : 2];
			PlayerNames = new string[IsTag ? 4 : 2];
			CurPlayers = new Player[2];
			IsReady = new bool[IsTag ? 4 : 2];
			m_handResult = new int[2];
			m_timelimit = new int[2];
			m_bonustime = new int[2];
			m_matchResult = new int[3];
			AutoEndTrun = Program.Config.AutoEndTurn;
			Observers = new List<Player>();
			if (config.LfList >= 0 && config.LfList < BanlistManager.Banlists.Count)
				Banlist = BanlistManager.Banlists[config.LfList];
			else if(BanlistManager.Banlists.Count>0){
				Banlist = BanlistManager.Banlists[0];
			}
			m_room = room;
			m_analyser = new GameAnalyser(this);
			yrpName=DateTime.Now.ToString("yyyyMMddHHmmss");
		}
 public static GameConfig Build(string gameinfo)
 {
     //默认值
     GameConfig config = new GameConfig();
     config.IsRandom = true;
     config.LfList = 0;
     config.BanList = BanlistManager.GetName(0);
     config.Rule = 2;
     config.Mode = 0;
     config.EnablePriority = false;
     config.NoCheckDeck = false;
     config.NoShuffleDeck = false;
     config.StartLp = 8000;
     config.StartHand = 5;
     config.DrawCount = 1;
     config.GameTimer = 120;
     if (!string.IsNullOrEmpty(gameinfo))
     {
         gameinfo = gameinfo.Trim();
     }
     gameinfo = gameinfo.Replace("*", "");
     gameinfo = gameinfo.Replace(":", "");
     config.RoomString = gameinfo;
     if (string.IsNullOrEmpty(gameinfo) || gameinfo == "random" || gameinfo == "#")
     {
         //random
         config.Name = RoomManager.RandomRoomName();
         Logger.Debug("random:" + config.Name);
         return config;
     }
     config.Parse(gameinfo);
     config.BanList = BanlistManager.GetName(config.LfList);
     if (string.IsNullOrEmpty(config.Name))
     {
         if (gameinfo.EndsWith("#"))
         {
             string _name = RoomManager.RandomRoomName(gameinfo);
             if (_name == null)
             {
                 //条件#的随机房间名没找到,则创建一个
                 config.Name = gameinfo + RoomManager.NewRandomRoomName();
             }
             else
             {
                 //条件#的随机房间名存在,则进去,可能重复观战
                 config.Name = _name;
                 Logger.Debug("1," + config.Name);
             }
         }
         else
         {
             config.IsRandom = false;
             config.Name = gameinfo;
         }
     }
     Logger.Debug("2,"+config.Name);
     return config;
 }
Exemple #7
0
		public static GameRoom CreateOrGetGame(GameConfig config)
		{
			//MutexRooms.WaitOne();
			int count=m_rooms.Count;
			if (m_rooms.ContainsKey(config.Name)){
				GameRoom room=m_rooms[config.Name];
				//MutexRooms.ReleaseMutex();
				return room;
			}
			if(count>=Program.Config.MaxRoomCount){
				return null;
			}
			return CreateRoom(config);
		}
Exemple #8
0
		public static bool onChat(GameConfig config,Player player,string msg)
		{
			if(!string.IsNullOrEmpty(msg)){
				msg = msg.Trim();
				if(msg=="/ai"){
					if(Program.Config.MaxAICount==0){
						player.ServerMessage(Messages.MSG_NO_AI);
					}
					else if(config!=null && AddAI(config.Name)){
						player.ServerMessage(Messages.MSG_ADD_AI);
					}else{
						player.ServerMessage(Messages.MSG_NO_FREE_AI);
					}
					return false;
				}
//				if(msg.StartsWith("@") && !Program.Config.PrivateChat){
//					player.ServerMessage(Messages.MSG_BAN_PCHAT);
//					return false;
//				}
//				if(msg.StartsWith("@server ")){
//					Logger.WriteLineWithColor(player.Name+":"+msg.Replace("@server ",""), ConsoleColor.Yellow);
//					return false;
//				}else if(msg.StartsWith("@system ")){
//					Logger.WriteLineWithColor(player.Name+":"+msg.Replace("@system ",""), ConsoleColor.Yellow);
//					return false;
//				}else if(msg.StartsWith("@@ ")){
//					Logger.WriteLineWithColor(player.Name+":"+msg.Replace("@@ ",""), ConsoleColor.Yellow);
//					return false;
//				}else if(msg.StartsWith("@")){
//					//私聊
//					int i=msg.IndexOf(' ');
//					if(i>0){
//						try{
//							string name=msg.Substring(1, i-1);
//							string cxt=msg.Substring(i+1);
//							if(GameManager.SendErrorMessage(player.Name+": "+cxt, name).Count==0){
//								player.ServerMessage(Messages.MSG_SEND_FAIL);
//							}else{
//								return false;
//							}
//						}catch(Exception){
//
//						}
//					}
//				}
			}
			return true;
		}
Exemple #9
0
		private static void OnRoomCreate(DuelServer server, PacketReader packet){
			string name = packet.ReadUnicode(20);
			string info = packet.ReadUnicode(20);
			string banlist=packet.ReadUnicode(50);
			GameConfig config=new GameConfig();
            config.RoomString = info;
            config.Parse(info);
			config.Name=name;
			config.BanList=banlist;
            
			Logger.Debug("OnRoomCreate:"+server.Port+","+name+"|"+info);
			lock(server.Rooms){
                server.Rooms[name] = config;
			}
            if (server.Server != null)
            {
                server.Server.server_OnRoomCreate(server, name, banlist, info);
            }
		}
Exemple #10
0
 public Game(GameRoom room, GameConfig config)
 {
     Config = config;
     State = GameState.Lobby;
     IsMatch = config.Mode == 1;
     IsTag = config.Mode == 2;
     CurrentPlayer = 0;
     LifePoints = new int[2];
     Players = new Player[IsTag ? 4 : 2];
     CurPlayers = new Player[2];
     IsReady = new bool[IsTag ? 4 : 2];
     m_handResult = new int[2];
     m_timelimit = new int[2];
     m_bonustime = new int[2];
     m_matchResult = new int[3];
     Observers = new List<Player>();
     if (config.LfList >= 0 && config.LfList < BanlistManager.Banlists.Count)
         Banlist = BanlistManager.Banlists[config.LfList];
     m_room = room;
     m_analyser = new GameAnalyser(this);
 }
Exemple #11
0
//
//		public static GameRoom SpectateRandomGame()
//		{
//			List<GameRoom> filteredRooms = new List<GameRoom>();
//			GameRoom[] rooms;
//			//MutexRooms.WaitOne();
//			rooms = new GameRoom[m_rooms.Count];
//			m_rooms.Values.CopyTo(rooms, 0);
//			//MutexRooms.ReleaseMutex();
//
//			foreach (GameRoom room in rooms)
//			{
//				if (room.Game.State != GameState.Lobby)
//					filteredRooms.Add(room);
//			}
//
//			if (filteredRooms.Count == 0)
//				return null;
//
//			return filteredRooms[Program.Random.Next(0, filteredRooms.Count)];
//		}

		private static GameRoom CreateRoom(GameConfig config)
		{
			GameRoom room = new GameRoom(config);
			//MutexRooms.WaitOne();
			m_rooms.Add(config.Name, room);
			//Logger.WriteLine(String.Format("++Game:{0}",config.Name));
			//MutexRooms.ReleaseMutex();
			return room;
		}
 public GameRoom(GameConfig config)
 {
     m_clients = new List <GameClient>();
     Game      = new Game(this, config);
     IsOpen    = true;
 }
Exemple #13
0
 public GameRoom(GameConfig config)
 {
     m_clients = new List<GameClient>();
     Game = new Game(this, config);
     IsOpen = true;
 }
Exemple #14
0
 /// <summary>
 /// 创建房间
 /// </summary>
 /// <param name="server"></param>
 /// <param name="config"></param>
 /// <returns></returns>
 public static GameRoom CreateOrGetGame(GameConfig config)
 {
     string roomname = Password.OnlyName(config.Name);
     lock (Games)
     {
         if (Games.ContainsKey(roomname))
         {
             return Games[roomname];
         }
         if (Games.Count >= Program.Config.MaxRoomCount)
         {
             return null;
         }
         GameRoom room = new GameRoom(config);
         Logger.Info("create room:" + room.Name);
         Games.Add(roomname, room);
         ServerApi.OnRoomCreate(room);
         return room;
     }
 }
Exemple #15
0
 public static GameRoom CreateOrGetGame(GameConfig config)
 {
     if (m_rooms.ContainsKey(config.Name))
         return m_rooms[config.Name];
     return CreateRoom(config);
 }
Exemple #16
0
		private void RoomCreate(string name,string banlist,string gameinfo){
			GameConfig config = new GameConfig();
			config.Parse(gameinfo);
			config.Name = gameinfo;
			config.BanList = banlist;
			lock(Rooms){
				if(Rooms.ContainsKey(name)){
					Rooms[name] = config;
				}else{
					Rooms.Add(name, config);
				}
			}
			if(OnRoomCreate!=null){
				OnRoomCreate(this, name, banlist, gameinfo);
			}
		}