Guest User

Admin System by mariosv819

a guest
Aug 11th, 2011
1,289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 13.81 KB | None | 0 0
  1. #include <a_samp>
  2. #include <dini>
  3. #include <dutils>
  4. #define FILTERSCRIPT
  5. #if defined FILTERSCRIPT
  6. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  7. #define COLOUR_GREEN           0x33AA33AA
  8. #define COLOUR_RED             0xAA3333AA
  9. #define COLOUR_YELLOW          0xFFFF00AA
  10. #define COLOUR_LIGHTBLUE       0x33CCFFAA
  11. #define COLOUR_ORANGE          0xFF9900AA
  12.  
  13. #define PlayerFile         "AdminScript/Users/%s.ini"
  14. #define SettingFile            "AdminScript/Settings/MainSettings.ini"
  15. #define CommandFile            "AdminScript/Settings/Commands.ini"
  16. public OnFilterScriptInit()
  17. {
  18.     print("\n****************************************");
  19.     print("* Admin Filterscript by mariosv819 *");
  20.     print("****************************************\n");
  21.  
  22.         if(!fexist(SettingFile))
  23.     {
  24.         dini_Create(SettingFile);
  25.         dini_IntSet(SettingFile, "PocketMoney", 3000);
  26.         dini_IntSet(SettingFile, "JailCommands", 0);
  27.         dini_IntSet(SettingFile, "AnnounceSeconds", 3);
  28.         dini_IntSet(SettingFile, "PassMin", 3);
  29.         dini_IntSet(SettingFile, "PassMax", 15);
  30.     }
  31.  
  32.     gSettings[POCKET_MONEY]         = dini_Int(SettingFile, "PocketMoney");
  33.     gSettings[JAIL_COMMANDS]        = dini_Int(SettingFile, "JailCommands");
  34.     gSettings[ANNOUNCE_SECONDS]             = dini_Int(SettingFile, "AnnounceSeconds");
  35.     gSettings[PASS_MIN]             = dini_Int(SettingFile, "PassMin");
  36.     gSettings[PASS_MAX]             = dini_Int(SettingFile, "PassMax");
  37.  
  38.     if(!fexist(CommandFile))
  39.     {
  40.         dini_Create(CommandFile);
  41.         dini_IntSet(CommandFile, "Akill", 6);
  42.         dini_IntSet(CommandFile, "Announce", 5);
  43.         dini_IntSet(CommandFile, "Armourall", 3);
  44.         dini_IntSet(CommandFile, "Ban", 9);
  45.         dini_IntSet(CommandFile, "Carhp", 4);
  46.         dini_IntSet(CommandFile, "Explode", 5);
  47.         dini_IntSet(CommandFile, "Goto", 4);
  48.         dini_IntSet(CommandFile, "Gethere", 5);
  49.         dini_IntSet(CommandFile, "Givearmour", 6);
  50.         dini_IntSet(CommandFile, "Givehealth", 6);
  51.         dini_IntSet(CommandFile, "Giveweapon", 7);
  52.         dini_IntSet(CommandFile, "God", 10);
  53.         dini_IntSet(CommandFile, "Healall", 7);
  54.         dini_IntSet(CommandFile, "Imitate", 8);
  55.         dini_IntSet(CommandFile, "Ip", 2);
  56.         dini_IntSet(CommandFile, "Kick", 7);
  57.         dini_IntSet(CommandFile, "Maxammo", 8);
  58.         dini_IntSet(CommandFile, "Ping", 1);
  59.         dini_IntSet(CommandFile, "Setlevel", 10);
  60.         dini_IntSet(CommandFile, "Setwanted", 6);
  61.         dini_IntSet(CommandFile, "Tban", 9);
  62.         dini_IntSet(CommandFile, "Time", 3);
  63.         dini_IntSet(CommandFile, "Weather", 3);
  64.         }
  65.  
  66.     gCommands[AKILL]            = dini_Int(CommandFile, "Akill");
  67.     gCommands[ANNOUNCE]                 = dini_Int(CommandFile, "Announce");
  68.     gCommands[ARMOURALL]            = dini_Int(CommandFile, "Armourall");
  69.     gCommands[BAN]              = dini_Int(CommandFile, "Ban");
  70.     gCommands[CARHP]            = dini_Int(CommandFile, "Carhp");
  71.     gCommands[EXPLODE]          = dini_Int(CommandFile, "Explode");
  72.     gCommands[GOTO]             = dini_Int(CommandFile, "Goto");
  73.     gCommands[GETHERE]          = dini_Int(CommandFile, "Gethere");
  74.     gCommands[GIVEARMOUR]           = dini_Int(CommandFile, "Givearmour");
  75.     gCommands[GIVEHEALTH]           = dini_Int(CommandFile, "Givehealth");
  76.     gCommands[GIVEWEAPON]           = dini_Int(CommandFile, "Giveweapon");
  77.     gCommands[GOD]              = dini_Int(CommandFile, "God");
  78.     gCommands[HEALALL]          = dini_Int(CommandFile, "Healall");
  79.     gCommands[IMITATE]          = dini_Int(CommandFile, "Imitate");
  80.     gCommands[IP]               = dini_Int(CommandFile, "Ip");
  81.     gCommands[KICK]             = dini_Int(CommandFile, "Kick");
  82.     gCommands[MAXAMMO]          = dini_Int(CommandFile, "Maxammo");
  83.     gCommands[SETLEVEL]             = dini_Int(CommandFile, "Setlevel");
  84.     gCommands[SETWANTED]            = dini_Int(CommandFile, "Setwanted");
  85.     gCommands[TBAN]             = dini_Int(CommandFile, "Tban");
  86.     gCommands[TIME]             = dini_Int(CommandFile, "Time");
  87.     gCommands[WEATHER]          = dini_Int(CommandFile, "Weather");
  88.  
  89.     return 1;
  90. }
  91.  
  92.     gSettings[POCKET_MONEY]         = dini_Int(SettingFile, "PocketMoney");
  93.     gSettings[JAIL_COMMANDS]        = dini_Int(SettingFile, "JailCommands");
  94.     gSettings[ANNOUNCE_SECONDS]             = dini_Int(SettingFile, "AnnounceSeconds");
  95.     gSettings[PASS_MIN]             = dini_Int(SettingFile, "PassMin");
  96.     gSettings[PASS_MAX]             = dini_Int(SettingFile, "PassMax");
  97.     return 1;
  98.     }
  99.  
  100.     #endif
  101. enum PLAYER_MAIN {
  102.     PLAYER_NAME[MAX_PLAYER_NAME],
  103.     PLAYER_IP[16],
  104.     PLAYER_REGGED,
  105.     PLAYER_PASS,
  106.     PLAYER_LOGGED,
  107.     PLAYER_LEVEL,
  108.     PLAYER_WIRED,
  109.     PLAYER_JAILED
  110. new gPlayerInfo[MAX_PLAYERS][PLAYER_MAIN];
  111. public OnPlayerConnect(playerid)
  112. {
  113.     new file[100],Name[MAX_PLAYER_NAME],Ip[16];
  114.         GetPlayerName(playerid,Name,sizeof(Name));
  115.         GetPlayerIp(playerid,Ip,sizeof(Ip));
  116.         format(file,sizeof(file),PlayerFile,Name);
  117.  
  118.     if(!dini_Exists(file))
  119.         {
  120.          dini_Create(file);
  121.          dini_Set(file,"Name",Name);
  122.          dini_Set(file,"Ip",Ip);
  123.          dini_IntSet(file,"Registered",-1);
  124.          dini_IntSet(file,"Password",0);
  125.          dini_IntSet(file,"Level",0);
  126.          dini_IntSet(file,"Wired",0);
  127.          dini_IntSet(file,"Jailed",0);
  128.          SendClientMessage(playerid,COLOUR_ORANGE,"Your username is not recognized on this server. Please /register to continue.");
  129.     }
  130.     strcat(gPlayerInfo[playerid][PLAYER_NAME],          dini_Get(file,"Name"));
  131.     strcat(gPlayerInfo[playerid][PLAYER_IP],            dini_Get(file,"Ip"));
  132.     gPlayerInfo[playerid][PLAYER_REGGED]                  = dini_Int(file,"Registered");
  133.     gPlayerInfo[playerid][PLAYER_PASS]                            = dini_Int(file,"Password");
  134.     gPlayerInfo[playerid][PLAYER_LEVEL]                   = dini_Int(file,"Level");
  135.     gPlayerInfo[playerid][PLAYER_WIRED]                           = dini_Int(file,"Wired");
  136.     gPlayerInfo[playerid][PLAYER_JAILED]                  = dini_Int(file,"Jailed");
  137.     if(gPlayerInfo[playerid][PLAYER_REGGED] == 0)                   SendClientMessage(playerid,COLOUR_ORANGE,"You're username is recognised on this server, but you have not registered. Please /register to continue.");
  138.     else if(gPlayerInfo[playerid][PLAYER_REGGED] == 1)              SendClientMessage(playerid,COLOUR_ORANGE,"You're username is recognised on this server. Please /login to continue.");
  139.         gPlayerInfo[playerid][PLAYER_REGGED]                          = 0;
  140.     return 1;
  141. }
  142. public OnPlayerDisconnect(playerid, reason)
  143. {
  144.     new file[100];
  145.         format(file,sizeof(file),PlayerFile,gPlayerInfo[playerid][PLAYER_NAME]);
  146.     dini_Set(file,"Name",gPlayerInfo[playerid][PLAYER_NAME]);
  147.     dini_Set(file,"Ip",gPlayerInfo[playerid][PLAYER_IP]);
  148.     dini_IntSet(file,"Registered",gPlayerInfo[playerid][PLAYER_REGGED]);
  149.     dini_IntSet(file,"Password",gPlayerInfo[playerid][PLAYER_PASS]);
  150.     dini_IntSet(file,"Level",gPlayerInfo[playerid][PLAYER_LEVEL]);
  151.     dini_IntSet(file,"Wired",gPlayerInfo[playerid][PLAYER_WIRED]);
  152.     dini_IntSet(file,"Jailed",gPlayerInfo[playerid][PLAYER_JAILED]);
  153.     gPlayerInfo[playerid][PLAYER_NAME]   = 0;
  154.     gPlayerInfo[playerid][PLAYER_IP]     = 0;
  155.     gPlayerInfo[playerid][PLAYER_REGGED] = 0;
  156.     gPlayerInfo[playerid][PLAYER_LOGGED] = 0;
  157.     gPlayerInfo[playerid][PLAYER_PASS]   = 0;
  158.     gPlayerInfo[playerid][PLAYER_LEVEL]  = 0;
  159.     gPlayerInfo[playerid][PLAYER_WIRED]  = 0;
  160.     gPlayerInfo[playerid][PLAYER_JAILED] = 0;
  161.         return 1;
  162. }
  163. public OnPlayerCommandText(playerid, cmdtext[])
  164. {
  165.     dcmd(register, 8, cmdtext);
  166.     dcmd(login, 5, cmdtext);
  167.     dcmd(logout, 6, cmdtext);
  168.     dcmd(password, 8, cmdtext);
  169.  
  170.     return 0;
  171. }
  172. dcmd_register(playerid, params[])
  173. {
  174.     if(gPlayerInfo[playerid][PLAYER_REGGED] == 1)
  175.     return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You have already registered!");
  176.     else if(!params[0])
  177.     return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /register [password]");
  178.     else if(strlen(params) < gSettings[PASS_MIN] || strlen(params) > gSettings[PASS_MAX])
  179.     {
  180.     new string[128];
  181.         format(string, sizeof(string), "ERROR: Password must be between %d and $d characters long!", gSettings[PASS_MIN], gSettings[PASS_MAX]);
  182.     return SendClientMessage(playerid, COLOUR_ORANGE, string);
  183.     }
  184.     else
  185.     {
  186.     new password = num_hash(params);
  187.     gPlayerInfo[playerid][PLAYER_PASS] = password;
  188.     gPlayerInfo[playerid][PLAYER_REGGED] = 1;
  189.         gPlayerInfo[playerid][PLAYER_LOGGED] = 1;
  190.     GetPlayerIp(playerid, gPlayerInfo[playerid][PLAYER_IP], 16);
  191.     new string[128]; format(string, sizeof(string), "You have successfully registered your account with the password \'%s\'. You have been automatically logged in.", params);
  192.     return SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
  193.     }
  194. }
  195. dcmd_login(playerid, params[])
  196. {
  197.     if(gPlayerInfo[playerid][PLAYER_REGGED] != 1)
  198.     return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You must register first to do that! Use /register [password] to register and login.");
  199.     else if(gPlayerInfo[playerid][PLAYER_LOGGED] == 1)
  200.     return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You are already logged-in.");
  201.     else if(!params[0])
  202.     return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /login [password]");
  203.     else
  204.     {
  205.     new password = num_hash(params);
  206.     if(gPlayerInfo[playerid][PLAYER_PASS] == password)
  207.     {
  208.         gPlayerInfo[playerid][PLAYER_LOGGED] = 1;
  209.             GetPlayerIp(playerid, gPlayerInfo[playerid][PLAYER_IP], 16);
  210.         return SendClientMessage(playerid, COLOUR_LIGHTBLUE, "You have successfully logged in to your account.");
  211.     }
  212.     else
  213.         return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: Incorrect password.");
  214.     }
  215. }
  216. dcmd_logout(playerid, params[])
  217. {
  218. #pragma unused params
  219.     if(gPlayerInfo[playerid][PLAYER_REGGED] != 1)
  220.     return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You must register first to do that! Use /register [password] to register.");
  221.     else if(gPlayerInfo[playerid][PLAYER_LOGGED] == 0)
  222.     return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You are already logged-out.");
  223.     else
  224.     {
  225.     gPlayerInfo[playerid][PLAYER_LOGGED] = 0;
  226.     return SendClientMessage(playerid, COLOUR_LIGHTBLUE, "You have successfully logged out of your account.");
  227.     }
  228. }
  229. dcmd_password(playerid, params[])
  230. {
  231.     if(gPlayerInfo[playerid][PLAYER_REGGED] != 1)
  232.         return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You must register first to do that! Use /register [password] to register and login.");
  233.     else if(gPlayerInfo[playerid][PLAYER_LOGGED] == 0)
  234.     return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You must be logged-in to do that! Use /login [password] to login.");
  235.     else
  236.     {
  237.     new tmp[30],
  238.         tmp2[30],
  239.         index;
  240.     tmp = strtok(params, index);
  241.     if(!strlen(tmp))
  242.             return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /password [password] [new password]");
  243.     tmp2 = strtok(params, index);
  244.     if(!strlen(tmp2))
  245.         return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /password [password] [new password]");
  246.         new oldpassword = num_hash(tmp), newpassword = num_hash(tmp2);
  247.     if(gPlayerInfo[playerid][PLAYER_PASS] == oldpassword)
  248.     {
  249.         if(oldpassword == newpassword)
  250.             return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: Your old password can not be the same as your new password.");
  251.             else if(strlen(tmp2) < gSettings[PASS_MIN] || strlen(tmp2) > gSettings[PASS_MAX])
  252.             {
  253.                 new string[100]; format(string, sizeof(string), "ERROR: Your new password must be between %d and %d characters long!", gSettings[PASS_MIN], gSettings[PASS_MAX]);
  254.                 return SendClientMessage(playerid, COLOUR_ORANGE, string);
  255.             }
  256.         gPlayerInfo[playerid][PLAYER_PASS] = newpassword;
  257.         new string[128]; format(string, sizeof(string), "You have successfully changed your password from \'%s\' to \'%s\'.", tmp, tmp2);
  258.         return SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
  259.     }
  260.     else
  261.         return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: Incorrect password.");
  262.     }
  263. }
  264. enum SETTINGS_MAIN {
  265.     POCKET_MONEY,
  266.     JAIL_COMMANDS,
  267.     ANNOUNCE_SECONDS,
  268.     PASS_MIN,
  269.     PASS_MAX
  270. }
  271.  
  272. new gSettings[SETTINGS_MAIN];
  273. enum COMMANDS_MAIN {
  274.     AKILL,
  275.     ANNOUNCE,
  276.     ARMOURALL,
  277.     BAN,
  278.     CARHP,
  279.     EXPLODE,
  280.     FLIP,
  281.     GOTO,
  282.     GETHERE,
  283.     GIVEARMOUR,
  284.     GIVEHEALTH,
  285.     GIVEWEAPON,
  286.     GOD,
  287.     HEALALL,
  288.     IMITATE,
  289.     IP,
  290.     KICK,
  291.     MAXAMMO,
  292.     PING,
  293.     SETLEVEL,
  294.     SETWANTED,
  295.     TBAN,
  296.     TIME,
  297.     WEATHER
  298. }
  299.  
  300. new gCommands[COMMANDS_MAIN];
  301. dcmd_akill(playerid, params[])
  302. {
  303.     if(gPlayerInfo[playerid][PLAYER_LEVEL] < gCommands[AKILL])
  304.     {
  305.         new string[100];
  306.         format(string, sizeof(string), "You must be administrator level %d to use that command!", gCommands[AKILL]);
  307.         return SendClientMessage(playerid, COLOUR_ORANGE, string);
  308.     }
  309.     else if(!strlen(params))
  310.         return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /akill [id | name]");
  311.     else
  312.     {
  313.     new id = (isNumeric(params)) ? strval(params) : GetPlayerId(params);
  314.     if(IsPlayerConnected(id) && id != playerid)
  315.     {
  316.         SetPlayerHealth(id, 0.0);
  317.         new string[128];
  318.         format(string, sizeof(string), "You have been admin-killed by administrator \'%s\'.", gPlayerInfo[playerid][PLAYER_NAME]);
  319.         SendClientMessage(id, COLOUR_ORANGE, string);
  320.         format(string, sizeof(string), "You have successfully admin-killed player \'%s\'.", gPlayerInfo[id][PLAYER_NAME]);
  321.         return SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
  322.     }
  323.     else
  324.         return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You can not admin-kill yourself or a disconnected player.");
  325.     }
  326. }
  327. dcmd_announce(playerid, params[])
  328. {
  329.     if(gPlayerInfo[playerid][PLAYER_LEVEL] < gCommands[ANNOUNCE])
  330.     {
  331.         new string[100];
  332.         format(string, sizeof(string), "You must be administrator level %d to use that command!", gCommands[ANNOUNCE]);
  333.         return SendClientMessage(playerid, COLOUR_ORANGE, string);
  334.     }
  335.     else if(!strlen(params))
  336.         return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /announce [message]");
  337.     else
  338.         return GameTextForAll(params, gSettings[ANNOUNCE_SECONDS] * 1000, 3);
  339. }
Advertisement
Add Comment
Please, Sign In to add comment