Skip to content

Commit

Permalink
fix(*): rename apiKey to secret (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc authored Sep 30, 2021
1 parent 762ea02 commit b547fce
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions scripting/connector.sp
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@
#define PLUGIN_VERSION "0.0.1"

ConVar tf2pickupOrgApiAddress = null;
ConVar tf2pickupOrgApiKey = null;
ConVar tf2pickupOrgSecret = null;
Handle timer = null;

public Plugin myinfo =
{
name = "tf2pickup.org connector",
author = "garrappachc",
description = "Connect your TF2 gameserver to your tf2pickup.org instance",
description = "Connect a TF2 gameserver to your tf2pickup.org instance",
version = PLUGIN_VERSION,
url= "https://github.com/tf2pickup-org"
}

public void OnPluginStart()
{
tf2pickupOrgApiAddress = CreateConVar("sm_tf2pickuporg_api_address", "", "tf2pickup.org endpoint address");
tf2pickupOrgApiAddress.AddChangeHook(OnApiAddressOrKeyChange);
tf2pickupOrgApiAddress.AddChangeHook(OnApiAddressOrSecretChange);

tf2pickupOrgApiKey = CreateConVar("sm_tf2pickuporg_api_key", "", "tf2pickup.org API key");
tf2pickupOrgApiKey.AddChangeHook(OnApiAddressOrKeyChange);
tf2pickupOrgSecret = CreateConVar("sm_tf2pickuporg_secret", "", "tf2pickup.org gameserver secret");
tf2pickupOrgSecret.AddChangeHook(OnApiAddressOrSecretChange);
}

public void OnPluginEnd()
{

}

public void OnApiAddressOrKeyChange(ConVar convar, char[] oldValue, char[] newValue)
public void OnApiAddressOrSecretChange(ConVar convar, char[] oldValue, char[] newValue)
{
if (timer != null) {
KillTimer(timer);
Expand All @@ -40,10 +40,10 @@ public void OnApiAddressOrKeyChange(ConVar convar, char[] oldValue, char[] newVa
char endpoint[128];
tf2pickupOrgApiAddress.GetString(endpoint, sizeof(endpoint));

char apiKey[128];
tf2pickupOrgApiKey.GetString(apiKey, sizeof(apiKey));
char secret[128];
tf2pickupOrgSecret.GetString(secret, sizeof(secret));

if (!StrEqual(endpoint, "") && !StrEqual(apiKey, "")) {
if (!StrEqual(endpoint, "") && !StrEqual(secret, "")) {
HeartbeatGameServer(null);
timer = CreateTimer(60.0, HeartbeatGameServer, _, TIMER_REPEAT);
}
Expand All @@ -54,10 +54,10 @@ public Action HeartbeatGameServer(Handle timerHandle)
char apiAddress[128];
tf2pickupOrgApiAddress.GetString(apiAddress, sizeof(apiAddress));

char apiKey[128];
tf2pickupOrgApiKey.GetString(apiKey, sizeof(apiKey));
char secret[128];
tf2pickupOrgSecret.GetString(secret, sizeof(secret));

if (StrEqual(apiAddress, "") || StrEqual(apiKey, "")) {
if (StrEqual(apiAddress, "") || StrEqual(secret, "")) {
return Plugin_Stop;
}

Expand All @@ -80,7 +80,7 @@ public Action HeartbeatGameServer(Handle timerHandle)
System2_URLEncode(rconPassword, sizeof(rconPassword), rconPassword);

System2HTTPRequest request = new System2HTTPRequest(HeartbeatHttpCallback, "%s/game-servers/", apiAddress);
request.SetHeader("Authorization", "api-key %s", apiKey);
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);
Expand Down

0 comments on commit b547fce

Please sign in to comment.