Started work on revamping command system for permissions, but I'm out for the night, cya tomorrow
This commit is contained in:
parent
3774c30f7d
commit
8344801128
6 changed files with 70 additions and 1 deletions
|
|
@ -10,6 +10,7 @@ namespace TShockAPI
|
||||||
public class Commands
|
public class Commands
|
||||||
{
|
{
|
||||||
public delegate void CommandDelegate(CommandArgs args);
|
public delegate void CommandDelegate(CommandArgs args);
|
||||||
|
public static Command[] commands;
|
||||||
|
|
||||||
public struct CommandArgs
|
public struct CommandArgs
|
||||||
{
|
{
|
||||||
|
|
@ -24,6 +25,37 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class Command
|
||||||
|
{
|
||||||
|
private string name;
|
||||||
|
private string permission;
|
||||||
|
CommandDelegate command;
|
||||||
|
|
||||||
|
public Command(string cmdName, string permissionNeeded, CommandDelegate cmd)
|
||||||
|
{
|
||||||
|
name = cmdName;
|
||||||
|
permission = permissionNeeded;
|
||||||
|
command = cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Run(string msg, TSPlayer ply)
|
||||||
|
{
|
||||||
|
if (!ply.group.HasPermission(permission))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandArgs args = new CommandArgs();
|
||||||
|
args.Message = msg;
|
||||||
|
args.PlayerX = (int)ply.GetPlayer().position.X;
|
||||||
|
args.PlayerY = (int)ply.GetPlayer().position.Y;
|
||||||
|
args.PlayerID = ply.GetPlayerID();
|
||||||
|
|
||||||
|
command(args);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void InitCommands()
|
public static void InitCommands()
|
||||||
{
|
{
|
||||||
TShock.admincommandList.Add("kick", new CommandDelegate(Kick));
|
TShock.admincommandList.Add("kick", new CommandDelegate(Kick));
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,10 @@ namespace TShockAPI
|
||||||
|
|
||||||
public virtual bool HasPermission(string permission)
|
public virtual bool HasPermission(string permission)
|
||||||
{
|
{
|
||||||
|
if (permission.Equals(""))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (negatedPermissions.Contains(permission))
|
if (negatedPermissions.Contains(permission))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,11 @@ namespace TShockAPI
|
||||||
return Terraria.Main.player[player];
|
return Terraria.Main.player[player];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int GetPlayerID()
|
||||||
|
{
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsAdmin()
|
public bool IsAdmin()
|
||||||
{
|
{
|
||||||
if (adminSet)
|
if (adminSet)
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ namespace TShockAPI
|
||||||
|
|
||||||
static TShock()
|
static TShock()
|
||||||
{
|
{
|
||||||
Tools.LoadGroups();
|
//Tools.LoadGroups();
|
||||||
#region Blacklisted tiles
|
#region Blacklisted tiles
|
||||||
|
|
||||||
BlacklistTiles = new bool[0x80];
|
BlacklistTiles = new bool[0x80];
|
||||||
|
|
@ -425,6 +425,7 @@ namespace TShockAPI
|
||||||
Tools.Kick(ply, "Not on whitelist.");
|
Tools.Kick(ply, "Not on whitelist.");
|
||||||
}
|
}
|
||||||
players[ply] = new TSPlayer(ply);
|
players[ply] = new TSPlayer(ply);
|
||||||
|
players[ply].group = Tools.GetGroupForIP(ip);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -373,6 +373,7 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
groups.Add(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -405,6 +406,31 @@ namespace TShockAPI
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a Group for a ip from users.txt
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ply">string ip</param>
|
||||||
|
public static Group GetGroupForIP(string ip)
|
||||||
|
{
|
||||||
|
ip = GetRealIP(ip);
|
||||||
|
|
||||||
|
StreamReader sr = new StreamReader("users.txt");
|
||||||
|
string data = sr.ReadToEnd();
|
||||||
|
data = data.Replace("\r", "");
|
||||||
|
string[] lines = data.Split('\n');
|
||||||
|
|
||||||
|
for (int i = 0; i < lines.Length; i++)
|
||||||
|
{
|
||||||
|
string[] args = lines[i].Split(' ');
|
||||||
|
if (args[0].Equals(ip))
|
||||||
|
{
|
||||||
|
return GetGroup(args[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return GetGroup("default");
|
||||||
|
}
|
||||||
|
|
||||||
public Tools() { }
|
public Tools() { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#currently avaliable permissions: kick ban ignorecheatdetection
|
#currently avaliable permissions: kick ban ignorecheatdetection
|
||||||
#Do not remove the group default
|
#Do not remove the group default
|
||||||
#Do not name a group SuperAdmin, that is hard-coded into the code, it grants total permissions
|
#Do not name a group SuperAdmin, that is hard-coded into the code, it grants total permissions
|
||||||
|
#ALWAYS DECLARE A GROUP'S PARENT BEFORE YOU DECLARE THE GROUP
|
||||||
default null
|
default null
|
||||||
admin default kick ban
|
admin default kick ban
|
||||||
trustedadmin admin ignorecheatdetection
|
trustedadmin admin ignorecheatdetection
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue