diff options
Diffstat (limited to 'webchat')
-rw-r--r-- | webchat/index.js | 6 | ||||
-rw-r--r-- | webchat/serverCommands.js | 14 |
2 files changed, 9 insertions, 11 deletions
diff --git a/webchat/index.js b/webchat/index.js index 14794e72..0ec448c4 100644 --- a/webchat/index.js +++ b/webchat/index.js @@ -24,7 +24,7 @@ clients.notifyAll = function (method, params) { }); } - +serverstate.clients = clients; var irc_reconnect = function() { //reconnt to irc console.log("reconnecting due to pingtimeout"); @@ -50,7 +50,7 @@ var irc_client = new irc.Client('irc.freenode.net', 'kweb', { //create irc_clien autoConnect: true, stripColors: true }); - +serverstate.irc_client = irc_client; irc_client.on('ping', function(server) { //restart timer on server ping console.log("got ping from server, renewing timeout for automatic reconnect"); @@ -114,7 +114,7 @@ echo.on('connection', function(conn) { if (!command || typeof command !== 'object') { command = {} } - return (serverCommands[command.method] || serverCommands.badcommand)(settings, command.params) + return (serverCommands[command.method] || serverCommands.badcommand)(serverstate, settings, command.params) }); conn.on('close', function() { //propagate if client quits the page clients.splice(clients.indexOf(conn)); diff --git a/webchat/serverCommands.js b/webchat/serverCommands.js index 0443bc91..dd755a97 100644 --- a/webchat/serverCommands.js +++ b/webchat/serverCommands.js @@ -1,22 +1,20 @@ - - var serverCommands = {}; -serverCommands.say = function (settings, params) { +serverCommands.say = function (serverstate, settings, params) { var nick = settings.nick var message = params.msg params.nick = nick - irc_client.say("#krebs", nick + ' → ' + message); - return clients.notifyAll('message', params) + serverstate.irc_client.say("#krebs", nick + ' → ' + message); + return serverstate.clients.notifyAll('message', params) } -serverCommands.nick = function (settings, params) { +serverCommands.nick = function (serverstate, settings, params) { var oldnick = settings.nick var newnick = params.nick settings.nick = newnick - return clients.notifyAll('nickchange', { nick: oldnick, newnick: newnick }); + return serverstate.clients.notifyAll('nickchange', { nick: oldnick, newnick: newnick }); } -serverCommands.badcommand = function (settings, params) { +serverCommands.badcommand = function (serversate, settings, params) { settings.conn.write(JSON.stringify({ method: 'usererror', params: { message: 'bad command' }})) } |