Skip to content

Commit

Permalink
Update core/ from dogfood database
Browse files Browse the repository at this point in the history
Changes from 2020-06-12T13.38.01.309Z.city.

Closes: #360, #385.
  • Loading branch information
cpcallen committed Jun 15, 2020
1 parent 11d884a commit 773fe05
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 54 deletions.
12 changes: 6 additions & 6 deletions core/core_11_$.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
// AUTO-GENERATED CODE FROM DUMP. EDIT WITH CAUTION!
//////////////////////////////////////////////////////////////////////

$.utils.isObject = function isObject(v) {
/* Returns true iff v is an object (of any class, including Array
* and Function). */
return (typeof v === 'object' && v !== null) || typeof v === 'function';
};
Object.setOwnerOf($.utils.isObject, Object.getOwnerOf($.system.onStartup.prototype));
$.utils.validate.ownArray = function(object, key) {
// Ensure that object[key] is an array not shared with any other
// object or property, not inherited from a prototype, etc.
Expand Down Expand Up @@ -64,6 +58,12 @@ $.utils.validate.ownArray.prototype.constructor = function(object, key) {
};
delete $.utils.validate.ownArray.prototype.constructor.name;
$.utils.validate.ownArray.prototype.constructor.prototype = $.utils.validate.ownArray.prototype;
$.utils.isObject = function isObject(v) {
/* Returns true iff v is an object (of any class, including Array
* and Function). */
return (typeof v === 'object' && v !== null) || typeof v === 'function';
};
Object.setOwnerOf($.utils.isObject, Object.getOwnerOf($.system.onStartup.prototype));
$.utils.imageMatch = {};
$.utils.imageMatch.send = function send(ink) {
var json = $.system.xhr('https://neil.fraser.name/scripts/imageMatch.py' +
Expand Down
3 changes: 3 additions & 0 deletions core/core_22_$.connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@

$.connection = {};
$.connection.onConnect = function onConnect() {
this.connectTime = Date.now();
this.user = null;
this.buffer = '';
this.connected = true;
};
Object.setOwnerOf($.connection.onConnect, Object.getOwnerOf($.Jssp.OutputBuffer));
Object.setOwnerOf($.connection.onConnect.prototype, Object.getOwnerOf($.Jssp.OutputBuffer));
$.connection.onReceive = function onReceive(text) {
this.buffer += text.replace(/\r/g, '');
var lf;
Expand All @@ -46,6 +48,7 @@ $.connection.onReceiveLine = function onReceiveLine(text) {
Object.setOwnerOf($.connection.onReceiveLine, Object.getOwnerOf($.Jssp.OutputBuffer));
$.connection.onEnd = function onEnd() {
this.connected = false;
this.disconnectTime = Date.now();
};
Object.setOwnerOf($.connection.onEnd, Object.getOwnerOf($.Jssp.OutputBuffer));
$.connection.write = function write(text) {
Expand Down
6 changes: 0 additions & 6 deletions core/core_24_$.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
$.www = {};

$.www[404] = {};
// CLOSURE: type: function, vars: source, jssp
// CLOSURE: type: funexp, vars: Jssp
$.www[404].www = function jssp(request, response) {
// DO NOT EDIT THIS CODE. AUTOMATICALLY GENERATED BY JSSP.
// To edit contents of generated page, edit this.source.
Expand All @@ -52,8 +50,6 @@ Object.defineProperty($.www[404].www.compiled_, 'name', {value: '$.www[404].www.
$.www[404].www.jssp = '<% response.statusCode = 404 %>\n<html>\n<head>\n <title>404 - Code City</title>\n <style>\n body {\n font-family: "Roboto Mono", monospace;\n text-align: center;\n }\n h1 {\n font-size: 40pt;\n font-weight: 100;\n }\n h1>img {\n vertical-align: text-bottom;\n }\n pre {\n margin: 2em;\n }\n </style>\n <link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">\n <link href="/static/favicon.ico" rel="shortcut icon">\n</head>\n<body>\n <h1>\n <img src="/static/logo-error.svg" alt="">\n 404 Page Not Found\n </h1>\n <pre><%= request.method %> <%= $.utils.html.escape(request.url) %></pre>\n</body>\n</html>';

$.www['/'] = {};
// CLOSURE: type: function, vars: source, jssp
// CLOSURE: type: funexp, vars: Jssp
$.www['/'].www = function jssp(request, response) {
// DO NOT EDIT THIS CODE. AUTOMATICALLY GENERATED BY JSSP.
// To edit contents of generated page, edit this.source.
Expand All @@ -73,8 +69,6 @@ Object.setOwnerOf($.www['/'].www.compiled_.prototype, Object.getOwnerOf($.Jssp.O
Object.defineProperty($.www['/'].www.compiled_, 'name', {value: '$.www.homepage.www.compiled_'});

$.www['/robots.txt'] = {};
// CLOSURE: type: function, vars: source, jssp
// CLOSURE: type: funexp, vars: Jssp
$.www['/robots.txt'].www = function jssp(request, response) {
// DO NOT EDIT THIS CODE. AUTOMATICALLY GENERATED BY JSSP.
// To edit contents of generated page, edit this.source.
Expand Down
2 changes: 0 additions & 2 deletions core/core_26_$.www.editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ $.www.editor.save = function save(obj, key, src) {
return this.load(obj, key);
};
Object.setOwnerOf($.www.editor.save, Object.getOwnerOf($.Jssp.OutputBuffer));
// CLOSURE: type: function, vars: source, jssp
// CLOSURE: type: funexp, vars: Jssp
$.www.editor.www = function jssp(request, response) {
// DO NOT EDIT THIS CODE. AUTOMATICALLY GENERATED BY JSSP.
// To edit contents of generated page, edit this.source.
Expand Down
2 changes: 0 additions & 2 deletions core/core_27_$.www.code.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
//////////////////////////////////////////////////////////////////////

$.www.code = {};
// CLOSURE: type: function, vars: source, jssp
// CLOSURE: type: funexp, vars: Jssp
$.www.code.www = function jssp(request, response) {
// DO NOT EDIT THIS CODE. AUTOMATICALLY GENERATED BY JSSP.
// To edit contents of generated page, edit this.source.
Expand Down
1 change: 0 additions & 1 deletion core/core_30_$.utils.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ $.utils.command.execute = function execute(cmdstr, user) {
var func = host[prop];
if (typeof func !== 'function') continue; // Not a function.
var verbSpec = func.verb;
var prepSpec = func.prep;
var dobjSpec = func.dobj;
var prepSpec = func.prep;
var iobjSpec = func.iobj; // I can't wait for ES6.
Expand Down
12 changes: 8 additions & 4 deletions core/core_32_physical.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ $.physical.look.verb = 'l(ook)?';
$.physical.look.dobj = 'this';
$.physical.look.prep = 'none';
$.physical.look.iobj = 'none';
// CLOSURE: type: function, vars: source, jssp
// CLOSURE: type: funexp, vars: Jssp
$.physical.lookJssp = function jssp(request, response) {
// DO NOT EDIT THIS CODE. AUTOMATICALLY GENERATED BY JSSP.
// To edit contents of generated page, edit this.source.
Expand Down Expand Up @@ -269,6 +267,14 @@ $.physical.validate = function validate() {
// TODO: check for circular containment?
};
Object.setOwnerOf($.physical.validate, Object.getOwnerOf($.Jssp.OutputBuffer));
$.physical.validate.prototype.constructor = function validate() {
// Super call.
$.physical.validate.call(this);
// Clean up list of connected objects.
$.servers.telnet.validate();
};
Object.setOwnerOf($.physical.validate.prototype.constructor, Object.getOwnerOf($.Jssp.OutputBuffer));
$.physical.validate.prototype.constructor.prototype = $.physical.validate.prototype;
$.physical.toString = function toString() {
return this.name;
};
Expand Down Expand Up @@ -561,8 +567,6 @@ $.physical.examine.verb = 'ex(amine)?';
$.physical.examine.dobj = 'this';
$.physical.examine.prep = 'none';
$.physical.examine.iobj = 'none';
// CLOSURE: type: function, vars: source, jssp
// CLOSURE: type: funexp, vars: Jssp
$.physical.examine.jssp = function jssp(request, response) {
// DO NOT EDIT THIS CODE. AUTOMATICALLY GENERATED BY JSSP.
// To edit contents of generated page, edit this.source.
Expand Down
14 changes: 11 additions & 3 deletions core/core_33_world.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,19 +435,23 @@ $.user.go = function go(cmd) {
var dest = null;
if ($.room.isPrototypeOf(cmd.iobj)) {
dest = cmd.iobj;
} else if (!cmd.iobj) {
} else if (!cmd.iobjstr) {
throw 'Usage: go to <name of room>';
} else {
var re = new RegExp(cmd.iobjstr, 'i');
// TODO: find best match, not just first match?
for (var name in $.physicals) {
if (name.match(re) && $.room.isPrototypeOf($.physicals[name])) {
dest = $.physicals[name];
break;
}
}
}
if (!dest) return;
this.teleportTo(dest);
if (dest) {
this.teleportTo(dest);
} else {
throw 'There is no room named ' + cmd.iobjstr + '.';
}
};
Object.setOwnerOf($.user.go, Object.getOwnerOf($.Jssp.OutputBuffer));
Object.setOwnerOf($.user.go.prototype, Object.getOwnerOf($.Jssp.OutputBuffer));
Expand Down Expand Up @@ -917,6 +921,8 @@ $.container.open = function open(cmd) {
cmd.user.narrate('You open ' + String(cmd.dobj) + '.');
this.look(cmd);
};
Object.setOwnerOf($.container.open, Object.getOwnerOf($.Jssp.OutputBuffer));
Object.setOwnerOf($.container.open.prototype, Object.getOwnerOf($.Jssp.OutputBuffer));
$.container.open.verb = 'open';
$.container.open.dobj = 'this';
$.container.open.prep = 'none';
Expand Down Expand Up @@ -950,6 +956,8 @@ $.container.setOpen = function setOpen(newState) {
this.isOpen = Boolean(newState);
return true;
};
Object.setOwnerOf($.container.setOpen, Object.getOwnerOf($.Jssp.OutputBuffer));
Object.setOwnerOf($.container.setOpen.prototype, Object.getOwnerOf($.Jssp.OutputBuffer));
$.container.getCommands = function getCommands(who) {
var commands = $.thing.getCommands.call(this, who);
if (this.isOpen) {
Expand Down
52 changes: 38 additions & 14 deletions core/core_34_$.servers.telnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,35 +63,34 @@ Object.setOwnerOf($.servers.telnet.connection.onReceiveLine, Object.getOwnerOf($
$.servers.telnet.connection.onEnd = function onEnd() {
var user = this.user;
// Mark connection as closed.
$.connection.onEnd.apply(this, arguments);
// Remove this and any other closed / debound connections from array of open connections.
$.servers.telnet.connected = $.servers.telnet.connected.filter(function(c) {
return c.connected && (!c.user || c.user.connection === c);
});
$.connection.onEnd.call(this);
if (user) {
// Unbind connection from user.
this.user = null;
if (user.connection === this) {
user.connection = null;
$.system.log('Unbinding connection from ' + user.name);
}
setPerms(user);
new Thread(user.onDisconnect, 0, user);
(function () {
setPerms(user);
new Thread(user.onDisconnect, 0, user);
})();
}
// Remove this and any other closed / debound connections from array of open connections.
$.servers.telnet.validate();
};
Object.setOwnerOf($.servers.telnet.connection.onEnd, Object.getOwnerOf($.Jssp.OutputBuffer));
$.servers.telnet.connection.onConnect = function() {
// super call.
$.servers.telnet.connection.onConnect = function onConnect() {
// super call. Records .connectTime (as number of ms since epoch).
$.connection.onConnect.apply(this, arguments);
// Record connection time.
this.startTime = new Date();
// Add this connection to list of active telnet connections.
$.servers.telnet.connected.push(this);

setTimeout((function() {
if (!this.user) this.close();
}).bind(this), $.servers.telnet.LOGIN_TIMEOUT_MS);
};
delete $.servers.telnet.connection.onConnect.name;
Object.setOwnerOf($.servers.telnet.connection.onConnect, Object.getOwnerOf($.Jssp.OutputBuffer));
$.servers.telnet.connection.onConnect.prototype = $.connection.onConnect.prototype;
Object.setOwnerOf($.servers.telnet.connection.onConnect.prototype, Object.getOwnerOf($.Jssp.OutputBuffer));
$.servers.telnet.createUser = function createUser() {
var guest = Object.create($.user);
guest.setName('Guest', /*tryAlternative:*/ true);
Expand All @@ -108,6 +107,31 @@ $.servers.telnet.createUser = function createUser() {
return guest;
};
Object.setOwnerOf($.servers.telnet.createUser, Object.getOwnerOf($.Jssp.OutputBuffer));
$.servers.telnet.validate = function validate() {
// Examine supposedly-open connections and close and/or remove
// closed / timed-out / debound ones from the .connected arary.
var limit = Date.now() - this.LOGIN_TIMEOUT_MS;
this.connected = this.connected.filter(function(c) {
// Close any connections that haven't logged in promptly.
if (!c.user && c.connectTime < limit) {
try {
// Call .close(). Note that that this won't result in the
// object's .connected property being set to false
// immediately, but only after an async callback to
// connection.onEnd() - which will result in another call
// to $.servers.telnet.validate().
c.close();
} catch (e) {
// Connection was already closed. Mark it as such.
c.connected = false;
}
}
return c.connected && (!c.user || c.user.connection === c);
});
};
Object.setOwnerOf($.servers.telnet.validate, Object.getOwnerOf($.Jssp.OutputBuffer));
Object.setOwnerOf($.servers.telnet.validate.prototype, Object.getOwnerOf($.Jssp.OutputBuffer));
$.servers.telnet.LOGIN_TIMEOUT_MS = 20000;

$.servers.telnet.connected = [];

5 changes: 1 addition & 4 deletions core/core_40_$.startRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ $.clock.getDescription = function() {
return 'It is currently ' + Date();
};
delete $.clock.getDescription.name;
// CLOSURE: type: function, vars: arguments, hangout, clock, bob, alice, fido
$.clock.getDescription.prototype.constructor = function() {
return 'It is currently ' + Date();
};
Expand Down Expand Up @@ -93,7 +92,6 @@ $.clock.getSvgText = function() {
return svg;
};
delete $.clock.getSvgText.name;
// CLOSURE: type: function, vars: arguments, hangout, clock, bob, alice, fido
$.clock.getSvgText.prototype.constructor = function() {
var svg = '<circle cx="0" cy="30" r="10" class="fillWhite" />';
var r = 10;
Expand Down Expand Up @@ -145,8 +143,7 @@ $.clock.validate = function validate() {
this.onTimer();
};
Object.setOwnerOf($.clock.validate, Object.getOwnerOf($.Jssp.OutputBuffer));
$.clock.validate.prototype = $.physical.validate.prototype;
$.clock.validate.prototype.constructor = $.clock.validate;
Object.setOwnerOf($.clock.validate.prototype, Object.getOwnerOf($.Jssp.OutputBuffer));
$.clock.onTimer = function onTimer() {
/* Function that creates a thread to call itself at the next hour
* (and calls this.chime() if it is the right time to do so.)
Expand Down
6 changes: 0 additions & 6 deletions core/core_42_plant.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 27 additions & 5 deletions core/core_43_genetics_lab.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/core_44_$.assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ $.assistant.say = function say(speech) {
};
this.location.sendMemo(memo);
};
$.assistant.lastActivated = 1584246539955;
$.assistant.lastActivated = 1591829514766;
$.assistant.onCommand = function onCommand(command) {
/* Attempt to find a handler for command, by calling methods on this
* named cmd_* until one of them returns true.
Expand Down

0 comments on commit 773fe05

Please sign in to comment.