-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial version of delay connect plugin.
- Loading branch information
1 parent
8317ce5
commit 9cbf427
Showing
2 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"DelayConnect" | ||
{ | ||
/** | ||
* Each section here defines a playtime limit. | ||
* | ||
* When checking whether a player has hit their limit, we select the first section that the client matches. | ||
* The following keys in each section define the checks performed (if the client matches any one, the section will be applied): | ||
* "steam" the Steam ID of the player | ||
* "group" a group the player is in (if an admin) | ||
* "flag" a flag the player has (if an admin) | ||
* "default" applies to all players | ||
* | ||
* The following keys define the limits: | ||
* "delay" the amount of time (in seconds) after the most recent disconnect that the player will be denied connect for | ||
*/ | ||
|
||
"default" | ||
{ | ||
"default" 1 | ||
|
||
"delay" 15 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#include <sourcemod> | ||
#include <connect> | ||
|
||
#pragma newdecls required | ||
|
||
public Plugin myinfo = { | ||
name = "Server Delay Connect", | ||
author = "Forward Command Post", | ||
description = "delays when players can connect", | ||
version = "0.1.0", | ||
url = "http://fwdcp.net" | ||
} | ||
|
||
KeyValues config; | ||
int disconnect; | ||
|
||
bool CheckPlayer(const char[] steamID) { | ||
bool result = true; | ||
|
||
if (config.GotoFirstSubKey()) { | ||
AdminId admin = FindAdminByIdentity(AUTHMETHOD_STEAM, steamID); | ||
|
||
ArrayList groups = new ArrayList(1024); | ||
if (admin != INVALID_ADMIN_ID) { | ||
int groupCount = GetAdminGroupCount(admin); | ||
for (int i = 0; i < groupCount; i++) { | ||
char group[1024]; | ||
|
||
GetAdminGroup(admin, i, group, sizeof(group)); | ||
|
||
groups.PushString(group); | ||
} | ||
} | ||
|
||
do { | ||
bool apply = false; | ||
|
||
if (!apply) { | ||
char configSteam[64]; | ||
|
||
config.GetString("steam", configSteam, sizeof(configSteam)); | ||
|
||
if (StrEqual(steamID, configSteam)) { | ||
apply = true; | ||
} | ||
} | ||
|
||
if (!apply && admin != INVALID_ADMIN_ID) { | ||
if (!apply) { | ||
char configGroup[1024]; | ||
|
||
config.GetString("group", configGroup, sizeof(configGroup)); | ||
|
||
if (groups.FindString(configGroup) != -1) { | ||
apply = true; | ||
} | ||
} | ||
|
||
if (!apply) { | ||
char configFlag[1]; | ||
|
||
config.GetString("flag", configFlag, sizeof(configFlag)); | ||
|
||
AdminFlag flag; | ||
if (FindFlagByChar(configFlag[0], flag) && GetAdminFlag(admin, flag)) { | ||
apply = true; | ||
} | ||
} | ||
} | ||
|
||
if (!apply) { | ||
if (config.GetNum("default")) { | ||
apply = true; | ||
} | ||
} | ||
|
||
if (apply) { | ||
int delay = config.GetNum("delay"); | ||
|
||
if (delay > 0 && GetTime() < disconnect + delay) { | ||
result = false; | ||
} | ||
else { | ||
result = true; | ||
} | ||
|
||
break; | ||
} | ||
} | ||
while (config.GotoNextKey()); | ||
} | ||
|
||
config.Rewind(); | ||
|
||
return result; | ||
} | ||
|
||
public bool OnClientPreConnectEx(const char[] name, char password[255], const char[] ip, const char[] steamID, char rejectReason[255]) { | ||
char steam[64]; | ||
|
||
if (Connect_GetAuthId(AuthId_Steam3, steam, sizeof(steam))) { | ||
bool result = CheckPlayer(steam); | ||
|
||
if (!result) { | ||
strcopy(rejectReason, sizeof(rejectReason), "you are not allowed to connect due to an enforced delay"); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public void OnPluginStart() { | ||
config = new KeyValues("DelayConnect"); | ||
char configFile[PLATFORM_MAX_PATH]; | ||
BuildPath(Path_SM, configFile, sizeof(configFile), "configs/delayconnect.cfg"); | ||
config.ImportFromFile(configFile); | ||
|
||
HookEvent("player_disconnect", OnPlayerDisconnect, EventHookMode_PostNoCopy); | ||
} | ||
|
||
public void OnPlayerDisconnect(Event event, const char[] name, bool dontBroadcast) { | ||
disconnect = GetTime(); | ||
} |