Skip to content

Commit

Permalink
Release 0.0.50
Browse files Browse the repository at this point in the history
-Updated mappings
-Added a better way to append server data to JSON commands
-Added SWEX version to JSON commands
  • Loading branch information
Xzandro committed Aug 5, 2022
1 parent 98b6183 commit 88240d6
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 4 deletions.
21 changes: 21 additions & 0 deletions app/mapping.js
Expand Up @@ -1094,6 +1094,27 @@ module.exports = {
25814: 'Madeleine',
25815: 'Deborah',

259: 'Shadowcaster',
25911: 'Minato',
25912: 'Ren',
25913: 'Zen',
25914: 'Shun',
25915: 'Ritsu',

260: 'Hypnomeow',
26011: 'Birman',
26012: 'Manx',
26013: 'Nebelung',
26014: 'Siamese',
26015: 'Bombay',

261: 'Battle Angel',
26111: 'Amber',
26112: 'Claire',
26113: 'Sonia',
26114: 'Veronica',
26115: 'Destiny',

15105: 'Devilmon',
14314: 'Rainbowmon',

Expand Down
47 changes: 46 additions & 1 deletion app/proxy/SWProxy.js
Expand Up @@ -8,6 +8,7 @@ const url = require('url');
const uuidv4 = require('uuid/v4');
const Proxy = require('http-mitm-proxy');
const { differenceInMonths } = require('date-fns');
const storage = require('electron-json-storage');

const { decrypt_request, decrypt_response } = require('./smon_decryptor');

Expand All @@ -24,6 +25,11 @@ class SWProxy extends EventEmitter {
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'];
}
async start(port) {
const self = this;
Expand Down Expand Up @@ -55,6 +61,16 @@ class SWProxy extends EventEmitter {
// 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);
Expand Down Expand Up @@ -100,10 +116,20 @@ class SWProxy extends EventEmitter {

// 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 @@ -224,17 +250,36 @@ class SWProxy extends EventEmitter {
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);
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;
}

removeProperties(data) {
if (!(data instanceof Object)) return data;
Object.keys(data).forEach((property) => {
if (this.sensitiveProperties.includes(property)) {
delete data[property];
} else if (data[property] instanceof Object) {
this.removeProperties(data[property]);
}
});

return data;
}

isRunning() {
if (this.proxy) {
return true;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "sw-exporter",
"productName": "Summoners War Exporter",
"version": "0.0.48",
"version": "0.0.50",
"description": "This tool will parse intercepted data from Summoners War and extract information on the monsters and runes of the user.",
"main": "./app/main.js",
"scripts": {
Expand Down

0 comments on commit 88240d6

Please sign in to comment.