Advertisement
Guest User

steaminviter2

a guest
Mar 23rd, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.06 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <steamcore>
  5.  
  6. #define PLUGIN_URL ""
  7. #define PLUGIN_VERSION "1.3"
  8. #define PLUGIN_NAME "Inviter"
  9. #define PLUGIN_AUTHOR "Statik"
  10.  
  11. public Plugin:myinfo =
  12. {
  13.     name = PLUGIN_NAME,
  14.     author = PLUGIN_AUTHOR,
  15.     description = "Steam group invites via game commands.",
  16.     version = PLUGIN_VERSION,
  17.     url = PLUGIN_URL
  18. }
  19.  
  20. new Handle:cvarGroupID;
  21. new Handle:cvarAdminFlags;
  22. new Handle:cvarAllInviteThemselves;
  23. new Handle:cvarAllInviteOthers;
  24. new Handle:cvarTimeBetweenInvites;
  25.  
  26. new Handle:disabledClients;
  27. new ReplySource:sources[32];
  28.  
  29. public OnPluginStart()
  30. {
  31.     // Cvars
  32.     CreateConVar("inviter_version", PLUGIN_VERSION, "Force Picker Version", FCVAR_SPONLY | FCVAR_DONTRECORD | FCVAR_NOTIFY);
  33.     cvarGroupID = CreateConVar("in_steamgroupid", "", "Group id where people is going to be invited.", 0);
  34.     cvarAdminFlags = CreateConVar("in_adminflags", "b", "Administrator flags to bypass the restrictions.", 0);
  35.     cvarAllInviteThemselves = CreateConVar("in_allcaninvitethemselves.", "1", "Allows everybody to send invites to them themselves.", 0, true, 0.0, true, 1.0);
  36.     cvarAllInviteOthers = CreateConVar("in_allcaninviteothers.", "0", "Allows everybody to send invites to other clients.", 0, true, 0.0, true, 1.0);
  37.     cvarTimeBetweenInvites = CreateConVar("in_timebetweeninvites", "240", "Time between invites that non-admins must wait to send more invites.", 0, true, 0.0, true, 7200.0);
  38.    
  39.     RegConsoleCmd("sm_invite", cmdInvite, "Sends a group invite");
  40.  
  41.     disabledClients = CreateArray();
  42.    
  43.     LoadTranslations("common.phrases");
  44. }
  45.  
  46. public Action:cmdInvite(client, args)
  47. {
  48.     new bool:isAdmin = IsClientAdmin(client);
  49.    
  50.     decl String:steamGroup[65];
  51.     GetConVarString(cvarGroupID, steamGroup, sizeof(steamGroup));
  52.     if (StrEqual(steamGroup, ""))
  53.     {
  54.         ReplyToCommand(client, "Steam group is not configured.");
  55.         return Plugin_Handled;
  56.     }
  57.    
  58.     if (!isAdmin)
  59.     {
  60.         new id = GetSteamAccountID(client);
  61.         if (FindValueInArray(disabledClients, id) != -1)
  62.         {
  63.             ReplyToCommand(client, "You must wait \x01%i seconds or less to send another invite.", GetConVarInt(cvarTimeBetweenInvites));
  64.             return Plugin_Handled;
  65.         }
  66.         PushArrayCell(disabledClients, id);
  67.     }
  68.    
  69.     switch(args)
  70.     {
  71.         case 0:
  72.         {
  73.             if (client == 0)
  74.             {
  75.                 ReplyToCommand(client, "You cannot invite a server to a Steam group.");
  76.                 return Plugin_Handled;
  77.             }
  78.             if (isAdmin || GetConVarBool(cvarAllInviteThemselves))
  79.             {
  80.                 new String:steamID64[32];
  81.                 GetClientAuthId(client, AuthId_SteamID64, steamID64, sizeof steamID64);
  82.                 sources[client] = GetCmdReplySource();
  83.                 SteamGroupInvite(client, steamID64, steamGroup, callback);
  84.                 return Plugin_Handled;
  85.             }
  86.            
  87.             ReplyToCommand(client, "You do not have access to this command.");
  88.             return Plugin_Handled;         
  89.         }
  90.        
  91.         case 1:
  92.         {
  93.             if (isAdmin || GetConVarBool(cvarAllInviteOthers))
  94.             {
  95.                 decl String:arg[64];
  96.                 GetCmdArg(1, arg, sizeof arg);
  97.                 new target = FindTarget(client, arg, true, false);
  98.                 if (target == -1)
  99.                 {
  100.                     decl String:buffer[32];
  101.                     GetCmdArg(0, buffer, sizeof(buffer));
  102.                     ReplyToCommand(client, "Incorrect target, usage: \x01%s [#userid|name]", buffer);
  103.                     return Plugin_Handled;
  104.                 }
  105.                 new String:steamID64[32];
  106.                 GetClientAuthId(target, AuthId_SteamID64, steamID64, sizeof steamID64);
  107.                 sources[client] = GetCmdReplySource();
  108.                 SteamGroupInvite(client, steamID64, steamGroup, callback);
  109.                 return Plugin_Handled;
  110.             }
  111.            
  112.             ReplyToCommand(client, "You are not allowed to invite other people.");
  113.             return Plugin_Handled;                     
  114.         }  
  115.     }
  116.    
  117.     ReplyToCommand(client, "Incorrect syntax, usage: \x01%s [#userid|name]");
  118.     return Plugin_Handled;
  119. }
  120.  
  121. public Action:cooldown(Handle:timer, any:id)
  122. {
  123.     new i;
  124.     if ((i = FindValueInArray(disabledClients, id)) != -1)
  125.         RemoveFromArray(disabledClients, i);
  126. }
  127.  
  128. public callback(client, bool:success, errorCode, any:data)
  129. {
  130.     if (client != 0 && !IsClientInGame(client)) return;
  131.    
  132.     SetCmdReplySource(sources[client]);
  133.     if (success) ReplyToCommand(client, "The group invite has been sent.");
  134.     else
  135.     {
  136.         if (errorCode < 0x10 || errorCode == 0x23)
  137.         {
  138.             new id = GetSteamAccountID(client);
  139.             new i;
  140.             if ((i = FindValueInArray(disabledClients, id)) != -1)
  141.                 RemoveFromArray(disabledClients, i);
  142.         }
  143.         switch(errorCode)
  144.         {
  145.             case 0x01:  ReplyToCommand(client, "Server is busy with another task at this time, try again in a few seconds.");
  146.             case 0x02:  ReplyToCommand(client, "There was a timeout in your request, try again.");
  147.             case 0x23:  ReplyToCommand(client, "Session expired, retry to reconnect.");
  148.             case 0x27:  ReplyToCommand(client, "Target has already received an invite or is already on the group.");
  149.             default:    ReplyToCommand(client, "There was an error \x010x%02x while sending your invite :(", errorCode);
  150.         }
  151.     }
  152. }
  153.  
  154. public bool:IsClientAdmin(client)
  155. {
  156.     decl String:strFlags[32];
  157.     GetConVarString(cvarAdminFlags, strFlags, sizeof strFlags);
  158.     new flags = ReadFlagString(strFlags);
  159.     if (flags & GetUserFlagBits(client) || ADMFLAG_ROOT & GetUserFlagBits(client))
  160.         return true;
  161.     return false;
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement