Skip to content

Commit

Permalink
Add initial version of delay connect plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
thesupremecommander committed Sep 19, 2015
1 parent 8317ce5 commit 9cbf427
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
23 changes: 23 additions & 0 deletions configs/delayconnect.cfg
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
}
}
125 changes: 125 additions & 0 deletions scripting/delayconnect.sp
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();
}

0 comments on commit 9cbf427

Please sign in to comment.