shuiguoHandler.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. 'use strict';
  2. var quick = require('quick-pomelo');
  3. var P = quick.Promise;
  4. var _ = require('lodash');
  5. var C = require('../../../../share/constant');
  6. var logger = quick.logger.getLogger('fhmj', __filename);
  7. var Handler = function (app) {
  8. this.app = app;
  9. };
  10. module.exports = function (app) {
  11. return new Handler(app);
  12. };
  13. var proto = Handler.prototype;
  14. // 判断桌子是否存在
  15. proto.isTableExist = P.coroutine(function* (msg, session, next) {
  16. // console.warn("XXXXXXXXXXXXXX000");
  17. if (!session.uid) {
  18. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  19. }
  20. if (!msg.tableId) {
  21. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  22. }
  23. var reload = parseInt(msg.reload) || 0;//ts++重入 1为重入
  24. return this.app.controllers.shuiguo.isTableExistAsync(session.uid, String(msg.tableId),reload).nodeify(next);
  25. });
  26. // 加入桌子
  27. proto.joinTable = P.coroutine(function* (msg, session, next) {
  28. let str3 = "sghander 加入桌子.......uid: " + session.uid
  29. logger.warn(str3);////cssj
  30. if (!session.uid) {
  31. return next(null, { code: C.ERROR, msg: C.PLAYER_HAS_LOGGED });
  32. }
  33. if (!msg.tableId) {
  34. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  35. }
  36. return this.app.controllers.shuiguo.joinTableAsync(session.uid, String(msg.tableId)).nodeify(next);
  37. });
  38. //////TL++创建或者加入桌子,用于玩家通过战绩分享进来之后
  39. proto.creatOrjoinTable = P.coroutine(function* (msg, session, next) {
  40. let str1 = "sghander 加入桌子.......uid: "
  41. logger.warn(str1);////cssj
  42. if (!session.uid) {
  43. return next(null, { code: C.ERROR, msg: C.PLAYER_HAS_LOGGED });
  44. }
  45. msg.upId = 0
  46. if (!msg.upId) {
  47. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  48. }
  49. // let str3 = "sghander 加入桌子222.......uid: " + session.uid + " upid "+msg.upId
  50. // logger.warn(str3);////cssj
  51. var round = 100;
  52. var type = 0;
  53. var kind = 1;////平搓还是冲刺 = 1代表平搓 = 2代表冲刺
  54. var playercount = 1;////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
  55. var other = 0;////TL++2人3人的游戏规则
  56. var upId = msg.upId;////TL++主动创建房间的话此值为"",通过战绩分享自动创建的房间此变量有值
  57. var agentId=msg.agentId || "";//数据库中agenter(推广员)数据表的主键(_id)
  58. // console.warn("创建或者加入桌子 agentId "+agentId+" session.uid "+session.uid);
  59. return this.app.controllers.shuiguo.creatOrjoinTableAsync(session.uid, round,type, kind,playercount,upId,other,agentId).nodeify(next);
  60. });
  61. // 创建桌子
  62. proto.createTable = P.coroutine(function* (msg, session, next) {
  63. console.warn("73")
  64. if (!session.uid) {
  65. return next(null, { code: C.ERROR, msg: C.PLAYER_HAS_LOGGED });
  66. }
  67. var round = 100;
  68. var type = 0;
  69. var gameKindTL = 1;////平搓还是冲刺 = 1代表平搓 = 2代表冲刺
  70. var playerAllCount = 1;////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
  71. var other = 0;////TL++2人3人的游戏规则
  72. var upId = msg.upId || "";////TL++主动创建房间的话此值为"",通过战绩分享自动创建的房间此变量有值
  73. var agentId=msg.agentId || "";
  74. // console.warn("创建桌子, "+agentId+" session.uid "+session.uid);//数据库中agenter(推广员)数据表的主键(_id)
  75. return this.app.controllers.shuiguo.createTableAsync(session.uid, round, type,gameKindTL,playerAllCount,upId,other,agentId).nodeify(next);/////修改局数
  76. });
  77. // 离开桌子
  78. proto.leaveTable = P.coroutine(function* (msg, session, next) {
  79. // console.warn("shuiguo hand 离开桌子 ")
  80. if (!session.uid) {
  81. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  82. }
  83. return this.app.controllers.shuiguo.leaveTableAsync(session.uid).nodeify(next);
  84. });
  85. // 准备(结束本小局)
  86. proto.ready = P.coroutine(function* (msg, session, next) {
  87. let str3 = "sghander 准备(结束本小局).......uid: " + session.uid
  88. logger.warn(str3);////cssj
  89. if (!session.uid) {
  90. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  91. }
  92. return this.app.controllers.shuiguo.readyGameAsync(session.uid).nodeify(next);
  93. });
  94. // 带入
  95. proto.dairu = P.coroutine(function* (msg, session, next) {
  96. if (!session.uid) {
  97. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  98. }
  99. return this.app.controllers.shuiguo.dairuAsync(session.uid).nodeify(next);
  100. });
  101. // 开始
  102. proto.startGame = P.coroutine(function* (msg, session, next) {
  103. // let str3 = "sghander 开始.......uid: " + session.uid
  104. // logger.warn(str3);////cssj
  105. if (!session.uid) {
  106. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  107. }
  108. // console.warn("shuiguo hand 开始 msg.yazhus : "+JSON.stringify( msg.yazhus));
  109. var yazhus = msg.yazhus;
  110. let isArr = msg.yazhus instanceof Array;////////判断参数是否是个数组
  111. if (!yazhus || !isArr) {
  112. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  113. }
  114. let yzsfhf = false;//押注是否合法
  115. for (var i = 0; i < yazhus.length; i++) {
  116. if(yazhus[i] > 0) {
  117. yzsfhf = true;
  118. break;
  119. }
  120. }
  121. if(!yzsfhf) return next(null, { code: C.FAILD, msg: "押注不能为0" });
  122. return this.app.controllers.shuiguo.startGameAsync(session.uid,yazhus).nodeify(next);
  123. });
  124. // 划分
  125. proto.huafen = P.coroutine(function* (msg, session, next) {
  126. if (!session.uid) {
  127. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  128. }
  129. // console.warn("shuiguo hand 划分 msg.type : "+JSON.stringify( msg.type) +" msg.value : "+JSON.stringify( msg.value));
  130. var type = parseInt(msg.type) || 0;////压大还是押小 = 1代表押小 = 2代表押大
  131. if(type != 1 && type != 2){
  132. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是押大也不是押小
  133. }
  134. var value = parseFloat(msg.value) || 0;////押的分数
  135. if(value <= 0){
  136. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////没有押的分数
  137. }
  138. return this.app.controllers.shuiguo.huafenAsync(session.uid,type,value).nodeify(next);
  139. });
  140. // 请求结束
  141. proto.overTable = P.coroutine(function* (msg, session, next) {
  142. if (!session.uid) {
  143. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  144. }
  145. // console.warn("请求结束 hand "+session.uid);
  146. return this.app.controllers.shuiguo.overTableAsync(session.uid).nodeify(next);
  147. });
  148. // 得到战绩
  149. proto.getRecord = P.coroutine(function* (msg, session, next) {
  150. if (!session.uid) {
  151. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  152. }
  153. return this.app.controllers.shuiguo.getRecordAsync(session.uid).nodeify(next);
  154. });
  155. // 角色信息
  156. proto.roleInfo = P.coroutine(function* (msg, session, next) {
  157. if (!session.uid) {
  158. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  159. }
  160. return this.app.controllers.shuiguo.roleInfoAsync(session.uid).nodeify(next);
  161. });
  162. // 得到排行榜
  163. proto.getPaiHang = P.coroutine(function* (msg, session, next) {
  164. if (!session.uid) {
  165. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  166. }
  167. return this.app.controllers.shuiguo.getPaiHangAsync(session.uid).nodeify(next);
  168. });
  169. // 上传真实姓名支付宝账号
  170. proto.upZFBInfo = P.coroutine(function* (msg, session, next) {
  171. if (!session.uid) {
  172. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  173. }
  174. // console.warn("shuiguo hand 划分 msg.type : "+JSON.stringify( msg.type) +" msg.value : "+JSON.stringify( msg.value));
  175. var realName = msg.realName;
  176. if(!realName){
  177. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是押大也不是押小
  178. }
  179. var zfbAcc = msg.zfbAcc;
  180. if(!zfbAcc){
  181. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是押大也不是押小
  182. }
  183. return this.app.controllers.shuiguo.upZFBInfoAsync(session.uid,realName,zfbAcc).nodeify(next);
  184. });
  185. // 得到玩家任务信息,里面包含任务信息
  186. proto.getTaskInfo = P.coroutine(function* (msg, session, next) {
  187. if (!session.uid) {
  188. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  189. }
  190. return this.app.controllers.shuiguo.getTaskInfoAsync(session.uid).nodeify(next);
  191. });
  192. // 处理任务领取任务
  193. proto.dealRenWu = P.coroutine(function* (msg, session, next) {
  194. if (!session.uid) {
  195. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  196. }
  197. if (!msg.item) {
  198. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  199. }
  200. return this.app.controllers.shuiguo.dealRenWuAsync(session.uid,msg.item).nodeify(next);
  201. });
  202. // 任务领奖
  203. proto.renWuLingjiang = P.coroutine(function* (msg, session, next) {
  204. if (!session.uid) {
  205. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  206. }
  207. if (!msg.item) {
  208. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  209. }
  210. return this.app.controllers.shuiguo.renWuLingjiangAsync(session.uid,msg.item).nodeify(next);
  211. });
  212. // 得到玩家已完成的任务列表
  213. proto.getOverTasks = P.coroutine(function* (msg, session, next) {
  214. if (!session.uid) {
  215. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  216. }
  217. return this.app.controllers.shuiguo.getOverTasksAsync(session.uid).nodeify(next);
  218. });