entryHandler.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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. self.downloadSvg(msg.headurl, localSvgPath, playerId, function(err) {
  299. console.warn("96:msg.headurl",msg.headurl)
  300. if (err) {
  301. console.error('下载失败:', err.message);
  302. return;
  303. }
  304. console.log('SVG 已下载到:', localSvgPath);
  305. // 调用转换函数
  306. self.convertSvgToPng(localSvgPath, destPngPath+md5(playerId)+".png", 1.0, function(err) {
  307. if (err) {
  308. console.error('转换 PNG 失败:', err.message);
  309. } else {
  310. console.log('转换成功!PNG 路径:', destPngPath);
  311. }
  312. });
  313. });
  314. console.warn("登陆+++++333%s",msg._id);//ts++
  315. let playerIsEnable = 0;
  316. if(typeof(player.enable) == "undefined"){
  317. playerIsEnable = 1;
  318. }
  319. else{
  320. playerIsEnable = player.enable;
  321. }
  322. // console.warn("isNew ===== "+isNew+" registerTime "+player.registerTime);
  323. let tel = player.tel || "";
  324. let pwd = player.pwd || "";
  325. var result = yield this.app.controllers.player.connectAsync(playerId,msg.name,msg.headurl, session.frontendId, ip,msg.sex,formId);
  326. if (result.oldGameSvrId) {
  327. // console.warn("登陆+++++111 "+result.oldGameSvrId+" result.oldGameId "+result.oldGameId);
  328. let oldGameSvrId = result.oldGameSvrId;
  329. let gameRemote = this.getRpc(result.oldGameId);
  330. if (gameRemote) gameRemote.leaveTable.toServer(oldGameSvrId, playerId, () => { });
  331. }
  332. if (result.oldConnectorId) {
  333. // console.warn("登陆+++++222 "+result.oldConnectorId);
  334. let oldConnectorId = result.oldConnectorId;
  335. let entryRemote = this.app.rpc.connector.entryRemote;
  336. yield P.promisify((cb) => entryRemote.kick({ frontendId: oldConnectorId }, playerId, (err, res) => cb(err, res)))();
  337. }
  338. // if(player.rTableId>0)
  339. // {
  340. // //仅仅适用于开发的时候没有退出房间关掉服务器导致进不去房间的时候使用
  341. // console.warn("登陆+++++333 player.rTableId "+player.rTableId);
  342. // player.tableId = '';
  343. // player.gameId = 0;
  344. // player.gameServerId = '';
  345. // player.rTableId = 0
  346. // player.diamond =1000000;
  347. // yield player.saveAsync();
  348. // }
  349. console.warn("登陆+++++444%s",msg._id);//ts++
  350. var self = this;
  351. session.bind(playerId);
  352. session.on('closed', function (session, reason) {
  353. if (reason === 'kick' || !session.uid) {
  354. return;
  355. }
  356. // console.warn("entryHandler用户离开了?????111 "+session.uid);
  357. var goose = self.app.memdb.goose;
  358. goose.transaction(function () {
  359. return P.promisify(self.logout, self)({ closed: true }, session);
  360. }, self.app.getServerId())
  361. .catch(function (e) {
  362. logger.error(e.stack);
  363. });
  364. //
  365. });
  366. // console.warn("登陆+++++555%s",msg._id);//ts++
  367. //logger.info('player %s login', playerId);
  368. //let openId=player.openId;//充值时使用
  369. //ts++代理属性
  370. let agentId='';
  371. let agentNo=String(player.userId);
  372. let agentName=player.name;
  373. //let connectUrl=player.myurl;
  374. let connectUrl='';
  375. let form ='';//新用户来源(如果是来自于推广的链接这里存储agentNo)
  376. if(msg.agentId)
  377. {
  378. // console.warn("代理+++++",msg.agentId);
  379. var agenter = yield this.app.models.Agenter.findByIdReadOnlyAsync(msg.agentId,'agentNo agentName myUrl levelFlag enabled contact tel agentRate');
  380. if (agenter)
  381. {
  382. // console.warn("代理 levelFlag "+agenter.levelFlag+" enabled "+ agenter.enabled+" contact " +agenter.contact+" tel "+agenter.tel+" agentRate "+ agenter.agentRate);
  383. let isEnable = 0;
  384. // let levelFlag = 0;
  385. if(typeof(agenter.enabled) == "undefined"){
  386. isEnable = 1;
  387. }
  388. else{
  389. isEnable = agenter.enabled;;
  390. }
  391. // if(typeof(agenter.levelFlag) == "undefined"){
  392. // levelFlag = 1;
  393. // }
  394. // else{
  395. // levelFlag = agenter.levelFlag;
  396. // }
  397. form=String(agenter.agentNo);
  398. // if(levelFlag != 2 && isEnable == 1){
  399. if(isEnable == 1){
  400. agentId=msg.agentId;
  401. agentNo=String(agenter.agentNo);
  402. agentName = agenter.agentName;
  403. connectUrl = agenter.myUrl;
  404. // if(player.mpId!= agenter.mpId)//重新读取
  405. // {
  406. // openId='';
  407. // }
  408. }
  409. }
  410. // console.warn("代理+++++:",agentName,connectUrl);
  411. }
  412. // if(player.formId!=0)//闲聊用户
  413. // {
  414. // console.warn("闲聊用户+++++:");
  415. // openId='xianliu';
  416. // }
  417. // openId='111111111';
  418. // console.warn("链接参数",msg.nid,msg.fid);
  419. // console.warn("登陆+++++666%s",msg._id);//ts++
  420. let doid=0;//操作指令
  421. let doroomid=0;//操作指令
  422. let dodata=null;//操作数据
  423. if(player.rTableId>0)
  424. {
  425. // console.warn("重入=== ",player.rTableId," gameId2 ",gameId2);
  426. let fjh = parseInt(player.rTableId)%100000;
  427. if(fjh >= 10000 && fjh < 30000) gameId2 = 10007;
  428. else if(fjh >= 30000 && fjh < 50000)gameId2 = 10006;
  429. else if(fjh >= 50000 && fjh < 70000)gameId2 = 10008;
  430. else if(fjh >= 50000 && fjh < 70000)gameId2 = 10008;
  431. else if(fjh >= 70000 && fjh < 80000)gameId2 = 10005;
  432. else if(fjh >= 80000 && fjh < 90000)gameId2 = 10004;
  433. // console.warn("重入111=== ",fjh," gameId2 ",gameId2);
  434. doid=1;//重入
  435. dodata = {
  436. gameId: gameId2
  437. };
  438. doroomid = player.rTableId;
  439. }
  440. else
  441. {
  442. if (msg.fid)
  443. {
  444. let nid=parseInt(msg.nid);
  445. let fid=msg.fid;
  446. if (nid==0)
  447. {
  448. //console.warn("查询房间",fid);
  449. if(fid!="" && fid.length>7)
  450. {
  451. // logger.warn("login findByIdReadOnlyAsync fid111--------" + fid );
  452. var record = yield this.app.models.FHMJTables.findByIdReadOnlyAsync(fid);
  453. if (!record) {
  454. // console.warn("这个房间没有战绩",fid);
  455. let room = fid.substr(fid.length - 7, fid.length)/////因为后六位为房间号
  456. doid=2;//加入房间
  457. dodata = {
  458. gameId: gameId2
  459. };
  460. doroomid = parseInt(room);
  461. // console.warn("下面功能疑似造成数据死锁故暂时去掉");
  462. // let fjsfysc = 0;//房间是否已删除
  463. // var gametable = yield this.app.models.GameTable.findByIdAsync(fid, '_id tableNo agentId type kind other playerCount round endMode');
  464. // if(gametable){
  465. // fjsfysc = gametable.endMode||0;//房间是否已删除
  466. // // console.warn("这个房间有gametable",fjsfysc,gametable.endMode);
  467. // if(fjsfysc){
  468. // // console.warn("这个房间有gametable设置为再来一局",fjsfysc);
  469. // doid=4;//再来一局
  470. // dodata = {
  471. // tableId: String(gametable.tableNo),
  472. // gameId: gameId2,
  473. // upId: String(gametable._id),
  474. // round: String(gametable.round),
  475. // kind: String(gametable.kind),
  476. // playercount: String(gametable.playerCount),
  477. // type: String(gametable.type),
  478. // other: String(gametable.other),
  479. // agentId: String(gametable.agentId)
  480. // }
  481. // }
  482. // }
  483. // if(!fjsfysc){
  484. // // console.warn("这个房间mei有gametable222这个房间没有被删除u ",fjsfysc);
  485. // let room = fid.substr(fid.length - 7, fid.length)/////因为后六位为房间号
  486. // doid=2;//加入房间
  487. // dodata = {
  488. // gameId: gameId2
  489. // };
  490. // doroomid = parseInt(room);
  491. // }
  492. //console.warn("加入房间",doroomid);
  493. }
  494. else
  495. {
  496. doid=3;//显示战绩
  497. dodata = {
  498. _id:record._id,
  499. gameId: record.gameId,
  500. tableNo: record.tableNo,
  501. agentId: record.agentId,
  502. type: record.type,
  503. kind: record.kind,
  504. other: record.other,
  505. playerCount: record.playerCount,
  506. round: record.round,
  507. over: record.over,
  508. time: record.time,
  509. ctime: record.ctime,
  510. // sszjFile: record.sszjFile,
  511. sszj: record.sszj,
  512. users: record.users
  513. };
  514. //console.warn("显示战绩数据",dodata);
  515. }
  516. }
  517. }
  518. else if(nid==1)
  519. {
  520. //console.warn("再来一局 查询房间",fid);
  521. if(fid!="" && fid.length>7)
  522. {
  523. // logger.warn("login findByIdReadOnlyAsync fid222--------" + fid );
  524. 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');
  525. if (!record) {
  526. //console.warn("再来一局 没有战绩",fid);
  527. }
  528. else
  529. {
  530. doid=4;//再来一局
  531. dodata = {
  532. tableId: String(record.tableNo),
  533. gameId: record.gameId,
  534. upId: String(record._id),
  535. round: String(record.round),
  536. kind: String(record.kind),
  537. playercount: String(record.playerCount),
  538. type: String(record.type),
  539. other: String(record.other),
  540. agentId: String(agentId)
  541. }
  542. // console.warn("再来一局数据",dodata);
  543. }
  544. }
  545. }
  546. }
  547. }
  548. ////TL++20200928,因为正式服的绝大多数玩家是没有记录推荐人这个字段(spreadId)的,一少部分记录的是推荐人的_id,一部分人记录的是推荐人userId
  549. ////为了统一,在这里玩家登录的时候对玩家的推荐人(spreadId)字段统一记录为该玩家推荐人的userId
  550. // console.warn("接下来修改玩家的推荐id msg. player. ",msg.spread,typeof msg.spread,player.spreadId,typeof player.spreadId);
  551. let spreadId = "";
  552. if((msg.spread+"").length == 6){
  553. let msgspread = parseInt(msg.spread)||0;
  554. if(msgspread >= 100000 && msgspread <= 999999) spreadId = msg.spread + ""
  555. }
  556. if(!spreadId) spreadId = "99999999";
  557. if(spreadId){
  558. let gwjdtjridsfhf = false;////该登陆玩家的推荐人id是否合法
  559. if((player.spreadId+"").length == 6){
  560. let playerspread = parseInt(player.spreadId)||0;
  561. if(playerspread >= 100000 && playerspread <= 999999){
  562. // console.warn("推荐人是不是自己",playerspread == parseInt(spreadId));
  563. ////推荐人不能是自己
  564. if(playerspread != parseInt(player.userId)){
  565. gwjdtjridsfhf = true;
  566. }
  567. else{
  568. spreadId = "99999999";
  569. }
  570. }
  571. }
  572. else if((player.spreadId+"").length == 0){
  573. if(parseInt(spreadId) == player.userId){
  574. spreadId = "99999999";
  575. }
  576. }
  577. else if((player.spreadId+"").length == 8 && player.spreadId == "99999999"){
  578. gwjdtjridsfhf = true;////推荐人是系统就不改了
  579. }
  580. else if((player.spreadId+"").length > 8){
  581. let spreader = yield this.app.models.Player.findByIdAsync(player.spreadId, 'userId');
  582. if (spreader) {
  583. spreadId = spreader.userId+"";
  584. }
  585. else{
  586. spreadId = "99999999";
  587. }
  588. }
  589. // gwjdtjridsfhf = false;
  590. // spreadId = "";
  591. // console.warn("合法吗???gwjdtjridsfhf ",gwjdtjridsfhf,"player",player.spreadId , "spreadId",spreadId);
  592. if(!gwjdtjridsfhf){////不合法需要修改
  593. player.spreadId = spreadId;
  594. // console.warn("不合法需要修改呢",player.spreadId);
  595. if(isNew && form){
  596. player.form = form;
  597. }
  598. isChange = true;
  599. }
  600. else{
  601. if(isNew && form){
  602. player.form = form;
  603. isChange = true;
  604. }
  605. }
  606. }
  607. else{
  608. if(isNew && form){
  609. player.form = form;
  610. isChange = true;
  611. }
  612. }
  613. //if(isChange){
  614. player.status = 6
  615. yield player.saveAsync();
  616. //}
  617. let nowTime = Date.now();///TL++
  618. // console.warn("??????????? rId "+player.rTableId+" doid "+doid +" doroomid "+doroomid+" dodata "+JSON.stringify(dodata));
  619. // console.warn("登陆+++++777 "+msg._id+" rId "+player.rTableId+" doid "+doid +" doroomid "+doroomid+" dodata "+JSON.stringify(dodata));//ts++
  620. if(dodata == null){
  621. dodata = {
  622. gameId: 0
  623. };
  624. }
  625. if(isNew){
  626. //给邀请新人按比例送钻这个活动记录新用户的邀请人信息,测试的话可以不用判断isNew
  627. yield this.app.controllers.player.setNewerYQXXAsync(playerId, player.userId, parseInt(msg.spread));
  628. }
  629. //在玩家登陆的时候给玩家发邮件,比如发送活动的奖励邮件等等
  630. yield this.app.controllers.player.sendMailOnLoginAsync(playerId, player.userId);
  631. console.warn("登陆+++++888==================================下面是登陆返回了",playerId,player.userId);
  632. let taskQuan = 0
  633. let sgjUser = yield this.app.models.SGJUser.findByIdAsync(playerId);
  634. if (sgjUser) {
  635. taskQuan = sgjUser.taskQuan.toFixed(2)
  636. }
  637. yield this.app.controllers.player.sendMailOnLoginAsync(playerId, player.userId);
  638. let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'whTip stateWH rebaterate yxndlbTime yxndlbTip');
  639. var whtip = whdata.yxndlbTip
  640. var isweihu = 0
  641. if (whdata.stateWH != 0) {
  642. isweihu = 1
  643. whtip = whdata.whTip
  644. }
  645. var SGJConfigs = yield this.app.models.SGJConfig.findMongoAsync()
  646. var SGJConfig = SGJConfigs[0]
  647. var url = encodeURIComponent(player.headurl)
  648. if (msg.istelegram != 1) {
  649. url = "https://barserver.bargame88.com/image/1.png"
  650. player.headurl = "1.png"
  651. }
  652. yield player.saveAsync()
  653. return next(null, { code: C.OK, data: {
  654. isNew: isNew,
  655. player: {
  656. _id: player._id,
  657. account: player.account,
  658. userId: String(player.userId),
  659. name: player.name,
  660. headurl:url,
  661. taskQuan:taskQuan,
  662. sex: player.sex,
  663. diamond: String(player.diamond),
  664. synPlayer:player.synPlayer,
  665. rId: String(player.rTableId),
  666. connectUrl: connectUrl,
  667. agentId: agentId,
  668. agentNo: agentNo,
  669. agentName: agentName,
  670. doid: String(doid),
  671. doroomid: String(doroomid),
  672. nowTime: nowTime,
  673. dodata: dodata,
  674. enabled: playerIsEnable,
  675. registerTime: player.registerTime,
  676. sfkjxyx: true,//是否可进小游戏
  677. tel: tel,
  678. pwd: pwd,
  679. smName:player.smName,
  680. smCardId: player.smCardId,
  681. isweihu: isweihu,
  682. yxndlbTip:whtip,
  683. fee: SGJConfig.withdrawfee,
  684. withdrawlowlimit:SGJConfig.withdrawlowlimit
  685. }
  686. }
  687. });
  688. });
  689. // 登出
  690. proto.logout = P.coroutine(function* (msg, session, next) {
  691. // console.error("logout logout "+session.uid+" msg.closed "+msg.closed);
  692. if (!session.uid) {
  693. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  694. }
  695. var playerId = session.uid;
  696. var result = yield this.app.controllers.player.disconnectAsync(playerId);
  697. if (result.gameSvrId) {
  698. let gameSvrId = result.gameSvrId;
  699. let gameRemote = this.getRpc(result.gameId)
  700. if (gameRemote) gameRemote.leaveTable.toServer(gameSvrId, playerId, () => { });
  701. }
  702. else{
  703. this.app.rpc.hall.hallRemote.leave.toServer("hall-server-1", playerId, () => { });
  704. }
  705. if (!msg.closed) {
  706. yield P.promisify(session.unbind, session)(playerId);
  707. }
  708. logger.info('player %s logout', playerId);
  709. return next(null, { code: C.OK });
  710. });
  711. proto.getTodaySJC = function (){
  712. var today = new Date();
  713. today.setHours(0);
  714. today.setMinutes(0);
  715. today.setSeconds(0);
  716. today.setMilliseconds(0);
  717. let jrsjc = today.getTime();
  718. // console.warn("111得到今日0点的时间戳 ",jrsjc, typeof jrsjc);
  719. return jrsjc;
  720. };