diff --git a/lib/server/socket.js b/lib/server/socket.js index 32fa379c..de862e58 100644 --- a/lib/server/socket.js +++ b/lib/server/socket.js @@ -12,7 +12,7 @@ Util = main.util, mainpackage = main.mainpackage, CLOUDCMD = mainpackage.name, - + lListen, ClientFuncs = [], OnMessageFuncs = [], INFO_LOG_LEVEL = 2, @@ -40,7 +40,7 @@ * @pServer {Object} started server object */ exports.listen = function(pServer) { - var lRet, lListen, lConnNum, lMsg, lConn_func; + var lRet, lConnNum, lMsg, lConn_func; if (io) { lListen = io.listen(pServer), @@ -119,10 +119,12 @@ */ function onMessage(pConnNum, pSocket) { return function(pCommand) { - var lMsg, lJSON, lWinCommand, lExec_func, lDir, + var lMsg, lJSON, lWinCommand, lExec_func, lDir, firstChar, + connName, lHome, lError, lRet, lExecSymbols, isContain; - Util.log('#' + pConnNum + ': ' + pCommand); + connName = '#' + pConnNum + ': '; + Util.log(connName + pCommand); if (Util.isContainStrAtBegin(pCommand, CLOUDCMD)) { pCommand = Util.removeStr(pCommand, CLOUDCMD); @@ -192,10 +194,22 @@ ClientFuncs[pConnNum] = getExec(pSocket, pConnNum); lExec_func = ClientFuncs[pConnNum]; - lExecSymbols = ['*','#', '&', '{', '}', '|', '\'', '"']; + lExecSymbols = ['*', '&', '{', '}', '|', '\'', '"']; isContain = Util.isContainStr(pCommand, lExecSymbols); + firstChar = pCommand[0]; - if (pCommand[0] === ' ' || isContain) + if (firstChar === '#') { + pCommand = pCommand.slice(1); + pCommand = connName + pCommand +'\n'; + + lJSON = { + stdout: pCommand + }; + + lMsg = Util.stringifyJSON(lJSON); + + lListen.sockets.emit('message', lMsg); + } else if (firstChar === ' ' || isContain) exec(pCommand, lExec_func); else getSpawn(pSocket, pConnNum, pCommand);