Commit a810ecff authored by LawnCable's avatar LawnCable
Browse files

online list for tmw2

parent f0b4b484
......@@ -31,7 +31,7 @@ const TMW2 = new GameServer(
new socialLink("fab fa-gitlab","Gitlab","https://gitlab.com/TMW2"),
],
"https://tmw2.org/legal",
{parser:OnlineListParser.EXAMPLE_DATA,url:"example"}
{parser:OnlineListParser.JSON_ARRAY,url:"https://tmw2.org/online.json"}
);
const Evol = new GameServer(
......
......@@ -56,6 +56,7 @@ export enum OnlineListParser {
TMW,
TMW2API,
EXAMPLE_DATA,
JSON_ARRAY
};
async function fetchOnlineList(server:GameServer):Promise<string[]>{
......@@ -74,6 +75,8 @@ async function fetchOnlineList(server:GameServer):Promise<string[]>{
];
case OnlineListParser.TMW:
return tmwParser(await request(server.OnlineList.url));
case OnlineListParser.JSON_ARRAY:
return jsonArrayParser(await request(server.OnlineList.url));
default:
throw new Error("Online List Parser is unknown");
}
......@@ -92,6 +95,9 @@ function tmwParser(rawData:string):string[]{
return stringArray;
}
function jsonArrayParser(rawData:string):string[]{
return JSON.parse(rawData);
}
function request(url:string):Promise<string>{
return new Promise((res, rej)=>{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment