Skip to content

Commit 27b2de9

Browse files
authored
feat(*): get rid of SteamWorks dependency (#19)
1 parent 8a6c55b commit 27b2de9

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

.github/workflows/build-and-test.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ jobs:
3030
wget "https://forums.alliedmods.net/attachment.php?attachmentid=188744&d=1618607414" -O system2.zip
3131
unzip -o system2.zip -d addons/sourcemod/
3232
33-
wget "https://github.com/KyleSanderson/SteamWorks/releases/download/1.2.3c/package-lin.tgz" -O steamworks.tgz
34-
tar -xf steamworks.tgz --strip-components=1
35-
3633
- name: Compile
3734
run: |
3835
spcomp \

Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ FROM melkortf/tf2-sourcemod:latest
22

33
RUN wget "https://forums.alliedmods.net/attachment.php?attachmentid=188744&d=1618607414" -O system2.zip \
44
&& unzip -o system2.zip -d "${SERVER_DIR}/tf/addons/sourcemod/" \
5-
&& rm -f system2.zip \
6-
&& wget "https://github.com/KyleSanderson/SteamWorks/releases/download/1.2.3c/package-lin.tgz" -O steamworks.tgz \
7-
&& tar -xf steamworks.tgz --strip-components=1 -C "${SERVER_DIR}/tf/" \
8-
&& rm -f steamworks.tgz
5+
&& rm -f system2.zip
96

107
COPY connector.smx "$SERVER_DIR/tf/addons/sourcemod/plugins/connector.smx"

scripting/connector.sp

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#include <sourcemod>
22
#include <system2>
3-
#include <SteamWorks>
43

54
#define PLUGIN_VERSION "0.4.1"
5+
#define PUBLIC_IP_API_ADDRESS "https://api.ipify.org"
66

77
ConVar tf2pickupOrgApiAddress = null;
88
ConVar tf2pickupOrgSecret = null;
99
ConVar tf2pickupOrgPriority = null;
1010
ConVar tf2pickupOrgOverrideInternalAddress = null;
1111
Handle timer = null;
12+
char publicIpAddress[64];
1213

1314
public Plugin myinfo =
1415
{
@@ -33,13 +34,39 @@ public void OnPluginStart()
3334
tf2pickupOrgOverrideInternalAddress.AddChangeHook(OnApiAddressOrSecretChange);
3435

3536
RegServerCmd("sm_tf2pickuporg_heartbeat", CommandHeartbeat);
37+
ResolvePublicIpAddress();
3638
}
3739

3840
public void OnPluginEnd()
3941
{
4042

4143
}
4244

45+
public void ResolvePublicIpAddress()
46+
{
47+
System2HTTPRequest request = new System2HTTPRequest(PublicIpCallback, PUBLIC_IP_API_ADDRESS);
48+
request.SetUserAgent("tf2pickup.org connector plugin/%s", PLUGIN_VERSION);
49+
request.GET();
50+
delete request;
51+
52+
PrintToServer("Querying https://api.ipify.org...");
53+
}
54+
55+
public void PublicIpCallback(bool success, const char[] error, System2HTTPRequest request, System2HTTPResponse response, HTTPRequestMethod method)
56+
{
57+
if (!success) {
58+
char url[128];
59+
request.GetURL(url, sizeof(url));
60+
PrintToServer("ERROR: %s failed: %s", url, error);
61+
return;
62+
}
63+
64+
publicIpAddress[0] = '\0';
65+
response.GetContent(publicIpAddress, sizeof(publicIpAddress));
66+
TrimString(publicIpAddress);
67+
PrintToServer("Gameserver public IP address: %s", publicIpAddress);
68+
}
69+
4370
public void OnApiAddressOrSecretChange(ConVar convar, char[] oldValue, char[] newValue)
4471
{
4572
if (timer != null) {
@@ -65,6 +92,11 @@ public Action CommandHeartbeat(int args)
6592

6693
public Action HeartbeatGameServer(Handle timerHandle)
6794
{
95+
if (strlen(publicIpAddress) == 0) {
96+
PrintToServer("Gameserver public IP address unknown; heartbeat impossible");
97+
return Plugin_Stop;
98+
}
99+
68100
char apiAddress[128];
69101
tf2pickupOrgApiAddress.GetString(apiAddress, sizeof(apiAddress));
70102

@@ -79,12 +111,8 @@ public Action HeartbeatGameServer(Handle timerHandle)
79111
request.SetHeader("Authorization", "secret %s", secret);
80112
request.SetHeader("Content-Type", "application/x-www-form-urlencoded");
81113

82-
int ipAddr[4];
83-
SteamWorks_GetPublicIP(ipAddr);
84-
85114
char address[64];
86-
Format(address, sizeof(address), "%d.%d.%d.%d", ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3]);
87-
System2_URLEncode(address, sizeof(address), address);
115+
System2_URLEncode(address, sizeof(address), publicIpAddress);
88116

89117
char port[6];
90118
GetConVarString(FindConVar("hostport"), port, sizeof(port));

0 commit comments

Comments
 (0)