├── README.md └── inviter.sp /README.md: -------------------------------------------------------------------------------- 1 | # Inviter 2 | _I haven't tested this plugin too much, if you see a bug or want to add a new feature you can always create an [issue](https://github.com/polvora/Inviter/issues/new)._ 3 | 4 | Send Steam group invites from the game chat. 5 | 6 | ### Client Commands 7 | 8 | * `sm_invite [#userid|name]` Sends a Steam group invite to the desired player, if it's used without arguments an invite is sent to the player who invoked it. 9 | 10 | ### ConVars 11 | #### Mandatory 12 | * `in_steamgroupid` ID of the Steam Group where players will be invited, [How to get your group ID](https://support.multiplay.co.uk/support/solutions/articles/1000202859-how-can-i-find-my-steam-group-64-id-)._(default = "")_ 13 | 14 | #### Optional 15 | * `in_adminflags` Administrator flags to bypass the restrictions. _(default = "b")_ 16 | * `in_allcaninvitethemselves` Allows everybody to send invites to them themselves. _(default = 1)_ 17 | * `in_allcaninviteothers` Allows everybody to send invites to other clients. _(default = 0)_ 18 | * `in_timebetweeninvites` Time (in seconds) between invites that non-admins must wait before sending another one. _(default = 240)_ 19 | * `in_removefriends` Removes friends after inviting them to group. _(default = 1)_ 20 | 21 | ### Install 22 | ##### Requirements 23 | * [A working version of Sourcemod](http://www.sourcemod.net/downloads.php). 24 | * [SteamCore library plugin](https://github.com/polvora/SteamCore). 25 | 26 | _**DON'T FORGET TO SETUP STEAMCORE**_ 27 | When you fulfil the requirements, just install as any other plugin, copy announcer.smx inside the plugins folder in your sourcemod directory. 28 | 29 | ### Download 30 | Compiled versions: [inviter.smx](https://github.com/polvora/Inviter/releases). 31 | 32 | If you want to compile the code yourself you have to add the include file `steamcore.inc` (from SteamCore, duh) inside `scripting/include` and then compile. _(You can't use includes with the online compiler)_ 33 | 34 | > ### Changelog 35 | > [11/05/2015] v1.0 36 | 37 | > * Initial Release. 38 | 39 | > [18/05/2015] v1.1 40 | 41 | > * Updated to the new error codes from SteamCore. 42 | 43 | > [29/01/2017] v1.2 44 | 45 | > * Minor optmizations. 46 | 47 | > [02/02/2017] v1.3 48 | 49 | > * Minor code updating. 50 | 51 | > [30/06/2016] v1.4 52 | 53 | > * Fixes typo in cvar declaration. 54 | > * Fixes bug when trying to invite from console. 55 | 56 | > [21/08/2017] v1.5 57 | 58 | > * Updated to the new Steam invite policies. -------------------------------------------------------------------------------- /inviter.sp: -------------------------------------------------------------------------------- 1 | #pragma semicolon 1 2 | 3 | #include 4 | #include 5 | 6 | #define PLUGIN_URL "https://github.com/polvora/Inviter" 7 | #define PLUGIN_VERSION "1.5" 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 | new Handle:cvarRemoveFriends; 26 | 27 | new Handle:disabledClients; 28 | new Handle:removingClients; 29 | new ReplySource:sources[32]; 30 | 31 | new pluginId = 4147279; 32 | 33 | public OnPluginStart() 34 | { 35 | // Cvars 36 | CreateConVar("inviter_version", PLUGIN_VERSION, "Inviter Version", FCVAR_SPONLY | FCVAR_DONTRECORD | FCVAR_NOTIFY); 37 | cvarGroupID = CreateConVar("in_steamgroupid", "", "Group id where people is going to be invited.", 0); 38 | cvarAdminFlags = CreateConVar("in_adminflags", "b", "Administrator flags to bypass the restrictions.", 0); 39 | cvarAllInviteThemselves = CreateConVar("in_allcaninvitethemselves", "1", "Allows everybody to send invites to them themselves.", 0, true, 0.0, true, 1.0); 40 | cvarAllInviteOthers = CreateConVar("in_allcaninviteothers", "0", "Allows everybody to send invites to other clients.", 0, true, 0.0, true, 1.0); 41 | cvarTimeBetweenInvites = CreateConVar("in_timebetweeninvites", "240", "Time between invites that non-admins must wait to send more invites.", 0, true, 0.0, true, 7200.0); 42 | cvarRemoveFriends = CreateConVar("in_removefriends", "1", "Removes friends after inviting them to group.", 0, true, 0.0, true, 1.0); 43 | 44 | RegConsoleCmd("sm_invite", cmdInvite, "Sends a group invite"); 45 | 46 | disabledClients = CreateArray(); 47 | removingClients = CreateArray(); 48 | 49 | LoadTranslations("common.phrases"); 50 | } 51 | 52 | public Action:cmdInvite(client, args) 53 | { 54 | new bool:isAdmin = IsClientAdmin(client); 55 | 56 | decl String:steamGroup[65]; 57 | GetConVarString(cvarGroupID, steamGroup, sizeof(steamGroup)); 58 | if (StrEqual(steamGroup, "")) 59 | { 60 | ReplyToCommand(client, "\x07FFF047Steam group is not configured."); 61 | return Plugin_Handled; 62 | } 63 | 64 | if (!IsClientAuthorized(client)) ReplyToCommand(client, "\x07FFF047Server is not connected to Steam at this moment, try again in a few minutes."); 65 | if (!isAdmin) 66 | { 67 | new id = GetSteamAccountID(client); 68 | if (FindValueInArray(disabledClients, id) != -1) 69 | { 70 | ReplyToCommand(client, "\x07FFF047You must wait \x01%i \x07FFF047seconds or less to send another invite.", GetConVarInt(cvarTimeBetweenInvites)); 71 | return Plugin_Handled; 72 | } 73 | PushArrayCell(disabledClients, id); 74 | CreateTimer(GetConVarFloat(cvarTimeBetweenInvites), cooldown, id); 75 | } 76 | 77 | switch(args) 78 | { 79 | case 0: 80 | { 81 | if (client == 0) 82 | { 83 | ReplyToCommand(client, "You cannot invite a server to a Steam group."); 84 | return Plugin_Handled; 85 | } 86 | if (isAdmin || GetConVarBool(cvarAllInviteThemselves)) 87 | { 88 | new String:steamID64[32]; 89 | GetClientAuthId(client, AuthId_SteamID64, steamID64, sizeof steamID64); 90 | sources[client] = GetCmdReplySource(); 91 | SteamCommunityGroupInvite(steamID64, steamGroup, pluginId); 92 | return Plugin_Handled; 93 | } 94 | 95 | ReplyToCommand(client, "\x07FFF047You do not have access to this command."); 96 | return Plugin_Handled; 97 | } 98 | 99 | case 1: 100 | { 101 | if (isAdmin || GetConVarBool(cvarAllInviteOthers)) 102 | { 103 | decl String:arg[64]; 104 | GetCmdArg(1, arg, sizeof arg); 105 | new target = FindTarget(client, arg, true, false); 106 | if (target == -1) 107 | { 108 | decl String:buffer[32]; 109 | GetCmdArg(0, buffer, sizeof(buffer)); 110 | ReplyToCommand(client, "\x07FFF047Incorrect target, usage: \x01%s [#userid|name]", buffer); 111 | return Plugin_Handled; 112 | } 113 | new String:steamID64[32]; 114 | GetClientAuthId(target, AuthId_SteamID64, steamID64, sizeof steamID64); 115 | sources[client] = GetCmdReplySource(); 116 | SteamCommunityGroupInvite(steamID64, steamGroup, pluginId); 117 | 118 | return Plugin_Handled; 119 | } 120 | 121 | ReplyToCommand(client, "\x07FFF047You are not allowed to invite other people."); 122 | return Plugin_Handled; 123 | } 124 | } 125 | 126 | ReplyToCommand(client, "\x07FFF047Incorrect syntax, usage: \x01%s [#userid|name]"); 127 | return Plugin_Handled; 128 | } 129 | 130 | public OnCommunityGroupInviteResult(const String:invitee[], const String:group[], errorCode, any:pid) 131 | { 132 | if (pid != pluginId) return; 133 | 134 | new client = FindClientFromSteamID64(invitee); 135 | if (client == 0) return; 136 | 137 | SetCmdReplySource(sources[client]); 138 | if (errorCode == 0x00) ReplyToCommand(client, "\x07FFF047The group invite has been sent."); 139 | else 140 | { 141 | if (errorCode == 0x28) 142 | { 143 | SteamChatConnect(); 144 | SteamCommunityAddFriend(invitee, pluginId); 145 | } 146 | else if(errorCode == 0x01) ReplyToCommand(client, "\x07FFF047Server logged out, try again in a few seconds."); 147 | else if(errorCode == 0x02) ReplyToCommand(client, "\x07FFF047There was a timeout in your request, try again."); 148 | else if(errorCode == 0x03) ReplyToCommand(client, "\x07FFF047Steam servers are down, try again in a few minutes."); 149 | else if (errorCode < 0x10) 150 | { 151 | new steamid = GetSteamAccountID(client); 152 | new i; 153 | if ((i = FindValueInArray(disabledClients, steamid)) != -1) 154 | RemoveFromArray(disabledClients, i); 155 | } 156 | else if(errorCode == 0x27) ReplyToCommand(client, "\x07FFF047Target has already received an invite or is already on the group."); 157 | else ReplyToCommand(client, "\x07FFF047There was an error \x010x%02x \x07FFF047while sending your invite :(", errorCode); 158 | 159 | } 160 | } 161 | 162 | public OnCommunityAddFriendResult(const String:friend[], errorCode, any:pid) 163 | { 164 | if (pid != pluginId) return; 165 | 166 | new client = FindClientFromSteamID64(friend); 167 | if (client == 0) return; 168 | 169 | SetCmdReplySource(sources[client]); 170 | if (errorCode == 0x00) ReplyToCommand(client, "\x07FFF047Friend request sent, please accept it to get a group invite."); 171 | else if (errorCode == 0x31) ReplyToCommand(client, "\x07FFF047You ignored the friend request i sent you."); 172 | else if (errorCode == 0x32) ReplyToCommand(client, "\x07FFF047It seems you have blocked the account that sends you the invite."); 173 | else ReplyToCommand(client, "\x07FFF047There was an error \x010x%02x \x07FFF047while sending your invite :(", errorCode); 174 | } 175 | 176 | public OnChatRelationshipChange(const String:account[], SteamChatRelationship:relationship) 177 | { 178 | if (relationship != SteamChatRelationshipFRIENDS) return; 179 | 180 | if (FindValueInArray(removingClients, SteamID64to32(account)) != -1) return; 181 | 182 | new String:steamGroup[65]; 183 | GetConVarString(cvarGroupID, steamGroup, sizeof(steamGroup)); 184 | 185 | SteamCommunityGroupInvite(account, steamGroup, pluginId); // We are now friends. 186 | SteamChatSendMessage(account, "Thanks for accepting the friend request, now please accept the group invite i sent you to finish :)", pluginId); 187 | 188 | if (GetConVarBool(cvarRemoveFriends)) CreateTimer(20.0, removeTimer, SteamID64to32(account)); 189 | } 190 | 191 | public Action:removeTimer(Handle:timer, any:SteamID32) 192 | { 193 | new String:SteamID64[32]; 194 | SteamID32to64(SteamID32, SteamID64, sizeof SteamID64); 195 | 196 | SteamCommunityRemoveFriend(SteamID64); 197 | } 198 | 199 | public Action:cooldown(Handle:timer, any:id) 200 | { 201 | new i; 202 | if ((i = FindValueInArray(disabledClients, id)) != -1) 203 | RemoveFromArray(disabledClients, i); 204 | } 205 | 206 | bool:IsClientAdmin(client) 207 | { 208 | if (client == 0) return true; 209 | decl String:strFlags[32]; 210 | GetConVarString(cvarAdminFlags, strFlags, sizeof strFlags); 211 | new flags = ReadFlagString(strFlags); 212 | if (flags & GetUserFlagBits(client) || ADMFLAG_ROOT & GetUserFlagBits(client)) 213 | return true; 214 | return false; 215 | } 216 | --------------------------------------------------------------------------------