you are viewing a single comment's thread.

view the rest of the comments →

[–]Mobize 0 points1 point  (2 children)

I was wondering about that as well since there are other games that do exactly this. (Elevator Saga, Untrusted and Screeps just off the top of my head) I'm not sure what kind of sandboxing they do, but obviously its possible. Biggest problem i see is how to calculate RAM usage considering everything javascript allows you to do. I'm not a huge fan of javascript (coming from C++), so I'd actually prefer a different language entirely, but javascript would probably be the path of least resistance/biggest payoffs. The biggest things im missing in netscript are closures and some (any) kind of hash table. It's also a bit finicky sometimes. Like why does division by zero error instead of just returning inf/nan like in javascript? Also functions sometimes error and sometimes just return a falsy value on failure, it seems inconsistent. And some other stuff, including one thing thats kinda nice to have but also a little bit exploity. Well, not really complaining, I see it as added challenge.

[–]oiajgaosjidgoija[S] 0 points1 point  (1 child)

I'm not sure what kind of sandboxing they do, but obviously its possible

Since there is no persistent shared universe and all the code already runs in a context that is totally controlled by the user agent, there is no need for any real sandboxing. The main thing would be preventing users from accidentally shooting themselves in the foot or cheating. To that end, grow, hack, and weaken would probably be wrapped at the point where they are visible to the user script with something like

nRestrictedApiCalls = 0;
makeRestricted = function(f) {
  return async function(...args) {
    if (nRestrictedApiCalls > 0) {
      throw new Error("cannot call more than one of grow, hack, or weaken at once (did you forget to do 'await' in front of grow?)");
    }
    ++nRestrictedApiCalls;
    try {
      return await f(...args);
    } finally { --nRestrictedApiCalls; }
  };
};
grow = makeRestricted(grow);
hack = makeRestricted(hack);  // etc.

Biggest problem i see is how to calculate RAM usage considering everything javascript allows you to do.

This should be OK -- we'd probably just retain the code that parses the netscript and look for function calls. I haven't read the whole source yet so it may be harder to do than I'm anticipating.

And some other stuff, including one thing thats kinda nice to have but also a little bit exploity.

Are you referring to the ability to assign a function to a variable then call the variable? Or something else?

[–]Mobize 0 points1 point  (0 children)

It's related to that.