'use strict'; var quick = require('quick-pomelo'); var P = quick.Promise; var _ = require('lodash'); var C = require('../../share/constant'); var conf = require('../config/games').shuiguo || {}; var User = require('../shuiguo/user'); var Table = require('../shuiguo/table'); var configCommon = require('../../share/configCommon');//////TL++配置相关的公共方法 var logger = quick.logger.getLogger('fhmj', __filename); /////TL++,下面这几行为了记录用户行为 // var log4js = require("log4js");////cssj // var log4js_config = require("../logConf.json"); // log4js.configure(log4js_config); // // console.log("log_start start!"); // var LogFile = log4js.getLogger('log_file',__filename);////cssj // 金币消耗 const COSTS = conf.crt_costs || {}; // 构造方法 var Controller = function (app) { this.app = app; this.id = 10005; this.lastId = 70000;//桌子号70000 console.warn("水果 游戏服务器启动",app.getServerType(),app.getServerId()); // logger.info("奉化2人 游戏服务器启动",app.getServerType(),app.getServerId()); this.users = {}; this.tables = []; this.predels = []; this.keepTm = 600000;// 10分钟 删除空闲桌子时间 this.lconfigCommon = new configCommon(this.app); //ts++60秒执行一下 if (app.getServerType() == 'game') setInterval(() => this.checkDelete(), 60000);//this.keepTm / 2 }; // 导出方法 module.exports = function (app) { return new Controller(app); }; // 原型对象 var proto = Controller.prototype; // 创建玩家 proto._createUser = function (player, table) { //let today = new Date(); //console.warn("创建玩家",today.getTime()); var user = new User(this, player, table); this.users[user.id] = user; return user; }; // 创建桌子 cell底分 round局数 proto._createTable = function (cPlayerId,cUserId,cName,cHead,cell, round, type,gameKindTL,playerAllCount,upId,other,agentId,yxndlbTime,yxndlbTip) { // this.lastId += _.random(1, 100);////在区间[1,100]内随机取整数 TL++zs yl this.lastId += 1; if(this.lastId>=80000) { this.lastId=70000; } var serverId = this.app.getServerId(); var prefix = serverId.charAt(serverId.length - 2)+serverId.charAt(serverId.length - 1)+ this.lastId;//ts++ game-server-10 取serverID的最后一个字符 //console.warn("创建桌子",prefix,serverId); // var str3 = "shuiguo 创建桌子Id:"+prefix // logger.info(str3);////cssj var table = new Table(cPlayerId,cUserId,cName,cHead,this, prefix , cell, round, type,gameKindTL,playerAllCount,upId,other,agentId,yxndlbTime,yxndlbTip); this.tables.push(table); return table; }; // 删除桌子 proto.deleteTable = function (tableId) { // console.warn("-------------------删除桌子----------------------",tableId); // var str3 = "shuiguo 删除桌子Id:"+tableId // logger.info(str3);////cssj var index = _.findIndex(this.tables, { id: tableId }); if (-1 != index) { this.tables.splice(index, 1); } }; // 检查删除 此方法目前(7月26日)每10分钟调用一次 proto.checkDelete = P.coroutine(function* () { var date1 = new Date(Date.now()); var date2=date1.toLocaleDateString().replace(/\//g, "-") + " " + date1.toTimeString().substr(0, 8); // console.warn("检查删除 房间数",this.tables.length,date2,this.app.getServerId()); var nowTime = Date.now(); if (this.tables.length > 0) { var validTables = []; for (let i = 0; i < this.tables.length;++i) { let table = this.tables[i]; if (table.stime ==0 && nowTime - table.ctime >= this.keepTm) { // console.warn("tableId ccccc",table); // let str3 = "shuiguo检查删除validTables"+table.id // logger.info(str3);////cssj validTables.push(table); } } // console.warn("删除数:",validTables.length); if (validTables.length > 0) { let app = this.app; return app.memdb.goose.transactionAsync(P.coroutine(function* () { for (let j = 0; j < validTables.length; ++j) { // let str3 = "shuiguo检查删除SYSTEMEND"+validTables[j].id // logger.info(str3);////cssj yield validTables[j].endResultAsync(Table.ENDMODE.SYSTEMEND);//ts++超时解散 } }), app.getServerId()) .then(() => app.event.emit('transactionSuccess'), () => app.event.emit('transactionFail')); } } }); // 回到桌子 proto.backTableAsync = P.coroutine(function* (user) { // console.warn("tssg+++++回到桌子playerId:%s",user.id);//ts++ // let str3 = "shuiguo回到桌子 "+user.id // logger.info(str3);////cssj // 查找玩家 var player = yield this.app.models.Player.findByIdAsync(user.id, 'tableId gameId gameServerId connectorId'); // let str4 = "shuiguo回到33桌子gameServerId "+player.gameServerId+" state "+ user.table.state +" isGameOk "+user.table.isGameOk // logger.info(str4);////cssj if (player.gameServerId) { // console.warn("-------进不来111",player.gameServerId); //return { code: C.FAILD, msg: C.TABLE_HAS_ALREADY }; } var bDel=false; var usertable = user.table; if(!usertable) { bDel=true; //console.warn('=======房间已经不存在了=====删除用户:%s', user.id); //logger.info('=======房间已经不存在了=====删除用户:%s', user.id); } if (!bDel && usertable.state == Table.STATE.END) { bDel=true; //console.warn('=======房间已经结束=====删除用户:%s', user.id); //logger.info('=======房间已经结束=====删除用户:%s', user.id); } if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>60000) { bDel=true; //console.warn('creatOrjoinTableAsync=======断线时间过长了=====删除用户:%s', user.id); //logger.info('=======断线时间过长了=====删除用户:%s', user.id); } if (bDel) { delete this.users[user.id]; console.warn("161 bDel:",bDel) return { code: C.FAILD, msg: C.TABLE_GAME_OVER }; } if (player.connectorId) { user.connectorId = player.connectorId; } var res = yield user.table.backAsync(user); // console.warn("ts+++++回到桌子usertable.state ",usertable.state);//ts++ // 保存服务 if (player) { // let str5 = "shuiguo回到33桌子tableId"+user.table.id // logger.info(str5);////cssj player.tableId = user.table.id; player.gameId = this.id; player.gameServerId = this.app.getServerId(); yield player.saveAsync(); } return res; }); // TL++,判断桌子是否存在 reload=1为重入 proto.isTableExistAsync = P.coroutine(function* (playerId, tableId,reload) { //console.warn("判断房间是否存在++++:%s,房间号:%s,重入:%d",playerId,tableId,reload); // let str5 = "shuiguo判断桌子是否存在 "+playerId // logger.info(str5);////cssj // 查找玩家 var user = this.users[playerId]; if (user) {//重入优化 var bDel=false; var usertable = user.table; if(!usertable) { bDel=true; // let str6 = "shuiguo判断桌子是否存在usertable "+usertable+" state "+usertable.state+" isGameOk "+ usertable.isGameOk // logger.info(str6);////cssj //console.warn('=======房间已经不存在了=====删除用户:%s', user.id); //logger.info('=======房间已经不存在了=====删除用户:%s', user.id); } if (!bDel && usertable.state == Table.STATE.END) { bDel=true; //console.warn('=======房间已经结束=====删除用户:%s', user.id); //logger.info('=======房间已经结束=====删除用户:%s', user.id); } if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>60000) { bDel=true; // let str6 = "shuiguo判断桌子是否存在断线时间过长user.id "+user.id // logger.info(str6);////cssj // console.warn('isTableExistAsync=======断线时间过长了=====删除用户:%s', user.id); //logger.info('=======断线时间过长了=====删除用户:%s', user.id); } if(!bDel ) { return { code: C.OK, data: {tid:usertable.id} }; } else { // let str6 = "shuiguo判断桌子是否存在==删除用户user.id "+user.id // logger.info(str6);////cssj // console.warn('isTableExistAsync==========删除用户==%s', user.id); //logger.info('==========删除用户==%s', user.id); delete this.users[playerId]; } } // 查找桌子 var table = _.find(this.tables, { id: tableId }); // let str6 = "shuiguo判断桌子是否存在==查找桌子 " // logger.info(str6);////cssj if (!table) { console.warn("remove 230") return { code: C.FAILD, msg: C.TABLE_NOT_FOUND }; } var table = _.find(this.tables, { id: tableId }); // let str7 = "shuiguo222判断桌子是否存在==查找桌子 state"+table.state +" isGameOk "+ table.isGameOk + "isFull" +table.isFull() // logger.info(str7);////cssj // 状态结束 if (table.state == Table.STATE.END) { console.warn("161 table:",table) return { code: C.FAILD, msg: C.TABLE_GAME_OVER }; } // 是否坐满 if (table.isFull(playerId)) { console.warn("remove 243") return { code: C.FAILD, msg: C.TABLE_IS_FULL }; } return { code: C.OK, data: {tid:tableId} }; }); ////TL++创建或者加入桌子,用于玩家通过战绩分享进来之后 proto.creatOrjoinTableAsync = P.coroutine(function* (playerId, round,type, kind,playercount,upId,other,agentId) { // let str6 = "shuiguo创建或者加入桌子 "+playerId+ " "+ round+ " "+type+ " "+ kind+ " "+playercount+ " "+upId+ " "+other+ " "+agentId // logger.info(str6);////cssj // let str64 = "shuiguo创建或者加入桌子 "+ typeof(playerId)+ " "+ typeof(round)+ " "+typeof(type)+ " "+ typeof(kind)+ " "+typeof(playercount)+ " "+typeof(upId)+ " "+typeof(other)+ " "+typeof(agentId) // logger.info(str64);////cssj // console.warn("创建或者加入桌子,用于玩家通过战绩分享进来之后:%s",playerId);//ts++ // console.warn(str6); // console.warn(str64); let player = yield this.app.models.Player.findByIdReadOnlyAsync(playerId, 'diamond userId name headurl'); let cUserId = String(player.userId); let cName = String(player.name); let cHead = String(player.headurl); //// 检查推广黑白名单功能,判断玩家是否可以进入(创建或者加入桌子) let chekRes = yield this.checkAgreeInfo(playerId,agentId,cUserId,cName,cHead); if(chekRes.code != C.OK){ return chekRes; } // 查找玩家 var user = this.users[playerId]; if (user) { var bDel=false; var usertable = user.table; if(!usertable) { bDel=true; //console.warn('=======房间已经不存在了=====删除用户:%s', user.id); // logger.info('creatOrjoinTableAsync=======房间已经不存在了=====删除用户:%s', user.id); } if (!bDel && usertable.state == Table.STATE.END) { bDel=true; //console.warn('=======房间已经结束=====删除用户:%s', user.id); // logger.info('creatOrjoinTableAsync=======房间已经结束=====删除用户:%s', user.id); } if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>60000) { bDel=true; //console.warn('creatOrjoinTableAsync=======断线时间过长了=====删除用户:%s', user.id); // logger.info('creatOrjoinTableAsync=======断线时间过长了=====删除用户:%s', user.id); } if(bDel) { delete this.users[playerId]; // logger.info('creatOrjoinTableAsync==========删除用户==%s', user.id); } else { return this.backTableAsync(user); } } // console.warn("得到下一局的信息查找桌子不存在就创建",data); // var table = _.find(this.tables, { upId: data.upId }); var table = _.find(this.tables, { upId: upId }); // console.warn("创建或者加入桌子,用于玩家通过战绩分享进来之后: table.state "+table.state); if (!table || table.isFull()) { // var agentId=data.agentId || ""; var agentId=agentId || ""; // console.warn("ts++下一局----------------新建"); // return this.createTableAsync(playerId, data.round, 0,data.kind,data.playercount,data.upId,data.other,agentId); return this.createTableAsync(playerId, round, type,kind,playercount,upId,other,agentId); } else { // console.warn("ts++下一局----------------加入:"+table.id); return this.joinTableAsync(playerId, table.id); } }); // 加入桌子 proto.joinTableAsync = P.coroutine(function* (playerId, tableId) { // console.warn("shuiguo加入桌子playerId: "+playerId+" ,tableId: "+tableId); // tjbjlmryxrs // let isXTCF = yield this.lconfigCommon.checkIsSystemCreat(playerId);//是否系统创房 // if(isXTCF) return tableId; // let str6 = "shuiguo加入桌子playerId:"+playerId+",tableId:"+tableId; // logger.info(str6);////cssj ////检查是否维护状态 let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'stateWH whTip'); // console.warn("22检查是否维护状态",whdata); if (whdata) { // console.warn("--33检查是否维护状态",whdata.stateWH,whdata.whTip); if(whdata.stateWH){ /////维护状态中 return { code: C.FAILD, tip: whdata.whTip }; } } else{ // console.warn("创建数据库"); // var whsj = new this.app.models.WHstate({ // _id: 'wh', // stateWH: 0, // whTip: '游戏正在维护,请稍后创建房间', // rebaterate: 60 // }); // yield whsj.saveAsync(); // console.warn("检查是否维护状态"); } // 查找玩家 var user = this.users[playerId]; if (user) { var bDel=false; var usertable = user.table; if(!usertable) { bDel=true; // console.warn('=======房间已经不存在了=====加入桌子:%s', user.id); // logger.info('joinTableAsync=======房间已经不存在了=====删除用户:%s', user.id); } if (!bDel && usertable.state == Table.STATE.END) { bDel=true; // console.warn('=======房间已经结束=====加入桌子:%s', user.id); // logger.info('joinTableAsync=======房间已经结束=====删除用户:%s', user.id); } if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>60000) { bDel=true; // console.warn('creatOrjoinTableAsync=======断线时间过长了=====加入桌子:%s', user.id); // logger.info('joinTableAsync=======断线时间过长了=====删除用户:%s', user.id); } if (bDel) { delete this.users[user.id]; if(usertable.id==tableId) { // console.warn("到这里返回了"); //return { code: C.FAILD, msg: C.TABLE_NOT_FOUND }; } } else { return this.backTableAsync(user); } } // 查找桌子 var table = _.find(this.tables, { id: tableId }); if (!table) { console.warn("remove 389") // console.warn("桌子没找到 到这里返回了 ",tableId); return { code: C.FAILD, msg: C.TABLE_NOT_FOUND }; } // table.agentId 数据库中agenter(推广员)数据表的主键(_id) // console.warn("=======加入桌子==table "+ table.agentId+ " playerId "+playerId); let player2 = yield this.app.models.Player.findByIdReadOnlyAsync(playerId, 'diamond userId name headurl'); let cUserId = String(player2.userId);/////TL++房主 let cName = String(player2.name);/////TL++房主 let cHead = String(player2.headurl);/////TL++房主 //// 检查推广黑白名单功能,判断玩家是否可以进入(加入桌子) let chekRes = yield this.checkAgreeInfo(playerId,table.agentId,cUserId,cName,cHead); if(chekRes.code != C.OK){ return chekRes; } // delete require.cache[require.resolve('../../share/configCommon')]; // configCommon = require('../../share/configCommon'); // this.lconfigCommon = new configCommon(this.app); // // console.warn("加入房间 table.agentId "+table.agentId+" table.isNeverStart "+table.isNeverStart) // let chekRes2 = yield this.lconfigCommon.checkIsCanJoin(this.id,table.agentId,2); // if(chekRes2.code != C.OK){ // // console.warn("加入房间 不在比赛期间内 table.isNeverStart "+table.isNeverStart) // // return chekRes2; // if(table.isNeverStart){ // return chekRes2;//不在比赛期间内,而且游戏从未开始过,不让进去 // } // } // 状态结束 if (table.state == Table.STATE.END) { //return { code: C.FAILD, msg: C.TABLE_GAME_OVER }; } // 是否坐满 console.warn("users:",table.users) if (table.isFull()) { console.warn("remove 425") // console.warn("创建的时候发现桌子坐满了"); return { code: C.FAILD, msg: C.TABLE_IS_FULL }; } // 查找玩家 var player = yield this.app.models.Player.findByIdAsync(playerId, 'account userId name sex headurl tableId gameId gameServerId connectorId diamond cost spreadId registerTime lastLoginTime'); if (player.gameServerId) { // console.warn("-------进不来666",player.gameServerId); //return { code: C.FAILD, msg: C.TABLE_HAS_ALREADY }; } // 创建玩家 var user = this._createUser(player, table); // 加入桌子 logger.info('==========joinTableAsync==%s', playerId); var res = yield table.joinAsync(user); // 保存服务 if (player) { player.tableId = tableId; player.rTableId = parseInt(tableId);//ts++重入时使用 player.gameId = this.id; player.gameServerId = this.app.getServerId(); player.headurl = playerId+".png"; yield player.saveAsync(); } // console.warn(" shuiguo加入桌子.... table.state "+table.state); // let str1 = "shuiguo 22加入桌子 "+playerId; // logger.info(str1);////cssj // console.warn("shuiguo加入桌子 res : "+JSON.stringify( res)); return res; }); ////检查推广黑白名单功能 proto.checkAgreeInfo = P.coroutine(function* (playerId,agentId,cUserId,cName,cHead) { // console.warn("检查推广黑白名单功能11 "+playerId); ////查询该推广员的白名单信息 检查玩家是否处于该推广员的白名单中,如果已经得到同意才能创建和加入房间 // var agentId = "xxxx"//_agentId if(!agentId) return { code: C.OK}; var agreeInfo = yield this.app.models.AgenterAgree.findByIdReadOnlyAsync(agentId, '_id isOpenAgree infoList'); if (agreeInfo) { // console.warn("该推广有白名单信息 "); // console.warn("该推广有白名单信息00 +agreeInfo.infoList "+" isOpenAgree "+agreeInfo.isOpenAgree ); let isInAgreeInfoList = false; let isAgreedPlayer = false;//该玩家是否被同意 //只要该玩家被拒绝,无论同意功能是否开启该玩家都不能进入 for (var i = agreeInfo.infoList.length - 1; i >= 0; i--) { if(agreeInfo.infoList[i].playerId == playerId){ isInAgreeInfoList = true; isAgreedPlayer = agreeInfo.infoList[i].agreeState == "1"; if(agreeInfo.infoList[i].agreeState == "2"){ console.warn("remove 477") return { code: C.FAILD, msg: "您已被推广员拒绝" }; } break; } } // console.warn("该推广有白名单信息22 改玩家未被拒绝 "+" isOpenAgree "+agreeInfo.isOpenAgree + " isInAgreeInfoList "+isInAgreeInfoList); //如果功能开启, if(agreeInfo.isOpenAgree == "1"){ if(!isInAgreeInfoList){ //此玩家未记录在同意或拒绝信息列表中则将该玩家加入待同意名单 agreeInfo.infoList.push({ _id: playerId, playerId: playerId, agreeState:'0', userId: cUserId, name: cName, headurl: cHead }); yield agreeInfo.saveAsync(); // console.warn(" 功能开启 此玩家未记录 "); return { code: C.FAILD, msg: "等待推广员同意" }; } else{ // console.warn(" 功能开启 此玩家已经有记录 不是拒绝也不是同意 "); //此玩家以记录在同意或待同意信息列表中,则判断该玩家能否进入游戏 if(!isAgreedPlayer){ return { code: C.FAILD, msg: "等待推广员同意2" }; } } } } else{ // console.warn("该推广尚未有白名单信息则创建该推广的白名单信息"); //该推广尚未有白名单信息则创建该推广的默认白名单信息 var agenteragree = new this.app.models.AgenterAgree({ _id: agentId,//记录 isOpenAgree: "0", infoList: [] }); // console.warn("agenteragree new",agenteragree); yield agenteragree.saveAsync(); } return { code: C.OK}; }); // 创建桌子 proto.createTableAsync = P.coroutine(function* (playerId, round, type,gameKind,playerAllCount,upId,other,agentId) { ////检查是否维护状态 let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'stateWH whTip yxndlbTime yxndlbTip'); // console.warn("22检查是否维护状态",whdata); if (whdata) { whdata.yxndlbTime = 120; yield whdata.saveAsync(); // console.warn("--33检查是否维护状态",whdata.stateWH,whdata.whTip); if(whdata.stateWH){ /////维护状态中 return { code: C.SERVER_WEIHU, msg: whdata.whTip }; } } else{ // console.warn("创建数据库"); // var whsj = new this.app.models.WHstate({ // _id: 'wh', // stateWH: 0, // whTip: '游戏正在维护,请稍后创建房间', // rebaterate: 60 // }); // yield whsj.saveAsync(); // console.warn("检查是否维护状态"); } // console.warn("44检查是否维护状态",whdata.stateWH,whdata.whTip); var user = this.users[playerId]; if (user) { var bDel=false; var usertable = user.table; if(!usertable) { bDel=true; //console.warn('=======房间已经不存在了=====删除用户:%s', user.id); // logger.info('createTableAsync=======房间已经不存在了=====删除用户:%s', user.id); } if (!bDel && usertable.state == Table.STATE.END) { bDel=true; //console.warn('=======房间已经结束=====删除用户:%s', user.id); // logger.info('createTableAsync=======房间已经结束=====删除用户:%s', user.id); } if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>60000) { bDel=true; //console.warn('createTableAsync=======断线时间过长了=====删除用户:%s', user.id); // logger.info('createTableAsync=======断线时间过长了=====删除用户:%s', user.id); } if(bDel) { delete this.users[playerId]; // logger.info('createTableAsync==========删除用户==%s', user.id); } else { return this.backTableAsync(user); } } // 金币消耗 /////TLzs8月6号,创房间不做钻石限制 // var num_cost = parseInt(COSTS[round]); // if(gameKind == 2){ // num_cost = 90;//////冲刺扣90 // } // var crt_cost = num_cost >= 0 ? num_cost : round * 10; // if (crt_cost > 0) { // let player = yield this.app.models.Player.findByIdAsync(playerId, 'diamond cost'); // if (!player || player.diamond < crt_cost) { // return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW }; // } // // player.diamond -= crt_cost; // // player.cost += crt_cost; // // yield player.saveAsync(); // } // 创建桌子 //logger.info('==========createTableAsync==%s', playerId); /////// 判断一个玩家是否还能再创建房间,限制每个玩家只能最多创建10个游戏未开始的房间 let today = new Date(); let time =today.getTime() -60000; //let opts = {registerTime: { $gte: time},playerId: playerId}; //let count = yield this.app.models.CTableRecord.countMongoAsync(opts) // delete require.cache[require.resolve('../../share/configCommon')]; // configCommon = require('../../share/configCommon'); // this.lconfigCommon = new configCommon(this.app); let cUserId = "";/////TL++房主 let cName = "";/////TL++房主 let cHead = "";/////TL++房主 let opts = {ctime: { $gte: time},ownerId: playerId}; let count = yield this.app.models.GameTable.countMongoAsync(opts) if(count >= 10){ return { code: C.FAILD, msg: C.TABLE_CREATETOOMUCH }; } let player = yield this.app.models.Player.findByIdReadOnlyAsync(playerId, 'diamond userId name headurl'); // if (!player || player.diamond < crt_cost) {/////TLzs8月6号,创房间不做钻石限制 // return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW }; // } cUserId = String(player.userId);/////TL++房主 cName = String(player.name);/////TL++房主 cHead = String(player.headurl);/////TL++房主 //// 检查推广黑白名单功能,判断玩家是否可以进入(创建桌子) let chekRes = yield this.checkAgreeInfo(playerId,agentId,cUserId,cName,cHead); if(chekRes.code != C.OK){ return chekRes; } let chekRes2 = yield this.lconfigCommon.checkIsCanJoin(this.id,agentId,1); if(chekRes2.code != C.OK){ return chekRes2; } ////////创建游戏桌子 let cell=1;//底分 let yxndlbTime = 6000; if(whdata && whdata.yxndlbTime) yxndlbTime = whdata.yxndlbTime; let yxndlbTip = ""; if(whdata && whdata.yxndlbTip) yxndlbTip = whdata.yxndlbTip; var table = this._createTable(playerId,cUserId,cName,cHead,cell, round, type,gameKind,playerAllCount,upId,other,agentId,yxndlbTime,yxndlbTip); var gametable = new this.app.models.GameTable({ _id: table.recordid,//记录 tableNo: table.id, ownerId: table.ownerId, agentId: table.agentId, type: table.type, kind: table.gameKindTL,//玩法 2冲刺 other: table.other,//////TL++2人3人的游戏规则 playerCount: table.playerAllCount,//游戏人数 round: table.round,// over: table.over,//游戏局数 ctime: table.ctime,//创建时间 // stime: 0,//开始时间 // time: 0,//结束时间 endMode: 0//结束类型 // gameCost: 0,//游戏消耗 // agentRebate: 0//代理返利 }); yield gametable.saveAsync(); // 加入桌子 return this.joinTableAsync(playerId, table.id); }); // 离开桌子 proto.leaveTableAsync = P.coroutine(function* (playerId, isOffline) { // console.warn("shuiguo 离开桌子==%s",playerId,isOffline); // logger.info("shuiguo 离开桌子==%s",playerId); var userdel = false;//ts++删除用户 // 内存离开 var user = this.users[playerId]; if (user) { // console.warn('shuiguo 内存玩家==%s,状态%d',playerId,user.state,user.isPlaying()); yield user.table.zsbgjlAsync(user); // logger.info('shuiguo 内存玩家==%s,状态%d',playerId,user.state); if (!user.isPlaying()) { // console.warn("离开桌子+++++用户空闲中"); user.state = User.STATE.FREE; yield user.table.leaveAsync(user); delete this.users[playerId]; userdel = true; //logger.info('shuiguo 玩家删除==%s', playerId); } else { // console.warn("离开桌子+++++用户游戏中"); if (user.isOffline()) { return { code: C.OK }; } // console.warn("离开桌子+++++提示玩家断线"); yield user.table.offlineAsync(user); //logger.info('shuiguo 玩家断线==%s', playerId); //return { code: C.OK };//ts++游戏开始后不让退出房间 } //console.warn("offlineAsync+++++状态%d",user.state);//ts++ } // 置空服务 //if (!isOffline) { let player = yield this.app.models.Player.findByIdAsync(playerId, 'tableId rTableId gameId gameServerId'); //if (player && player.gameServerId) { //ts++upd if (player) { //console.warn("shuiguo 用户信息==",player);////css if(userdel)//ts++删除用户 重入后清空 { player.rTableId = 0; } // console.warn("在这里指控了服务shuiguo"); player.tableId = ''; player.gameId = 0; player.gameServerId = ''; yield player.saveAsync(); } //} //console.warn("shuiguo 离开成功==%s",playerId); // logger.info("shuiguo 离开成功==%s",playerId); return { code: C.OK }; }); // 准备(结束本小局) proto.readyGameAsync = P.coroutine(function* (playerId) { let str5 = "shuiguo 准备 "+playerId; logger.warn(str5);////cssj // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } let str2 = "shuiguo 准备 chairId "+user.chairId+" utstate "+user.table.state+" utate2 "+user.state2; logger.warn(str2);////cssj if (user.chairId == -1) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } if (user.table.state != Table.STATE.PLAYING) { // 状态校验 //return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING }; } // console.warn("sgj玩家准备 ",user.state,user.state2 , User.STATE.PLAYING); if (user.state2 != User.STATE.PLAYING || user.state2 != User.STATE.PLAYING) { return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING }; } // let str6 = "shuiguo 22准备 "+playerId; // logger.info(str6);////cssj return user.table.readyGameAsync(user); }); // 带入 proto.dairuAsync = P.coroutine(function* (playerId) { // console.warn("sgj带入+++++++++playerId:%s",playerId); // let str2 = "shuiguo 角色信息 "+playerId; // logger.info(str2);////cssj // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } if (user.chairId == -1) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } return user.table.dairuAsync(playerId,user.chairId); }); // 开始游戏 proto.startGameAsync = P.coroutine(function* (playerId,yazhus) { // console.warn("sgj开始游戏+++++++++playerId:%s",playerId); // let str6 = "shuiguo 开始游戏 "+playerId; // logger.info(str6);////cssj // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } if (user.chairId == -1) { //return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } // 状态校验 var table = user.table; if (table.state != Table.STATE.FREE && table.state != Table.STATE.FREE2) { //return { code: C.FAILD, msg: 'table is not free' }; //return { code: C.FAILD, msg: C.TABLE_NOT_FREE }; } // 是否房主 if (!user.isOwner()) { //return { code: C.FAILD, msg: C.TABLE_NOT_OWNER }; } // 是否准备 if (!table.isReady2()) { // console.warn("走到这里了???? "); //return { code: C.FAILD, msg: C.TABLE_NOT_READY }; } if (user.diamond < _.sum(yazhus)) { return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW }; } // let str5 = "shuiguo 222开始游戏 "+playerId; // logger.info(str5);////cssj return table.startGameAsync(yazhus); }); // 划分 proto.huafenAsync = P.coroutine(function* (playerId,type,value) { // console.warn("sgj划分+++++++++playerId:%s",playerId); // let str6 = "shuiguo 划分 "+playerId; // logger.info(str6);////cssj // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } if (user.chairId == -1) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } // 状态校验 桌子是否游戏中 var table = user.table; if (table.state != Table.STATE.PLAYING) { //return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING }; } // 玩家是否房主 if (!user.isOwner()) { //return { code: C.FAILD, msg: C.TABLE_NOT_OWNER }; } // 玩家是否游戏中 if (!user.isPlaying()) { return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING }; } return table.huafenAsync(type,value); }); // 请求结束 proto.overTableAsync = P.coroutine(function* (playerId) { // 查找玩家 // console.warn("请求结束 "+playerId); var user = this.users[playerId]; if (!user) { // console.warn("请求结束2222 "+playerId); return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } // 是否房主 if (!user.isOwner()) { //return { code: C.FAILD, msg: C.TABLE_NOT_OWNER }; } return user.table.overTableAsync(user);////TL++参数userID userState }); // 得到战绩 proto.getRecordAsync = P.coroutine(function* (playerId) { let str5 = "shuiguo 得到战绩 "+playerId; logger.info(str5);////cssj // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } if (user.chairId == -1) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } return user.table.getRecordAsync(user); }); // 角色信息 proto.roleInfoAsync = P.coroutine(function* (playerId) { // console.warn("角色信息+++++++++playerId:%s",playerId); // let str2 = "shuiguo 角色信息 "+playerId; // logger.info(str2);////cssj // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } if (user.chairId == -1) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } // let str1 = "shuiguo 22角色信息 "+playerId; // logger.info(str1);////cssj return user.table.roleInfoAsync(playerId,user.chairId); }); // 得到排行榜 proto.getPaiHangAsync = P.coroutine(function* (playerId) { // console.warn("得到排行榜+++++++++playerId:%s",playerId); // let str2 = "shuiguo 得到排行榜 "+playerId; // logger.info(str2);////cssj // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } if (user.chairId == -1) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } // let str1 = "shuiguo 22得到排行榜 "+playerId; // logger.info(str1);////cssj return user.table.getPaiHangAsync(playerId); }); // 上传真实姓名支付宝账号 proto.upZFBInfoAsync = P.coroutine(function* (playerId,realName,zfbAcc) { // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } return user.table.upZFBInfoAsync(playerId,realName,zfbAcc); }); // 得到玩家任务信息,里面包含任务信息 proto.getTaskInfoAsync = P.coroutine(function* (playerId) { // console.warn("sgj角色信息+++++++++playerId:%s",playerId); // let str2 = "shuiguo 角色信息 "+playerId; // logger.info(str2);////cssj // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } if (user.chairId == -1) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } // let str1 = "shuiguo 22角色信息 "+playerId; // logger.info(str1);////cssj return user.table.getTaskInfoAsync(playerId,user.chairId); }); // 处理任务 proto.dealRenWuAsync = P.coroutine(function* (playerId,item) { // console.warn("shuiguo 处理任务+++++++++playerId:%s",playerId,item); // let str2 = "shuiguo 处理任务 "+playerId; // logger.info(str2);////cssj // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } if (user.chairId == -1) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } return user.table.dealRenWuAsync(playerId,user.chairId,item); }); // 任务领奖 proto.renWuLingjiangAsync = P.coroutine(function* (playerId,item) { // console.warn("shuiguo 任务领奖+++++++++playerId:%s",playerId,item); // let str2 = "shuiguo 任务领奖 "+playerId; // logger.info(str2);////cssj // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } if (user.chairId == -1) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } return user.table.renWuLingjiangAsync(playerId,user.chairId,item); }); // 得到玩家已完成的任务列表 proto.getOverTasksAsync = P.coroutine(function* (playerId) { // console.warn("sgj角色信息+++++++++playerId:%s",playerId); // let str2 = "shuiguo 角色信息 "+playerId; // logger.info(str2);////cssj // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } if (user.chairId == -1) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } // let str1 = "shuiguo 22角色信息 "+playerId; // logger.info(str1);////cssj return user.table.getOverTasksAsync(playerId,user.chairId); });