diff options
author | LawnCable <lawncable.tmw2@simonlaux.de> | 2018-06-30 19:37:08 +0200 |
---|---|---|
committer | LawnCable <lawncable.tmw2@simonlaux.de> | 2018-06-30 19:37:08 +0200 |
commit | a810ecff525f6cf49381c47c1072b2799bc0b7d5 (patch) | |
tree | 84bdf9cffae9edf712afe876662593d23af34ef6 | |
parent | f0b4b484b13371fe842966ee7ad687f39011d1ab (diff) | |
download | electron-onlineCount.tar.gz electron-onlineCount.tar.bz2 electron-onlineCount.tar.xz electron-onlineCount.zip |
online list for tmw2onlineCount
-rw-r--r-- | src/renderer/gameserver/data.ts | 2 | ||||
-rw-r--r-- | src/renderer/gameserver/onlineCount.ts | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/renderer/gameserver/data.ts b/src/renderer/gameserver/data.ts index a55b745..eb0f74f 100644 --- a/src/renderer/gameserver/data.ts +++ b/src/renderer/gameserver/data.ts @@ -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( diff --git a/src/renderer/gameserver/onlineCount.ts b/src/renderer/gameserver/onlineCount.ts index d78fa96..cfde7e5 100644 --- a/src/renderer/gameserver/onlineCount.ts +++ b/src/renderer/gameserver/onlineCount.ts @@ -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)=>{ |