public string Execute( [CustomSuggestions(nameof(GetClanTagSuggestions))] string clanTag) { var faction = FactionSystem.ServerGetFactionByClanTag(clanTag); var bannedCount = 0; foreach (var playerName in FactionSystem.ServerGetFactionMemberNames(faction)) { var character = Server.Characters.GetPlayerCharacter(playerName); if (character == this.ExecutionContextCurrentCharacter) { continue; } if (ServerPlayerAccessSystem.SetBlackListEntry(playerName, isEnabled: true)) { bannedCount++; } } if (bannedCount == 0) { return($"No need to add anyone from the faction [{clanTag}] to the blacklist (already added)"); } return($"{bannedCount} player(s) of the faction [{clanTag}] were added to the blacklist"); }
private static ILogicObject ServerGetOwningFaction(IWorldObject worldObject) { ILogicObject faction = null; if (worldObject is IStaticWorldObject staticWorldObject) { var areasGroup = LandClaimSystem.SharedGetLandClaimAreasGroup(staticWorldObject); if (areasGroup is null) { throw new Exception( "Cannot modify faction access mode for an object without a faction land claim area"); } faction = LandClaimAreasGroup.GetPublicState(areasGroup).ServerFaction; } else if (worldObject.ProtoGameObject is IProtoVehicle) { var clanTag = worldObject.GetPublicState <VehiclePublicState>().ClanTag; if (string.IsNullOrEmpty(clanTag)) { throw new Exception("The vehicle doesn't belong to a faction: " + worldObject); } faction = FactionSystem.ServerGetFactionByClanTag(clanTag); } if (faction is null) { throw new Exception( "Cannot modify faction access mode for an object without a faction land claim area"); } return(faction); }
private static void ServerNotifyFactionAllies( ILogicObject faction, ILogicObject area, ILogicObject areasGroup) { var allyFactions = Faction.GetPrivateState(faction) .FactionDiplomacyStatuses .Where(p => p.Value == FactionDiplomacyStatus.Ally) .Select(p => FactionSystem.ServerGetFactionByClanTag(p.Key)) .ToArray(); if (allyFactions.Length == 0) { return; } var charactersToNotify = allyFactions.SelectMany(FactionSystem.ServerGetFactionMembersReadOnly) .ToArray(); var playerCharactersToNotify = new List <ICharacter>(); foreach (var memberEntry in charactersToNotify) { var character = Server.Characters.GetPlayerCharacter(memberEntry.Name); if (character is not null && !LandClaimSystem.ServerIsOwnedArea(area, character, requireFactionPermission: false)) { playerCharactersToNotify.Add(character); } } if (playerCharactersToNotify.Count == 0) { return; } var clanTag = FactionSystem.SharedGetClanTag(faction); var mark = new ServerAllyBaseUnderRaidMark(areasGroup, factionMemberName: null, clanTag); ServerNotifiedCharactersForAreasGroups[mark] = playerCharactersToNotify; var mapPosition = LandClaimSystem.SharedGetLandClaimGroupCenterPosition(areasGroup); Instance.CallClient(playerCharactersToNotify, _ => _.ClientRemote_AllyBaseUnderRaid( areasGroup.Id, mark.FactionMemberName, mark.ClanTag, mapPosition)); }
public string Execute(ICharacter player, string clanTag) { var faction = FactionSystem.ServerGetFactionByClanTag(clanTag); if (faction is null) { return("Faction not found: " + clanTag); } var result = FactionSystem.ServerForceAcceptApplication(player, faction); return("Faction application accept result: " + result.GetDescription()); }
private static void ServerAreasGroupChangedHandler( ILogicObject area, [CanBeNull] ILogicObject areasGroupFrom, [CanBeNull] ILogicObject areasGroupTo) { var byMember = ServerPlayerCharacterCurrentActionStateContext.CurrentCharacter ?? (ServerRemoteContext.IsRemoteCall ? ServerRemoteContext.Character : null); if (areasGroupTo is not null) { var clanTag = LandClaimAreasGroup.GetPublicState(areasGroupTo).FactionClanTag; if (string.IsNullOrEmpty(clanTag)) { return; } var faction = FactionSystem.ServerGetFactionByClanTag(clanTag); var centerTilePosition = LandClaimArea.GetPublicState(area).LandClaimCenterTilePosition; Logger.Important( string.Format("Faction-owned land claim areas group expanded with a new claim area: {0} at {1}", areasGroupTo, centerTilePosition)); FactionSystem.ServerOnLandClaimExpanded(faction, centerTilePosition, byMember: byMember); } else if (areasGroupFrom is not null) { var clanTag = LandClaimAreasGroup.GetPublicState(areasGroupFrom).FactionClanTag; if (string.IsNullOrEmpty(clanTag)) { return; } var faction = FactionSystem.ServerGetFactionByClanTag(clanTag); var centerTilePosition = LandClaimArea.GetPublicState(area).LandClaimCenterTilePosition; Logger.Important( string.Format("Faction-owned land claim areas group removed: {0} at {1}", areasGroupFrom, centerTilePosition)); FactionSystem.ServerOnLandClaimRemoved(faction, centerTilePosition, byMember: byMember); } }
private static void ServerRaidBlockStartedOrExtendedHandler( ILogicObject area, ICharacter raiderCharacter, bool isNewRaidBlock, bool isStructureDestroyed) { if (!isNewRaidBlock) { return; } var areasGroup = LandClaimSystem.SharedGetLandClaimAreasGroup(area); if (ServerNotifiedCharactersForAreasGroups.ContainsKey( ServerAllyBaseUnderRaidMark.CreateKeyOnly(areasGroup))) { // notification for this areas group is already sent return; } ILogicObject faction; var clanTag = LandClaimSystem.SharedGetAreaOwnerFactionClanTag(area); if (!string.IsNullOrEmpty(clanTag)) { // owned by a faction, notify allies faction = FactionSystem.ServerGetFactionByClanTag(clanTag); ServerNotifyFactionAllies(faction, area, areasGroup); return; } // not owned by faction, // check whether its founder is a member of any faction and notify its members var founderName = LandClaimArea.GetPrivateState(area) .LandClaimFounder; var founderCharacter = Server.Characters.GetPlayerCharacter(founderName); if (founderCharacter is null) { return; } faction = FactionSystem.ServerGetFaction(founderCharacter); if (faction is not null) { ServerNotifyFactionMembers(faction, founderCharacter, area, areasGroup); } }
public string Execute(string clanTag, byte level) { var faction = FactionSystem.ServerGetFactionByClanTag(clanTag); if (faction is null) { return("Faction not found: " + clanTag); } level = (byte)MathHelper.Clamp((int)level, min: 1, max: FactionConstants.MaxFactionLevel); Faction.GetPublicState(faction).Level = level; return("Faction level changed to: " + level); }
public string Execute( [CustomSuggestions(nameof(GetClanTagSuggestions))] string clanTag, int minutes = 30, string kickMessageInQuotes = null) { var faction = FactionSystem.ServerGetFactionByClanTag(clanTag); if (minutes < 1 || minutes > 10000) { throw new Exception("Minutes must be in 1-10000 range"); } var kickedCount = 0; foreach (var playerName in FactionSystem.ServerGetFactionMemberNames(faction)) { var character = Server.Characters.GetPlayerCharacter(playerName); if (character == this.ExecutionContextCurrentCharacter) { continue; } ServerPlayerAccessSystem.Kick(character, minutes, kickMessageInQuotes); kickedCount++; } if (kickedCount == 0) { return($"Cannot kick anyone from the faction [{clanTag}]"); } var result = $"{kickedCount} player(s) of the faction [{clanTag}] successfully kicked from the server for {minutes} minutes"; if (!string.IsNullOrEmpty(kickMessageInQuotes)) { result += " with a following message:" + Environment.NewLine + kickMessageInQuotes; } return(result); }
public static IReadOnlyList <string> SharedGetOwners(IWorldObject worldObject, out bool isFactionAccess) { isFactionAccess = false; switch (worldObject) { case IStaticWorldObject staticWorldObject: { var areasGroup = LandClaimSystem.SharedGetLandClaimAreasGroup(staticWorldObject); if (areasGroup is null || LandClaimAreasGroup.GetPublicState(areasGroup).FactionClanTag is not { } clanTag || string.IsNullOrEmpty(clanTag)) { break; } // the static object is inside the faction-owned land claim, var faction = FactionSystem.ServerGetFactionByClanTag(clanTag); return(FactionSystem.ServerGetFactionMemberNames(faction).ToList()); } case IDynamicWorldObject when worldObject.ProtoGameObject is IProtoVehicle: { var clanTag = worldObject.GetPublicState <VehiclePublicState>().ClanTag; if (string.IsNullOrEmpty(clanTag)) { break; } // the vehicle is owned by faction var faction = FactionSystem.ServerGetFactionByClanTag(clanTag); return(FactionSystem.ServerGetFactionMemberNames(faction).ToList()); } } return(SharedGetDirectOwners(worldObject)); }
public static ILogicObject ServerGetLandOwnerFactionOrFounderFaction(ILogicObject area) { ILogicObject faction = null; { var clanTag = SharedGetAreaOwnerFactionClanTag(area); if (!string.IsNullOrEmpty(clanTag)) { faction = FactionSystem.ServerGetFactionByClanTag(clanTag); } else { var founderName = LandClaimArea.GetPrivateState(area) .LandClaimFounder; var founderCharacter = Server.Characters.GetPlayerCharacter(founderName); if (founderCharacter is not null) { faction = FactionSystem.ServerGetFaction(founderCharacter); } } } return(faction); }
private static void ServerBossDefeatedHandler( IProtoCharacterMob protoCharacterBoss, Vector2Ushort bossPosition, List <ServerBossLootSystem.WinnerEntry> winnerEntries) { var lootByFaction = winnerEntries.GroupBy(e => FactionSystem.SharedGetClanTag(e.Character)) .Where(g => !string.IsNullOrEmpty(g.Key)) .ToDictionary(g => g.Key, g => g.Sum(l => l.LootCount)); foreach (var pair in lootByFaction) { var clanTag = pair.Key; var faction = FactionSystem.ServerGetFactionByClanTag(clanTag); if (faction is null) { Api.Logger.Error("Should be impossible - no faction for clan tag: " + clanTag); continue; } var factionPrivateState = Faction.GetPrivateState(faction); factionPrivateState.ServerMetricBossScore += (ulong)pair.Value; /*Logger.Dev("Boss metric updated: " + factionPrivateState.ServerMetricBossScore);*/ } }
private static bool ServerHasFactionAccess( ICharacter character, string objectClanTag, WorldObjectFactionAccessModes factionAccessModes) { if (factionAccessModes == WorldObjectFactionAccessModes.Closed) { // always closed return(false); } if (factionAccessModes == WorldObjectFactionAccessModes.Everyone) { // always opened return(true); } var playerClanTag = FactionSystem.SharedGetClanTag(character); if (string.IsNullOrEmpty(playerClanTag)) { // player don't have a faction return(false); } if (factionAccessModes.HasFlag(WorldObjectFactionAccessModes.AllyFactionMembers)) { if (objectClanTag == playerClanTag) { // current faction also allowed return(true); } var objectFaction = FactionSystem.ServerGetFactionByClanTag(objectClanTag); return(FactionSystem.SharedGetFactionDiplomacyStatus(objectFaction, playerClanTag) == FactionDiplomacyStatus.Ally); } // all further checks are only for the current faction if (objectClanTag != playerClanTag) { return(false); } if (factionAccessModes.HasFlag(WorldObjectFactionAccessModes.AllFactionMembers)) { // all current faction members allowed return(true); } // only a specific role or roles are allowed var characterRole = FactionSystem.ServerGetRole(character); return(CheckAccessRights(WorldObjectFactionAccessModes.Leader, FactionMemberRole.Leader) || CheckAccessRights(WorldObjectFactionAccessModes.Officer1, FactionMemberRole.Officer1) || CheckAccessRights(WorldObjectFactionAccessModes.Officer2, FactionMemberRole.Officer2) || CheckAccessRights(WorldObjectFactionAccessModes.Officer3, FactionMemberRole.Officer3)); bool CheckAccessRights(WorldObjectFactionAccessModes flag, FactionMemberRole role) => characterRole == role && factionAccessModes.HasFlag(flag); }
private IReadOnlyDictionary <ProtoFactionScoreMetric, uint> ServerRemote_GetScoreMetrics(string clanTag) { var faction = FactionSystem.ServerGetFactionByClanTag(clanTag); return(Faction.GetPrivateState(faction).LeaderboardScoreByMetric); }