'use strict'; var quick = require('quick-pomelo'); var P = quick.Promise; var _ = require('lodash'); var C = require('../../share/constant'); var conf = require('../config/games').paodekuai || {}; var User = require('../paodekuai/user'); var Table = require('../paodekuai/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 = 10008; this.lastId = 50000;//桌子号50000 console.warn("跑得快 游戏服务器启动",app.getServerType(),app.getServerId()); // logger.info("奉化2人 游戏服务器启动",app.getServerType(),app.getServerId()); this.users = {}; this.tables = []; this.predels = []; this.keepTm = 1200000;// 20分钟 删除空闲桌子时间 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 += _.random(1, 20); if(this.lastId>=70000) { this.lastId=50000; } 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 = "paodekuai 创建桌子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 = "paodekuai 删除桌子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); 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 = "paodekuai检查删除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 = "paodekuai检查删除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("ts+++++回到桌子playerId:%s",user.id);//ts++ // let str3 = "paodekuai回到桌子 "+user.id // logger.info(str3);////cssj // 查找玩家 var player = yield this.app.models.Player.findByIdAsync(user.id, 'tableId gameId gameServerId connectorId'); // let str4 = "paodekuai回到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 && usertable.isGameOk) { bDel=true; //console.warn('=======房间局数完成=====删除用户:%s', user.id); //logger.info('=======房间局数完成=====删除用户:%s', user.id); } if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000) { bDel=true; //console.warn('creatOrjoinTableAsync=======断线时间过长了=====删除用户:%s', user.id); //logger.info('=======断线时间过长了=====删除用户:%s', user.id); } if (bDel) { delete this.users[user.id]; return { code: C.FAILD, msg: C.TABLE_GAME_OVER }; } if (player.connectorId) { user.connectorId = player.connectorId; } var res = yield user.table.backAsync(user); // 保存服务 if (player) { // let str5 = "paodekuai回到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++,得到玩家位置 proto.sendLocationAsync = P.coroutine(function* (playerId,msg) { //console.warn("得到玩家位置+++++++++playerId:%s",playerId,msg); // let str4 = "paodekuai得到玩家位置 "+playerId // logger.info(str4);////cssj // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } // // 查找桌子 // var table = _.find(this.tables, { id: msg.tableid }); // if (!table) { // return { code: C.FAILD, msg: C.TABLE_NOT_FOUND }; // } // let str5 = "paodekuai得到玩家位置end "+playerId // logger.info(str5);////cssj return user.table.sendLocationAsync(user,msg); }); // TL++,判断桌子是否存在 reload=1为重入 proto.isTableExistAsync = P.coroutine(function* (playerId, tableId,reload) { //console.warn("判断房间是否存在++++:%s,房间号:%s,重入:%d",playerId,tableId,reload); // let str5 = "paodekuai判断桌子是否存在 "+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 = "paodekuai判断桌子是否存在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 && usertable.isGameOk) { bDel=true; //console.warn('=======房间局数完成=====删除用户:%s', user.id); //logger.info('=======房间局数完成=====删除用户:%s', user.id); } if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000) { bDel=true; // let str6 = "paodekuai判断桌子是否存在断线时间过长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 = "paodekuai判断桌子是否存在==删除用户user.id "+user.id // logger.info(str6);////cssj // console.warn('isTableExistAsync==========删除用户==%s', user.id); //logger.info('==========删除用户==%s', user.id); delete this.users[playerId]; } // if(!bDel) // { // if (user.isOffline()) {//断线中可以直接回来页面 // logger.info('==========重入断线中==%s', user.id); // } // if(!bDel) // { // return { code: C.OK, data: {} }; // } // } // logger.info('==========删除用户==%s', user.id); // delete this.users[playerId];//ts++修改卡桌 // //return { code: C.FAILD, msg: C.TABLE_HAS_ALREADY }; } // 查找桌子 var table = _.find(this.tables, { id: tableId }); // let str6 = "paodekuai判断桌子是否存在==查找桌子 " // logger.info(str6);////cssj if (!table) { return { code: C.FAILD, msg: C.TABLE_NOT_FOUND }; } var table = _.find(this.tables, { id: tableId }); // let str7 = "paodekuai222判断桌子是否存在==查找桌子 state"+table.state +" isGameOk "+ table.isGameOk + "isFull" +table.isFull() // logger.info(str7);////cssj // 状态结束 if (table.state == Table.STATE.END) { return { code: C.FAILD, msg: C.TABLE_GAME_OVER }; } // 局数完成 if (table.isGameOk) { return { code: C.FAILD, msg: C.TABLE_GAME_OVER }; } // 是否坐满 if (table.isFull()) { 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 = "paodekuai创建或者加入桌子 "+playerId+ " "+ round+ " "+type+ " "+ kind+ " "+playercount+ " "+upId+ " "+other+ " "+agentId // logger.info(str6);////cssj // let str64 = "paodekuai创建或者加入桌子 "+ 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 && usertable.isGameOk) { bDel=true; //console.warn('=======房间局数完成=====删除用户:%s', user.id); // logger.info('creatOrjoinTableAsync=======房间局数完成=====删除用户:%s', user.id); } if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000) { 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 }); if (!table) { // 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("paodekuai加入桌子playerId: "+playerId+" ,tableId: "+tableId); let isXTCF = yield this.lconfigCommon.checkIsSystemCreat(playerId);//是否系统创房 if(isXTCF) return tableId; // let str6 = "paodekuai加入桌子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 && usertable.isGameOk) { bDel=true; //console.warn('=======房间局数完成=====删除用户:%s', user.id); // logger.info('joinTableAsync=======房间局数完成=====删除用户:%s', user.id); } if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000) { 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) { return { code: C.FAILD, msg: C.TABLE_NOT_FOUND }; } } else { return this.backTableAsync(user); } } // 查找桌子 var table = _.find(this.tables, { id: tableId }); if (!table) { 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 }; } // 局数完成 if (table.isGameOk) { return { code: C.FAILD, msg: C.TABLE_GAME_OVER }; } // 是否坐满 if (table.isFull()) { 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(); yield player.saveAsync(); } // let str1 = "paodekuai 22加入桌子 "+playerId; // logger.info(str1);////cssj console.warn("paodekuai加入桌子 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"){ 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) { // console.warn("创建桌子+++++++++代理:%s",agentId); // let str6 = "paodekuai 创建桌子 "+playerId+" "+ round+" "+ type+" "+gameKind+" "+playerAllCount+" "+upId+" "+other+" "+agentId; // logger.info(str6);////cssj // let str65 = "paodekuai 创建桌子 "+typeof(playerId)+" "+ typeof(round)+" "+ typeof(type)+" "+typeof(gameKind)+" "+typeof(playerAllCount)+" "+typeof(upId)+" "+typeof(other)+" "+typeof(agentId); // logger.info(str65);////cssj // console.warn(str6); // console.warn(str65); // 已有桌子 // if (this.users[playerId]) { // // console.warn("-------进不来777",this.users[playerId]); // delete this.users[playerId];//ts++修改卡桌 // //return { code: C.FAILD, msg: C.TABLE_HAS_ALREADY }; // } ////检查是否维护状态 let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'stateWH whTip yxndlbTime yxndlbTip'); // 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("检查是否维护状态"); } // 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 && usertable.isGameOk) { bDel=true; //console.warn('=======房间局数完成=====删除用户:%s', user.id); // logger.info('createTableAsync=======房间局数完成=====删除用户:%s', user.id); } if(!bDel && user.offlinetime>0 && Date.now()-user.offlinetime>1200000) { 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() -1200000; //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 isXTCF = yield this.lconfigCommon.checkIsSystemCreat(playerId);//是否系统创房 if(isXTCF){ cUserId = "0";/////TL++房主 cName = "系统比赛";/////TL++房主 cHead = "http://aa.bb.com/mj/ksbs.png";/////TL++房主 } else{ let opts = {ctime: { $gte: time},ownerId: playerId}; let count = yield this.app.models.GameTable.countMongoAsync(opts) if(count >= 50){ 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); //this.timeDelete(table.id);/////TL++,在桌子创建的时候设置20分钟后删除桌子 //ts++ 房间创建记录 // var ctablerecord = new this.app.models.CTableRecord({ // _id: table.recordid, // playerId: playerId // }); // let str5 = "paodekuai 2222创建桌子 ,"+playerId; // logger.info(str5);////cssj // yield ctablerecord.saveAsync(); 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(); // console.warn("创建房间",table.id,table.agentId,table.playerAllCount,isXTCF); // this.app.controllers.bisai.addTable(table.id,table.agentId,table.playerAllCount); if(isXTCF){ let cd = { id: table.id, agentId: table.agentId, playerAllCount: table.playerAllCount } this.app.rpc.hall.hallRemote.creatTable.toServer("hall-server-1", cd, () => { }); } // return table.id; // 加入桌子 return this.joinTableAsync(playerId, table.id); }); // 离开桌子 proto.leaveTableAsync = P.coroutine(function* (playerId, isOffline) { // console.warn("paodekuai 离开桌子==%s",playerId); // logger.info("paodekuai 离开桌子==%s",playerId); var userdel = false;//ts++删除用户 // 内存离开 var user = this.users[playerId]; if (user) { //console.warn('paodekuai 内存玩家==%s,状态%d',playerId,user.state); // logger.info('paodekuai 内存玩家==%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('paodekuai 玩家删除==%s', playerId); } else { //console.warn("离开桌子+++++用户游戏中"); if (user.isOffline()) { return { code: C.OK }; } // console.warn("离开桌子+++++提示玩家断线"); yield user.table.offlineAsync(user); //logger.info('paodekuai 玩家断线==%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("paodekuai 用户信息==",player);////css if(userdel)//ts++删除用户 重入后清空 { player.rTableId = 0; } //console.warn("在这里指控了服务"); player.tableId = ''; player.gameId = 0; player.gameServerId = ''; yield player.saveAsync(); } //} //console.warn("paodekuai 离开成功==%s",playerId); // logger.info("paodekuai 离开成功==%s",playerId); return { code: C.OK }; }); // 坐下桌子 proto.seatAsync = P.coroutine(function* (playerId, chairId) { // console.warn("坐下桌子+++++++++playerId:%s",playerId); // let str5 = "paodekuai 坐下桌子 "+playerId; // logger.info(str5);////cssj // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } // 状态校验 if (user.state > User.STATE.READY) { return { code: C.FAILD, msg: C.PLAYER_NOT_FREE }; } var table = user.table; if (table.state != Table.STATE.FREE) { return { code: C.FAILD, msg: C.TABLE_NOT_FREE }; } // 局数完成 if (table.isGameOk) { return { code: C.FAILD, msg: C.TABLE_GAME_OVER }; } // let str4 = "paodekuai 222坐下桌子 "+playerId; // logger.info(str4);////cssj return table.seatAsync(user, chairId); }); // 站起桌子 proto.standAsync = P.coroutine(function* (playerId) { // console.warn("站起桌子+++++++++playerId:%s",playerId); // let str5 = "paodekuai 站起桌子 "+playerId; // logger.info(str5);////cssj // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } // 状态校验 if (user.state > User.STATE.READY) { return { code: C.FAILD, msg: C.PLAYER_NOT_FREE }; } var table = user.table; if (table.state != Table.STATE.FREE) { return { code: C.FAILD, msg: C.TABLE_NOT_FREE }; } // let str6 = "paodekuai 222站起桌子 "+playerId; // logger.info(str6);////cssj return table.standAsync(user); }); // 准备 proto.readyGameAsync = P.coroutine(function* (playerId) { // let str5 = "paodekuai 准备 "+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 }; } if (user.table.state == Table.STATE.FREE2) //ts++二次准备状态 { // 状态校验 if (user.state2 != User.STATE.FREE && user.state2 != User.STATE.OFFLINE) { return { code: C.FAILD, msg: C.PLAYER_NOT_FREE }; } } else { // 状态校验 if (user.state != User.STATE.FREE) { return { code: C.FAILD, msg: C.PLAYER_NOT_FREE }; } if (user.table.state != Table.STATE.FREE) { return { code: C.FAILD, msg: C.TABLE_NOT_FREE }; } } // 局数完成 if (user.table.isGameOk) { return { code: C.FAILD, msg: C.TABLE_GAME_OVER }; } // let str6 = "paodekuai 22准备 "+playerId; // logger.info(str6);////cssj return user.table.readyGameAsync(user); }); // 开始游戏 proto.startGameAsync = P.coroutine(function* (playerId) { // console.warn("开始游戏+++++++++playerId:%s",playerId); // let str6 = "paodekuai 开始游戏 "+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) { return { code: C.FAILD, msg: C.TABLE_NOT_FREE }; } // 是否房主 if (!user.isOwner()) { return { code: C.FAILD, msg: C.TABLE_NOT_OWNER }; } // 局数完成 if (table.isGameOk) { return { code: C.FAILD, msg: C.TABLE_GAME_OVER }; } // 是否准备 if (!table.isReady()) { return { code: C.FAILD, msg: C.TABLE_NOT_READY }; } // let str5 = "paodekuai 222开始游戏 "+playerId; // logger.info(str5);////cssj return table.startGameAsync(); }); // 出牌处理 proto.outCardAsync = P.coroutine(function* (playerId, cards) { // console.warn("出牌处理+++++++++playerId:%s",playerId); // let str5 = "paodekuai 出牌处理 "+playerId+"==card "+card; // 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 }; } // 状态校验 if (user.state !== User.STATE.PLAYING) { return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING }; } if (user.table.state !== Table.STATE.PLAYING) { return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING }; } // let str6 = "paodekuai 22出牌处理 "+playerId+" cards "+cards // logger.info(str6);////cssj return user.table.outCardAsync(user.chairId, cards); }); // 操作是否自动出牌 proto.autoOutCard = P.coroutine(function* (playerId) { // console.warn("操作是否自动出牌+++++++++playerId:%s",playerId); // let str1 = "csjiang 操作是否自动出牌 "+playerId; // logger.info(str1);////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 }; } // 状态校验 // if (user.state !== User.STATE.PLAYING) { // return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING }; // } // if (user.table.state !== Table.STATE.PLAYING) { // return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING }; // } // let str2 = "csjiang 操作是否自动出牌 "+playerId; // logger.info(str2);////cssj return user.table.autoOutCardAsync(user.chairId); }); // 发送聊天 proto.sendMsgAsync = P.coroutine(function* (playerId, msg) { // console.warn("发送聊天+++++++++playerId:%s",playerId); // let str2 = "paodekuai 发送聊天 "+playerId; // logger.info(str2);////cssj // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } if (!user.table) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } // let str1 = "paodekuai 222发送聊天 "+playerId; // logger.info(str1);////cssj return user.table.sendMsgAsync(user.chairId, msg); }); // 收费聊天 proto.vsendMsgAsync = P.coroutine(function* (playerId, chairId, msg) { // console.warn("收费聊天+++++++++playerId:%s",playerId); // let str1 = "paodekuai 收费聊天 "+playerId; // logger.info(str1);////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 str2 = "paodekuai 22收费聊天 "+playerId; // logger.info(str2);////cssj return user.table.vsendMsgAsync(user.chairId, chairId, msg); }); // 角色信息 proto.roleInfoAsync = P.coroutine(function* (playerId, chairId) { // console.warn("角色信息+++++++++playerId:%s",playerId); // let str2 = "paodekuai 角色信息 "+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 = "paodekuai 22角色信息 "+playerId; // logger.info(str1);////cssj return user.table.roleInfoAsync(chairId); }); // 请求结束 proto.overTableAsync = P.coroutine(function* (playerId) { // console.warn("请求结束+++++++++playerId:%s",playerId); // let str1 = "paodekuai 请求结束 "+playerId; // logger.info(str1);////cssj // 查找玩家 var user = this.users[playerId]; //////TL++zsyl,原先下面这一段是 游戏开始之前不能申请解散 准备之前不能申请解散 if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } // if (user.chairId == -1) { // return { code: C.FAILD, msg: C.TABLE_NOT_USER }; // } // // 状态校验 // if (user.state <= User.STATE.READY) { // return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING }; // } // if (user.table.state <= Table.STATE.FREE) { // return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING }; // } // let str2 = "paodekuai 222请求结束 "+playerId; // logger.info(str2);////cssj return user.table.overTableAsync(user);////TL++参数userID userState }); // 拒绝结束 proto.refuseOverAsync = P.coroutine(function* (playerId) { // let str2 = "paodekuai 拒绝结束 "+playerId; // logger.info(str2);////cssj // console.warn("拒绝结束+++++++++playerId:%s",playerId); // 查找玩家 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 }; } // 状态校验 if (user.state <= User.STATE.READY) { return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING }; } if (user.table.state <= Table.STATE.FREE) { return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING }; } // let str1 = "paodekuai 222拒绝结束 "+playerId; // logger.info(str1);////cssj return user.table.refuseOverAsync(user); }); // 同意结束 proto.agreeOverAsync = P.coroutine(function* (playerId) { // console.warn("同意结束+++++++++playerId:%s",playerId); // let str1 = "paodekuai 同意结束 "+playerId; // logger.info(str1);////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 }; } // 状态校验 if (user.state <= User.STATE.READY) { return { code: C.FAILD, msg: C.PLAYER_NOT_PLAYING }; } if (user.table.state <= Table.STATE.FREE) { return { code: C.FAILD, msg: C.TABLE_NOT_PLAYING }; } // let str2 = "paodekuai 222同意结束 "+playerId; // logger.info(str2);////cssj return user.table.agreeOverAsync(user); }); // 得到玩家位置 proto.getLocationAsync = P.coroutine(function* (playerId,msg) { // console.warn("ts+++++得到玩家位置",playerId); // 查找玩家 var user = this.users[playerId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } return user.table.getLocationAsync(); });