数数:修改创建角色逻辑
This commit is contained in:
@@ -18,7 +18,7 @@ import { pushData, everydayRefresh, kickUser, getModuleData } from '../../../ser
|
|||||||
// import { setComBtlOnUserLeave } from '../../../services/comBattleService';
|
// import { setComBtlOnUserLeave } from '../../../services/comBattleService';
|
||||||
import Counter from '../../../db/Counter';
|
import Counter from '../../../db/Counter';
|
||||||
import { getExpByLv } from '../../../pubUtils/data';
|
import { getExpByLv } from '../../../pubUtils/data';
|
||||||
import { 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';
|
||||||
|
|
||||||
@@ -65,8 +65,9 @@ export class EntryHandler {
|
|||||||
let serverName = this.app.getServerId();
|
let serverName = this.app.getServerId();
|
||||||
await roleLogin(role.roleId, user.userCode, serverName, user.pkgName, role.createTime, role.serverId); // 保存在线用户
|
await roleLogin(role.roleId, user.userCode, serverName, user.pkgName, role.createTime, role.serverId); // 保存在线用户
|
||||||
await this.addSession(user, role, session);
|
await this.addSession(user, role, session);
|
||||||
saveLoginAndOutLog(LOG_TYPE.LOGIN, session);
|
|
||||||
|
|
||||||
|
await reportCreateRoleEventToTa(role, this.getIp(session));
|
||||||
|
saveLoginAndOutLog(LOG_TYPE.LOGIN, session);
|
||||||
addRoleToSysChannel(role.roleId, self.app.get('serverId'), role.serverId);
|
addRoleToSysChannel(role.roleId, self.app.get('serverId'), role.serverId);
|
||||||
addRoleToWorldChannel(role.roleId, self.app.get('serverId'), role.serverId);
|
addRoleToWorldChannel(role.roleId, self.app.get('serverId'), role.serverId);
|
||||||
reportOneOnline(role.roleId, user.userCode, self.app.get('serverId'), true, user);
|
reportOneOnline(role.roleId, user.userCode, self.app.get('serverId'), true, user);
|
||||||
@@ -95,9 +96,13 @@ export class EntryHandler {
|
|||||||
return resResult(STATUS.SUCCESS, { todayZeroPoint });
|
return resResult(STATUS.SUCCESS, { todayZeroPoint });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getIp(session: FrontendSession) {
|
||||||
|
return session.remoteAddress.ip.replace('::ffff:', '');
|
||||||
|
}
|
||||||
|
|
||||||
async addSession(user: UserType, role: RoleType, session: FrontendSession) {
|
async addSession(user: UserType, role: RoleType, session: FrontendSession) {
|
||||||
const self = this;
|
const self = this;
|
||||||
let ip = session.remoteAddress.ip.replace('::ffff:', '');
|
let ip = this.getIp(session);
|
||||||
|
|
||||||
await session.abind(role.roleId);
|
await session.abind(role.roleId);
|
||||||
session.set('userid', role.userInfo.uid);
|
session.set('userid', role.userInfo.uid);
|
||||||
@@ -320,7 +325,7 @@ export class EntryHandler {
|
|||||||
const code = genCode(6);
|
const code = genCode(6);
|
||||||
const seqId = await Counter.getNewCounter(COUNTER.ROLE) || -1;
|
const seqId = await Counter.getNewCounter(COUNTER.ROLE) || -1;
|
||||||
|
|
||||||
await RoleModel.createRole(user.uid, serverId, { roleId, code, roleName: roleId, seqId, lv: DEFAULT_LV, exp: (getExpByLv(DEFAULT_LV - 1) || { sum: 0 }).sum || 0 });
|
await RoleModel.createRole(user.uid, serverId, { roleId, code, roleName: roleId, seqId, lv: DEFAULT_LV, exp: (getExpByLv(DEFAULT_LV - 1) || { sum: 0 }).sum || 0 }, '');
|
||||||
}
|
}
|
||||||
console.log('debugQueryTokenByTel got user:', token);
|
console.log('debugQueryTokenByTel got user:', token);
|
||||||
return resResult(STATUS.SUCCESS, { user: token });
|
return resResult(STATUS.SUCCESS, { user: token });
|
||||||
|
|||||||
@@ -541,7 +541,7 @@ export class RoleHandler {
|
|||||||
let newRoleId = genCode(10);
|
let newRoleId = genCode(10);
|
||||||
const seqId = await Counter.getNewCounter(COUNTER.ROLE) || -1;
|
const seqId = await Counter.getNewCounter(COUNTER.ROLE) || -1;
|
||||||
await RoleModel.findOneAndUpdate({ roleId }, { $set: { 'userInfo.uid': 0, roleName: 'deletedRole' } });
|
await RoleModel.findOneAndUpdate({ roleId }, { $set: { 'userInfo.uid': 0, roleName: 'deletedRole' } });
|
||||||
role = await RoleModel.createRole(userInfo.uid, role.serverId, { roleId: newRoleId, code: role.code, roleName: newRoleId, seqId, lv: DEFAULT_LV, exp: (getExpByLv(DEFAULT_LV - 1) || { sum: 0 }).sum || 0 });
|
role = await RoleModel.createRole(userInfo.uid, role.serverId, { roleId: newRoleId, code: role.code, roleName: newRoleId, seqId, lv: DEFAULT_LV, exp: (getExpByLv(DEFAULT_LV - 1) || { sum: 0 }).sum || 0 }, '');
|
||||||
|
|
||||||
session.set('roleId', newRoleId);
|
session.set('roleId', newRoleId);
|
||||||
session.push('roleId', () => {});
|
session.push('roleId', () => {});
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ function getApWithDataAp(roleId: string, ip: string, lv: number, dataAp: ActionP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(result.ap > oldAp) {
|
if(result.ap > oldAp) {
|
||||||
reportTAEvent(roleId, TA_EVENT.AP_GET, { change_count: oldAp - result.ap, change_after: result.ap, change_reason: ITEM_CHANGE_REASON.AP_RECOVERY })
|
reportTAEvent(roleId, TA_EVENT.AP_GET, { change_count: result.ap - oldAp, change_after: result.ap, change_reason: ITEM_CHANGE_REASON.AP_RECOVERY })
|
||||||
}
|
}
|
||||||
|
|
||||||
return fromGetAp?result: pick(result, ['ap', 'maxAp', 'apRemainTime', 'apMaxRemainTime', 'buyTimes', 'apBefore']);
|
return fromGetAp?result: pick(result, ['ap', 'maxAp', 'apRemainTime', 'apMaxRemainTime', 'buyTimes', 'apBefore']);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { RoleModel, RoleType } from "../db/Role";
|
|||||||
import { Chat37Params, CheckGuild37Params, CheckName37Params, GetWordParam } from "../domain/sdk";
|
import { Chat37Params, CheckGuild37Params, CheckName37Params, GetWordParam } from "../domain/sdk";
|
||||||
import { sendMailByContent, sendMailToGuildByContent } from './mailService';
|
import { sendMailByContent, sendMailToGuildByContent } from './mailService';
|
||||||
import { NAMEPLATE } from '../pubUtils/dicParam';
|
import { NAMEPLATE } from '../pubUtils/dicParam';
|
||||||
import { CHANNEL_PREFIX, FILENAME, getSdkChannelId, MAIL_TYPE, PUSH_ROUTE, REDIS_KEY, SDK_37_ADDR, SDK_37_CONST, SDK_TA_CONST, STATUS, TA_USERSET_TYPE, THINKING_DATA_MODE, THINKING_DATA_MODE_LIST } from "../consts";
|
import { CHANNEL_PREFIX, FILENAME, getSdkChannelId, MAIL_TYPE, PUSH_ROUTE, REDIS_KEY, SDK_37_ADDR, SDK_37_CONST, SDK_TA_CONST, STATUS, TA_EVENT, TA_USERSET_TYPE, THINKING_DATA_MODE, THINKING_DATA_MODE_LIST } from "../consts";
|
||||||
import { UserModel } from "../db/User";
|
import { UserModel } from "../db/User";
|
||||||
import { request37CheckChat, request37GetWord, request37Post } from "../pubUtils/httpUtil";
|
import { request37CheckChat, request37GetWord, request37Post } from "../pubUtils/httpUtil";
|
||||||
import { GuildModel } from "../db/Guild";
|
import { GuildModel } from "../db/Guild";
|
||||||
@@ -165,27 +165,29 @@ export async function treatGuildName(content: string) {
|
|||||||
|
|
||||||
export function connectThinkingData(app: Application) {
|
export function connectThinkingData(app: Application) {
|
||||||
let ta;
|
let ta;
|
||||||
if(THINKING_DATA_MODE == THINKING_DATA_MODE_LIST.DEBUG) {
|
if(app.get('env') != 'development') {
|
||||||
ta = ThinkingAnalytics.initWithDebugMode(SDK_TA_CONST.APPID, SDK_TA_CONST.SERVER_URL);
|
if(THINKING_DATA_MODE == THINKING_DATA_MODE_LIST.DEBUG) {
|
||||||
} else if (THINKING_DATA_MODE == THINKING_DATA_MODE_LIST.BATCH) {
|
ta = ThinkingAnalytics.initWithDebugMode(SDK_TA_CONST.APPID, SDK_TA_CONST.SERVER_URL);
|
||||||
ta = ThinkingAnalytics.initWithBatchMode(SDK_TA_CONST.APPID, SDK_TA_CONST.SERVER_URL);
|
} else if (THINKING_DATA_MODE == THINKING_DATA_MODE_LIST.BATCH) {
|
||||||
} else if (THINKING_DATA_MODE == THINKING_DATA_MODE_LIST.LOGGING) {
|
ta = ThinkingAnalytics.initWithBatchMode(SDK_TA_CONST.APPID, SDK_TA_CONST.SERVER_URL);
|
||||||
ta = ThinkingAnalytics.initWithLoggingMode(SDK_TA_CONST.LOG_PATH, {
|
} else if (THINKING_DATA_MODE == THINKING_DATA_MODE_LIST.LOGGING) {
|
||||||
pm2: true
|
ta = ThinkingAnalytics.initWithLoggingMode(SDK_TA_CONST.LOG_PATH, {
|
||||||
});
|
pm2: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ta.setDynamicSuperProperties(() => {
|
||||||
|
return {
|
||||||
|
env: app.get('env'),
|
||||||
|
sid: app.getServerId()
|
||||||
|
};
|
||||||
|
});
|
||||||
|
app.set('ta', ta);
|
||||||
}
|
}
|
||||||
// ta.setDynamicSuperProperties(() => {
|
|
||||||
// return {
|
|
||||||
// env: app.get('env'),
|
|
||||||
// server: app.getServerId(),
|
|
||||||
// mode: THINKING_DATA_MODE
|
|
||||||
// };
|
|
||||||
// });
|
|
||||||
app.set('ta', ta);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function reportTAEvent(roleId: string, eventName: string, properties: any, ip?: string) {
|
export function reportTAEvent(roleId: string, eventName: string, properties: any, ip?: string) {
|
||||||
let ta = pinus.app.get('ta');
|
let ta = pinus.app.get('ta');
|
||||||
|
if(!ta) return
|
||||||
let event = {
|
let event = {
|
||||||
// 账号 ID (可选)
|
// 账号 ID (可选)
|
||||||
accountId: `${roleId}`,
|
accountId: `${roleId}`,
|
||||||
@@ -209,6 +211,7 @@ export function reportTAEvent(roleId: string, eventName: string, properties: any
|
|||||||
|
|
||||||
export function reportTAUserSet(type: TA_USERSET_TYPE, roleId: string, properties: any) {
|
export function reportTAUserSet(type: TA_USERSET_TYPE, roleId: string, properties: any) {
|
||||||
let ta = pinus.app.get('ta');
|
let ta = pinus.app.get('ta');
|
||||||
|
if(!ta) return
|
||||||
let userData = {
|
let userData = {
|
||||||
// 账号 ID (可选)
|
// 账号 ID (可选)
|
||||||
accountId: `${roleId}`,
|
accountId: `${roleId}`,
|
||||||
@@ -232,8 +235,16 @@ export function reportTAUserSet(type: TA_USERSET_TYPE, roleId: string, propertie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function reportCreateRoleEventToTa(role: RoleType, ip: string) {
|
||||||
|
if(role.shushuMark) {
|
||||||
|
reportTAEvent(role.roleId, TA_EVENT.CREATE_ROLE, null, ip);
|
||||||
|
await RoleModel.updateRoleInfo(role.roleId, { shushuMark: '' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function taflush() {
|
export function taflush() {
|
||||||
let ta = pinus.app.get('ta');
|
let ta = pinus.app.get('ta');
|
||||||
|
if(!ta) return;
|
||||||
ta.flush();
|
ta.flush();
|
||||||
ta.close();
|
ta.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export enum SDK_37_CONST {
|
|||||||
export enum SDK_TA_CONST {
|
export enum SDK_TA_CONST {
|
||||||
APPID = '74120ffc6f2945448cc60bf1540c5ad4',
|
APPID = '74120ffc6f2945448cc60bf1540c5ad4',
|
||||||
SERVER_URL = 'https://shushu.xyplay.cn',
|
SERVER_URL = 'https://shushu.xyplay.cn',
|
||||||
LOG_PATH = '/root/zyz/game-server/logs/ta',
|
LOG_PATH = '/zyz_logs/ta',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WJX_KEY = "f98551ef-4c7a-4ae2-abda-b7cca2684fe6"
|
export const WJX_KEY = "f98551ef-4c7a-4ae2-abda-b7cca2684fe6"
|
||||||
@@ -846,7 +846,7 @@ export enum THINKING_DATA_MODE_LIST {
|
|||||||
BATCH = 'batch',
|
BATCH = 'batch',
|
||||||
LOGGING = 'logging',
|
LOGGING = 'logging',
|
||||||
}
|
}
|
||||||
export let THINKING_DATA_MODE = THINKING_DATA_MODE_LIST.BATCH;
|
export let THINKING_DATA_MODE = THINKING_DATA_MODE_LIST.LOGGING;
|
||||||
|
|
||||||
|
|
||||||
export enum BLOCK_TYPE {
|
export enum BLOCK_TYPE {
|
||||||
|
|||||||
+4
-2
@@ -311,6 +311,8 @@ export default class Role extends BaseModel {
|
|||||||
|
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
sdkMark: boolean; // 37sdk标记有问题
|
sdkMark: boolean; // 37sdk标记有问题
|
||||||
|
@prop({ required: false })
|
||||||
|
shushuMark: string; // 数数distinctId
|
||||||
|
|
||||||
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 });
|
||||||
@@ -356,11 +358,11 @@ export default class Role extends BaseModel {
|
|||||||
return role;
|
return role;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async createRole(uid: number, serverId: number, roleInfo: { roleId: string; roleName: string; seqId: number; code: string, lv?: number, exp?: number }, lean = true) {
|
public static async createRole(uid: number, serverId: number, roleInfo: { roleId: string; roleName: string; seqId: number; code: string, lv?: number, exp?: number }, distinctId: string, lean = true) {
|
||||||
const user = await User.findUserByUid(uid);
|
const user = await User.findUserByUid(uid);
|
||||||
if (!user) return null;
|
if (!user) return null;
|
||||||
const doc = new RoleModel();
|
const doc = new RoleModel();
|
||||||
const update = Object.assign(doc.toJSON(), roleInfo, { userInfo: user, serverType: user.serverType, serverId });
|
const update = Object.assign(doc.toJSON(), roleInfo, { userInfo: user, serverType: user.serverType, serverId, shushuMark: distinctId });
|
||||||
delete update._id;
|
delete update._id;
|
||||||
const role: RoleType = await RoleModel.findOneAndUpdate({ 'userInfo.uid': uid, serverId }, update, { upsert: true, new: true }).lean(lean);
|
const role: RoleType = await RoleModel.findOneAndUpdate({ 'userInfo.uid': uid, serverId }, update, { upsert: true, new: true }).lean(lean);
|
||||||
return role;
|
return role;
|
||||||
|
|||||||
+18
-16
@@ -99,23 +99,25 @@ export default class FooBoot implements IBoot {
|
|||||||
|
|
||||||
public connectThinkingData(app: Application) {
|
public connectThinkingData(app: Application) {
|
||||||
let ta;
|
let ta;
|
||||||
if(THINKING_DATA_MODE == THINKING_DATA_MODE_LIST.DEBUG) {
|
if(app.config.realEnv != 'development') {
|
||||||
ta = ThinkingAnalytics.initWithDebugMode(SDK_TA_CONST.APPID, SDK_TA_CONST.SERVER_URL);
|
if(THINKING_DATA_MODE == THINKING_DATA_MODE_LIST.DEBUG) {
|
||||||
} else if (THINKING_DATA_MODE == THINKING_DATA_MODE_LIST.BATCH) {
|
ta = ThinkingAnalytics.initWithDebugMode(SDK_TA_CONST.APPID, SDK_TA_CONST.SERVER_URL);
|
||||||
ta = ThinkingAnalytics.initWithBatchMode(SDK_TA_CONST.APPID, SDK_TA_CONST.SERVER_URL);
|
} else if (THINKING_DATA_MODE == THINKING_DATA_MODE_LIST.BATCH) {
|
||||||
} else if (THINKING_DATA_MODE == THINKING_DATA_MODE_LIST.LOGGING) {
|
ta = ThinkingAnalytics.initWithBatchMode(SDK_TA_CONST.APPID, SDK_TA_CONST.SERVER_URL);
|
||||||
ta = ThinkingAnalytics.initWithLoggingMode(SDK_TA_CONST.LOG_PATH, {
|
} else if (THINKING_DATA_MODE == THINKING_DATA_MODE_LIST.LOGGING) {
|
||||||
pm2: true
|
ta = ThinkingAnalytics.initWithLoggingMode(SDK_TA_CONST.LOG_PATH, {
|
||||||
});
|
pm2: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// ta.setDynamicSuperProperties(() => {
|
||||||
|
// return {
|
||||||
|
// env: app.get('env'),
|
||||||
|
// server: app.getServerId(),
|
||||||
|
// mode: THINKING_DATA_MODE
|
||||||
|
// };
|
||||||
|
// });
|
||||||
|
app.context.ta = ta;
|
||||||
}
|
}
|
||||||
// ta.setDynamicSuperProperties(() => {
|
|
||||||
// return {
|
|
||||||
// env: app.get('env'),
|
|
||||||
// server: app.getServerId(),
|
|
||||||
// mode: THINKING_DATA_MODE
|
|
||||||
// };
|
|
||||||
// });
|
|
||||||
app.context.ta = ta;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
import { COUNTER, DEFAULT_LV, ADULT_AGE, GUEST_MAX_TIME, BLOCK_TYPE, TA_EVENT } from '@consts';
|
import { COUNTER, DEFAULT_LV, ADULT_AGE, GUEST_MAX_TIME, BLOCK_TYPE } from '@consts';
|
||||||
import { RoleModel } from '@db/Role';
|
import { RoleModel } from '@db/Role';
|
||||||
import { UserModel, UserType } from '@db/User';
|
import { UserModel, UserType } from '@db/User';
|
||||||
import { STATUS, GET_SMS_TYPE, ADDICTION_PREVENTION_CODE } from '@consts';
|
import { STATUS, GET_SMS_TYPE, ADDICTION_PREVENTION_CODE } from '@consts';
|
||||||
@@ -317,12 +317,9 @@ 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 });
|
const role = await RoleModel.createRole(uid, serverId, { roleId, code, roleName: "默认玩家名", seqId, lv: DEFAULT_LV, exp: (getExpByLv(DEFAULT_LV - 1) || { sum: 0 }).sum || 0 }, distinctId);
|
||||||
if (role) {
|
if (role) {
|
||||||
await ServerlistModel.incRoleCnt(serverId);
|
await ServerlistModel.incRoleCnt(serverId);
|
||||||
// 任务
|
|
||||||
|
|
||||||
ctx.service.sdk.reportTAEventWithRoleIdAndDistinctId(roleId, distinctId, TA_EVENT.CREATE_ROLE, null, ctx.clientIp);
|
|
||||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { roleId: role.roleId });
|
return ctx.service.utils.resResult(STATUS.SUCCESS, { roleId: role.roleId });
|
||||||
}
|
}
|
||||||
return ctx.service.utils.resResult(STATUS.ROLE_NOT_FOUND);
|
return ctx.service.utils.resResult(STATUS.ROLE_NOT_FOUND);
|
||||||
|
|||||||
@@ -369,6 +369,7 @@ export default class Sdk extends Service {
|
|||||||
|
|
||||||
public reportTAEventWithDistinctId(distinctId: string, eventName: string, properties: any, ip: string) {
|
public reportTAEventWithDistinctId(distinctId: string, eventName: string, properties: any, ip: string) {
|
||||||
let ta = this.app.context.ta;
|
let ta = this.app.context.ta;
|
||||||
|
if(!ta) return
|
||||||
let event = {
|
let event = {
|
||||||
// 账号 ID (可选)
|
// 账号 ID (可选)
|
||||||
accountId: "",
|
accountId: "",
|
||||||
@@ -392,6 +393,7 @@ export default class Sdk extends Service {
|
|||||||
|
|
||||||
public reportTAEventWithRoleIdAndDistinctId(roleId: string, distinctId: string, eventName: string, properties: any, ip?: string) {
|
public reportTAEventWithRoleIdAndDistinctId(roleId: string, distinctId: string, eventName: string, properties: any, ip?: string) {
|
||||||
let ta = this.app.context.ta;
|
let ta = this.app.context.ta;
|
||||||
|
if(!ta) return
|
||||||
let event = {
|
let event = {
|
||||||
// 账号 ID (可选)
|
// 账号 ID (可选)
|
||||||
accountId: `${roleId}`,
|
accountId: `${roleId}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user