Skip to content

Commit

Permalink
Update l4d2_localhost.sp and shared_cvars.cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
altair-sossai committed Oct 29, 2024
1 parent 634ebd5 commit 0d72025
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
Binary file modified addons/sourcemod/plugins/optional/l4d2_localhost.smx
Binary file not shown.
38 changes: 36 additions & 2 deletions addons/sourcemod/scripting/l4d2_localhost.sp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#pragma newdecls required

#include <sourcemod>
#include <ripext>

public Plugin myinfo =
{
Expand All @@ -12,11 +13,14 @@ public Plugin myinfo =
url = "https://github.com/altair-sossai/l4d2-zone-server"
};

ConVar hLocalhostUrl;
ConVar
hLocalhostUrl,
hLocalhostType;

public void OnPluginStart()
{
hLocalhostUrl = CreateConVar("localhost_url", "", "URL used to perform local tests", FCVAR_PROTECTED);
hLocalhostType = CreateConVar("localhost_type", "url", "Type of content to be displayed, url|text", FCVAR_PROTECTED);

RegConsoleCmd("sm_localhost", LocalHostCmd);
}
Expand All @@ -26,6 +30,36 @@ Action LocalHostCmd(int client, int args)
char localHostUrl[100];
GetConVarString(hLocalhostUrl, localHostUrl, sizeof(localHostUrl));

ShowMOTDPanel(client, "localhost", localHostUrl, MOTDPANEL_TYPE_URL);
char localHostType[10];
GetConVarString(hLocalhostType, localHostType, sizeof(localHostType));

if (StrEqual(localHostType, "url"))
{
ShowMOTDPanel(client, "localhost", localHostUrl, MOTDPANEL_TYPE_URL);
return Plugin_Handled;
}

if (StrEqual(localHostType, "text"))
{
HTTPRequest request = new HTTPRequest(localHostUrl);

request.Get(LocalHostResponse, client);

return Plugin_Handled;
}

return Plugin_Handled;
}

void LocalHostResponse(HTTPResponse httpResponse, any client)
{
if (httpResponse.Status != HTTPStatus_OK)
return;

JSONObject response = view_as<JSONObject>(httpResponse.Data);

char content[40000];
response.GetString("content", content, sizeof(content));

ShowMOTDPanel(client, "localhost", content, MOTDPANEL_TYPE_TEXT);
}
1 change: 1 addition & 0 deletions cfg/cfgogl/zonemod/shared_cvars.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ confogl_addcvar patent_icon_max_level 15

// [l4d2_localhost.smx]
confogl_addcvar localhost_url "http://localhost:5000"
confogl_addcvar localhost_type "url"

// Stripper Path
confogl_addcvar stripper_cfg_path cfg/stripper/zonemod

0 comments on commit 0d72025

Please sign in to comment.