Fixed bugs with new Netscript commands

This commit is contained in:
Daniel Xie 2017-06-06 23:09:53 -05:00
parent 77e6bdbfdc
commit f92556e754
5 changed files with 27 additions and 21 deletions

@ -184,7 +184,7 @@ background-color: #555;
.active-scripts-server-panel { .active-scripts-server-panel {
margin: 0px 6px 6px 6px; margin: 0px 6px 6px 6px;
padding: 6px; padding: 0px 6px 6px 6px;
width: 55%; width: 55%;
margin-left: 5%; margin-left: 5%;
display: none; display: none;

@ -34,7 +34,7 @@ CONSTANTS = {
/* Script related things */ /* Script related things */
//Time (ms) it takes to run one operation in Netscript. //Time (ms) it takes to run one operation in Netscript.
CodeInstructionRunTime: 750, CodeInstructionRunTime: 500,
//RAM Costs for different commands //RAM Costs for different commands
ScriptWhileRamCost: 0.2, ScriptWhileRamCost: 0.2,
@ -538,7 +538,7 @@ CONSTANTS = {
"v0.20.0<br>" + "v0.20.0<br>" +
"-Refactored Netscript Interpreter code. Operations in Netscript should now run significantly faster (Every operation " + "-Refactored Netscript Interpreter code. Operations in Netscript should now run significantly faster (Every operation " +
"such as a variable assignment, a function call, a binary operator, getting a variable's value, etc. used to take up to several seconds, " + "such as a variable assignment, a function call, a binary operator, getting a variable's value, etc. used to take up to several seconds, " +
"now each one should only take 750 milliseconds). <br><br>" + "now each one should only take ~500 milliseconds). <br><br>" +
"-Percentage money stolen when hacking lowered to compensate for faster script speeds<br><br>" + "-Percentage money stolen when hacking lowered to compensate for faster script speeds<br><br>" +
"-Hacking experience granted by grow() halved<br><br>" + "-Hacking experience granted by grow() halved<br><br>" +
"-Weaken() is now ~11% faster, but only grants 3 base hacking exp upon completion instead of 5 <br><br>" + "-Weaken() is now ~11% faster, but only grants 3 base hacking exp upon completion instead of 5 <br><br>" +
@ -560,7 +560,7 @@ CONSTANTS = {
"-Server growth no longer happens naturally<br><br>" + "-Server growth no longer happens naturally<br><br>" +
"-Servers now have a maximum limit to their money. This limit is 50 times it's starting money<br><br>" + "-Servers now have a maximum limit to their money. This limit is 50 times it's starting money<br><br>" +
"-Hacking now grants 10% less hacking experience<br><br>" + "-Hacking now grants 10% less hacking experience<br><br>" +
"-You can now edit scripts that are running<br><br>+ " + "-You can now edit scripts that are running<br><br>" +
"-Augmentations cost ~11% more money and 25% more faction reputation<br><br>" + "-Augmentations cost ~11% more money and 25% more faction reputation<br><br>" +
"v0.19.7<br>" + "v0.19.7<br>" +
"-Added changelog to Options menu<br>" + "-Added changelog to Options menu<br>" +
@ -648,7 +648,7 @@ CONSTANTS = {
"v0.20.0<br>" + "v0.20.0<br>" +
"-Refactored Netscript Interpreter code. Operations in Netscript should now run significantly faster (Every operation " + "-Refactored Netscript Interpreter code. Operations in Netscript should now run significantly faster (Every operation " +
"such as a variable assignment, a function call, a binary operator, getting a variable's value, etc. used to take up to several seconds, " + "such as a variable assignment, a function call, a binary operator, getting a variable's value, etc. used to take up to several seconds, " +
"now each one should only take 750 milliseconds). <br><br>" + "now each one should only take ~500 milliseconds). <br><br>" +
"-Percentage money stolen when hacking lowered to compensate for faster script speeds<br><br>" + "-Percentage money stolen when hacking lowered to compensate for faster script speeds<br><br>" +
"-Hacking experience granted by grow() halved<br><br>" + "-Hacking experience granted by grow() halved<br><br>" +
"-Weaken() is now ~11% faster, but only grants 3 base hacking exp upon completion instead of 5 <br><br>" + "-Weaken() is now ~11% faster, but only grants 3 base hacking exp upon completion instead of 5 <br><br>" +
@ -670,6 +670,6 @@ CONSTANTS = {
"-Server growth no longer happens naturally<br><br>" + "-Server growth no longer happens naturally<br><br>" +
"-Servers now have a maximum limit to their money. This limit is 50 times it's starting money<br><br>" + "-Servers now have a maximum limit to their money. This limit is 50 times it's starting money<br><br>" +
"-Hacking now grants 10% less hacking experience<br><br>" + "-Hacking now grants 10% less hacking experience<br><br>" +
"-You can now edit scripts that are running<br><br>+ " + "-You can now edit scripts that are running<br><br>" +
"-Augmentations cost ~11% more money and 25% more faction reputation<br><br>", "-Augmentations cost ~11% more money and 25% more faction reputation<br><br>",
} }

@ -43,7 +43,6 @@ function addMessageToServer(msg, serverHostname) {
//Checks if any of the 'timed' messages should be sent //Checks if any of the 'timed' messages should be sent
function checkForMessagesToSend() { function checkForMessagesToSend() {
console.log("checkForMessagesToSend() called");
var jumper0 = Messages[MessageFilenames.Jumper0]; var jumper0 = Messages[MessageFilenames.Jumper0];
var jumper1 = Messages[MessageFilenames.Jumper1]; var jumper1 = Messages[MessageFilenames.Jumper1];
var jumper2 = Messages[MessageFilenames.Jumper2]; var jumper2 = Messages[MessageFilenames.Jumper2];

@ -280,15 +280,16 @@ function evaluate(exp, workerScript) {
return reject(makeRuntimeRejectMsg(workerScript, "Invalid IP or hostname passed into kill() command")); return reject(makeRuntimeRejectMsg(workerScript, "Invalid IP or hostname passed into kill() command"));
} }
for (var i = 0; i < server.runningScripts.length; ++i) { var res = killWorkerScript(filename, server.ip);
if (filename == server.runningScripts[i].filename) { if (res) {
killWorkerScript(filename, server.ip); workerScript.scriptRef.log("Killing " + filename + ". May take up to a few minutes for the scripts to die...");
workerScript.scriptRef.log("Killing " + scriptName + ". May take up to a few minutes for the scripts to die..."); return Promise.resolve(true);
return resolve(true); } else {
} workerScript.scriptRef.log("kill() failed. No such script "+ filename + " on " + server.hostname);
return Promise.resolve(false);
} }
workerScript.scriptRef.log("kill() failed. No such script "+ scriptName + " on " + server.hostname); }).then(function(res) {
return resolve(false); resolve(res);
}).catch(function(e) { }).catch(function(e) {
reject(e); reject(e);
}); });
@ -304,7 +305,7 @@ function evaluate(exp, workerScript) {
workerScript.scriptRef.log("killall() failed. Invalid IP or hostname passed in: " + ip); workerScript.scriptRef.log("killall() failed. Invalid IP or hostname passed in: " + ip);
return reject(makeRuntimeRejectMsg(workerScript, "Invalid IP or hostname passed into killall() command")); return reject(makeRuntimeRejectMsg(workerScript, "Invalid IP or hostname passed into killall() command"));
} }
workerScript.scriptRef.log("killall(): Killing all scrips on " + server.hostname); workerScript.scriptRef.log("killall(): Killing all scripts on " + server.hostname + ". May take a few minutes for the scripts to die");
for (var i = server.runningScripts.length; i >= 0; --i) { for (var i = server.runningScripts.length; i >= 0; --i) {
killWorkerScript(server.runningScripts[i], server.ip); killWorkerScript(server.runningScripts[i], server.ip);
} }
@ -344,7 +345,7 @@ function evaluate(exp, workerScript) {
} }
if (sourceScript == null) { if (sourceScript == null) {
workerScript.scriptRef.log(scriptname + " does not exist. scp() failed"); workerScript.scriptRef.log(scriptname + " does not exist. scp() failed");
return resolve(false); return Promise.resolve(false);
} }
//Overwrite script if it already exists //Overwrite script if it already exists
@ -355,8 +356,7 @@ function evaluate(exp, workerScript) {
var oldScript = destServer.scripts[i]; var oldScript = destServer.scripts[i];
oldScript.code = sourceScript.code; oldScript.code = sourceScript.code;
oldScript.ramUsage = sourceScript.ramUsage; oldScript.ramUsage = sourceScript.ramUsage;
resolve(true); return Promise.resolve(true);
return;
} }
} }
@ -368,7 +368,10 @@ function evaluate(exp, workerScript) {
newScript.server = destServer.ip; newScript.server = destServer.ip;
destServer.scripts.push(newScript); destServer.scripts.push(newScript);
workerScript.scriptRef.log(scriptname + " copied over to " + destServer.hostname); workerScript.scriptRef.log(scriptname + " copied over to " + destServer.hostname);
return resolve(true); return Promise.resolve(true);
return;
}).then(function(res) {
resolve(res);
}).catch(function(e) { }).catch(function(e) {
reject(e); reject(e);
}); });
@ -431,7 +434,7 @@ function evaluate(exp, workerScript) {
workerScript.scriptRef.log("getServerRequiredHackingLevel() failed. Invalid IP or hostname passed in: " + ip); workerScript.scriptRef.log("getServerRequiredHackingLevel() failed. Invalid IP or hostname passed in: " + ip);
return reject(makeRuntimeRejectMsg(workerScript, "Invalid IP or hostname passed into getServerRequiredHackingLevel() command")); return reject(makeRuntimeRejectMsg(workerScript, "Invalid IP or hostname passed into getServerRequiredHackingLevel() command"));
} }
workerScript.scriptRef.log("getServerRequiredHackingLevel returned " + formatNumber(server.requiredHackingSkill, 0) + " for " + server.hsostname); workerScript.scriptRef.log("getServerRequiredHackingLevel returned " + formatNumber(server.requiredHackingSkill, 0) + " for " + server.hostname);
resolve(server.requiredHackingSkill); resolve(server.requiredHackingSkill);
}, function(e) { }, function(e) {
reject(e); reject(e);

@ -111,6 +111,8 @@ function runScriptsLoop() {
return; return;
} }
} }
} else {
dialogBoxCreate("An unknown script died for an unknown reason. This is a bug please contact game dev");
} }
}); });
} }
@ -152,8 +154,10 @@ function killWorkerScript(scriptName, serverIp) {
for (var i = 0; i < workerScripts.length; i++) { for (var i = 0; i < workerScripts.length; i++) {
if (workerScripts[i].name == scriptName && workerScripts[i].serverIp == serverIp) { if (workerScripts[i].name == scriptName && workerScripts[i].serverIp == serverIp) {
workerScripts[i].env.stopFlag = true; workerScripts[i].env.stopFlag = true;
return true;
} }
} }
return false;
} }
//Queues a script to be run //Queues a script to be run