/// <summary> /// Fires the action associated with the limitation /// </summary> /// <param name="d"></param> /// <param name="m_host"></param> /// <param name="itemID"></param> /// <returns>Whether the event should be dropped</returns> bool TriggerAction(LimitDef d, ISceneChildEntity m_host, UUID itemID) { if (d.Action == LimitAction.None) { return(true); } if (d.Action == LimitAction.Drop) { return(false); //Drop it } if (d.Action == LimitAction.TerminateEvent) { throw new Exception(""); //Blank messages kill events, but don't show anything on the console/inworld } if (d.Action == LimitAction.TerminateScript) { ScriptData script = GetScript(itemID); if (script != null) { script.IgnoreNew = true; //Blocks all new events, can be reversed by resetting or resaving the script } throw new Exception(""); //Blank messages kill events, but don't show anything on the console/inworld } if (d.Action == LimitAction.Delay) { MainConsole.Instance.Warn("Function delaying is not implemented"); } return(true); }
void TriggerAlert(string function, LimitDef d, string message, ISceneChildEntity host) { if (d.Alert == LimitAlert.Console || d.Alert == LimitAlert.ConsoleAndInworld) { MainConsole.Instance.Warn("[Limitor]: " + message); } if (d.Alert == LimitAlert.Inworld || d.Alert == LimitAlert.ConsoleAndInworld) { IChatModule chatModule = host.ParentEntity.Scene.RequestModuleInterface <IChatModule>(); if (chatModule != null) { chatModule.SimChat("[Limitor]: " + message, ChatTypeEnum.DebugChannel, 2147483647, host.AbsolutePosition, host.Name, host.UUID, false, host.ParentEntity.Scene); } } }
bool CheckFunctionLimits(string function, ISceneChildEntity m_host, string API, UUID itemID) { LimitDef d = null; bool isAPI = m_functionsToLimit.TryGetValue(API, out d); bool isFunction = m_functionsToLimit.TryGetValue(function, out d); //Function overrides API if (m_allowFunctionLimiting && (isAPI || isFunction)) { //Get the list for the given type Dictionary <string, LimitReq> functions; bool doInsert = false; if (d.Type == LimitType.Owner) { if (!m_functionLimiting.TryGetValue(m_host.OwnerID, out functions)) { doInsert = true; functions = new Dictionary <string, LimitReq>(); } } else if (d.Type == LimitType.Script) { if (!m_functionLimiting.TryGetValue(itemID, out functions)) { doInsert = true; functions = new Dictionary <string, LimitReq>(); } } else if (d.Type == LimitType.Group) { if (!m_functionLimiting.TryGetValue(m_host.ParentEntity.UUID, out functions)) { doInsert = true; functions = new Dictionary <string, LimitReq>(); } } else if (d.Type == LimitType.Prim) { if (!m_functionLimiting.TryGetValue(m_host.UUID, out functions)) { doInsert = true; functions = new Dictionary <string, LimitReq>(); } } else { return(true); } LimitReq r; if (!functions.TryGetValue(function, out r)) { r = new LimitReq(); } if (d.MaxNumberOfTimes != 0) { if (r.NumberOfTimesFired + 1 > d.MaxNumberOfTimes) //Too Many, kill it { TriggerAlert(function, d, "You have exceeded the number of times this function (" + function + ") is allowed to be fired", m_host); return(TriggerAction(d, m_host, itemID)); } r.NumberOfTimesFired++; } if (d.TimeScale != 0) { if (r.LastFired != 0 && Util.EnvironmentTickCountSubtract(r.LastFired) < d.TimeScale) { if (r.FunctionsSinceLastFired + 1 > d.FunctionsOverTimeScale) { TriggerAlert(function, d, "You have fired the given function " + function + " too quickly.", m_host); return(TriggerAction(d, m_host, itemID)); } } else { r.LastFired = Util.EnvironmentTickCount(); r.FunctionsSinceLastFired = 0; //Clear it out again } r.FunctionsSinceLastFired++; } //Put it back where it came from functions[isFunction ? function : API] = r; if (doInsert) { if (d.Type == LimitType.Owner) { m_functionLimiting[m_host.OwnerID] = functions; } else if (d.Type == LimitType.Script) { m_functionLimiting[itemID] = functions; } else if (d.Type == LimitType.Group) { m_functionLimiting[m_host.ParentEntity.UUID] = functions; } else if (d.Type == LimitType.Prim) { m_functionLimiting[m_host.UUID] = functions; } } } return(true); }
public void Initialize(IConfig config) { m_config = config; EnabledAPIs = new List <string>(config.GetString("AllowedAPIs", "LSL").ToLower().Split(',')); allowHTMLLinking = config.GetBoolean("AllowHTMLLinking", true); #region Limitation configuration m_allowFunctionLimiting = config.GetBoolean("AllowFunctionLimiting", false); foreach (string kvp in config.GetKeys()) { if (kvp.EndsWith("_Limit", StringComparison.Ordinal)) { string functionName = kvp.Remove(kvp.Length - 6); LimitDef limitDef = new LimitDef(); string limitType = config.GetString(functionName + "_LimitType", "None"); string limitAlert = config.GetString(functionName + "_LimitAlert", "None"); string limitAction = config.GetString(functionName + "_LimitAction", "None"); int limitTimeScale = config.GetInt(functionName + "_LimitTimeScale", 0); int limitMaxNumberOfTimes = config.GetInt(functionName + "_LimitMaxNumberOfTimes", 0); int limitFunctionsOverTimeScale = config.GetInt(functionName + "_LimitFunctionsOverTimeScale", 0); try { limitDef.Type = (LimitType)Enum.Parse(typeof(LimitType), limitType, true); } catch { } try { limitDef.Alert = (LimitAlert)Enum.Parse(typeof(LimitAlert), limitAlert, true); } catch { } try { limitDef.Action = (LimitAction)Enum.Parse(typeof(LimitAction), limitAction, true); } catch { } limitDef.TimeScale = limitTimeScale; limitDef.MaxNumberOfTimes = limitMaxNumberOfTimes; limitDef.FunctionsOverTimeScale = limitFunctionsOverTimeScale; m_functionsToLimit[functionName] = limitDef; } } #endregion m_threatLevelNone = new ThreatLevelDefinition(ThreatLevel.None, UserSetHelpers.ParseUserSetConfigSetting(config, "NoneUserSet", UserSet.None), this); m_threatLevelNuisance = new ThreatLevelDefinition(ThreatLevel.Nuisance, UserSetHelpers.ParseUserSetConfigSetting(config, "NuisanceUserSet", UserSet.None), this); m_threatLevelVeryLow = new ThreatLevelDefinition(ThreatLevel.VeryLow, UserSetHelpers.ParseUserSetConfigSetting(config, "VeryLowUserSet", UserSet.None), this); m_threatLevelLow = new ThreatLevelDefinition(ThreatLevel.Low, UserSetHelpers.ParseUserSetConfigSetting(config, "LowUserSet", UserSet.None), this); m_threatLevelModerate = new ThreatLevelDefinition(ThreatLevel.Moderate, UserSetHelpers.ParseUserSetConfigSetting(config, "ModerateUserSet", UserSet.None), this); m_threatLevelHigh = new ThreatLevelDefinition(ThreatLevel.High, UserSetHelpers.ParseUserSetConfigSetting(config, "HighUserSet", UserSet.None), this); m_threatLevelVeryHigh = new ThreatLevelDefinition(ThreatLevel.VeryHigh, UserSetHelpers.ParseUserSetConfigSetting(config, "VeryHighUserSet", UserSet.None), this); m_threatLevelSevere = new ThreatLevelDefinition(ThreatLevel.Severe, UserSetHelpers.ParseUserSetConfigSetting(config, "SevereUserSet", UserSet.None), this); m_threatLevelNoAccess = new ThreatLevelDefinition(ThreatLevel.NoAccess, UserSetHelpers.ParseUserSetConfigSetting(config, "NoAccessUserSet", UserSet.None), this); }
private void TriggerAlert(string function, LimitDef d, string message, ISceneChildEntity host) { if (d.Alert == LimitAlert.Console || d.Alert == LimitAlert.ConsoleAndInworld) MainConsole.Instance.Warn("[Limitor]: " + message); if (d.Alert == LimitAlert.Inworld || d.Alert == LimitAlert.ConsoleAndInworld) { IChatModule chatModule = host.ParentEntity.Scene.RequestModuleInterface<IChatModule>(); if (chatModule != null) chatModule.SimChat("[Limitor]: " + message, ChatTypeEnum.DebugChannel, 2147483647, host.AbsolutePosition, host.Name, host.UUID, false, host.ParentEntity.Scene); } }
/// <summary> /// Fires the action associated with the limitation /// </summary> /// <param name="d"></param> /// <param name="m_host"></param> /// <param name="itemID"></param> /// <returns>Whether the event should be dropped</returns> private bool TriggerAction(LimitDef d, ISceneChildEntity m_host, UUID itemID) { if (d.Action == LimitAction.None) return true; else if (d.Action == LimitAction.Drop) return false; //Drop it else if (d.Action == LimitAction.TerminateEvent) throw new Exception(""); //Blank messages kill events, but don't show anything on the console/inworld else if (d.Action == LimitAction.TerminateScript) { ScriptData script = GetScript(itemID); script.IgnoreNew = true; //Blocks all new events, can be reversed by resetting or resaving the script throw new Exception(""); //Blank messages kill events, but don't show anything on the console/inworld } else if (d.Action == LimitAction.Delay) MainConsole.Instance.Warn("Function delaying is not implemented"); return true; }
public void Initialize(ScriptEngine engine, IConfig config) { m_config = config; m_scriptEngine = engine; EnabledAPIs = new List<string>(config.GetString("AllowedAPIs", "LSL").ToLower().Split(',')); allowHTMLLinking = config.GetBoolean("AllowHTMLLinking", true); #region Limitation configs m_allowFunctionLimiting = config.GetBoolean("AllowFunctionLimiting", false); foreach (string kvp in config.GetKeys()) { if (kvp.EndsWith("_Limit")) { string functionName = kvp.Remove(kvp.Length - 6); LimitDef limitDef = new LimitDef(); string limitType = config.GetString(functionName + "_LimitType", "None"); string limitAlert = config.GetString(functionName + "_LimitAlert", "None"); string limitAction = config.GetString(functionName + "_LimitAction", "None"); int limitTimeScale = config.GetInt(functionName + "_LimitTimeScale", 0); int limitMaxNumberOfTimes = config.GetInt(functionName + "_LimitMaxNumberOfTimes", 0); int limitFunctionsOverTimeScale = config.GetInt(functionName + "_LimitFunctionsOverTimeScale", 0); try { limitDef.Type = (LimitType) Enum.Parse(typeof (LimitType), limitType, true); } catch { } try { limitDef.Alert = (LimitAlert) Enum.Parse(typeof (LimitAlert), limitAlert, true); } catch { } try { limitDef.Action = (LimitAction) Enum.Parse(typeof (LimitAction), limitAction, true); } catch { } limitDef.TimeScale = limitTimeScale; limitDef.MaxNumberOfTimes = limitMaxNumberOfTimes; limitDef.FunctionsOverTimeScale = limitFunctionsOverTimeScale; m_functionsToLimit[functionName] = limitDef; } } #endregion m_threatLevelNone = new ThreatLevelDefinition(ThreatLevel.None, UserSetHelpers.ParseUserSetConfigSetting(config, "NoneUserSet", UserSet.None), this); m_threatLevelNuisance = new ThreatLevelDefinition(ThreatLevel.Nuisance, UserSetHelpers.ParseUserSetConfigSetting(config, "NuisanceUserSet", UserSet.None), this); m_threatLevelVeryLow = new ThreatLevelDefinition(ThreatLevel.VeryLow, UserSetHelpers.ParseUserSetConfigSetting(config, "VeryLowUserSet", UserSet.None), this); m_threatLevelLow = new ThreatLevelDefinition(ThreatLevel.Low, UserSetHelpers.ParseUserSetConfigSetting(config, "LowUserSet", UserSet.None), this); m_threatLevelModerate = new ThreatLevelDefinition(ThreatLevel.Moderate, UserSetHelpers.ParseUserSetConfigSetting(config, "ModerateUserSet", UserSet.None), this); m_threatLevelHigh = new ThreatLevelDefinition(ThreatLevel.High, UserSetHelpers.ParseUserSetConfigSetting(config, "HighUserSet", UserSet.None), this); m_threatLevelVeryHigh = new ThreatLevelDefinition(ThreatLevel.VeryHigh, UserSetHelpers.ParseUserSetConfigSetting(config, "VeryHighUserSet", UserSet.None), this); m_threatLevelSevere = new ThreatLevelDefinition(ThreatLevel.Severe, UserSetHelpers.ParseUserSetConfigSetting(config, "SevereUserSet", UserSet.None), this); m_threatLevelNoAccess = new ThreatLevelDefinition(ThreatLevel.NoAccess, UserSetHelpers.ParseUserSetConfigSetting(config, "NoAccessUserSet", UserSet.None), this); }