diff --git a/app/proxy/SWProxy.js b/app/proxy/SWProxy.js index 2a9c91e..1c0cda3 100644 --- a/app/proxy/SWProxy.js +++ b/app/proxy/SWProxy.js @@ -28,9 +28,6 @@ class SWProxy extends EventEmitter { this.proxy = null; this.logEntries = []; this.addresses = []; - this.endpoints = new Map(); - const restoredEndpoints = storage.getSync('Endpoints'); - this.restoredEndpoints = Object.keys(restoredEndpoints).length > 0 ? new Map(restoredEndpoints) : new Map(); this.sensitiveCommands = ['BattleRTPvPStart', 'getRtpvpReplayData']; this.sensitiveProperties = ['runes', 'artifacts', 'skills', 'replay_data']; @@ -79,43 +76,6 @@ class SWProxy extends EventEmitter { }); this.proxy.onRequest(function (ctx, callback) { - const locationEndpoint = '/api/location_c2.php'; - if (locationEndpoint.includes(ctx.clientToProxyRequest.url)) { - ctx.use(Proxy.gunzip); - ctx.SWResponseChunksLocation = []; - - ctx.onResponseData(function (ctx, chunk, callback) { - ctx.SWResponseChunksLocation.push(chunk); - return callback(null, chunk); - }); - - ctx.onResponseEnd(function (ctx, callback) { - let respData; - - try { - respData = decrypt_response(Buffer.concat(ctx.SWResponseChunksLocation).toString()); - // map the server endpoints by their gateway subdomain - if (respData.server_url_list) { - self.mapEndpoints(respData.server_url_list); - self.log({ - type: 'debug', - source: 'proxy', - message: `Mapping server gateways: ${JSON.stringify( - [...self.endpoints].reduce((acc, val) => { - acc[val[0]] = val[1]; - return acc; - }, {}) - )}`, - }); - } - } catch (e) { - console.log(e); - return callback(); - } - return callback(); - }); - } - if (ctx.clientToProxyRequest.url.includes('/api/gateway_c2.php')) { ctx.use(Proxy.gunzip); ctx.SWRequestChunks = []; @@ -147,25 +107,9 @@ class SWProxy extends EventEmitter { self.clearLogs(); } - // get endpoiont and server info - const endpoint = self.getEndpointInfo(ctx.clientToProxyRequest.socket.servername); - // populate req and resp with the server data if available try { respData = self.checkSensitiveCommands(respData); - if (endpoint) { - self.log({ - type: 'debug', - source: 'proxy', - message: `Endpoint found for ${ctx.clientToProxyRequest.socket.servername}. Event: ${command} ID: ${endpoint.server_id} Endpoint: ${endpoint.server_endpoint}`, - }); - reqData = { ...reqData, ...endpoint }; - respData = { ...respData, ...endpoint }; - } else { - self.log({ type: 'debug', source: 'proxy', message: `No Endpoint found for ${ctx.clientToProxyRequest.socket.servername}` }); - } - reqData = { ...reqData, swex_version: app.getVersion() }; - respData = { ...respData, swex_version: app.getVersion() }; } catch (error) { // in some cases this might actually would not work if the data is not JSON // thats why we need to catch it @@ -324,26 +268,6 @@ class SWProxy extends EventEmitter { await this.copyCertToPublic(); } - mapEndpoints(serverList) { - serverList.forEach((endpoint) => { - const parsedGateway = url.parse(endpoint.gateway); - if (parsedGateway.host) { - this.endpoints.set(parsedGateway.host.split('.').shift(), endpoint); - } - }); - - storage.set('Endpoints', Array.from(this.endpoints.entries())); - } - - getEndpointInfo(serverName) { - if (!serverName) { - return null; - } - const parsedserverName = serverName.split('.').shift(); - const endpoint = this.endpoints.get(parsedserverName) || this.restoredEndpoints.get(parsedserverName); - return endpoint ? { server_id: endpoint.server_id, server_endpoint: parsedserverName } : null; - } - checkSensitiveCommands(respData) { return respData.command && this.sensitiveCommands.includes(respData.command) ? this.removeProperties(respData) : respData; }