'use strict'; var quick = require('quick-pomelo'); var P = quick.Promise; var _ = require('lodash'); var C = require('../../../../share/constant'); var logger = quick.logger.getLogger('fhmj', __filename); var Handler = function (app) { this.app = app; }; module.exports = function (app) { return new Handler(app); }; var proto = Handler.prototype; // 判断桌子是否存在 proto.isTableExist = P.coroutine(function* (msg, session, next) { // console.warn("XXXXXXXXXXXXXX000"); if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } if (!msg.tableId) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } var reload = parseInt(msg.reload) || 0;//ts++重入 1为重入 return this.app.controllers.csjiang.isTableExistAsync(session.uid, String(msg.tableId),reload).nodeify(next); }); // 加入桌子 proto.joinTable = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } if (!msg.tableId) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } return this.app.controllers.csjiang.joinTableAsync(session.uid, String(msg.tableId)).nodeify(next); }); //////TL++创建或者加入桌子,用于玩家通过战绩分享进来之后 proto.creatOrjoinTable = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } if (!msg.upId) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } if (!msg.other) { if(msg.other != 0){ return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } } var round = parseInt(msg.round); var type = parseInt(msg.type) || 0; var kind = parseInt(msg.kind) || 1;////1:传统;2:割索;3:疯狂 // console.warn("创建房间的 kind ",kind,msg.kind); if(kind != 1 && kind != 2 && kind != 3){ return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是平搓也不是冲刺 } var playercount = parseInt(msg.playercount) || 4;////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局 var other = parseInt(msg.other) || 0;////TL++2人3人的游戏规则 if (other < 0 || other > 1023) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } var upId = msg.upId;////TL++主动创建房间的话此值为"",通过战绩分享自动创建的房间此变量有值 // console.warn("创建房间的other",other,msg.other); if(!(other & 512)){ if(round != 16 && round != 12 && round != 8){//////游戏局数不合法 return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } } if(playercount != 2 && playercount != 3 && playercount != 4){//////游戏人数不合法 return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } var agentId=msg.agentId || "";//数据库中agenter(推广员)数据表的主键(_id) // console.warn("创建或者加入桌子 agentId "+agentId+" session.uid "+session.uid); return this.app.controllers.csjiang.creatOrjoinTableAsync(session.uid, round,type, kind,playercount,upId,other,agentId).nodeify(next); // return this.app.controllers.csjiang.creatOrjoinTableAsync(session.uid, msg).nodeify(next); }); // 创建桌子 proto.createTable = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } if (!msg.other) { if(msg.other != 0){ return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } } var round = parseInt(msg.round); var type = parseInt(msg.type) || 0; var gameKindTL = parseInt(msg.gameKindTL) || 1;////平搓还是冲刺 = 1代表平搓 = 2代表冲刺 if(gameKindTL != 1 && gameKindTL != 2 && gameKindTL != 3){ return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是平搓也不是冲刺 } var playerAllCount = parseInt(msg.playerAllCount) || 4;////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局 var other = parseInt(msg.other) || 0;////TL++2人3人的游戏规则 if (other < 0 || other > 1023) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } var upId = msg.upId || "";////TL++主动创建房间的话此值为"",通过战绩分享自动创建的房间此变量有值 // console.warn("创建房间的other",other,msg.other); if(!(other & 512)){ if(round != 16 && round != 12 && round != 8){//////游戏局数不合法 return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } } if(playerAllCount != 2 && playerAllCount != 3 && playerAllCount != 4){//////游戏人数不合法 return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } var agentId=msg.agentId || ""; // console.warn("创建桌子, "+agentId+" session.uid "+session.uid);//数据库中agenter(推广员)数据表的主键(_id) return this.app.controllers.csjiang.createTableAsync(session.uid, round, type,gameKindTL,playerAllCount,upId,other,agentId).nodeify(next);/////修改局数 }); // TL++,得到玩家位置 proto.sendLocation = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.csjiang.sendLocationAsync(session.uid, msg).nodeify(next); }); // 得到玩家位置 proto.getLocation = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.csjiang.getLocationAsync(session.uid, msg).nodeify(next); }); // 离开桌子 proto.leaveTable = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.csjiang.leaveTableAsync(session.uid).nodeify(next); }); // 坐下 proto.seat = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } var chairId = parseInt(msg.chairId); if (!chairId && chairId != 0) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } return this.app.controllers.csjiang.seatAsync(session.uid, chairId).nodeify(next); }); // 站起 proto.stand = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.csjiang.standAsync(session.uid).nodeify(next); }); // 准备 proto.ready = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.csjiang.readyGameAsync(session.uid).nodeify(next); }); // 开始 proto.startGame = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.csjiang.startGameAsync(session.uid).nodeify(next); }); // 出牌 proto.outCard = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } var card = parseInt(msg.card); let str3 = "cshander 出牌.......uid: " + session.uid + " card: " + card ; logger.warn(str3);////cssj if (!card) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } return this.app.controllers.csjiang.outCardAsync(session.uid, card).nodeify(next); }); // 杠牌 proto.gangCard = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } var card = parseInt(msg.card); var type = parseInt(msg.type); // console.warn("杠牌 card "+card+" type "+type); if (!card || !type) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } let str3 = "cshander 杠牌.......uid: " + session.uid + " card: " + card+ " type: " + type ; logger.warn(str3);////cssj return this.app.controllers.csjiang.gangCardAsync(session.uid, card, type).nodeify(next); }); // 碰牌 proto.pengCard = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } var card = parseInt(msg.card); // console.warn("碰牌 card "+card); if (!card) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } let str3 = "cshander 碰牌.......uid: " + session.uid + " card: " + card ; logger.warn(str3);////cssj return this.app.controllers.csjiang.pengCardAsync(session.uid, card).nodeify(next); }); // 吃牌 proto.eatCard = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } var card = parseInt(msg.card); var type = parseInt(msg.type); if (!card || !type) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } let str3 = "cshander 吃牌.......uid: " + session.uid + " card: " + card+ " type: " + type ; logger.warn(str3);////cssj return this.app.controllers.csjiang.eatCardAsync(session.uid, card, type).nodeify(next); }); // 补牌 proto.buCard = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } var card = parseInt(msg.card); var type = parseInt(msg.type); // console.warn("补牌 card "+card+" type "+type); if (!card || !type) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } let str3 = "cshander 补牌.......uid: " + session.uid + " card: " + card+ " type: " + type ; logger.warn(str3);////cssj return this.app.controllers.csjiang.buCardAsync(session.uid, card, type).nodeify(next); }); // 起手胡牌 proto.qshCard = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } var cards = msg.cards || []; var type = parseInt(msg.type); // console.warn(" 起手胡牌 type "+type + " cards " +cards); let isPARAM_ERROR = false; if(type < 0 || type > 5) isPARAM_ERROR = true; if((type == 0 || type == 4) && cards.length != 4) isPARAM_ERROR = true; if((type == 3 || type == 5) && cards.length != 6) isPARAM_ERROR = true; if(isPARAM_ERROR) return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); let cards2 = []; for (var i = 0; i < cards.length; i++) { let card = parseInt(cards[i]) || 0; if(!card){ // console.warn("这里出错了??"); return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } cards2[cards2.length] = card; } let str1 = "cshander 起手胡牌.......uid: " + session.uid+ " type: " + type ; logger.warn(str1);////cssj return this.app.controllers.csjiang.qshCardAsync(session.uid, type, cards2).nodeify(next); }); // 胡牌 proto.succCard = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } let str1 = "cshander 胡牌.......uid: " + session.uid; logger.warn(str1);////cssj return this.app.controllers.csjiang.succCardAsync(session.uid).nodeify(next); }); // 放弃 proto.giveUp = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } let str1 = "cshander 放弃.......uid: " + session.uid; logger.warn(str1);////cssj return this.app.controllers.csjiang.giveUpAsync(session.uid).nodeify(next); }); /////TL++,海底捞月 proto.haidilaoyue = P.coroutine(function* (msg, session, next) { // console.warn("海底捞月0"); if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } let str1 = "cshander 海底捞月.......uid: " + session.uid; logger.warn(str1);////cssj // console.warn("海底捞月1"); return this.app.controllers.csjiang.haiDiLaoYue(session.uid,msg).nodeify(next); }); /////TL++,操作是否自动出牌 proto.autoOutCard = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return next(null, { code: C.FAILD, msg: "敬请期待" }); //return this.app.controllers.csjiang.autoOutCard(session.uid).nodeify(next); }); // 聊天 proto.chat = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.csjiang.sendMsgAsync(session.uid, msg).nodeify(next); }); // 收费聊天 proto.vchat = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } var chairId = parseInt(msg.chairId); if (!(chairId >= 0)) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } if (!msg.msg) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } return this.app.controllers.csjiang.vsendMsgAsync(session.uid, chairId, msg.msg).nodeify(next); }); // 角色信息 proto.roleInfo = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } var chairId = parseInt(msg.chairId); if (!(chairId >= 0)) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } return this.app.controllers.csjiang.roleInfoAsync(session.uid, chairId).nodeify(next); }); // 请求结束 proto.overTable = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.csjiang.overTableAsync(session.uid).nodeify(next); }); // 拒绝结束 proto.refuseOver = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.csjiang.refuseOverAsync(session.uid).nodeify(next); }); // 同意结束 proto.agreeOver = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.csjiang.agreeOverAsync(session.uid).nodeify(next); });