initial commit of poker game
This commit is contained in:
90
game-server/app/servers/chat/handler/chatHandler.js
Normal file
90
game-server/app/servers/chat/handler/chatHandler.js
Normal file
@@ -0,0 +1,90 @@
|
||||
var UserStore = require('../../../persistence/users');
|
||||
var dispatcher = require('../../../util/dispatcher');
|
||||
|
||||
module.exports = function(app){
|
||||
return new Handler(app, app.get('chatService'));
|
||||
};
|
||||
var Handler = function(app, chatService){
|
||||
this.app = app;
|
||||
this.chatService = chatService;
|
||||
};
|
||||
var handler = Handler.prototype;
|
||||
|
||||
/**
|
||||
* Send messages to users in the channel
|
||||
*
|
||||
* @param {Object} msg message from client
|
||||
* @param {Object} session
|
||||
* @param {Function} next next stemp callback
|
||||
*
|
||||
*/
|
||||
handler.sendMessage = function(msg, session, next){
|
||||
var me = this;
|
||||
var tid = session.get('tid');
|
||||
var channelService = this.app.get('channelService');
|
||||
UserStore.getByAttr('id', session.uid, false, function(e, user){
|
||||
if(!user){
|
||||
next(null, {
|
||||
code : 500,
|
||||
error : 'user-not-exist'
|
||||
});
|
||||
return;
|
||||
}
|
||||
// target is all users
|
||||
if(msg.target == 'table'){
|
||||
var channel = channelService.getChannel(tid, true);
|
||||
msg.target = '*';
|
||||
channel.pushMessage({
|
||||
route : 'onChat',
|
||||
msg : msg.content,
|
||||
username : user.username,
|
||||
target : msg.target
|
||||
});
|
||||
next(null, {
|
||||
code : 200,
|
||||
route : msg.route
|
||||
});
|
||||
}else{
|
||||
// target is specific user
|
||||
me.chatService.pushByPlayerName(msg.target, {
|
||||
username : user.username,
|
||||
msg : msg.content
|
||||
}, function(e){
|
||||
if(e){
|
||||
return next(null, {
|
||||
code : 500,
|
||||
error : e
|
||||
});
|
||||
}
|
||||
next(null, {
|
||||
code : 200,
|
||||
route : msg.route
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Get friend list
|
||||
*
|
||||
* @param {Object} msg game parameters from client
|
||||
* @param {Object} session
|
||||
* @param {Function} next next step callback
|
||||
*
|
||||
*/
|
||||
handler.getFriends = function(msg, session, next){
|
||||
this.chatService.getFriendList(session.uid, function(e, friends){
|
||||
if(e){
|
||||
return next(null, {
|
||||
code : 500,
|
||||
error : e
|
||||
});
|
||||
}
|
||||
next(null, {
|
||||
code : 200,
|
||||
route : msg.route,
|
||||
friends : friends
|
||||
});
|
||||
});
|
||||
};
|
48
game-server/app/servers/chat/remote/chatRemote.js
Normal file
48
game-server/app/servers/chat/remote/chatRemote.js
Normal file
@@ -0,0 +1,48 @@
|
||||
module.exports = function(app){
|
||||
return new ChatRemote(app, app.get('chatService'));
|
||||
};
|
||||
|
||||
var ChatRemote = function(app, chatService){
|
||||
this.app = app;
|
||||
this.chatService = chatService;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add player into channel
|
||||
*/
|
||||
ChatRemote.prototype.addToChannel = function(uid, cid, cb){
|
||||
this.chatService.addToChannel(uid, cid, cb);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add player record
|
||||
*/
|
||||
ChatRemote.prototype.add = function(uid, cid, cb){
|
||||
this.chatService.add(uid, cid, cb);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get members in a channel
|
||||
*/
|
||||
ChatRemote.prototype.getMembers = function(cid, cb){
|
||||
this.chatService.getMembers(cid, cb);
|
||||
};
|
||||
|
||||
/**
|
||||
* leave Channel
|
||||
* uid
|
||||
* cid
|
||||
*/
|
||||
ChatRemote.prototype.leave = function(uid, cid, cb){
|
||||
this.chatService.leave(uid, cid);
|
||||
cb();
|
||||
};
|
||||
|
||||
/**
|
||||
* kick out user
|
||||
*
|
||||
*/
|
||||
ChatRemote.prototype.disconnect = function(uid, cb){
|
||||
this.chatService.disconnect(uid);
|
||||
cb();
|
||||
};
|
Reference in New Issue
Block a user