后台:可以设置固定ip属地
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user