Skip to content

Commit

Permalink
Migrate fully to electron-store and seperate filtering settings acros…
Browse files Browse the repository at this point in the history
…s versions
  • Loading branch information
Heath123 committed Dec 24, 2020
1 parent fe2a7d8 commit cfe3c7a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 28 deletions.
14 changes: 14 additions & 0 deletions html/mainPage/js/defaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"^bedrock-proxypass-json$": {
"hiddenPackets": {
"serverbound": ["move_player", "player_action", "level_sound_event"],
"clientbound": ["level_chunk", "update_block", "network_chunk_publisher_update", "set_entity_motion", "move_entity_absolute", "set_entity_data", "level_sound_event"]
}
},
"^java-node-minecraft-protocol-.*$": {
"hiddenPackets": {
"serverbound": ["position", "position_look", "look", "keep_alive", "entity_action"],
"clientbound": ["keep_alive", "update_time", "rel_entity_move", "entity_teleport", "map_chunk", "update_light", "update_view_position", "entity_metadata", "entity_update_attributes", "unload_chunk", "entity_velocity", "entity_move_look", "entity_head_rotation"]
}
}
}
73 changes: 47 additions & 26 deletions html/mainPage/js/main.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
/* global Split, jsonTree, escapeHtml, alert, CodeMirror */

/*
box.onclick = function() {
if (!box.checked) {
return
}
if (window.wasIn) {
window.wasIn = false;
} else {
box.checked = false;
box.indeterminate = true;
window.wasIn = true;
}
}
*/
const Store = require('electron-store');

const store = new Store();

const axios = require('axios')

Expand Down Expand Up @@ -113,15 +102,50 @@ const sharedVars = {
proxyCapabilities: {},
ipcRenderer: require('electron').ipcRenderer,
packetList: document.getElementById('packetlist'),
hiddenPackets: localStorage.getItem('hiddenPackets')
? JSON.parse(localStorage.getItem('hiddenPackets'))
: Object.assign({}, defaultHiddenPackets),
hiddenPackets: undefined,
scripting: undefined,
lastFilter: ''
}

sharedVars.proxyCapabilities = JSON.parse(sharedVars.ipcRenderer.sendSync('proxyCapabilities', ''))

function getVersionSpecificVar(name, defaultValue) {
const versionId = 'version-' + sharedVars.proxyCapabilities.versionId
const settingsObject = store.get(versionId)
if (settingsObject) {
if (!settingsObject[name]) {
settingsObject[name] = JSON.stringify(defaultValue)
store.set(versionId, settingsObject)
}
} else {
store.set(versionId, {
[name]: JSON.stringify(defaultValue)
})
}
return JSON.parse(store.get(versionId)[name])
}

function setVersionSpecificVar(name, value) {
const versionId = 'version-' + sharedVars.proxyCapabilities.versionId
const settingsObject = store.get(versionId)
settingsObject[name] = JSON.stringify(value)
store.set(versionId, settingsObject)
}

const defaultsJson = require('./js/defaults.json')

function findDefault(setting) {
const versionId = sharedVars.proxyCapabilities.versionId
for (const key in defaultsJson) {
const regex = new RegExp(key)
if (versionId.match(regex)) {
return defaultsJson[key][setting]
}
}
}

sharedVars.hiddenPackets = getVersionSpecificVar('hiddenPackets', findDefault('hiddenPackets'))

if (!sharedVars.proxyCapabilities.scriptingSupport) {
document.getElementById('scriptingTab').style.display = 'none'
}
Expand All @@ -147,7 +171,7 @@ sharedVars.ipcHandler.setup(sharedVars)
const filteringPackets = document.getElementById('filtering-packets')

function updateFilteringStorage () {
localStorage.setItem('hiddenPackets', JSON.stringify(sharedVars.hiddenPackets))
setVersionSpecificVar('hiddenPackets', JSON.stringify(sharedVars.hiddenPackets))
}

function updateFilteringTab () {
Expand Down Expand Up @@ -263,7 +287,9 @@ sharedVars.ipcRenderer.on('editAndResend', (event, arg) => { // Context menu
})

function deselectPacket () {
removeOrAddSelection(currentPacket, false)
if (currentPacket) {
removeOrAddSelection(currentPacket, false)
}
currentPacket = undefined
currentPacketType = undefined
sharedVars.packetDom.getTreeElement().firstElementChild.innerHTML = 'No packet selected!'
Expand All @@ -288,13 +314,13 @@ const hexViewer = document.getElementById('hex-viewer')

function removeOrAddSelection (id, add) {
const fakeElement = document.createElement('div')
fakeElement.innerHTML = sharedVars.allPacketsHTML[currentPacket][0]
fakeElement.innerHTML = sharedVars.allPacketsHTML[id][0]
if (add) {
fakeElement.firstChild.classList.add('selected')
} else {
fakeElement.firstChild.classList.remove('selected')
}
sharedVars.allPacketsHTML[currentPacket] = [fakeElement.innerHTML]
sharedVars.allPacketsHTML[id] = [fakeElement.innerHTML]

wrappedClusterizeUpdate(sharedVars.allPacketsHTML)
clusterize.refresh()
Expand All @@ -303,11 +329,6 @@ function removeOrAddSelection (id, add) {
window.packetClick = function (id) { // window. stops standardjs from complaining
// Remove selection background from old selected packet
if (currentPacket) {
/* const previousPacket = document.getElementById('packet' + currentPacket)
// May not be in view
if (previousPacket) {
document.getElementById('packet' + currentPacket).classList.remove('selected')
} */
removeOrAddSelection(currentPacket, false)
}

Expand Down
3 changes: 2 additions & 1 deletion src/proxy/bedrock/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ exports.capabilities = {
scriptingSupport: false,
clientboundPackets: {},
serverboundPackets: {},
wikiVgPage: 'https://wiki.vg/Bedrock_Protocol'
wikiVgPage: 'https://wiki.vg/Bedrock_Protocol',
versionId: 'bedrock-proxypass-json'
}

exports.startProxy = function (host, port, listenPort, version, authConsent, callback, dataFolder) {
Expand Down
7 changes: 6 additions & 1 deletion src/proxy/java/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ exports.capabilities = {
clientboundPackets: [],
serverboundPackets: [],
// TODO: Only for latest, or fetch older pages
wikiVgPage: 'https://wiki.vg/Protocol'
wikiVgPage: 'https://wiki.vg/Protocol',
versionId: undefined
}

exports.startProxy = function (host, port, listenPort, version, authConsent, callback, dataFolder) {
storedCallback = callback

// . cannot be in a JSON property name with electron-store
exports.capabilities.versionId = 'java-node-minecraft-protocol-' + version.split('.').join('-')

const mcdata = require('minecraft-data')(version) // Used to get packets, may remove if I find a better way
toClientMappings = mcdata.protocol.play.toClient.types.packet[1][0].type[1].mappings
toServerMappings = mcdata.protocol.play.toServer.types.packet[1][0].type[1].mappings
Expand Down

0 comments on commit cfe3c7a

Please sign in to comment.