sxjiangHandler.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 Handler = function (app) {
  7. this.app = app;
  8. };
  9. module.exports = function (app) {
  10. return new Handler(app);
  11. };
  12. var proto = Handler.prototype;
  13. // 判断桌子是否存在
  14. proto.isTableExist = P.coroutine(function* (msg, session, next) {
  15. // console.warn("XXXXXXXXXXXXXX000");
  16. if (!session.uid) {
  17. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  18. }
  19. if (!msg.tableId) {
  20. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  21. }
  22. var reload = parseInt(msg.reload) || 0;//ts++重入 1为重入
  23. return this.app.controllers.sxjiang.isTableExistAsync(session.uid, String(msg.tableId),reload).nodeify(next);
  24. });
  25. // 加入桌子
  26. proto.joinTable = P.coroutine(function* (msg, session, next) {
  27. if (!session.uid) {
  28. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  29. }
  30. if (!msg.tableId) {
  31. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  32. }
  33. return this.app.controllers.sxjiang.joinTableAsync(session.uid, String(msg.tableId)).nodeify(next);
  34. });
  35. //////TL++创建或者加入桌子,用于玩家通过战绩分享进来之后
  36. proto.creatOrjoinTable = P.coroutine(function* (msg, session, next) {
  37. if (!session.uid) {
  38. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  39. }
  40. if (!msg.upId) {
  41. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  42. }
  43. if (!msg.other) {
  44. if(msg.other != 0){
  45. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  46. }
  47. }
  48. var round = parseInt(msg.round);
  49. var type = parseInt(msg.type) || 0;
  50. var kind = parseInt(msg.kind) || 1;////平搓还是冲刺 = 1代表平搓 = 2代表冲刺
  51. if(kind != 1 && kind != 2){
  52. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是平搓也不是冲刺
  53. }
  54. var playercount = parseInt(msg.playercount) || 4;////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
  55. var other = parseInt(msg.other) || 0;////TL++2人3人的游戏规则
  56. if (other < 0 || other > 4095) {
  57. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  58. }
  59. if(!((other & 64) || (other & 1024) || (other & 2048))&& (other & 512)){
  60. //“红中个数”=0的时候不能勾选“无红中胡加一码”
  61. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  62. }
  63. if((!(other & 1)) && (!(other & 2)) && (!(other & 4))){
  64. //没有勾选任何奖码方式,如159奖码,摸几奖几,一码全中
  65. if((other & 8) || (other & 16) || (other & 32) || (other & 512)){
  66. //没有勾选任何奖码方式的话指定奖码张数是不合法的
  67. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  68. }
  69. }
  70. var upId = msg.upId;////TL++主动创建房间的话此值为"",通过战绩分享自动创建的房间此变量有值
  71. // console.warn("创建房间的other",other,msg.other);
  72. if(round != 24 && round != 16 && round != 8){//////游戏局数不合法
  73. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  74. }
  75. if(playercount != 2 && playercount != 3 && playercount != 4){//////游戏人数不合法
  76. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  77. }
  78. var agentId=msg.agentId || "";//数据库中agenter(推广员)数据表的主键(_id)
  79. // console.warn("创建或者加入桌子 agentId "+agentId+" session.uid "+session.uid);
  80. return this.app.controllers.sxjiang.creatOrjoinTableAsync(session.uid, round,type, kind,playercount,upId,other,agentId).nodeify(next);
  81. // return this.app.controllers.sxjiang.creatOrjoinTableAsync(session.uid, msg).nodeify(next);
  82. });
  83. // 创建桌子
  84. proto.createTable = P.coroutine(function* (msg, session, next) {
  85. if (!session.uid) {
  86. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  87. }
  88. if (!msg.other) {
  89. if(msg.other != 0){
  90. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  91. }
  92. }
  93. var round = parseInt(msg.round);
  94. var type = parseInt(msg.type) || 0;
  95. var gameKindTL = parseInt(msg.gameKindTL) || 1;////平搓还是冲刺 = 1代表平搓 = 2代表冲刺
  96. if(gameKindTL != 1 && gameKindTL != 2){
  97. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是平搓也不是冲刺
  98. }
  99. var playerAllCount = parseInt(msg.playerAllCount) || 4;////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
  100. var other = parseInt(msg.other) || 0;////TL++2人3人的游戏规则
  101. if (other < 0 || other > 4095) {
  102. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  103. }
  104. if(!((other & 64) || (other & 1024) || (other & 2048))&& (other & 512)){
  105. //“红中个数”=0的时候不能勾选“无红中胡加一码”
  106. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  107. }
  108. if((!(other & 1)) && (!(other & 2)) && (!(other & 4))){
  109. //没有勾选任何奖码方式,如159奖码,摸几奖几,一码全中
  110. if((other & 8) || (other & 16) || (other & 32) || (other & 512)){
  111. //没有勾选任何奖码方式的话指定奖码张数是不合法的
  112. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  113. }
  114. }
  115. var upId = msg.upId || "";////TL++主动创建房间的话此值为"",通过战绩分享自动创建的房间此变量有值
  116. // console.warn("创建房间的other",other,msg.other);
  117. if(round != 24 && round != 16 && round != 8){//////游戏局数不合法
  118. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  119. }
  120. if(playerAllCount != 2 && playerAllCount != 3 && playerAllCount != 4){//////游戏人数不合法
  121. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  122. }
  123. var agentId=msg.agentId || "";
  124. // console.warn("创建桌子, "+agentId+" session.uid "+session.uid);//数据库中agenter(推广员)数据表的主键(_id)
  125. return this.app.controllers.sxjiang.createTableAsync(session.uid, round, type,gameKindTL,playerAllCount,upId,other,agentId).nodeify(next);/////修改局数
  126. });
  127. // TL++,得到玩家位置
  128. proto.sendLocation = P.coroutine(function* (msg, session, next) {
  129. if (!session.uid) {
  130. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  131. }
  132. return this.app.controllers.sxjiang.sendLocationAsync(session.uid, msg).nodeify(next);
  133. });
  134. // 得到玩家位置
  135. proto.getLocation = P.coroutine(function* (msg, session, next) {
  136. if (!session.uid) {
  137. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  138. }
  139. return this.app.controllers.sxjiang.getLocationAsync(session.uid, msg).nodeify(next);
  140. });
  141. // 离开桌子
  142. proto.leaveTable = P.coroutine(function* (msg, session, next) {
  143. if (!session.uid) {
  144. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  145. }
  146. return this.app.controllers.sxjiang.leaveTableAsync(session.uid).nodeify(next);
  147. });
  148. // 坐下
  149. proto.seat = P.coroutine(function* (msg, session, next) {
  150. if (!session.uid) {
  151. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  152. }
  153. var chairId = parseInt(msg.chairId);
  154. if (!chairId && chairId != 0) {
  155. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  156. }
  157. return this.app.controllers.sxjiang.seatAsync(session.uid, chairId).nodeify(next);
  158. });
  159. // 站起
  160. proto.stand = P.coroutine(function* (msg, session, next) {
  161. if (!session.uid) {
  162. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  163. }
  164. return this.app.controllers.sxjiang.standAsync(session.uid).nodeify(next);
  165. });
  166. // 准备
  167. proto.ready = P.coroutine(function* (msg, session, next) {
  168. if (!session.uid) {
  169. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  170. }
  171. return this.app.controllers.sxjiang.readyGameAsync(session.uid).nodeify(next);
  172. });
  173. // 开始
  174. proto.startGame = P.coroutine(function* (msg, session, next) {
  175. if (!session.uid) {
  176. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  177. }
  178. return this.app.controllers.sxjiang.startGameAsync(session.uid).nodeify(next);
  179. });
  180. // 出牌
  181. proto.outCard = P.coroutine(function* (msg, session, next) {
  182. if (!session.uid) {
  183. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  184. }
  185. var card = parseInt(msg.card);
  186. if (!card) {
  187. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  188. }
  189. return this.app.controllers.sxjiang.outCardAsync(session.uid, card).nodeify(next);
  190. });
  191. // 杠牌
  192. proto.gangCard = P.coroutine(function* (msg, session, next) {
  193. if (!session.uid) {
  194. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  195. }
  196. var card = parseInt(msg.card);
  197. var type = parseInt(msg.type);
  198. if (!card || !type) {
  199. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  200. }
  201. return this.app.controllers.sxjiang.gangCardAsync(session.uid, card, type).nodeify(next);
  202. });
  203. // 碰牌
  204. proto.pengCard = P.coroutine(function* (msg, session, next) {
  205. if (!session.uid) {
  206. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  207. }
  208. var card = parseInt(msg.card);
  209. if (!card) {
  210. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  211. }
  212. return this.app.controllers.sxjiang.pengCardAsync(session.uid, card).nodeify(next);
  213. });
  214. // 吃牌
  215. proto.eatCard = P.coroutine(function* (msg, session, next) {
  216. if (!session.uid) {
  217. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  218. }
  219. var card = parseInt(msg.card);
  220. var type = parseInt(msg.type);
  221. if (!card || !type) {
  222. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  223. }
  224. return this.app.controllers.sxjiang.eatCardAsync(session.uid, card, type).nodeify(next);
  225. });
  226. // 胡牌
  227. proto.succCard = P.coroutine(function* (msg, session, next) {
  228. if (!session.uid) {
  229. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  230. }
  231. return this.app.controllers.sxjiang.succCardAsync(session.uid).nodeify(next);
  232. });
  233. // 放弃
  234. proto.giveUp = P.coroutine(function* (msg, session, next) {
  235. if (!session.uid) {
  236. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  237. }
  238. return this.app.controllers.sxjiang.giveUpAsync(session.uid).nodeify(next);
  239. });
  240. /////TL++,海底捞月
  241. proto.haidilaoyue = P.coroutine(function* (msg, session, next) {
  242. if (!session.uid) {
  243. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  244. }
  245. return this.app.controllers.sxjiang.haiDiLaoYue(session.uid,msg).nodeify(next);
  246. });
  247. /////TL++,操作是否自动出牌
  248. proto.autoOutCard = P.coroutine(function* (msg, session, next) {
  249. if (!session.uid) {
  250. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  251. }
  252. return next(null, { code: C.FAILD, msg: "敬请期待" });
  253. // return this.app.controllers.sxjiang.autoOutCard(session.uid).nodeify(next);
  254. });
  255. // 聊天
  256. proto.chat = P.coroutine(function* (msg, session, next) {
  257. if (!session.uid) {
  258. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  259. }
  260. return this.app.controllers.sxjiang.sendMsgAsync(session.uid, msg).nodeify(next);
  261. });
  262. // 收费聊天
  263. proto.vchat = P.coroutine(function* (msg, session, next) {
  264. if (!session.uid) {
  265. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  266. }
  267. var chairId = parseInt(msg.chairId);
  268. if (!(chairId >= 0)) {
  269. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  270. }
  271. if (!msg.msg) {
  272. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  273. }
  274. return this.app.controllers.sxjiang.vsendMsgAsync(session.uid, chairId, msg.msg).nodeify(next);
  275. });
  276. // 角色信息
  277. proto.roleInfo = P.coroutine(function* (msg, session, next) {
  278. if (!session.uid) {
  279. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  280. }
  281. var chairId = parseInt(msg.chairId);
  282. if (!(chairId >= 0)) {
  283. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  284. }
  285. return this.app.controllers.sxjiang.roleInfoAsync(session.uid, chairId).nodeify(next);
  286. });
  287. // 请求结束
  288. proto.overTable = P.coroutine(function* (msg, session, next) {
  289. if (!session.uid) {
  290. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  291. }
  292. return this.app.controllers.sxjiang.overTableAsync(session.uid).nodeify(next);
  293. });
  294. // 拒绝结束
  295. proto.refuseOver = P.coroutine(function* (msg, session, next) {
  296. if (!session.uid) {
  297. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  298. }
  299. return this.app.controllers.sxjiang.refuseOverAsync(session.uid).nodeify(next);
  300. });
  301. // 同意结束
  302. proto.agreeOver = P.coroutine(function* (msg, session, next) {
  303. if (!session.uid) {
  304. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  305. }
  306. return this.app.controllers.sxjiang.agreeOverAsync(session.uid).nodeify(next);
  307. });