[MIRROR] Fix GLOB Edit button crashing the server (#7548)

Co-authored-by: Heroman3003 <31296024+Heroman3003@users.noreply.github.com>
Co-authored-by: CHOMPStation2 <chompsation2@gmail.com>
This commit is contained in:
CHOMPStation2
2024-01-14 16:08:02 -07:00
committed by GitHub
parent 44eecddb7e
commit 63b26c4ce8
2 changed files with 241 additions and 239 deletions

View File

@@ -36,7 +36,7 @@ GLOBAL_REAL(GLOB, /datum/controller/global_vars)
if(!statclick) if(!statclick)
statclick = new/obj/effect/statclick/debug(null, "Initializing...", src) statclick = new/obj/effect/statclick/debug(null, "Initializing...", src)
stat("GLOB:", "Button Removed Due To Crashing") //VOREStation Edit stat("GLOB:", statclick.update("Edit"))
/datum/controller/global_vars/vv_edit_var(var_name, var_value) /datum/controller/global_vars/vv_edit_var(var_name, var_value)
if(gvars_datum_protected_varlist[var_name]) if(gvars_datum_protected_varlist[var_name])

View File

@@ -15,269 +15,271 @@
if (!islist && !istype(D)) if (!islist && !istype(D))
return return
var/title = "" //VOREStation Edit Start - the rest of this proc in a spawn
var/refid = "\ref[D]" spawn(0)
var/icon/sprite var/title = ""
var/hash var/refid = "\ref[D]"
var/icon/sprite
var/hash
var/type = /list var/type = /list
if (!islist) if (!islist)
type = D.type type = D.type
if(istype(D, /atom)) if(istype(D, /atom))
var/atom/AT = D var/atom/AT = D
if(AT.icon && AT.icon_state) if(AT.icon && AT.icon_state)
sprite = new /icon(AT.icon, AT.icon_state) sprite = new /icon(AT.icon, AT.icon_state)
hash = md5(AT.icon) hash = md5(AT.icon)
hash = md5(hash + AT.icon_state) hash = md5(hash + AT.icon_state)
src << browse_rsc(sprite, "vv[hash].png") src << browse_rsc(sprite, "vv[hash].png")
title = "[D] (\ref[D]) = [type]" title = "[D] (\ref[D]) = [type]"
var/formatted_type = replacetext("[type]", "/", "<wbr>/") var/formatted_type = replacetext("[type]", "/", "<wbr>/")
var/sprite_text var/sprite_text
if(sprite) if(sprite)
sprite_text = "<img src='vv[hash].png'></td><td>" sprite_text = "<img src='vv[hash].png'></td><td>"
var/list/header = islist(D)? list("<b>/list</b>") : D.vv_get_header() var/list/header = islist(D)? list("<b>/list</b>") : D.vv_get_header()
var/marked var/marked
if(holder && holder.marked_datum && holder.marked_datum == D) if(holder && holder.marked_datum && holder.marked_datum == D)
marked = VV_MSG_MARKED marked = VV_MSG_MARKED
var/varedited_line = "" var/varedited_line = ""
if(!islist && (D.datum_flags & DF_VAR_EDITED)) if(!islist && (D.datum_flags & DF_VAR_EDITED))
varedited_line = VV_MSG_EDITED varedited_line = VV_MSG_EDITED
var/deleted_line var/deleted_line
if(!islist && D.gc_destroyed) if(!islist && D.gc_destroyed)
deleted_line = VV_MSG_DELETED deleted_line = VV_MSG_DELETED
var/list/dropdownoptions = list() var/list/dropdownoptions = list()
var/autoconvert_dropdown = FALSE var/autoconvert_dropdown = FALSE
if (islist) if (islist)
dropdownoptions = list( dropdownoptions = list(
"---", "---",
"Add Item" = "?_src_=vars;[HrefToken()];[VV_HK_LIST_ADD]=TRUE;target=[refid]", "Add Item" = "?_src_=vars;[HrefToken()];[VV_HK_LIST_ADD]=TRUE;target=[refid]",
"Remove Nulls" = "?_src_=vars;[HrefToken()];[VV_HK_LIST_ERASE_NULLS]=TRUE;target=[refid]", "Remove Nulls" = "?_src_=vars;[HrefToken()];[VV_HK_LIST_ERASE_NULLS]=TRUE;target=[refid]",
"Remove Dupes" = "?_src_=vars;[HrefToken()];[VV_HK_LIST_ERASE_DUPES]=TRUE;target=[refid]", "Remove Dupes" = "?_src_=vars;[HrefToken()];[VV_HK_LIST_ERASE_DUPES]=TRUE;target=[refid]",
"Set len" = "?_src_=vars;[HrefToken()];[VV_HK_LIST_SET_LENGTH]=TRUE;target=[refid]", "Set len" = "?_src_=vars;[HrefToken()];[VV_HK_LIST_SET_LENGTH]=TRUE;target=[refid]",
"Shuffle" = "?_src_=vars;[HrefToken()];[VV_HK_LIST_SHUFFLE]=TRUE;target=[refid]", "Shuffle" = "?_src_=vars;[HrefToken()];[VV_HK_LIST_SHUFFLE]=TRUE;target=[refid]",
// "Show VV To Player" = "?_src_=vars;[HrefToken()];[VV_HK_EXPOSE]=TRUE;target=[refid]" // TODO - Not yet implemented for lists // "Show VV To Player" = "?_src_=vars;[HrefToken()];[VV_HK_EXPOSE]=TRUE;target=[refid]" // TODO - Not yet implemented for lists
) )
autoconvert_dropdown = TRUE autoconvert_dropdown = TRUE
else else
dropdownoptions = D.vv_get_dropdown() dropdownoptions = D.vv_get_dropdown()
var/list/dropdownoptions_html = list() var/list/dropdownoptions_html = list()
if(autoconvert_dropdown) if(autoconvert_dropdown)
for (var/name in dropdownoptions) for (var/name in dropdownoptions)
var/link = dropdownoptions[name] var/link = dropdownoptions[name]
if (link) if (link)
dropdownoptions_html += "<option value='[link]'>[name]</option>" dropdownoptions_html += "<option value='[link]'>[name]</option>"
else else
dropdownoptions_html += "<option value>[name]</option>" dropdownoptions_html += "<option value>[name]</option>"
else else
dropdownoptions_html = dropdownoptions + D.get_view_variables_options() dropdownoptions_html = dropdownoptions + D.get_view_variables_options()
var/list/names = list() var/list/names = list()
if (!islist) if (!islist)
names = D.get_variables() names = D.get_variables()
sleep(1)//For some reason, without this sleep, VVing will cause client to disconnect on certain objects. //sleep(1)//For some reason, without this sleep, VVing will cause client to disconnect on certain objects. //VOREStation edit - commented out, replaced with spawn(0) above
var/list/variable_html = list() var/list/variable_html = list()
if (islist) if (islist)
var/list/L = D var/list/L = D
for (var/i in 1 to L.len) for (var/i in 1 to L.len)
var/key = L[i] var/key = L[i]
var/value var/value
if (IS_NORMAL_LIST(L) && IS_VALID_ASSOC_KEY(key)) if (IS_NORMAL_LIST(L) && IS_VALID_ASSOC_KEY(key))
value = L[key] value = L[key]
variable_html += debug_variable(i, value, 0, D) variable_html += debug_variable(i, value, 0, D)
else else
names = sortList(names) names = sortList(names)
for (var/V in names) for (var/V in names)
if(D.can_vv_get(V)) if(D.can_vv_get(V))
variable_html += D.vv_get_var(V) variable_html += D.vv_get_var(V)
var/html = {" var/html = {"
<html> <html>
<head> <head>
<title>[title]</title> <title>[title]</title>
<style> <style>
body { body {
font-family: Verdana, sans-serif; font-family: Verdana, sans-serif;
font-size: 9pt; font-size: 9pt;
} }
.value { .value {
font-family: "Courier New", monospace; font-family: "Courier New", monospace;
font-size: 8pt; font-size: 8pt;
} }
</style> </style>
</head> </head>
<body onload='selectTextField()' onkeydown='return handle_keydown()' onkeyup='handle_keyup()'> <body onload='selectTextField()' onkeydown='return handle_keydown()' onkeyup='handle_keyup()'>
<script type="text/javascript"> <script type="text/javascript">
// onload // onload
function selectTextField() { function selectTextField() {
var filter_text = document.getElementById('filter'); var filter_text = document.getElementById('filter');
filter_text.focus(); filter_text.focus();
filter_text.select(); filter_text.select();
var lastsearch = getCookie("[refid][cookieoffset]search"); var lastsearch = getCookie("[refid][cookieoffset]search");
if (lastsearch) { if (lastsearch) {
filter_text.value = lastsearch; filter_text.value = lastsearch;
updateSearch();
}
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca\[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(name)==0) return c.substring(name.length,c.length);
}
return "";
}
// main search functionality
var last_filter = "";
function updateSearch() {
var filter = document.getElementById('filter').value.toLowerCase();
var vars_ol = document.getElementById("vars");
if (filter === last_filter) {
// An event triggered an update but nothing has changed.
return;
} else if (filter.indexOf(last_filter) === 0) {
// The new filter starts with the old filter, fast path by removing only.
var children = vars_ol.childNodes;
for (var i = children.length - 1; i >= 0; --i) {
try {
var li = children\[i];
if (li.innerText.toLowerCase().indexOf(filter) == -1) {
vars_ol.removeChild(li);
}
} catch(err) {}
}
} else {
// Remove everything and put back what matches.
while (vars_ol.hasChildNodes()) {
vars_ol.removeChild(vars_ol.lastChild);
}
for (var i = 0; i < complete_list.length; ++i) {
try {
var li = complete_list\[i];
if (!filter || li.innerText.toLowerCase().indexOf(filter) != -1) {
vars_ol.appendChild(li);
}
} catch(err) {}
}
}
last_filter = filter;
document.cookie="[refid][cookieoffset]search="+encodeURIComponent(filter);
}
// onkeydown
function handle_keydown() {
if(event.keyCode == 116) { //F5 (to refresh properly)
document.getElementById("refresh_link").click();
event.preventDefault ? event.preventDefault() : (event.returnValue = false);
return false;
}
return true;
}
// onkeyup
function handle_keyup() {
updateSearch(); updateSearch();
} }
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca\[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(name)==0) return c.substring(name.length,c.length);
}
return "";
}
// main search functionality // onchange
var last_filter = ""; function handle_dropdown(list) {
function updateSearch() { var value = list.options\[list.selectedIndex].value;
var filter = document.getElementById('filter').value.toLowerCase(); if (value !== "") {
var vars_ol = document.getElementById("vars"); location.href = value;
if (filter === last_filter) {
// An event triggered an update but nothing has changed.
return;
} else if (filter.indexOf(last_filter) === 0) {
// The new filter starts with the old filter, fast path by removing only.
var children = vars_ol.childNodes;
for (var i = children.length - 1; i >= 0; --i) {
try {
var li = children\[i];
if (li.innerText.toLowerCase().indexOf(filter) == -1) {
vars_ol.removeChild(li);
}
} catch(err) {}
}
} else {
// Remove everything and put back what matches.
while (vars_ol.hasChildNodes()) {
vars_ol.removeChild(vars_ol.lastChild);
}
for (var i = 0; i < complete_list.length; ++i) {
try {
var li = complete_list\[i];
if (!filter || li.innerText.toLowerCase().indexOf(filter) != -1) {
vars_ol.appendChild(li);
}
} catch(err) {}
} }
list.selectedIndex = 0;
document.getElementById('filter').focus();
} }
last_filter = filter; // byjax
document.cookie="[refid][cookieoffset]search="+encodeURIComponent(filter); function replace_span(what) {
var idx = what.indexOf(':');
} document.getElementById(what.substr(0, idx)).innerHTML = what.substr(idx + 1);
// onkeydown
function handle_keydown() {
if(event.keyCode == 116) { //F5 (to refresh properly)
document.getElementById("refresh_link").click();
event.preventDefault ? event.preventDefault() : (event.returnValue = false);
return false;
} }
return true; </script>
} <div align='center'>
<table width='100%'>
// onkeyup <tr>
function handle_keyup() { <td width='50%'>
updateSearch(); <table align='center' width='100%'>
} <tr>
<td>
// onchange [sprite_text]
function handle_dropdown(list) { <div align='center'>
var value = list.options\[list.selectedIndex].value; [header.Join()]
if (value !== "") { </div>
location.href = value; </td>
} </tr>
list.selectedIndex = 0; </table>
document.getElementById('filter').focus(); <div align='center'>
} <b><font size='1'>[formatted_type]</font></b>
<span id='marked'>[marked]</span>
// byjax <span id='varedited'>[varedited_line]</span>
function replace_span(what) { <span id='deleted'>[deleted_line]</span>
var idx = what.indexOf(':'); </div>
document.getElementById(what.substr(0, idx)).innerHTML = what.substr(idx + 1); </td>
} <td width='50%'>
</script> <div align='center'>
<div align='center'> <a id='refresh_link' href='?_src_=vars;
datumrefresh=[refid]'>Refresh</a>
<form>
<select name="file" size="1"
onchange="handle_dropdown(this)"
onmouseclick="this.focus()">
<option value selected>Select option</option>
[dropdownoptions_html.Join()]
</select>
</form>
</div>
</td>
</tr>
</table>
</div>
<hr>
<font size='1'>
<b>E</b> - Edit, tries to determine the variable type by itself.<br>
<b>C</b> - Change, asks you for the var type first.<br>
<b>M</b> - Mass modify: changes this variable for all objects of this type.<br>
</font>
<hr>
<table width='100%'> <table width='100%'>
<tr> <tr>
<td width='50%'> <td width='20%'>
<table align='center' width='100%'>
<tr>
<td>
[sprite_text]
<div align='center'>
[header.Join()]
</div>
</td>
</tr>
</table>
<div align='center'> <div align='center'>
<b><font size='1'>[formatted_type]</font></b> <b>Search:</b>
<span id='marked'>[marked]</span>
<span id='varedited'>[varedited_line]</span>
<span id='deleted'>[deleted_line]</span>
</div> </div>
</td> </td>
<td width='50%'> <td width='80%'>
<div align='center'> <input type='text' id='filter' name='filter_text' value='' style='width:100%;'>
<a id='refresh_link' href='?_src_=vars;
datumrefresh=[refid]'>Refresh</a>
<form>
<select name="file" size="1"
onchange="handle_dropdown(this)"
onmouseclick="this.focus()">
<option value selected>Select option</option>
[dropdownoptions_html.Join()]
</select>
</form>
</div>
</td> </td>
</tr> </tr>
</table> </table>
</div> <hr>
<hr> <ol id='vars'>
<font size='1'> [variable_html.Join()]
<b>E</b> - Edit, tries to determine the variable type by itself.<br> </ol>
<b>C</b> - Change, asks you for the var type first.<br> <script type='text/javascript'>
<b>M</b> - Mass modify: changes this variable for all objects of this type.<br> var complete_list = \[\];
</font> var lis = document.getElementById("vars").children;
<hr> for(var i = lis.length; i--;) complete_list\[i\] = lis\[i\];
<table width='100%'> </script>
<tr> </body>
<td width='20%'> </html>
<div align='center'> "}
<b>Search:</b> src << browse(html, "window=variables[refid];size=475x650") //VOREStation edit end
</div>
</td>
<td width='80%'>
<input type='text' id='filter' name='filter_text' value='' style='width:100%;'>
</td>
</tr>
</table>
<hr>
<ol id='vars'>
[variable_html.Join()]
</ol>
<script type='text/javascript'>
var complete_list = \[\];
var lis = document.getElementById("vars").children;
for(var i = lis.length; i--;) complete_list\[i\] = lis\[i\];
</script>
</body>
</html>
"}
src << browse(html, "window=variables[refid];size=475x650")
/client/proc/vv_update_display(datum/D, span, content) /client/proc/vv_update_display(datum/D, span, content)
src << output("[span]:[content]", "variables\ref[D].browser:replace_span") src << output("[span]:[content]", "variables\ref[D].browser:replace_span")