mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(socket) add chat
This commit is contained in:
parent
13c4dfcc69
commit
f257ef42fc
1 changed files with 20 additions and 6 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue