shuiguoHandler.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 roomType = msg.roomType
  74. var agentId=msg.agentId || "";
  75. // console.warn("创建桌子, "+agentId+" session.uid "+session.uid);//数据库中agenter(推广员)数据表的主键(_id)
  76. return this.app.controllers.shuiguo.createTableAsync(session.uid, round, type,gameKindTL,playerAllCount,upId,other,agentId,roomType).nodeify(next);/////修改局数
  77. });
  78. // 离开桌子
  79. proto.leaveTable = P.coroutine(function* (msg, session, next) {
  80. // console.warn("shuiguo hand 离开桌子 ")
  81. if (!session.uid) {
  82. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  83. }
  84. return this.app.controllers.shuiguo.leaveTableAsync(session.uid).nodeify(next);
  85. });
  86. // 准备(结束本小局)
  87. proto.ready = P.coroutine(function* (msg, session, next) {
  88. let str3 = "sghander 准备(结束本小局).......uid: " + session.uid
  89. logger.warn(str3);////cssj
  90. if (!session.uid) {
  91. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  92. }
  93. return this.app.controllers.shuiguo.readyGameAsync(session.uid).nodeify(next);
  94. });
  95. // 带入
  96. proto.dairu = P.coroutine(function* (msg, session, next) {
  97. if (!session.uid) {
  98. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  99. }
  100. return this.app.controllers.shuiguo.dairuAsync(session.uid).nodeify(next);
  101. });
  102. // 开始
  103. proto.startGame = P.coroutine(function* (msg, session, next) {
  104. // let str3 = "sghander 开始.......uid: " + session.uid
  105. // logger.warn(str3);////cssj
  106. if (!session.uid) {
  107. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  108. }
  109. // console.warn("shuiguo hand 开始 msg.yazhus : "+JSON.stringify( msg.yazhus));
  110. var yazhus = msg.yazhus;
  111. let isArr = msg.yazhus instanceof Array;////////判断参数是否是个数组
  112. if (!yazhus || !isArr) {
  113. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  114. }
  115. let yzsfhf = false;//押注是否合法
  116. for (var i = 0; i < yazhus.length; i++) {
  117. if(yazhus[i] > 0) {
  118. yzsfhf = true;
  119. break;
  120. }
  121. }
  122. if(!yzsfhf) return next(null, { code: C.FAILD, msg: "押注不能为0" });
  123. return this.app.controllers.shuiguo.startGameAsync(session.uid,yazhus).nodeify(next);
  124. });
  125. // 划分
  126. proto.huafen = P.coroutine(function* (msg, session, next) {
  127. if (!session.uid) {
  128. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  129. }
  130. // console.warn("shuiguo hand 划分 msg.type : "+JSON.stringify( msg.type) +" msg.value : "+JSON.stringify( msg.value));
  131. var type = parseInt(msg.type) || 0;////压大还是押小 = 1代表押小 = 2代表押大
  132. if(type != 1 && type != 2){
  133. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是押大也不是押小
  134. }
  135. var value = parseFloat(msg.value) || 0;////押的分数
  136. if(value <= 0){
  137. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////没有押的分数
  138. }
  139. return this.app.controllers.shuiguo.huafenAsync(session.uid,type,value).nodeify(next);
  140. });
  141. // 请求结束
  142. proto.overTable = P.coroutine(function* (msg, session, next) {
  143. if (!session.uid) {
  144. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  145. }
  146. // console.warn("请求结束 hand "+session.uid);
  147. return this.app.controllers.shuiguo.overTableAsync(session.uid).nodeify(next);
  148. });
  149. // 得到战绩
  150. proto.getRecord = P.coroutine(function* (msg, session, next) {
  151. if (!session.uid) {
  152. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  153. }
  154. return this.app.controllers.shuiguo.getRecordAsync(session.uid).nodeify(next);
  155. });
  156. // 角色信息
  157. proto.roleInfo = P.coroutine(function* (msg, session, next) {
  158. if (!session.uid) {
  159. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  160. }
  161. return this.app.controllers.shuiguo.roleInfoAsync(session.uid).nodeify(next);
  162. });
  163. // 得到排行榜
  164. proto.getPaiHang = P.coroutine(function* (msg, session, next) {
  165. if (!session.uid) {
  166. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  167. }
  168. return this.app.controllers.shuiguo.getPaiHangAsync(session.uid).nodeify(next);
  169. });
  170. // 上传真实姓名支付宝账号
  171. proto.upZFBInfo = P.coroutine(function* (msg, session, next) {
  172. if (!session.uid) {
  173. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  174. }
  175. // console.warn("shuiguo hand 划分 msg.type : "+JSON.stringify( msg.type) +" msg.value : "+JSON.stringify( msg.value));
  176. var realName = msg.realName;
  177. if(!realName){
  178. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是押大也不是押小
  179. }
  180. var zfbAcc = msg.zfbAcc;
  181. if(!zfbAcc){
  182. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是押大也不是押小
  183. }
  184. return this.app.controllers.shuiguo.upZFBInfoAsync(session.uid,realName,zfbAcc).nodeify(next);
  185. });
  186. // 得到玩家任务信息,里面包含任务信息
  187. proto.getTaskInfo = P.coroutine(function* (msg, session, next) {
  188. if (!session.uid) {
  189. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  190. }
  191. return this.app.controllers.shuiguo.getTaskInfoAsync(session.uid).nodeify(next);
  192. });
  193. // 处理任务领取任务
  194. proto.dealRenWu = P.coroutine(function* (msg, session, next) {
  195. if (!session.uid) {
  196. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  197. }
  198. if (!msg.item) {
  199. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  200. }
  201. return this.app.controllers.shuiguo.dealRenWuAsync(session.uid,msg.item).nodeify(next);
  202. });
  203. // 任务领奖
  204. proto.renWuLingjiang = P.coroutine(function* (msg, session, next) {
  205. if (!session.uid) {
  206. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  207. }
  208. if (!msg.item) {
  209. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  210. }
  211. return this.app.controllers.shuiguo.renWuLingjiangAsync(session.uid,msg.item).nodeify(next);
  212. });
  213. // 得到玩家已完成的任务列表
  214. proto.getOverTasks = P.coroutine(function* (msg, session, next) {
  215. if (!session.uid) {
  216. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  217. }
  218. return this.app.controllers.shuiguo.getOverTasksAsync(session.uid).nodeify(next);
  219. });