From f738034033888ce91afe314dc5d038c299dda278 Mon Sep 17 00:00:00 2001 From: Daniel Xie Date: Fri, 2 Jun 2017 14:46:14 -0500 Subject: [PATCH 1/2] scp() command in scripts now overwrites scripts at destination. Fixed some bugs in Network creation --- src/NetscriptEvaluator.js | 50 ++++++++++++++++++++++++--------------- src/NetscriptWorker.js | 1 + src/Server.js | 4 ++-- src/Terminal.js | 1 - 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/NetscriptEvaluator.js b/src/NetscriptEvaluator.js index 2bb27c7a3..f9463adf2 100644 --- a/src/NetscriptEvaluator.js +++ b/src/NetscriptEvaluator.js @@ -801,36 +801,48 @@ function evaluate(exp, workerScript) { return; } - //Check that a script with this filename does not already exist - for (var i = 0; i < destServer.scripts.length; ++i) { - if (scriptname == destServer.scripts[i].filename) { - workerScript.scriptRef.log(destServer.hostname + " already contains a script named " + scriptname); - resolve(false); - return; - } - } - var currServ = getServer(workerScript.serverIp); if (currServ == null) { reject(makeRuntimeRejectMsg(workerScript, "Could not find server ip for this script. This is a bug please contact game developer")); return; } + + var sourceScript = null; for (var i = 0; i < currServ.scripts.length; ++i) { if (scriptname == currServ.scripts[i].filename) { - var newScript = new Script(); - newScript.filename = scriptname; - newScript.code = currServ.scripts[i].code; - newScript.ramUsage = currServ.scripts[i].ramUsage; - newScript.server = destServer.ip; - destServer.scripts.push(newScript); - workerScript.scriptRef.log(scriptname + " copied over to " + destServer.hostname); + sourceScript = currServ.scripts[i]; + break; + } + } + if (sourceScript == null) { + workerScript.scriptRef.log(scriptname + " does not exist. scp() failed"); + resolve(false); + return; + } + + //Overwrite script if it already exists + for (var i = 0; i < destServer.scripts.length; ++i) { + if (scriptname == destServer.scripts[i].filename) { + workerScript.scriptRef.log("WARNING: " + scriptname + " already exists on " + destServer.hostname + " and it will be overwritten."); + workerScript.scriptRef.log(scriptname + " overwritten on " + destServer.hostname); + var oldScript = destServer.scripts[i]; + oldScript.code = sourceScript.code; + oldScript.ramUsage = sourceScript.ramUsage; resolve(true); return; } } - workerScript.scriptRef.log(scriptname + " does not exist. scp() failed"); - resolve(false); - + + //Create new script if it does not already exist + var newScript = new Script(); + newScript.filename = scriptname; + newScript.code = sourceScript.code; + newScript.ramUsage = sourceScript.ramUsage; + newScript.server = destServer.ip; + destServer.scripts.push(newScript); + workerScript.scriptRef.log(scriptname + " copied over to " + destServer.hostname); + resolve(true); + return; }, function(e) { reject(e); }); diff --git a/src/NetscriptWorker.js b/src/NetscriptWorker.js index b7b786623..601442d07 100644 --- a/src/NetscriptWorker.js +++ b/src/NetscriptWorker.js @@ -33,6 +33,7 @@ function runScriptsLoop() { var ast = Parser(Tokenizer(InputStream(workerScripts[i].code))); //console.log(ast); } catch (e) { + console.log("Error parsing script: " + workerScripts[i].name); dialogBoxCreate("Syntax ERROR in " + workerScripts[i].name + ":
" + e); workerScripts[i].env.stopFlag = true; continue; diff --git a/src/Server.js b/src/Server.js index 8be912d96..a2891e299 100644 --- a/src/Server.js +++ b/src/Server.js @@ -573,9 +573,9 @@ initForeignServers = function() { var NetworkGroup3 = [OmegaSoftwareServer, PhantasyServer, SilverHelixServer, NeoNightclubServer]; var NetworkGroup4 = [CrushFitnessGymServer, NetLinkTechnologiesServer, CompuTekServer, TheHubServer, JohnsonOrthopedicsServer, NiteSecServer]; var NetworkGroup5 = [CatalystVenturesServer, SysCoreSecuritiesServer, SummitUniversityServer, ZBInstituteOfTechnologyServer, RothmanUniversityServer, TheBlackHandServer]; - var NetworkGroup6 = [LexoCorpServer, RhoConstructionServer, AlphaEnterprisesServer, AevumPoliceServer, MilleniumFitnessGymServer, CyberSecServer, NiteSecServer]; + var NetworkGroup6 = [LexoCorpServer, RhoConstructionServer, AlphaEnterprisesServer, AevumPoliceServer, MilleniumFitnessGymServer]; var NetworkGroup7 = [GlobalPharmaceuticalsServer, AeroCorpServer, GalacticCyberSystemsServer, SnapFitnessGymServer]; - var NetworkGroup8 = [DeltaOneServer, UnitaLifeGroupServer, OmniaCybersystemsServer, BitRunnersServer]; + var NetworkGroup8 = [DeltaOneServer, UnitaLifeGroupServer, OmniaCybersystemsServer]; var NetworkGroup9 = [ZeusMedicalServer, SolarisSpaceSystemsServer, UniversalEnergyServer, IcarusMicrosystemsServer, DefCommServer]; var NetworkGroup10 = [NovaMedicalServer, ZBDefenseServer, TaiYangDigitalServer, InfoCommServer]; var NetworkGroup11 = [AppliedEnergeticsServer, MicrodyneTechnologiesServer, TitanLabsServer, BitRunnersServer]; diff --git a/src/Terminal.js b/src/Terminal.js index 055f8d166..ef97c3a1e 100644 --- a/src/Terminal.js +++ b/src/Terminal.js @@ -384,7 +384,6 @@ var Terminal = { //Process any aliases command = substituteAliases(command); - console.log("command after alises: " + command); //Only split the first space var commandArray = command.split(" "); From 697855d0f5c61e8ce501b5cf73270214efb44d20 Mon Sep 17 00:00:00 2001 From: Daniel Xie Date: Fri, 2 Jun 2017 14:54:36 -0500 Subject: [PATCH 2/2] scp terminal command now overwrites. Updated version to 0.19.5 --- src/Constants.js | 2 +- src/Terminal.js | 44 ++++++++++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/Constants.js b/src/Constants.js index 66fba7fbb..60d6b5356 100644 --- a/src/Constants.js +++ b/src/Constants.js @@ -1,5 +1,5 @@ CONSTANTS = { - Version: "0.19.4", + Version: "0.19.5", //Max level for any skill, assuming no multipliers. Determined by max numerical value in javascript for experience //and the skill level formula in Player.js. Note that all this means it that when experience hits MAX_INT, then diff --git a/src/Terminal.js b/src/Terminal.js index ef97c3a1e..8bd7e00a9 100644 --- a/src/Terminal.js +++ b/src/Terminal.js @@ -827,28 +827,40 @@ var Terminal = { } var ip = server.ip; - //Check that a script with this filename does not already exist + var currServ = Player.getCurrentServer(); + + //Get the current script + var sourceScript = null; + for (var i = 0; i < currServ.scripts.length; ++i) { + if (scriptname == currServ.scripts[i].filename) { + sourceScript = currServ.scripts[i]; + break; + } + } + if (sourceScript == null) { + post("ERROR: scp() failed. No such script exists"); + return; + } + + //Overwrite script if it exists for (var i = 0; i < server.scripts.length; ++i) { if (scriptname == server.scripts[i].filename) { - post(server.hostname + " already contains a script named " + scriptname); + post("WARNING: " + scriptname + " already exists on " + server.hostname + " and will be overwritten"); + var oldScript = server.scripts[i]; + oldScript.code = sourceScript.code; + oldScript.ramUsage = sourceScript.ramUsage; + post(scriptname + " overwriten on " + server.hostname); return; } } - var currServ = Player.getCurrentServer(); - for (var i = 0; i < currServ.scripts.length; ++i) { - if (scriptname == currServ.scripts[i].filename) { - var newScript = new Script(); - newScript.filename = scriptname; - newScript.code = currServ.scripts[i].code; - newScript.ramUsage = currServ.scripts[i].ramUsage; - newScript.server = ip; - server.scripts.push(newScript); - post(scriptname + " copied over to " + server.hostname); - return; - } - } - post("Script not found"); + var newScript = new Script(); + newScript.filename = scriptname; + newScript.code = sourceScript.code; + newScript.ramUsage = sourceScript.ramUsage; + newScript.server = ip; + server.scripts.push(newScript); + post(scriptname + " copied over to " + server.hostname); break; case "sudov": if (commandArray.length != 1) {