添加ip归属地
This commit is contained in:
@@ -21,6 +21,7 @@ import { getExpByLv } from '../../../pubUtils/data';
|
|||||||
import { reportCreateRoleEventToTa, reportTAEvent, reportTAUserSet } from '../../../services/sdkService';
|
import { reportCreateRoleEventToTa, reportTAEvent, reportTAUserSet } from '../../../services/sdkService';
|
||||||
import { saveLoginAndOutLog } from '../../../pubUtils/logUtil';
|
import { saveLoginAndOutLog } from '../../../pubUtils/logUtil';
|
||||||
import { sendMessageToAllWithSuc } from '../../../services/pushService';
|
import { sendMessageToAllWithSuc } from '../../../services/pushService';
|
||||||
|
import { setIpLocation } from '../../../services/roleService';
|
||||||
|
|
||||||
export default function (app: Application) {
|
export default function (app: Application) {
|
||||||
new HandlerService(app, {});
|
new HandlerService(app, {});
|
||||||
@@ -63,6 +64,8 @@ export class EntryHandler {
|
|||||||
return resResult(STATUS.ROLE_NOT_FOUND);
|
return resResult(STATUS.ROLE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setIpLocation(role.roleId, this.getIp(session));
|
||||||
|
|
||||||
let serverName = this.app.getServerId();
|
let serverName = this.app.getServerId();
|
||||||
await roleLogin(role.roleId, user.userCode, serverName, role.createTime, role.serverId, role.lv, role.topLineupCe); // 保存在线用户
|
await roleLogin(role.roleId, user.userCode, serverName, role.createTime, role.serverId, role.lv, role.topLineupCe); // 保存在线用户
|
||||||
await this.addSession(user, role, session);
|
await this.addSession(user, role, session);
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ import { Figure } from '../domain/dbGeneral';
|
|||||||
import { pick } from 'underscore';
|
import { pick } from 'underscore';
|
||||||
import { Reward } from '../domain/battleField/pvp';
|
import { Reward } from '../domain/battleField/pvp';
|
||||||
import { CheckMeterial } from './role/checkMaterial';
|
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) {
|
export async function getTeraphStrengthenResult(role: RoleType, count: number, dicTeraph: DicTeraph, teraph: Teraph) {
|
||||||
let criAttr: number[] = [], times = 0;
|
let criAttr: number[] = [], times = 0;
|
||||||
@@ -289,3 +292,13 @@ export async function getSchoolPoint(roleId: string) {
|
|||||||
return pre;
|
return pre;
|
||||||
}, 0);
|
}, 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+5
@@ -1620,6 +1620,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz",
|
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz",
|
||||||
"integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo="
|
"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": {
|
"is-binary-path": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
"crc": "^3.5.0",
|
"crc": "^3.5.0",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"csprng": "^0.1.2",
|
"csprng": "^0.1.2",
|
||||||
|
"ip2region": "^2.3.0",
|
||||||
"koa-is-json": "^1.0.0",
|
"koa-is-json": "^1.0.0",
|
||||||
"local": "^0.3.3",
|
"local": "^0.3.3",
|
||||||
"moment": "^2.29.1",
|
"moment": "^2.29.1",
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export enum FRIEND_SHIP_SELECT {
|
|||||||
GET_FRIEND_VALUE = 'friendValue friendLv'
|
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 {
|
export enum SURVEY_SELECT {
|
||||||
FIND = '-__v -_id -surveyName -roleIndex -reward -mailContent -receivedRole -createdAt -updatedAt'
|
FIND = '-__v -_id -surveyName -roleIndex -reward -mailContent -receivedRole -createdAt -updatedAt'
|
||||||
|
|||||||
@@ -327,6 +327,13 @@ export default class Role extends BaseModel {
|
|||||||
@prop({ required: false })
|
@prop({ required: false })
|
||||||
shushuMark: string; // 数数distinctId
|
shushuMark: string; // 数数distinctId
|
||||||
|
|
||||||
|
// 最后登录 IP
|
||||||
|
@prop({ required: false })
|
||||||
|
ip: string;
|
||||||
|
|
||||||
|
@prop({ required: false })
|
||||||
|
ipLocation: string;
|
||||||
|
|
||||||
public static async findAllByUid(uid: number, getters = false, virtuals = true) {
|
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 });
|
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;
|
return role;
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ export class PlayerDetail {
|
|||||||
roleName: string;
|
roleName: string;
|
||||||
lv: number;
|
lv: number;
|
||||||
title?: number = 1;
|
title?: number = 1;
|
||||||
|
ipLocation: string = '';
|
||||||
head?: number = EXTERIOR.EXTERIOR_FACE;
|
head?: number = EXTERIOR.EXTERIOR_FACE;
|
||||||
frame?: number = EXTERIOR.EXTERIOR_FACECASE;
|
frame?: number = EXTERIOR.EXTERIOR_FACECASE;
|
||||||
spine?: number = EXTERIOR.EXTERIOR_APPEARANCE;
|
spine?: number = EXTERIOR.EXTERIOR_APPEARANCE;
|
||||||
@@ -126,6 +127,7 @@ export class PlayerDetail {
|
|||||||
if(role.head) this.head = role.head;
|
if(role.head) this.head = role.head;
|
||||||
if(role.frame) this.frame = role.frame;
|
if(role.frame) this.frame = role.frame;
|
||||||
if(role.spine) this.spine = role.spine;
|
if(role.spine) this.spine = role.spine;
|
||||||
|
if(role.ipLocation) this.ipLocation = role.ipLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
setCe(ce: number) {
|
setCe(ce: number) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export class FriendParams {
|
|||||||
serverName: string;
|
serverName: string;
|
||||||
type: number = FRIEND_RELATION_TYPE.NORMAL;
|
type: number = FRIEND_RELATION_TYPE.NORMAL;
|
||||||
guildName: string = '';
|
guildName: string = '';
|
||||||
|
ipLocation: string = '';
|
||||||
|
|
||||||
constructor(role: RoleType) {
|
constructor(role: RoleType) {
|
||||||
this.roleId = role.roleId;
|
this.roleId = role.roleId;
|
||||||
@@ -29,6 +30,7 @@ export class FriendParams {
|
|||||||
this.ce = role.ce;
|
this.ce = role.ce;
|
||||||
this.title = role.title;
|
this.title = role.title;
|
||||||
this.guildName = role.guildName||'';
|
this.guildName = role.guildName||'';
|
||||||
|
this.ipLocation = role.ipLocation||'';
|
||||||
}
|
}
|
||||||
|
|
||||||
setServerName(serverId: number, serverName: string) {
|
setServerName(serverId: number, serverName: string) {
|
||||||
|
|||||||
@@ -331,7 +331,7 @@ export default class Auth extends Service {
|
|||||||
const code = ctx.service.utils.genCode(6);
|
const code = ctx.service.utils.genCode(6);
|
||||||
const seqId = await Counter.getNewCounter(COUNTER.ROLE) || -1;
|
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) {
|
if (role) {
|
||||||
await ServerlistModel.incRoleCnt(serverId);
|
await ServerlistModel.incRoleCnt(serverId);
|
||||||
if(server.isReview) { // 审核服跳关卡
|
if(server.isReview) { // 审核服跳关卡
|
||||||
|
|||||||
Reference in New Issue
Block a user