entryHandler.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. 'use strict';
  2. var execFile = require('child_process').execFile;
  3. var phantomjs = require('phantomjs-prebuilt');
  4. var request = require('request');
  5. var svg2png = require('svg2png');
  6. var md5 = require("md5")
  7. var path = require('path');
  8. console.log('svg2png 加载成功', svg2png.version);
  9. var https = require('https');
  10. var Jimp = require('jimp');
  11. var fs = require('fs');
  12. var uuid = require('node-uuid');
  13. var util = require('util');
  14. var quick = require('quick-pomelo');
  15. var P = quick.Promise;
  16. var logger = quick.logger.getLogger('connector', __filename);
  17. var C = require('../../../../share/constant');
  18. // var compateDate = require('../../../../share/compateDate');
  19. var phantomjsCmd = phantomjs.path;
  20. console.log('PhantomJS 路径:', phantomjsCmd);
  21. var Handler = function (app) {
  22. this.app = app;
  23. // this.lcompateDate = new compateDate();
  24. };
  25. module.exports = function (app) {
  26. return new Handler(app);
  27. };
  28. var proto = Handler.prototype;
  29. // RPC
  30. proto.getRpc = function (gameId) {
  31. console.log("----进入游戏房间++++++++++++++++++++",gameId)
  32. switch (gameId) {
  33. case 10006: return this.app.rpc.game.csjiangRemote; // 湖南长沙
  34. case 10007: return this.app.rpc.game.sxjiangRemote; // 湖南红中
  35. case 10008: return this.app.rpc.game.paodekuaiRemote; // 湖南跑得快
  36. case 10005: return this.app.rpc.game.shuiguoRemote; // 湖南水果
  37. case 10004: return this.app.rpc.game.paohuziRemote; // 湖南跑胡子
  38. }
  39. };
  40. proto.convertSvgToPng1 = P.coroutine(function* (svgPath, pngPath,cb) {
  41. // 拼接 PhantomJS 要执行的参数:转换脚本、SVG 路径、PNG 路径、缩放比例
  42. var args = [
  43. path.join(__dirname, 'converter.js'), // 转换脚本路径
  44. svgPath,
  45. pngPath,
  46. scale
  47. ];
  48. // 执行 PhantomJS 命令(核心!Node 调用子进程执行 PhantomJS)
  49. execFile(phantomjsCmd, args, function(err, stdout, stderr) {
  50. if (err) {
  51. cb(new Error('PhantomJS 执行失败:' + err.message));
  52. } else if (stderr) {
  53. cb(new Error('PhantomJS 错误输出:' + stderr));
  54. } else if (stdout) {
  55. cb(new Error('PhantomJS 标准输出:' + stdout));
  56. } else {
  57. cb(null); // 转换成功
  58. }
  59. });
  60. });
  61. proto.convertSvgToPng = P.coroutine(function* (svgPath, pngPath, scale, cb) {
  62. // 拼接 PhantomJS 要执行的参数:转换脚本、SVG 路径、PNG 路径、缩放比例
  63. var args = [
  64. "D:\\hnhzServer\\converter.js", //path.join(__dirname, 'converter.js'), // 转换脚本路径
  65. "\./1.svg",
  66. pngPath,
  67. scale
  68. ];
  69. console.warn(args)
  70. console.warn("phantomjsCmd:",phantomjsCmd)
  71. var targetCwd = "D:\\web\\root80\\image"
  72. // 执行 PhantomJS 命令(核心!Node 调用子进程执行 PhantomJS)
  73. execFile(phantomjsCmd, args, {
  74. cwd: targetCwd, // 关键!相当于执行 cd /d D:\hnhzServer\svg_temp
  75. timeout: 10000, // 10秒超时,防止卡死
  76. encoding: 'utf8'
  77. }, function(err, stdout, stderr) {
  78. console.warn("err:",err," stdout:",stdout," stderr:",stderr)
  79. if (err) {
  80. cb(new Error('PhantomJS 执行失败:' + err.message));
  81. } else if (stderr) {
  82. cb(new Error('PhantomJS 错误输出:' + stderr));
  83. } else if (stdout) {
  84. //cb(new Error('PhantomJS 标准输出:' + stdout));
  85. cb(null);
  86. } else {
  87. cb(null); // 转换成功
  88. }
  89. });
  90. });
  91. proto.downloadSvg = P.coroutine(function* (svgUrl, savePath,playerId, cb) {
  92. var self = this
  93. var req = https.get(svgUrl, function(res) {
  94. console.warn("res.statusCode:",res.statusCode)
  95. console.warn("res.headers:",res.headers)
  96. if (res.statusCode === 302 && res.headers.location) {
  97. console.log('检测到302重定向,新地址:', res.headers.location);
  98. // 递归请求重定向后的地址
  99. self.downloadSvg(res.headers.location, destPngPath+playerId+".png",playerId,function(){});
  100. return;
  101. }
  102. if (res.statusCode !== 200) {
  103. return cb(new Error('下载 SVG 失败,状态码:' + res.statusCode));
  104. }
  105. var stream = fs.createWriteStream(savePath);
  106. res.pipe(stream);
  107. stream.on('finish', function() {
  108. stream.close(function() {
  109. cb(null); // 下载完成,无错误
  110. });
  111. });
  112. stream.on('error', function(err) {
  113. fs.unlink(savePath, function(){}); // 删除不完整文件
  114. cb(err);
  115. });
  116. });
  117. req.on('error', cb);
  118. req.setTimeout(10000, function() {
  119. req.destroy();
  120. cb(new Error('下载 SVG 超时'));
  121. });
  122. });
  123. var svgUrl = 'https://bargame.ala456.com/gameRes/1.svg'; // 目标 SVG 地址
  124. var localSvgPath = 'D:\\web\\root80\\image\\1.svg'; // 本地 SVG 路径
  125. var localPngPath = 'D:\\web\\root80\\image\\'; // 本地 PNG 路径
  126. var destPngPath = path.join("D:\\web\\root80\\image\\"); // 目标 PNG 路径
  127. var requestGet = P.promisify(request.get, {multiArgs: true});
  128. proto.fetchSvg = P.coroutine(function* (url, cb) {
  129. const client = url.startsWith('https') ? require('https') : require('http');
  130. client.get(url, (res) => {
  131. if (res.statusCode !== 200) {
  132. cb(new Error('请求 SVG 失败,状态码: ' + res.statusCode));
  133. res.resume();
  134. return;
  135. }
  136. const chunks = [];
  137. res.on('data', (chunk) => chunks.push(chunk));
  138. res.on('end', () => cb(null, Buffer.concat(chunks)));
  139. }).on('error', (e) => cb(e));
  140. });
  141. proto.convertUrlToPng = P.coroutine(function* (url, outputPath) {
  142. try {
  143. console.warn("url:",url)
  144. // 1. 使用 request 获取数据,必须 encoding: null
  145. var result = yield requestGet({
  146. url: url,
  147. encoding: null,
  148. timeout: 10000,
  149. headers: {
  150. 'User-Agent': 'Mozilla/5.0'
  151. }
  152. });
  153. // console.warn("湖南红中 游戏服务器启动",result);
  154. //console.log("result[1]:",result[1])
  155. // 重点:multiArgs: true 会返回 [response, body]
  156. // result[0] 是响应头,result[1] 才是真正的图片 Buffer
  157. var response = result[0];
  158. var body = result[1];
  159. const width = 800;
  160. const height = 600;
  161. if (!response || response.statusCode !== 200) {
  162. throw new Error('Download failed, status: ' + (response ? response.statusCode : 'unknown'));
  163. }
  164. if (!body || body.length === 0) {
  165. throw new Error('Received empty buffer');
  166. }
  167. // 2. 使用 Jimp 读取 Buffer
  168. // 如果依然报 MIME 错误,可以尝试强制指定格式 (仅限确定是 jpg/png 的情况)
  169. svg2png(body, { width, height }, (err, buffer) => {
  170. console.warn("svg2png:",74)
  171. if (err) {
  172. console.warn('SVG 转 PNG 失败:', err);
  173. return;
  174. }
  175. console.warn("svg2png:",78)
  176. fs.writeFile('D:\\web\\root80\\image\\output.png', buffer, (err) => {
  177. if (err) console.warn('写出 PNG 失败:', err);
  178. else console.warn('输出 output.png 完成');
  179. });
  180. });
  181. console.warn("84")
  182. } catch (error) {
  183. // 增加更详细的报错日志,方便排查
  184. console.error('图片转换失败详情:', error.message);
  185. if (error.stack) console.error(error.stack);
  186. }
  187. });
  188. // 登陆
  189. proto.login = P.coroutine(function* (msg, session, next) {
  190. //{"hash":"eaf94f7eff192ff4eb49338bc2c5dd286034cf40b73df81dd4990d8ff3dea0bb","refOrderId":"ORDER20240228001","amount":0.01,"status":0,"message":"\u6210\u529F","fees":0,"feesU":0.123322,"timestamp":1772271039176,"sign":"968121dcd20682ab9dc296296b6aca46"}
  191. var self = this;
  192. if (session.uid) {
  193. return next(null, { code: C.ERROR, msg: C.PLAYER_HAS_LOGGED });
  194. }
  195. if (!msg._id) {
  196. return next(null, { code: C.ERROR, msg: C.PLAYER_HAS_LOGGED });
  197. }
  198. let sgjconfig = yield this.app.models.SGJConfig.findByIdAsync('sgconfigs');
  199. console.warn("sgjconfig:",sgjconfig)
  200. var istelegram = 0
  201. if (sgjconfig) {
  202. istelegram = sgjconfig.istelegram; //排行榜已发奖励的日期(0点时间戳)
  203. // console.warn("获取水果机排行榜已发奖励的日期 ",this.phbyfjlrq);
  204. }
  205. if (istelegram) {
  206. console.warn("msg:",msg)
  207. if (!msg.istelegram || msg.istelegram !== 1) {
  208. return next(null, { code: C.FAILD, msg: C.SERVER_WEIHU });
  209. }
  210. }
  211. // console.warn("登陆+++++%s",msg._id,session.uid);//ts++
  212. // console.warn("登陆+++++ "+ JSON.stringify(msg));//ts++
  213. var playerId = msg._id;
  214. var isNew = 0;
  215. var ip = session.__session__.__socket__.remoteAddress.ip;
  216. let gameId2 = 0;
  217. if(msg.game){
  218. if(msg.game == "mahjongsx"){
  219. gameId2 = 10007;
  220. }
  221. else if(msg.game == "mahjongcs"){
  222. gameId2 = 10006;
  223. }
  224. else if(msg.game == "paodekuai"){
  225. gameId2 = 10008;
  226. }
  227. else if(msg.game == "shuiguo"){
  228. gameId2 = 10005;
  229. }
  230. else if(msg.game == "paohuzi"){
  231. gameId2 = 10004;
  232. }
  233. }
  234. // if(gameId2 == 0) gameId2 = 10007
  235. let formId=0;//开源平台 0为微信
  236. if (msg.formId)
  237. {
  238. formId=parseInt(msg.formId);
  239. }
  240. let isChange = false;
  241. let telStr = ""+msg.tel || "";
  242. let pwdStr = ""+msg.pwd || "";
  243. // console.warn("登陆+++++111%s",playerId);//ts++
  244. var player = yield this.app.models.Player.findByIdAsync(playerId);
  245. // console.warn("登陆+++++222%s",msg._id);//ts++
  246. if (!player) {
  247. // let idq11w = "";
  248. // if(playerId.length == 18) idq11w = playerId.substr(0, 11);//_id前11位
  249. // console.warn("登陆=== telStr: "+telStr+" idq11w "+idq11w);
  250. var yPlayers = [];
  251. if(telStr && telStr.length == 11) yPlayers = yield this.app.models.Player.findMongoAsync({ tel: telStr });
  252. if (yPlayers.length > 1){
  253. // console.warn("手机号被重复绑定=== telStr: ",yPlayers);
  254. return next(null, { code: C.ERROR, msg: 117 });//"手机号被重复绑定"
  255. }
  256. else if (yPlayers.length == 1){
  257. if(pwdStr != yPlayers[0].pwd) {
  258. return next(null, { code: C.ERROR, msg: 118 });//"手机号的密码错误"
  259. }
  260. // console.warn("用手机号登陆成功: ",yPlayers[0]);
  261. playerId = yPlayers[0]._id;
  262. player = yPlayers[0];
  263. isChange = true;
  264. }
  265. else if (yPlayers.length == 0 && playerId.length > 18){//按照手机号查不到用户
  266. //换商户号同步方案
  267. // console.warn("登陆++新用户",msg._id);//ts++
  268. var oldPlayers = yield this.app.models.Player.findMongoAsync({ name: msg.name },'diamond');
  269. if (oldPlayers.length > 0) {
  270. var diamond = oldPlayers[0].diamond;
  271. // console.warn("oldplayer", diamond);
  272. player = yield this.app.controllers.player.createAsync(playerId, msg.name, "1", msg.headurl,telStr,pwdStr, ip, msg.spread,formId,diamond);//ts++upd代理 spread
  273. } else {
  274. player = yield this.app.controllers.player.createAsync(playerId, msg.name, "1", msg.headurl,telStr,pwdStr, ip, msg.spread,formId);//ts++upd代理 spread
  275. }
  276. isNew = 1;
  277. }
  278. else{
  279. return next(null, { code: C.ERROR, msg: 116 });//"目前暂未开放手机号注册新用户"
  280. }
  281. }
  282. else{
  283. if(telStr && telStr.length == 11){
  284. var yPlayers = yield this.app.models.Player.findMongoAsync({ tel: telStr });
  285. if (yPlayers.length == 0){
  286. if(player.tel != telStr){
  287. player.tel = telStr;
  288. isChange = true;
  289. }
  290. if(player.pwd != pwdStr){
  291. player.pwd = pwdStr;
  292. isChange = true;
  293. }
  294. }
  295. }
  296. }
  297. self.downloadSvg(msg.headurl, localSvgPath, playerId, function(err) {
  298. console.warn("96:msg.headurl",msg.headurl)
  299. if (err) {
  300. console.error('下载失败:', err.message);
  301. return;
  302. }
  303. console.log('SVG 已下载到:', localSvgPath);
  304. // 调用转换函数
  305. self.convertSvgToPng(localSvgPath, destPngPath+playerId+".png", 1.0, function(err) {
  306. if (err) {
  307. console.error('转换 PNG 失败:', err.message);
  308. } else {
  309. console.log('转换成功!PNG 路径:', destPngPath);
  310. }
  311. });
  312. });
  313. console.warn("登陆+++++333%s",msg._id);//ts++
  314. let playerIsEnable = 0;
  315. if(typeof(player.enable) == "undefined"){
  316. playerIsEnable = 1;
  317. }
  318. else{
  319. playerIsEnable = player.enable;
  320. }
  321. // console.warn("isNew ===== "+isNew+" registerTime "+player.registerTime);
  322. let tel = player.tel || "";
  323. let pwd = player.pwd || "";
  324. var result = yield this.app.controllers.player.connectAsync(playerId,msg.name,msg.headurl, session.frontendId, ip,msg.sex,formId);
  325. if (result.oldGameSvrId) {
  326. // console.warn("登陆+++++111 "+result.oldGameSvrId+" result.oldGameId "+result.oldGameId);
  327. let oldGameSvrId = result.oldGameSvrId;
  328. let gameRemote = this.getRpc(result.oldGameId);
  329. if (gameRemote) gameRemote.leaveTable.toServer(oldGameSvrId, playerId, () => { });
  330. }
  331. if (result.oldConnectorId) {
  332. // console.warn("登陆+++++222 "+result.oldConnectorId);
  333. let oldConnectorId = result.oldConnectorId;
  334. let entryRemote = this.app.rpc.connector.entryRemote;
  335. yield P.promisify((cb) => entryRemote.kick({ frontendId: oldConnectorId }, playerId, (err, res) => cb(err, res)))();
  336. }
  337. // if(player.rTableId>0)
  338. // {
  339. // //仅仅适用于开发的时候没有退出房间关掉服务器导致进不去房间的时候使用
  340. // console.warn("登陆+++++333 player.rTableId "+player.rTableId);
  341. // player.tableId = '';
  342. // player.gameId = 0;
  343. // player.gameServerId = '';
  344. // player.rTableId = 0
  345. // player.diamond =1000000;
  346. // yield player.saveAsync();
  347. // }
  348. console.warn("登陆+++++444%s",msg._id);//ts++
  349. var self = this;
  350. session.bind(playerId);
  351. session.on('closed', function (session, reason) {
  352. if (reason === 'kick' || !session.uid) {
  353. return;
  354. }
  355. // console.warn("entryHandler用户离开了?????111 "+session.uid);
  356. var goose = self.app.memdb.goose;
  357. goose.transaction(function () {
  358. return P.promisify(self.logout, self)({ closed: true }, session);
  359. }, self.app.getServerId())
  360. .catch(function (e) {
  361. logger.error(e.stack);
  362. });
  363. //
  364. });
  365. // console.warn("登陆+++++555%s",msg._id);//ts++
  366. //logger.info('player %s login', playerId);
  367. //let openId=player.openId;//充值时使用
  368. //ts++代理属性
  369. let agentId='';
  370. let agentNo=String(player.userId);
  371. let agentName=player.name;
  372. //let connectUrl=player.myurl;
  373. let connectUrl='';
  374. let form ='';//新用户来源(如果是来自于推广的链接这里存储agentNo)
  375. if(msg.agentId)
  376. {
  377. // console.warn("代理+++++",msg.agentId);
  378. var agenter = yield this.app.models.Agenter.findByIdReadOnlyAsync(msg.agentId,'agentNo agentName myUrl levelFlag enabled contact tel agentRate');
  379. if (agenter)
  380. {
  381. // console.warn("代理 levelFlag "+agenter.levelFlag+" enabled "+ agenter.enabled+" contact " +agenter.contact+" tel "+agenter.tel+" agentRate "+ agenter.agentRate);
  382. let isEnable = 0;
  383. // let levelFlag = 0;
  384. if(typeof(agenter.enabled) == "undefined"){
  385. isEnable = 1;
  386. }
  387. else{
  388. isEnable = agenter.enabled;;
  389. }
  390. // if(typeof(agenter.levelFlag) == "undefined"){
  391. // levelFlag = 1;
  392. // }
  393. // else{
  394. // levelFlag = agenter.levelFlag;
  395. // }
  396. form=String(agenter.agentNo);
  397. // if(levelFlag != 2 && isEnable == 1){
  398. if(isEnable == 1){
  399. agentId=msg.agentId;
  400. agentNo=String(agenter.agentNo);
  401. agentName = agenter.agentName;
  402. connectUrl = agenter.myUrl;
  403. // if(player.mpId!= agenter.mpId)//重新读取
  404. // {
  405. // openId='';
  406. // }
  407. }
  408. }
  409. // console.warn("代理+++++:",agentName,connectUrl);
  410. }
  411. // if(player.formId!=0)//闲聊用户
  412. // {
  413. // console.warn("闲聊用户+++++:");
  414. // openId='xianliu';
  415. // }
  416. // openId='111111111';
  417. // console.warn("链接参数",msg.nid,msg.fid);
  418. // console.warn("登陆+++++666%s",msg._id);//ts++
  419. let doid=0;//操作指令
  420. let doroomid=0;//操作指令
  421. let dodata=null;//操作数据
  422. if(player.rTableId>0)
  423. {
  424. // console.warn("重入=== ",player.rTableId," gameId2 ",gameId2);
  425. let fjh = parseInt(player.rTableId)%100000;
  426. if(fjh >= 10000 && fjh < 30000) gameId2 = 10007;
  427. else if(fjh >= 30000 && fjh < 50000)gameId2 = 10006;
  428. else if(fjh >= 50000 && fjh < 70000)gameId2 = 10008;
  429. else if(fjh >= 50000 && fjh < 70000)gameId2 = 10008;
  430. else if(fjh >= 70000 && fjh < 80000)gameId2 = 10005;
  431. else if(fjh >= 80000 && fjh < 90000)gameId2 = 10004;
  432. // console.warn("重入111=== ",fjh," gameId2 ",gameId2);
  433. doid=1;//重入
  434. dodata = {
  435. gameId: gameId2
  436. };
  437. doroomid = player.rTableId;
  438. }
  439. else
  440. {
  441. if (msg.fid)
  442. {
  443. let nid=parseInt(msg.nid);
  444. let fid=msg.fid;
  445. if (nid==0)
  446. {
  447. //console.warn("查询房间",fid);
  448. if(fid!="" && fid.length>7)
  449. {
  450. // logger.warn("login findByIdReadOnlyAsync fid111--------" + fid );
  451. var record = yield this.app.models.FHMJTables.findByIdReadOnlyAsync(fid);
  452. if (!record) {
  453. // console.warn("这个房间没有战绩",fid);
  454. let room = fid.substr(fid.length - 7, fid.length)/////因为后六位为房间号
  455. doid=2;//加入房间
  456. dodata = {
  457. gameId: gameId2
  458. };
  459. doroomid = parseInt(room);
  460. // console.warn("下面功能疑似造成数据死锁故暂时去掉");
  461. // let fjsfysc = 0;//房间是否已删除
  462. // var gametable = yield this.app.models.GameTable.findByIdAsync(fid, '_id tableNo agentId type kind other playerCount round endMode');
  463. // if(gametable){
  464. // fjsfysc = gametable.endMode||0;//房间是否已删除
  465. // // console.warn("这个房间有gametable",fjsfysc,gametable.endMode);
  466. // if(fjsfysc){
  467. // // console.warn("这个房间有gametable设置为再来一局",fjsfysc);
  468. // doid=4;//再来一局
  469. // dodata = {
  470. // tableId: String(gametable.tableNo),
  471. // gameId: gameId2,
  472. // upId: String(gametable._id),
  473. // round: String(gametable.round),
  474. // kind: String(gametable.kind),
  475. // playercount: String(gametable.playerCount),
  476. // type: String(gametable.type),
  477. // other: String(gametable.other),
  478. // agentId: String(gametable.agentId)
  479. // }
  480. // }
  481. // }
  482. // if(!fjsfysc){
  483. // // console.warn("这个房间mei有gametable222这个房间没有被删除u ",fjsfysc);
  484. // let room = fid.substr(fid.length - 7, fid.length)/////因为后六位为房间号
  485. // doid=2;//加入房间
  486. // dodata = {
  487. // gameId: gameId2
  488. // };
  489. // doroomid = parseInt(room);
  490. // }
  491. //console.warn("加入房间",doroomid);
  492. }
  493. else
  494. {
  495. doid=3;//显示战绩
  496. dodata = {
  497. _id:record._id,
  498. gameId: record.gameId,
  499. tableNo: record.tableNo,
  500. agentId: record.agentId,
  501. type: record.type,
  502. kind: record.kind,
  503. other: record.other,
  504. playerCount: record.playerCount,
  505. round: record.round,
  506. over: record.over,
  507. time: record.time,
  508. ctime: record.ctime,
  509. // sszjFile: record.sszjFile,
  510. sszj: record.sszj,
  511. users: record.users
  512. };
  513. //console.warn("显示战绩数据",dodata);
  514. }
  515. }
  516. }
  517. else if(nid==1)
  518. {
  519. //console.warn("再来一局 查询房间",fid);
  520. if(fid!="" && fid.length>7)
  521. {
  522. // logger.warn("login findByIdReadOnlyAsync fid222--------" + fid );
  523. var record = yield this.app.models.FHMJTables.findByIdReadOnlyAsync(fid,'_id gameId tableNo agentId type kind other playerCount round over ctime stime time endMode sszj users');
  524. if (!record) {
  525. //console.warn("再来一局 没有战绩",fid);
  526. }
  527. else
  528. {
  529. doid=4;//再来一局
  530. dodata = {
  531. tableId: String(record.tableNo),
  532. gameId: record.gameId,
  533. upId: String(record._id),
  534. round: String(record.round),
  535. kind: String(record.kind),
  536. playercount: String(record.playerCount),
  537. type: String(record.type),
  538. other: String(record.other),
  539. agentId: String(agentId)
  540. }
  541. // console.warn("再来一局数据",dodata);
  542. }
  543. }
  544. }
  545. }
  546. }
  547. ////TL++20200928,因为正式服的绝大多数玩家是没有记录推荐人这个字段(spreadId)的,一少部分记录的是推荐人的_id,一部分人记录的是推荐人userId
  548. ////为了统一,在这里玩家登录的时候对玩家的推荐人(spreadId)字段统一记录为该玩家推荐人的userId
  549. // console.warn("接下来修改玩家的推荐id msg. player. ",msg.spread,typeof msg.spread,player.spreadId,typeof player.spreadId);
  550. let spreadId = "";
  551. if((msg.spread+"").length == 6){
  552. let msgspread = parseInt(msg.spread)||0;
  553. if(msgspread >= 100000 && msgspread <= 999999) spreadId = msg.spread + ""
  554. }
  555. if(!spreadId) spreadId = "99999999";
  556. if(spreadId){
  557. let gwjdtjridsfhf = false;////该登陆玩家的推荐人id是否合法
  558. if((player.spreadId+"").length == 6){
  559. let playerspread = parseInt(player.spreadId)||0;
  560. if(playerspread >= 100000 && playerspread <= 999999){
  561. // console.warn("推荐人是不是自己",playerspread == parseInt(spreadId));
  562. ////推荐人不能是自己
  563. if(playerspread != parseInt(player.userId)){
  564. gwjdtjridsfhf = true;
  565. }
  566. else{
  567. spreadId = "99999999";
  568. }
  569. }
  570. }
  571. else if((player.spreadId+"").length == 0){
  572. if(parseInt(spreadId) == player.userId){
  573. spreadId = "99999999";
  574. }
  575. }
  576. else if((player.spreadId+"").length == 8 && player.spreadId == "99999999"){
  577. gwjdtjridsfhf = true;////推荐人是系统就不改了
  578. }
  579. else if((player.spreadId+"").length > 8){
  580. let spreader = yield this.app.models.Player.findByIdAsync(player.spreadId, 'userId');
  581. if (spreader) {
  582. spreadId = spreader.userId+"";
  583. }
  584. else{
  585. spreadId = "99999999";
  586. }
  587. }
  588. // gwjdtjridsfhf = false;
  589. // spreadId = "";
  590. // console.warn("合法吗???gwjdtjridsfhf ",gwjdtjridsfhf,"player",player.spreadId , "spreadId",spreadId);
  591. if(!gwjdtjridsfhf){////不合法需要修改
  592. player.spreadId = spreadId;
  593. // console.warn("不合法需要修改呢",player.spreadId);
  594. if(isNew && form){
  595. player.form = form;
  596. }
  597. isChange = true;
  598. }
  599. else{
  600. if(isNew && form){
  601. player.form = form;
  602. isChange = true;
  603. }
  604. }
  605. }
  606. else{
  607. if(isNew && form){
  608. player.form = form;
  609. isChange = true;
  610. }
  611. }
  612. //if(isChange){
  613. player.status = 6
  614. yield player.saveAsync();
  615. //}
  616. let nowTime = Date.now();///TL++
  617. // console.warn("??????????? rId "+player.rTableId+" doid "+doid +" doroomid "+doroomid+" dodata "+JSON.stringify(dodata));
  618. // console.warn("登陆+++++777 "+msg._id+" rId "+player.rTableId+" doid "+doid +" doroomid "+doroomid+" dodata "+JSON.stringify(dodata));//ts++
  619. if(dodata == null){
  620. dodata = {
  621. gameId: 0
  622. };
  623. }
  624. if(isNew){
  625. //给邀请新人按比例送钻这个活动记录新用户的邀请人信息,测试的话可以不用判断isNew
  626. yield this.app.controllers.player.setNewerYQXXAsync(playerId, player.userId, parseInt(msg.spread));
  627. }
  628. //在玩家登陆的时候给玩家发邮件,比如发送活动的奖励邮件等等
  629. yield this.app.controllers.player.sendMailOnLoginAsync(playerId, player.userId);
  630. console.warn("登陆+++++888==================================下面是登陆返回了",playerId,player.userId);
  631. let taskQuan = 0
  632. let sgjUser = yield this.app.models.SGJUser.findByIdAsync(playerId);
  633. if (sgjUser) {
  634. taskQuan = sgjUser.taskQuan.toFixed(2)
  635. }
  636. yield this.app.controllers.player.sendMailOnLoginAsync(playerId, player.userId);
  637. let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'whTip stateWH rebaterate yxndlbTime yxndlbTip');
  638. var whtip = whdata.yxndlbTip
  639. var isweihu = 0
  640. if (whdata.stateWH != 0) {
  641. isweihu = 1
  642. whtip = whdata.whTip
  643. }
  644. var SGJConfigs = yield this.app.models.SGJConfig.findMongoAsync()
  645. var SGJConfig = SGJConfigs[0]
  646. return next(null, { code: C.OK, data: {
  647. isNew: isNew,
  648. player: {
  649. _id: player._id,
  650. account: player.account,
  651. userId: String(player.userId),
  652. name: player.name,
  653. headurl:encodeURIComponent(player.headurl),
  654. taskQuan:taskQuan,
  655. sex: player.sex,
  656. diamond: String(player.diamond),
  657. synPlayer:player.synPlayer,
  658. rId: String(player.rTableId),
  659. connectUrl: connectUrl,
  660. agentId: agentId,
  661. agentNo: agentNo,
  662. agentName: agentName,
  663. doid: String(doid),
  664. doroomid: String(doroomid),
  665. nowTime: nowTime,
  666. dodata: dodata,
  667. enabled: playerIsEnable,
  668. registerTime: player.registerTime,
  669. sfkjxyx: true,//是否可进小游戏
  670. tel: tel,
  671. pwd: pwd,
  672. smName:player.smName,
  673. smCardId: player.smCardId,
  674. isweihu: isweihu,
  675. yxndlbTip:whtip,
  676. fee: SGJConfig.withdrawfee,
  677. withdrawlowlimit:SGJConfig.withdrawlowlimit
  678. }
  679. }
  680. });
  681. });
  682. // 登出
  683. proto.logout = P.coroutine(function* (msg, session, next) {
  684. // console.error("logout logout "+session.uid+" msg.closed "+msg.closed);
  685. if (!session.uid) {
  686. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  687. }
  688. var playerId = session.uid;
  689. var result = yield this.app.controllers.player.disconnectAsync(playerId);
  690. if (result.gameSvrId) {
  691. let gameSvrId = result.gameSvrId;
  692. let gameRemote = this.getRpc(result.gameId)
  693. if (gameRemote) gameRemote.leaveTable.toServer(gameSvrId, playerId, () => { });
  694. }
  695. else{
  696. this.app.rpc.hall.hallRemote.leave.toServer("hall-server-1", playerId, () => { });
  697. }
  698. if (!msg.closed) {
  699. yield P.promisify(session.unbind, session)(playerId);
  700. }
  701. logger.info('player %s logout', playerId);
  702. return next(null, { code: C.OK });
  703. });
  704. proto.getTodaySJC = function (){
  705. var today = new Date();
  706. today.setHours(0);
  707. today.setMinutes(0);
  708. today.setSeconds(0);
  709. today.setMilliseconds(0);
  710. let jrsjc = today.getTime();
  711. // console.warn("111得到今日0点的时间戳 ",jrsjc, typeof jrsjc);
  712. return jrsjc;
  713. };