Skip to content

Commit

Permalink
Removed endpoint functionality
Browse files Browse the repository at this point in the history
Removed swex_version from the data payload
  • Loading branch information
Xzandro committed Feb 13, 2024
1 parent 4175c6f commit 616aead
Showing 1 changed file with 0 additions and 76 deletions.
76 changes: 0 additions & 76 deletions app/proxy/SWProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 616aead

Please sign in to comment.