添加ip归属地

This commit is contained in:
luying
2022-08-04 13:38:38 +08:00
parent b83d9db979
commit d656d12a74
9 changed files with 35 additions and 2 deletions

View File

@@ -21,6 +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';
export default function (app: Application) {
new HandlerService(app, {});
@@ -63,6 +64,8 @@ export class EntryHandler {
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);

View File

@@ -13,6 +13,9 @@ import { Figure } from '../domain/dbGeneral';
import { pick } from 'underscore';
import { Reward } from '../domain/battleField/pvp';
import { CheckMeterial } from './role/checkMaterial';
import IP2Region from "ip2region";
const query = new IP2Region({ disableIpv6: true });
export async function getTeraphStrengthenResult(role: RoleType, count: number, dicTeraph: DicTeraph, teraph: Teraph) {
let criAttr: number[] = [], times = 0;
@@ -288,4 +291,14 @@ export async function getSchoolPoint(roleId: string) {
}
return pre;
}, 0);
}
export async function setIpLocation(roleId: string, ip: string) {
try {
const res = query.search(ip);
console.log('##### setIpLocation', res)
await RoleModel.updateRoleInfo(roleId, { ip, ipLocation: res.province||res.country })
} catch(e) {
console.error('setIpLocation', e)
}
}

View File

@@ -1620,6 +1620,11 @@
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz",
"integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo="
},
"ip2region": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/ip2region/-/ip2region-2.3.0.tgz",
"integrity": "sha512-zV5Xsadzrx9Ej6heoyhbXMsfGWWQ3C6bAIYStrHhw9kzLpGpVNlnAyRBxxPgxA1GNqr1Ti7oUxcWsMWNN3jZBg=="
},
"is-binary-path": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",

View File

@@ -35,6 +35,7 @@
"crc": "^3.5.0",
"cross-env": "^7.0.3",
"csprng": "^0.1.2",
"ip2region": "^2.3.0",
"koa-is-json": "^1.0.0",
"local": "^0.3.3",
"moment": "^2.29.1",

View File

@@ -57,7 +57,7 @@ export enum FRIEND_SHIP_SELECT {
GET_FRIEND_VALUE = 'friendValue friendLv'
}
export const ENTERY_ROLE_PICK = ['roleId', 'roleName', 'serverId', 'ce', 'topLineupCe', 'coin', 'lv', 'exp', 'vLv', 'gold', 'heros', 'jewels', 'consumeGoods', 'title', 'teraphs', 'showLineup', 'heads', 'head', 'frames', 'frame', 'spines', 'spine', 'hasGuild', 'guildCode', 'todayZeroPoint', 'apJson', 'skins', 'totalPay', 'guide', 'hasInit', 'renameCnt', 'totalCost', 'guildName', 'isVip', 'createTime'];
export const ENTERY_ROLE_PICK = ['roleId', 'roleName', 'serverId', 'ce', 'topLineupCe', 'coin', 'lv', 'exp', 'vLv', 'gold', 'heros', 'jewels', 'consumeGoods', 'title', 'teraphs', 'showLineup', 'heads', 'head', 'frames', 'frame', 'spines', 'spine', 'hasGuild', 'guildCode', 'todayZeroPoint', 'apJson', 'skins', 'totalPay', 'guide', 'hasInit', 'renameCnt', 'totalCost', 'guildName', 'isVip', 'createTime', 'ipLocation'];
export enum SURVEY_SELECT {
FIND = '-__v -_id -surveyName -roleIndex -reward -mailContent -receivedRole -createdAt -updatedAt'

View File

@@ -327,6 +327,13 @@ export default class Role extends BaseModel {
@prop({ required: false })
shushuMark: string; // 数数distinctId
// 最后登录 IP
@prop({ required: false })
ip: string;
@prop({ required: false })
ipLocation: 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;

View File

@@ -88,6 +88,7 @@ export class PlayerDetail {
roleName: string;
lv: number;
title?: number = 1;
ipLocation: string = '';
head?: number = EXTERIOR.EXTERIOR_FACE;
frame?: number = EXTERIOR.EXTERIOR_FACECASE;
spine?: number = EXTERIOR.EXTERIOR_APPEARANCE;
@@ -126,6 +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;
}
setCe(ce: number) {

View File

@@ -18,6 +18,7 @@ export class FriendParams {
serverName: string;
type: number = FRIEND_RELATION_TYPE.NORMAL;
guildName: string = '';
ipLocation: string = '';
constructor(role: RoleType) {
this.roleId = role.roleId;
@@ -29,6 +30,7 @@ export class FriendParams {
this.ce = role.ce;
this.title = role.title;
this.guildName = role.guildName||'';
this.ipLocation = role.ipLocation||'';
}
setServerName(serverId: number, serverName: string) {

View File

@@ -331,7 +331,7 @@ export default class Auth extends Service {
const code = ctx.service.utils.genCode(6);
const seqId = await Counter.getNewCounter(COUNTER.ROLE) || -1;
const role = await RoleModel.createRole(uid, serverId, { roleId, code, roleName: "默认玩家名", seqId, lv: DEFAULT_LV, exp: (getExpByLv(DEFAULT_LV - 1) || { sum: 0 }).sum || 0 }, distinctId);
const role = await RoleModel.createRole(uid, serverId, { roleId, code, roleName: "默认玩家名", seqId, lv: DEFAULT_LV, exp: (getExpByLv(DEFAULT_LV - 1) || { sum: 0 }).sum || 0, ip: ctx.clientIp }, distinctId);
if (role) {
await ServerlistModel.incRoleCnt(serverId);
if(server.isReview) { // 审核服跳关卡