sxjiang.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  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').sxjiang || {};
  7. var User = require('../sxjiang/user');
  8. var Table = require('../sxjiang/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 = 10007;
  23. this.lastId = 10000;//桌子号10000
  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>=30000)
  53. {
  54. this.lastId=10000;
  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.outCardAsync = P.coroutine(function* (playerId, card) {
  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.outCardAsync(user.chairId, card);
  935. });
  936. // 杠牌处理,1-普通杠, 2-暗杠, 3-自摸明杠
  937. proto.gangCardAsync = P.coroutine(function* (playerId, card, type) {
  938. // console.warn("杠牌处理+++++++++playerId:%s",playerId);
  939. // let str6 = "sxjiang 杠牌处理, "+playerId+"==card "+card;
  940. // logger.info(str6);////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 str5 = "sxjiang 22杠牌处理, "+playerId+"==card "+card
  957. // logger.info(str5);////cssj
  958. return user.table.gangCardAsync(user.chairId, card, type);
  959. });
  960. // 碰牌处理
  961. proto.pengCardAsync = P.coroutine(function* (playerId, card) {
  962. // console.warn("碰牌处理+++++++++playerId:%s",playerId);
  963. // let str5 = "sxjiang 碰牌处理 "+playerId+"==card "+card;
  964. // logger.info(str5);////cssj
  965. // 查找玩家
  966. var user = this.users[playerId];
  967. if (!user) {
  968. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  969. }
  970. if (user.chairId == -1) {
  971. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  972. }
  973. // 状态校验
  974. if (user.state !== User.STATE.PLAYING) {
  975. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  976. }
  977. if (user.table.state !== Table.STATE.PLAYING) {
  978. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  979. }
  980. // let str3 = "sxjiang 22碰牌处理 "+playerId+"==card "+card;
  981. // logger.info(str3);////cssj
  982. return user.table.pengCardAsync(user.chairId, card);
  983. });
  984. // 吃牌处理,1-@**左吃, 2-*@*中吃, 3-@**右吃
  985. proto.eatCardAsync = P.coroutine(function* (playerId, card, type) {
  986. // console.warn("吃牌处理+++++++++playerId:%s",playerId);
  987. // let str2 = "sxjiang 吃牌处理, "+playerId+"==card "+card;
  988. // logger.warn(str2);////cssj
  989. // 查找玩家
  990. var user = this.users[playerId];
  991. if (!user) {
  992. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  993. }
  994. if (user.chairId == -1) {
  995. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  996. }
  997. // 状态校验
  998. if (user.state !== User.STATE.PLAYING) {
  999. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1000. }
  1001. if (user.table.state !== Table.STATE.PLAYING) {
  1002. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1003. }
  1004. // let str1 = "sxjiang 222吃牌处理, "+playerId+"==card "+card
  1005. // logger.info(str1);////cssj
  1006. return user.table.eatCardAsync(user.chairId, card, type);
  1007. });
  1008. // 胡牌处理,1-自摸, 2-点炮
  1009. proto.succCardAsync = P.coroutine(function* (playerId) {
  1010. // console.warn("胡牌处理+++++++++playerId:%s",playerId);
  1011. // let str1 = "sxjiang 胡牌处理,"+playerId;
  1012. // logger.info(str1);////cssj
  1013. // 查找玩家
  1014. var user = this.users[playerId];
  1015. if (!user) {
  1016. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1017. }
  1018. if (user.chairId == -1) {
  1019. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1020. }
  1021. // 状态校验
  1022. if (user.state !== User.STATE.PLAYING) {
  1023. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1024. }
  1025. if (user.table.state !== Table.STATE.PLAYING) {
  1026. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1027. }
  1028. // let str2 = "sxjiang 22胡牌处理,"+playerId;
  1029. // logger.info(str2);////cssj
  1030. return user.table.succCardAsync(user.chairId);
  1031. });
  1032. // 放弃吃碰杠胡
  1033. proto.giveUpAsync = P.coroutine(function* (playerId) {
  1034. // console.warn("放弃吃碰杠胡+++++++++playerId:%s",playerId);
  1035. // let str1 = "sxjiang 放弃吃碰杠胡 "+playerId;
  1036. // logger.info(str1);////cssj
  1037. // 查找玩家
  1038. var user = this.users[playerId];
  1039. if (!user) {
  1040. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1041. }
  1042. if (user.chairId == -1) {
  1043. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1044. }
  1045. // 状态校验
  1046. if (user.state !== User.STATE.PLAYING) {
  1047. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1048. }
  1049. if (user.table.state !== Table.STATE.PLAYING) {
  1050. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1051. }
  1052. // let str2 = "sxjiang 放弃吃碰杠胡 "+playerId;
  1053. // logger.info(str2);////cssj
  1054. return user.table.giveUpAsync(user.chairId);
  1055. });
  1056. // //////TL++,是否进行海底捞月的操作
  1057. proto.haiDiLaoYue = P.coroutine(function* (playerId,type) {
  1058. // console.warn("是否进行海底捞月的操作+++++++++playerId:%s",playerId);
  1059. // let str1 = "sxjiang 是否进行海底捞月的操作 "+playerId;
  1060. // logger.info(str1);////cssj
  1061. // 查找玩家
  1062. var user = this.users[playerId];
  1063. if (!user) {
  1064. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1065. }
  1066. if (user.chairId == -1) {
  1067. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1068. }
  1069. // 状态校验
  1070. if (user.state !== User.STATE.PLAYING) {
  1071. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1072. }
  1073. if (user.table.state !== Table.STATE.PLAYING) {
  1074. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1075. }
  1076. // let str2 = "sxjiang 22是否进行海底捞月的操作 "+playerId;
  1077. // logger.info(str2);////cssj
  1078. return user.table.haiDiLaoYue(user.chairId,type);
  1079. });
  1080. // 操作是否自动出牌
  1081. proto.autoOutCard = P.coroutine(function* (playerId) {
  1082. // console.warn("操作是否自动出牌+++++++++playerId:%s",playerId);
  1083. // let str1 = "csjiang 操作是否自动出牌 "+playerId;
  1084. // logger.info(str1);////cssj
  1085. // 查找玩家
  1086. var user = this.users[playerId];
  1087. if (!user) {
  1088. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1089. }
  1090. if (user.chairId == -1) {
  1091. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1092. }
  1093. // 状态校验
  1094. if (user.state !== User.STATE.PLAYING) {
  1095. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1096. }
  1097. if (user.table.state !== Table.STATE.PLAYING) {
  1098. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1099. }
  1100. // let str2 = "csjiang 操作是否自动出牌 "+playerId;
  1101. // logger.info(str2);////cssj
  1102. return user.table.autoOutCardAsync(user.chairId);
  1103. });
  1104. // 发送聊天
  1105. proto.sendMsgAsync = P.coroutine(function* (playerId, msg) {
  1106. // console.warn("发送聊天+++++++++playerId:%s",playerId);
  1107. // let str2 = "sxjiang 发送聊天 "+playerId;
  1108. // logger.info(str2);////cssj
  1109. // 查找玩家
  1110. var user = this.users[playerId];
  1111. if (!user) {
  1112. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1113. }
  1114. if (!user.table) {
  1115. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1116. }
  1117. // let str1 = "sxjiang 222发送聊天 "+playerId;
  1118. // logger.info(str1);////cssj
  1119. return user.table.sendMsgAsync(user.chairId, msg);
  1120. });
  1121. // 收费聊天
  1122. proto.vsendMsgAsync = P.coroutine(function* (playerId, chairId, msg) {
  1123. // console.warn("收费聊天+++++++++playerId:%s",playerId);
  1124. // let str1 = "sxjiang 收费聊天 "+playerId;
  1125. // logger.info(str1);////cssj
  1126. // 查找玩家
  1127. var user = this.users[playerId];
  1128. if (!user) {
  1129. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1130. }
  1131. if (user.chairId == -1) {
  1132. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1133. }
  1134. // let str2 = "sxjiang 22收费聊天 "+playerId;
  1135. // logger.info(str2);////cssj
  1136. return user.table.vsendMsgAsync(user.chairId, chairId, msg);
  1137. });
  1138. // 角色信息
  1139. proto.roleInfoAsync = P.coroutine(function* (playerId, chairId) {
  1140. // console.warn("角色信息+++++++++playerId:%s",playerId);
  1141. // let str2 = "sxjiang 角色信息 "+playerId;
  1142. // logger.info(str2);////cssj
  1143. // 查找玩家
  1144. var user = this.users[playerId];
  1145. if (!user) {
  1146. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1147. }
  1148. if (user.chairId == -1) {
  1149. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1150. }
  1151. // let str1 = "sxjiang 22角色信息 "+playerId;
  1152. // logger.info(str1);////cssj
  1153. return user.table.roleInfoAsync(chairId);
  1154. });
  1155. // 请求结束
  1156. proto.overTableAsync = P.coroutine(function* (playerId) {
  1157. // console.warn("请求结束+++++++++playerId:%s",playerId);
  1158. // let str1 = "sxjiang 请求结束 "+playerId;
  1159. // logger.info(str1);////cssj
  1160. // 查找玩家
  1161. var user = this.users[playerId];
  1162. //////TL++zsyl,原先下面这一段是 游戏开始之前不能申请解散 准备之前不能申请解散
  1163. if (!user) {
  1164. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1165. }
  1166. // if (user.chairId == -1) {
  1167. // return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1168. // }
  1169. // // 状态校验
  1170. // if (user.state <= User.STATE.READY) {
  1171. // return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1172. // }
  1173. // if (user.table.state <= Table.STATE.FREE) {
  1174. // return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1175. // }
  1176. // let str2 = "sxjiang 222请求结束 "+playerId;
  1177. // logger.info(str2);////cssj
  1178. return user.table.overTableAsync(user);////TL++参数userID userState
  1179. });
  1180. // 拒绝结束
  1181. proto.refuseOverAsync = P.coroutine(function* (playerId) {
  1182. // let str2 = "sxjiang 拒绝结束 "+playerId;
  1183. // logger.info(str2);////cssj
  1184. // console.warn("拒绝结束+++++++++playerId:%s",playerId);
  1185. // 查找玩家
  1186. var user = this.users[playerId];
  1187. if (!user) {
  1188. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1189. }
  1190. if (user.chairId == -1) {
  1191. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1192. }
  1193. // 状态校验
  1194. if (user.state <= User.STATE.READY) {
  1195. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1196. }
  1197. if (user.table.state <= Table.STATE.FREE) {
  1198. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1199. }
  1200. // let str1 = "sxjiang 222拒绝结束 "+playerId;
  1201. // logger.info(str1);////cssj
  1202. return user.table.refuseOverAsync(user);
  1203. });
  1204. // 同意结束
  1205. proto.agreeOverAsync = P.coroutine(function* (playerId) {
  1206. // console.warn("同意结束+++++++++playerId:%s",playerId);
  1207. // let str1 = "sxjiang 同意结束 "+playerId;
  1208. // logger.info(str1);////cssj
  1209. // 查找玩家
  1210. var user = this.users[playerId];
  1211. if (!user) {
  1212. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1213. }
  1214. if (user.chairId == -1) {
  1215. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1216. }
  1217. // 状态校验
  1218. if (user.state <= User.STATE.READY) {
  1219. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1220. }
  1221. if (user.table.state <= Table.STATE.FREE) {
  1222. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1223. }
  1224. // let str2 = "sxjiang 222同意结束 "+playerId;
  1225. // logger.info(str2);////cssj
  1226. return user.table.agreeOverAsync(user);
  1227. });
  1228. // 得到玩家位置
  1229. proto.getLocationAsync = P.coroutine(function* (playerId,msg) {
  1230. // console.warn("ts+++++得到玩家位置",playerId);
  1231. // 查找玩家
  1232. var user = this.users[playerId];
  1233. if (!user) {
  1234. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1235. }
  1236. return user.table.getLocationAsync();
  1237. });