From aeea5a7e1856a1c4a06cfc12506322cf37446872 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 7 May 2016 16:04:10 +0000 Subject: [PATCH] multiple udp clients --- modules/udp/config.json | 2 ++ modules/udp/udp.js | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/udp/config.json b/modules/udp/config.json index 4619fcd..0821b85 100644 --- a/modules/udp/config.json +++ b/modules/udp/config.json @@ -1,6 +1,8 @@ { + "services": [{ "port":14628, "address": "127.0.0.1", "server": "freenode", "channel": "#oaosidl" + }] } diff --git a/modules/udp/udp.js b/modules/udp/udp.js index 6a4b5a7..78e5a0a 100644 --- a/modules/udp/udp.js +++ b/modules/udp/udp.js @@ -6,17 +6,20 @@ var dgram = require('dgram'); var udp = function(dbot) { + _.each(dbot.config.modules.udp.servers, function(data) { var server = dgram.createSocket("udp4"); server.on("message", function(msg, msginfo) { var message = msg.toString(); - console.log(message); - if (msginfo.address == this.config.address) { - dbot.say(this.config.server, this.config.channel, message); + if (msginfo.address == data.address) { + dbot.say(data.server, data.channel, message); } }.bind(this)); this.onLoad = function() { - server.bind(this.config.port); + _.each(dbot.config.modules.udp.servers, function(data) { + server.bind(data.port); + }); }.bind(this); + }.bind(this)); }; exports.fetch = function(dbot) {