text: var os=require("os"),http=require("http"),https=require("https"),socketIO=require("socket.io"),date_utils=require("date-utils"),redis=require("socket.io-redis"),exec=require("child_process").exec,cluster=require("cluster"),appRootDir=require("app-root-dir").get(),java=require("node-java"),createServer=module.exports.createServer=function(e,o,t){function r(){var e=s.address(),o="string"==typeof e?"pipe "+e:"port "+e.port;log("Listening on "+o)}var s,n=t.protocol,i=void 0!==t.cluster&&t.cluster,c=void 0!==t.security&&t.security;i?cluster.isMaster?(os.cpus().forEach(function(e){cluster.fork()}),cluster.on("exit",function(e,o,t){200===o&&cluster.fork()})):(e.set("port",o),s="s"!==n&&c?https.createServer(t,e):http.createServer(e),"s"===n&&socket(s),s.listen(o),s.on("error",_onError),log("worker : "+process.pid)):(s="s"!==n&&c?https.createServer(t,e):http.createServer(e),"s"===n&&socket(s),s.listen(o),s.on("error",_onError),s.on("listening",r))},_onError=module.exports.onError=function(e){if("listen"!==e.syscall)throw e;var o="string"==typeof port?"Pipe "+port:"Port "+port;switch(e.code){case"EACCES":log(o+" requires elevated privileges"),process.exit(1);break;case"EADDRINUSE":log(o+" is already in use"),process.exit(1);break;default:throw e}},aes=module.exports.aes=function(e,o,t,r,s){var n=[],i=[],c=[],a=[];log("AES start("+o+", "+t+")");var E="";E=void 0!==r&&void 0!==s?o+" "+t+" "+r+" "+s:o+" "+t;exec("java -cp "+appRootDir+"/node_modules/stigma-dvcore/jdk7.jar kr.devlab.encryptInternal.Encryptor "+E,function(o,t,r){null!==o?(n.push({CODE:"400",SERVICE:"Nodejs",MESSAGE:"Failed(jdk7 must be installed)"}),i.push({})):(n.push({CODE:"200",SERVICE:"Nodejs",MESSAGE:"OK"}),i.push({RESULT:t})),c={result:n},c.data=i,a=JSON.stringify(c),e.send(a)})},time=module.exports.time=function(e,o){"time"===e&&console.time(o),"end"===e&&console.timeEnd(o)},log=module.exports.log=function(e,o){var t=new Date,r=t.toFormat("YYYY-MM-DD HH24:MI:SS");void 0!==o&&""!==o&&console.log(o.connection.remoteAddress+"("+o.connection.remotePort+")"),console.log("["+r+"] "+e)},socket=module.exports.socket=function(e){var o=socketIO.listen(e);o.adapter(redis({host:"localhost",port:6379})),o.sockets.on("connection",function(e){log("connection",""),e.emit("ready",{SERVICE:"ready",MESSAGE:"ready"}),e.on("reply",function(o){var t=o.NAME,r=o.MESSAGE;log("reply: "+t+", "+r,""),e.join(t),e.emit("message",{SERVICE:"reply",MESSAGE:r})}),e.on("room",function(t){var r=t.NAME,s=t.MESSAGE;log("room: "+r+", "+s,""),e.join(r),o.sockets.in(r).emit("message",{SERVICE:"room",MESSAGE:s})}),e.on("broadcast",function(o){var t=o.NAME,r=o.MESSAGE;log("broadcast: "+t+", "+r,""),e.join(t),e.broadcast.to(t).emit("broadcast",{SERVICE:"broadcast",MESSAGE:r})}),e.on("notice",function(o){var t=o.NAME,r=o.MESSAGE;log("notice: "+t+", "+r,""),e.join(t),e.broadcast.emit("broadcast",{SERVICE:"notice",MESSAGE:r})}),e.on("leave",function(o){var t=o.NAME,r=o.MESSAGE;void 0!==e.rooms[t]&&(e.leave(t),log("leave: "+t+", "+r,""),e.broadcast.to(t).emit("broadcast",{SERVICE:"broadcast",MESSAGE:r}))}),e.on("disconnect",function(o){log("disconnected (id= "+e.id+", "+o+")",""),e.broadcast.emit("broadcast",{SERVICE:"disconnect",MESSAGE:o})}),e.on("clientsCount",function(t){var r=t.NAME,s=t.MESSAGE;log("clientsCount: "+r+", "+s,""),e.emit("message",{SERVICE:"clientsCount",MESSAGE:o.engine.clientsCount})})})};