public RoomChangeRuleNotifyAck2Message(ChangeRuleDto2 settings) { Settings = settings; }
public RoomChangeRuleNotifyAck2Message() { Settings = new ChangeRuleDto2(); }
public RoomChangeRuleAckMessage(ChangeRuleDto2 settings) { Settings = settings; }
public RoomChangeRuleAckMessage() { Settings = new ChangeRuleDto2(); }
public void ChangeRules2(ChangeRuleDto2 options) { using (_playerSync.Lock()) { if (IsChangingRules) { Master?.Session?.SendAsync(new ServerResultAckMessage(ServerResult.RoomChangingRules)); return; } if (!RoomManager.GameRuleFactory.Contains((GameRule)options.GameRule)) { Logger.ForAccount(Master) .Error("Game rule {gameRule} does not exist", options.GameRule); //throw new Exception("gamerule is not available"); Master?.Session?.SendAsync(new ServerResultAckMessage(ServerResult.FailedToRequestTask)); return; } // ToDo check if current player count is not above the new player limit var israndom = false; if ((GameRule)options.GameRule != GameRule.Practice && (GameRule)options.GameRule != GameRule.CombatTrainingTD && (GameRule)options.GameRule != GameRule.CombatTrainingDM) { if (options.Map_ID == 228 && (GameRule)options.GameRule == GameRule.BattleRoyal) //random br { israndom = true; options.Map_ID = 112; } else if (options.Map_ID == 229 && (GameRule)options.GameRule == GameRule.Chaser) //random chaser { israndom = true; options.Map_ID = 225; } else if (options.Map_ID == 231 && (GameRule)options.GameRule == GameRule.Deathmatch ) //random deathmatch { israndom = true; options.Map_ID = 20; } else if (options.Map_ID == 230 && (GameRule)options.GameRule == GameRule.Touchdown ) //random touchdown { israndom = true; options.Map_ID = 66; } var map = GameServer.Instance.ResourceCache.GetMaps().GetValueOrDefault(options.Map_ID); if (map == null) { Logger.ForAccount(Master) .Error($"Map {options.Map_ID} does not exist"); Master?.Session?.SendAsync(new ServerResultAckMessage(ServerResult.FailedToRequestTask)); return; } if (!map.GameRules.Contains((GameRule)options.GameRule)) { Logger.ForAccount(Master) .Error( $"Map {map.Id}({map.Name}) is not available for game rule {(GameRule) options.GameRule}"); Master?.Session?.SendAsync(new ServerResultAckMessage(ServerResult.FailedToRequestTask)); return; } } if (options.Player_Limit < 1) { options.Player_Limit = 1; } if ((GameRule)options.GameRule == GameRule.CombatTrainingTD || (GameRule)options.GameRule == GameRule.CombatTrainingDM) { options.Player_Limit = 12; } var matchkey = new MatchKey(); if ((GameRule)options.GameRule == GameRule.CombatTrainingDM || (GameRule)options.GameRule == GameRule.CombatTrainingTD || (GameRule)options.GameRule == GameRule.Practice) { options.FMBurnMode = 1; } var isfriendly = false; var isburning = false; var isWithoutStats = false; switch (options.FMBurnMode) { case 0: isfriendly = false; break; case 1: isfriendly = true; break; case 2: isfriendly = false; isburning = true; break; case 3: isburning = true; isfriendly = true; break; case 4: isWithoutStats = true; break; case 5: isWithoutStats = isfriendly = true; break; } Options.Name = options.Name; Options.MapId = options.Map_ID; Options.PlayerLimit = options.Player_Limit; Options.GameRule = (GameRule)options.GameRule; Options.TimeLimit = TimeSpan.FromMinutes(options.Time); Options.ScoreLimit = options.Points; Options.Password = options.Password; Options.IsFriendly = isfriendly; Options.IsBurning = isburning; Options.IsRandom = israndom; Options.ItemLimit = (byte)options.Weapon_Limit; Options.HasSpectator = options.HasSpectator; Options.SpectatorLimit = options.SpectatorLimit; Options.IsWithoutStats = isWithoutStats; Players.Values.ToList().ForEach(playr => { playr.RoomInfo.IsReady = false; }); RoomChangePlayers = TeamManager.Players.ToList(); GameRuleManager.MapInfo = GameServer.Instance.ResourceCache.GetMaps()[Options.MapId]; GameRuleManager.GameRule = RoomManager.GameRuleFactory.Get(Options.GameRule, this); BroadcastExcept(Master, new RoomChangeRuleNotifyAck2Message(Options.Map <RoomCreationOptions, ChangeRuleDto2>())); _changingRulesTimer = TimeSpan.Zero; IsChangingRules = true; } }
public void ChangeRules2(ChangeRuleDto2 options) { if (Disposed) { return; } if (IsChangingRules) { Master?.SendAsync(new ServerResultAckMessage(ServerResult.RoomChangingRules)); return; } if (options.PlayerLimit < Players.Count) { Logger.ForAccount(Master).Error("Room has more players than new limit"); Master?.SendAsync(new MessageChatAckMessage(ChatType.Channel, Master.Account.Id, "SYSTEM", "Room has more players than new limit")); Master?.SendAsync(new ServerResultAckMessage(ServerResult.FailedToRequestTask)); return; } if (options.SpectatorLimit < (byte)TeamManager.Spectators.Count()) { Logger.ForAccount(Master).Error("Room has more spectators than new limit"); Master?.SendAsync(new MessageChatAckMessage(ChatType.Channel, Master.Account.Id, "SYSTEM", "Room has more players than new limit")); Master?.SendAsync(new ServerResultAckMessage(ServerResult.FailedToRequestTask)); return; } var gameRule = (GameRule)options.GameRule; if (!RoomManager.GameRuleFactory.Contains((GameRule)options.GameRule)) { Logger.ForAccount(Master).Error("Game rule {0} does not exist", options.GameRule); Master?.SendAsync(new ServerResultAckMessage(ServerResult.FailedToRequestTask)); return; } if (string.IsNullOrWhiteSpace(options.Name) || string.IsNullOrEmpty(options.Name)) { Master?.SendAsync(new ServerResultAckMessage(ServerResult.FailedToRequestTask)); return; } var israndom = false; var maps = GameServer.Instance.ResourceCache.GetMaps(); var map = maps.FirstOrDefault(x => x.Value.byteId == options.MapId && x.Value.GameRule == options.GameRule) .Value; if (!Master.Channel?.RoomManager.GameRuleFactory.Contains(options.GameRule) ?? false) { Logger.ForAccount(Master) .Error("Game rule {gameRule} does not exist", options.GameRule); Master.SendAsync(new ServerResultAckMessage(ServerResult.FailedToRequestTask)); return; } if (map == null) { Logger.ForAccount(Master) .Error("Map {map} does not exist", options.MapId); Master.SendAsync(new ServerResultAckMessage(ServerResult.FailedToRequestTask)); return; } if (map.IsRandom && map.GameRule == options.GameRule) { israndom = true; var modeMaps = maps.Where(x => x.Value.GameRule == options.GameRule && !x.Value.IsRandom); var selmap = modeMaps.ElementAtOrDefault(new SecureRandom().Next(0, modeMaps.Count())); options.MapId = (byte)selmap.Key; } map = maps.GetValueOrDefault(options.MapId); Logger.ForAccount(Master).Information("ChangeRoom || Id: {id} Room: {mode}, {mapid}", Id, options.GameRule, options.MapId); if (options.GameRule != GameRule.Practice && options.GameRule != GameRule.CombatTrainingTD && options.GameRule != GameRule.CombatTrainingDM) { if (map.GameRule != options.GameRule) { Logger.ForAccount(Master).Error("Map {mapId}({mapName}) is not available for game rule {gameRule}", map.Id, map.Name, options.GameRule); Master.SendAsync(new ServerResultAckMessage(ServerResult.FailedToCreateRoom)); return; } if (options.GameRule == GameRule.Practice) { if (!Namecheck.IsNameValid(options.Name, true)) { Master.SendAsync(new ServerResultAckMessage(ServerResult.FailedToRequestTask)); return; } } } if (options.PlayerLimit > map.MaxPlayers) { Logger.ForAccount(Master).Error("Wrong playerLimit for Map {0}", map.Id); Master.SendAsync(new ServerResultAckMessage(ServerResult.FailedToCreateRoom)); return; } var isfriendly = false; var isburning = false; var isWithoutStats = false; switch (options.FMBurnMode) { case 0: isfriendly = false; break; case 1: isfriendly = true; break; case 2: isfriendly = false; isburning = true; break; case 3: isburning = true; isfriendly = true; break; case 4: isWithoutStats = true; break; case 5: isWithoutStats = isfriendly = true; break; } _changingRulesTimer = TimeSpan.Zero; IsChangingRules = true; Options.ChangeRuleId = options.ChangeRuleId; Options.Name = options.Name; Options.MapId = options.MapId; Options.PlayerLimit = options.PlayerLimit; Options.GameRule = gameRule; Options.TimeLimit = TimeSpan.FromMinutes(options.Time); Options.ScoreLimit = options.Points; Options.Password = options.Password; Options.IsFriendly = isfriendly; Options.IsBurning = isburning; Options.IsRandom = israndom; Options.ItemLimit = (byte)options.ItemLimit; Options.HasSpectator = options.HasSpectator; Options.SpectatorLimit = options.SpectatorLimit; Options.IsWithoutStats = isWithoutStats; Players.Values.ToList().ForEach(playr => { playr.RoomInfo.IsReady = false; }); foreach (var plr in Players.Values) { _roomChangePlayers.Add(plr, plr.RoomInfo.Mode); if (TeamManager.ContainsKey(Team.Alpha) && plr.RoomInfo.Team.Team == Team.Alpha) { _roomChangeAlphaPlayers.Add(plr, plr.RoomInfo.Mode); } if (TeamManager.ContainsKey(Team.Beta) && plr.RoomInfo.Team.Team == Team.Beta) { _roomChangeBetaPlayers.Add(plr, plr.RoomInfo.Mode); } } GameRuleManager.MapInfo = GameServer.Instance.ResourceCache.GetMaps()[Options.MapId]; GameRuleManager.GameRule = RoomManager.GameRuleFactory.Get(Options.GameRule, this); BroadcastExcept(Master, new RoomChangeRuleNotifyAck2Message(Options.Map <RoomCreationOptions, ChangeRuleDto2>())); }