Skip to content

Commit

Permalink
feat(*): add heartbeat admin command (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc authored Oct 4, 2021
1 parent 3902191 commit ea0308f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions scripting/connector.sp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Plugin myinfo =
author = "garrappachc",
description = "Connect a TF2 gameserver to your tf2pickup.org instance",
version = PLUGIN_VERSION,
url= "https://github.com/tf2pickup-org"
url = "https://github.com/tf2pickup-org"
}

public void OnPluginStart()
Expand All @@ -24,6 +24,8 @@ public void OnPluginStart()

tf2pickupOrgSecret = CreateConVar("sm_tf2pickuporg_secret", "", "tf2pickup.org gameserver secret");
tf2pickupOrgSecret.AddChangeHook(OnApiAddressOrSecretChange);

RegServerCmd("sm_tf2pickuporg_heartbeat", CommandHeartbeat);
}

public void OnPluginEnd()
Expand All @@ -49,6 +51,11 @@ public void OnApiAddressOrSecretChange(ConVar convar, char[] oldValue, char[] ne
}
}

public Action CommandHeartbeat(int args)
{
return HeartbeatGameServer(null);
}

public Action HeartbeatGameServer(Handle timerHandle)
{
char apiAddress[128];
Expand Down Expand Up @@ -83,7 +90,7 @@ public Action HeartbeatGameServer(Handle timerHandle)
request.SetHeader("Authorization", "secret %s", secret);
request.SetHeader("Content-Type", "application/x-www-form-urlencoded");
request.SetData("address=%s&port=%s&name=%s&rconPassword=%s", address, port, name, rconPassword);
request.SetUserAgent("tf2pickup.org connector plugin %s", PLUGIN_VERSION);
request.SetUserAgent("tf2pickup.org connector plugin/%s", PLUGIN_VERSION);
request.POST();
delete request;

Expand Down

0 comments on commit ea0308f

Please sign in to comment.