-
Notifications
You must be signed in to change notification settings - Fork 1
/
announcer.sp
229 lines (187 loc) · 7.57 KB
/
announcer.sp
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
#pragma dynamic 2048 // Increases stack space to 8kb, needed for saving user announcements
#include <sourcemod>
#include <steamcore>
#define PLUGIN_URL ""
#define PLUGIN_VERSION "1.6"
#define PLUGIN_NAME "Announcer"
#define PLUGIN_AUTHOR "Statik"
public Plugin:myinfo =
{
name = PLUGIN_NAME,
author = PLUGIN_AUTHOR,
description = "Steam group announcements via game commands.",
version = PLUGIN_VERSION,
url = PLUGIN_URL
}
new String:announcements[32][128];
new ReplySource:sources[32];
new Handle:cvarSteamGroupID;
new Handle:cvarUpperCase;
new Handle:cvarCallerInfo;
new Handle:cvarServerInfo;
new Handle:cvarRevealPass;
new Handle:cvarRedirectURL;
new Handle:cvarExtraInfo;
public OnPluginStart()
{
// Commands
RegAdminCmd("sm_announcer", cmdAnnounce, ADMFLAG_CONFIG, "Posts a new announcement to a Steam group.");
RegAdminCmd("sm_an", cmdAnnounce, ADMFLAG_CONFIG, "Posts a new announcement to a Steam group.");
// Convars
CreateConVar("announcer_version", PLUGIN_VERSION, "Announcer Version", FCVAR_SPONLY | FCVAR_DONTRECORD | FCVAR_NOTIFY);
cvarSteamGroupID = CreateConVar("an_steamgroupid", "", "Steam group community ID to make announcements.", 0);
cvarUpperCase = CreateConVar("an_uppercase", "0", "Changes the announcement title to upper-case.", 0, true, 0.0, true, 1.0);
cvarCallerInfo = CreateConVar("an_callerinfo", "1", "Toggles information of caller displayed in announcement body.", 0, true, 0.0, true, 1.0);
cvarServerInfo = CreateConVar("an_serverinfo", "1", "Toggles information of server displayed in announcement body.", 0, true, 0.0, true, 1.0);
cvarRevealPass = CreateConVar("an_revealpassword", "0", "If set, server password will be shown on server information.", 0, true, 0.0, true, 1.0);
cvarRedirectURL = CreateConVar("an_redirecturl", "", "URL to parse HTTP GET requests to Steam requests.", 0);
cvarExtraInfo = CreateConVar("an_extrainfo", "", "Extra text to add at the start of the announcement description.", 0);
}
public Action:cmdAnnounce(client, args)
{
decl String:steamGroup[65];
GetConVarString(cvarSteamGroupID, steamGroup, sizeof(steamGroup));
if (StrEqual(steamGroup, ""))
{
ReplyToCommand(client, "\x07FFF047There is no steam group to announce.");
return Plugin_Handled;
}
if (GetCmdArgs() == 0)
{
if (strcmp(announcements[client], "") == 0)
{
ReplyToCommand(client, "\x07FFF047No previous message set: \x01sm_an [message]");
return Plugin_Handled;
}
}
else GetCmdArgString(announcements[client], sizeof(announcements[]));
if (GetConVarBool(cvarUpperCase))
String_ToUpper(announcements[client], announcements[client], sizeof announcements[]);
decl String:body[2048];
GetBodySting(client, body, sizeof(body));
sources[client] = GetCmdReplySource();
SteamCommunityGroupAnnounce(announcements[client], body, steamGroup, client);
return Plugin_Handled;
}
public OnCommunityGroupAnnounceResult(const String:title[], const String:body[], const String:group[], errorCode, any:client)
{
if (client != 0 && !IsClientInGame(client)) return;
SetCmdReplySource(sources[client]);
if (errorCode == 0x00) ReplyToCommand(client, "\x07FFF047Your announcement was successfully posted.");
else if (errorCode == 0x01) ReplyToCommand(client, "\x07FFF047Server logged out, try again in a few seconds.");
else if (errorCode == 0x02 || errorCode == 0x03) ReplyToCommand(client, "\x07FFF047There was a timeout in your request, try again.");
else ReplyToCommand(client, "\x07FFF047There was an error \x010x%02x \x07FFF047while posting your announcement :(", errorCode);
}
public OnClientDisconnect(client)
{
strcopy(announcements[client], sizeof(announcements[]), "");
}
GetBodySting(client, String:body[], maxSize)
{
strcopy(body, maxSize, "");
decl String:buffer[1024];
GetConVarString(cvarExtraInfo, buffer, sizeof buffer);
if (!StrEqual(buffer, ""))
{
StrCat(body, maxSize, buffer);
StrCat(body, maxSize, "\n");
}
if (client == 0)
{
StrCat(body, maxSize, "\n");
return;
}
if (GetConVarBool(cvarCallerInfo))
{
decl String:clientName[64];
decl String:clientCommunityID[32];
decl String:clientSteamID[32];
GetClientName(client, clientName, sizeof(clientName));
GetClientAuthId(client, AuthId_SteamID64, clientCommunityID, sizeof(clientCommunityID));
GetClientAuthId(client, AuthId_Steam2, clientSteamID, sizeof(clientSteamID));
String_ToUpper(clientName, clientName, sizeof(clientName));
Format(buffer, sizeof(buffer), "[b][url=http://steamcommunity.com/profiles/%s]%s[/url][/b]", clientCommunityID, clientName);
StrCat(body, maxSize, buffer);
Format(buffer, sizeof(buffer), " - [i]%s[/i]", clientSteamID);
StrCat(body, maxSize, buffer);
StrCat(body, maxSize, "\n");
}
if (IsClientInGame(client))
{
decl String:IP[32];
decl String:PORT[16];
decl String:pw[32];
decl String:map[64];
GetServerIP(IP, sizeof(IP));
GetConVarString(FindConVar("hostport"), PORT, sizeof(PORT));
GetConVarString(FindConVar("sv_password"), pw, sizeof(pw));
GetCurrentMap(map, sizeof map);
if (GetConVarBool(cvarServerInfo))
{
decl String:hostname[64];
GetConVarString(FindConVar("hostname"), hostname, sizeof(hostname));
Format(buffer, sizeof(buffer), "[b]%s[/b] (%i/%i) - [i]@%s[/i]", hostname, GetClientCount(), MaxClients, map);
StrCat(body, maxSize, buffer);
StrCat(body, maxSize, "\n");
}
decl String:redirectURL[128];
GetConVarString(cvarRedirectURL, redirectURL, sizeof(redirectURL));
if (StrEqual(redirectURL, ""))
return;
decl String:finalRedirectURL[128];
Format(finalRedirectURL, sizeof(finalRedirectURL), "%s?ip=%s&port=%s", redirectURL, IP, PORT);
if (GetConVarBool(cvarRevealPass) && !StrEqual(pw, ""))
{
Format(buffer, sizeof(buffer), "&pw=%s", pw);
StrCat(finalRedirectURL, sizeof(finalRedirectURL), buffer);
}
if (!GetConVarBool(cvarRevealPass) || StrEqual(pw, ""))
Format(buffer, sizeof(buffer), "[i]connect [b]%s:%s[/b][/i]", IP, PORT);
else
Format(buffer, sizeof(buffer), "[i]connect [b]%s:%s[/b]; password [b]%s[/b][/i]", IP, PORT, pw);
StrCat(body, maxSize, buffer);
StrCat(body, maxSize, "\n");
Format(buffer, sizeof(buffer), "[url=%s][h1][b][u][Join Server][/u][/b][/h1][/url]", finalRedirectURL);
StrCat(body, maxSize, buffer);
StrCat(body, maxSize, "\n");
}
}
/*======================================
================EXTRAS==================
======================================*/
/**
* Converts the whole String to upper case.
* Only works with alphabetical characters (not öäü) because Sourcemod suxx !
* The Output String can be the same as the Input String.
*
* @param input Input String.
* @param output Output String.
* @param size Max Size of the Output string
* @noreturn
*/
// SMLib https://forums.alliedmods.net/showthread.php?t=148387
stock String_ToUpper(const String:input[], String:output[], size)
{
size--;
new x=0;
while (input[x] != '\0') {
if (IsCharLower(input[x])) {
output[x] = CharToUpper(input[x]);
}
else {
output[x] = input[x];
}
x++;
}
output[x] = '\0';
}
stock GetServerIP(String:buffer[], maxSize) // https://forums.alliedmods.net/archive/index.php/t-56987.html
{
new pieces[4];
new longip = GetConVarInt(FindConVar("hostip"));
pieces[0] = (longip >> 24) & 0x000000FF;
pieces[1] = (longip >> 16) & 0x000000FF;
pieces[2] = (longip >> 8) & 0x000000FF;
pieces[3] = longip & 0x000000FF;
FormatEx(buffer, maxSize, "%d.%d.%d.%d", pieces[0], pieces[1], pieces[2], pieces[3]);
}