paohuzi.js 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  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 conf = require('../config/games').paohuzi || {};
  7. var User = require('../paohuzi/user');
  8. var Table = require('../paohuzi/table');
  9. var configCommon = require('../../share/configCommon');//////TL++配置相关的公共方法
  10. var logger = quick.logger.getLogger('fhmj', __filename);
  11. /////TL++,下面这几行为了记录用户行为
  12. // var log4js = require("log4js");////cssj
  13. // var log4js_config = require("../logConf.json");
  14. // log4js.configure(log4js_config);
  15. // // console.log("log_start start!");
  16. // var LogFile = log4js.getLogger('log_file',__filename);////cssj
  17. // 金币消耗
  18. const COSTS = conf.crt_costs || {};
  19. // 构造方法
  20. var Controller = function (app) {
  21. this.app = app;
  22. this.id = 10004;
  23. this.lastId = 80000;//桌子号80000
  24. console.warn("湖南跑胡子 游戏服务器启动",app.getServerType(),app.getServerId());
  25. // logger.info("奉化2人 游戏服务器启动",app.getServerType(),app.getServerId());
  26. this.users = {};
  27. this.tables = [];
  28. this.predels = [];
  29. this.keepTm = 1200000;// 20分钟 删除空闲桌子时间
  30. this.lconfigCommon = new configCommon(this.app);
  31. //ts++60秒执行一下
  32. if (app.getServerType() == 'game') setInterval(() => this.checkDelete(), 60000);//this.keepTm / 2
  33. };
  34. // 导出方法
  35. module.exports = function (app) {
  36. return new Controller(app);
  37. };
  38. // 原型对象
  39. var proto = Controller.prototype;
  40. // 创建玩家
  41. proto._createUser = function (player, table) {
  42. //let today = new Date();
  43. //console.warn("创建玩家",today.getTime());
  44. var user = new User(this, player, table);
  45. this.users[user.id] = user;
  46. return user;
  47. };
  48. // 创建桌子 cell底分 round局数
  49. proto._createTable = function (cPlayerId,cUserId,cName,cHead,cell, round, type,gameKindTL,playerAllCount,upId,other,agentId,yxndlbTime,yxndlbTip) {
  50. // this.lastId += _.random(1, 100);////在区间[1,100]内随机取整数 TL++zs yl
  51. this.lastId += _.random(1, 20);
  52. if(this.lastId>=90000)
  53. {
  54. this.lastId=80000;
  55. }
  56. var serverId = this.app.getServerId();
  57. var prefix = serverId.charAt(serverId.length - 2)+serverId.charAt(serverId.length - 1)+ this.lastId;//ts++ game-server-10 取serverID的最后一个字符
  58. //console.warn("创建桌子",prefix,serverId);
  59. // var str3 = "sxjiang 创建桌子Id:"+prefix
  60. // logger.info(str3);////cssj
  61. var table = new Table(cPlayerId,cUserId,cName,cHead,this, prefix , cell, round, type,gameKindTL,playerAllCount,upId,other,agentId,yxndlbTime,yxndlbTip);
  62. this.tables.push(table);
  63. return table;
  64. };
  65. // 删除桌子
  66. proto.deleteTable = function (tableId) {
  67. // console.warn("-------------------删除桌子----------------------",tableId);
  68. // var str3 = "sxjiang 删除桌子Id:"+tableId
  69. // logger.info(str3);////cssj
  70. var index = _.findIndex(this.tables, { id: tableId });
  71. if (-1 != index) {
  72. this.tables.splice(index, 1);
  73. }
  74. };
  75. // // 定时删除
  76. // proto.timeDelete = function (tableId) {
  77. // console.warn("-------------------timeDelete----------------------");
  78. // var pos = _.findIndex(this.predels, { tid: tableId });
  79. // if (pos == -1) {
  80. // this.predels.push({ tid: tableId, time: Date.now() });
  81. // }
  82. // };
  83. // 取消删除
  84. // proto.cancelDelete = function (tableId) {
  85. // var pos = _.findIndex(this.predels, { tid: tableId });
  86. // if (pos != -1) this.predels.splice(pos, 1);
  87. // }
  88. // 检查删除 此方法目前(7月26日)每10分钟调用一次
  89. proto.checkDelete = P.coroutine(function* () {
  90. var date1 = new Date(Date.now());
  91. var date2=date1.toLocaleDateString().replace(/\//g, "-") + " " + date1.toTimeString().substr(0, 8);
  92. // console.warn("检查删除 房间数",this.tables.length,date2);
  93. var nowTime = Date.now();
  94. if (this.tables.length > 0) {
  95. var validTables = [];
  96. for (let i = 0; i < this.tables.length;++i) {
  97. let table = this.tables[i];
  98. if (table.stime ==0 && nowTime - table.ctime >= this.keepTm)
  99. {
  100. // console.warn("tableId ccccc",table);
  101. // let str3 = "sxjiang检查删除validTables"+table.id
  102. // logger.info(str3);////cssj
  103. validTables.push(table);
  104. }
  105. }
  106. // console.warn("删除数:",validTables.length);
  107. if (validTables.length > 0) {
  108. let app = this.app;
  109. return app.memdb.goose.transactionAsync(P.coroutine(function* () {
  110. for (let j = 0; j < validTables.length; ++j) {
  111. // let str3 = "sxjiang检查删除SYSTEMEND"+validTables[j].id
  112. // logger.info(str3);////cssj
  113. yield validTables[j].endResultAsync(Table.ENDMODE.SYSTEMEND);//ts++超时解散
  114. }
  115. }), app.getServerId())
  116. .then(() => app.event.emit('transactionSuccess'), () => app.event.emit('transactionFail'));
  117. }
  118. }
  119. // this.users.forEach((w, c) => {
  120. // if(w.createtime && w.createtime<(nowTime - 1000*60*1)) //90分钟
  121. // {
  122. // console.warn("系统强制退出------------------",w.id);
  123. // this.leaveTableAsync(w.id,true);//系统强制退出
  124. // return;
  125. // console.warn("系统强制退出2222222222222222------------------",w.id);
  126. // }
  127. // });
  128. //
  129. // var nowTime = Date.now();
  130. // var validTables = [];
  131. // for (let i = 0; i < this.predels.length;) {
  132. // let index = _.findIndex(this.tables, { id: this.predels[i].tid });
  133. // if (index != -1) {
  134. // let table = this.tables[index];
  135. // // if (nowTime - this.predels[i].time >= this.keepTm && table.isEmpty()) {
  136. // if (nowTime - this.predels[i].time >= this.keepTm) {
  137. // this.predels.splice(i, 1);
  138. // this.tables.splice(index, 1);
  139. // if (table.over > 0 && !table.isGameOver()) {
  140. // validTables.push(table);
  141. // }
  142. // } else i += 1;
  143. // }
  144. // }
  145. // if (validTables.length > 0) {
  146. // let app = this.app;
  147. // return app.memdb.goose.transactionAsync(P.coroutine(function* () {
  148. // for (let i = 0; i < validTables.length; ++i) {
  149. // yield validTables[i].endResultAsync(Table.ENDMODE.SYSTEMEND);//ts++超时解散
  150. // }
  151. // }), app.getServerId())
  152. // .then(() => app.event.emit('transactionSuccess'), () => app.event.emit('transactionFail'));
  153. // }
  154. });
  155. // 回到桌子
  156. proto.backTableAsync = P.coroutine(function* (user) {
  157. // console.warn("ts+++++回到桌子playerId:%s",user.id);//ts++
  158. // let str3 = "sxjiang回到桌子 "+user.id
  159. // logger.info(str3);////cssj
  160. // 查找玩家
  161. var player = yield this.app.models.Player.findByIdAsync(user.id, 'tableId gameId gameServerId connectorId');
  162. // let str4 = "sxjiang回到33桌子gameServerId "+player.gameServerId+" state "+ user.table.state +" isGameOk "+user.table.isGameOk
  163. // logger.info(str4);////cssj
  164. if (player.gameServerId) {
  165. //console.warn("-------进不来111",player.gameServerId);
  166. return { code: C.FAILD, msg: C.TABLE_HAS_ALREADY };
  167. }
  168. var bDel=false;
  169. var usertable = user.table;
  170. if(!usertable)
  171. {
  172. bDel=true;
  173. //console.warn('=======房间已经不存在了=====删除用户:%s', user.id);
  174. //logger.info('=======房间已经不存在了=====删除用户:%s', user.id);
  175. }
  176. if (!bDel && usertable.state == Table.STATE.END) {
  177. bDel=true;
  178. //console.warn('=======房间已经结束=====删除用户:%s', user.id);
  179. //logger.info('=======房间已经结束=====删除用户:%s', user.id);
  180. }
  181. // 局数完成
  182. if (!bDel && usertable.isGameOk) {
  183. bDel=true;
  184. //console.warn('=======房间局数完成=====删除用户:%s', user.id);
  185. //logger.info('=======房间局数完成=====删除用户:%s', user.id);
  186. }
  187. if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000)
  188. {
  189. bDel=true;
  190. //console.warn('creatOrjoinTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  191. //logger.info('=======断线时间过长了=====删除用户:%s', user.id);
  192. }
  193. if (bDel) {
  194. delete this.users[user.id];
  195. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  196. }
  197. if (player.connectorId) {
  198. user.connectorId = player.connectorId;
  199. }
  200. var res = yield user.table.backAsync(user);
  201. // 保存服务
  202. if (player) {
  203. // let str5 = "sxjiang回到33桌子tableId"+user.table.id
  204. // logger.info(str5);////cssj
  205. player.tableId = user.table.id;
  206. player.gameId = this.id;
  207. player.gameServerId = this.app.getServerId();
  208. yield player.saveAsync();
  209. }
  210. return res;
  211. });
  212. // TL++,得到玩家位置
  213. proto.sendLocationAsync = P.coroutine(function* (playerId,msg) {
  214. //console.warn("得到玩家位置+++++++++playerId:%s",playerId,msg);
  215. // let str4 = "sxjiang得到玩家位置 "+playerId
  216. // logger.info(str4);////cssj
  217. // 查找玩家
  218. var user = this.users[playerId];
  219. if (!user) {
  220. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  221. }
  222. // // 查找桌子
  223. // var table = _.find(this.tables, { id: msg.tableid });
  224. // if (!table) {
  225. // return { code: C.FAILD, msg: C.TABLE_NOT_FOUND };
  226. // }
  227. // let str5 = "sxjiang得到玩家位置end "+playerId
  228. // logger.info(str5);////cssj
  229. return user.table.sendLocationAsync(user,msg);
  230. });
  231. // TL++,判断桌子是否存在 reload=1为重入
  232. proto.isTableExistAsync = P.coroutine(function* (playerId, tableId,reload) {
  233. //console.warn("判断房间是否存在++++:%s,房间号:%s,重入:%d",playerId,tableId,reload);
  234. // let str5 = "sxjiang判断桌子是否存在 "+playerId
  235. // logger.info(str5);////cssj
  236. // 查找玩家
  237. var user = this.users[playerId];
  238. if (user) {//重入优化
  239. var bDel=false;
  240. var usertable = user.table;
  241. if(!usertable)
  242. {
  243. bDel=true;
  244. // let str6 = "sxjiang判断桌子是否存在usertable "+usertable+" state "+usertable.state+" isGameOk "+ usertable.isGameOk
  245. // logger.info(str6);////cssj
  246. //console.warn('=======房间已经不存在了=====删除用户:%s', user.id);
  247. //logger.info('=======房间已经不存在了=====删除用户:%s', user.id);
  248. }
  249. if (!bDel && usertable.state == Table.STATE.END) {
  250. bDel=true;
  251. //console.warn('=======房间已经结束=====删除用户:%s', user.id);
  252. //logger.info('=======房间已经结束=====删除用户:%s', user.id);
  253. }
  254. // 局数完成
  255. if (!bDel && usertable.isGameOk) {
  256. bDel=true;
  257. //console.warn('=======房间局数完成=====删除用户:%s', user.id);
  258. //logger.info('=======房间局数完成=====删除用户:%s', user.id);
  259. }
  260. if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000)
  261. {
  262. bDel=true;
  263. // let str6 = "sxjiang判断桌子是否存在断线时间过长user.id "+user.id
  264. // logger.info(str6);////cssj
  265. // console.warn('isTableExistAsync=======断线时间过长了=====删除用户:%s', user.id);
  266. //logger.info('=======断线时间过长了=====删除用户:%s', user.id);
  267. }
  268. if(!bDel )
  269. {
  270. return { code: C.OK, data: {tid:usertable.id} };
  271. }
  272. else
  273. {
  274. // let str6 = "sxjiang判断桌子是否存在==删除用户user.id "+user.id
  275. // logger.info(str6);////cssj
  276. // console.warn('isTableExistAsync==========删除用户==%s', user.id);
  277. //logger.info('==========删除用户==%s', user.id);
  278. delete this.users[playerId];
  279. }
  280. // if(!bDel)
  281. // {
  282. // if (user.isOffline()) {//断线中可以直接回来页面
  283. // logger.info('==========重入断线中==%s', user.id);
  284. // }
  285. // if(!bDel)
  286. // {
  287. // return { code: C.OK, data: {} };
  288. // }
  289. // }
  290. // logger.info('==========删除用户==%s', user.id);
  291. // delete this.users[playerId];//ts++修改卡桌
  292. // //return { code: C.FAILD, msg: C.TABLE_HAS_ALREADY };
  293. }
  294. // 查找桌子
  295. var table = _.find(this.tables, { id: tableId });
  296. // let str6 = "sxjiang判断桌子是否存在==查找桌子 "
  297. // logger.info(str6);////cssj
  298. if (!table) {
  299. return { code: C.FAILD, msg: C.TABLE_NOT_FOUND };
  300. }
  301. var table = _.find(this.tables, { id: tableId });
  302. // let str7 = "sxjiang222判断桌子是否存在==查找桌子 state"+table.state +" isGameOk "+ table.isGameOk + "isFull" +table.isFull()
  303. // logger.info(str7);////cssj
  304. // 状态结束
  305. if (table.state == Table.STATE.END) {
  306. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  307. }
  308. // 局数完成
  309. if (table.isGameOk) {
  310. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  311. }
  312. // 是否坐满
  313. if (table.isFull()) {
  314. return { code: C.FAILD, msg: C.TABLE_IS_FULL };
  315. }
  316. return { code: C.OK, data: {tid:tableId} };
  317. });
  318. ////TL++创建或者加入桌子,用于玩家通过战绩分享进来之后
  319. proto.creatOrjoinTableAsync = P.coroutine(function* (playerId, round,type, kind,playercount,upId,other,agentId) {
  320. // let str6 = "sxjiang创建或者加入桌子 "+playerId+ " "+ round+ " "+type+ " "+ kind+ " "+playercount+ " "+upId+ " "+other+ " "+agentId
  321. // logger.info(str6);////cssj
  322. // let str64 = "sxjiang创建或者加入桌子 "+ typeof(playerId)+ " "+ typeof(round)+ " "+typeof(type)+ " "+ typeof(kind)+ " "+typeof(playercount)+ " "+typeof(upId)+ " "+typeof(other)+ " "+typeof(agentId)
  323. // logger.info(str64);////cssj
  324. // console.warn("创建或者加入桌子,用于玩家通过战绩分享进来之后:%s",playerId);//ts++
  325. // console.warn(str6);
  326. // console.warn(str64);
  327. let player = yield this.app.models.Player.findByIdReadOnlyAsync(playerId, 'diamond userId name headurl');
  328. let cUserId = String(player.userId);
  329. let cName = String(player.name);
  330. let cHead = String(player.headurl);
  331. //// 检查推广黑白名单功能,判断玩家是否可以进入(创建或者加入桌子)
  332. let chekRes = yield this.checkAgreeInfo(playerId,agentId,cUserId,cName,cHead);
  333. if(chekRes.code != C.OK){
  334. return chekRes;
  335. }
  336. // 查找玩家
  337. var user = this.users[playerId];
  338. if (user) {
  339. var bDel=false;
  340. var usertable = user.table;
  341. if(!usertable)
  342. {
  343. bDel=true;
  344. //console.warn('=======房间已经不存在了=====删除用户:%s', user.id);
  345. // logger.info('creatOrjoinTableAsync=======房间已经不存在了=====删除用户:%s', user.id);
  346. }
  347. if (!bDel && usertable.state == Table.STATE.END) {
  348. bDel=true;
  349. //console.warn('=======房间已经结束=====删除用户:%s', user.id);
  350. // logger.info('creatOrjoinTableAsync=======房间已经结束=====删除用户:%s', user.id);
  351. }
  352. // 局数完成
  353. if (!bDel && usertable.isGameOk) {
  354. bDel=true;
  355. //console.warn('=======房间局数完成=====删除用户:%s', user.id);
  356. // logger.info('creatOrjoinTableAsync=======房间局数完成=====删除用户:%s', user.id);
  357. }
  358. if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000)
  359. {
  360. bDel=true;
  361. //console.warn('creatOrjoinTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  362. // logger.info('creatOrjoinTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  363. }
  364. if(bDel)
  365. {
  366. delete this.users[playerId];
  367. // logger.info('creatOrjoinTableAsync==========删除用户==%s', user.id);
  368. }
  369. else
  370. {
  371. return this.backTableAsync(user);
  372. }
  373. }
  374. // console.warn("得到下一局的信息查找桌子不存在就创建",data);
  375. // var table = _.find(this.tables, { upId: data.upId });
  376. var table = _.find(this.tables, { upId: upId });
  377. if (!table)
  378. {
  379. // var agentId=data.agentId || "";
  380. var agentId=agentId || "";
  381. // console.warn("ts++下一局----------------新建");
  382. // return this.createTableAsync(playerId, data.round, 0,data.kind,data.playercount,data.upId,data.other,agentId);
  383. return this.createTableAsync(playerId, round, type,kind,playercount,upId,other,agentId);
  384. }
  385. else
  386. {
  387. // console.warn("ts++下一局----------------加入:"+table.id);
  388. return this.joinTableAsync(playerId, table.id);
  389. }
  390. });
  391. // 加入桌子
  392. proto.joinTableAsync = P.coroutine(function* (playerId, tableId) {
  393. // console.warn("sxjiang加入桌子playerId: "+playerId+" ,tableId: "+tableId);
  394. // let str6 = "sxjiang加入桌子playerId:"+playerId+",tableId:"+tableId;
  395. // logger.info(str6);////cssj
  396. ////检查是否维护状态
  397. let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'stateWH whTip');
  398. // console.warn("22检查是否维护状态",whdata);
  399. if (whdata) {
  400. // console.warn("--33检查是否维护状态",whdata.stateWH,whdata.whTip);
  401. if(whdata.stateWH){
  402. /////维护状态中
  403. return { code: C.FAILD, tip: whdata.whTip };
  404. }
  405. }
  406. else{
  407. // console.warn("创建数据库");
  408. // var whsj = new this.app.models.WHstate({
  409. // _id: 'wh',
  410. // stateWH: 0,
  411. // whTip: '游戏正在维护,请稍后创建房间',
  412. // rebaterate: 60
  413. // });
  414. // yield whsj.saveAsync();
  415. // console.warn("检查是否维护状态");
  416. }
  417. // 查找玩家
  418. var user = this.users[playerId];
  419. if (user) {
  420. var bDel=false;
  421. var usertable = user.table;
  422. if(!usertable)
  423. {
  424. bDel=true;
  425. //console.warn('=======房间已经不存在了=====删除用户:%s', user.id);
  426. // logger.info('joinTableAsync=======房间已经不存在了=====删除用户:%s', user.id);
  427. }
  428. if (!bDel && usertable.state == Table.STATE.END) {
  429. bDel=true;
  430. //console.warn('=======房间已经结束=====删除用户:%s', user.id);
  431. // logger.info('joinTableAsync=======房间已经结束=====删除用户:%s', user.id);
  432. }
  433. // 局数完成
  434. if (!bDel && usertable.isGameOk) {
  435. bDel=true;
  436. //console.warn('=======房间局数完成=====删除用户:%s', user.id);
  437. // logger.info('joinTableAsync=======房间局数完成=====删除用户:%s', user.id);
  438. }
  439. if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000)
  440. {
  441. bDel=true;
  442. //console.warn('creatOrjoinTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  443. // logger.info('joinTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  444. }
  445. if (bDel) {
  446. delete this.users[user.id];
  447. if(usertable.id==tableId)
  448. {
  449. return { code: C.FAILD, msg: C.TABLE_NOT_FOUND };
  450. }
  451. }
  452. else
  453. {
  454. return this.backTableAsync(user);
  455. }
  456. }
  457. // 查找桌子
  458. var table = _.find(this.tables, { id: tableId });
  459. if (!table) {
  460. return { code: C.FAILD, msg: C.TABLE_NOT_FOUND };
  461. }
  462. // table.agentId 数据库中agenter(推广员)数据表的主键(_id)
  463. // console.warn("=======加入桌子==table "+ table.agentId+ " playerId "+playerId);
  464. let player2 = yield this.app.models.Player.findByIdReadOnlyAsync(playerId, 'diamond userId name headurl');
  465. let cUserId = String(player2.userId);/////TL++房主
  466. let cName = String(player2.name);/////TL++房主
  467. let cHead = String(player2.headurl);/////TL++房主
  468. //// 检查推广黑白名单功能,判断玩家是否可以进入(加入桌子)
  469. let chekRes = yield this.checkAgreeInfo(playerId,table.agentId,cUserId,cName,cHead);
  470. if(chekRes.code != C.OK){
  471. return chekRes;
  472. }
  473. // delete require.cache[require.resolve('../../share/configCommon')];
  474. // configCommon = require('../../share/configCommon');
  475. // this.lconfigCommon = new configCommon(this.app);
  476. // console.warn("加入房间 table.agentId "+table.agentId+" table.isNeverStart "+table.isNeverStart)
  477. let chekRes2 = yield this.lconfigCommon.checkIsCanJoin(this.id,table.agentId,2);
  478. if(chekRes2.code != C.OK){
  479. // console.warn("加入房间 不在比赛期间内 table.isNeverStart "+table.isNeverStart)
  480. // return chekRes2;
  481. if(table.isNeverStart){
  482. return chekRes2;//不在比赛期间内,而且游戏从未开始过,不让进去
  483. }
  484. }
  485. // 状态结束
  486. if (table.state == Table.STATE.END) {
  487. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  488. }
  489. // 局数完成
  490. if (table.isGameOk) {
  491. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  492. }
  493. // 是否坐满
  494. if (table.isFull()) {
  495. return { code: C.FAILD, msg: C.TABLE_IS_FULL };
  496. }
  497. // 查找玩家
  498. var player = yield this.app.models.Player.findByIdAsync(playerId, 'account userId name sex headurl tableId gameId gameServerId connectorId diamond cost spreadId registerTime lastLoginTime');
  499. if (player.gameServerId) {
  500. //console.warn("-------进不来666",player.gameServerId);
  501. return { code: C.FAILD, msg: C.TABLE_HAS_ALREADY };
  502. }
  503. // 创建玩家
  504. var user = this._createUser(player, table);
  505. // 加入桌子
  506. //logger.info('==========joinTableAsync==%s', playerId);
  507. var res = yield table.joinAsync(user);
  508. // 保存服务
  509. if (player) {
  510. player.tableId = tableId;
  511. player.rTableId = parseInt(tableId);//ts++重入时使用
  512. player.gameId = this.id;
  513. player.gameServerId = this.app.getServerId();
  514. yield player.saveAsync();
  515. }
  516. // let str1 = "sxjiang 22加入桌子 "+playerId;
  517. // logger.info(str1);////cssj
  518. return res;
  519. });
  520. ////检查推广黑白名单功能
  521. proto.checkAgreeInfo = P.coroutine(function* (playerId,agentId,cUserId,cName,cHead) {
  522. // console.warn("检查推广黑白名单功能11 "+playerId);
  523. ////查询该推广员的白名单信息 检查玩家是否处于该推广员的白名单中,如果已经得到同意才能创建和加入房间
  524. // var agentId = "xxxx"//_agentId
  525. if(!agentId) return { code: C.OK};
  526. var agreeInfo = yield this.app.models.AgenterAgree.findByIdReadOnlyAsync(agentId, '_id isOpenAgree infoList');
  527. if (agreeInfo) {
  528. // console.warn("该推广有白名单信息 ");
  529. // console.warn("该推广有白名单信息00 +agreeInfo.infoList "+" isOpenAgree "+agreeInfo.isOpenAgree );
  530. let isInAgreeInfoList = false;
  531. let isAgreedPlayer = false;//该玩家是否被同意
  532. //只要该玩家被拒绝,无论同意功能是否开启该玩家都不能进入
  533. for (var i = agreeInfo.infoList.length - 1; i >= 0; i--) {
  534. if(agreeInfo.infoList[i].playerId == playerId){
  535. isInAgreeInfoList = true;
  536. isAgreedPlayer = agreeInfo.infoList[i].agreeState == "1";
  537. if(agreeInfo.infoList[i].agreeState == "2"){
  538. return { code: C.FAILD, msg: "您已被推广员拒绝" };
  539. }
  540. break;
  541. }
  542. }
  543. // console.warn("该推广有白名单信息22 改玩家未被拒绝 "+" isOpenAgree "+agreeInfo.isOpenAgree + " isInAgreeInfoList "+isInAgreeInfoList);
  544. //如果功能开启,
  545. if(agreeInfo.isOpenAgree == "1"){
  546. if(!isInAgreeInfoList){
  547. //此玩家未记录在同意或拒绝信息列表中则将该玩家加入待同意名单
  548. agreeInfo.infoList.push({
  549. _id: playerId,
  550. playerId: playerId,
  551. agreeState:'0',
  552. userId: cUserId,
  553. name: cName,
  554. headurl: cHead
  555. });
  556. yield agreeInfo.saveAsync();
  557. // console.warn(" 功能开启 此玩家未记录 ");
  558. return { code: C.FAILD, msg: "等待推广员同意" };
  559. }
  560. else{
  561. // console.warn(" 功能开启 此玩家已经有记录 不是拒绝也不是同意 ");
  562. //此玩家以记录在同意或待同意信息列表中,则判断该玩家能否进入游戏
  563. if(!isAgreedPlayer){
  564. return { code: C.FAILD, msg: "等待推广员同意2" };
  565. }
  566. }
  567. }
  568. }
  569. else{
  570. // console.warn("该推广尚未有白名单信息则创建该推广的白名单信息");
  571. //该推广尚未有白名单信息则创建该推广的默认白名单信息
  572. var agenteragree = new this.app.models.AgenterAgree({
  573. _id: agentId,//记录
  574. isOpenAgree: "0",
  575. infoList: []
  576. });
  577. // console.warn("agenteragree new",agenteragree);
  578. yield agenteragree.saveAsync();
  579. }
  580. return { code: C.OK};
  581. });
  582. // 创建桌子
  583. proto.createTableAsync = P.coroutine(function* (playerId, round, type,gameKind,playerAllCount,upId,other,agentId) {
  584. //console.warn("创建桌子+++++++++代理:%s",agentId);
  585. // let str6 = "sxjiang 创建桌子 "+playerId+" "+ round+" "+ type+" "+gameKind+" "+playerAllCount+" "+upId+" "+other+" "+agentId;
  586. // logger.info(str6);////cssj
  587. // let str65 = "sxjiang 创建桌子 "+typeof(playerId)+" "+ typeof(round)+" "+ typeof(type)+" "+typeof(gameKind)+" "+typeof(playerAllCount)+" "+typeof(upId)+" "+typeof(other)+" "+typeof(agentId);
  588. // logger.info(str65);////cssj
  589. // console.warn(str6);
  590. // console.warn(str65);
  591. // 已有桌子
  592. // if (this.users[playerId]) {
  593. // // console.warn("-------进不来777",this.users[playerId]);
  594. // delete this.users[playerId];//ts++修改卡桌
  595. // //return { code: C.FAILD, msg: C.TABLE_HAS_ALREADY };
  596. // }
  597. ////检查是否维护状态
  598. let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'stateWH whTip yxndlbTime yxndlbTip');
  599. // console.warn("22检查是否维护状态",whdata);
  600. if (whdata) {
  601. // console.warn("--33检查是否维护状态",whdata.stateWH,whdata.whTip);
  602. if(whdata.stateWH){
  603. /////维护状态中
  604. return { code: C.FAILD, tip: whdata.whTip };
  605. }
  606. }
  607. else{
  608. // console.warn("创建数据库");
  609. // var whsj = new this.app.models.WHstate({
  610. // _id: 'wh',
  611. // stateWH: 0,
  612. // whTip: '游戏正在维护,请稍后创建房间',
  613. // rebaterate: 60
  614. // });
  615. // yield whsj.saveAsync();
  616. // console.warn("检查是否维护状态");
  617. }
  618. // console.warn("44检查是否维护状态",whdata.stateWH,whdata.whTip);
  619. var user = this.users[playerId];
  620. if (user) {
  621. var bDel=false;
  622. var usertable = user.table;
  623. if(!usertable)
  624. {
  625. bDel=true;
  626. //console.warn('=======房间已经不存在了=====删除用户:%s', user.id);
  627. // logger.info('createTableAsync=======房间已经不存在了=====删除用户:%s', user.id);
  628. }
  629. if (!bDel && usertable.state == Table.STATE.END) {
  630. bDel=true;
  631. //console.warn('=======房间已经结束=====删除用户:%s', user.id);
  632. // logger.info('createTableAsync=======房间已经结束=====删除用户:%s', user.id);
  633. }
  634. // 局数完成
  635. if (!bDel && usertable.isGameOk) {
  636. bDel=true;
  637. //console.warn('=======房间局数完成=====删除用户:%s', user.id);
  638. // logger.info('createTableAsync=======房间局数完成=====删除用户:%s', user.id);
  639. }
  640. if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000)
  641. {
  642. bDel=true;
  643. //console.warn('createTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  644. // logger.info('createTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  645. }
  646. if(bDel)
  647. {
  648. delete this.users[playerId];
  649. // logger.info('createTableAsync==========删除用户==%s', user.id);
  650. }
  651. else
  652. {
  653. return this.backTableAsync(user);
  654. }
  655. }
  656. // 金币消耗 /////TLzs8月6号,创房间不做钻石限制
  657. // var num_cost = parseInt(COSTS[round]);
  658. // if(gameKind == 2){
  659. // num_cost = 90;//////冲刺扣90
  660. // }
  661. // var crt_cost = num_cost >= 0 ? num_cost : round * 10;
  662. // if (crt_cost > 0) {
  663. // let player = yield this.app.models.Player.findByIdAsync(playerId, 'diamond cost');
  664. // if (!player || player.diamond < crt_cost) {
  665. // return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW };
  666. // }
  667. // // player.diamond -= crt_cost;
  668. // // player.cost += crt_cost;
  669. // // yield player.saveAsync();
  670. // }
  671. // 创建桌子
  672. //logger.info('==========createTableAsync==%s', playerId);
  673. /////// 判断一个玩家是否还能再创建房间,限制每个玩家只能最多创建10个游戏未开始的房间
  674. let today = new Date();
  675. let time =today.getTime() -1200000;
  676. //let opts = {registerTime: { $gte: time},playerId: playerId};
  677. //let count = yield this.app.models.CTableRecord.countMongoAsync(opts)
  678. let opts = {ctime: { $gte: time},ownerId: playerId};
  679. let count = yield this.app.models.GameTable.countMongoAsync(opts)
  680. if(count >= 50){
  681. return { code: C.FAILD, msg: C.TABLE_CREATETOOMUCH };
  682. }
  683. let player = yield this.app.models.Player.findByIdReadOnlyAsync(playerId, 'diamond userId name headurl');
  684. // if (!player || player.diamond < crt_cost) {/////TLzs8月6号,创房间不做钻石限制
  685. // return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW };
  686. // }
  687. let cUserId = String(player.userId);/////TL++房主
  688. let cName = String(player.name);/////TL++房主
  689. let cHead = String(player.headurl);/////TL++房主
  690. //// 检查推广黑白名单功能,判断玩家是否可以进入(创建桌子)
  691. let chekRes = yield this.checkAgreeInfo(playerId,agentId,cUserId,cName,cHead);
  692. if(chekRes.code != C.OK){
  693. return chekRes;
  694. }
  695. // delete require.cache[require.resolve('../../share/configCommon')];
  696. // configCommon = require('../../share/configCommon');
  697. // this.lconfigCommon = new configCommon(this.app);
  698. let chekRes2 = yield this.lconfigCommon.checkIsCanJoin(this.id,agentId,1);
  699. if(chekRes2.code != C.OK){
  700. return chekRes2;
  701. }
  702. ////////创建游戏桌子
  703. let cell=1;//底分
  704. let yxndlbTime = 6000;
  705. if(whdata && whdata.yxndlbTime) yxndlbTime = whdata.yxndlbTime;
  706. let yxndlbTip = "";
  707. if(whdata && whdata.yxndlbTip) yxndlbTip = whdata.yxndlbTip;
  708. var table = this._createTable(playerId,cUserId,cName,cHead,cell, round, type,gameKind,playerAllCount,upId,other,agentId,yxndlbTime,yxndlbTip);
  709. //this.timeDelete(table.id);/////TL++,在桌子创建的时候设置20分钟后删除桌子
  710. //ts++ 房间创建记录
  711. // var ctablerecord = new this.app.models.CTableRecord({
  712. // _id: table.recordid,
  713. // playerId: playerId
  714. // });
  715. // let str5 = "sxjiang 2222创建桌子 ,"+playerId;
  716. // logger.info(str5);////cssj
  717. // yield ctablerecord.saveAsync();
  718. var gametable = new this.app.models.GameTable({
  719. _id: table.recordid,//记录
  720. tableNo: table.id,
  721. ownerId: table.ownerId,
  722. agentId: table.agentId,
  723. type: table.type,
  724. kind: table.gameKindTL,//玩法 2冲刺
  725. other: table.other,//////TL++2人3人的游戏规则
  726. playerCount: table.playerAllCount,//游戏人数
  727. round: table.round,//
  728. over: table.over,//游戏局数
  729. ctime: table.ctime,//创建时间
  730. // stime: 0,//开始时间
  731. // time: 0,//结束时间
  732. endMode: 0//结束类型
  733. // gameCost: 0,//游戏消耗
  734. // agentRebate: 0//代理返利
  735. });
  736. yield gametable.saveAsync();
  737. // console.warn("创建房间",table.id);
  738. // 加入桌子
  739. return this.joinTableAsync(playerId, table.id);
  740. });
  741. // 离开桌子
  742. proto.leaveTableAsync = P.coroutine(function* (playerId, isOffline) {
  743. //console.warn("sxjiang 离开桌子==%s",playerId);
  744. // logger.info("sxjiang 离开桌子==%s",playerId);
  745. var userdel = false;//ts++删除用户
  746. // 内存离开
  747. var user = this.users[playerId];
  748. if (user) {
  749. //console.warn('sxjiang 内存玩家==%s,状态%d',playerId,user.state);
  750. // logger.info('sxjiang 内存玩家==%s,状态%d',playerId,user.state);
  751. if (!user.isPlaying()) {
  752. //console.warn("离开桌子+++++用户空闲中");
  753. user.state = User.STATE.FREE;
  754. yield user.table.leaveAsync(user);
  755. delete this.users[playerId];
  756. userdel = true;
  757. //logger.info('sxjiang 玩家删除==%s', playerId);
  758. } else {
  759. //console.warn("离开桌子+++++用户游戏中");
  760. if (user.isOffline()) {
  761. return { code: C.OK };
  762. }
  763. //console.warn("离开桌子+++++提示玩家断线");
  764. yield user.table.offlineAsync(user);
  765. //logger.info('sxjiang 玩家断线==%s', playerId);
  766. //return { code: C.OK };//ts++游戏开始后不让退出房间
  767. }
  768. //console.warn("offlineAsync+++++状态%d",user.state);//ts++
  769. }
  770. // 置空服务
  771. //if (!isOffline) {
  772. let player = yield this.app.models.Player.findByIdAsync(playerId, 'tableId rTableId gameId gameServerId');
  773. //if (player && player.gameServerId) {
  774. //ts++upd
  775. if (player) {
  776. //console.warn("sxjiang 用户信息==",player);////css
  777. if(userdel)//ts++删除用户 重入后清空
  778. {
  779. player.rTableId = 0;
  780. }
  781. //console.warn("在这里指控了服务");
  782. player.tableId = '';
  783. player.gameId = 0;
  784. player.gameServerId = '';
  785. yield player.saveAsync();
  786. }
  787. //}
  788. //console.warn("sxjiang 离开成功==%s",playerId);
  789. // logger.info("sxjiang 离开成功==%s",playerId);
  790. return { code: C.OK };
  791. });
  792. // 坐下桌子
  793. proto.seatAsync = P.coroutine(function* (playerId, chairId) {
  794. // console.warn("坐下桌子+++++++++playerId:%s",playerId);
  795. // let str5 = "sxjiang 坐下桌子 "+playerId;
  796. // logger.info(str5);////cssj
  797. // 查找玩家
  798. var user = this.users[playerId];
  799. if (!user) {
  800. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  801. }
  802. // 状态校验
  803. if (user.state > User.STATE.READY) {
  804. return { code: C.FAILD, msg: C.PLAYER_NOT_FREE };
  805. }
  806. var table = user.table;
  807. if (table.state != Table.STATE.FREE) {
  808. return { code: C.FAILD, msg: C.TABLE_NOT_FREE };
  809. }
  810. // 局数完成
  811. if (table.isGameOk) {
  812. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  813. }
  814. // let str4 = "sxjiang 222坐下桌子 "+playerId;
  815. // logger.info(str4);////cssj
  816. return table.seatAsync(user, chairId);
  817. });
  818. // 站起桌子
  819. proto.standAsync = P.coroutine(function* (playerId) {
  820. // console.warn("站起桌子+++++++++playerId:%s",playerId);
  821. // let str5 = "sxjiang 站起桌子 "+playerId;
  822. // logger.info(str5);////cssj
  823. // 查找玩家
  824. var user = this.users[playerId];
  825. if (!user) {
  826. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  827. }
  828. // 状态校验
  829. if (user.state > User.STATE.READY) {
  830. return { code: C.FAILD, msg: C.PLAYER_NOT_FREE };
  831. }
  832. var table = user.table;
  833. if (table.state != Table.STATE.FREE) {
  834. return { code: C.FAILD, msg: C.TABLE_NOT_FREE };
  835. }
  836. // let str6 = "sxjiang 222站起桌子 "+playerId;
  837. // logger.info(str6);////cssj
  838. return table.standAsync(user);
  839. });
  840. // 准备
  841. proto.readyGameAsync = P.coroutine(function* (playerId) {
  842. // console.warn("准备+++++++++playerId:%s",playerId);
  843. // let str5 = "sxjiang 准备 "+playerId;
  844. // logger.info(str5);////cssj
  845. // 查找玩家
  846. var user = this.users[playerId];
  847. if (!user) {
  848. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  849. }
  850. if (user.chairId == -1) {
  851. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  852. }
  853. if (user.table.state == Table.STATE.FREE2) //ts++二次准备状态
  854. {
  855. // 状态校验
  856. if (user.state2 != User.STATE.FREE) {
  857. return { code: C.FAILD, msg: C.PLAYER_NOT_FREE };
  858. }
  859. }
  860. else
  861. {
  862. // 状态校验
  863. if (user.state != User.STATE.FREE) {
  864. return { code: C.FAILD, msg: C.PLAYER_NOT_FREE };
  865. }
  866. if (user.table.state != Table.STATE.FREE) {
  867. return { code: C.FAILD, msg: C.TABLE_NOT_FREE };
  868. }
  869. }
  870. // 局数完成
  871. if (user.table.isGameOk) {
  872. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  873. }
  874. // let str6 = "sxjiang 22准备 "+playerId;
  875. // logger.info(str6);////cssj
  876. return user.table.readyGameAsync(user);
  877. });
  878. // 开始游戏
  879. proto.startGameAsync = P.coroutine(function* (playerId) {
  880. // console.warn("开始游戏+++++++++playerId:%s",playerId);
  881. // let str6 = "sxjiang 开始游戏 "+playerId;
  882. // logger.info(str6);////cssj
  883. // 查找玩家
  884. var user = this.users[playerId];
  885. if (!user) {
  886. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  887. }
  888. if (user.chairId == -1) {
  889. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  890. }
  891. // 状态校验
  892. var table = user.table;
  893. if (table.state != Table.STATE.FREE) {
  894. return { code: C.FAILD, msg: C.TABLE_NOT_FREE };
  895. }
  896. // 是否房主
  897. if (!user.isOwner()) {
  898. return { code: C.FAILD, msg: C.TABLE_NOT_OWNER };
  899. }
  900. // 局数完成
  901. if (table.isGameOk) {
  902. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  903. }
  904. // 是否准备
  905. if (!table.isReady()) {
  906. return { code: C.FAILD, msg: C.TABLE_NOT_READY };
  907. }
  908. // let str5 = "sxjiang 222开始游戏 "+playerId;
  909. // logger.info(str5);////cssj
  910. return table.startGameAsync();
  911. });
  912. // 调整牌
  913. proto.adjustCardAsync = P.coroutine(function* (playerId, isfy,card,oldIndex,newIndex) {
  914. // console.warn("调整牌+++++++++playerId:%s",playerId);
  915. // let str5 = "sxjiang 调整牌 "+playerId+"==card "+card;
  916. // logger.info(str5);////cssj
  917. // 查找玩家
  918. var user = this.users[playerId];
  919. if (!user) {
  920. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  921. }
  922. if (user.chairId == -1) {
  923. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  924. }
  925. // 状态校验
  926. if (user.state !== User.STATE.PLAYING) {
  927. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  928. }
  929. if (user.table.state !== Table.STATE.PLAYING) {
  930. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  931. }
  932. // let str6 = "sxjiang 22调整牌 "+playerId+" card "+card
  933. // logger.info(str6);////cssj
  934. return user.table.adjustCardAsync(user.chairId, isfy,card,oldIndex,newIndex);
  935. });
  936. // 出牌处理
  937. proto.outCardAsync = P.coroutine(function* (playerId, card,oldIndex) {
  938. // console.warn("出牌处理+++++++++playerId:%s",playerId);
  939. // let str5 = "sxjiang 出牌处理 "+playerId+"==card "+card;
  940. // logger.info(str5);////cssj
  941. // 查找玩家
  942. var user = this.users[playerId];
  943. if (!user) {
  944. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  945. }
  946. if (user.chairId == -1) {
  947. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  948. }
  949. // 状态校验
  950. if (user.state !== User.STATE.PLAYING) {
  951. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  952. }
  953. if (user.table.state !== Table.STATE.PLAYING) {
  954. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  955. }
  956. let isCanOut = false;//是否允许手动出牌
  957. let cpres = user.table.getIsCanOut();
  958. _.forEach(cpres, function(value, key) {
  959. // console.warn("key "+key+" value "+JSON.stringify(value));
  960. if(key == "_settledValue"){
  961. if(value && value.isCanOut && value.isCanOut == true){
  962. isCanOut = true;
  963. }
  964. return;
  965. }
  966. })
  967. console.warn("获得是否允许手动出牌 ",isCanOut,user.chairId, card,oldIndex);
  968. if (!isCanOut) return { code: C.FAILD, msg: C.TABLE_TURN_ERROR };
  969. // let str6 = "sxjiang 22出牌处理 "+playerId+" card "+card
  970. // logger.info(str6);////cssj
  971. return user.table.outCardAsync(user.chairId, card,oldIndex);
  972. });
  973. // 杠牌处理,1-普通杠, 2-暗杠, 3-自摸明杠
  974. proto.gangCardAsync = P.coroutine(function* (playerId, card, type) {
  975. // console.warn("杠牌处理+++++++++playerId:%s",playerId);
  976. // let str6 = "sxjiang 杠牌处理, "+playerId+"==card "+card;
  977. // logger.info(str6);////cssj
  978. // 查找玩家
  979. var user = this.users[playerId];
  980. if (!user) {
  981. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  982. }
  983. if (user.chairId == -1) {
  984. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  985. }
  986. // 状态校验
  987. if (user.state !== User.STATE.PLAYING) {
  988. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  989. }
  990. if (user.table.state !== Table.STATE.PLAYING) {
  991. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  992. }
  993. // let str5 = "sxjiang 22杠牌处理, "+playerId+"==card "+card
  994. // logger.info(str5);////cssj
  995. return user.table.gangCardAsync(user.chairId, card, type);
  996. });
  997. // 碰牌处理
  998. proto.pengCardAsync = P.coroutine(function* (playerId, card) {
  999. // console.warn("碰牌处理+++++++++playerId:%s",playerId);
  1000. // let str5 = "sxjiang 碰牌处理 "+playerId+"==card "+card;
  1001. // logger.info(str5);////cssj
  1002. // 查找玩家
  1003. var user = this.users[playerId];
  1004. if (!user) {
  1005. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1006. }
  1007. if (user.chairId == -1) {
  1008. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1009. }
  1010. // 状态校验
  1011. if (user.state !== User.STATE.PLAYING) {
  1012. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1013. }
  1014. if (user.table.state !== Table.STATE.PLAYING) {
  1015. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1016. }
  1017. // let str3 = "sxjiang 22碰牌处理 "+playerId+"==card "+card;
  1018. // logger.info(str3);////cssj
  1019. return user.table.pengCardAsync(user.chairId, card);
  1020. });
  1021. // 吃牌处理,1-@**左吃, 2-*@*中吃, 3-@**右吃
  1022. proto.eatCardAsync = P.coroutine(function* (playerId, card, type, bi1Type, bi2Type) {
  1023. console.warn("吃牌处理+++++++++playerId:%s",playerId);
  1024. // let str2 = "sxjiang 吃牌处理, "+playerId+"==card "+card;
  1025. // logger.warn(str2);////cssj
  1026. // 查找玩家
  1027. var user = this.users[playerId];
  1028. if (!user) {
  1029. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1030. }
  1031. if (user.chairId == -1) {
  1032. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1033. }
  1034. // 状态校验
  1035. if (user.state !== User.STATE.PLAYING) {
  1036. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1037. }
  1038. if (user.table.state !== Table.STATE.PLAYING) {
  1039. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1040. }
  1041. // let str1 = "sxjiang 222吃牌处理, "+playerId+"==card "+card
  1042. // logger.info(str1);////cssj
  1043. return user.table.eatCardAsync(user.chairId, card, type, bi1Type, bi2Type);
  1044. });
  1045. // 胡牌处理,1-自摸, 2-点炮
  1046. proto.succCardAsync = P.coroutine(function* (playerId) {
  1047. // console.warn("胡牌处理+++++++++playerId:%s",playerId);
  1048. // let str1 = "sxjiang 胡牌处理,"+playerId;
  1049. // logger.info(str1);////cssj
  1050. // 查找玩家
  1051. var user = this.users[playerId];
  1052. if (!user) {
  1053. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1054. }
  1055. if (user.chairId == -1) {
  1056. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1057. }
  1058. // 状态校验
  1059. if (user.state !== User.STATE.PLAYING) {
  1060. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1061. }
  1062. if (user.table.state !== Table.STATE.PLAYING) {
  1063. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1064. }
  1065. // let str2 = "sxjiang 22胡牌处理,"+playerId;
  1066. // logger.info(str2);////cssj
  1067. return user.table.succCardAsync(user.chairId);
  1068. });
  1069. // 放弃吃碰杠胡
  1070. proto.giveUpAsync = P.coroutine(function* (playerId) {
  1071. // console.warn("放弃吃碰杠胡+++++++++playerId:%s",playerId);
  1072. // let str1 = "sxjiang 放弃吃碰杠胡 "+playerId;
  1073. // logger.info(str1);////cssj
  1074. // 查找玩家
  1075. var user = this.users[playerId];
  1076. if (!user) {
  1077. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1078. }
  1079. if (user.chairId == -1) {
  1080. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1081. }
  1082. // 状态校验
  1083. if (user.state !== User.STATE.PLAYING) {
  1084. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1085. }
  1086. if (user.table.state !== Table.STATE.PLAYING) {
  1087. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1088. }
  1089. // let str2 = "sxjiang 放弃吃碰杠胡 "+playerId;
  1090. // logger.info(str2);////cssj
  1091. return user.table.giveUpAsync(user.chairId);
  1092. });
  1093. // //////TL++,是否进行海底捞月的操作
  1094. proto.haiDiLaoYue = P.coroutine(function* (playerId,type) {
  1095. // console.warn("是否进行海底捞月的操作+++++++++playerId:%s",playerId);
  1096. // let str1 = "sxjiang 是否进行海底捞月的操作 "+playerId;
  1097. // logger.info(str1);////cssj
  1098. // 查找玩家
  1099. var user = this.users[playerId];
  1100. if (!user) {
  1101. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1102. }
  1103. if (user.chairId == -1) {
  1104. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1105. }
  1106. // 状态校验
  1107. if (user.state !== User.STATE.PLAYING) {
  1108. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1109. }
  1110. if (user.table.state !== Table.STATE.PLAYING) {
  1111. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1112. }
  1113. // let str2 = "sxjiang 22是否进行海底捞月的操作 "+playerId;
  1114. // logger.info(str2);////cssj
  1115. return user.table.haiDiLaoYue(user.chairId,type);
  1116. });
  1117. // 操作是否自动出牌
  1118. proto.autoOutCard = P.coroutine(function* (playerId) {
  1119. // console.warn("操作是否自动出牌+++++++++playerId:%s",playerId);
  1120. // let str1 = "csjiang 操作是否自动出牌 "+playerId;
  1121. // logger.info(str1);////cssj
  1122. // 查找玩家
  1123. var user = this.users[playerId];
  1124. if (!user) {
  1125. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1126. }
  1127. if (user.chairId == -1) {
  1128. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1129. }
  1130. // 状态校验
  1131. if (user.state !== User.STATE.PLAYING) {
  1132. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1133. }
  1134. if (user.table.state !== Table.STATE.PLAYING) {
  1135. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1136. }
  1137. // let str2 = "csjiang 操作是否自动出牌 "+playerId;
  1138. // logger.info(str2);////cssj
  1139. return user.table.autoOutCardAsync(user.chairId);
  1140. });
  1141. // 发送聊天
  1142. proto.sendMsgAsync = P.coroutine(function* (playerId, msg) {
  1143. // console.warn("发送聊天+++++++++playerId:%s",playerId);
  1144. // let str2 = "sxjiang 发送聊天 "+playerId;
  1145. // logger.info(str2);////cssj
  1146. // 查找玩家
  1147. var user = this.users[playerId];
  1148. if (!user) {
  1149. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1150. }
  1151. if (!user.table) {
  1152. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1153. }
  1154. // let str1 = "sxjiang 222发送聊天 "+playerId;
  1155. // logger.info(str1);////cssj
  1156. return user.table.sendMsgAsync(user.chairId, msg);
  1157. });
  1158. // 收费聊天
  1159. proto.vsendMsgAsync = P.coroutine(function* (playerId, chairId, msg) {
  1160. // console.warn("收费聊天+++++++++playerId:%s",playerId);
  1161. // let str1 = "sxjiang 收费聊天 "+playerId;
  1162. // logger.info(str1);////cssj
  1163. // 查找玩家
  1164. var user = this.users[playerId];
  1165. if (!user) {
  1166. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1167. }
  1168. if (user.chairId == -1) {
  1169. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1170. }
  1171. // let str2 = "sxjiang 22收费聊天 "+playerId;
  1172. // logger.info(str2);////cssj
  1173. return user.table.vsendMsgAsync(user.chairId, chairId, msg);
  1174. });
  1175. // 角色信息
  1176. proto.roleInfoAsync = P.coroutine(function* (playerId, chairId) {
  1177. // console.warn("角色信息+++++++++playerId:%s",playerId);
  1178. // let str2 = "sxjiang 角色信息 "+playerId;
  1179. // logger.info(str2);////cssj
  1180. // 查找玩家
  1181. var user = this.users[playerId];
  1182. if (!user) {
  1183. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1184. }
  1185. if (user.chairId == -1) {
  1186. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1187. }
  1188. // let str1 = "sxjiang 22角色信息 "+playerId;
  1189. // logger.info(str1);////cssj
  1190. return user.table.roleInfoAsync(chairId);
  1191. });
  1192. // 请求结束
  1193. proto.overTableAsync = P.coroutine(function* (playerId) {
  1194. // console.warn("请求结束+++++++++playerId:%s",playerId);
  1195. // let str1 = "sxjiang 请求结束 "+playerId;
  1196. // logger.info(str1);////cssj
  1197. // 查找玩家
  1198. var user = this.users[playerId];
  1199. //////TL++zsyl,原先下面这一段是 游戏开始之前不能申请解散 准备之前不能申请解散
  1200. if (!user) {
  1201. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1202. }
  1203. // if (user.chairId == -1) {
  1204. // return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1205. // }
  1206. // // 状态校验
  1207. // if (user.state <= User.STATE.READY) {
  1208. // return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1209. // }
  1210. // if (user.table.state <= Table.STATE.FREE) {
  1211. // return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1212. // }
  1213. // let str2 = "sxjiang 222请求结束 "+playerId;
  1214. // logger.info(str2);////cssj
  1215. return user.table.overTableAsync(user);////TL++参数userID userState
  1216. });
  1217. // 拒绝结束
  1218. proto.refuseOverAsync = P.coroutine(function* (playerId) {
  1219. // let str2 = "sxjiang 拒绝结束 "+playerId;
  1220. // logger.info(str2);////cssj
  1221. // console.warn("拒绝结束+++++++++playerId:%s",playerId);
  1222. // 查找玩家
  1223. var user = this.users[playerId];
  1224. if (!user) {
  1225. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1226. }
  1227. if (user.chairId == -1) {
  1228. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1229. }
  1230. // 状态校验
  1231. if (user.state <= User.STATE.READY) {
  1232. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1233. }
  1234. if (user.table.state <= Table.STATE.FREE) {
  1235. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1236. }
  1237. // let str1 = "sxjiang 222拒绝结束 "+playerId;
  1238. // logger.info(str1);////cssj
  1239. return user.table.refuseOverAsync(user);
  1240. });
  1241. // 同意结束
  1242. proto.agreeOverAsync = P.coroutine(function* (playerId) {
  1243. // console.warn("同意结束+++++++++playerId:%s",playerId);
  1244. // let str1 = "sxjiang 同意结束 "+playerId;
  1245. // logger.info(str1);////cssj
  1246. // 查找玩家
  1247. var user = this.users[playerId];
  1248. if (!user) {
  1249. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1250. }
  1251. if (user.chairId == -1) {
  1252. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1253. }
  1254. // 状态校验
  1255. if (user.state <= User.STATE.READY) {
  1256. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1257. }
  1258. if (user.table.state <= Table.STATE.FREE) {
  1259. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1260. }
  1261. // let str2 = "sxjiang 222同意结束 "+playerId;
  1262. // logger.info(str2);////cssj
  1263. return user.table.agreeOverAsync(user);
  1264. });
  1265. // 得到玩家位置
  1266. proto.getLocationAsync = P.coroutine(function* (playerId,msg) {
  1267. // console.warn("ts+++++得到玩家位置",playerId);
  1268. // 查找玩家
  1269. var user = this.users[playerId];
  1270. if (!user) {
  1271. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1272. }
  1273. return user.table.getLocationAsync();
  1274. });