diff --git a/game-server/app/servers/connector/handler/entryHandler.ts b/game-server/app/servers/connector/handler/entryHandler.ts index 9dd3f36ee..0794c61a4 100644 --- a/game-server/app/servers/connector/handler/entryHandler.ts +++ b/game-server/app/servers/connector/handler/entryHandler.ts @@ -21,7 +21,7 @@ import { getExpByLv } from '../../../pubUtils/data'; import { reportCreateRoleEventToTa, reportTAEvent, reportTAUserSet } from '../../../services/sdkService'; import { saveLoginAndOutLog } from '../../../pubUtils/logUtil'; import { sendMessageToAllWithSuc } from '../../../services/pushService'; -import { setIpLocation } from '../../../services/roleService'; +import { getIpLocation } from '../../../services/roleService'; export default function (app: Application) { new HandlerService(app, {}); @@ -59,18 +59,18 @@ export class EntryHandler { } } - let role = await RoleModel.findByUidAndSetTime(user.uid, serverId, null, true); + let ip = this.getIp(session); + let ipLocation = await getIpLocation(ip); + let role = await RoleModel.findByUidAndSetTime(user.uid, serverId, ip, ipLocation, null, true); if (!role) { return resResult(STATUS.ROLE_NOT_FOUND); } - setIpLocation(role.roleId, this.getIp(session)); - let serverName = this.app.getServerId(); await roleLogin(role.roleId, user.userCode, serverName, role.createTime, role.serverId, role.lv, role.topLineupCe); // 保存在线用户 await this.addSession(user, role, session); - await reportCreateRoleEventToTa(role, this.getIp(session)); + await reportCreateRoleEventToTa(role, ip); saveLoginAndOutLog(LOG_TYPE.LOGIN, session); addRoleToSysChannel(role.roleId, self.app.get('serverId'), role.serverId); addRoleToWorldChannel(role.roleId, self.app.get('serverId'), role.serverId); diff --git a/game-server/app/servers/gm/handler/gmRoleHandler.ts b/game-server/app/servers/gm/handler/gmRoleHandler.ts index b5c10cb13..2ac09a7d7 100644 --- a/game-server/app/servers/gm/handler/gmRoleHandler.ts +++ b/game-server/app/servers/gm/handler/gmRoleHandler.ts @@ -37,13 +37,10 @@ export class GmRoleHandler { constructor(private app: Application) { } - async addItems(msg: { roleId: string, roleName: string, serverId: number, values: { reward: RewardInter[], heroes: number[], lv: number, expInc: number }}, session: BackendSession) { + async addItems(msg: { roleId: string, roleName: string, serverId: number, values: { reward: RewardInter[], heroes: number[], lv: number, expInc: number, fixedIpLocation: string }}, session: BackendSession) { let { roleId, roleName, serverId, values } = msg; - let { reward, heroes, lv, expInc = 0 } = values; - if (reward == undefined && heroes == undefined && lv == undefined) { - return resResult(STATUS.WRONG_PARMS); - } + let { reward, heroes, lv, expInc = 0, fixedIpLocation } = values; let connect = await getRoleOnlineInfo(roleId); let sid = connect.isOnline?connect.sid: null; @@ -64,6 +61,9 @@ export class GmRoleHandler { isLvUp: false, lv: newLv, exp }, sid); } + if(fixedIpLocation != undefined) { + await RoleModel.updateRoleInfo(roleId, { fixedIpLocation }) + } return resResult(STATUS.SUCCESS); } diff --git a/game-server/app/services/connectorService.ts b/game-server/app/services/connectorService.ts index 309cba3a2..58e45dd3d 100644 --- a/game-server/app/services/connectorService.ts +++ b/game-server/app/services/connectorService.ts @@ -126,6 +126,7 @@ export async function getModuleData(type: string, data: { role: RoleType, sessio role['skins'] = skins; let apJson = await getAp(role.roleId, '', role.lv); role['apJson'] = apJson; + role['ipLocation'] = role.fixedIpLocation||role.ipLocation||'未知'; if (!role.showLineup) role.showLineup = role.topLineup.map(cur => cur.hid); role.heads = role.heads.filter(cur => cur.status); diff --git a/game-server/app/services/roleService.ts b/game-server/app/services/roleService.ts index 880e106af..3e10af022 100644 --- a/game-server/app/services/roleService.ts +++ b/game-server/app/services/roleService.ts @@ -293,11 +293,11 @@ export async function getSchoolPoint(roleId: string) { }, 0); } -export async function setIpLocation(roleId: string, ip: string) { +export async function getIpLocation(ip: string) { try { const res = query.search(ip); console.log('##### setIpLocation', res) - await RoleModel.updateRoleInfo(roleId, { ip, ipLocation: res.province||res.country }) + return res.province||res.country||'未知'; } catch(e) { console.error('setIpLocation', e) } diff --git a/gm-server/app/service/users.ts b/gm-server/app/service/users.ts index 5c2b1fe40..936998f34 100644 --- a/gm-server/app/service/users.ts +++ b/gm-server/app/service/users.ts @@ -131,10 +131,10 @@ export default class GMUsers extends Service { let heroCount = await HeroModel.count({ roleId: role.roleId }).lean(); let itemCount = await ItemModel.count({ roleId: role.roleId }).lean(); - let { roleId, roleName, serverId, lv, gold, coin, ce, blockType = 0, blockReason = '' } = role; + let { roleId, roleName, serverId, lv, gold, coin, ce, blockType = 0, blockReason = '', fixedIpLocation, ipLocation } = role; let { uid, tel } = role.userInfo; list.push({ - key: roleId, roleId, roleName, serverId, lv, uid, tel, heroCount, itemCount, gold, coin, ce, blockType, blockReason, + key: roleId, roleId, roleName, serverId, lv, uid, tel, heroCount, itemCount, gold, coin, ce, blockType, blockReason, fixedIpLocation, ipLocation, env: ctx.app.config.realEnv }); } diff --git a/shared/db/Role.ts b/shared/db/Role.ts index 86236a9b3..b5e8191e3 100644 --- a/shared/db/Role.ts +++ b/shared/db/Role.ts @@ -334,15 +334,18 @@ export default class Role extends BaseModel { @prop({ required: false }) ipLocation: string; + @prop({ required: false }) + fixedIpLocation: string; + public static async findAllByUid(uid: number, getters = false, virtuals = true) { const role: RoleType[] = await RoleModel.find({ 'userInfo.uid': uid }).select('roleId roleName serverId head frame spine heads frames spines lv updatedAt').lean({ getters, virtuals }); return role; } - public static async findByUidAndSetTime(uid: number, serverId: number, select?: string, getters = false) { + public static async findByUidAndSetTime(uid: number, serverId: number, ip: string, ipLocation: string, select?: string, getters = false) { const curSec = nowSeconds(); // 为了计算累计登录,此处查询new为false - const role: RoleType = await RoleModel.findOneAndUpdate({ 'userInfo.uid': uid, serverId }, { loginTime: curSec, quitTime: curSec }, { new: false }).select(select).lean({ getters, virtuals: true }); + const role: RoleType = await RoleModel.findOneAndUpdate({ 'userInfo.uid': uid, serverId }, { $set: { loginTime: curSec, quitTime: curSec, ip, ipLocation } }, { new: false }).select(select).lean({ getters, virtuals: true }); return role; } diff --git a/shared/domain/battleField/guild.ts b/shared/domain/battleField/guild.ts index 87c2569d0..148f270a1 100644 --- a/shared/domain/battleField/guild.ts +++ b/shared/domain/battleField/guild.ts @@ -127,7 +127,7 @@ export class PlayerDetail { if(role.head) this.head = role.head; if(role.frame) this.frame = role.frame; if(role.spine) this.spine = role.spine; - if(role.ipLocation) this.ipLocation = role.ipLocation; + this.ipLocation = role.fixedIpLocation||role.ipLocation||'未知'; } setCe(ce: number) { diff --git a/shared/domain/roleField/friend.ts b/shared/domain/roleField/friend.ts index a6f0428ec..7481b8d57 100644 --- a/shared/domain/roleField/friend.ts +++ b/shared/domain/roleField/friend.ts @@ -30,7 +30,7 @@ export class FriendParams { this.ce = role.ce; this.title = role.title; this.guildName = role.guildName||''; - this.ipLocation = role.ipLocation||''; + this.ipLocation = role.fixedIpLocation||role.ipLocation||'未知'; } setServerName(serverId: number, serverName: string) {