paodekuai.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  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').paodekuai || {};
  7. var User = require('../paodekuai/user');
  8. var Table = require('../paodekuai/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 = 10008;
  23. this.lastId = 50000;//桌子号50000
  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>=70000)
  53. {
  54. this.lastId=50000;
  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 = "paodekuai 创建桌子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 = "paodekuai 删除桌子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. // 检查删除 此方法目前(7月26日)每10分钟调用一次
  76. proto.checkDelete = P.coroutine(function* () {
  77. var date1 = new Date(Date.now());
  78. var date2=date1.toLocaleDateString().replace(/\//g, "-") + " " + date1.toTimeString().substr(0, 8);
  79. // console.warn("检查删除 房间数",this.tables.length,date2);
  80. var nowTime = Date.now();
  81. if (this.tables.length > 0) {
  82. var validTables = [];
  83. for (let i = 0; i < this.tables.length;++i) {
  84. let table = this.tables[i];
  85. if (table.stime ==0 && nowTime - table.ctime >= this.keepTm)
  86. {
  87. // console.warn("tableId ccccc",table);
  88. // let str3 = "paodekuai检查删除validTables"+table.id
  89. // logger.info(str3);////cssj
  90. validTables.push(table);
  91. }
  92. }
  93. // console.warn("删除数:",validTables.length);
  94. if (validTables.length > 0) {
  95. let app = this.app;
  96. return app.memdb.goose.transactionAsync(P.coroutine(function* () {
  97. for (let j = 0; j < validTables.length; ++j) {
  98. // let str3 = "paodekuai检查删除SYSTEMEND"+validTables[j].id
  99. // logger.info(str3);////cssj
  100. yield validTables[j].endResultAsync(Table.ENDMODE.SYSTEMEND);//ts++超时解散
  101. }
  102. }), app.getServerId())
  103. .then(() => app.event.emit('transactionSuccess'), () => app.event.emit('transactionFail'));
  104. }
  105. }
  106. });
  107. // 回到桌子
  108. proto.backTableAsync = P.coroutine(function* (user) {
  109. // console.warn("ts+++++回到桌子playerId:%s",user.id);//ts++
  110. // let str3 = "paodekuai回到桌子 "+user.id
  111. // logger.info(str3);////cssj
  112. // 查找玩家
  113. var player = yield this.app.models.Player.findByIdAsync(user.id, 'tableId gameId gameServerId connectorId');
  114. // let str4 = "paodekuai回到33桌子gameServerId "+player.gameServerId+" state "+ user.table.state +" isGameOk "+user.table.isGameOk
  115. // logger.info(str4);////cssj
  116. if (player.gameServerId) {
  117. //console.warn("-------进不来111",player.gameServerId);
  118. return { code: C.FAILD, msg: C.TABLE_HAS_ALREADY };
  119. }
  120. var bDel=false;
  121. var usertable = user.table;
  122. if(!usertable)
  123. {
  124. bDel=true;
  125. //console.warn('=======房间已经不存在了=====删除用户:%s', user.id);
  126. //logger.info('=======房间已经不存在了=====删除用户:%s', user.id);
  127. }
  128. if (!bDel && usertable.state == Table.STATE.END) {
  129. bDel=true;
  130. //console.warn('=======房间已经结束=====删除用户:%s', user.id);
  131. //logger.info('=======房间已经结束=====删除用户:%s', user.id);
  132. }
  133. // 局数完成
  134. if (!bDel && usertable.isGameOk) {
  135. bDel=true;
  136. //console.warn('=======房间局数完成=====删除用户:%s', user.id);
  137. //logger.info('=======房间局数完成=====删除用户:%s', user.id);
  138. }
  139. if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000)
  140. {
  141. bDel=true;
  142. //console.warn('creatOrjoinTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  143. //logger.info('=======断线时间过长了=====删除用户:%s', user.id);
  144. }
  145. if (bDel) {
  146. delete this.users[user.id];
  147. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  148. }
  149. if (player.connectorId) {
  150. user.connectorId = player.connectorId;
  151. }
  152. var res = yield user.table.backAsync(user);
  153. // 保存服务
  154. if (player) {
  155. // let str5 = "paodekuai回到33桌子tableId"+user.table.id
  156. // logger.info(str5);////cssj
  157. player.tableId = user.table.id;
  158. player.gameId = this.id;
  159. player.gameServerId = this.app.getServerId();
  160. yield player.saveAsync();
  161. }
  162. return res;
  163. });
  164. // TL++,得到玩家位置
  165. proto.sendLocationAsync = P.coroutine(function* (playerId,msg) {
  166. //console.warn("得到玩家位置+++++++++playerId:%s",playerId,msg);
  167. // let str4 = "paodekuai得到玩家位置 "+playerId
  168. // logger.info(str4);////cssj
  169. // 查找玩家
  170. var user = this.users[playerId];
  171. if (!user) {
  172. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  173. }
  174. // // 查找桌子
  175. // var table = _.find(this.tables, { id: msg.tableid });
  176. // if (!table) {
  177. // return { code: C.FAILD, msg: C.TABLE_NOT_FOUND };
  178. // }
  179. // let str5 = "paodekuai得到玩家位置end "+playerId
  180. // logger.info(str5);////cssj
  181. return user.table.sendLocationAsync(user,msg);
  182. });
  183. // TL++,判断桌子是否存在 reload=1为重入
  184. proto.isTableExistAsync = P.coroutine(function* (playerId, tableId,reload) {
  185. //console.warn("判断房间是否存在++++:%s,房间号:%s,重入:%d",playerId,tableId,reload);
  186. // let str5 = "paodekuai判断桌子是否存在 "+playerId
  187. // logger.info(str5);////cssj
  188. // 查找玩家
  189. var user = this.users[playerId];
  190. if (user) {//重入优化
  191. var bDel=false;
  192. var usertable = user.table;
  193. if(!usertable)
  194. {
  195. bDel=true;
  196. // let str6 = "paodekuai判断桌子是否存在usertable "+usertable+" state "+usertable.state+" isGameOk "+ usertable.isGameOk
  197. // logger.info(str6);////cssj
  198. //console.warn('=======房间已经不存在了=====删除用户:%s', user.id);
  199. //logger.info('=======房间已经不存在了=====删除用户:%s', user.id);
  200. }
  201. if (!bDel && usertable.state == Table.STATE.END) {
  202. bDel=true;
  203. //console.warn('=======房间已经结束=====删除用户:%s', user.id);
  204. //logger.info('=======房间已经结束=====删除用户:%s', user.id);
  205. }
  206. // 局数完成
  207. if (!bDel && usertable.isGameOk) {
  208. bDel=true;
  209. //console.warn('=======房间局数完成=====删除用户:%s', user.id);
  210. //logger.info('=======房间局数完成=====删除用户:%s', user.id);
  211. }
  212. if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000)
  213. {
  214. bDel=true;
  215. // let str6 = "paodekuai判断桌子是否存在断线时间过长user.id "+user.id
  216. // logger.info(str6);////cssj
  217. // console.warn('isTableExistAsync=======断线时间过长了=====删除用户:%s', user.id);
  218. //logger.info('=======断线时间过长了=====删除用户:%s', user.id);
  219. }
  220. if(!bDel )
  221. {
  222. return { code: C.OK, data: {tid:usertable.id} };
  223. }
  224. else
  225. {
  226. // let str6 = "paodekuai判断桌子是否存在==删除用户user.id "+user.id
  227. // logger.info(str6);////cssj
  228. // console.warn('isTableExistAsync==========删除用户==%s', user.id);
  229. //logger.info('==========删除用户==%s', user.id);
  230. delete this.users[playerId];
  231. }
  232. // if(!bDel)
  233. // {
  234. // if (user.isOffline()) {//断线中可以直接回来页面
  235. // logger.info('==========重入断线中==%s', user.id);
  236. // }
  237. // if(!bDel)
  238. // {
  239. // return { code: C.OK, data: {} };
  240. // }
  241. // }
  242. // logger.info('==========删除用户==%s', user.id);
  243. // delete this.users[playerId];//ts++修改卡桌
  244. // //return { code: C.FAILD, msg: C.TABLE_HAS_ALREADY };
  245. }
  246. // 查找桌子
  247. var table = _.find(this.tables, { id: tableId });
  248. // let str6 = "paodekuai判断桌子是否存在==查找桌子 "
  249. // logger.info(str6);////cssj
  250. if (!table) {
  251. return { code: C.FAILD, msg: C.TABLE_NOT_FOUND };
  252. }
  253. var table = _.find(this.tables, { id: tableId });
  254. // let str7 = "paodekuai222判断桌子是否存在==查找桌子 state"+table.state +" isGameOk "+ table.isGameOk + "isFull" +table.isFull()
  255. // logger.info(str7);////cssj
  256. // 状态结束
  257. if (table.state == Table.STATE.END) {
  258. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  259. }
  260. // 局数完成
  261. if (table.isGameOk) {
  262. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  263. }
  264. // 是否坐满
  265. if (table.isFull()) {
  266. return { code: C.FAILD, msg: C.TABLE_IS_FULL };
  267. }
  268. return { code: C.OK, data: {tid:tableId} };
  269. });
  270. ////TL++创建或者加入桌子,用于玩家通过战绩分享进来之后
  271. proto.creatOrjoinTableAsync = P.coroutine(function* (playerId, round,type, kind,playercount,upId,other,agentId) {
  272. // let str6 = "paodekuai创建或者加入桌子 "+playerId+ " "+ round+ " "+type+ " "+ kind+ " "+playercount+ " "+upId+ " "+other+ " "+agentId
  273. // logger.info(str6);////cssj
  274. // let str64 = "paodekuai创建或者加入桌子 "+ typeof(playerId)+ " "+ typeof(round)+ " "+typeof(type)+ " "+ typeof(kind)+ " "+typeof(playercount)+ " "+typeof(upId)+ " "+typeof(other)+ " "+typeof(agentId)
  275. // logger.info(str64);////cssj
  276. // console.warn("创建或者加入桌子,用于玩家通过战绩分享进来之后:%s",playerId);//ts++
  277. // console.warn(str6);
  278. // console.warn(str64);
  279. let player = yield this.app.models.Player.findByIdReadOnlyAsync(playerId, 'diamond userId name headurl');
  280. let cUserId = String(player.userId);
  281. let cName = String(player.name);
  282. let cHead = String(player.headurl);
  283. //// 检查推广黑白名单功能,判断玩家是否可以进入(创建或者加入桌子)
  284. let chekRes = yield this.checkAgreeInfo(playerId,agentId,cUserId,cName,cHead);
  285. if(chekRes.code != C.OK){
  286. return chekRes;
  287. }
  288. // 查找玩家
  289. var user = this.users[playerId];
  290. if (user) {
  291. var bDel=false;
  292. var usertable = user.table;
  293. if(!usertable)
  294. {
  295. bDel=true;
  296. //console.warn('=======房间已经不存在了=====删除用户:%s', user.id);
  297. // logger.info('creatOrjoinTableAsync=======房间已经不存在了=====删除用户:%s', user.id);
  298. }
  299. if (!bDel && usertable.state == Table.STATE.END) {
  300. bDel=true;
  301. //console.warn('=======房间已经结束=====删除用户:%s', user.id);
  302. // logger.info('creatOrjoinTableAsync=======房间已经结束=====删除用户:%s', user.id);
  303. }
  304. // 局数完成
  305. if (!bDel && usertable.isGameOk) {
  306. bDel=true;
  307. //console.warn('=======房间局数完成=====删除用户:%s', user.id);
  308. // logger.info('creatOrjoinTableAsync=======房间局数完成=====删除用户:%s', user.id);
  309. }
  310. if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000)
  311. {
  312. bDel=true;
  313. //console.warn('creatOrjoinTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  314. // logger.info('creatOrjoinTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  315. }
  316. if(bDel)
  317. {
  318. delete this.users[playerId];
  319. // logger.info('creatOrjoinTableAsync==========删除用户==%s', user.id);
  320. }
  321. else
  322. {
  323. return this.backTableAsync(user);
  324. }
  325. }
  326. // console.warn("得到下一局的信息查找桌子不存在就创建",data);
  327. // var table = _.find(this.tables, { upId: data.upId });
  328. var table = _.find(this.tables, { upId: upId });
  329. if (!table)
  330. {
  331. // var agentId=data.agentId || "";
  332. var agentId=agentId || "";
  333. // console.warn("ts++下一局----------------新建");
  334. // return this.createTableAsync(playerId, data.round, 0,data.kind,data.playercount,data.upId,data.other,agentId);
  335. return this.createTableAsync(playerId, round, type,kind,playercount,upId,other,agentId);
  336. }
  337. else
  338. {
  339. // console.warn("ts++下一局----------------加入:"+table.id);
  340. return this.joinTableAsync(playerId, table.id);
  341. }
  342. });
  343. // 加入桌子
  344. proto.joinTableAsync = P.coroutine(function* (playerId, tableId) {
  345. // console.warn("paodekuai加入桌子playerId: "+playerId+" ,tableId: "+tableId);
  346. let isXTCF = yield this.lconfigCommon.checkIsSystemCreat(playerId);//是否系统创房
  347. if(isXTCF) return tableId;
  348. // let str6 = "paodekuai加入桌子playerId:"+playerId+",tableId:"+tableId;
  349. // logger.info(str6);////cssj
  350. ////检查是否维护状态
  351. let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'stateWH whTip');
  352. // console.warn("22检查是否维护状态",whdata);
  353. if (whdata) {
  354. // console.warn("--33检查是否维护状态",whdata.stateWH,whdata.whTip);
  355. if(whdata.stateWH){
  356. /////维护状态中
  357. return { code: C.FAILD, tip: whdata.whTip };
  358. }
  359. }
  360. else{
  361. // console.warn("创建数据库");
  362. // var whsj = new this.app.models.WHstate({
  363. // _id: 'wh',
  364. // stateWH: 0,
  365. // whTip: '游戏正在维护,请稍后创建房间',
  366. // rebaterate: 60
  367. // });
  368. // yield whsj.saveAsync();
  369. // console.warn("检查是否维护状态");
  370. }
  371. // 查找玩家
  372. var user = this.users[playerId];
  373. if (user) {
  374. var bDel=false;
  375. var usertable = user.table;
  376. if(!usertable)
  377. {
  378. bDel=true;
  379. //console.warn('=======房间已经不存在了=====删除用户:%s', user.id);
  380. // logger.info('joinTableAsync=======房间已经不存在了=====删除用户:%s', user.id);
  381. }
  382. if (!bDel && usertable.state == Table.STATE.END) {
  383. bDel=true;
  384. //console.warn('=======房间已经结束=====删除用户:%s', user.id);
  385. // logger.info('joinTableAsync=======房间已经结束=====删除用户:%s', user.id);
  386. }
  387. // 局数完成
  388. if (!bDel && usertable.isGameOk) {
  389. bDel=true;
  390. //console.warn('=======房间局数完成=====删除用户:%s', user.id);
  391. // logger.info('joinTableAsync=======房间局数完成=====删除用户:%s', user.id);
  392. }
  393. if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000)
  394. {
  395. bDel=true;
  396. //console.warn('creatOrjoinTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  397. // logger.info('joinTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  398. }
  399. if (bDel) {
  400. delete this.users[user.id];
  401. if(usertable.id==tableId)
  402. {
  403. return { code: C.FAILD, msg: C.TABLE_NOT_FOUND };
  404. }
  405. }
  406. else
  407. {
  408. return this.backTableAsync(user);
  409. }
  410. }
  411. // 查找桌子
  412. var table = _.find(this.tables, { id: tableId });
  413. if (!table) {
  414. return { code: C.FAILD, msg: C.TABLE_NOT_FOUND };
  415. }
  416. // table.agentId 数据库中agenter(推广员)数据表的主键(_id)
  417. // console.warn("=======加入桌子==table "+ table.agentId+ " playerId "+playerId);
  418. let player2 = yield this.app.models.Player.findByIdReadOnlyAsync(playerId, 'diamond userId name headurl');
  419. let cUserId = String(player2.userId);/////TL++房主
  420. let cName = String(player2.name);/////TL++房主
  421. let cHead = String(player2.headurl);/////TL++房主
  422. //// 检查推广黑白名单功能,判断玩家是否可以进入(加入桌子)
  423. let chekRes = yield this.checkAgreeInfo(playerId,table.agentId,cUserId,cName,cHead);
  424. if(chekRes.code != C.OK){
  425. return chekRes;
  426. }
  427. // delete require.cache[require.resolve('../../share/configCommon')];
  428. // configCommon = require('../../share/configCommon');
  429. // this.lconfigCommon = new configCommon(this.app);
  430. // console.warn("加入房间 table.agentId "+table.agentId+" table.isNeverStart "+table.isNeverStart)
  431. let chekRes2 = yield this.lconfigCommon.checkIsCanJoin(this.id,table.agentId,2);
  432. if(chekRes2.code != C.OK){
  433. // console.warn("加入房间 不在比赛期间内 table.isNeverStart "+table.isNeverStart)
  434. // return chekRes2;
  435. if(table.isNeverStart){
  436. return chekRes2;//不在比赛期间内,而且游戏从未开始过,不让进去
  437. }
  438. }
  439. // 状态结束
  440. if (table.state == Table.STATE.END) {
  441. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  442. }
  443. // 局数完成
  444. if (table.isGameOk) {
  445. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  446. }
  447. // 是否坐满
  448. if (table.isFull()) {
  449. return { code: C.FAILD, msg: C.TABLE_IS_FULL };
  450. }
  451. // 查找玩家
  452. var player = yield this.app.models.Player.findByIdAsync(playerId, 'account userId name sex headurl tableId gameId gameServerId connectorId diamond cost spreadId registerTime lastLoginTime');
  453. if (player.gameServerId) {
  454. //console.warn("-------进不来666",player.gameServerId);
  455. return { code: C.FAILD, msg: C.TABLE_HAS_ALREADY };
  456. }
  457. // 创建玩家
  458. var user = this._createUser(player, table);
  459. // 加入桌子
  460. //logger.info('==========joinTableAsync==%s', playerId);
  461. var res = yield table.joinAsync(user);
  462. // 保存服务
  463. if (player) {
  464. player.tableId = tableId;
  465. player.rTableId = parseInt(tableId);//ts++重入时使用
  466. player.gameId = this.id;
  467. player.gameServerId = this.app.getServerId();
  468. yield player.saveAsync();
  469. }
  470. // let str1 = "paodekuai 22加入桌子 "+playerId;
  471. // logger.info(str1);////cssj
  472. console.warn("paodekuai加入桌子 res : "+JSON.stringify( res));
  473. return res;
  474. });
  475. ////检查推广黑白名单功能
  476. proto.checkAgreeInfo = P.coroutine(function* (playerId,agentId,cUserId,cName,cHead) {
  477. // console.warn("检查推广黑白名单功能11 "+playerId);
  478. ////查询该推广员的白名单信息 检查玩家是否处于该推广员的白名单中,如果已经得到同意才能创建和加入房间
  479. // var agentId = "xxxx"//_agentId
  480. if(!agentId) return { code: C.OK};
  481. var agreeInfo = yield this.app.models.AgenterAgree.findByIdReadOnlyAsync(agentId, '_id isOpenAgree infoList');
  482. if (agreeInfo) {
  483. // console.warn("该推广有白名单信息 ");
  484. // console.warn("该推广有白名单信息00 +agreeInfo.infoList "+" isOpenAgree "+agreeInfo.isOpenAgree );
  485. let isInAgreeInfoList = false;
  486. let isAgreedPlayer = false;//该玩家是否被同意
  487. //只要该玩家被拒绝,无论同意功能是否开启该玩家都不能进入
  488. for (var i = agreeInfo.infoList.length - 1; i >= 0; i--) {
  489. if(agreeInfo.infoList[i].playerId == playerId){
  490. isInAgreeInfoList = true;
  491. isAgreedPlayer = agreeInfo.infoList[i].agreeState == "1";
  492. if(agreeInfo.infoList[i].agreeState == "2"){
  493. return { code: C.FAILD, msg: "您已被推广员拒绝" };
  494. }
  495. break;
  496. }
  497. }
  498. // console.warn("该推广有白名单信息22 改玩家未被拒绝 "+" isOpenAgree "+agreeInfo.isOpenAgree + " isInAgreeInfoList "+isInAgreeInfoList);
  499. //如果功能开启,
  500. if(agreeInfo.isOpenAgree == "1"){
  501. if(!isInAgreeInfoList){
  502. //此玩家未记录在同意或拒绝信息列表中则将该玩家加入待同意名单
  503. agreeInfo.infoList.push({
  504. _id: playerId,
  505. playerId: playerId,
  506. agreeState:'0',
  507. userId: cUserId,
  508. name: cName,
  509. headurl: cHead
  510. });
  511. yield agreeInfo.saveAsync();
  512. // console.warn(" 功能开启 此玩家未记录 ");
  513. return { code: C.FAILD, msg: "等待推广员同意" };
  514. }
  515. else{
  516. // console.warn(" 功能开启 此玩家已经有记录 不是拒绝也不是同意 ");
  517. //此玩家以记录在同意或待同意信息列表中,则判断该玩家能否进入游戏
  518. if(!isAgreedPlayer){
  519. return { code: C.FAILD, msg: "等待推广员同意2" };
  520. }
  521. }
  522. }
  523. }
  524. else{
  525. // console.warn("该推广尚未有白名单信息则创建该推广的白名单信息");
  526. //该推广尚未有白名单信息则创建该推广的默认白名单信息
  527. var agenteragree = new this.app.models.AgenterAgree({
  528. _id: agentId,//记录
  529. isOpenAgree: "0",
  530. infoList: []
  531. });
  532. // console.warn("agenteragree new",agenteragree);
  533. yield agenteragree.saveAsync();
  534. }
  535. return { code: C.OK};
  536. });
  537. // 创建桌子
  538. proto.createTableAsync = P.coroutine(function* (playerId, round, type,gameKind,playerAllCount,upId,other,agentId) {
  539. // console.warn("创建桌子+++++++++代理:%s",agentId);
  540. // let str6 = "paodekuai 创建桌子 "+playerId+" "+ round+" "+ type+" "+gameKind+" "+playerAllCount+" "+upId+" "+other+" "+agentId;
  541. // logger.info(str6);////cssj
  542. // let str65 = "paodekuai 创建桌子 "+typeof(playerId)+" "+ typeof(round)+" "+ typeof(type)+" "+typeof(gameKind)+" "+typeof(playerAllCount)+" "+typeof(upId)+" "+typeof(other)+" "+typeof(agentId);
  543. // logger.info(str65);////cssj
  544. // console.warn(str6);
  545. // console.warn(str65);
  546. // 已有桌子
  547. // if (this.users[playerId]) {
  548. // // console.warn("-------进不来777",this.users[playerId]);
  549. // delete this.users[playerId];//ts++修改卡桌
  550. // //return { code: C.FAILD, msg: C.TABLE_HAS_ALREADY };
  551. // }
  552. ////检查是否维护状态
  553. let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'stateWH whTip yxndlbTime yxndlbTip');
  554. // console.warn("22检查是否维护状态",whdata);
  555. if (whdata) {
  556. // console.warn("--33检查是否维护状态",whdata.stateWH,whdata.whTip);
  557. if(whdata.stateWH){
  558. /////维护状态中
  559. return { code: C.FAILD, tip: whdata.whTip };
  560. }
  561. }
  562. else{
  563. // console.warn("创建数据库");
  564. // var whsj = new this.app.models.WHstate({
  565. // _id: 'wh',
  566. // stateWH: 0,
  567. // whTip: '游戏正在维护,请稍后创建房间',
  568. // rebaterate: 60
  569. // });
  570. // yield whsj.saveAsync();
  571. // console.warn("检查是否维护状态");
  572. }
  573. // console.warn("44检查是否维护状态",whdata.stateWH,whdata.whTip);
  574. var user = this.users[playerId];
  575. if (user) {
  576. var bDel=false;
  577. var usertable = user.table;
  578. if(!usertable)
  579. {
  580. bDel=true;
  581. //console.warn('=======房间已经不存在了=====删除用户:%s', user.id);
  582. // logger.info('createTableAsync=======房间已经不存在了=====删除用户:%s', user.id);
  583. }
  584. if (!bDel && usertable.state == Table.STATE.END) {
  585. bDel=true;
  586. //console.warn('=======房间已经结束=====删除用户:%s', user.id);
  587. // logger.info('createTableAsync=======房间已经结束=====删除用户:%s', user.id);
  588. }
  589. // 局数完成
  590. if (!bDel && usertable.isGameOk) {
  591. bDel=true;
  592. //console.warn('=======房间局数完成=====删除用户:%s', user.id);
  593. // logger.info('createTableAsync=======房间局数完成=====删除用户:%s', user.id);
  594. }
  595. if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000)
  596. {
  597. bDel=true;
  598. //console.warn('createTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  599. // logger.info('createTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  600. }
  601. if(bDel)
  602. {
  603. delete this.users[playerId];
  604. // logger.info('createTableAsync==========删除用户==%s', user.id);
  605. }
  606. else
  607. {
  608. return this.backTableAsync(user);
  609. }
  610. }
  611. // 金币消耗 /////TLzs8月6号,创房间不做钻石限制
  612. // var num_cost = parseInt(COSTS[round]);
  613. // if(gameKind == 2){
  614. // num_cost = 90;//////冲刺扣90
  615. // }
  616. // var crt_cost = num_cost >= 0 ? num_cost : round * 10;
  617. // if (crt_cost > 0) {
  618. // let player = yield this.app.models.Player.findByIdAsync(playerId, 'diamond cost');
  619. // if (!player || player.diamond < crt_cost) {
  620. // return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW };
  621. // }
  622. // // player.diamond -= crt_cost;
  623. // // player.cost += crt_cost;
  624. // // yield player.saveAsync();
  625. // }
  626. // 创建桌子
  627. //logger.info('==========createTableAsync==%s', playerId);
  628. /////// 判断一个玩家是否还能再创建房间,限制每个玩家只能最多创建10个游戏未开始的房间
  629. let today = new Date();
  630. let time =today.getTime() -1200000;
  631. //let opts = {registerTime: { $gte: time},playerId: playerId};
  632. //let count = yield this.app.models.CTableRecord.countMongoAsync(opts)
  633. // delete require.cache[require.resolve('../../share/configCommon')];
  634. // configCommon = require('../../share/configCommon');
  635. // this.lconfigCommon = new configCommon(this.app);
  636. let cUserId = "";/////TL++房主
  637. let cName = "";/////TL++房主
  638. let cHead = "";/////TL++房主
  639. let isXTCF = yield this.lconfigCommon.checkIsSystemCreat(playerId);//是否系统创房
  640. if(isXTCF){
  641. cUserId = "0";/////TL++房主
  642. cName = "系统比赛";/////TL++房主
  643. cHead = "http://aa.bb.com/mj/ksbs.png";/////TL++房主
  644. }
  645. else{
  646. let opts = {ctime: { $gte: time},ownerId: playerId};
  647. let count = yield this.app.models.GameTable.countMongoAsync(opts)
  648. if(count >= 50){
  649. return { code: C.FAILD, msg: C.TABLE_CREATETOOMUCH };
  650. }
  651. let player = yield this.app.models.Player.findByIdReadOnlyAsync(playerId, 'diamond userId name headurl');
  652. // if (!player || player.diamond < crt_cost) {/////TLzs8月6号,创房间不做钻石限制
  653. // return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW };
  654. // }
  655. cUserId = String(player.userId);/////TL++房主
  656. cName = String(player.name);/////TL++房主
  657. cHead = String(player.headurl);/////TL++房主
  658. //// 检查推广黑白名单功能,判断玩家是否可以进入(创建桌子)
  659. let chekRes = yield this.checkAgreeInfo(playerId,agentId,cUserId,cName,cHead);
  660. if(chekRes.code != C.OK){
  661. return chekRes;
  662. }
  663. let chekRes2 = yield this.lconfigCommon.checkIsCanJoin(this.id,agentId,1);
  664. if(chekRes2.code != C.OK){
  665. return chekRes2;
  666. }
  667. }
  668. ////////创建游戏桌子
  669. let cell=1;//底分
  670. let yxndlbTime = 6000;
  671. if(whdata && whdata.yxndlbTime) yxndlbTime = whdata.yxndlbTime;
  672. let yxndlbTip = "";
  673. if(whdata && whdata.yxndlbTip) yxndlbTip = whdata.yxndlbTip;
  674. var table = this._createTable(playerId,cUserId,cName,cHead,cell, round, type,gameKind,playerAllCount,upId,other,agentId,yxndlbTime,yxndlbTip);
  675. //this.timeDelete(table.id);/////TL++,在桌子创建的时候设置20分钟后删除桌子
  676. //ts++ 房间创建记录
  677. // var ctablerecord = new this.app.models.CTableRecord({
  678. // _id: table.recordid,
  679. // playerId: playerId
  680. // });
  681. // let str5 = "paodekuai 2222创建桌子 ,"+playerId;
  682. // logger.info(str5);////cssj
  683. // yield ctablerecord.saveAsync();
  684. var gametable = new this.app.models.GameTable({
  685. _id: table.recordid,//记录
  686. tableNo: table.id,
  687. ownerId: table.ownerId,
  688. agentId: table.agentId,
  689. type: table.type,
  690. kind: table.gameKindTL,//玩法 2冲刺
  691. other: table.other,//////TL++2人3人的游戏规则
  692. playerCount: table.playerAllCount,//游戏人数
  693. round: table.round,//
  694. over: table.over,//游戏局数
  695. ctime: table.ctime,//创建时间
  696. // stime: 0,//开始时间
  697. // time: 0,//结束时间
  698. endMode: 0//结束类型
  699. // gameCost: 0,//游戏消耗
  700. // agentRebate: 0//代理返利
  701. });
  702. yield gametable.saveAsync();
  703. // console.warn("创建房间",table.id,table.agentId,table.playerAllCount,isXTCF);
  704. // this.app.controllers.bisai.addTable(table.id,table.agentId,table.playerAllCount);
  705. if(isXTCF){
  706. let cd = {
  707. id: table.id,
  708. agentId: table.agentId,
  709. playerAllCount: table.playerAllCount
  710. }
  711. this.app.rpc.hall.hallRemote.creatTable.toServer("hall-server-1", cd, () => { });
  712. }
  713. // return table.id;
  714. // 加入桌子
  715. return this.joinTableAsync(playerId, table.id);
  716. });
  717. // 离开桌子
  718. proto.leaveTableAsync = P.coroutine(function* (playerId, isOffline) {
  719. // console.warn("paodekuai 离开桌子==%s",playerId);
  720. // logger.info("paodekuai 离开桌子==%s",playerId);
  721. var userdel = false;//ts++删除用户
  722. // 内存离开
  723. var user = this.users[playerId];
  724. if (user) {
  725. //console.warn('paodekuai 内存玩家==%s,状态%d',playerId,user.state);
  726. // logger.info('paodekuai 内存玩家==%s,状态%d',playerId,user.state);
  727. if (!user.isPlaying()) {
  728. //console.warn("离开桌子+++++用户空闲中");
  729. user.state = User.STATE.FREE;
  730. yield user.table.leaveAsync(user);
  731. delete this.users[playerId];
  732. userdel = true;
  733. //logger.info('paodekuai 玩家删除==%s', playerId);
  734. } else {
  735. //console.warn("离开桌子+++++用户游戏中");
  736. if (user.isOffline()) {
  737. return { code: C.OK };
  738. }
  739. // console.warn("离开桌子+++++提示玩家断线");
  740. yield user.table.offlineAsync(user);
  741. //logger.info('paodekuai 玩家断线==%s', playerId);
  742. //return { code: C.OK };//ts++游戏开始后不让退出房间
  743. }
  744. //console.warn("offlineAsync+++++状态%d",user.state);//ts++
  745. }
  746. // 置空服务
  747. //if (!isOffline) {
  748. let player = yield this.app.models.Player.findByIdAsync(playerId, 'tableId rTableId gameId gameServerId');
  749. //if (player && player.gameServerId) {
  750. //ts++upd
  751. if (player) {
  752. //console.warn("paodekuai 用户信息==",player);////css
  753. if(userdel)//ts++删除用户 重入后清空
  754. {
  755. player.rTableId = 0;
  756. }
  757. //console.warn("在这里指控了服务");
  758. player.tableId = '';
  759. player.gameId = 0;
  760. player.gameServerId = '';
  761. yield player.saveAsync();
  762. }
  763. //}
  764. //console.warn("paodekuai 离开成功==%s",playerId);
  765. // logger.info("paodekuai 离开成功==%s",playerId);
  766. return { code: C.OK };
  767. });
  768. // 坐下桌子
  769. proto.seatAsync = P.coroutine(function* (playerId, chairId) {
  770. // console.warn("坐下桌子+++++++++playerId:%s",playerId);
  771. // let str5 = "paodekuai 坐下桌子 "+playerId;
  772. // logger.info(str5);////cssj
  773. // 查找玩家
  774. var user = this.users[playerId];
  775. if (!user) {
  776. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  777. }
  778. // 状态校验
  779. if (user.state > User.STATE.READY) {
  780. return { code: C.FAILD, msg: C.PLAYER_NOT_FREE };
  781. }
  782. var table = user.table;
  783. if (table.state != Table.STATE.FREE) {
  784. return { code: C.FAILD, msg: C.TABLE_NOT_FREE };
  785. }
  786. // 局数完成
  787. if (table.isGameOk) {
  788. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  789. }
  790. // let str4 = "paodekuai 222坐下桌子 "+playerId;
  791. // logger.info(str4);////cssj
  792. return table.seatAsync(user, chairId);
  793. });
  794. // 站起桌子
  795. proto.standAsync = P.coroutine(function* (playerId) {
  796. // console.warn("站起桌子+++++++++playerId:%s",playerId);
  797. // let str5 = "paodekuai 站起桌子 "+playerId;
  798. // logger.info(str5);////cssj
  799. // 查找玩家
  800. var user = this.users[playerId];
  801. if (!user) {
  802. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  803. }
  804. // 状态校验
  805. if (user.state > User.STATE.READY) {
  806. return { code: C.FAILD, msg: C.PLAYER_NOT_FREE };
  807. }
  808. var table = user.table;
  809. if (table.state != Table.STATE.FREE) {
  810. return { code: C.FAILD, msg: C.TABLE_NOT_FREE };
  811. }
  812. // let str6 = "paodekuai 222站起桌子 "+playerId;
  813. // logger.info(str6);////cssj
  814. return table.standAsync(user);
  815. });
  816. // 准备
  817. proto.readyGameAsync = P.coroutine(function* (playerId) {
  818. // let str5 = "paodekuai 准备 "+playerId;
  819. // logger.info(str5);////cssj
  820. // 查找玩家
  821. var user = this.users[playerId];
  822. if (!user) {
  823. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  824. }
  825. if (user.chairId == -1) {
  826. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  827. }
  828. if (user.table.state == Table.STATE.FREE2) //ts++二次准备状态
  829. {
  830. // 状态校验
  831. if (user.state2 != User.STATE.FREE && user.state2 != User.STATE.OFFLINE) {
  832. return { code: C.FAILD, msg: C.PLAYER_NOT_FREE };
  833. }
  834. }
  835. else
  836. {
  837. // 状态校验
  838. if (user.state != User.STATE.FREE) {
  839. return { code: C.FAILD, msg: C.PLAYER_NOT_FREE };
  840. }
  841. if (user.table.state != Table.STATE.FREE) {
  842. return { code: C.FAILD, msg: C.TABLE_NOT_FREE };
  843. }
  844. }
  845. // 局数完成
  846. if (user.table.isGameOk) {
  847. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  848. }
  849. // let str6 = "paodekuai 22准备 "+playerId;
  850. // logger.info(str6);////cssj
  851. return user.table.readyGameAsync(user);
  852. });
  853. // 开始游戏
  854. proto.startGameAsync = P.coroutine(function* (playerId) {
  855. // console.warn("开始游戏+++++++++playerId:%s",playerId);
  856. // let str6 = "paodekuai 开始游戏 "+playerId;
  857. // logger.info(str6);////cssj
  858. // 查找玩家
  859. var user = this.users[playerId];
  860. if (!user) {
  861. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  862. }
  863. if (user.chairId == -1) {
  864. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  865. }
  866. // 状态校验
  867. var table = user.table;
  868. if (table.state != Table.STATE.FREE) {
  869. return { code: C.FAILD, msg: C.TABLE_NOT_FREE };
  870. }
  871. // 是否房主
  872. if (!user.isOwner()) {
  873. return { code: C.FAILD, msg: C.TABLE_NOT_OWNER };
  874. }
  875. // 局数完成
  876. if (table.isGameOk) {
  877. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  878. }
  879. // 是否准备
  880. if (!table.isReady()) {
  881. return { code: C.FAILD, msg: C.TABLE_NOT_READY };
  882. }
  883. // let str5 = "paodekuai 222开始游戏 "+playerId;
  884. // logger.info(str5);////cssj
  885. return table.startGameAsync();
  886. });
  887. // 出牌处理
  888. proto.outCardAsync = P.coroutine(function* (playerId, cards) {
  889. // console.warn("出牌处理+++++++++playerId:%s",playerId);
  890. // let str5 = "paodekuai 出牌处理 "+playerId+"==card "+card;
  891. // logger.info(str5);////cssj
  892. // 查找玩家
  893. var user = this.users[playerId];
  894. if (!user) {
  895. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  896. }
  897. if (user.chairId == -1) {
  898. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  899. }
  900. // 状态校验
  901. if (user.state !== User.STATE.PLAYING) {
  902. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  903. }
  904. if (user.table.state !== Table.STATE.PLAYING) {
  905. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  906. }
  907. // let str6 = "paodekuai 22出牌处理 "+playerId+" cards "+cards
  908. // logger.info(str6);////cssj
  909. return user.table.outCardAsync(user.chairId, cards);
  910. });
  911. // 操作是否自动出牌
  912. proto.autoOutCard = P.coroutine(function* (playerId) {
  913. // console.warn("操作是否自动出牌+++++++++playerId:%s",playerId);
  914. // let str1 = "csjiang 操作是否自动出牌 "+playerId;
  915. // logger.info(str1);////cssj
  916. // 查找玩家
  917. var user = this.users[playerId];
  918. if (!user) {
  919. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  920. }
  921. if (user.chairId == -1) {
  922. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  923. }
  924. // 状态校验
  925. // if (user.state !== User.STATE.PLAYING) {
  926. // return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  927. // }
  928. // if (user.table.state !== Table.STATE.PLAYING) {
  929. // return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  930. // }
  931. // let str2 = "csjiang 操作是否自动出牌 "+playerId;
  932. // logger.info(str2);////cssj
  933. return user.table.autoOutCardAsync(user.chairId);
  934. });
  935. // 发送聊天
  936. proto.sendMsgAsync = P.coroutine(function* (playerId, msg) {
  937. // console.warn("发送聊天+++++++++playerId:%s",playerId);
  938. // let str2 = "paodekuai 发送聊天 "+playerId;
  939. // logger.info(str2);////cssj
  940. // 查找玩家
  941. var user = this.users[playerId];
  942. if (!user) {
  943. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  944. }
  945. if (!user.table) {
  946. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  947. }
  948. // let str1 = "paodekuai 222发送聊天 "+playerId;
  949. // logger.info(str1);////cssj
  950. return user.table.sendMsgAsync(user.chairId, msg);
  951. });
  952. // 收费聊天
  953. proto.vsendMsgAsync = P.coroutine(function* (playerId, chairId, msg) {
  954. // console.warn("收费聊天+++++++++playerId:%s",playerId);
  955. // let str1 = "paodekuai 收费聊天 "+playerId;
  956. // logger.info(str1);////cssj
  957. // 查找玩家
  958. var user = this.users[playerId];
  959. if (!user) {
  960. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  961. }
  962. if (user.chairId == -1) {
  963. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  964. }
  965. // let str2 = "paodekuai 22收费聊天 "+playerId;
  966. // logger.info(str2);////cssj
  967. return user.table.vsendMsgAsync(user.chairId, chairId, msg);
  968. });
  969. // 角色信息
  970. proto.roleInfoAsync = P.coroutine(function* (playerId, chairId) {
  971. // console.warn("角色信息+++++++++playerId:%s",playerId);
  972. // let str2 = "paodekuai 角色信息 "+playerId;
  973. // logger.info(str2);////cssj
  974. // 查找玩家
  975. var user = this.users[playerId];
  976. if (!user) {
  977. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  978. }
  979. if (user.chairId == -1) {
  980. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  981. }
  982. // let str1 = "paodekuai 22角色信息 "+playerId;
  983. // logger.info(str1);////cssj
  984. return user.table.roleInfoAsync(chairId);
  985. });
  986. // 请求结束
  987. proto.overTableAsync = P.coroutine(function* (playerId) {
  988. // console.warn("请求结束+++++++++playerId:%s",playerId);
  989. // let str1 = "paodekuai 请求结束 "+playerId;
  990. // logger.info(str1);////cssj
  991. // 查找玩家
  992. var user = this.users[playerId];
  993. //////TL++zsyl,原先下面这一段是 游戏开始之前不能申请解散 准备之前不能申请解散
  994. if (!user) {
  995. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  996. }
  997. // if (user.chairId == -1) {
  998. // return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  999. // }
  1000. // // 状态校验
  1001. // if (user.state <= User.STATE.READY) {
  1002. // return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1003. // }
  1004. // if (user.table.state <= Table.STATE.FREE) {
  1005. // return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1006. // }
  1007. // let str2 = "paodekuai 222请求结束 "+playerId;
  1008. // logger.info(str2);////cssj
  1009. return user.table.overTableAsync(user);////TL++参数userID userState
  1010. });
  1011. // 拒绝结束
  1012. proto.refuseOverAsync = P.coroutine(function* (playerId) {
  1013. // let str2 = "paodekuai 拒绝结束 "+playerId;
  1014. // logger.info(str2);////cssj
  1015. // console.warn("拒绝结束+++++++++playerId:%s",playerId);
  1016. // 查找玩家
  1017. var user = this.users[playerId];
  1018. if (!user) {
  1019. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1020. }
  1021. if (user.chairId == -1) {
  1022. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1023. }
  1024. // 状态校验
  1025. if (user.state <= User.STATE.READY) {
  1026. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1027. }
  1028. if (user.table.state <= Table.STATE.FREE) {
  1029. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1030. }
  1031. // let str1 = "paodekuai 222拒绝结束 "+playerId;
  1032. // logger.info(str1);////cssj
  1033. return user.table.refuseOverAsync(user);
  1034. });
  1035. // 同意结束
  1036. proto.agreeOverAsync = P.coroutine(function* (playerId) {
  1037. // console.warn("同意结束+++++++++playerId:%s",playerId);
  1038. // let str1 = "paodekuai 同意结束 "+playerId;
  1039. // logger.info(str1);////cssj
  1040. // 查找玩家
  1041. var user = this.users[playerId];
  1042. if (!user) {
  1043. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1044. }
  1045. if (user.chairId == -1) {
  1046. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1047. }
  1048. // 状态校验
  1049. if (user.state <= User.STATE.READY) {
  1050. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1051. }
  1052. if (user.table.state <= Table.STATE.FREE) {
  1053. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1054. }
  1055. // let str2 = "paodekuai 222同意结束 "+playerId;
  1056. // logger.info(str2);////cssj
  1057. return user.table.agreeOverAsync(user);
  1058. });
  1059. // 得到玩家位置
  1060. proto.getLocationAsync = P.coroutine(function* (playerId,msg) {
  1061. // console.warn("ts+++++得到玩家位置",playerId);
  1062. // 查找玩家
  1063. var user = this.users[playerId];
  1064. if (!user) {
  1065. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1066. }
  1067. return user.table.getLocationAsync();
  1068. });