Skip to content

Commit

Permalink
Create ConfigValidator.html
Browse files Browse the repository at this point in the history
Just a quick tool for validating configs since there are a load of options now. It will try to eval the config object using roapi.
  • Loading branch information
MrAntares authored Oct 8, 2024
1 parent 8f29715 commit 113ad99
Showing 1 changed file with 174 additions and 0 deletions.
174 changes: 174 additions & 0 deletions tools/config/ConfigValidator.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<!DOCTYPE html>
<html>
<head>
<title>roBrowser Config Validator</title>
<style type="text/css">
pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
.string { color: green; }
.number { color: darkorange; }
.boolean { color: blue; }
.null { color: magenta; }
.key { color: red; }
</style>
<script id="roapi" type="text/javascript" src=""></script>
<script type="text/javascript">


function init(){
fixtab();
document.getElementById("validate").addEventListener("click", loadroapi);
}


function validate(){
let result = "No result";

if(ROBrowser){

let input = document.getElementById("input").value;

if(input){
try{
let obj;
eval('obj = '+input);
result = syntaxHighlight(JSON.stringify(obj, undefined, 4));
result = "[SUCCESS!] Evaluated conf object result:\n\n" + result;
}catch(e){
result = "[ERROR] "+e.name+": "+e.message;
}
} else {
result = "Empty input";
}

} else {
result = "api.js not loaded. Please update the url.";
}

output(result);
}


function syntaxHighlight(json) {
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
//match = match.replaceAll('"', ''); //Replace json key quotes for cleaner look (might confuze ppl and use output as conf, which won't work...)
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
}

function fixtab(){
document.getElementById('input').addEventListener('keydown', function(e) {
if (e.key == 'Tab') {
e.preventDefault();
var start = this.selectionStart;
var end = this.selectionEnd;

// set textarea value to: text before caret + tab + text after caret
this.value = this.value.substring(0, start) +
"\t" + this.value.substring(end);

// put caret at right position again
this.selectionStart =
this.selectionEnd = start + 1;
}
});
}

function loadroapi(){
document.getElementById('roapi')?.remove();
let script = document.createElement('script');
script.id = "roapi";
script.src = document.getElementById('roapiurl').value;
script.addEventListener('load', validate);
script.addEventListener('error', function(){ output("[ERROR] Can't load api.js"); });
document.getElementsByTagName('head')[0].appendChild(script);
}

function output(text){
document.getElementById("output").innerHTML = text;
}

window.addEventListener("load", init);
</script>
</head>

<body>
<table>
<tr>
<td>Api.js url:</td>
<td>
<input id="roapiurl" type="text" value="/api.js"/>
</td>
</tr>
<tr>
<td>RoConf:</td>
<td>
<textarea id="input" rows="36" cols="75">
{
target: document.getElementById("robrowser"),
type: ROBrowser.TYPE.FRAME,
application: ROBrowser.APP.ONLINE,
version: 20241008,
packetDump: false,

//Remote client for main menu data
remoteClient: 'https://grf.robrowser.com/',

servers: [
{
display: 'roBrowser Demo Server',
desc: 'roBrowser\'s demo server',
address: 'connect.robrowser.com',
port: 6900,
version: 25,
langtype: 12,
packetver: 20130618,
renewal: false,
worldMapSettings: { episode: 12 },
packetKeys: false,
socketProxy: 'wss://connect.robrowser.com',
remoteClient: 'https://grf.robrowser.com/',
adminList: [2000000]
},
// ADD OTHER SERVERS HERE
],

development: true,
ThirdPersonCamera: true,
FirstPersonCamera: true,
CameraMaxZoomOut: 50
};

</textarea>
</td>
</tr>
<tr>
<td colspan="2">
<button id="validate">Validate</button>
</td>
</tr>

<tr>
<td>Output:</td>
<td>
<pre id="output"></pre>
</td>
</tr>
</table>
<br/>
<div id="robrowser">TestTagetDiv</div>

</body>
</html>

0 comments on commit 113ad99

Please sign in to comment.