Skip to content

Commit

Permalink
1.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dretax committed May 10, 2022
1 parent 6a2c14d commit 3f14842
Show file tree
Hide file tree
Showing 53 changed files with 175 additions and 114 deletions.
2 changes: 1 addition & 1 deletion Fougerite/Fougerite/Bootstrap.cs
Expand Up @@ -16,7 +16,7 @@ public class Bootstrap : Facepunch.MonoBehaviour
/// <summary>
/// Returns the Current Fougerite Version
/// </summary>
public const string Version = "1.8.0";
public const string Version = "1.8.1";
/// <summary>
/// This value decides wheather we should remove the player classes from the cache upon disconnect.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions Fougerite/Fougerite/PluginLoaders/BasePlugin.cs
Expand Up @@ -54,6 +54,12 @@ public class BasePlugin : CountedInstance, IPlugin
/// </summary>
/// <value>The globals.</value>
public IList<string> Globals { get; protected set; }

/// <summary>
/// Global methods of the plugin along with their functions.
/// </summary>
/// <value>The globals.</value>
public Dictionary<string, object> CachedGlobals { get; protected set; }

/// <summary>
/// Dictionary that holds the timers.
Expand Down Expand Up @@ -96,6 +102,7 @@ public BasePlugin(string name, DirectoryInfo rootdir)
Name = name;
RootDir = rootdir;
Globals = new List<string>();
CachedGlobals = new Dictionary<string, object>();

Timers = new Dictionary<string, TimedEvent>();
ParallelTimers = new List<TimedEvent>();
Expand Down
6 changes: 3 additions & 3 deletions Fougerite/Fougerite/PluginLoaders/JavaScriptPlugin.cs
Expand Up @@ -82,9 +82,9 @@ public override void Load(string code = "")
.SetFunction("importClass", new importit(importClass));
Program = JintEngine.Compile(code, false);

Globals = (from statement in Program.Statements
where statement.GetType() == typeof(FunctionDeclarationStatement)
select ((FunctionDeclarationStatement) statement).Name).ToList<string>();
Globals = (Program.Statements
.Where(statement => statement.GetType() == typeof(FunctionDeclarationStatement))
.Select(statement => ((FunctionDeclarationStatement)statement).Name)).ToList();

Engine.Run(Program);

Expand Down
25 changes: 20 additions & 5 deletions Fougerite/Fougerite/PluginLoaders/PythonPlugin.cs
Expand Up @@ -4,6 +4,7 @@
using Fougerite.Caches;
using Fougerite.Permissions;
using IronPython.Hosting;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;

