Klo u di suruh Bikin Kaya Gini gimana Ini baru 1 Prodesur doank loh belom yang lain 
	Code:
	using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using aIW;
namespace adminpig
{
    public class adminpig : AdminPluginBase
    {
        public int i = 0;
        public long[] GUIDs = new long[128];
        public bool needUpdate = true;
        public bool voteInProgress = false;
        public int target = 0;
        public int got = 0;
        public string mapTarget = "mp_rust";
        public long[] alreadyVoted = new long[18];
        #region InArray
        public static bool InArray(long[] myArray, long myObject)
        {
            foreach (long aObject in myArray)
            {
                if (aObject.ToString() == myObject.ToString())
                    return true;
            }
            return false;
        }
        #endregion
        #region OnSay
        public override EventEat OnSay(AdminClient client, string message)
        {
            if (message.StartsWith("!reload"))
            {
                needUpdate = true;
            }
            else if (message.StartsWith("!"))
            {
                Commands(message, client);
                return EventEat.EatNone;
            }
            else if (message.StartsWith("/"))
            {
                Commands(message, client);
                return EventEat.EatAll;
            }
            return EventEat.EatNone;
        }
        #endregion
        //This function is generated every frame.
        #region OnFrame
        public override void OnFrame()
        {
            try
            {
                if (needUpdate)
                {
                    AdminLevel.UpdateAdminList();
                    needUpdate = false;
                }
            }
            catch (Exception e)
            {
                Log.Info("PigAdminError: " + Convert.ToString(e));
            }
        }
        #endregion
        #region Commands.
        public void Commands(string message, AdminClient client)
        {
            string[] messageFirstArr = message.Split(' ');
            string messageFirstStr = "";
            messageFirstStr = messageFirstArr[0];
            //removed the ! or / from start
            messageFirstStr = messageFirstStr.Substring(1);
            switch (messageFirstStr)
            {
                case "rcon":
                    RCon(message, client);
                    break;
                    //Added !say
                case "say":
                    Say(message, client);
                    break;
                case "kick":
                    kickPerson(message, client);
                    break;
                case "map":
                    changeMap(message, client);
                    break;
                case "ban":
                    banPerson(message, client);
                    break;
            }
        }
        #endregion
        #region RCon
        public void RCon(string message, AdminClient client)
        {
            if (AdminLevel.IsAdmin(client.GUID) == 3)
            {
                if (message.Length < 7)
                {
                    SayTo(client, "^1Invalid Parameters.");
                }
                else
                {
                    Log.Info(client.Name + " executed RCon Command: " + message.Substring(6));
                    ExecuteCommand(message.Substring(6));
                    SayTo(client, "^5Executed RCON: ^7" + message.Substring(6));
                }
            }
            else
            {
                SayTo(client, "^1You don't have ^4admin ^1access.");
            }
        }
        #endregion
        #region Say
        public void Say(string message, AdminClient client)
        {
            if (AdminLevel.IsAdmin(client.GUID) == 3)
            {
                if (message.Length < 6)
                {
                    SayTo(client, "^1Invalid Parameters.");
                }
                else
                {
                    //Executes the say command to server.
                    ExecuteCommand("say " + message.Substring(5));
                    //SayTo(client, "^2Said: ^7" + message.Substring(5));
                    //logs it
                    Log.Info(client.Name + " executed Say Command: " + message.Substring(5));
                }
            }
            else
            {
                SayTo(client, "^1You don't have ^4admin ^1access.");
            }
        }
        #endregion
        #region changeMap
        public void changeMap(string message, AdminClient client)
        {
            if (AdminLevel.IsAdmin(client.GUID) >= 2)
            {
                if (message.Length < 6)
                {
                    SayTo(client, "^1Invalid Parameters.");
                }
                else
                {
                    //Executes the say command to server.
                    ExecuteCommand("map " + message.Substring(5));
                    //SayTo(client, "^2Said: ^7" + message.Substring(5));
                    //logs it
                    Log.Info(client.Name + " changed map to: " + message.Substring(5));
                }
            }
            else
            {
                SayTo(client, "^1You don't have ^4admin ^1access.");
            }
        }
        #endregion
        #region partNametoclientID
        public short realPlayerName(string partName)
        {
            //    AdminPluginBase test = new aIW.AdminPluginBase();
            var tempname = "";
            var clients = GetClients();
            foreach (var client in clients)
            {
                tempname = client.Name;
                tempname = tempname.ToLower();
                partName = partName.ToLower();
                if (tempname.Contains(partName) == true)
                {
                    return client.ClientNum;
                }
            }
            return -1;
        }
        #endregion
        #region KickPerson
        public void kickPerson(string message, AdminClient client)
        {
            if (AdminLevel.IsAdmin(client.GUID) >= 1)
            {
                if (message.Substring(4) == "k " || message.Substring(4) == "k")
                {
                    SayTo(client, "^2Invalid parameters");
                }
                else
                {
                    string command = "";
                    string namereason = message.Substring(6);
                    string[] namereasonArr = Split_(namereason, " ", "\"", true);
                    if (namereasonArr.Length > 1)
                    {
                        string name = namereasonArr[0];
                        name = name.Replace("\"", "");
                        // Console.WriteLine("\"\" Filtered: " + name);
                        short nameID;
                        nameID = realPlayerName(name);
                        if (nameID == -1)
                        {
                            SayTo(client, "^2Player is invalid");
                            return;
                        }
                        string reason = namereason.Substring(name.Length + 1); ;
                        //  Console.WriteLine("Full text to output: kick \"" + name + "\" \"" + reason + "\"");
                        SayAll(AdminClient.Get(nameID).Name + " has been kicked for reason: " + reason);
                        command = "clientkick " + nameID + " \"" + reason + "\"";
                    }
                    else
                    {
                        string name = namereasonArr[0];
                        name = name.Replace("\"", "");
                        // Console.WriteLine("\"\" Filtered: " + name);
                        short nameID;
                        nameID = realPlayerName(name);
                        if (nameID == -1)
                        {
                            SayTo(client, "^2Player is invalid");
                            return;
                        }
                        SayAll(AdminClient.Get(nameID).Name + " has been kicked");
                        command = "clientkick " + nameID;
                        //AdminPluginBase.ExecuteCommand(command);
                    }
                    ExecuteCommand(command);
                }
            }
            else
            {
                SayTo(client, "^1You don't have ^4admin ^1access.");
            }
                
        }
        #endregion
        #region SplitWithQuantitative
        static public string[] Split_(string expression, string delimiter,
            string qualifier, bool ignoreCase)
        {
            bool _QualifierState = false;
            int _StartIndex = 0;
            System.Collections.ArrayList _Values = new System.Collections.ArrayList();
            for (int _CharIndex = 0; _CharIndex < expression.Length - 1; _CharIndex++)
            {
                if ((qualifier != null)
                 & (string.Compare(expression.Substring
                (_CharIndex, qualifier.Length), qualifier, ignoreCase) == 0))
                {
                    _QualifierState = !(_QualifierState);
                }
                else if (!(_QualifierState) & (delimiter != null)
                      & (string.Compare(expression.Substring
                (_CharIndex, delimiter.Length), delimiter, ignoreCase) == 0))
                {
                    _Values.Add(expression.Substring
                (_StartIndex, _CharIndex - _StartIndex));
                    _StartIndex = _CharIndex + 1;
                }
            }
            if (_StartIndex < expression.Length)
                _Values.Add(expression.Substring
                (_StartIndex, expression.Length - _StartIndex));
            string[] _returnValues = new string[_Values.Count];
            _Values.CopyTo(_returnValues);
            return _returnValues;
        }
        #endregion
        #region banPerson
        public void banPerson(string message, AdminClient client)
        {
            if (AdminLevel.IsAdmin(client.GUID) >= 1)
            {
                if (message.Substring(3) == "n " || message.Substring(3) == "n")
                {
                    SayTo(client, "^2Invalid parameters");
                }
                else
                {
                    string command = "";
                    string namereason = message.Substring(5);
                    string[] namereasonArr = Split_(namereason, " ", "\"", true);
                    if (namereasonArr.Length > 1)
                    {
                        string name = namereasonArr[0];
                        name = name.Replace("\"", "");
                        // Console.WriteLine("\"\" Filtered: " + name);
                        short nameID;
                        nameID = realPlayerName(name);
                        if (nameID == -1)
                        {
                            SayTo(client, "^2Player is invalid");
                            return;
                        }
                        string reason = namereason.Substring(name.Length + 1); ;
                        //  Console.WriteLine("Full text to output: kick \"" + name + "\" \"" + reason + "\"");
                        SayAll(AdminClient.Get(nameID).Name + " has been banned for reason: " + reason);
                        command = "tempbanclient " + nameID + " \"" + reason + "\"";
                    }
                    else
                    {
                        string name = namereasonArr[0];
                        name = name.Replace("\"", "");
                        // Console.WriteLine("\"\" Filtered: " + name);
                        short nameID;
                        nameID = realPlayerName(name);
                        if (nameID == -1)
                        {
                            SayTo(client, "^2Player is invalid");
                            return;
                        }
                        SayAll(AdminClient.Get(nameID).Name + " has been banned");
                        command = "tempbanclient " + nameID;
                        //AdminPluginBase.ExecuteCommand(command);
                    }
                    ExecuteCommand(command);
                }
            }
            else
            {
                SayTo(client, "^1You don't have ^4admin ^1access.");
            }
        }
        #endregion
    }
    #region AdminLevelClass
    public class AdminLevel
    {
        //#region static helpers
        //private static Dictionary<long, Client> XUIDClients { get; set; }
        //#endregion
        //Removed isL1, isL2, isL3. Whats better is having one: isAdmin, which returns the level. If no admin is found, then the value returned is -1.
        public static int IsAdmin(long xuid)
        {
            if (L1.Contains(xuid))
                return 1;
            else if (L2.Contains(xuid))
                return 2;
            else if (L3.Contains(xuid))
                return 3;
            return -1;
        }
        private static List<long> L1 { get; set; }
        private static List<long> L2 { get; set; }
        private static List<long> L3 { get; set; }
        public static void UpdateAdminList()
        {
            L1 = new List<long>();
            L2 = new List<long>();
            L3 = new List<long>();
            //Relocated admin.txt to be in the /plugins/adminpig folder.
            if (!File.Exists("./plugins/adminpig/admin.txt"))
            {
                Log.Error("No admin file, quitting.");
                return;
            }
            //Relocated admin.txt to be in the /plugins/adminpig folder.
            var adminFile = File.OpenText("./plugins/adminpig/admin.txt");
            while (!adminFile.EndOfStream)
            {
                var line = adminFile.ReadLine().Trim();
                if (line == "")
                {
                    continue;
                }
                //added another ignore if the line starts with //
                if (line[0] == ';' || line[0] == '#' || (line[0] == '/' && line[1] == '/'))
                {
                    continue;
                }
                var data = line.Split(' ');
                if (data.Length != 2)
                {
                    continue;
                }
                //Changed the stuff at the front to lowercase, just in case we use other things
                data[0] = data[0].ToLower();
                Log.Info(data.ToString());
                try
                {
                    switch (data[0])
                    {
                        case "l1":
                            Log.Info("Found L1 admin of XUID " + data[1] + " and a GUID of " + long.Parse(data[1], System.Globalization.NumberStyles.HexNumber));
                            L1.Add(long.Parse(data[1], System.Globalization.NumberStyles.HexNumber));
                            break;
                        case "l2":
                            Log.Info("Found L2 admin of XUID " + data[1] + " and a GUID of " + long.Parse(data[1], System.Globalization.NumberStyles.HexNumber));
                            L3.Add(long.Parse(data[1], System.Globalization.NumberStyles.HexNumber));
                            break;
                        case "l3":
                            Log.Info("Found L3 admin of XUID " + data[1] + " and a GUID of " + long.Parse(data[1], System.Globalization.NumberStyles.HexNumber));
                            L3.Add(long.Parse(data[1], System.Globalization.NumberStyles.HexNumber));
                            break;
                    }
                }
                catch (FormatException) { }
            }
            adminFile.Close();
        }
    
    }
    #endregion
}
 
Share This Thread