C#:
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using Oxide.Core.Libraries.Covalence;
using Oxide.Game.Rust.Cui;
using Oxide.Core.Plugins;
using UnityEngine;
using ProtoBuf;
using Oxide.Core;
using System;
using System.Collections;
using System.IO;
using System.Text.RegularExpressions;
namespace Oxide.Plugins {
[Info("HUDPanel", "FouDuGame360", "1.2.5")]
[Description("This plugin allows you to have a graphical interface on your servers which will then give you information on the number of players, my not only that, all that in real time")]
public class HUDPanel : RustPlugin {
#region Reference Plugin
[PluginReference]
Plugin TimedPermissions;
[PluginReference]
Plugin IQPermissions;
[PluginReference]
Plugin Economics;
[PluginReference]
Plugin ServerRewards;
[PluginReference]
Plugin TruePVE;
//[PluginReference] private Plugin NextGenPVE;
[PluginReference]
Plugin ImageLibrary;
[PluginReference]
Plugin ZoneManager;
#endregion
#region Reference Global
private bool DEV_DEBUG = false;
private bool IsPveEnabled = false;
private bool IsPluginTimedPermission = false;
private static string _LinkGeneratorImages = "https://hud-panel.the-bandit.ovh/api/v1.0.0/GIMG/index.php";
private Configuration _config;
private List<CargoPlane> ActivePlanes;
private List<PatrolHelicopter> ActiveHelicopters;
private List<CargoShip> ActiveCargoships;
private List<CH47Helicopter> ActiveChinooks;
private List<BradleyAPC> ActiveBradleys;
private Dictionary<string, bool> Tmp_Val_EventCustom = new Dictionary<string, bool>();
private Dictionary<string, Dictionary<string, DateTime>> InfoPluginTimedPerms = new Dictionary<string, Dictionary<string, DateTime>>();
private Dictionary<BasePlayer, ListPlayerConnectServer> _ListPlayerConnectServer = new Dictionary<BasePlayer, ListPlayerConnectServer>();
private class ListPlayerConnectServer {
public List<string> HideLoad = new List<string>();
public bool _PlayerPowerToggle = false;
public InfoList _PlayerInfoEvent = new InfoList();
public Vector3 PlayerMarkerPos = Vector3.zero;
public int GetCoordID = 0;
public int MessagesID = 0;
public string PvpPVE_Info1 = string.Empty;
public string PvpPVE_Info2 = string.Empty;
public bool PlayerZoneNoPve = false;
}
#endregion
#region API Plugin
private bool API_HUDPanel_GetIsPveEnabled() => IsPveEnabled;
private bool API_HUDPanel_EditIsPveEnabled(bool pve) => IsPveEnabled = pve;
private void API_HUDPanel_ReloadBloc(BasePlayer player, string name) {
CuiElementContainer container = new CuiElementContainer();
UI.AddModuleUI(this, ref container, GetAllPanelList(), name, player, true);
UI.Create(player, container);
}
#endregion
#region Langage
protected override void LoadDefaultMessages() {
lang.RegisterMessages(new Dictionary<string, string> {
["TimePermissions_Wn_Reload"]
= "Attention : le {0} devra être redémarré à cause des TimedPermissions.", ["TimePermissions_label"] = "{4} {0}d {1}h {2}m", ["Coordinate_label_1"] = "carte : {0}", ["Coordinate_label_2"] = "X: {0} | Z: {1}", ["Downloads_images_label"] = "Téléchargement d'images : ( {0} / {1} ) :: {2}%", ["Loaded_plugin_label"] = "Plugin chargé {0}", ["Timed_Permissions_End"] = "Terminer", ["Time_Format"] = "HH:mm", ["Bank_T"] = "$ {0}T", ["Bank_G"] = "$ {0}G", ["Bank_M"] = "$ {0}M", ["Bank_K"] = "$ {0}K", ["Bank_N"] = "$ {0}", ["ServerRewards_T"] = "$ {0}T", ["ServerRewards_G"] = "$ {0}G", ["ServerRewards_M"] = "$ {0}M", ["ServerRewards_K"] = "$ {0}K", ["ServerRewards_N"] = "$ {0}", ["NamePVP"] = "PVP", ["NoPve"] = "Non Pve", ["UnDestr"] = "Un Destr", ["PveGod"] = "Pve God", ["PvpGod"] = "Pvp God", ["NoRadiation"] = "Non Radiation", ["SleepGod"] = "Dieu du sommeil", ["Kill"] = "No Tuer", ["RaidableBase"] = "PVP", ["TruePVE"] = "PVE", ["ServerPve"] = "PVE", ["vip_1"] = "VIP ", ["vip"] = "VIP ", ["demo"] = "DEMO ",
}
, this, "fr");
lang.RegisterMessages(new Dictionary<string, string> {
["TimePermissions_Wn_Reload"]
= "Warning: the {0} will have to be restarted because of TimedPermissions", ["TimePermissions_label"] = "{4} {0}d {1}h {2}m", ["Coordinate_label_1"] = "map : {0}", ["Coordinate_label_2"] = "X: {0} | Z: {1}", ["Downloads_images_label"] = "Downloads images : ( {0} / {1} ) :: {2}%", ["Loaded_plugin_label"] = "Loaded plugin {0}", ["Timed_Permissions_End"] = "Finish", ["Time_Format"] = "hh:mm tt", ["Bank_T"] = "$ {0}T", ["Bank_G"] = "$ {0}G", ["Bank_M"] = "$ {0}M", ["Bank_K"] = "$ {0}K", ["Bank_N"] = "$ {0}", ["ServerRewards_T"] = "$ {0}T", ["ServerRewards_G"] = "$ {0}G", ["ServerRewards_M"] = "$ {0}M", ["ServerRewards_K"] = "$ {0}K", ["ServerRewards_N"] = "$ {0}", ["NamePVP"] = "PVP", ["NoPve"] = "No Pve", ["UnDestr"] = "Un Destr", ["PveGod"] = "Pve God", ["PvpGod"] = "Pvp God", ["NoRadiation"] = "No Radiation", ["SleepGod"] = "Sleep God", ["Kill"] = "No Kill", ["RaidableBase"] = "PVP", ["TruePVE"] = "PVE", ["ServerPve"] = "PVE", ["vip_1"] = "VIP ", ["vip"] = "VIP ", ["demo"] = "DEMO ",
}
, this);
}
#endregion
#region Console Commands UI
[ConsoleCommand("HUDPanelCMD")]
private void cmdMenuCui(ConsoleSystem.Arg arg) {
BasePlayer player = arg.Player();
if (player != null && (DEV_DEBUG ? true : player.IsConnected)) {
Effect.server.Run(_config.SoundButtonPanel, player.transform.position, Vector3.zero, null, false);
switch (arg.Args[0].ToString()) {
case "SwichUI" : SwichUIPower(player, (_ListPlayerConnectServer.ContainsKey(player) ? !_ListPlayerConnectServer[player]._PlayerPowerToggle : false));
break;
default : SwichUIPower(player, true);
break;
}
}
}
private void CmdShowHud(IPlayer ipl, string command, string[] args) {
BasePlayer player = ipl?.Object as BasePlayer;
if (player != null && (DEV_DEBUG ? true : player.IsConnected)) {
Effect.server.Run(_config.SoundButtonPanel, player.transform.position, Vector3.zero, null, false);
SwichUIPower(player, (_ListPlayerConnectServer.ContainsKey(player) ? !_ListPlayerConnectServer[player]._PlayerPowerToggle : false));
}
}
#endregion
#region Loading the plugin
private void Init() => LoadConfig();
void OnServerInitialized() {
if (ImageLibrary == null) Puts($"{this.Name} WARNING !! : The plugin needs ImageLibrary!");
try {
if (_config.ScanEvent) {
ReloadEvents();
}
else {
ActiveCargoships = new List<CargoShip>();
ActiveChinooks = new List<CH47Helicopter>();
ActiveBradleys = new List<BradleyAPC>();
ActivePlanes = new List<CargoPlane>();
ActiveHelicopters = new List<PatrolHelicopter>();
}
AddCovalenceCommand(_config.CmdShowHud, nameof(CmdShowHud));
FindHooks();
LoadPluginIQPermissions();
LoadPluginTimedPermissions();
foreach (BasePlayer player in BasePlayer.activePlayerList) {
if (player != null && (DEV_DEBUG ? true : player.IsConnected)) {
if (!_ListPlayerConnectServer.ContainsKey(player)) {
NextTick(() => HudGuiShow(player));
}
}
}
if (DEV_DEBUG) {
int counterBot = BasePlayer.activePlayerList.Count;
foreach (BasePlayer player in BasePlayer.bots) {
if (player != null && ConVar.Server.maxplayers > counterBot) {
if (!_ListPlayerConnectServer.ContainsKey(player)) {
NextTick(() => HudGuiShow(player));
counterBot++;
}
}
}
Puts($"Loaded BOT {counterBot} ( Test {this.Name} ) !");
}
ServerMgr.Instance.StartCoroutine(RefreshPanelPlayerAll(1f));
}
catch (Exception e) {
Puts($"{this.Name} : The plugin is not loaded! {e}");
}
}
private void ReloadEvents() {
ActiveCargoships = new List<CargoShip>();
ActiveChinooks = new List<CH47Helicopter>();
ActiveBradleys = new List<BradleyAPC>();
ActivePlanes = new List<CargoPlane>();
ActiveHelicopters = new List<PatrolHelicopter>();
foreach (var Entity in BaseNetworkable.serverEntities) {
if (Entity is PatrolHelicopter) {
ActiveHelicopters.Add((PatrolHelicopter)Entity);
}
if (Entity is CargoPlane) {
CargoPlane plane = (CargoPlane)Entity;
if (plane.dropped) ActivePlanes.Add(plane);
}
if (Entity is CargoShip) {
ActiveCargoships.Add((CargoShip)Entity);
}
if (Entity is CH47Helicopter) {
ActiveChinooks.Add((CH47Helicopter)Entity);
}
if (Entity is BradleyAPC) {
ActiveBradleys.Add((BradleyAPC)Entity);
}
}
}
private void OnPlayerConnected(BasePlayer user) {
if (user != null && user.IsConnected) {
HudGuiShow(user);
}
}
private void Unload() {
foreach (BasePlayer player in BasePlayer.activePlayerList) {
if (player != null && (DEV_DEBUG ? true : player.IsConnected)) {
RemoveHUDPanel(player);
}
}
}
#endregion
#region Reloading loop
private IEnumerator RefreshPanelPlayerAll(float time) {
int TimeReloadEvents = 0;
while (true) {
if (!IsLoaded) yield break;
try {
if (Performance.report.frameRate > _config.Anti_Freeze_Serveur_Fps_Limite) {
List<BasePlayer> _ListPlayerDisconnectedServer = new List<BasePlayer>();
Dictionary<string, AllPanelList> Global_CF = GetAllPanelList();
CuiElementContainer Global_UI_container = new CuiElementContainer();
if (!IsPluginTimedPermission && TimedPermissions != null) {
Debug.LogWarning(string.Format(lang.GetMessage("TimePermissions_Wn_Reload", this), this.Name));
Interface.Oxide.UnloadPlugin(this.Name);
Interface.Oxide.LoadPlugin(this.Name);
}
foreach (var HUDData in Global_CF) {
UI.AddModuleUI(this, ref Global_UI_container, Global_CF, HUDData.Key, null, false);
}
/*
foreach (CargoPlane plane in ActivePlanes) {
float dist = Vector3.Distance(new Vector3(plane.transform.position.x, 0, plane.transform.position.z), new Vector3(plane.endPos.x, 0, plane.endPos.z));
if (1000 >= dist) OnEventServer((BaseEntity)plane, true);
}
*/
if (600 > TimeReloadEvents) {
TimeReloadEvents++;
}
else {
TimeReloadEvents = 0;
ReloadEvents();
}
foreach (BasePlayer player in BasePlayer.activePlayerList ) {
if (player != null && (DEV_DEBUG ? true : player.IsConnected)) {
if (!_ListPlayerConnectServer.ContainsKey(player)) {
if (player.IsConnected) NextTick(() => HudGuiShow(player));
}
else {
if (true) {
UI.Create(player, Global_UI_container);
CuiElementContainer container = new CuiElementContainer();
;
UI.AddModuleUI(this, ref container, Global_CF, "Times", player, false);
UI.AddModuleUI(this, ref container, Global_CF, "PvpPve", player, false);
UI.AddModuleUI(this, ref container, Global_CF, "MarkerPos", player, false);
UI.AddModuleUI(this, ref container, Global_CF, "Messages", player, false);
UI.AddModuleUI(this, ref container, Global_CF, "Coordinate", player, false);
UI.AddModuleUI(this, ref container, Global_CF, "ServerRewards", player, false);
if (IsPluginTimedPermission) {
foreach (var l in _config.PanelTimedPermissionstList) {
if (!l.Value.Show) continue;
if (InfoPluginTimedPerms != null && InfoPluginTimedPerms.ContainsKey(player.UserIDString) && InfoPluginTimedPerms[player.UserIDString].ContainsKey(l.Key)) {
UI.AddModuleUI(this, ref container, Global_CF, l.Key, player, false);
}
}
}
UI.Create(player, container);
if (TimeReloadEvents == 0) LoadUiEventDefault(player);
}
}
}
else {
if (!_ListPlayerDisconnectedServer.Contains(player)) _ListPlayerDisconnectedServer.Add(player);
}
}
foreach (BasePlayer l in _ListPlayerDisconnectedServer) _ListPlayerConnectServer.Remove(l);
}
}
catch (Exception e) {
if (DEV_DEBUG) Puts($"Error ::: {e}");
}
yield return new WaitForSeconds(time);
}
}
#endregion
#region Fonction: Hook PVP/PVE
private void SetPVPPVE(BasePlayer player, bool allowPVP, string info) {
Dictionary<string, AllPanelList> Global_CF = GetAllPanelList();
CuiElementContainer Global_UI_container = new CuiElementContainer();
if (_ListPlayerConnectServer.ContainsKey(player)) _ListPlayerConnectServer[player].PlayerZoneNoPve = allowPVP;
if (_ListPlayerConnectServer.ContainsKey(player)) _ListPlayerConnectServer[player].PvpPVE_Info2 = info;
UI.AddModuleUI(this, ref Global_UI_container, Global_CF, "PvpPve", player, true);
UI.Create(player, Global_UI_container);
}
private void OnPlayerExitedRaidableBase(BasePlayer player, Vector3 location, bool allowPVP) => SetPVPPVE(player, false, string.Empty);
private void OnPlayerEnteredRaidableBase(BasePlayer player, Vector3 location, bool allowPVP) => SetPVPPVE(player, allowPVP, lang.GetMessage("RaidableBase", this, player.UserIDString));
private void OnExitZone(string ZoneID, BasePlayer player) => SetPVPPVE(player, false, string.Empty);
private void OnEnterZone(string ZoneID, BasePlayer player) {
if (ZoneManager != null) {
string Name = string.Empty;
string AB = "";
bool c = false;
c = ZoneManager?.Call<bool>("HasFlag", ZoneID, "SleepGod") ?? false;
if (c) {
Name = (Name.Length >= 1 ? AB : string.Empty) + lang.GetMessage("SleepGod", this, player.UserIDString);
}
c = ZoneManager?.Call<bool>("HasFlag", ZoneID, "Kill") ?? false;
if (c) {
Name = (Name.Length >= 1 ? AB : string.Empty) + lang.GetMessage("Kill", this, player.UserIDString);
}
c = ZoneManager?.Call<bool>("HasFlag", ZoneID, "NoRadiation") ?? false;
if (c) {
Name = (Name.Length >= 1 ? AB : string.Empty) + lang.GetMessage("NoRadiation", this, player.UserIDString);
}
c = ZoneManager?.Call<bool>("HasFlag", ZoneID, "UnDestr") ?? false;
if (c) {
Name = (Name.Length >= 1 ? AB : string.Empty) + lang.GetMessage("UnDestr", this, player.UserIDString);
}
c = ZoneManager?.Call<bool>("HasFlag", ZoneID, "PveGod") ?? false;
if (c) {
Name = (Name.Length >= 1 ? AB : string.Empty) + lang.GetMessage("PveGod", this, player.UserIDString);
}
c = ZoneManager?.Call<bool>("HasFlag", ZoneID, "PvpGod") ?? false;
if (c) {
Name = (Name.Length >= 1 ? AB : string.Empty) + lang.GetMessage("UnDestr", this, player.UserIDString);
}
c = ZoneManager?.Call<bool>("HasFlag", ZoneID, "NoPve") ?? false;
if (c) {
Name = (Name.Length >= 1 ? AB : string.Empty) + lang.GetMessage("NoPve", this, player.UserIDString);
}
SetPVPPVE(player, c, Name);
}
}
private bool IsPVPPVE(BasePlayer player) {
bool Check = false;
string Name = lang.GetMessage("NamePVP", this, player.UserIDString);
/* awaiting response
if (NextGenPVE != null){
if (NextGenPVE.Call<bool>(string.Empty)) Check = true;
}
*/
if (TruePVE != null) {
string CurrentRuleSetName = TruePVE.Call<string>("CurrentRuleSetName");
if (CurrentRuleSetName != "pvp") {
Check = true;
Name = lang.GetMessage("TruePVE", this, player.UserIDString);
}
}
if (IsPveEnabled) {
Check = true;
Name = lang.GetMessage("IsPveEnabled", this, player.UserIDString);
}
if (ConVar.Server.pve) {
Check = true;
Name = lang.GetMessage("ServerPve", this, player.UserIDString);
;
}
if (!_ListPlayerConnectServer.ContainsKey(player)) return Check;
if (_ListPlayerConnectServer[player].PlayerZoneNoPve) {
Check = true;
}
_ListPlayerConnectServer[player].PvpPVE_Info1 = Name;
return Check;
}
#endregion
#region Fonction: Hook Events Server
private void OnEntitySpawned(PatrolHelicopter Entity) => OnEventServer(Entity, false);
private void OnEntitySpawned(CargoPlane Entity) => OnEventServer(Entity, false);
private void OnEntitySpawned(CargoShip Entity) => OnEventServer(Entity, false);
private void OnEntitySpawned(CH47Helicopter Entity) => OnEventServer(Entity, false);
private void OnEntitySpawned(BradleyAPC Entity) => OnEventServer(Entity, false);
private void OnEntityKill(PatrolHelicopter Entity) => OnEventServer(Entity, true);
private void OnEntityKill(CargoPlane Entity) => OnEventServer(Entity, true);
private void OnEntityKill(CargoShip Entity) => OnEventServer(Entity, true);
private void OnEntityKill(CH47Helicopter Entity) => OnEventServer(Entity, true);
private void OnEntityKill(BradleyAPC Entity) => OnEventServer(Entity, true);
private void OnEventServer(BaseEntity entity, bool kill) {
if (entity == null) return;
if (entity is PatrolHelicopter) {
PatrolHelicopter PH = (PatrolHelicopter)entity;
if (!kill) {
if (!ActiveHelicopters.Contains(PH)) ActiveHelicopters.Add(PH);
}
else {
if (ActiveHelicopters.Contains(PH)) ActiveHelicopters.Remove(PH);
}
}
else if (entity is CargoPlane) {
CargoPlane CP = (CargoPlane)entity;
if (!kill) {
if (!ActivePlanes.Contains(CP)) ActivePlanes.Add(CP);
}
else {
if (ActivePlanes.Contains(CP)) ActivePlanes.Remove(CP);
}
}
else if (entity is CargoShip) {
CargoShip CS = (CargoShip)entity;
if (!kill) {
if (!ActiveCargoships.Contains(CS)) ActiveCargoships.Add(CS);
}
else {
if (ActiveCargoships.Contains(CS)) ActiveCargoships.Remove(CS);
}
}
else if (entity is CH47Helicopter) {
CH47Helicopter CH47 = (CH47Helicopter)entity;
if (!kill) {
if (!ActiveChinooks.Contains(CH47)) ActiveChinooks.Add(CH47);
}
else {
if (ActiveChinooks.Contains(CH47)) ActiveChinooks.Remove(CH47);
}
}
else if (entity is BradleyAPC) {
BradleyAPC BAPC = (BradleyAPC)entity;
if (!kill) {
if (!ActiveBradleys.Contains(BAPC)) ActiveBradleys.Add(BAPC);
}
else {
if (ActiveBradleys.Contains(BAPC)) ActiveBradleys.Remove(BAPC);
}
}
else {
return;
}
List<BasePlayer> _ListPlayerDisconnectedServer = new List<BasePlayer>();
foreach (BasePlayer player in BasePlayer.activePlayerList) {
if (player != null && (DEV_DEBUG ? true : player.IsConnected)) {
LoadUiEventDefault(player);
}
else {
if (!_ListPlayerDisconnectedServer.Contains(player)) _ListPlayerDisconnectedServer.Add(player);
}
}
foreach (BasePlayer l in _ListPlayerDisconnectedServer) _ListPlayerConnectServer.Remove(l);
}
private void LoadUiEventDefault(BasePlayer player, bool Reload=false) => NextTick(() => {
if (player != null && (DEV_DEBUG ? true : player.IsConnected)) {
if (!_ListPlayerConnectServer.ContainsKey(player)) return;
if (_ListPlayerConnectServer[player]._PlayerPowerToggle) {
if (true) {
Dictionary<string, AllPanelList> Global_CF = GetAllPanelList();
CuiElementContainer container = new CuiElementContainer();
if (Reload || ActiveHelicopters != null && _ListPlayerConnectServer[player]._PlayerInfoEvent.CountActiveHelicopters != ActiveHelicopters.Count) {
UI.AddModuleUI(this, ref container, Global_CF, "Patrol", player, true);
_ListPlayerConnectServer[player]._PlayerInfoEvent.CountActiveHelicopters = ActiveHelicopters.Count;
}
if (Reload || ActiveChinooks != null && _ListPlayerConnectServer[player]._PlayerInfoEvent.CountActiveChinooks != ActiveChinooks.Count) {
UI.AddModuleUI(this, ref container, Global_CF, "Ch47", player, true);
_ListPlayerConnectServer[player]._PlayerInfoEvent.CountActiveChinooks = ActiveChinooks.Count;
}
if (Reload || ActivePlanes != null && _ListPlayerConnectServer[player]._PlayerInfoEvent.CountActivePlanes != ActivePlanes.Count) {
UI.AddModuleUI(this, ref container, Global_CF, "Plane", player, true);
_ListPlayerConnectServer[player]._PlayerInfoEvent.CountActivePlanes = ActivePlanes.Count;
}
if (Reload || ActiveCargoships != null && _ListPlayerConnectServer[player]._PlayerInfoEvent.CountActiveCargoships != ActiveCargoships.Count) {
UI.AddModuleUI(this, ref container, Global_CF, "Cargo", player, true);
_ListPlayerConnectServer[player]._PlayerInfoEvent.CountActiveCargoships = ActiveCargoships.Count;
}
if (Reload || ActiveBradleys != null && _ListPlayerConnectServer[player]._PlayerInfoEvent.CountActiveBradleys != ActiveBradleys.Count) {
UI.AddModuleUI(this, ref container, Global_CF, "BradleyAPC", player, true);
_ListPlayerConnectServer[player]._PlayerInfoEvent.CountActiveBradleys = ActiveBradleys.Count;
}
UI.Create(player, container);
}
}
}
}
);
#endregion
#region Fonction: Hook ServerRewards
/*
Waiting for the plugin developer to add a Hook.
*/
public void OnServerRewardsPointsUpdated(BasePlayer player, int amount) {
if (player != null) API_HUDPanel_ReloadBloc(player, "ServerRewards");
}
#endregion
#region Fonction: Hook economic
private void OnEconomicsBalanceUpdated(string playerId, double amount) {
BasePlayer player = BasePlayer.Find(playerId);
if (player != null ) API_HUDPanel_ReloadBloc(player, "Economics");
}
#endregion
#region Fonction: Hook Map Marker
void OnMapMarkerAdded(BasePlayer player, MapNote note) {
if (_ListPlayerConnectServer.ContainsKey(player)) {
_ListPlayerConnectServer[player].PlayerMarkerPos = note.worldPosition;
}
return;
}
#endregion
#region Fonction: Hook TimedPermissions
void OnTimedPermissionGranted(string Id, string permission, TimeSpan duration) => AddTimedPermissions(Id, permission, System.DateTime.UtcNow.Add(duration), false);
void OnTimedPermissionGranted_End(string Id, string permission, TimeSpan duration) => AddTimedPermissions(Id, permission, System.DateTime.UtcNow.Add(duration), true);
void OnTimedGroupAdded(string Id, string group, TimeSpan duration) => AddTimedPermissions(Id, group, System.DateTime.UtcNow.Add(duration), false);
void OnTimedGroupAdded_End(string Id, string group, TimeSpan duration) => AddTimedPermissions(Id, group, System.DateTime.UtcNow.Add(duration), false);
void OnIQPermissionsPermission(string Id, string permission, DateTime duration) => AddTimedPermissions(Id, permission, duration, false);
void OnTimedPermissionRest() {
if (TimedPermissions != null || IQPermissions != null) {
if (InfoPluginTimedPerms != null) {
InfoPluginTimedPerms = new Dictionary<string, Dictionary<string, DateTime>>();
}
foreach (BasePlayer player in BasePlayer.activePlayerList) {
if (player != null && player.IsConnected) {
NextTick(() => HudGuiShow(player));
}
}
}
}
void OnTimedPermissionRemove(string UserID, string Name) {
if (InfoPluginTimedPerms.ContainsKey(UserID)) {
if (InfoPluginTimedPerms[UserID].ContainsKey(Name)) {
InfoPluginTimedPerms[UserID].Remove(Name);
BasePlayer player = BasePlayer.Find(UserID);
if (player != null) HudGuiShow(player);
}
}
}
void OnTimedGroupRemove(string UserID, string Name) {
if (InfoPluginTimedPerms.ContainsKey(UserID)) {
if (InfoPluginTimedPerms[UserID].ContainsKey(Name)) {
InfoPluginTimedPerms[UserID].Remove(Name);
BasePlayer player = BasePlayer.Find(UserID);
if (player != null) HudGuiShow(player);
}
}
}
public void LoadPluginTimedPermissions() {
if (TimedPermissions != null) {
string __file = Interface.Oxide.PluginDirectory + (SystemInfo.operatingSystem.Contains("Windows") ? "\\" : "//") + "TimedPermissions.cs";
string AddCode = string.Empty;
string ReadCode = File.ReadAllText(Utility.CleanPath(__file));
bool IsWrite = false;
if (!ReadCode.Contains("Interface.CallHook(\"OnTimedPermissionGranted_End\", Id, permission, existingAccess.ExpireDate - DateTime.UtcNow);")) {
ReadCode = ReadCode.Replace("_plugin.Puts($\"{Name} ({Id}) - Permission time extended: {permission} to {existingAccess.ExpireDate - DateTime.UtcNow}\");", "Interface.CallHook(\"OnTimedPermissionGranted_End\", Id, permission, existingAccess.ExpireDate - DateTime.UtcNow);\n _plugin.Puts($\"{Name} ({Id}) - Permission time extended: {permission} to {existingAccess.ExpireDate - DateTime.UtcNow}\");");
IsWrite = true;
}
if (!ReadCode.Contains("Interface.CallHook(\"OnTimedGroupAdded_End\", Id, group, existingAccess.ExpireDate - DateTime.UtcNow);")) {
ReadCode = ReadCode.Replace("_plugin.Puts($\"{Name} ({Id}) - Group time extended: {group} to {existingAccess.ExpireDate - DateTime.UtcNow}\");", "Interface.CallHook(\"OnTimedGroupAdded_End\", Id, group, existingAccess.ExpireDate - DateTime.UtcNow);\n _plugin.Puts($\"{Name} ({Id}) - Group time extended: {group} to {existingAccess.ExpireDate - DateTime.UtcNow}\");");
IsWrite = true;
}
if (!ReadCode.Contains("Interface.CallHook(\"OnTimedPermissionRest\");")) {
ReadCode = ReadCode.Replace("SaveData(_playerInformationCollection, backupFileName);", "Interface.CallHook(\"OnTimedPermissionRest\");\n SaveData(_playerInformationCollection, backupFileName);");
IsWrite = true;
}
if (!ReadCode.Contains("Interface.CallHook(\"OnTimedPermissionRemove\",target.Id, args[1].ToLower());")) {
ReadCode = ReadCode.Replace("information.RemovePermission(args[1].ToLower());", "information.RemovePermission(args[1].ToLower());\n Interface.CallHook(\"OnTimedPermissionRemove\",target.Id, args[1].ToLower());");
IsWrite = true;
}
if (!ReadCode.Contains("Interface.CallHook(\"OnTimedGroupRemove\",target.Id, args[1].ToLower());")) {
ReadCode = ReadCode.Replace("information.RemoveGroup(args[1].ToLower());", "information.RemoveGroup(args[1].ToLower());\n Interface.CallHook(\"OnTimedGroupRemove\",target.Id, args[1].ToLower());");
IsWrite = true;
}
if (AddCode.Length != 0 || IsWrite) {
File.WriteAllText(__file, ReadCode.Substring(0, ReadCode.Length - 5) + AddCode + "\n }\n}");
timer.In(15f, () => LoadPluginTimedPermissions());
return;
}
}
if (Interface.Oxide.DataFileSystem.ExistsDatafile("TimedPermissions") && InfoPluginTimedPerms != null) {
List<PlayerInformation> dataFile = Interface.Oxide.DataFileSystem.ReadObject<List<PlayerInformation>>("TimedPermissions");
foreach (PlayerInformation playerInformation in dataFile) {
UInt64 userID;
if(!UInt64.TryParse(playerInformation.Id, out userID)) continue;
var lis = new Dictionary<string, DateTime> {
}
;
foreach (var ps in playerInformation._permissions) {
if (!lis.ContainsKey(ps .Value)) lis.Add(ps.Value, ps.ExpireDate);
}
foreach (var gp in playerInformation._groups) {
if (!lis.ContainsKey(gp .Value)) lis.Add(gp.Value, gp.ExpireDate);
}
InfoPluginTimedPerms.Add(playerInformation.Id, lis);
}
IsPluginTimedPermission = true;
}
if (IQPermissions != null && Interface.Oxide.DataFileSystem.ExistsDatafile("IQSystem/IQPermissions/OldPlayers")) {
foreach (BasePlayer player in BasePlayer.activePlayerList) {
GetPlayerIQPermissions(player.userID);
}
}
}
public void LoadPluginIQPermissions() {
if (IQPermissions != null) {
string __file = Interface.Oxide.PluginDirectory + (SystemInfo.operatingSystem.Contains("Windows") ? "\\" : "//") + "IQPermissions.cs";
string ReadCode = File.ReadAllText(Utility.CleanPath(__file));
bool IsWrite = false;
if (!ReadCode.Contains("private Dictionary<String, DateTime> GetGroups_Prv(UInt64 userID) => InformationPrivilagesUser.GetParametresUser(userID, TypeData.Group);")) {
ReadCode = ReadCode.Replace("public Dictionary<String, DateTime> GetGroups(UInt64 userID) => InformationPrivilagesUser.GetParametresUser(userID, TypeData.Group);", "public Dictionary<String, DateTime> GetGroups(UInt64 userID) => InformationPrivilagesUser.GetParametresUser(userID, TypeData.Group);\n private Dictionary<String, DateTime> GetGroups_Prv(UInt64 userID) => InformationPrivilagesUser.GetParametresUser(userID, TypeData.Group);");
IsWrite = true;
}
if (!ReadCode.Contains("private Dictionary<String, DateTime> GetPermissions_Prv(UInt64 userID) => InformationPrivilagesUser.GetParametresUser(userID, TypeData.Permission);")) {
ReadCode = ReadCode.Replace("public Dictionary<String, DateTime> GetPermissions(UInt64 userID) => InformationPrivilagesUser.GetParametresUser(userID, TypeData.Permission);", "public Dictionary<String, DateTime> GetPermissions(UInt64 userID) => InformationPrivilagesUser.GetParametresUser(userID, TypeData.Permission);\n private Dictionary<String, DateTime> GetPermissions_Prv(UInt64 userID) => InformationPrivilagesUser.GetParametresUser(userID, TypeData.Permission);");
IsWrite = true;
}
if (!ReadCode.Contains("Interface.CallHook(\"OnIQPermissionsPermission\", userID.ToString(), Key.ToString(), dateExpired);")) {
ReadCode = ReadCode.Replace("String LeftTime = _.GetLeftTime(dateExpired, userID.ToString());", "String LeftTime = _.GetLeftTime(dateExpired, userID.ToString());\n Interface.CallHook(\"OnIQPermissionsPermission\", userID.ToString(), Key.ToString(), dateExpired);");
IsWrite = true;
}
if (!ReadCode.Contains("Interface.CallHook(\"OnTimedPermissionRemove\", userID.ToString(), Key.ToString());")) {
ReadCode = ReadCode.Replace("if (!selectStructureData.ContainsKey(Key) ) return;", "Interface.CallHook(\"OnTimedPermissionRemove\", userID.ToString(), Key.ToString());\n if (!selectStructureData.ContainsKey(Key) ) return;");
IsWrite = true;
}
if (IsWrite) {
File.WriteAllText(__file, ReadCode.Substring(0, ReadCode.Length - 5) + "\n }\n}");
timer.In(15f, () => LoadPluginIQPermissions());
return;
}
}
}
private Dictionary<string, DateTime> GetPlayerIQPermissions(UInt64 userID) {
Dictionary<string, DateTime> l = new Dictionary<string, DateTime> {
}
;
if (InfoPluginTimedPerms.ContainsKey($"{userID}")) {
l = InfoPluginTimedPerms[$"{userID}"];
}
Dictionary<String, DateTime> _perms = new Dictionary<String, DateTime> {
}
;
Dictionary<String, DateTime> _groups = new Dictionary<String, DateTime> {
}
;
if (IQPermissions != null) {
_perms = (Dictionary<String, DateTime>)IQPermissions.Call("GetPermissions_Prv", userID);
_groups = (Dictionary<String, DateTime>)IQPermissions.Call("GetGroups_Prv", userID);
}
if(_perms != null) foreach (var gp in _perms) {
if (!l.ContainsKey(gp.Key)) l.Add(gp.Key, gp.Value);
}
if(_groups != null) foreach (var gp in _groups) {
if (!l.ContainsKey(gp.Key)) l.Add(gp.Key, gp.Value);
}
if (l != null && InfoPluginTimedPerms != null) {
if (InfoPluginTimedPerms.ContainsKey(userID.ToString())) {
InfoPluginTimedPerms[userID.ToString()] = l;
}
else {
InfoPluginTimedPerms.Add(userID.ToString(), l);
}
IsPluginTimedPermission = true;
}
return l;
}
private void AddTimedPermissions(string Id, string name, DateTime NewDate, bool ext) {
NextTick(() => {
if (IsPluginTimedPermission && TimedPermissions != null && InfoPluginTimedPerms != null) {
if (!_config.PanelTimedPermissionstList.ContainsKey(name)) return;
if (InfoPluginTimedPerms != null && !InfoPluginTimedPerms.ContainsKey(Id)) {
InfoPluginTimedPerms.Add(Id, new Dictionary<string, DateTime> {
}
);
}
BasePlayer player = BasePlayer.Find(Id);
if (InfoPluginTimedPerms != null && InfoPluginTimedPerms[Id].ContainsKey(name)) {
InfoPluginTimedPerms[Id][name] = NewDate;
var container = new CuiElementContainer();
if (player != null) UI.AddModuleUI(this, ref container, GetAllPanelList(), name, player, true);
UI.Create(player, container);
}
else {
InfoPluginTimedPerms[Id].Add(name, NewDate);
if (player != null ) HudGuiShow(player);
}
}
}
);
}
#endregion
#region Fonction: Hook Events custom
private void FindHooks() {
string __file = Interface.Oxide.PluginDirectory + (SystemInfo.operatingSystem.Contains("Windows") ? "\\" : "//") + this.Name + ".cs";
string AddCode = string.Empty;
string ReadCode = File.ReadAllText(Utility.CleanPath(__file));
foreach (var b in _config.PanelCustomEventList) {
if (!ReadCode.Contains(b.Value.OnEventStart + "()")) AddCode += $" private void " + b.Value.OnEventStart + "()=> NextTick(() => OnCustomEventHook(\"" + b.Value.OnEventStart + "\"));\n";
if (!ReadCode.Contains(b.Value.OnEventEnd + "()")) AddCode += $" private void " + b.Value.OnEventEnd + "()=> NextTick(() => OnCustomEventHook(\"" + b.Value.OnEventEnd + "\"));\n";
}
if (AddCode.Length != 0) File.WriteAllText(__file, ReadCode.Substring(0, ReadCode.Length - 43) + AddCode + " /*--------- END -------- */\n }\n}");
}
void OnCustomEventHook(string hook) {
if (_LibraryHookCostomEvents.ContainsKey(hook)) {
string ID = _LibraryHookCostomEvents[hook].ID;
string Hook = _LibraryHookCostomEvents[hook].Hook;
bool Enabled = _LibraryHookCostomEvents[hook].Enabled;
if (!_ServerIsCostomEvents.ContainsKey(ID)) {
_ServerIsCostomEvents.Add(ID, Enabled);
}
else {
_ServerIsCostomEvents[ID] = Enabled;
}
}
}
#endregion
#region Function: Application
private void RemoveHUDPanel(BasePlayer player) {
if (player != null && (DEV_DEBUG ? true : player.IsConnected)) {
if (_ListPlayerConnectServer.ContainsKey(player)) _ListPlayerConnectServer.Remove(player);
CuiHelper.DestroyUi(player, this.Name + ".BG.LT");
CuiHelper.DestroyUi(player, this.Name + ".BG.CT");
CuiHelper.DestroyUi(player, this.Name + ".BG.RT");
CuiHelper.DestroyUi(player, this.Name + ".BG.LB");
CuiHelper.DestroyUi(player, this.Name + ".BG.CB");
CuiHelper.DestroyUi(player, this.Name + ".BG.RB");
}
}
private void HudGuiShow(BasePlayer player) {
if (player != null && (DEV_DEBUG ? true : player.IsConnected)) {
NextTick(() => {
if (player.HasPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot)) {
timer.In(2, () => HudGuiShow(player));
return;
}
RemoveHUDPanel(player);
Dictionary<string, AllPanelList> Global_CF = GetAllPanelList();
if (!_ListPlayerConnectServer.ContainsKey(player)) {
_ListPlayerConnectServer.Add(player, new ListPlayerConnectServer {
_PlayerPowerToggle = true, _PlayerInfoEvent = new InfoList() {
CountActiveHelicopters = 0, CountActiveChinooks = 0, CountActivePlanes = 0, CountActiveCargoships = 0, CountActiveBradleys = 0
}
, GetCoordID = 0, MessagesID = 0, PlayerMarkerPos = Vector3.zero, PvpPVE_Info1 = string.Empty, PvpPVE_Info2 = string.Empty, PlayerZoneNoPve = IsPVPPVE(player),
}
);
}
string parentOPT = "Hud";
string moneyplayer = "0";
var container = new CuiElementContainer();
float BorderScreen = 8f;
float CH = Get_H_UI();
// Value 30 Default;
float CW = Get_W_UI();
// Value 400 Default;
float H = 0.001f * CH;
float W = 0.001f * CW;
float HTHUB = 1f - (0.001f * CH);
float depl_LeftTop = 0f;
float depl_RightTop = 1f;
float depl_RightBottom = 1f;
float depl_LeftBottom = 0f;
float depl_CenterTop = 0f;
float depl_CenterBottom = 0f;
float depl_CenterTop_C = 0f;
float depl_CenterBottom_C = 0f;
bool _background_Bool_LeftTop = false;
bool _background_Bool_CenterTop = false;
bool _background_Bool_RightTop = false;
bool _background_Bool_LeftBottom = false;
bool _background_Bool_CenterBottom = false;
bool _background_Bool_RightBottom = false;
foreach (var HUDData in Global_CF) {
if (!HUDData.Value.Show) continue;
if (BoolLostTimedPerms(player, HUDData.Key)) continue;
string PositionHud = SelectPositionHud(HUDData.Value.PositionHud);
float Container_H = CH;
float Container_W = CH + (CH / 2);
if (HUDData.Value.L >= 2) Container_W = Container_W + (HUDData.Value.L * Container_W);
if (PositionHud == "CenterTop") depl_CenterTop_C += (Container_W / 1000) + (0.001f * _config.WidthBetweenIcon);
if (PositionHud == "CenterBottom") depl_CenterBottom_C += (Container_W / 1000) + (0.001f * _config.WidthBetweenIcon);
if (PositionHud == "LeftTop") _background_Bool_LeftTop = true;
if (PositionHud == "CenterTop") _background_Bool_CenterTop = true;
if (PositionHud == "RightTop") _background_Bool_RightTop = true;
if (PositionHud == "LeftBottom") _background_Bool_LeftBottom = true;
if (PositionHud == "CenterBottom") _background_Bool_CenterBottom = true;
if (PositionHud == "RightBottom") _background_Bool_RightBottom = true;
}
float Ico_H_Auto = ((((CH / 2) + BorderScreen) / 100) * CH);
/**************************************
******* Main Panel : LeftTop **********
**************************************/
if (_background_Bool_LeftTop) {
container.Add(new CuiPanel {
KeyboardEnabled = false, CursorEnabled = false, RectTransform = {
AnchorMin = "0 1", AnchorMax = "0 1",
}
, Image = {
Color = "0 0 0 0", Material = null, Sprite = null
}
}
, parentOPT, this.Name + ".BG.LT", this.Name + ".BG.LT");
container.Add(new CuiElement {
Parent = this.Name + ".BG.LT", Name = this.Name + "_LeftTop", DestroyUi = this.Name + "_LeftTop", Components = {
new CuiRectTransformComponent {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = $"{BorderScreen} -{CH - Ico_H_Auto}", OffsetMax = $"{CW} -{BorderScreen}"
}
, new CuiImageComponent {
Color = "0 0 0 0",
}
,
}
}
);
}
/**************************************
******* Main Panel : CenterTop ********
*****
// ... [Code preview truncated due to length. Full source in attached file] ...