Release Permission plugin
Hey @SgtLegend can you upload your permission plugin with the passwords please. Smile
~FYANB~ Servers Website

Primary Account:
[Image: 76561198070236721.png]
Secondary Account:
[Image: 76561198096107676.png]
Third Account:
[Image: 76561198164751656.png]
Reply

I will need to build it again, I had some troubles when I permanently deleted my plugins source folder and lost that plus others, I can get it compiled again within the next day or two
I now host all my MW3 projects on my private GIT repo
Reply

(01-05-2014, 03:55)SgtLegend Wrote: I will need to build it again, I had some troubles when I permanently deleted my plugins source folder and lost that plus others, I can get it compiled again within the next day or two

Thank You! I'm in a giving mood so OMA for you!!
~FYANB~ Servers Website

Primary Account:
[Image: 76561198070236721.png]
Secondary Account:
[Image: 76561198096107676.png]
Third Account:
[Image: 76561198164751656.png]
Reply

Alright, first you need to add the following to the [Permission] section, make sure you update the password hash before you restart your server.

Code:
// Do users need to login before they can execute commands, this only works if they are part of the // groups set below // // Accepts "true" or "false" (without the quotes) LoginRequired=true // The groups that are required to login before they can execute commands LoginGroups=Admin,Moderator // The MD5 hashed password that the user is required to enter in order to execute commands, if this // value is empty the login will instantly become void and commands will work normally again // // To generate an MD5 hash simply visit google.com and search for "MD5 generator" // // Default: password LoginPassword=5f4dcc3b5aa765d61d8327deb882cf99 // The time in milliseconds before a locked out user can attempt to use commands again // // Default: 300000 (5 minutes) CoolDownPeriod=300000 // The total number of times a user can enter the wrong password before they get locked out // // Default: 3 FailedAttempts=3

Next download the attachment and overwrite your current DLL file, restart your server and simply type !login password for example, for those who want to know how this work's the source is below. There is really nothing special about the plugin apart from that it's my own custom version, you may notice some pretty heavy changes in places but it works the same.

NOTE: This version was compiled using .NET 3.5 which is fine for Windows servers as all game server hosts should have applied the upgrade patch long ago but Linux users are sadly left behind, sorry about that but I can't fix something that wasn't designed for Linux.

