Skip to content

Commit

Permalink
feat(*): add sm_tf2pickuporg_override_internal_address cvar (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc authored Nov 6, 2021
1 parent f49fc83 commit cca2e39
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion scripting/connector.sp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ConVar tf2pickupOrgApiAddress = null;
ConVar tf2pickupOrgSecret = null;
ConVar tf2pickupOrgVoiceChannelName = null;
ConVar tf2pickupOrgPriority = null;
ConVar tf2pickupOrgOverrideInternalAddress = null;
Handle timer = null;

public Plugin myinfo =
Expand All @@ -30,6 +31,9 @@ public void OnPluginStart()
tf2pickupOrgVoiceChannelName = CreateConVar("sm_tf2pickuporg_voice_channel_name", "", "gameserver voice channel name");
tf2pickupOrgPriority = CreateConVar("sm_tf2pickuporg_priority", "1", "gameserver priority", _, true, -9999.99, true, 9999.99);

tf2pickupOrgOverrideInternalAddress = CreateConVar("sm_tf2pickuporg_override_internal_address", "", "override internal game server address");
tf2pickupOrgOverrideInternalAddress.AddChangeHook(OnApiAddressOrSecretChange);

RegServerCmd("sm_tf2pickuporg_heartbeat", CommandHeartbeat);
}

Expand Down Expand Up @@ -100,8 +104,20 @@ public Action HeartbeatGameServer(Handle timerHandle)
System2HTTPRequest request = new System2HTTPRequest(HeartbeatHttpCallback, "%s/game-servers/", apiAddress);
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&voiceChannelName=%s&priority=%d",

char data[256];
Format(data, sizeof(data), "address=%s&port=%s&name=%s&rconPassword=%s&voiceChannelName=%s&priority=%d",
address, port, name, rconPassword, voiceChannelName, priority);

char overrideInternalAddress[64];
tf2pickupOrgOverrideInternalAddress.GetString(overrideInternalAddress, sizeof(overrideInternalAddress));

if (!StrEqual(overrideInternalAddress, "")) {
System2_URLEncode(overrideInternalAddress, sizeof(overrideInternalAddress), overrideInternalAddress);
Format(data, sizeof(data), "%s&internalIpAddress=%s", data, overrideInternalAddress);
}

request.SetData("%s", data);
request.SetUserAgent("tf2pickup.org connector plugin/%s", PLUGIN_VERSION);
request.POST();
delete request;
Expand Down

0 comments on commit cca2e39

Please sign in to comment.