mirror of
https://github.com/ineedbots/t4_bot_warfare.git
synced 2025-04-22 07:55:43 +00:00
Added http
This commit is contained in:
parent
9255703c72
commit
fe6b11f2e8
@ -1,13 +1,50 @@
|
|||||||
|
/*
|
||||||
|
_bot_http
|
||||||
|
Author: INeedGames
|
||||||
|
Date: 12/16/2020
|
||||||
|
The HTTP module
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include maps\mp\bots\_bot_utility;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Will attempt to retreive waypoints from the internet
|
||||||
|
*/
|
||||||
getRemoteWaypoints(mapname)
|
getRemoteWaypoints(mapname)
|
||||||
{
|
{
|
||||||
println("MAP");
|
url = "https://raw.githubusercontent.com/ineedbots/t4m_waypoints/master/" + mapname + "_wp.csv";
|
||||||
}
|
filename = "waypoints/" + mapname + "_wp.csv";
|
||||||
|
|
||||||
getRemoteVersion()
|
println("Attempting to get remote waypoints from " + url);
|
||||||
{
|
res = getLinesFromUrl(url, filename);
|
||||||
println("VERSION");
|
|
||||||
|
if (!res.lines.size)
|
||||||
|
return;
|
||||||
|
|
||||||
|
waypointCount = int(res.lines[0]);
|
||||||
|
|
||||||
|
waypoints = [];
|
||||||
|
println("Loading remote waypoints...");
|
||||||
|
|
||||||
|
for (i = 1; i <= waypointCount; i++)
|
||||||
|
{
|
||||||
|
tokens = tokenizeLine(res.lines[i], ",");
|
||||||
|
|
||||||
|
waypoint = parseTokensIntoWaypoint(tokens);
|
||||||
|
|
||||||
|
waypoints[i-1] = waypoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (waypoints.size)
|
||||||
|
{
|
||||||
|
level.waypoints = waypoints;
|
||||||
|
println("Loaded " + waypoints.size + " waypoints from remote.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Does the version check, if we are up too date
|
||||||
|
*/
|
||||||
doVersionCheck()
|
doVersionCheck()
|
||||||
{
|
{
|
||||||
remoteVersion = getRemoteVersion();
|
remoteVersion = getRemoteVersion();
|
||||||
@ -28,3 +65,49 @@ doVersionCheck()
|
|||||||
println("You are on the latest version of Bot Warfare!");
|
println("You are on the latest version of Bot Warfare!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns the version of bot warfare found on the internet
|
||||||
|
*/
|
||||||
|
getRemoteVersion()
|
||||||
|
{
|
||||||
|
data = httpGet( "https://raw.githubusercontent.com/ineedbots/t4m_waypoints/master/version.txt" );
|
||||||
|
|
||||||
|
if (!isDefined(data))
|
||||||
|
return undefined;
|
||||||
|
|
||||||
|
return strtok(data, "\n")[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns an array of each line from the response of the http url request
|
||||||
|
*/
|
||||||
|
getLinesFromUrl(url, filename)
|
||||||
|
{
|
||||||
|
result = spawnStruct();
|
||||||
|
result.lines = [];
|
||||||
|
|
||||||
|
data = HTTPGet(url);
|
||||||
|
|
||||||
|
if (!isDefined(data))
|
||||||
|
return result;
|
||||||
|
|
||||||
|
line = "";
|
||||||
|
for (i=0;i<data.size;i++)
|
||||||
|
{
|
||||||
|
c = data[i];
|
||||||
|
|
||||||
|
if (c == "\n")
|
||||||
|
{
|
||||||
|
result.lines[result.lines.size] = line;
|
||||||
|
|
||||||
|
line = "";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
line += c;
|
||||||
|
}
|
||||||
|
result.lines[result.lines.size] = line;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user