namespace Fougerite.PluginLoaders
Expand Down Expand Up @@ -37,7 +38,6 @@ public PythonPlugin(string name, string code, DirectoryInfo rootdir) : base(name
{
Type = PluginType.Python;


Load(code);
}

Expand All @@ -62,13 +62,14 @@ public override object Invoke(string func, params object[] args)
{
try
{
if (State == PluginState.Loaded && Globals.Contains(func))
object functionToCall = null;
if (State == PluginState.Loaded && CachedGlobals.TryGetValue(func, out functionToCall))
{
object result = null;

using (new Stopper(Type + " " + Name, func))
{
result = Engine.Operations.InvokeMember(Class, func, args);
result = Engine.Operations.Invoke(functionToCall, args);
}

return result;
Expand Down Expand Up @@ -113,12 +114,26 @@ public override void Load(string code = "")
Scope.SetVariable("SQLite", Fougerite.SQLiteConnector.GetInstance);
Scope.SetVariable("PermissionSystem", PermissionSystem.GetPermissionSystem());
Scope.SetVariable("PlayerCache", PlayerCache.GetPlayerCache());

try
{
Engine.Execute(code, Scope);
ScriptSource source = Engine.CreateScriptSourceFromString(code, Path.GetFileName(RootDir.FullName), SourceCodeKind.Statements);
CompiledCode compiled = source.Compile();
compiled.Execute(Scope);

Class = Engine.Operations.Invoke(Scope.GetVariable(Name));
Globals = Engine.Operations.GetMemberNames(Class);

foreach (string name in Globals)
{
object func;
if (!Engine.Operations.TryGetMember(Class, name, out func) || !Engine.Operations.IsCallable(func))
{
continue;
}

CachedGlobals.Add(name, func);
}

object author = GetGlobalObject("__author__");
object about = GetGlobalObject("__about__");
Expand Down
2 changes: 1 addition & 1 deletion Fougerite/Fougerite/PluginLoaders/PythonPluginLoader.cs
Expand Up @@ -139,7 +139,7 @@ public void UnloadPlugin(string name)

PythonPlugin pythonPlugin = (PythonPlugin) plugin;

if (plugin.Globals.Contains("On_PluginDeinit"))
if (plugin.CachedGlobals.ContainsKey("On_PluginDeinit"))
plugin.Invoke("On_PluginDeinit");

plugin.KillTimers();
Expand Down
2 changes: 1 addition & 1 deletion Fougerite/Fougerite/Server.cs
Expand Up @@ -29,7 +29,7 @@ public class Server
/// PlayersCache or GetCachePlayer() if you need to use this.
/// (We also can't change this to a ConcurrentDictionary because other old plugins may depend on this)
/// </summary>
public static Dictionary<ulong, Player> Cache = new Dictionary<ulong, Player>();
public static IDictionary<ulong, Player> Cache = new Dictionary<ulong, Fougerite.Player>();
public static IEnumerable<string> ForceCallForCommands = new List<string>();


Expand Down
6 changes: 5 additions & 1 deletion Fougerite/Fougerite/Sleeper.cs
@@ -1,4 +1,6 @@

using Fougerite.Caches;

namespace Fougerite
{
using UnityEngine;
Expand All @@ -18,7 +20,9 @@ public Sleeper(DeployableObject obj)
this._sleeper = obj;
this._instanceid = this._sleeper.GetInstanceID();
this._uid = this._sleeper.ownerID;
this._name = Fougerite.Server.Cache.ContainsKey(UID) ? Fougerite.Server.Cache[UID].Name : this._sleeper.ownerName;
CachedPlayer cachedPlayer;
bool success = PlayerCache.GetPlayerCache().CachedPlayers.TryGetValue(UID, out cachedPlayer);
this._name = success ? cachedPlayer.Name : this._sleeper.ownerName;
}

/// <summary>
Expand Down
Binary file modified Fougerite/References/FougeriteExtraReferences/RustPP.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion RustPP/Commands/AboutCommand.cs
Expand Up @@ -8,7 +8,7 @@ public class AboutCommand : ChatCommand
{
public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Fougerite.Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
pl.MessageFrom(Core.Name, "Fougerite is currently running Rust++ v" + Core.Version);
pl.MessageFrom(Core.Name, "Brought to you by xEnt & EquiFox17 & the Fougerite project.");
}
Expand Down
4 changes: 2 additions & 2 deletions RustPP/Commands/AddAdminCommand.cs
Expand Up @@ -12,7 +12,7 @@ internal class AddAdminCommand : ChatCommand
{
public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Fougerite.Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
string playerName = string.Join(" ", ChatArguments).Trim(new char[] { ' ', '"' });
if (playerName == string.Empty)
{
Expand Down Expand Up @@ -77,7 +77,7 @@ public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatA

public void PartialNameNewAdmin(ref ConsoleSystem.Arg Arguments, int id)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
if (id == 0)
{
pl.MessageFrom(Core.Name, "Cancelled!");
Expand Down
4 changes: 2 additions & 2 deletions RustPP/Commands/AddFlagCommand.cs
Expand Up @@ -14,7 +14,7 @@ public class AddFlagCommand : ChatCommand
{
public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
if (ChatArguments.Length <= 1)
{
pl.MessageFrom(Core.Name, "AddFlag Usage: /addflag playerName flag1 flag2...");
Expand Down Expand Up @@ -117,7 +117,7 @@ public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatA

public void PartialNameAddFlags(ref ConsoleSystem.Arg Arguments, int id)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
if (id == 0)
{
pl.MessageFrom(Core.Name, "Cancelled!");
Expand Down
4 changes: 2 additions & 2 deletions RustPP/Commands/AddFriendCommand.cs
Expand Up @@ -11,7 +11,7 @@ internal class AddFriendCommand : ChatCommand
{
public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
string playerName = string.Join(" ", ChatArguments).Trim(new char[] { ' ', '"' });
if (playerName == string.Empty)
{
Expand Down Expand Up @@ -68,7 +68,7 @@ public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatA

public void PartialNameAddFriend(ref ConsoleSystem.Arg Arguments, int id)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
if (id == 0)
{
pl.MessageFrom(Core.Name, "Cancelled!");
Expand Down
2 changes: 1 addition & 1 deletion RustPP/Commands/AnnounceCommand.cs
Expand Up @@ -8,7 +8,7 @@ public class AnnounceCommand : ChatCommand
{
public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
string strText = string.Join(" ", ChatArguments).Trim(new char[] { ' ', '"' });

if (strText == string.Empty)
Expand Down
4 changes: 2 additions & 2 deletions RustPP/Commands/BanCommand.cs
Expand Up @@ -13,7 +13,7 @@ internal class BanCommand : ChatCommand
{
public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
string queryName = Arguments.ArgsStr.Trim(new char[] { ' ', '"' });
if (queryName == string.Empty)
{
Expand Down Expand Up @@ -48,7 +48,7 @@ into matches

public void PartialNameBan(ref ConsoleSystem.Arg Arguments, int id)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
if (id == 0)
{
pl.MessageFrom(Core.Name, "Canceled!");
Expand Down
2 changes: 1 addition & 1 deletion RustPP/Commands/ChatCommand.cs
Expand Up @@ -23,7 +23,7 @@ public static void AddCommand(string cmdString, ChatCommand command)

public static void CallCommand(string cmd, ref ConsoleSystem.Arg arg, ref string[] chatArgs)
{
var pl = Fougerite.Server.Cache[arg.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(arg.argUser.userID);
if (pl.CommandCancelList.Contains(cmd)) { return; }
foreach (ChatCommand command in classInstances)
{
Expand Down
2 changes: 1 addition & 1 deletion RustPP/Commands/FriendsCommand.cs
Expand Up @@ -29,7 +29,7 @@ public bool ContainsException(ulong id)

public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
if (!friendsLists.ContainsKey(Arguments.argUser.userID))
{
pl.MessageFrom(Core.Name, "You currently have no friend.");
Expand Down
4 changes: 2 additions & 2 deletions RustPP/Commands/GetFlagsCommand.cs
Expand Up @@ -10,7 +10,7 @@ public class GetFlagsCommand : ChatCommand
{
public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
string queryName = Arguments.ArgsStr.Trim(new char[] { ' ', '"' });

string playerName = string.Join(" ", ChatArguments).Trim(new char[] { ' ', '"' });
Expand Down Expand Up @@ -88,7 +88,7 @@ into matches

public void PartialNameGetFlags(ref ConsoleSystem.Arg Arguments, int id)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
if (id == 0)
{
pl.MessageFrom(Core.Name, "Cancelled!");
Expand Down
2 changes: 1 addition & 1 deletion RustPP/Commands/GiveItemCommand.cs
Expand Up @@ -11,7 +11,7 @@ internal class GiveItemCommand : ChatCommand
{
public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
if (pl.CommandCancelList.Contains("give"))
{
return;
Expand Down
2 changes: 1 addition & 1 deletion RustPP/Commands/GodModeCommand.cs
Expand Up @@ -10,7 +10,7 @@ public class GodModeCommand : ChatCommand

public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
if (pl.CommandCancelList.Contains("god"))
{
if (userIDs.Contains(pl.UID))
Expand Down
2 changes: 1 addition & 1 deletion RustPP/Commands/HelpCommand.cs
Expand Up @@ -9,7 +9,7 @@ public class HelpCommand : ChatCommand
{
public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
int i = 1;
string setting = Core.config.GetSetting("Settings", "help_string" + i);
while (setting != null)
Expand Down
2 changes: 1 addition & 1 deletion RustPP/Commands/HistoryCommand.cs
Expand Up @@ -8,7 +8,7 @@ public class HistoryCommand : ChatCommand
{
public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
for (int i = 1 + int.Parse(Core.config.GetSetting("Settings", "chat_history_amount")); i > 0; i--)
{
if (Fougerite.Data.GetData().chat_history_username.Count >= i)
Expand Down
3 changes: 2 additions & 1 deletion RustPP/Commands/InstaKOAllCommand.cs
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Fougerite;
using RustPP.Commands;

namespace RustPP
Expand All @@ -12,7 +13,7 @@ public class InstaKOAllCommand : ChatCommand

public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
if (pl.CommandCancelList.Contains("instakoall"))
{
if (userIDs.Contains(pl.UID))
Expand Down
2 changes: 1 addition & 1 deletion RustPP/Commands/InstaKOCommand.cs
Expand Up @@ -10,7 +10,7 @@ public class InstaKOCommand : ChatCommand

public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
if (pl.CommandCancelList.Contains("instako"))
{
if (userIDs.Contains(pl.UID))
Expand Down
4 changes: 2 additions & 2 deletions RustPP/Commands/KickCommand.cs
Expand Up @@ -12,7 +12,7 @@ internal class KickCommand : ChatCommand
{
public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
string playerName = string.Join(" ", ChatArguments).Trim(new char[] { ' ', '"' });
if (playerName == string.Empty)
{
Expand Down Expand Up @@ -53,7 +53,7 @@ public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatA

public void PartialNameKick(ref ConsoleSystem.Arg Arguments, int id)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
if (id == 0)
{
pl.MessageFrom(Core.Name, "Cancelled!");
Expand Down
4 changes: 2 additions & 2 deletions RustPP/Commands/KillCommand.cs
Expand Up @@ -12,7 +12,7 @@ internal class KillCommand : ChatCommand
{
public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
string playerName = string.Join(" ", ChatArguments).Trim(new char[] { ' ', '"' });
if (playerName == string.Empty)
{
Expand Down Expand Up @@ -47,7 +47,7 @@ public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatA

public void PartialNameKill(ref ConsoleSystem.Arg Arguments, int id)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
if (id == 0)
{
pl.MessageFrom(Core.Name, "Cancelled!");
Expand Down
2 changes: 1 addition & 1 deletion RustPP/Commands/LoadoutCommand.cs
Expand Up @@ -11,7 +11,7 @@ public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatA
int items;
if (int.TryParse(Core.config.GetSetting("AdminLoadout", "items"), out items))
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
for (int i = 1; i <= items; i++)
{
string name = Core.config.GetSetting("AdminLoadout", "item" + i + "_name");
Expand Down
2 changes: 1 addition & 1 deletion RustPP/Commands/LocationCommand.cs
Expand Up @@ -8,7 +8,7 @@ public class LocationCommand : ChatCommand
{
public override void Execute(ref ConsoleSystem.Arg Arguments, ref string[] ChatArguments)
{
var pl = Fougerite.Server.Cache[Arguments.argUser.userID];
var pl = Server.GetServer().GetCachePlayer(Arguments.argUser.userID);
string targetName = string.Join(" ", ChatArguments).Trim(new char[] { ' ', '"' });
if (targetName.Equals(string.Empty) || targetName.Equals(Arguments.argUser.displayName))
{
Expand Down

0 comments on commit 3f14842

Please sign in to comment.