entryHandler.js 30 KB

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