csjiang.js 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398
  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').csjiang || {};
  7. var User = require('../csjiang/user');
  8. var Table = require('../csjiang/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 = 10006;
  23. this.lastId = 30000;//桌子号30000
  24. // console.warn("湖南长沙 游戏服务器启动",app.getServerType(),app.getServerId());
  25. logger.warn("湖南长沙 游戏服务器启动",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("cs创建玩家",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>=50000)
  53. {
  54. this.lastId=30000;
  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 = "csjiang 创建桌子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 = "csjiang 删除桌子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. // 检查删除 每1分钟调用一次
  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",nowTime , table.ctime,(nowTime - table.ctime));
  101. // let str3 = "csjiang检查删除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 = "csjiang检查删除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+++++cs 回到桌子playerId:%s",user.id);//ts++
  158. // let str3 = "csjiang回到桌子 "+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 = "csjiang回到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 = "csjiang回到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 = "csjiang得到玩家位置 "+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 = "csjiang得到玩家位置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 = "csjiang判断桌子是否存在 "+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 = "csjiang判断桌子是否存在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 = "csjiang判断桌子是否存在断线时间过长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 = "csjiang判断桌子是否存在==删除用户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 = "csjiang判断桌子是否存在==查找桌子 "
  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 = "csjiang222判断桌子是否存在==查找桌子 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 = "csjiang创建或者加入桌子 "+playerId+ " "+ round+ " "+type+ " "+ kind+ " "+playercount+ " "+upId+ " "+other+ " "+agentId
  321. // logger.info(str6);////cssj
  322. // let str64 = "csjiang创建或者加入桌子 "+ 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("csjiang加入桌子playerId: "+playerId+" ,tableId: "+tableId);
  394. // console.warn("csjiang 11加入桌子 "+JSON.stringify(this.users));
  395. // let str6 = "csjiang加入桌子playerId:"+playerId+",tableId:"+tableId;
  396. // logger.info(str6);////cssj
  397. ////检查是否维护状态
  398. let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'stateWH whTip yxndlbTime yxndlbTip');
  399. // console.warn("22检查是否维护状态",whdata);
  400. if (whdata) {
  401. // console.warn("--33检查是否维护状态",whdata.stateWH,whdata.whTip);
  402. if(whdata.stateWH){
  403. /////维护状态中
  404. return { code: C.FAILD, tip: whdata.whTip };
  405. }
  406. // whdata.yxndlbTime = 6;
  407. // whdata.yxndlbTip = "测试游戏内大喇叭!!!";
  408. // whdata.saveAsync();
  409. }
  410. else{
  411. // console.warn("创建数据库");
  412. // var whsj = new this.app.models.WHstate({
  413. // _id: 'wh',
  414. // stateWH: 0,
  415. // whTip: '游戏正在维护,请稍后创建房间',
  416. // rebaterate: 60
  417. // });
  418. // yield whsj.saveAsync();
  419. // console.warn("检查是否维护状态");
  420. }
  421. // 查找玩家
  422. var user = this.users[playerId];
  423. if (user) {
  424. var bDel=false;
  425. var usertable = user.table;
  426. if(!usertable)
  427. {
  428. bDel=true;
  429. //console.warn('=======房间已经不存在了=====删除用户:%s', user.id);
  430. // logger.info('joinTableAsync=======房间已经不存在了=====删除用户:%s', user.id);
  431. }
  432. if (!bDel && usertable.state == Table.STATE.END) {
  433. bDel=true;
  434. //console.warn('=======房间已经结束=====删除用户:%s', user.id);
  435. // logger.info('joinTableAsync=======房间已经结束=====删除用户:%s', user.id);
  436. }
  437. // 局数完成
  438. if (!bDel && usertable.isGameOk) {
  439. bDel=true;
  440. //console.warn('=======房间局数完成=====删除用户:%s', user.id);
  441. // logger.info('joinTableAsync=======房间局数完成=====删除用户:%s', user.id);
  442. }
  443. if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000)
  444. {
  445. bDel=true;
  446. //console.warn('creatOrjoinTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  447. // logger.info('joinTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  448. }
  449. if (bDel) {
  450. delete this.users[user.id];
  451. if(usertable.id==tableId)
  452. {
  453. return { code: C.FAILD, msg: C.TABLE_NOT_FOUND };
  454. }
  455. }
  456. else
  457. {
  458. return this.backTableAsync(user);
  459. }
  460. }
  461. // 查找桌子
  462. var table = _.find(this.tables, { id: tableId });
  463. if (!table) {
  464. return { code: C.FAILD, msg: C.TABLE_NOT_FOUND };
  465. }
  466. // table.agentId 数据库中agenter(推广员)数据表的主键(_id)
  467. // console.warn("=======加入桌子==table "+ table.agentId+ " playerId "+playerId);
  468. let player2 = yield this.app.models.Player.findByIdReadOnlyAsync(playerId, 'diamond userId name headurl');
  469. let cUserId = String(player2.userId);/////TL++房主csjiang加入桌子
  470. let cName = String(player2.name);/////TL++房主
  471. let cHead = String(player2.headurl);/////TL++房主
  472. //// 检查推广黑白名单功能,判断玩家是否可以进入(加入桌子)
  473. let chekRes = yield this.checkAgreeInfo(playerId,table.agentId,cUserId,cName,cHead);
  474. if(chekRes.code != C.OK){
  475. return chekRes;
  476. }
  477. // delete require.cache[require.resolve('../../share/configCommon')];
  478. // configCommon = require('../../share/configCommon');
  479. // this.lconfigCommon = new configCommon(this.app);
  480. // console.warn("加入房间 table.agentId "+table.agentId+" table.isNeverStart "+table.isNeverStart)
  481. let chekRes2 = yield this.lconfigCommon.checkIsCanJoin(this.id,table.agentId,2);
  482. if(chekRes2.code != C.OK){
  483. console.warn("加入房间 不在比赛期间内 table.isNeverStart "+table.isNeverStart)
  484. // return chekRes2;
  485. if(table.isNeverStart){
  486. return chekRes2;//不在比赛期间内,而且游戏从未开始过,不让进去
  487. }
  488. }
  489. // 状态结束
  490. if (table.state == Table.STATE.END) {
  491. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  492. }
  493. // 局数完成
  494. if (table.isGameOk) {
  495. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  496. }
  497. // 是否坐满
  498. if (table.isFull()) {
  499. return { code: C.FAILD, msg: C.TABLE_IS_FULL };
  500. }
  501. // 查找玩家
  502. var player = yield this.app.models.Player.findByIdAsync(playerId, 'account userId name sex headurl tableId gameId gameServerId connectorId diamond cost spreadId registerTime lastLoginTime');
  503. if (player.gameServerId) {
  504. //console.warn("-------进不来666",player.gameServerId);
  505. return { code: C.FAILD, msg: C.TABLE_HAS_ALREADY };
  506. }
  507. // 创建玩家
  508. var user = this._createUser(player, table);
  509. // 加入桌子
  510. //logger.info('==========joinTableAsync==%s', playerId);
  511. var res = yield table.joinAsync(user);
  512. // 保存服务
  513. if (player) {
  514. player.tableId = tableId;
  515. player.rTableId = parseInt(tableId);//ts++重入时使用
  516. player.gameId = this.id;
  517. player.gameServerId = this.app.getServerId();
  518. yield player.saveAsync();
  519. }
  520. // console.warn("csjiang 22加入桌子 ",res);
  521. let str1 = "csjiang 22加入桌子 "+playerId;
  522. logger.warn(str1);////cssj
  523. return res;
  524. });
  525. ////检查推广黑白名单功能
  526. proto.checkAgreeInfo = P.coroutine(function* (playerId,agentId,cUserId,cName,cHead) {
  527. // console.warn("检查推广黑白名单功能11 "+playerId);
  528. ////查询该推广员的白名单信息 检查玩家是否处于该推广员的白名单中,如果已经得到同意才能创建和加入房间
  529. // var agentId = "xxxx"//_agentId
  530. if(!agentId) return { code: C.OK};
  531. var agreeInfo = yield this.app.models.AgenterAgree.findByIdReadOnlyAsync(agentId, '_id isOpenAgree infoList');
  532. if (agreeInfo) {
  533. // console.warn("该推广有白名单信息 ");
  534. // console.warn("该推广有白名单信息00 +agreeInfo.infoList "+" isOpenAgree "+agreeInfo.isOpenAgree );
  535. let isInAgreeInfoList = false;
  536. let isAgreedPlayer = false;//该玩家是否被同意
  537. //只要该玩家被拒绝,无论同意功能是否开启该玩家都不能进入
  538. for (var i = agreeInfo.infoList.length - 1; i >= 0; i--) {
  539. if(agreeInfo.infoList[i].playerId == playerId){
  540. isInAgreeInfoList = true;
  541. isAgreedPlayer = agreeInfo.infoList[i].agreeState == "1";
  542. if(agreeInfo.infoList[i].agreeState == "2"){
  543. return { code: C.FAILD, msg: "您已被推广员拒绝" };
  544. }
  545. break;
  546. }
  547. }
  548. // console.warn("该推广有白名单信息22 改玩家未被拒绝 "+" isOpenAgree "+agreeInfo.isOpenAgree + " isInAgreeInfoList "+isInAgreeInfoList);
  549. //如果功能开启,
  550. if(agreeInfo.isOpenAgree == "1"){
  551. if(!isInAgreeInfoList){
  552. //此玩家未记录在同意或拒绝信息列表中则将该玩家加入待同意名单
  553. agreeInfo.infoList.push({
  554. _id: playerId,
  555. playerId: playerId,
  556. agreeState:'0',
  557. userId: cUserId,
  558. name: cName,
  559. headurl: cHead
  560. });
  561. yield agreeInfo.saveAsync();
  562. // console.warn(" 功能开启 此玩家未记录 ");
  563. return { code: C.FAILD, msg: "等待推广员同意" };
  564. }
  565. else{
  566. // console.warn(" 功能开启 此玩家已经有记录 不是拒绝也不是同意 ");
  567. //此玩家以记录在同意或待同意信息列表中,则判断该玩家能否进入游戏
  568. if(!isAgreedPlayer){
  569. return { code: C.FAILD, msg: "等待推广员同意2" };
  570. }
  571. }
  572. }
  573. }
  574. else{
  575. // console.warn("该推广尚未有白名单信息则创建该推广的白名单信息");
  576. //该推广尚未有白名单信息则创建该推广的默认白名单信息
  577. var agenteragree = new this.app.models.AgenterAgree({
  578. _id: agentId,//记录
  579. isOpenAgree: "0",
  580. infoList: []
  581. });
  582. // console.warn("agenteragree new",agenteragree);
  583. yield agenteragree.saveAsync();
  584. }
  585. return { code: C.OK};
  586. });
  587. var checkVersion = function () {
  588. // let confCodeVer = require('../config/csTableVer').codeVer || {};
  589. // // console.warn("cs的csjiang中检查table版本111 "+JSON.stringify(confCodeVer));
  590. // if(confCodeVer.csTable){
  591. // delete require.cache[require.resolve('../config/csTableVer')];
  592. // let confCodeVer2 = require('../config/csTableVer').codeVer || {};
  593. // // console.warn("cs的csjiang中检查table版本222 "+confCodeVer.csTable +" "+ confCodeVer2.csTable);
  594. // if(confCodeVer.csTable && confCodeVer2.csTable && confCodeVer.csTable != confCodeVer2.csTable){
  595. // delete require.cache[require.resolve('../csjiang/table')];
  596. // Table = require('../csjiang/table');
  597. // console.warn("cs的csjiang中的table更新了 ")
  598. // }
  599. // }
  600. }
  601. // 创建桌子
  602. proto.createTableAsync = P.coroutine(function* (playerId, round, type,gameKind,playerAllCount,upId,other,agentId) {
  603. console.warn("cs创建桌子+++++++++代理:%s",agentId);
  604. checkVersion();
  605. // let str6 = "csjiang 创建桌子 "+playerId+" "+ round+" "+ type+" "+gameKind+" "+playerAllCount+" "+upId+" "+other+" "+agentId;
  606. // logger.info(str6);////cssj
  607. // let str65 = "csjiang 创建桌子 "+typeof(playerId)+" "+ typeof(round)+" "+ typeof(type)+" "+typeof(gameKind)+" "+typeof(playerAllCount)+" "+typeof(upId)+" "+typeof(other)+" "+typeof(agentId);
  608. // logger.info(str65);////cssj
  609. // console.warn(str6);
  610. // console.warn(str65);
  611. // 已有桌子
  612. // if (this.users[playerId]) {
  613. // // console.warn("-------进不来777",this.users[playerId]);
  614. // delete this.users[playerId];//ts++修改卡桌
  615. // //return { code: C.FAILD, msg: C.TABLE_HAS_ALREADY };
  616. // }
  617. ////检查是否维护状态
  618. let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'stateWH whTip yxndlbTime yxndlbTip');
  619. // console.warn("22检查是否维护状态",whdata);
  620. if (whdata) {
  621. // console.warn("--33检查是否维护状态",whdata.stateWH,whdata.whTip);
  622. if(whdata.stateWH){
  623. /////维护状态中
  624. return { code: C.FAILD, tip: whdata.whTip };
  625. }
  626. }
  627. else{
  628. // console.warn("创建数据库");
  629. // var whsj = new this.app.models.WHstate({
  630. // _id: 'wh',
  631. // stateWH: 0,
  632. // whTip: '游戏正在维护,请稍后创建房间',
  633. // rebaterate: 60
  634. // });
  635. // yield whsj.saveAsync();
  636. // console.warn("检查是否维护状态");
  637. }
  638. // console.warn("44检查是否维护状态",whdata.stateWH,whdata.whTip);
  639. var user = this.users[playerId];
  640. if (user) {
  641. console.warn("csjiang 用户存在 this.users.length "+this.users.length);
  642. var bDel=false;
  643. var usertable = user.table;
  644. if(!usertable)
  645. {
  646. bDel=true;
  647. //console.warn('=======房间已经不存在了=====删除用户:%s', user.id);
  648. // logger.info('createTableAsync=======房间已经不存在了=====删除用户:%s', user.id);
  649. }
  650. if (!bDel && usertable.state == Table.STATE.END) {
  651. bDel=true;
  652. //console.warn('=======房间已经结束=====删除用户:%s', user.id);
  653. // logger.info('createTableAsync=======房间已经结束=====删除用户:%s', user.id);
  654. }
  655. // 局数完成
  656. if (!bDel && usertable.isGameOk) {
  657. bDel=true;
  658. //console.warn('=======房间局数完成=====删除用户:%s', user.id);
  659. // logger.info('createTableAsync=======房间局数完成=====删除用户:%s', user.id);
  660. }
  661. if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000)
  662. {
  663. bDel=true;
  664. //console.warn('createTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  665. // logger.info('createTableAsync=======断线时间过长了=====删除用户:%s', user.id);
  666. }
  667. if(bDel)
  668. {
  669. delete this.users[playerId];
  670. // logger.info('createTableAsync==========删除用户==%s', user.id);
  671. }
  672. else
  673. {
  674. console.warn("csjiang backTableAsync "+this.users.length);
  675. return this.backTableAsync(user);
  676. }
  677. }
  678. // 金币消耗 /////TLzs8月6号,创房间不做钻石限制
  679. // var num_cost = parseInt(COSTS[round]);
  680. // if(gameKind == 2){
  681. // num_cost = 90;//////冲刺扣90
  682. // }
  683. // var crt_cost = num_cost >= 0 ? num_cost : round * 10;
  684. // if (crt_cost > 0) {
  685. // let player = yield this.app.models.Player.findByIdAsync(playerId, 'diamond cost');
  686. // if (!player || player.diamond < crt_cost) {
  687. // return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW };
  688. // }
  689. // // player.diamond -= crt_cost;
  690. // // player.cost += crt_cost;
  691. // // yield player.saveAsync();
  692. // }
  693. // 创建桌子
  694. //logger.info('==========createTableAsync==%s', playerId);
  695. /////// 判断一个玩家是否还能再创建房间,限制每个玩家只能最多创建10个游戏未开始的房间
  696. let today = new Date();
  697. let time =today.getTime() -1200000;
  698. //let opts = {registerTime: { $gte: time},playerId: playerId};
  699. //let count = yield this.app.models.CTableRecord.countMongoAsync(opts)
  700. let opts = {ctime: { $gte: time},ownerId: playerId};
  701. let count = yield this.app.models.GameTable.countMongoAsync(opts)
  702. if(count >= 50){
  703. return { code: C.FAILD, msg: C.TABLE_CREATETOOMUCH };
  704. }
  705. let player = yield this.app.models.Player.findByIdReadOnlyAsync(playerId, 'diamond userId name headurl');
  706. // if (!player || player.diamond < crt_cost) {/////TLzs8月6号,创房间不做钻石限制
  707. // return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW };
  708. // }
  709. let cUserId = String(player.userId);/////TL++房主
  710. let cName = String(player.name);/////TL++房主
  711. let cHead = String(player.headurl);/////TL++房主
  712. //// 检查推广黑白名单功能,判断玩家是否可以进入(创建桌子)
  713. let chekRes = yield this.checkAgreeInfo(playerId,agentId,cUserId,cName,cHead);
  714. if(chekRes.code != C.OK){
  715. return chekRes;
  716. }
  717. // delete require.cache[require.resolve('../../share/configCommon')];
  718. // configCommon = require('../../share/configCommon');
  719. // this.lconfigCommon = new configCommon(this.app);
  720. let chekRes2 = yield this.lconfigCommon.checkIsCanJoin(this.id,agentId,1);
  721. if(chekRes2.code != C.OK){
  722. return chekRes2;
  723. }
  724. ////////创建游戏桌子
  725. let cell=1;//底分
  726. let yxndlbTime = 6000;
  727. if(whdata && whdata.yxndlbTime) yxndlbTime = whdata.yxndlbTime;
  728. let yxndlbTip = "";
  729. if(whdata && whdata.yxndlbTip) yxndlbTip = whdata.yxndlbTip;
  730. var table = this._createTable(playerId,cUserId,cName,cHead,cell, round, type,gameKind,playerAllCount,upId,other,agentId,yxndlbTime,yxndlbTip);
  731. //this.timeDelete(table.id);/////TL++,在桌子创建的时候设置20分钟后删除桌子
  732. //ts++ 房间创建记录
  733. // var ctablerecord = new this.app.models.CTableRecord({
  734. // _id: table.recordid,
  735. // playerId: playerId
  736. // });
  737. // let str5 = "csjiang 2222创建桌子 ,"+playerId;
  738. // logger.info(str5);////cssj
  739. // yield ctablerecord.saveAsync();
  740. var gametable = new this.app.models.GameTable({
  741. _id: table.recordid,//记录
  742. tableNo: table.id,
  743. ownerId: table.ownerId,
  744. agentId: table.agentId,
  745. type: table.type,
  746. kind: table.gameKindTL,//玩法 2冲刺
  747. other: table.other,//////TL++2人3人的游戏规则
  748. playerCount: table.playerAllCount,//游戏人数
  749. round: table.round,//
  750. over: table.over,//游戏局数
  751. ctime: table.ctime,//创建时间
  752. // stime: 0,//开始时间
  753. // time: 0,//结束时间
  754. endMode: 0//结束类型
  755. // gameCost: 0,//游戏消耗
  756. // agentRebate: 0//代理返利
  757. });
  758. yield gametable.saveAsync();
  759. // console.warn("创建房间",table.id);
  760. console.warn("csjiang backTableAsync 下面是加入桌子 "+this.users.length);
  761. // 加入桌子
  762. return this.joinTableAsync(playerId, table.id);
  763. });
  764. // 离开桌子
  765. proto.leaveTableAsync = P.coroutine(function* (playerId, isOffline) {
  766. //console.warn("csjiang 离开桌子==%s",playerId);
  767. // logger.info("csjiang 离开桌子==%s",playerId);
  768. var userdel = false;//ts++删除用户
  769. // 内存离开
  770. var user = this.users[playerId];
  771. if (user) {
  772. //console.warn('csjiang 内存玩家==%s,状态%d',playerId,user.state);
  773. // logger.info('csjiang 内存玩家==%s,状态%d',playerId,user.state);
  774. if (!user.isPlaying()) {
  775. //console.warn("离开桌子+++++用户空闲中");
  776. user.state = User.STATE.FREE;
  777. yield user.table.leaveAsync(user);
  778. delete this.users[playerId];
  779. userdel = true;
  780. //logger.info('csjiang 玩家删除==%s', playerId);
  781. } else {
  782. //console.warn("离开桌子+++++用户游戏中");
  783. if (user.isOffline()) {
  784. return { code: C.OK };
  785. }
  786. //console.warn("离开桌子+++++提示玩家断线");
  787. yield user.table.offlineAsync(user);
  788. //logger.info('csjiang 玩家断线==%s', playerId);
  789. //return { code: C.OK };//ts++游戏开始后不让退出房间
  790. }
  791. //console.warn("offlineAsync+++++状态%d",user.state);//ts++
  792. }
  793. // 置空服务
  794. //if (!isOffline) {
  795. let player = yield this.app.models.Player.findByIdAsync(playerId, 'tableId rTableId gameId gameServerId');
  796. //if (player && player.gameServerId) {
  797. //ts++upd
  798. if (player) {
  799. //console.warn("csjiang 用户信息==",player);////css
  800. if(userdel)//ts++删除用户 重入后清空
  801. {
  802. player.rTableId = 0;
  803. }
  804. //console.warn("在这里指控了服务");
  805. player.tableId = '';
  806. player.gameId = 0;
  807. player.gameServerId = '';
  808. yield player.saveAsync();
  809. }
  810. //}
  811. //console.warn("csjiang 离开成功==%s",playerId);
  812. // logger.info("csjiang 离开成功==%s",playerId);
  813. return { code: C.OK };
  814. });
  815. // 坐下桌子
  816. proto.seatAsync = P.coroutine(function* (playerId, chairId) {
  817. // console.warn("坐下桌子+++++++++playerId:%s",playerId);
  818. // let str5 = "csjiang 坐下桌子 "+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. // 状态校验
  826. if (user.state > User.STATE.READY) {
  827. return { code: C.FAILD, msg: C.PLAYER_NOT_FREE };
  828. }
  829. var table = user.table;
  830. if (table.state != Table.STATE.FREE) {
  831. return { code: C.FAILD, msg: C.TABLE_NOT_FREE };
  832. }
  833. // 局数完成
  834. if (table.isGameOk) {
  835. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  836. }
  837. // let str4 = "csjiang 222坐下桌子 "+playerId;
  838. // logger.info(str4);////cssj
  839. return table.seatAsync(user, chairId);
  840. });
  841. // 站起桌子
  842. proto.standAsync = P.coroutine(function* (playerId) {
  843. // console.warn("站起桌子+++++++++playerId:%s",playerId);
  844. // let str5 = "csjiang 站起桌子 "+playerId;
  845. // logger.info(str5);////cssj
  846. // 查找玩家
  847. var user = this.users[playerId];
  848. if (!user) {
  849. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  850. }
  851. // 状态校验
  852. if (user.state > User.STATE.READY) {
  853. return { code: C.FAILD, msg: C.PLAYER_NOT_FREE };
  854. }
  855. var table = user.table;
  856. if (table.state != Table.STATE.FREE) {
  857. return { code: C.FAILD, msg: C.TABLE_NOT_FREE };
  858. }
  859. // let str6 = "csjiang 222站起桌子 "+playerId;
  860. // logger.info(str6);////cssj
  861. return table.standAsync(user);
  862. });
  863. // 准备
  864. proto.readyGameAsync = P.coroutine(function* (playerId) {
  865. // console.warn("准备+++++++++playerId:%s",playerId);
  866. // let str5 = "csjiang 准备 "+playerId;
  867. // logger.info(str5);////cssj
  868. // 查找玩家
  869. var user = this.users[playerId];
  870. if (!user) {
  871. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  872. }
  873. if (user.chairId == -1) {
  874. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  875. }
  876. if (user.table.state == Table.STATE.FREE2) //ts++二次准备状态
  877. {
  878. // 状态校验
  879. if (user.state2 != User.STATE.FREE) {
  880. return { code: C.FAILD, msg: C.PLAYER_NOT_FREE };
  881. }
  882. }
  883. else
  884. {
  885. // 状态校验
  886. if (user.state != User.STATE.FREE) {
  887. return { code: C.FAILD, msg: C.PLAYER_NOT_FREE };
  888. }
  889. if (user.table.state != Table.STATE.FREE) {
  890. return { code: C.FAILD, msg: C.TABLE_NOT_FREE };
  891. }
  892. }
  893. // 局数完成
  894. if (user.table.isGameOk) {
  895. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  896. }
  897. // let str6 = "csjiang 22准备 "+playerId;
  898. // logger.info(str6);////cssj
  899. return user.table.readyGameAsync(user);
  900. });
  901. // 开始游戏
  902. proto.startGameAsync = P.coroutine(function* (playerId) {
  903. // console.warn("开始游戏+++++++++playerId:%s",playerId);
  904. // let str6 = "csjiang 开始游戏 "+playerId;
  905. // logger.info(str6);////cssj
  906. // 查找玩家
  907. var user = this.users[playerId];
  908. if (!user) {
  909. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  910. }
  911. if (user.chairId == -1) {
  912. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  913. }
  914. // 状态校验
  915. var table = user.table;
  916. if (table.state != Table.STATE.FREE) {
  917. return { code: C.FAILD, msg: C.TABLE_NOT_FREE };
  918. }
  919. // 是否房主
  920. if (!user.isOwner()) {
  921. return { code: C.FAILD, msg: C.TABLE_NOT_OWNER };
  922. }
  923. // 局数完成
  924. if (table.isGameOk) {
  925. return { code: C.FAILD, msg: C.TABLE_GAME_OVER };
  926. }
  927. // 是否准备
  928. if (!table.isReady()) {
  929. return { code: C.FAILD, msg: C.TABLE_NOT_READY };
  930. }
  931. // let str5 = "csjiang 222开始游戏 "+playerId;
  932. // logger.info(str5);////cssj
  933. return table.startGameAsync();
  934. });
  935. // 出牌处理
  936. proto.outCardAsync = P.coroutine(function* (playerId, card) {
  937. // console.warn("出牌处理+++++++++playerId:%s",playerId);
  938. // let str5 = "csjiang 出牌处理 "+playerId+"==card "+card;
  939. // logger.info(str5);////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.chairId == -1) {
  946. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  947. }
  948. // 状态校验
  949. if (user.state !== User.STATE.PLAYING) {
  950. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  951. }
  952. if (user.table.state !== Table.STATE.PLAYING) {
  953. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  954. }
  955. // let str6 = "csjiang 22出牌处理 "+playerId+" card "+card
  956. // logger.info(str6);////cssj
  957. let str3 = "csjiang 出牌---id:"+user.table.id + " ,uid "+user.chairId+" card "+card+" playerId "+ playerId;
  958. logger.warn(str3);////cssj
  959. return user.table.outCardAsync(user.chairId, card);
  960. });
  961. // 杠牌处理,1-普通杠, 2-暗杠, 3-自摸明杠
  962. proto.gangCardAsync = P.coroutine(function* (playerId, card, type) {
  963. // console.warn("杠牌处理+++++++++playerId:%s",playerId);
  964. // let str6 = "csjiang 杠牌处理, "+playerId+"==card "+card;
  965. // logger.info(str6);////cssj
  966. // 查找玩家
  967. var user = this.users[playerId];
  968. if (!user) {
  969. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  970. }
  971. if (user.chairId == -1) {
  972. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  973. }
  974. // 状态校验
  975. if (user.state !== User.STATE.PLAYING) {
  976. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  977. }
  978. if (user.table.state !== Table.STATE.PLAYING) {
  979. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  980. }
  981. // let str5 = "csjiang 22杠牌处理, "+playerId+"==card "+card
  982. // logger.info(str5);////cssj
  983. let str3 = "csjiang 杠牌---id:"+user.table.id + " ,uid "+user.chairId+" card "+card+" type "+type+" playerId "+ playerId;
  984. logger.warn(str3);////cssj
  985. return user.table.gangCardAsync(user.chairId, card, type);
  986. });
  987. // 碰牌处理
  988. proto.pengCardAsync = P.coroutine(function* (playerId, card) {
  989. // console.warn("碰牌处理+++++++++playerId:%s",playerId);
  990. // let str5 = "csjiang 碰牌处理 "+playerId+"==card "+card;
  991. // logger.info(str5);////cssj
  992. // 查找玩家
  993. var user = this.users[playerId];
  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.PLAYING) {
  1002. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1003. }
  1004. if (user.table.state !== Table.STATE.PLAYING) {
  1005. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1006. }
  1007. // let str3 = "csjiang 22碰牌处理 "+playerId+"==card "+card;
  1008. // logger.info(str3);////cssj
  1009. let str3 = "csjiang 碰牌---id:"+user.table.id + " ,uid "+user.chairId+" card "+card+" playerId "+ playerId;
  1010. logger.warn(str3);////cssj
  1011. return user.table.pengCardAsync(user.chairId, card);
  1012. });
  1013. // 吃牌处理,1-@**左吃, 2-*@*中吃, 3-@**右吃
  1014. proto.eatCardAsync = P.coroutine(function* (playerId, card, type) {
  1015. // console.warn("吃牌处理+++++++++playerId:%s",playerId);
  1016. // let str2 = "csjiang 吃牌处理, "+playerId+"==card "+card;
  1017. // logger.info(str2);////cssj
  1018. // 查找玩家
  1019. var user = this.users[playerId];
  1020. if (!user) {
  1021. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1022. }
  1023. if (user.chairId == -1) {
  1024. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1025. }
  1026. // 状态校验
  1027. if (user.state !== User.STATE.PLAYING) {
  1028. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1029. }
  1030. if (user.table.state !== Table.STATE.PLAYING) {
  1031. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1032. }
  1033. // let str1 = "csjiang 222吃牌处理, "+playerId+"==card "+card
  1034. // logger.info(str1);////cssj
  1035. let str3 = "csjiang 吃牌---id:"+user.table.id + " ,uid "+user.chairId+" card "+card+" type "+type+" playerId "+ playerId;
  1036. logger.warn(str3);////cssj
  1037. return user.table.eatCardAsync(user.chairId, card, type);
  1038. });
  1039. // 补牌处理
  1040. proto.buCardAsync = P.coroutine(function* (playerId, card, type) {
  1041. // console.warn("胡牌处理+++++++++playerId:%s",playerId);
  1042. // let str1 = "csjiang 胡牌处理,"+playerId;
  1043. // logger.info(str1);////cssj
  1044. // 查找玩家
  1045. var user = this.users[playerId];
  1046. if (!user) {
  1047. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1048. }
  1049. if (user.chairId == -1) {
  1050. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1051. }
  1052. // 状态校验
  1053. if (user.state !== User.STATE.PLAYING) {
  1054. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1055. }
  1056. if (user.table.state !== Table.STATE.PLAYING) {
  1057. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1058. }
  1059. // let str2 = "csjiang 22胡牌处理,"+playerId;
  1060. // logger.info(str2);////cssj
  1061. let str3 = "csjiang 补牌---id:"+user.table.id + " ,uid "+user.chairId+" card "+card+" type "+type+" playerId "+ playerId;
  1062. logger.warn(str3);////cssj
  1063. return user.table.buCardAsync(user.chairId, card, type);
  1064. });
  1065. // 起手胡牌处理
  1066. proto.qshCardAsync = P.coroutine(function* (playerId, type, cards) {
  1067. // console.warn("胡牌处理+++++++++playerId:%s",playerId);
  1068. // let str1 = "csjiang 胡牌处理,"+playerId;
  1069. // logger.info(str1);////cssj
  1070. // 查找玩家
  1071. var user = this.users[playerId];
  1072. if (!user) {
  1073. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1074. }
  1075. if (user.chairId == -1) {
  1076. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1077. }
  1078. // 状态校验
  1079. if (user.state !== User.STATE.PLAYING) {
  1080. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1081. }
  1082. if (user.table.state !== Table.STATE.PLAYING) {
  1083. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1084. }
  1085. let str2 = "csjiang 起手胡牌处理"+playerId+ " type: " + type;
  1086. logger.warn(str2);////cssj
  1087. return user.table.qshCardAsync(user.chairId, type, cards);
  1088. });
  1089. // 胡牌处理,1-自摸, 2-点炮
  1090. proto.succCardAsync = P.coroutine(function* (playerId) {
  1091. // console.warn("胡牌处理+++++++++playerId:%s",playerId);
  1092. // let str1 = "csjiang 胡牌处理,"+playerId;
  1093. // logger.info(str1);////cssj
  1094. // 查找玩家
  1095. var user = this.users[playerId];
  1096. if (!user) {
  1097. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1098. }
  1099. if (user.chairId == -1) {
  1100. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1101. }
  1102. // 状态校验
  1103. if (user.state !== User.STATE.PLAYING) {
  1104. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1105. }
  1106. if (user.table.state !== Table.STATE.PLAYING) {
  1107. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1108. }
  1109. let str2 = "csjiang 22胡牌处理,"+playerId+" uid "+user.chairId;;
  1110. logger.warn(str2);////cssj
  1111. return user.table.succCardAsync(user.chairId);
  1112. });
  1113. // 放弃吃碰杠胡
  1114. proto.giveUpAsync = P.coroutine(function* (playerId) {
  1115. // console.warn("放弃吃碰杠胡+++++++++playerId:%s",playerId);
  1116. // let str1 = "csjiang 放弃吃碰杠胡 "+playerId;
  1117. // logger.info(str1);////cssj
  1118. // 查找玩家
  1119. var user = this.users[playerId];
  1120. if (!user) {
  1121. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1122. }
  1123. if (user.chairId == -1) {
  1124. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1125. }
  1126. // 状态校验
  1127. if (user.state !== User.STATE.PLAYING) {
  1128. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1129. }
  1130. if (user.table.state !== Table.STATE.PLAYING) {
  1131. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1132. }
  1133. let str2 = "csjiang 放弃吃碰杠胡 "+playerId+" uid "+user.chairId;
  1134. logger.warn(str2);////cssj
  1135. return user.table.giveUpAsync(user.chairId);
  1136. });
  1137. // //////TL++,是否进行海底捞月的操作
  1138. proto.haiDiLaoYue = P.coroutine(function* (playerId,type) {
  1139. // console.warn("是否进行海底捞月的操作+++++++++playerId:%s",playerId);
  1140. let str1 = "csjiang 是否进行海底捞月的操作 "+playerId+type;
  1141. logger.warn(str1);////cssj
  1142. // 查找玩家
  1143. // console.warn("海底捞月2");
  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. // 状态校验
  1152. if (user.state !== User.STATE.PLAYING) {
  1153. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1154. }
  1155. if (user.table.state !== Table.STATE.PLAYING) {
  1156. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1157. }
  1158. // console.warn("海底捞月3");
  1159. // let str2 = "csjiang 22是否进行海底捞月的操作 "+playerId;
  1160. // logger.info(str2);////cssj
  1161. return user.table.haiDiLaoYue(user.chairId,type);
  1162. });
  1163. // 操作是否自动出牌
  1164. proto.autoOutCard = P.coroutine(function* (playerId) {
  1165. console.warn("操作是否自动出牌+++++++++playerId:%s",playerId);
  1166. // let str1 = "csjiang 操作是否自动出牌 "+playerId;
  1167. // logger.info(str1);////cssj
  1168. // 查找玩家
  1169. var user = this.users[playerId];
  1170. if (!user) {
  1171. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1172. }
  1173. if (user.chairId == -1) {
  1174. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1175. }
  1176. // 状态校验
  1177. if (user.state !== User.STATE.PLAYING) {
  1178. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1179. }
  1180. if (user.table.state !== Table.STATE.PLAYING) {
  1181. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1182. }
  1183. // let str2 = "csjiang 操作是否自动出牌 "+playerId;
  1184. // logger.info(str2);////cssj
  1185. return user.table.autoOutCardAsync(user.chairId);
  1186. });
  1187. // 发送聊天
  1188. proto.sendMsgAsync = P.coroutine(function* (playerId, msg) {
  1189. // console.warn("发送聊天+++++++++playerId:%s",playerId);
  1190. // let str2 = "csjiang 发送聊天 "+playerId;
  1191. // logger.info(str2);////cssj
  1192. // 查找玩家
  1193. var user = this.users[playerId];
  1194. if (!user) {
  1195. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1196. }
  1197. if (!user.table) {
  1198. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1199. }
  1200. // let str1 = "csjiang 222发送聊天 "+playerId;
  1201. // logger.info(str1);////cssj
  1202. return user.table.sendMsgAsync(user.chairId, msg);
  1203. });
  1204. // 收费聊天
  1205. proto.vsendMsgAsync = P.coroutine(function* (playerId, chairId, msg) {
  1206. // console.warn("收费聊天+++++++++playerId:%s",playerId);
  1207. // let str1 = "csjiang 收费聊天 "+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. // let str2 = "csjiang 22收费聊天 "+playerId;
  1218. // logger.info(str2);////cssj
  1219. return user.table.vsendMsgAsync(user.chairId, chairId, msg);
  1220. });
  1221. // 角色信息
  1222. proto.roleInfoAsync = P.coroutine(function* (playerId, chairId) {
  1223. // console.warn("角色信息+++++++++playerId:%s",playerId);
  1224. // let str2 = "csjiang 角色信息 "+playerId;
  1225. // logger.info(str2);////cssj
  1226. // 查找玩家
  1227. var user = this.users[playerId];
  1228. if (!user) {
  1229. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1230. }
  1231. if (user.chairId == -1) {
  1232. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1233. }
  1234. // let str1 = "csjiang 22角色信息 "+playerId;
  1235. // logger.info(str1);////cssj
  1236. return user.table.roleInfoAsync(chairId);
  1237. });
  1238. // 请求结束
  1239. proto.overTableAsync = P.coroutine(function* (playerId) {
  1240. // console.warn("请求结束+++++++++playerId:%s",playerId);
  1241. // let str1 = "csjiang 请求结束 "+playerId;
  1242. // logger.info(str1);////cssj
  1243. // 查找玩家
  1244. var user = this.users[playerId];
  1245. //////TL++zsyl,原先下面这一段是 游戏开始之前不能申请解散 准备之前不能申请解散
  1246. if (!user) {
  1247. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1248. }
  1249. // if (user.chairId == -1) {
  1250. // return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1251. // }
  1252. // // 状态校验
  1253. // if (user.state <= User.STATE.READY) {
  1254. // return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1255. // }
  1256. // if (user.table.state <= Table.STATE.FREE) {
  1257. // return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1258. // }
  1259. // let str2 = "csjiang 222请求结束 "+playerId;
  1260. // logger.info(str2);////cssj
  1261. return user.table.overTableAsync(user);////TL++参数userID userState
  1262. });
  1263. // 拒绝结束
  1264. proto.refuseOverAsync = P.coroutine(function* (playerId) {
  1265. // let str2 = "csjiang 拒绝结束 "+playerId;
  1266. // logger.info(str2);////cssj
  1267. // console.warn("拒绝结束+++++++++playerId:%s",playerId);
  1268. // 查找玩家
  1269. var user = this.users[playerId];
  1270. if (!user) {
  1271. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1272. }
  1273. if (user.chairId == -1) {
  1274. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1275. }
  1276. // 状态校验
  1277. if (user.state <= User.STATE.READY) {
  1278. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1279. }
  1280. if (user.table.state <= Table.STATE.FREE) {
  1281. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1282. }
  1283. // let str1 = "csjiang 222拒绝结束 "+playerId;
  1284. // logger.info(str1);////cssj
  1285. return user.table.refuseOverAsync(user);
  1286. });
  1287. // 同意结束
  1288. proto.agreeOverAsync = P.coroutine(function* (playerId) {
  1289. // console.warn("同意结束+++++++++playerId:%s",playerId);
  1290. // let str1 = "csjiang 同意结束 "+playerId;
  1291. // logger.info(str1);////cssj
  1292. // 查找玩家
  1293. var user = this.users[playerId];
  1294. if (!user) {
  1295. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1296. }
  1297. if (user.chairId == -1) {
  1298. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1299. }
  1300. // 状态校验
  1301. if (user.state <= User.STATE.READY) {
  1302. return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING };
  1303. }
  1304. if (user.table.state <= Table.STATE.FREE) {
  1305. return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING };
  1306. }
  1307. // let str2 = "csjiang 222同意结束 "+playerId;
  1308. // logger.info(str2);////cssj
  1309. return user.table.agreeOverAsync(user);
  1310. });
  1311. // 得到玩家位置
  1312. proto.getLocationAsync = P.coroutine(function* (playerId,msg) {
  1313. // console.warn("ts+++++得到玩家位置",playerId);
  1314. // 查找玩家
  1315. var user = this.users[playerId];
  1316. if (!user) {
  1317. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  1318. }
  1319. return user.table.getLocationAsync();
  1320. });