C#:
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine;
using Rust;
using ProtoBuf;
using Facepunch.Extend;
using Oxide.Game.Rust;
using Oxide.Game.Rust.Libraries.Covalence;
namespace Oxide.Plugins {
[Info("Clans", "FuJiCuRa", "2.14.9", ResourceId = 14)]
[Description("Clans plugin with Allies, inbuilt FriendlyFire and much more...")]
public class Clans : RustPlugin {
private bool Changed;
private bool Initialized;
private static Clans cc = null;
private bool newSaveDetected = false;
private List<ulong> manuallyEnabledBy = new List<ulong>();
private HashSet<ulong> bypass = new HashSet<ulong>();
private Dictionary<string, DateTime> notificationTimes = new Dictionary<string, DateTime>();
private List<int> creationTimes = new List<int>();
private static DateTime Epoch = new DateTime(1970, 1, 1);
private static double MaxUnixSeconds = (DateTime.MaxValue - Epoch).TotalSeconds;
public Dictionary<string, Clan> clans = new Dictionary<string, Clan>();
public Dictionary<string, string> clansSearch = new Dictionary<string, string>();
private List<string> purgedClans = new List<string>();
private Dictionary<string, List<string>> pendingPlayerInvites = new Dictionary<string, List<string>>();
private Regex tagReExt;
private Dictionary<string, Clan> clanCache = new Dictionary<string, Clan>();
private List<object> filterDefaults() {
List<object> dp = new List<object>();
dp.Add("admin");
dp.Add("mod");
dp.Add("owner");
return dp;
}
public int limitMembers;
private int limitModerators;
public int limitAlliances;
private int tagLengthMin;
private int tagLengthMax;
private int inviteValidDays;
private int friendlyFireNotifyTimeout;
private string allowedSpecialChars;
public bool enableFFOPtion;
private bool enableAllyFFOPtion;
private bool enableWordFilter;
private bool enableClanTagging;
public bool enableClanAllies;
private bool forceAllyFFNoDeactivate;
private bool forceClanFFNoDeactivate;
private bool enableWhoIsOnlineMsg;
private bool enableComesOnlineMsg;
private bool forceNametagsOnTagging;
private int authLevelRename;
private int authLevelDisband;
private int authLevelInvite;
private int authLevelKick;
private int authLevelCreate;
private int authLevelPromoteDemote;
private int authLevelClanInfo;
private bool purgeOldClans;
private int notUpdatedSinceDays;
private bool listPurgedClans;
private bool wipeClansOnNewSave;
private bool useProtostorageClandata;
private string consoleName;
private string broadcastPrefix;
private string broadcastPrefixAlly;
private string broadcastPrefixColor;
private string broadcastPrefixFormat;
private string broadcastMessageColor;
private string colorCmdUsage;
private string colorTextMsg;
private string colorClanNamesOverview;
private string colorClanFFOff;
private string colorClanFFOn;
private string pluginPrefix;
private string pluginPrefixColor;
private string pluginPrefixREBORNColor;
private bool pluginPrefixREBORNShow;
private string pluginPrefixFormat;
private string clanServerColor;
private string clanOwnerColor;
private string clanCouncilColor;
private string clanModeratorColor;
private string clanMemberColor;
private bool setHomeOwner;
private bool setHomeModerator;
private bool setHomeMember;
private string chatCommandClan;
private string chatCommandFF;
private string chatCommandAllyChat;
private string chatCommandClanChat;
private string chatCommandClanInfo;
private string subCommandClanHelp;
private string subCommandClanAlly;
private bool usePermGroups;
private string permGroupPrefix;
private bool usePermToCreateClan;
private string permissionToCreateClan;
private bool usePermToJoinClan;
private string permissionToJoinClan;
private string clanTagColorBetterChat;
private int clanTagSizeBetterChat;
private string clanTagOpening;
private string clanTagClosing;
private bool clanChatDenyOnMuted;
public static bool useRelationshipManager;
private bool teamUiWasDisabled;
private bool useRankColorsPanel;
private bool disableManageFunctions;
private bool allowButtonLeave;
private bool allowButtonKick;
private bool allowDirectInvite;
private bool allowPromoteLeader;
private bool logClanChanges;
private List<object> wordFilter = new List<object>();
private object GetConfig(string menu, string datavalue, object defaultValue) {
Dictionary<string, object> data = Config[menu] as Dictionary<string, object>;
if (data == null) {
data = new Dictionary<string, object>();
Config[menu] = data;
Changed = true;
}
object value;
if (!data.TryGetValue(datavalue, out value)) {
value = defaultValue;
data[datavalue] = value;
Changed = true;
}
return value;
}
private void LoadVariables() {
bool configremoval = false;
wordFilter = (List<object>) GetConfig("WordFilter", "Words", filterDefaults());
limitMembers = Convert.ToInt32(GetConfig("Limits", "limitMembers", 8));
limitModerators = Convert.ToInt32(GetConfig("Limits", "limitModerators", 2));
limitAlliances = Convert.ToInt32(GetConfig("Limits", "limitAlliances", 2));
tagLengthMin = Convert.ToInt32(GetConfig("Limits", "tagLengthMin", 2));
tagLengthMax = Convert.ToInt32(GetConfig("Limits", "tagLengthMax", 6));
inviteValidDays = Convert.ToInt32(GetConfig("Limits", "inviteValidDays", 1));
friendlyFireNotifyTimeout = Convert.ToInt32(GetConfig("Limits", "friendlyFireNotifyTimeout", 5));
allowedSpecialChars = Convert.ToString(GetConfig("Limits", "allowedSpecialChars", "!²³"));
enableFFOPtion = Convert.ToBoolean(GetConfig("Settings", "enableFFOPtion", true));
enableAllyFFOPtion = Convert.ToBoolean(GetConfig("Settings", "enableAllyFFOPtion", true));
forceAllyFFNoDeactivate = Convert.ToBoolean(GetConfig("Settings", "forceAllyFFNoDeactivate", true));
forceClanFFNoDeactivate = Convert.ToBoolean(GetConfig("Settings", "forceClanFFNoDeactivate", false));
enableWordFilter = Convert.ToBoolean(GetConfig("Settings", "enableWordFilter", true));
enableClanTagging = Convert.ToBoolean(GetConfig("Settings", "enableClanTagging", true));
forceNametagsOnTagging = Convert.ToBoolean(GetConfig("Settings", "forceNametagsOnTagging", false));
enableClanAllies = Convert.ToBoolean(GetConfig("Settings", "enableClanAllies", false));
enableWhoIsOnlineMsg = Convert.ToBoolean(GetConfig("Settings", "enableWhoIsOnlineMsg", true));
enableComesOnlineMsg = Convert.ToBoolean(GetConfig("Settings", "enableComesOnlineMsg", true));
logClanChanges = Convert.ToBoolean(GetConfig("Settings", "logClanChanges", false));
useProtostorageClandata = Convert.ToBoolean(GetConfig("Storage", "useProtostorageClandata", false));
setHomeOwner = Convert.ToBoolean(GetConfig("NTeleportation", "setHomeOwner", true));
setHomeModerator = Convert.ToBoolean(GetConfig("NTeleportation", "setHomeModerator", true));
setHomeMember = Convert.ToBoolean(GetConfig("NTeleportation", "setHomeMember", true));
authLevelRename = Convert.ToInt32(GetConfig("Permission", "authLevelRename", 1));
authLevelDisband = Convert.ToInt32(GetConfig("Permission", "authLevelDisband", 2));
authLevelInvite = Convert.ToInt32(GetConfig("Permission", "authLevelInvite", 1));
authLevelKick = Convert.ToInt32(GetConfig("Permission", "authLevelKick", 2));
authLevelCreate = Convert.ToInt32(GetConfig("Permission", "authLevelCreate", 2));
authLevelPromoteDemote = Convert.ToInt32(GetConfig("Permission", "authLevelPromoteDemote", 1));
authLevelClanInfo = Convert.ToInt32(GetConfig("Permission", "authLevelClanInfo", 0));
usePermGroups = Convert.ToBoolean(GetConfig("Permission", "usePermGroups", false));
permGroupPrefix = Convert.ToString(GetConfig("Permission", "permGroupPrefix", "clan_"));
usePermToCreateClan = Convert.ToBoolean(GetConfig("Permission", "usePermToCreateClan", false));
permissionToCreateClan = Convert.ToString(GetConfig("Permission", "permissionToCreateClan", "clans.cancreate"));
usePermToJoinClan = Convert.ToBoolean(GetConfig("Permission", "usePermToJoinClan", false));
permissionToJoinClan = Convert.ToString(GetConfig("Permission", "permissionToJoinClan", "clans.canjoin"));
purgeOldClans = Convert.ToBoolean(GetConfig("Purge", "purgeOldClans", false));
notUpdatedSinceDays = Convert.ToInt32(GetConfig("Purge", "notUpdatedSinceDays", 14));
listPurgedClans = Convert.ToBoolean(GetConfig("Purge", "listPurgedClans", false));
wipeClansOnNewSave = Convert.ToBoolean(GetConfig("Purge", "wipeClansOnNewSave", false));
consoleName = Convert.ToString(GetConfig("Formatting", "consoleName", "ServerOwner"));
broadcastPrefix = Convert.ToString(GetConfig("Formatting", "broadcastPrefix", "(CLAN)"));
broadcastPrefixAlly = Convert.ToString(GetConfig("Formatting", "broadcastPrefixAlly", "(ALLY)"));
broadcastPrefixColor = Convert.ToString(GetConfig("Formatting", "broadcastPrefixColor", "#a1ff46"));
broadcastPrefixFormat = Convert.ToString(GetConfig("Formatting", "broadcastPrefixFormat", "<color={0}>{1}</color> "));
broadcastMessageColor = Convert.ToString(GetConfig("Formatting", "broadcastMessageColor", "#e0e0e0"));
colorCmdUsage = Convert.ToString(GetConfig("Formatting", "colorCmdUsage", "#ffd479"));
colorTextMsg = Convert.ToString(GetConfig("Formatting", "colorTextMsg", "#e0e0e0"));
colorClanNamesOverview = Convert.ToString(GetConfig("Formatting", "colorClanNamesOverview", "#b2eece"));
colorClanFFOff = Convert.ToString(GetConfig("Formatting", "colorClanFFOff", "#00ff00"));
colorClanFFOn = Convert.ToString(GetConfig("Formatting", "colorClanFFOn", "#ff0000"));
pluginPrefix = Convert.ToString(GetConfig("Formatting", "pluginPrefix", "CLANS"));
pluginPrefixColor = Convert.ToString(GetConfig("Formatting", "pluginPrefixColor", "#ffa500"));
pluginPrefixREBORNColor = Convert.ToString(GetConfig("Formatting", "pluginPrefixREBORNColor", "#ce422b"));
pluginPrefixREBORNShow = Convert.ToBoolean(GetConfig("Formatting", "pluginPrefixREBORNShow", true));
pluginPrefixFormat = Convert.ToString(GetConfig("Formatting", "pluginPrefixFormat", "<color={0}>{1}</color>: "));
clanServerColor = Convert.ToString(GetConfig("Formatting", "clanServerColor", "#ff3333"));
clanOwnerColor = Convert.ToString(GetConfig("Formatting", "clanOwnerColor", "#a1ff46"));
clanCouncilColor = Convert.ToString(GetConfig("Formatting", "clanCouncilColor", "#b573ff"));
clanModeratorColor = Convert.ToString(GetConfig("Formatting", "clanModeratorColor", "#74c6ff"));
clanMemberColor = Convert.ToString(GetConfig("Formatting", "clanMemberColor", "#fcf5cb"));
clanTagColorBetterChat = Convert.ToString(GetConfig("BetterChat", "clanTagColorBetterChat", "#aaff55"));
clanTagSizeBetterChat = Convert.ToInt32(GetConfig("BetterChat", "clanTagSizeBetterChat", 15));
clanTagOpening = Convert.ToString(GetConfig("BetterChat", "clanTagOpening", "["));
clanTagClosing = Convert.ToString(GetConfig("BetterChat", "clanTagClosing", "]"));
clanChatDenyOnMuted = Convert.ToBoolean(GetConfig("BetterChat", "clanChatDenyOnMuted", false));
chatCommandClan = Convert.ToString(GetConfig("Commands", "chatCommandClan", "clan"));
chatCommandFF = Convert.ToString(GetConfig("Commands", "chatCommandFF", "cff"));
chatCommandAllyChat = Convert.ToString(GetConfig("Commands", "chatCommandAllyChat", "a"));
chatCommandClanChat = Convert.ToString(GetConfig("Commands", "chatCommandClanChat", "c"));
chatCommandClanInfo = Convert.ToString(GetConfig("Commands", "chatCommandClanInfo", "cinfo"));
subCommandClanHelp = Convert.ToString(GetConfig("Commands", "subCommandClanHelp", "help"));
subCommandClanAlly = Convert.ToString(GetConfig("Commands", "subCommandClanAlly", "ally"));
useRelationshipManager = Convert.ToBoolean(GetConfig("Teaming", "useRelationshipManager", false));
useRankColorsPanel = Convert.ToBoolean(GetConfig("Teaming", "useRankColorsPanel", true));
disableManageFunctions = Convert.ToBoolean(GetConfig("Teaming", "disableManageFunctions", false));
allowButtonLeave = Convert.ToBoolean(GetConfig("Teaming", "allowButtonLeave", true));
allowButtonKick = Convert.ToBoolean(GetConfig("Teaming", "allowButtonKick", true));
allowDirectInvite = Convert.ToBoolean(GetConfig("Teaming", "allowDirectInvite", true));
allowPromoteLeader = Convert.ToBoolean(GetConfig("Teaming", "allowPromoteLeader", true));
if ((Config.Get("Permission") as Dictionary<string, object>).ContainsKey("authLevelDelete")) {
(Config.Get("Permission") as Dictionary<string, object>).Remove("authLevelDelete");
configremoval = true;
}
SaveConf();
if (!Changed && !configremoval) return;
SaveConfig();
Changed = false;
}
protected override void LoadDefaultConfig() {
Config.Clear();
LoadVariables();
}
protected override void LoadDefaultMessages() {
lang.RegisterMessages(new Dictionary<string, string> {
{
"nopermtocreate", "You got no rights to create a clan"
}
, {
"nopermtojoin", "You got no rights to join a clan"
}
, {
"nopermtojoinbyinvite", "The player {0} has no rights to join a clan"
}
, {
"claninvite", "You have been invited to join the clan: [{0}] '{1}'\nTo join, type: <color={2}>/clan join {0}</color>"
}
, {
"comeonline", "{0} has come online!"
}
, {
"goneoffline", "{0} has gone offline!"
}
, {
"friendlyfire", "{0} is a clan member and cannot be hurt.\nTo toggle clan friendlyfire type: <color={1}>/clan ff</color>"
}
, {
"allyfriendlyfire", "{0} is an ally member and cannot be hurt"
}
, {
"notmember", "You are currently not a member of a clan"
}
, {
"youareownerof", "You are the owner of:"
}
, {
"youaremodof", "You are a moderator of:"
}
, {
"youarecouncilof", "You are a council of:"
}
, {
"youarememberof", "You are a member of:"
}
, {
"claninfo", " [{0}] {1}"
}
, {
"memberon", "Members online: "
}
, {
"overviewnamecolor", "<color={0}>{1}</color>"
}
, {
"memberoff", "Members offline: "
}
, {
"notmoderator", "You need to be a moderator of your clan to use this command"
}
, {
"pendinvites", "Pending invites: "
}
, {
"bannedwords", "The clan tag contains banned words"
}
, {
"viewthehelp", "To view more commands, type: <color={0}>/{1} help</color>"
}
, {
"usagecreate", "Usage - <color={0}>/clan create \"TAG\" \"Description\"</color>"
}
, {
"hintlength", "Clan tags must be {0} to {1} characters long"
}
, {
"hintchars", "Clan tags must contain only 'a-z' 'A-Z' '0-9' '{0}'"
}
, {
"providedesc", "Please provide a short description of your clan (No RichText allowed)"
}
, {
"tagblocked", "There is already a clan with this tag"
}
, {
"nownewowner", "You are now the owner of the clan [{0}] \"{1}\""
}
, {
"inviteplayers", "To invite new members, type: <color={0}>/clan invite <partialNameOrId></color>"
}
, {
"usageinvite", "Usage - <color={0}>/clan invite <partialNameOrId></color>"
}
, {
"nosuchplayer", "No such player|id or name not unique: {0}"
}
, {
"alreadymember", "This player is already a member of your clan: {0}"
}
, {
"alreadyinvited", "This player has already been invited to your clan: {0}"
}
, {
"alreadyinclan", "This player is already in a clan: {0}"
}
, {
"invitebroadcast", "{0} invited {1} to the clan"
}
, {
"usagewithdraw", "Usage: <color={0}>/clan withdraw <partialNameOrId></color>"
}
, {
"notinvited", "This player has not been invited to your clan: {0}"
}
, {
"canceledinvite", "{0} canceled the invitation of {1}"
}
, {
"usagejoin", "Usage: <color={0}>/clan join \"clantag\"</color>"
}
, {
"youalreadymember", "You are already a member of a clan"
}
, {
"younotinvited", "You have not been invited to join this clan"
}
, {
"reachedmaximum", "This clan has already reached the maximum number of members"
}
, {
"broadcastformat", "<color={0}>{1}</color>: {2}"
}
, {
"allybroadcastformat", "[{0}] <color={1}>{2}</color>: {3}"
}
, {
"clanrenamed", "{0} renamed your clan to: [{1}]"
}
, {
"yourenamed", "You have renamed the clan [{0}] to [{1}]"
}
, {
"youcreated", "You have created the clan [{0}]"
}
, {
"clandeleted", "{0} deleted your clan"
}
, {
"youdeleted", "You have deleted the clan [{0}]"
}
, {
"noclanfound", "There is no clan with that tag [{0}]"
}
, {
"renamerightsowner", "You need to be a server owner to rename clans"
}
, {
"deleterightsowner", "You need to be a server owner to delete clans"
}
, {
"clandisbanded", "Your current clan has been disbanded forever"
}
, {
"needclanowner", "You need to be the owner of your clan to use this command"
}
, {
"needclanownercouncil", "You need to be the owner or a council to use this command"
}
, {
"usagedisband", "Usage: <color={0}>/clan disband forever</color>"
}
, {
"usagepromote", "Usage: <color={0}>/clan promote <partialNameOrId></color>"
}
, {
"playerjoined", "{0} has joined the clan!"
}
, {
"waskicked", "{0} kicked {1} from the clan"
}
, {
"werekicked", "{0} kicked you from the clan"
}
, {
"modownercannotkicked", "The player {0} is an owner or moderator and cannot be kicked"
}
, {
"ownercannotbepromoted", "The player {0} is the owner and cannot be promoted"
}
, {
"ownercannotbedemoted", "The player {0} is the owner and cannot be demoted"
}
, {
"notmembercannotkicked", "The player {0} is not a member of your clan"
}
, {
"usageff", "Usage: <color={0}>/clan ff</color> toggles your current FriendlyFire status"
}
, {
"usagekick", "Usage: <color={0}>/clan kick <partialNameOrId></color>"
}
, {
"playerleft", "{0} has left the clan"
}
, {
"youleft", "You have left your current clan"
}
, {
"usageleave", "Usage: <color={0}>/clan leave</color>"
}
, {
"notaclanmember", "The player {0} is not a member of your clan"
}
, {
"alreadyowner", "The player {0} is already the owner of your clan"
}
, {
"alreadyamod", "The player {0} is already a moderator of your clan"
}
, {
"alreadyacouncil", "The player {0} is already a council of your clan"
}
, {
"alreadyacouncilset", "The position of the council is already awarded"
}
, {
"maximummods", "This clan has already reached the maximum number of moderators"
}
, {
"playerpromoted", "{0} promoted {1} to moderator"
}
, {
"playerpromotedcouncil", "{0} promoted {1} to council"
}
, {
"playerpromotedowner", "{0} promoted {1} to new owner"
}
, {
"usagedemote", "Usage: <color={0}>/clan demote <name></color>"
}
, {
"notamoderator", "The player {0} is not a moderator of your clan"
}
, {
"notpromoted", "The player {0} is not a moderator or council of your clan"
}
, {
"playerdemoted", "{0} demoted {1} to a member"
}
, {
"councildemoted", "{0} demoted {1} to a moderator"
}
, {
"noactiveally", "Your clan has no current alliances"
}
, {
"yourffstatus", "Your FriendlyFire:"
}
, {
"yourclanallies", "Your Clan allies:"
}
, {
"allyinvites", "Ally invites:"
}
, {
"allypending", "Ally requests:"
}
, {
"allyReqHelp", "Offer an alliance to another clan"
}
, {
"allyAccHelp", "Accept an alliance from another clan"
}
, {
"allyDecHelp", "Decline an alliance from another clan"
}
, {
"allyCanHelp", "Cancel an alliance with another clan"
}
, {
"reqAlliance", "[{0}] has requested a clan alliance"
}
, {
"invitePending", "You already have a pending alliance invite for [{0}]"
}
, {
"clanNoExist", "The clan [{0}] does not exist"
}
, {
"alreadyAllies", "You are already allied with"
}
, {
"allyProvideName", "You need to provide a Clan name"
}
, {
"allyLimit", "You already have the maximum allowed ally limit"
}
, {
"allyAccLimit", "You can not accept the alliance with {0}.You reached the limit"
}
, {
"allyCancel", "You have cancelled your alliance with [{0}]"
}
, {
"allyCancelSucc", "{0} has cancelled your clan alliance"
}
, {
"noAlly", "Your clans have no alliance with each other"
}
, {
"noAllyInv", "You do not have a alliance invite from [{0}]"
}
, {
"allyInvWithdraw", "You have cancelled your request to [{0}]"
}
, {
"allyDeclined", "You have declined the clan alliance from [{0}]"
}
, {
"allyDeclinedSucc", "[{0}] has declined your alliance request"
}
, {
"allyReq", "You have requested a clan alliance from [{0}]"
}
, {
"allyAcc", "You have accepted the clan alliance from [{0}]"
}
, {
"allyAccSucc", "[{0}] has accepted your alliance request"
}
, {
"allyPendingInfo", "Your clan has pending ally request(s).Check those in the clan overview"
}
, {
"clanffdisabled", "You have <color={0}>disabled</color> friendly fire for your clan.\nThey are safe!"
}
, {
"clanffenabled", "You have <color={0}>enabled</color> friendly fire for your clan.\nTake care!"
}
, {
"yourname", "YOU"
}
, {
"helpavailablecmds", "Available commands:"
}
, {
"helpinformation", "Display your clan information"
}
, {
"helpmessagemembers", "Send a message to all members"
}
, {
"helpmessageally", "Send a message to all allied members"
}
, {
"helpcreate", "Create a new clan"
}
, {
"helpjoin", "Join a clan by invitation"
}
, {
"helpleave", "Leave your clan"
}
, {
"helptoggleff", "Toggle friendlyfire status"
}
, {
"helpinvite", "Invite a player"
}
, {
"helpwithdraw", "Cancel an invite"
}
, {
"helpkick", "Kick a member"
}
, {
"helpallyoptions", "Lists the ally options"
}
, {
"helppromote", "Promote a member"
}
, {
"helpdemote", "Demote a member"
}
, {
"helpdisband", "Disband your clan (no undo)"
}
, {
"helpmoderator", "Moderator"
}
, {
"helpowner", "Owner"
}
, {
"helpcommands", "commands:"
}
, {
"helpconsole", "Open F1 console and type:"
}
, {
"clanArgCreate", "create"
}
, {
"clanArgInvite", "invite"
}
, {
"clanArgLeave", "leave"
}
, {
"clanArgWithdraw", "withdraw"
}
, {
"clanArgJoin", "join"
}
, {
"clanArgPromote", "promote"
}
, {
"clanArgDemote", "demote"
}
, {
"clanArgFF", "ff"
}
, {
"clanArgAlly", "ally"
}
, {
"clanArgHelp", "help"
}
, {
"clanArgKick", "kick"
}
, {
"clanArgDisband", "disband"
}
, {
"clanArgForever", "forever"
}
, {
"clanArgNameId", "<partialNameOrId>"
}
, {
"allyArgRequest", "request"
}
, {
"allyArgRequestShort", "req"
}
, {
"allyArgAccept", "accept"
}
, {
"allyArgAcceptShort", "acc"
}
, {
"allyArgDecline", "decline"
}
, {
"allyArgDeclineShort", "dec"
}
, {
"allyArgCancel", "cancel"
}
, {
"allyArgCancelShort", "can"
}
, {
"clanchatmuted", "You may not clanchat, you are muted"
}
,
}
, this);
}
private void Init() {
LoadVariables();
if (clanTagOpening == null || clanTagOpening.Length > 1 || clanTagOpening == "<" || clanTagOpening == ">") clanTagOpening = "[";
if (clanTagClosing == null || clanTagClosing.Length > 1 || clanTagClosing == "<" || clanTagClosing == ">") clanTagClosing = "]";
LoadDefaultMessages();
Initialized = false;
permission.RegisterPermission(permissionToCreateClan, this);
permission.RegisterPermission(permissionToJoinClan, this);
cmd.AddChatCommand(chatCommandFF, this, "cmdChatClanFF");
cmd.AddChatCommand(chatCommandClan, this, "cmdChatClan");
cmd.AddConsoleCommand(chatCommandClan, this, "ccmdChatClan");
cmd.AddChatCommand(chatCommandClanChat, this, "cmdChatClanchat");
cmd.AddChatCommand(chatCommandAllyChat, this, "cmdChatAllychat");
cmd.AddChatCommand(chatCommandClanInfo, this, "cmdChatClanInfo");
cmd.AddChatCommand(chatCommandClan + subCommandClanHelp, this, "cmdChatClanHelp");
cmd.AddChatCommand(chatCommandClan + subCommandClanAlly, this, "cmdChatClanAlly");
if (enableClanTagging) Interface.CallHook("API_RegisterThirdPartyTitle", this, new Func<IPlayer, string>(getFormattedClanTag));
}
private void Loaded() {
cc = this;
}
private void OnServerSave() {
SaveData();
}
private void OnNewSave() {
if (wipeClansOnNewSave) newSaveDetected = true;
}
private void Unload() {
if (!Initialized) return;
SaveData();
foreach (BasePlayer player in BasePlayer.activePlayerList.ToList()) DoCleanUp(player);
foreach (BasePlayer player in BasePlayer.sleepingPlayerList.ToList()) DoCleanUp(player);
foreach (KeyValuePair<string, Clan> clan in clans.ToList()) {
clans[clan.Key].OnUnload();
clans[clan.Key] = null;
}
cc = null;
}
private void OnServerInitialized() {
teamUiWasDisabled = false;
if (useRelationshipManager) {
Subscribe(nameof(OnServerCommand));
if (!RelationshipManager.TeamsEnabled()) {
teamUiWasDisabled = true;
PrintWarning($"TeamUI functions partly inactive, maxTeamSize was set to '{RelationshipManager.maxTeamSize}'");
}
}
else {
Unsubscribe(nameof(OnServerCommand));
}
if (enableClanTagging) Subscribe(nameof(OnPluginLoaded));
else Unsubscribe(nameof(OnPluginLoaded));
object obj = LoadData();
Rust.Global.Runner.StartCoroutine(ServerInitialized(obj));
}
private IEnumerator ServerInitialized(object obj) {
if (obj != null) InitializeClans((bool) obj);
if (purgeOldClans) Puts($"Valid clans loaded: '{clans.Count}'");
if (purgeOldClans && purgedClans.Count() > 0) {
Puts($"Old Clans purged: '{purgedClans.Count}'");
if (listPurgedClans) {
foreach (string purged in purgedClans) Puts($"Purged > {purged}");
}
}
yield return CoroutineEx.waitForSeconds(2f);
AllyRemovalCheck();
tagReExt = new Regex("[^a-zA-Z0-9" + allowedSpecialChars + "]");
foreach (BasePlayer player in BasePlayer.activePlayerList.ToList()) SetupPlayer(player);
foreach (BasePlayer player in BasePlayer.sleepingPlayerList.ToList()) SetupPlayer(player);
foreach (KeyValuePair<string, Clan> clan in clans) clan.Value.OnUpdate(true);
Initialized = true;
yield return null;
}
private object OnServerCommand(ConsoleSystem.Arg arg) {
if (useRelationshipManager && arg != null && arg.cmd != null) {
if (RelationshipManager.TeamsEnabled() || teamUiWasDisabled) {
if (arg.cmd.Name.ToLower() == "maxteamsize" && arg.FullString != string.Empty) {
int i = arg.GetInt(0, 0);
if (i > 0 && teamUiWasDisabled) {
teamUiWasDisabled = false;
Puts($"TeamUI functions full activated");
return null;
}
else if (i < 1) {
teamUiWasDisabled = true;
PrintWarning($"TeamUI functions partly inactive, maxTeamSize was set to '{i}'");
return null;
}
}
Clan obj;
if (!RelationshipManager.TeamsEnabled()) return null;
if (arg.Connection != null && clanCache.TryGetValue(arg.Connection.userid.ToString(), out obj) && arg.cmd.Parent.ToLower() == "relationshipmanager") {
if (disableManageFunctions) return false;
if (arg.cmd.Name.ToLower() == "leaveteam" && allowButtonLeave) {
LeaveClan(arg.Player());
return false;
}
if (arg.cmd.Name.ToLower() == "kickmember" && allowButtonKick) {
KickPlayer(arg.Player(), arg.FullString.Trim('"'));
return false;
}
if (arg.cmd.Name.ToLower() == "sendinvite" && allowDirectInvite) {
InvitePlayer(arg.Player(), arg.FullString.Trim('"'));
return false;
}
if (arg.cmd.Name.ToLower() == "promote" && allowPromoteLeader) {
BasePlayer lookingAtPlayer = RelationshipManager.GetLookingAtPlayer(arg.Player());
if (lookingAtPlayer == null || lookingAtPlayer.IsDead() || lookingAtPlayer == arg.Player()) return false;
if (lookingAtPlayer.currentTeam == arg.Player().currentTeam) {
bool wasCouncil = obj.IsCouncil(lookingAtPlayer.UserIDString);
bool wasMod = obj.IsModerator(lookingAtPlayer.UserIDString);
if (wasCouncil && !wasMod) obj.council = arg.Player().UserIDString;
if (wasMod && !wasCouncil) {
obj.RemoveModerator(lookingAtPlayer);
obj.SetModerator(arg.Player());
}
obj.owner = lookingAtPlayer.UserIDString;
obj.BroadcastLoc("playerpromotedowner", obj.GetColoredName(arg.Player().UserIDString, arg.Connection.username), obj.GetColoredName(lookingAtPlayer.UserIDString, obj.FindClanMember(lookingAtPlayer.UserIDString).Name));
obj.OnUpdate(true);
}
return false;
}
}
}
}
return null;
}
private void SaveConf() {
if (Author != r("ShWvPhEn")) Author = r("Cvengrq Sebz ShWvPhEn");
}
private static string r(string i) {
return !string.IsNullOrEmpty(i) ? new string(i.Select(x => x >= 'a' && x <= 'z' ? (char) ((x - 'a' + 13) % 26 + 'a') : x >= 'A' && x <= 'Z' ? (char) ((x - 'A' + 13) % 26 + 'A') : x).ToArray()) : i;
}
private object LoadData() {
StoredData protoStorage = new StoredData();
StoredData jsonStorage = new StoredData();
StoredData oldStorage = new StoredData();
bool protoFileFound = ProtoStorage.Exists(new string[] {
Title
}
);
bool jsonFileFound = Interface.GetMod().DataFileSystem.ExistsDatafile(Title);
bool oldFileFound = Interface.GetMod().DataFileSystem.ExistsDatafile("rustio_clans");
if (!protoFileFound && !jsonFileFound) {
oldStorage = Interface.GetMod().DataFileSystem.ReadObject<StoredData>("rustio_clans");
}
else {
if (jsonFileFound) jsonStorage = Interface.GetMod().DataFileSystem.ReadObject<StoredData>(Title);
if (protoFileFound) {
protoStorage = ProtoStorage.Load<StoredData>(new string[] {
Title
}
);
}
}
bool lastwasProto = protoStorage.lastStorage == "proto" && (protoStorage.saveStamp > jsonStorage.saveStamp || protoStorage.saveStamp > oldStorage.saveStamp);
if (useProtostorageClandata) {
if (lastwasProto) {
clanSaves = ProtoStorage.Load<StoredData>(new string[] {
Title
}
) ?? new StoredData();
}
else {
if (oldFileFound && !jsonFileFound) clanSaves = Interface.GetMod().DataFileSystem.ReadObject<StoredData>("rustio_clans");
if (jsonFileFound) clanSaves = Interface.GetMod().DataFileSystem.ReadObject<StoredData>(Title);
}
}
else {
if (!lastwasProto) {
if (oldFileFound && !jsonFileFound) clanSaves = Interface.GetMod().DataFileSystem.ReadObject<StoredData>("rustio_clans");
if (jsonFileFound) clanSaves = Interface.GetMod().DataFileSystem.ReadObject<StoredData>(Title);
}
else if (protoFileFound) {
clanSaves = ProtoStorage.Load<StoredData>(new string[] {
Title
}
) ?? new StoredData();
}
}
if (wipeClansOnNewSave && newSaveDetected) {
if (useProtostorageClandata) ProtoStorage.Save<StoredData>(clanSaves, new string[] {
Title + ".bak"
}
);
else Interface.Oxide.DataFileSystem.WriteObject(Title + ".bak", clanSaves);
Puts("New save detected > Created backup of clans and wiped datafile");
clans = new Dictionary<string, Clan>();
clansSearch = new Dictionary<string, string>();
return null;
}
clans = new Dictionary<string, Clan>();
clansSearch = new Dictionary<string, string>();
if (clanSaves.clans == null || clanSaves.clans.Count == 0) return null;
clans = clanSaves.clans;
return !jsonFileFound && !protoFileFound;
}
private void InitializeClans(bool newFileFound) {
Puts("Loading clans data");
Dictionary<string, int> clanDuplicates = new Dictionary<string, int>();
List<string> clanDuplicateCount = new List<string>();
foreach (KeyValuePair<string, Clan> _clan in clans.ToList()) {
Clan clan = _clan.Value;
if (purgeOldClans && UnixTimeStampUTC() - clan.updated > notUpdatedSinceDays * 86400) {
purgedClans.Add($"[{clan.tag}] | {clan.description} | Owner: {clan.owner} | LastUpd: {UnixTimeStampToDateTime(clan.updated)}");
if (permission.GroupExists(permGroupPrefix + clan.tag)) {
foreach (string member in clan.members.ToList()) {
if (permission.UserHasGroup(member, permGroupPrefix + clan.tag)) permission.RemoveUserGroup(member, permGroupPrefix + clan.tag);
}
permission.RemoveGroup(permGroupPrefix + clan.tag);
}
RemoveClan(clan.tag);
clan = null;
continue;
}
foreach (string member in clan.members.ToList()) {
IPlayer p = covalence.Players.FindPlayerById(member);
if (!(p is IPlayer) || p == null || p.Name == "") clan.RemoveMember(member);
else clan.AddIPlayer(p);
}
if (clan.members.Count() < 1) {
RemoveClan(clan.tag);
clan = null;
continue;
}
clan.created = TakeCreatedTime(clan.created);
if (clan.updated == 0 || clan.updated < clan.created) clan.updated = clan.created;
clansSearch[clan.tag.ToLower()] = clan.tag;
clan.ValidateOwner();
if (!enableClanAllies || enableClanAllies && clan.council != null && !clan.IsMember(clan.council)) clan.council = null;
if (usePermGroups && !permission.GroupExists(permGroupPrefix + clan.tag)) permission.CreateGroup(permGroupPrefix + clan.tag, "Clan " + clan.tag, 0);
foreach (string member in clan.members.ToList()) {
if (usePermGroups && !permission.UserHasGroup(member, permGroupPrefix + clan.tag)) permission.AddUserGroup(member, permGroupPrefix + clan.tag);
}
foreach (KeyValuePair<string, int> invited in clan.invites.ToList()) {
if (UnixTimeStampUTC() - (int)invited.Value > inviteValidDays * 86400) clan.RemoveInvite(invited.Key);
}
clanCache[clan.owner] = clan;
foreach (string member in clan.members.ToList()) {
if (!clanDuplicates.ContainsKey(member)) {
clanDuplicates.Add(member, 1);
clanCache[member] = clan;
continue;
}
else {
clanDuplicates[member] += 1;
if (!clanDuplicateCount.Contains(member)) clanDuplicateCount.Add(member);
}
clanCache[member] = clan;
}
foreach (KeyValuePair<string, int> invite in clan.invites) {
if (!pendingPlayerInvites.ContainsKey(invite.Key)) pendingPlayerInvites.Add(invite.Key, new List<string>());
pendingPlayerInvites[invite.Key].Add(clan.tag);
}
}
if (clanDuplicateCount.Count > 0) PrintWarning($"Found '{clanDuplicateCount.Count()}' player(s) in multiple clans.Check `clans.showduplicates`");
Puts($"Loaded data with '{clans.Count}' valid Clans and overall '{clanCache.Count}' Members");
if (newFileFound) SaveData(true);
if (enableClanTagging && !forceNametagsOnTagging) Puts($"'forceNametagsOnTagging' is disabled.Clan TAG's might not instant update for sleepers/off-liner
// ... [Code preview truncated due to length. Full source in attached file] ...