| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- '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.shuiguo.isTableExistAsync(session.uid, String(msg.tableId),reload).nodeify(next);
-
- });
- // 加入桌子
- proto.joinTable = P.coroutine(function* (msg, session, next) {
- let str3 = "sghander 加入桌子.......uid: " + session.uid
- logger.warn(str3);////cssj
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_HAS_LOGGED });
- }
- if (!msg.tableId) {
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
- }
- return this.app.controllers.shuiguo.joinTableAsync(session.uid, String(msg.tableId)).nodeify(next);
- });
- //////TL++创建或者加入桌子,用于玩家通过战绩分享进来之后
- proto.creatOrjoinTable = P.coroutine(function* (msg, session, next) {
- let str1 = "sghander 加入桌子.......uid: "
- logger.warn(str1);////cssj
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_HAS_LOGGED });
- }
- msg.upId = 0
- if (!msg.upId) {
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
- }
- // let str3 = "sghander 加入桌子222.......uid: " + session.uid + " upid "+msg.upId
- // logger.warn(str3);////cssj
- var round = 100;
- var type = 0;
- var kind = 1;////平搓还是冲刺 = 1代表平搓 = 2代表冲刺
- var playercount = 1;////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
- var other = 0;////TL++2人3人的游戏规则
- var upId = msg.upId;////TL++主动创建房间的话此值为"",通过战绩分享自动创建的房间此变量有值
- var agentId=msg.agentId || "";//数据库中agenter(推广员)数据表的主键(_id)
- // console.warn("创建或者加入桌子 agentId "+agentId+" session.uid "+session.uid);
- return this.app.controllers.shuiguo.creatOrjoinTableAsync(session.uid, round,type, kind,playercount,upId,other,agentId).nodeify(next);
- });
- // 创建桌子
- proto.createTable = P.coroutine(function* (msg, session, next) {
- console.warn("73")
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_HAS_LOGGED });
- }
- var round = 100;
- var type = 0;
- var gameKindTL = 1;////平搓还是冲刺 = 1代表平搓 = 2代表冲刺
- var playerAllCount = 1;////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
- var other = 0;////TL++2人3人的游戏规则
- var upId = msg.upId || "";////TL++主动创建房间的话此值为"",通过战绩分享自动创建的房间此变量有值
- var agentId=msg.agentId || "";
- // console.warn("创建桌子, "+agentId+" session.uid "+session.uid);//数据库中agenter(推广员)数据表的主键(_id)
- return this.app.controllers.shuiguo.createTableAsync(session.uid, round, type,gameKindTL,playerAllCount,upId,other,agentId).nodeify(next);/////修改局数
- });
- // 离开桌子
- proto.leaveTable = P.coroutine(function* (msg, session, next) {
- // console.warn("shuiguo hand 离开桌子 ")
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
- }
- return this.app.controllers.shuiguo.leaveTableAsync(session.uid).nodeify(next);
- });
- // 准备(结束本小局)
- proto.ready = P.coroutine(function* (msg, session, next) {
- let str3 = "sghander 准备(结束本小局).......uid: " + session.uid
- logger.warn(str3);////cssj
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
- }
- return this.app.controllers.shuiguo.readyGameAsync(session.uid).nodeify(next);
- });
- // 带入
- proto.dairu = P.coroutine(function* (msg, session, next) {
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
- }
- return this.app.controllers.shuiguo.dairuAsync(session.uid).nodeify(next);
- });
- // 开始
- proto.startGame = P.coroutine(function* (msg, session, next) {
- // let str3 = "sghander 开始.......uid: " + session.uid
- // logger.warn(str3);////cssj
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
- }
- // console.warn("shuiguo hand 开始 msg.yazhus : "+JSON.stringify( msg.yazhus));
- var yazhus = msg.yazhus;
- let isArr = msg.yazhus instanceof Array;////////判断参数是否是个数组
- if (!yazhus || !isArr) {
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
- }
- let yzsfhf = false;//押注是否合法
- for (var i = 0; i < yazhus.length; i++) {
- if(yazhus[i] > 0) {
- yzsfhf = true;
- break;
- }
- }
- if(!yzsfhf) return next(null, { code: C.FAILD, msg: "押注不能为0" });
- return this.app.controllers.shuiguo.startGameAsync(session.uid,yazhus).nodeify(next);
- });
- // 划分
- proto.huafen = P.coroutine(function* (msg, session, next) {
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
- }
- // console.warn("shuiguo hand 划分 msg.type : "+JSON.stringify( msg.type) +" msg.value : "+JSON.stringify( msg.value));
- var type = parseInt(msg.type) || 0;////压大还是押小 = 1代表押小 = 2代表押大
- if(type != 1 && type != 2){
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是押大也不是押小
- }
- var value = parseFloat(msg.value) || 0;////押的分数
- if(value <= 0){
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////没有押的分数
- }
- return this.app.controllers.shuiguo.huafenAsync(session.uid,type,value).nodeify(next);
- });
- // 请求结束
- proto.overTable = P.coroutine(function* (msg, session, next) {
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
- }
- // console.warn("请求结束 hand "+session.uid);
- return this.app.controllers.shuiguo.overTableAsync(session.uid).nodeify(next);
- });
- // 得到战绩
- proto.getRecord = P.coroutine(function* (msg, session, next) {
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
- }
- return this.app.controllers.shuiguo.getRecordAsync(session.uid).nodeify(next);
- });
- // 角色信息
- proto.roleInfo = P.coroutine(function* (msg, session, next) {
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
- }
- return this.app.controllers.shuiguo.roleInfoAsync(session.uid).nodeify(next);
- });
- // 得到排行榜
- proto.getPaiHang = P.coroutine(function* (msg, session, next) {
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
- }
- return this.app.controllers.shuiguo.getPaiHangAsync(session.uid).nodeify(next);
- });
- // 上传真实姓名支付宝账号
- proto.upZFBInfo = P.coroutine(function* (msg, session, next) {
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
- }
- // console.warn("shuiguo hand 划分 msg.type : "+JSON.stringify( msg.type) +" msg.value : "+JSON.stringify( msg.value));
- var realName = msg.realName;
- if(!realName){
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是押大也不是押小
- }
- var zfbAcc = msg.zfbAcc;
- if(!zfbAcc){
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是押大也不是押小
- }
- return this.app.controllers.shuiguo.upZFBInfoAsync(session.uid,realName,zfbAcc).nodeify(next);
- });
- // 得到玩家任务信息,里面包含任务信息
- proto.getTaskInfo = P.coroutine(function* (msg, session, next) {
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
- }
- return this.app.controllers.shuiguo.getTaskInfoAsync(session.uid).nodeify(next);
- });
- // 处理任务领取任务
- proto.dealRenWu = P.coroutine(function* (msg, session, next) {
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
- }
- if (!msg.item) {
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
- }
- return this.app.controllers.shuiguo.dealRenWuAsync(session.uid,msg.item).nodeify(next);
- });
- // 任务领奖
- proto.renWuLingjiang = P.coroutine(function* (msg, session, next) {
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
- }
- if (!msg.item) {
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
- }
- return this.app.controllers.shuiguo.renWuLingjiangAsync(session.uid,msg.item).nodeify(next);
- });
- // 得到玩家已完成的任务列表
- proto.getOverTasks = P.coroutine(function* (msg, session, next) {
- if (!session.uid) {
- return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
- }
- return this.app.controllers.shuiguo.getOverTasksAsync(session.uid).nodeify(next);
- });
|