shuiguoHandler.js 9.5 KB

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