-
Notifications
You must be signed in to change notification settings - Fork 3
/
pubcomp.sp
304 lines (254 loc) · 10.3 KB
/
pubcomp.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
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
#include <sourcemod>
#include <string>
#include <usermessages>
#include "config.inc"
#include "version.inc"
public Plugin:myinfo = {
name = "PubComp",
author = "The PubComp Team",
description = "",
version = PLUGIN_VERSION,
url = "http://pubcomp.com/"
};
new String:steamID[32][20] = { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
new Float:steamIDExpire[32];
new bool:tickStarted = false;
new bool:pubCompBotKicked = false;
new String:gameCommands[MAX_COMMANDS][MAX_COMMAND_LENGTH];
new commandCount = 0;
public OnPluginStart() {
RegConsoleCmd( "pubcomp_add_steamid", CommandAddSteamID, "", FCVAR_PLUGIN );
RegConsoleCmd( "pubcomp_set_warmup_mod", CommandSetWarmupMod, "", FCVAR_PLUGIN);
RegConsoleCmd( "pubcomp_add_game_command", CommandAddGameCommand, "", FCVAR_PLUGIN);
RegConsoleCmd( "pubcomp_reset_game_commands", CommandResetGameCommands, "", FCVAR_PLUGIN);
RegConsoleCmd( "pubcomp_add_game_position", CommandResetGameCommands, "", FCVAR_PLUGIN);
RegConsoleCmd( "pubcomp_start_item_vote", CommandStartItemVote, "", FCVAR_PLUGIN );
RegConsoleCmd( "say", ReadyUnready, "", FCVAR_PLUGIN);
ServerCommand("mp_waitingforplayers_cancel 1");
}
bool:findSteamID( const String:id[] ) {
for ( new i = 0; i < 32; i++ ) {
if ( StrEqual( id, steamID[i] ) ) {
steamID[i][0] = 0;
return ( steamIDExpire[i] >= GetGameTime() );
}
}
return false;
}
public Action:CommandAddSteamID( client, args ) {
if ( client != 0 ) {
LogMessage( "Client %d is not permitted to add users to the whitelist.", client );
return Plugin_Stop;
}
decl String:id[20];
GetCmdArgString( id, sizeof( id ) );
findSteamID( id );
if ( !tickStarted ) {
CreateFakeClient( "PubComp" ); // Will be auto-kicked; we need this to start the server ticking.
tickStarted = true;
}
for ( new i = 0; i < 32; i++ ) {
if ( steamID[i][0] == 0 || steamIDExpire[i] < GetGameTime() ) {
strcopy( steamID[i], 20, id );
steamIDExpire[i] = GetGameTime() + 300.0; // 5 minutes to join
LogMessage( "Added %s to the whitelist.", id );
return Plugin_Handled;
}
}
LogMessage( "Failed to add %s to the whitelist. Whitelist is full.", id );
return Plugin_Handled;
}
public OnClientAuthorized( client, const String:auth[] ) {
// Don't kick the SourceTV bot or the replay bot.
if ( StrEqual( auth, "BOT" ) ) {
decl String:botName[MAX_NAME_LENGTH];
GetClientName( client, botName, MAX_NAME_LENGTH );
decl String:sourceTV[MAX_NAME_LENGTH];
new Handle:_sourceTV = FindConVar( "tv_name" );
GetConVarString( _sourceTV, sourceTV, MAX_NAME_LENGTH );
CloseHandle( _sourceTV );
if ( StrEqual( botName, "replay" ) || StrEqual( botName, sourceTV ) )
return;
}
new bool:foundSteamID = findSteamID( auth );
if ( !foundSteamID ) {
KickClient( client, "Please join from the PubComp web interface" );
}
}
public OnClientDisconnect_Post( client ) {
if ( !pubCompBotKicked ) {
pubCompBotKicked = true;
return;
}
}
public OnClientPutInServer( client ) {
decl String:map[PLATFORM_MAX_PATH];
GetCurrentMap( map, PLATFORM_MAX_PATH );
if ( StrEqual( map, "mge_training_v7" ) ) {
FakeClientCommand( client, "say /first" );
}
}
// These functions allow the rcon user to add settings that will take
// effect when the actual match begins.
// Wipe out all previously added commands.
public Action:CommandResetGameCommands( client, args ) {
if ( client != 0 ) {
LogMessage( "Client %d is not permitted to change PubComp game settings.", client );
return Plugin_Stop;
}
for ( new i = 0; i < commandCount; i++ ) {
gameCommands[i][0] = 0;
}
commandCount = 0;
return Plugin_Handled;
}
// Add a command to be executed when the match begins.
public Action:CommandAddGameCommand( client, args ) {
if ( client != 0 ) {
LogMessage( "Client %d is not permitted to change PubComp game settings.", client );
return Plugin_Stop;
}
decl String:command[MAX_COMMAND_LENGTH];
GetCmdArgString( command, sizeof( command ) );
if ( commandCount + 1 == MAX_COMMANDS ) {
LogMessage( "Failed to add command \"%s\" to buffer; Command list is full.", command );
return Plugin_Stop;
}
strcopy( gameCommands[commandCount], MAX_COMMAND_LENGTH, command );
commandCount++;
return Plugin_Handled;
}
// Internal function that will execute the commands when the match begins.
public ExecuteGameCommands() {
for ( new i = 0; i < commandCount; i++ ) {
ServerCommand(gameCommands[i]);
}
commandCount = 0;
}
// These functions and globals are for setting, activating and
// deactivating the desired pre-game/pause warmup mode.
#define NUM_WARMUP_MODES 2
#define ENABLE 0
#define DISABLE 1
new String:warmupModes[NUM_WARMUP_MODES + 1][16] = {"NONE", "SOAP", "MGE"};
new activeWarmupMode;
new String:warmupActivationCommands[NUM_WARMUP_MODES + 1][2][MAX_COMMAND_LENGTH] = {
{"", ""},
{"sm plugins load soap_tf2dm", "sm plugins unload soap_tf2dm"},
{"sm plugins load mgemod", "sm plugins unload mgemod"}
};
public Action:CommandSetWarmupMod( client, args ) {
if ( client != 0 ) {
LogMessage( "Client %d is not permitted to change the warmup mod.", client );
return Plugin_Stop;
}
decl String:modeName[20];
GetCmdArgString( modeName, sizeof( modeName ) );
activeWarmupMode = -1;
for (new i = 0; i < NUM_WARMUP_MODES + 1; i++) {
if (strcmp(modeName, warmupModes[i]) == 0) {
activeWarmupMode = i;
}
ServerCommand(warmupActivationCommands[i][1]);
}
if (activeWarmupMode == -1) {
LogMessage("Could not find warmup mode \"%s\".", modeName);
return Plugin_Stop;
}
ServerCommand(warmupActivationCommands[activeWarmupMode][0]);
return Plugin_Handled;
}
// Track player ready states and start a game when we have enough
// ready players.
new bool:playerReady[MAXPLAYERS+1];
new playersNeeded = 1;
new Handle:gameCountdown = INVALID_HANDLE;
public Action:ReadyUnready(client, args) {
decl String:text[192];
GetCmdArg(1, text, sizeof(text));
if (strcmp(text, ".ready") == 0 || strcmp(text, ".gaben") == 0) {
playerReady[client] = true;
decl String:playerName[32];
GetClientName(client, playerName, sizeof(playerName));
PrintToChatAll("Player %s is now ready.", playerName);
}
if (strcmp(text, ".notready") == 0 || strcmp(text, ".unready") == 0) {
playerReady[client] = false;
decl String:playerName[32];
GetClientName(client, playerName, sizeof(playerName));
PrintToChatAll("Player %s is no longer ready.", playerName);
}
new readyCount = 0;
for (new i = 0; i < MAXPLAYERS+1; i++) {
readyCount += playerReady[i] ? 1 : 0;
}
if (readyCount == playersNeeded) {
gameCountdown = CreateTimer(float(GAME_START_DELAY), Timer:PubCompStartGame);
new seconds = GAME_START_DELAY % 60;
new minutes = GAME_START_DELAY / 60;
PrintToChatAll("%d players are now ready.", readyCount);
if (minutes == 0) {
PrintToChatAll("Game Starts in %d seconds.", seconds);
} else if (seconds == 0) {
PrintToChatAll("Game Starts in %d minutes.", minutes);
} else {
PrintToChatAll("Game Starts in %d minutes and %d seconds.", minutes, seconds);
}
} else if (gameCountdown != INVALID_HANDLE) {
KillTimer(gameCountdown);
gameCountdown = INVALID_HANDLE;
PrintToChatAll("Down to %d ready player%s. Countdown canceled.", readyCount, readyCount == 1 ? "" : "s");
} else {
}
return Plugin_Continue;
}
public Timer:PubCompStartGame(Handle:data) {
// Tell node we're starting a game here. Node should already
// have the steamids of the players in the game, and their map
// and position preferences will be entered through the web,
// so it will have those as well. So we don't have to send
// anything except a message that we're starting the game.
//
// It should send us (through rcon console commands) team
// assignments and position assignments.
LogMessage( "PubComp: Requesting team and position assignments..." );
ServerCommand("mp_tournament 0");
ServerCommand(warmupActivationCommands[activeWarmupMode][DISABLE]);
// TODO: Put players on their respective teams and alert them
// that they are now on that team.
ServerCommand("mp_restartgame 1");
CreateTimer(1.0, Timer:PubCompStartGame2);
}
public Timer:PubCompStartGame2(Handle:data) {
PrintCenterTextAll("Setup Classes. Game will start in %d seconds.", SETUP_CLASSES_TIME);
LogToGame("Setup Classes. Game will start in %d seconds.", SETUP_CLASSES_TIME);
// TODO: Inform players of the classes they drew and engage
// the class limit freezer.
ServerCommand("mp_restartgame %d", SETUP_CLASSES_TIME);
CreateTimer(float(SETUP_CLASSES_TIME + 1), Timer:PubCompStartGame3);
}
public Timer:PubCompStartGame3(Handle:data) {
ExecuteGameCommands();
PrintCenterTextAll("----Game is LIVE----");
}
public Action:CommandStartItemVote( client, args ) {
if ( client != 0 ) {
LogMessage( "Client %d is not permitted to start an item vote.", client );
return Plugin_Stop;
}
new Handle:vote = StartMessageAll( "VoteStart", USERMSG_RELIABLE );
BfWriteByte( vote, 255 ); // Send to both teams
BfWriteByte( vote, 0 ); // Comes from world
BfWriteString( vote, "PubComp: What items should be allowed during this match?" ); // Vote description
BfWriteString( vote, "" ); // We're not translating on the client side, so this is blank
BfWriteBool( vote, false ); // This is not a yes/no vote
EndMessage();
vote = StartMessageAll( "vote_options", USERMSG_RELIABLE );
BfWriteByte( vote, 4 ); // 4 options
BfWriteString( vote, "Vanilla" ); // No unlockable weapons
BfWriteString( vote, "Cinnamon" ); // WTF IS THIS
BfWriteString( vote, "Lax" ); // ???
BfWriteString( vote, "Everything" ); // No restrictions
EndMessage();
return Plugin_Handled;
}