Code:
using Addon; using System; using System.Collections.Generic; using System.Linq; using System.Globalization; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using System.Timers; namespace Permissions { public class Main : CPlugin { private Timer _failedTimer; private List<string> _userGroups; private List<ConfigurationOption> _config; private bool _useAuthentication; private int _coolDownPeriod; private TimeSpan _coolDownPeriodTime; private int _failedAttemptsAllowed; private List<string> _authGroups; private readonly Dictionary<string, bool> _authenticated = new Dictionary<string, bool>(); private readonly Dictionary<string, FailedAttempts> _failedLoginAttempts = new Dictionary<string, FailedAttempts>(); /// <summary> /// Executes when the MW3 server loads /// </summary> public override void OnServerLoad() { ServerPrint("Permission plugin loaded. Author: Pozzuh. Version 1.4"); ServerPrint("Permission plugin updated by SgtLegend"); // First thing we need to do is construct the configuration for the permissions plugin CheckAndSetPermissionConfig(); // Next we need to initialize the user groups InitUserGroups(); // Are we using authentication? bool.TryParse(GetConfigValue("LoginRequired"), out _useAuthentication); // Ensure a password hash was set if (GetConfigValue("LoginPassword").Length == 0) { _useAuthentication = false; } if (_useAuthentication) { _authGroups = new List<string>(GetConfigValue("LoginGroups").Split(',')); _coolDownPeriod = int.Parse(GetConfigValue("CoolDownPeriod")); _failedAttemptsAllowed = int.Parse(GetConfigValue("FailedAttempts")); _coolDownPeriodTime = TimeSpan.FromMilliseconds(_coolDownPeriod); // Create the failed timer _failedTimer = new Timer { Enabled = true, Interval = 2000 }; _failedTimer.Elapsed += CheckFailedAttempts; _failedTimer.Start(); } } /// <summary> /// Checks every user that has a locked status other than the min value /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CheckFailedAttempts(object sender, ElapsedEventArgs e) { var players = _failedLoginAttempts.Where(player => player.Value.Locked); foreach (KeyValuePair<string, FailedAttempts> player in players) { if ((DateTime.Now - player.Value.Time) <= TimeSpan.Zero) continue; player.Value.Locked = false; player.Value.Time = DateTime.MinValue; player.Value.Total = 0; } } /// <summary> /// Executes when a player joins the server /// </summary> /// <param name="client"></param> public override void OnPlayerConnect(ServerClient client) { if (!_authenticated.ContainsKey(client.XUID)) { _authenticated.Add(client.XUID, false); _failedLoginAttempts.Add(client.XUID, new FailedAttempts()); } } /// <summary> /// Executes when a player leaves the server /// </summary> /// <param name="client"></param> public override void OnPlayerDisconnect(ServerClient client) { _authenticated[client.XUID] = false; } /// <summary> /// Exeutes when a player types something in the chat /// </summary> /// <param name="message"></param> /// <param name="client"></param> /// <param name="teamchat"></param> /// <returns></returns> public override ChatType OnSay(string message, ServerClient client, bool teamchat) { string returnMessage = null; // Get the command string[] split = message.Split(' '); if (split[0] == null || (split[0] != null && split[0].Length == 0)) { return ChatType.ChatContinue; } string command = split[0].ToLower(); string theCommand = command.Substring(1); // Get the group that the user is in and the commands allowed by that group string userGroup = GetUserGroup(client.XUID); List<string> groupCommands = GetGroupValue(userGroup, "commands"); // Are we using authentication for the users group? If so ensure they are logged in before // they can continue if (_useAuthentication && _authGroups.Contains(userGroup) && !_authenticated[client.XUID] && command.StartsWith("!")) { FailedAttempts player = _failedLoginAttempts[client.XUID]; if (player.Locked) { returnMessage = string.Format( "[^1Permissions^7] ^:You have been locked out from logging in for {0} for too many failed attempts", GetOverallTime(DateTime.Now - player.Time)); } else if (!Regex.Match(theCommand, "^(login|logout)$").Success) { returnMessage = "[^1Permissions^7] ^:You're not logged in yet, please use ^7!login <password>"; } if (returnMessage != null) { TellClient(client.ClientNum, returnMessage, true); return ChatType.ChatNone; } } // Execute the command switch (theCommand) { case "login": case "logout": returnMessage = "[^1Permissions^7] ^:You're already logged out, please use ^7!login <password> ^:if you wish to log in"; if (!_useAuthentication) { returnMessage = "[^1Permissions^7] ^:Authentication is disabled, simply type commands as normal"; } else if (!_authGroups.Contains(userGroup)) { returnMessage = "[^1Permissions^7] ^:You don't need to be logged in, simply type commands as normal"; } else if (theCommand == "login") { if (_authenticated[client.XUID]) { returnMessage = "[^1Permissions^7] ^:You're already logged in, type commands as normal"; } else { if (split.Length == 1 || (split.Length == 2 && split[1].Length == 0)) { returnMessage = "[^1Permissions^7] ^:Usage: ^7!login <password>"; } else if (GetMd5Hash(split[1]) == GetConfigValue("LoginPassword")) { _authenticated[client.XUID] = true; ServerPrint( string.Format( "[Permissions] ({0:dd/MM/yyyy HH:mm:ss}) {1} aka {2} was logged in successfully", DateTime.Now, client.XUID, client.Name)); returnMessage = "[^1Permissions^7] ^:You have been logged in successfully"; } else { returnMessage = "[^1Permissions^7] ^:The password you entered is incorrect!"; FailedAttempts player = _failedLoginAttempts[client.XUID]; if (++player.Total == _failedAttemptsAllowed) { returnMessage = string.Format( "[^1Permissions^7] ^:You have been locked out from logging in for {0} for too many failed attempts", GetOverallTime(_coolDownPeriodTime)); ServerPrint( string.Format( "[Permissions] ({0:dd/MM/yyyy HH:mm:ss}) {1} aka {2} was locked out", DateTime.Now, client.XUID, client.Name)); player.Locked = true; player.Time = DateTime.Now + TimeSpan.FromMilliseconds(_coolDownPeriod); } _failedLoginAttempts[client.XUID] = player; } } } else if (theCommand == "logout" && _authenticated[client.XUID]) { _authenticated[client.XUID] = false; ServerPrint(string.Format("[Permissions] ({0:dd/MM/yyyy HH:mm:ss}) {1} aka {2} logged out", DateTime.Now, client.XUID, client.Name)); returnMessage = "[^1Permissions^7] ^:You have been logged out"; } TellClient(client.ClientNum, returnMessage, true); return ChatType.ChatNone; case "getxuid": case "gettype": TellClient(client.ClientNum, (command == "!getxuid" ? string.Format("Your XUID is: {0}", client.XUID) : string.Format("Your user type is: {0}", userGroup)), true); return ChatType.ChatNone; case "help": case "cmdlist": string allowedCommands = "^1You can use: ^7"; // Join the commands by a seperated comma allowedCommands += string.Join("^1, ^7", groupCommands.ToArray()); // Check the length of the "allowedCommands", if it's total length doesn't exceed 143 characters allowedCommands = ReplaceLastCommand(allowedCommands) + "..."; TellClient(client.ClientNum, allowedCommands, true); return ChatType.ChatNone; } // Check if the player is protected against the given command string[] protectedXuids = GetServerCFG("Permission", "Protected_xuids", "").Split(','); string[] protectedCommands = GetServerCFG("Permission", "Protected_commands", "").Split(','); ServerClient requestedPlayer = protectedXuids.Length > 0 ? DeterminePlayer(message.ToLower()) : null; if (requestedPlayer != null && protectedCommands.Length > 0) { if (protectedCommands.Any(x => x == command && protectedXuids.Contains(requestedPlayer.XUID))) { TellClient(client.ClientNum, string.Format( "[^1Permissions^7] ^:You aren't allowed to use ^7{0} ^:command against ^7{1}", command, requestedPlayer.Name), true); return ChatType.ChatNone; } } // Finally check the immune groups against the current user, if the user is trying to use a command // they aren't allowed to be using let them know that string[] immuneGroups = GetServerCFG("Permission", "Immune_groups", "Admin").Split(','); if (!immuneGroups.Contains(userGroup) && command.StartsWith("!") && !groupCommands.Contains(command)) { TellClient(client.ClientNum, "[^1Permissions^7] ^:You aren't allowed to use that command!", true); return ChatType.ChatNone; } return ChatType.ChatContinue; } /// <summary> /// Sets all the default configuration data then attempts to collect the user configured data /// from the sv_config.ini file that exists on the server /// </summary> private void CheckAndSetPermissionConfig() { _config = new List<ConfigurationOption> { new ConfigurationOption { Name = "Usergroups", Value = "Admin,Moderator,User" }, new ConfigurationOption { Name = "Admin_xuids", Value = "" }, new ConfigurationOption { Name = "Admin_commands", Value = "*ALL*" }, new ConfigurationOption { Name = "Moderator_xuids", Value = "" }, new ConfigurationOption { Name = "Moderator_commands", Value = "!help,!getxuid,!gettype" }, new ConfigurationOption { Name = "User_xuids", Value = "*EVERYONE*" }, new ConfigurationOption { Name = "User_commands", Value = "!help,!getxuid,!gettype" }, new ConfigurationOption { Name = "LoginRequired", Value = "false" }, new ConfigurationOption { Name = "LoginGroups", Value = "Admin,Moderator" }, new ConfigurationOption { Name = "LoginPassword", Value = "" }, new ConfigurationOption { Name = "CoolDownPeriod", Value = "300000" }, new ConfigurationOption { Name = "FailedAttempts", Value = "3" } }; foreach (ConfigurationOption c in _config) { string configValue = GetServerCFG("Permission", c.Name, "xx__xx"); if (configValue == "xx__xx") { SetServerCFG("Permission", c.Name, c.Value); } else { c.Value = configValue; } } } /// <summary> /// Retrieves the user group configuration for the permission plugin /// </summary> private void InitUserGroups() { _userGroups = new List<string>((GetConfigValue("Usergroups") ?? string.Empty).Split(',')); } /// <summary> /// Retrieves the group name for the given player XUID /// </summary> /// <param name="xuid"></param> /// <returns></returns> private string GetUserGroup(string xuid) { if (_userGroups.Count > 0) { foreach (string group in _userGroups) { List<string> usersInGroup = GetGroupValue(group, "xuids"); if (usersInGroup.Contains(xuid) || (usersInGroup[0] != null && usersInGroup[0] == "*EVERYONE*")) { return group; } } } return "User"; } /// <summary> /// Retrieves the given value type for the given group name /// </summary> /// <param name="groupName"></param> /// <param name="type"></param> /// <returns></returns> private List<string> GetGroupValue(string groupName, string type) { groupName = groupName + "_" + type; // Attempt to get the value from the configuration string groupPlayers = GetConfigValue(groupName); if (groupPlayers == null) { groupPlayers = GetServerCFG("Permission", groupName, ""); _config.Add(new ConfigurationOption { Name = groupName, Value = groupPlayers }); } return new List<string>(groupPlayers.Split(',')); } /// <summary> /// Attempts to return the configuration string for the given configuration name, if it /// can't find the value it will simply return a null value /// </summary> /// <param name="name"></param> /// <returns></returns> private string GetConfigValue(string name) { ConfigurationOption configOpt = _config.SingleOrDefault(x => x.Name == name); return configOpt != null ? configOpt.Value : null; } /// <summary> /// Checks the length of the given string and ensures it always stays under 143 characters so /// everything fits nicely in the users chat /// </summary> /// <param name="commands"></param> /// <returns></returns> private static string ReplaceLastCommand(string commands) { if (commands.Length > 143) { commands = commands.Substring(0, commands.LastIndexOf("^1,^7", StringComparison.InvariantCulture)); } return (commands.Length > 143) ? ReplaceLastCommand(commands) : commands; } /// <summary> /// Attempts to match the given chat message against a list of clients currently logged on to /// the server /// </summary> /// <param name="msg"></param> /// <returns></returns> private ServerClient DeterminePlayer(string msg) { return (from m in msg.Split(',') from client in GetClients() where (client.ClientNum.ToString(CultureInfo.InvariantCulture) == m || client.Name.ToLower() == m || client.Name.ToLower().Contains(m)) select client).FirstOrDefault(); } /// <summary> /// Generates an MD5 hash from the input string /// </summary> /// <param name="input"></param> /// <returns></returns> private static string GetMd5Hash(string input) { MD5 md5 = new MD5CryptoServiceProvider(); //compute hash from the bytes of text md5.ComputeHash(Encoding.ASCII.GetBytes(input)); // Get hash result after compute it byte[] result = md5.Hash; var strBuilder = new StringBuilder(); for (int i = 0; i < result.Length; i++) { strBuilder.Append(result[i].ToString("x2")); } return strBuilder.ToString(); } /// <summary> /// Converts the given timespan into a readable "hours" "minutes" "seconds" format /// </summary> /// <param name="time"></param> /// <returns></returns> private string GetOverallTime(TimeSpan time) { var timeLeft = new List<string>(); int hours = Math.Abs(time.Hours); if (hours > 0) { timeLeft.Add(string.Format("{0} hours", hours)); } int minutes = Math.Abs(time.Minutes); if (minutes > 0) { timeLeft.Add(string.Format("{0} minutes", minutes)); } int seconds = Math.Abs(time.Seconds); if (seconds > 0) { timeLeft.Add(string.Format("{0} seconds", seconds)); } return string.Join(" ", timeLeft.ToArray()); } } /// <summary> /// A simple class used for determining when a client uses an incorrect password /// </summary> internal class FailedAttempts { public bool Locked = false; public DateTime Time = DateTime.MinValue; public int Total = 0; } /// <summary> /// A simple class to handle the configuration options /// </summary> internal class ConfigurationOption { public string Name, Value; } }
I now host all my MW3 projects on my private GIT repo
Reply

Where is the sv_config.ini? xD
I have a Nitrado gameserver
Reply

http://www.itsmods.com/forum/Thread-Rele...-7734.html
I now host all my MW3 projects on my private GIT repo
Reply

Thanks
When I compile this source don't work in server.
(without change in source)
Nyan Cat You can't teach an old dog new tricks Nyan Cat
Nyan Cat You can't teach grandmother to suck eggs Nyan Cat
Reply

Which source are you referring to?
I now host all my MW3 projects on my private GIT repo
Reply

(06-07-2014, 02:52)SgtLegend Wrote: Which source are you referring to?

source in first post
Nyan Cat You can't teach an old dog new tricks Nyan Cat
Nyan Cat You can't teach grandmother to suck eggs Nyan Cat
Reply

Why not just download the DLL?

http://www.itsmods.com/forum/attachment.php?aid=1377
I now host all my MW3 projects on my private GIT repo
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
Rainbow [Release] Plugin ReservedSlot v1.3 frst_ 1 4,991 11-08-2018, 19:17
Last Post: frst_
Tongue [Release] MW3 Shop plugin Dude 56 51,156 03-25-2018, 05:18
Last Post: [email protected]
  [Release] FIXED SPEED PLUGIN hillbilly 2 5,640 06-02-2016, 20:23
Last Post: clacki
  [Release] Bots Plugin For Users Casper 22 39,788 08-22-2015, 17:45
Last Post: SnapBacks
  [Release] God Plugin v5.0 [Ingame Rcon Tool] OzonE 464 335,101 06-27-2015, 15:38
Last Post: bluedot
  [Release] Anti Hardscope Plugin 8q4s8 26 27,545 06-20-2015, 22:44
Last Post: urj88419
  [Release] ProMod Plugin zxz0O0 875 760,788 03-25-2015, 22:02
Last Post: kris
  [Release] [Discontinued] Speed Plugin Pozzuh 164 121,728 10-06-2014, 12:56
Last Post: Nekochan
  [help]how create a ping plugin clacki 3 5,071 09-13-2014, 01:23
Last Post: clacki
  Help How Compile Mw3 Plugin By VB 2010 clacki 3 5,343 06-11-2014, 11:55
Last Post: SgtLegend

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2026 Melroy van den Berg.