This repository was archived by the owner on Jan 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSteam-Group-Invite.sp
More file actions
325 lines (255 loc) · 7.91 KB
/
Steam-Group-Invite.sp
File metadata and controls
325 lines (255 loc) · 7.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*
* Steam Group Invite - A simple plugin that invites the player to the desired group
*
* Copyright (C) 2017 RumbleFrog
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma semicolon 1
#define PLUGIN_AUTHOR "Fishy"
#define PLUGIN_VERSION "1.2.0"
#include <sourcemod>
#include <SteamWorks>
#include <steamcore>
#include <morecolors>
#include <bigint>
#undef REQUIRE_EXTENSIONS
#include <steamtools>
#pragma newdecls required
ConVar cGroupID;
ConVar cAutoInvite;
Handle InCoolDown;
char GroupID[64];
char GroupID32[64];
bool InGroup[MAXPLAYERS + 1];
bool AutoInvite;
EngineVersion g_EngineVersion;
public Plugin myinfo =
{
name = "Steam Group Invite",
author = PLUGIN_AUTHOR,
description = "A simple plugin that invites the player to the desired group",
version = PLUGIN_VERSION,
url = "https://keybase.io/rumblefrog"
};
public void OnPluginStart()
{
CreateConVar("sgi_version", PLUGIN_VERSION, "Steam Group Invite", FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY);
cGroupID = CreateConVar("sgi_groupid", "0", "Group ID | Ex: 103582791457828777", 0, true, 0.0);
cGroupID.GetString(GroupID, sizeof GroupID);
cAutoInvite = CreateConVar("sgi_autoinvite", "0", "Automatically Invite To Group; If Not In Group Already", 0, true, 0.0, true, 1.0);
AutoInvite = cAutoInvite.BoolValue;
cGroupID.AddChangeHook(OnConVarChanged);
cAutoInvite.AddChangeHook(OnConVarChanged);
RegConsoleCmd("sm_invite", InviteCmd, "Invites the client to desired Steam group");
RegConsoleCmd("sm_ingroup", InGroupCmd, "Checks if the client is in desired Steam group");
InCoolDown = CreateArray();
CalculateGroupID32();
HookGameStart();
}
public Action InviteCmd(int client, int args)
{
InviteClient(client, false);
return Plugin_Handled;
}
public Action InGroupCmd(int client, int args)
{
if (InGroup[client])
CPrintToChat(client, "{lightseagreen}[SGI] {grey}You are currently in the Steam group.");
else
CPrintToChat(client, "{lightseagreen}[SGI] {grey}You are currently not in the Steam group");
return Plugin_Handled;
}
public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
if (convar == cGroupID)
{
cGroupID.GetString(GroupID, sizeof GroupID);
CalculateGroupID32();
}
if (convar == cAutoInvite)
AutoInvite = cAutoInvite.BoolValue;
}
void InviteClient(int client, bool silent = false)
{
if (StrEqual(GroupID, "0"))
{
if (!silent)
CPrintToChat(client, "{lightseagreen}[SGI] {grey}Group ID Convar not setup.");
return;
}
int AccountID = GetSteamAccountID(client);
if (FindValueInArray(InCoolDown, AccountID) != -1)
{
if (!silent)
CPrintToChat(client, "{lightseagreen}[SGI] {grey}Please wait 4 minutes between requests.");
return;
}
char SteamID64[32];
GetClientAuthId(client, AuthId_SteamID64, SteamID64, sizeof SteamID64);
if (silent)
SteamGroupInvite(client, SteamID64, GroupID, SteamCore_SilentCall);
else
SteamGroupInvite(client, SteamID64, GroupID, SteamCore_CallBack);
PushArrayCell(InCoolDown, AccountID);
CreateTimer(240.0, Core_Cooldown, AccountID);
}
void AttemptAutoInvite(int client)
{
if (!AutoInvite || InGroup[client]) return;
InviteClient(client, true);
}
void CalculateGroupID32()
{
int IntArray[1024], IntArraySub[1024], Int32[1024];
hexString2BigInt(GroupID, IntArray, sizeof IntArray);
hexString2BigInt("103582791429521408", IntArraySub, sizeof IntArraySub);
subBigInt(IntArray, IntArraySub, 10, Int32, sizeof Int32);
bigInt2HexString(Int32, GroupID32, sizeof GroupID32);
}
void HookGameStart()
{
g_EngineVersion = GetEngineVersion();
switch (g_EngineVersion)
{
case Engine_TF2, Engine_CSS:
HookEvent("teamplay_round_start", OnGameEventStart, EventHookMode_PostNoCopy);
case Engine_CSGO, Engine_Left4Dead2, Engine_HL2DM:
HookEvent("round_start", OnGameEventStart, EventHookMode_PostNoCopy);
case Engine_DODS:
HookEvent("dod_round_start", OnGameEventStart, EventHookMode_PostNoCopy);
}
}
public void OnGameEventStart(Event event, const char[] name, bool dontBroadcast)
{
for (int i = 1; i <= MaxClients; i++)
{
if (Client_IsValid(i))
{
if (!InGroup[i])
PrintHintText(i, "Consider joining our group using !invite");
}
}
}
public Action Core_Cooldown(Handle timer, any data)
{
int i;
if ((i = FindValueInArray(InCoolDown, data)) != -1)
RemoveFromArray(InCoolDown, i);
}
public void SteamCore_CallBack(int iClient, bool bSuccess, int iErrorCode, any data)
{
if (iClient != 0 && !IsClientInGame(iClient)) return;
if (bSuccess) CPrintToChat(iClient, "{lightseagreen}[SGI] {grey}The group invite has been sent.");
else
{
if (iErrorCode < 0x10 || iErrorCode == 0x23)
{
int i;
if ((i = FindValueInArray(InCoolDown, data)) != -1)
RemoveFromArray(InCoolDown, i);
}
switch(iErrorCode)
{
case 0x01: CPrintToChat(iClient, "{lightseagreen}[SGI] {grey}Request overflow. Please try again later.");
case 0x02: CPrintToChat(iClient, "{lightseagreen}[SGI] {grey}Your request took too long. Please try again.");
case 0x27: CPrintToChat(iClient, "{lightseagreen}[SGI] {grey}You're already been invited or is already in the group.");
default: CPrintToChat(iClient, "{lightseagreen}[SGI] {grey}A fatal error has occured: {chartreuse}%i{grey}. Please try again later.", iErrorCode);
}
}
}
public void SteamCore_SilentCall(int iClient, bool bSuccess, int iErrorCode, any data)
{
if (iClient != 0 && !IsClientInGame(iClient)) return;
if (!bSuccess)
{
if (iErrorCode < 0x10 || iErrorCode == 0x23)
{
int i;
if ((i = FindValueInArray(InCoolDown, data)) != -1)
RemoveFromArray(InCoolDown, i);
}
}
}
public void OnClientPostAdminCheck(int iClient)
{
if (!StrEqual(GroupID32, "0"))
{
if (!SteamWorks_GetUserGroupStatus(iClient, StringToInt(GroupID32)))
{
CPrintToChat(iClient, "{lightseagreen}[SGI] {grey}Request overflow. Please try again later.");
return;
}
}
}
public int SteamWorks_OnClientGroupStatus(int authid, int groupid, bool isMember, bool isOfficer)
{
if (groupid != StringToInt(GroupID32))
return;
int iClient = GetUserFromAuthID(authid);
if (iClient == -1)
return;
if (isMember || isOfficer)
{
InGroup[iClient] = true;
return;
}
AttemptAutoInvite(iClient);
return;
}
//In cases where Steamtools is also loaded and Steamworks fails to see the callback
public int Steam_GroupStatusResult(int client, int groupAccountID, bool groupMember, bool groupOfficer)
{
if (groupAccountID != StringToInt(GroupID32))
return;
if (client == -1)
return;
if (groupMember || groupOfficer)
{
InGroup[client] = true;
return;
}
AttemptAutoInvite(client);
return;
}
public int GetUserFromAuthID(int authid)
{
for (int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i)) {
char charauth[64];
GetClientAuthId(i, AuthId_Steam3, charauth, sizeof(charauth));
char charauth2[64];
IntToString(authid, charauth2, sizeof(charauth2));
if(StrContains(charauth, charauth2, false) > -1)
{
return i;
}
}
}
return -1;
}
stock bool Client_IsValid(int iClient, bool bAlive = false)
{
if (iClient >= 1 &&
iClient <= MaxClients &&
IsClientConnected(iClient) &&
IsClientInGame(iClient) &&
!IsFakeClient(iClient) &&
(bAlive == false || IsPlayerAlive(iClient)))
{
return true;
}
return false;
}