网安:修改手机存储

This commit is contained in:
luying
2021-04-09 10:43:42 +08:00
parent ad2b62d426
commit a02ee04a5b
11 changed files with 4504 additions and 213 deletions

View File

@@ -5,6 +5,9 @@ export const TURBO_PARM_SECRET = 'ipqw05du6ob4x130w89t31yrqd6xs005zzltcmg2zpqnvr
export const ENCRYPT_IV = 'f7182j5f04e377ux';
export const ENCRYPT_KEY = 'fiqaxijabbantusmprc234fj';
export const TEL_ENCRYPT_IV = 'f7182j5f04e377ux';
export const TEL_ENCRYPT_KEY = 'fiqaxijabbantusm';
export const DEBUG_MAGIC_WORD = 'zyz666server518';
export const AUTH_SMS_CNT_PER_DAY = 8;

View File

@@ -305,7 +305,7 @@ export const STATUS = {
// 商店相关 30900-31000
BUY_COUNT_OVER: { code: 30900, simStr: '已超过限购次数' },
GUILD_LV_LIMIT: { code: 30901, simStr: '军团等级不足' },
GUILD_LV_LIMIT: { code: 30901, simStr: '军团商店等级不足' },
ITEM_NOT_SOUL: { code: 30902, simStr: '该物品不是将魂' },
SKIN_HAS_NOT_HERO: { code: 30903, simStr: '未拥有该武将不可获得皮肤' },
HERO_NOT_MAX: { code: 30904, simStr: '该武将未升满星' },

View File

@@ -1,6 +1,8 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { generateNum } from '../pubUtils/util';
import { generateNum, aesEncryptcfb, aesDecryptcfb } from '../pubUtils/util';
import { ENCRYPT_KEY, ENCRYPT_IV } from './../consts';
const moment = require('moment');
/**
@@ -9,7 +11,7 @@ const moment = require('moment');
@index({ tel: 1 })
export default class Sms extends BaseModel {
@prop({ required: true })
@prop({ required: true, set: (val: string) => aesEncryptcfb(val, ENCRYPT_KEY, ENCRYPT_IV), get: (val: string) => aesDecryptcfb(val, ENCRYPT_KEY, ENCRYPT_IV) })
tel: string;
@prop({ required: true })
@@ -31,17 +33,20 @@ export default class Sms extends BaseModel {
isFixed: boolean;
public static async findByTel(tel: string, lean = true) {
const sms: SmsType = await smsModel.findOne({ tel }).lean(lean);
let _tel = aesEncryptcfb(tel, ENCRYPT_KEY, ENCRYPT_IV);
const sms: SmsType = await smsModel.findOne({ tel: _tel }).lean(lean);
return sms;
}
public static async updateByTel(tel: string, code: string, used: boolean, updateTime: Date, countToday: number, lean = true) {
const sms: SmsType = await smsModel.findOneAndUpdate({ tel }, { code, used, updateTime, countToday }, { upsert: true }).lean(lean);
public static async updateByTel(tel: string, code: string, used: boolean, updateTime: Date, countToday: number) {
const sms: SmsType = await smsModel.findOneAndUpdate({ tel }, { tel, code, used, updateTime, countToday }, { upsert: true }).lean({ getters: true });
return sms;
}
public static async validateSms(tel: string, code: string, lean = true) {
const record: SmsType = await smsModel.findOneAndUpdate({ tel, code, used: false }, { used: true }).lean(lean);
public static async validateSms(tel: string, code: string) {
const record: SmsType = await smsModel.findOneAndUpdate({ tel, code, used: false }, { used: true }).lean({ getters: true });
return !!record;
}
@@ -66,14 +71,16 @@ export default class Sms extends BaseModel {
return moment(this.updateTime).format('YYYY-MM-DD') === moment(Date.now()).format('YYYY-MM-DD');
}
public static async fixSms(tel: string, lean = true) {
const sms: SmsType = await smsModel.findOneAndUpdate({ tel }, { $setOnInsert: {
public static async fixSms(tel: string) {
let _tel = aesEncryptcfb(tel, ENCRYPT_KEY, ENCRYPT_IV);
const sms: SmsType = await smsModel.findOneAndUpdate({ tel: _tel }, { $setOnInsert: {
tel,
code: generateNum(6),
used: false,
updateTime: new Date(),
countToday: 1
}, $set: { isFixed: true } }, {new: true, upsert: true}).lean(lean);
}, $set: { isFixed: true } }, {new: true, upsert: true}).lean({ getters: true });
return sms;
}
}

View File

@@ -1,8 +1,8 @@
import { COUNTER } from './../consts';
import { COUNTER, ENCRYPT_KEY, ENCRYPT_IV } from './../consts';
import { CounterModel } from './Counter';
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { genCode } from '../pubUtils/util';
import { genCode, aesEncryptcfb, aesDecryptcfb } from '../pubUtils/util';
const bcrypt = require('bcrypt');
const SALT_WORK_FACTOR = 5
@@ -25,7 +25,7 @@ export default class User extends BaseModel {
@prop({ required: true })
token: string;
@prop({ required: true })
@prop({ required: true, set: (val: string) => aesEncryptcfb(val, ENCRYPT_KEY, ENCRYPT_IV), get: (val: string) => aesDecryptcfb(val, ENCRYPT_KEY, ENCRYPT_IV) })
tel: string; // 账号
@prop({ required: true, default: '' })
@@ -102,6 +102,7 @@ export default class User extends BaseModel {
auth: number;
public static async createUser(isGuest: boolean, tel: string, token: string, platform: string, pkgName: string, serverType: string, deviceId: string, guestTime: number = 0) {
let _tel = aesEncryptcfb(tel, ENCRYPT_KEY, ENCRYPT_IV);
const curTime: Date = new Date();
const uid = await CounterModel.getNewCounter(COUNTER.UID);
@@ -109,27 +110,30 @@ export default class User extends BaseModel {
const doc = new UserModel();
let update = {};
update = Object.assign(update, doc.toJSON(), { platform, pkgName, serverType, createTime: curTime, uid, userCode, username: `用户${uid}`, isGuest, token, lastLoginTime: curTime, guestTime });
if(isGuest) update["guestId"] = tel;
if(isGuest) update["guestId"] = _tel;
delete update["device"];
const user: UserType = await UserModel.findOneAndUpdate({ tel }, { $set: update, $addToSet: {device: deviceId}}, { upsert: true, new: true }).lean();
const user: UserType = await UserModel.findOneAndUpdate({ tel }, { $set: update, $addToSet: {device: deviceId}}, { upsert: true, new: true }).lean({ getters: true });
return user;
}
public static async getLastDeviceGuest(deviceId: string, token: string) {
const user: UserType = await UserModel.findOneAndUpdate({ device: { $elemMatch: { $eq: deviceId } }, isGuest: true }, { token }, { new: true }).sort({createTime: -1}).lean();
const user: UserType = await UserModel.findOneAndUpdate({ device: { $elemMatch: { $eq: deviceId } }, isGuest: true }, { token }, { new: true }).sort({createTime: -1}).lean({ getters: true });
return user;
}
public static async updateToken(tel: string, token: string, deviceId: string, lean = true) {
public static async updateToken(tel: string, token: string, deviceId: string) {
const curTime: Date = new Date();
let user = await UserModel.findOneAndUpdate({ tel }, { $set: { token, lastLoginTime: curTime }, $addToSet: {device: deviceId}}, { new: true }).lean(lean);
let user = await UserModel.findOneAndUpdate({ tel }, { $set: { token, lastLoginTime: curTime }, $addToSet: {device: deviceId}}, { new: true }).lean({ getters: true });
return user;
}
public static async createOrUpdate(isGuest: boolean, tel: string, token: string, platform: string, pkgName: string, serverType: string, deviceId: string) {
let user: UserType = await UserModel.findOne({ tel }).lean();
console.log(tel);
let user: UserType = await UserModel.findOne({ tel }).lean({ getters: true });
if (!user) {
user = await UserModel.createUser(isGuest, tel, token, platform, pkgName, serverType, deviceId);
} else {
@@ -146,73 +150,76 @@ export default class User extends BaseModel {
return { npassword, salt };
}
public static async setPass(uid: number, password: string, lean = true) {
public static async setPass(uid: number, password: string) {
let r = await this.encryptPass(password);
const user: UserType = await UserModel.findOneAndUpdate({ uid }, { $set: { password: r.npassword, salt: r.salt, hasSetPw: true }}, {new: true}).lean(lean);
const user: UserType = await UserModel.findOneAndUpdate({ uid }, { $set: { password: r.npassword, salt: r.salt, hasSetPw: true }}, {new: true}).lean({ getters: true });
return user;
}
public static async bindTel(uid: number, tel: string, lean = true) {
const user: UserType = await UserModel.findOneAndUpdate({ uid, isGuest: true }, { $set: { tel, isGuest: false }}, {new: true}).lean(lean);
public static async bindTel(uid: number, tel: string) {
const user: UserType = await UserModel.findOneAndUpdate({ uid, isGuest: true }, { $set: { tel, isGuest: false }}, {new: true}).lean({ getters: true });
return user;
}
public static async checkPass(tel: string, password: string, token: string, deviceId: string, lean = true) {
const user: UserType = await UserModel.findOne({ tel }).select('salt').lean();
public static async checkPass(tel: string, password: string, token: string, deviceId: string) {
const user: UserType = await UserModel.findOne({ tel }).select('salt').lean({ getters: true });
if (user) {
const curTime: Date = new Date();
let { salt } = user;
let { npassword } = await this.encryptPass(password, salt);
const checkUser: UserType = await UserModel.findOneAndUpdate({ tel, password: npassword }, { $set: { token, lastLoginTime: curTime }, $addToSet: {device: deviceId}}, { new: true }).lean(lean);
const checkUser: UserType = await UserModel.findOneAndUpdate({ tel, password: npassword }, { $set: { token, lastLoginTime: curTime }, $addToSet: {device: deviceId}}, { new: true }).lean({ getters: true });
return checkUser;
} else {
return null
}
}
public static async findUserByToken(token: string, lean = true) {
const user: UserType = await UserModel.findOne({ token }).select('uid token serverType auth tel userCode pkgName').lean(lean);
public static async findUserByToken(token: string) {
const user: UserType = await UserModel.findOne({ token }).select('uid token serverType auth tel userCode pkgName').lean({ getters: true });
return user;
}
public static async findTokenByTel(tel: string, lean = true) {
const { token } = await UserModel.findOne({ tel }).select('token').lean(lean);
public static async findTokenByTel(tel: string) {
const { token } = await UserModel.findOne({ tel }).select('token').lean({ getters: true });
return token;
}
public static async findUserByTel(tel: string, lean = true) {
const user: UserType = await UserModel.findOne({ tel }).select('uid tel hasSetPw').lean(lean);
public static async findUserByTel(tel: string) {
const user: UserType = await UserModel.findOne({ tel }).select('uid tel hasSetPw').lean({ getters: true });
return user;
}
public static async findUserByUid(uid: number, lean = true) {
const user: UserType = await UserModel.findOne({ uid }).select('uid tel').lean(lean);
public static async findUserByUid(uid: number) {
const user: UserType = await UserModel.findOne({ uid }).select('uid tel').lean({ getters: true });
return user;
}
public static async findUserByUserCode(userCode: string, lean = true) {
const user: UserType = await UserModel.findOne({ userCode }).lean(lean);
public static async findUserByUserCode(userCode: string) {
const user: UserType = await UserModel.findOne({ userCode }).lean({ getters: true });
return user;
}
public static async addAuth(uid: number, auth: number, lean = true) {
const user: UserType = await UserModel.findOneAndUpdate({ uid }, { auth }, {new: true}).select('uid tel').lean(lean);
public static async addAuth(uid: number, auth: number) {
const user: UserType = await UserModel.findOneAndUpdate({ uid }, { auth }, {new: true}).select('uid tel').lean({ getters: true });
return user;
}
public static async authentication(uid: number, birthday: string, pi: string, lean = true) {
const user: UserType = await UserModel.findOneAndUpdate({ uid }, { hasAuthenticated: true, birthday, pi }, {new: true}).lean(lean);
public static async authentication(uid: number, birthday: string, pi: string) {
const user: UserType = await UserModel.findOneAndUpdate({ uid }, { hasAuthenticated: true, birthday, pi }, {new: true}).lean({ getters: true });
return user;
}
public static async findUserByField(field: string, value?: Array<number|string>, lean = true) {
public static async findUserByField(field: string, value?: Array<number|string>) {
let searchObj = {};
if(field != 'all') {
searchObj[field] = {
$in: value
};
}
const user: UserType[] = await UserModel.find(searchObj).select('uid tel username serverType auth').lean(lean);
const user: UserType[] = await UserModel.find(searchObj).select('uid tel username serverType auth').lean({ getters: true });
return user;
}
@@ -220,7 +227,7 @@ export default class User extends BaseModel {
public static async updatePlayTime(userCode: string, guestTimeInc: number, todayPlayTime: number, todayPlayType?: number) {
let update = { todayPlayTime, todayPlayType, reportTime: new Date() };
if(todayPlayType) update.todayPlayType;
const user: UserType = await UserModel.findOneAndUpdate({ userCode }, { $inc: { guestTime: guestTimeInc }, $set: update}, { new: true }).lean();
const user: UserType = await UserModel.findOneAndUpdate({ userCode }, { $inc: { guestTime: guestTimeInc }, $set: update}, { new: true }).lean({ getters: true });
return user;
}
}

View File

@@ -1,7 +1,6 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
import { genCode } from '../pubUtils/util';
import { ShopItem } from '../domain/dbGeneral';
import { getCurWeekDate, getCurMonthDate, getTodayZeroDate } from '../pubUtils/timeUtil';
import { SHOP_REFRESH_TYPE } from '../consts';
import { DicShop } from '../pubUtils/dictionary/DicShop';

View File

@@ -1,9 +1,9 @@
import { GUILDACTIVITY } from "../../pubUtils/dicParam";
import { SimpleGuildRankParam, SimpleRoleRankParam, GuildRankParam } from '../rank'
import { SimpleGuildRankParam, SimpleRoleRankParam } from '../rank'
import { prop } from "@typegoose/typegoose";
import { CITY_STATUS, RACE_EVENT_TYPE, RACE_EVENT_EFFECT_TYPE, REDIS_KEY, RACE_EVENT, STATUS } from "../../consts";
import { CITY_STATUS, RACE_EVENT } from "../../consts";
import { gameData, getRaceEventItems } from "../../pubUtils/data";
import { getRandEelm, sortArrRandom, resResult } from "../../pubUtils/util";
import { getRandEelm } from "../../pubUtils/util";
import { RewardInter } from "../../pubUtils/interface";
export class GateMembersRec {
@@ -85,7 +85,6 @@ export class WoodenHorse {
this.time = Date.now();
}
let effectiveEvents = new Array<Event>();
let delEvents = new Array<number>();
for(let i = 0; i < events.length; i++) {
let event = events[i];
if(!event.startTime && event.startDistance && this.distance > event.startDistance) {

View File

@@ -10,6 +10,40 @@ import { findIndex } from 'underscore';
import { getWeekDate } from './timeUtil';
const randomName = require("chinese-random-name");
const moment = require('moment');
const crypto = require('crypto');
export function aesEncrypt(data, key, iv) {
const cipher = crypto.createCipheriv('aes-192-cbc', key, iv);
let crypted = cipher.update(data, 'utf8', 'hex');
crypted += cipher.final('hex');
return crypted;
}
export function aesDecrypt(data, key, iv) {
const decipher = crypto.createDecipheriv('aes-192-cbc', key, iv);
let decrypted = decipher.update(data, 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}
export function aesEncryptcfb(data, key, iv) {
console.log('****aesEncryptcfb', data)
const cipher = crypto.createCipheriv('aes-192-cfb', key, iv);
let crypted = cipher.update(data, 'utf8', 'hex');
crypted += cipher.final('hex');
return crypted;
}
export function aesDecryptcfb(data, key, iv) {
if(data) {
const decipher = crypto.createDecipheriv('aes-192-cfb', key, iv);
let decrypted = decipher.update(data, 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
} else {
return ''
}
}
export function genCode(len) {
const chars = '123456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijklmnopqrstuvwxyz';

View File

@@ -1,82 +1,87 @@
[
{
"id": 1,
"content": "您对军团%d的申请被拒绝",
"content": "<color= #000000>您对军团%d的申请被拒绝</color>",
"time": 24
},
{
"id": 2,
"content": "由于被弹劾,您在军团%d的大将军职务已卸任",
"content": "<color= #000000>由于被弹劾,您在军团%d的大将军职务已卸任</color>",
"time": 24
},
{
"id": 3,
"content": "您被任命为军团%d的大将军",
"content": "<color= #000000>您被任命为军团%d的大将军</color>",
"time": 24
},
{
"id": 4,
"content": "您被军团%d踢出",
"content": "<color= #000000>您被军团%d踢出</color>",
"time": 24
},
{
"id": 5,
"content": "亲爱的小将军,您昨日的军团活跃奖励忘记领取了,现已通过邮件发放,请查收",
"content": "<color= #000000>亲爱的小将军,您昨日的军团活跃奖励忘记领取了,现已通过邮件发放,请查收</color>",
"time": 24
},
{
"id": 6,
"content": "您被任命为军团%d的管理",
"content": "<color= #000000>您被任命为军团%d的管理</color>",
"time": 24
},
{
"id": 7,
"content": "您已卸任军团%d的管理",
"content": "<color= #000000>您已卸任军团%d的管理</color>",
"time": 24
},
{
"id": 8,
"content": "小将军您的军团已开启boss%d请赶往支援",
"content": "<color= #000000>小将军您的军团已开启boss%d请赶往支援</color>",
"time": 24
},
{
"id": 9,
"content": "恭喜小将军军团上下一心已成功压制boss%d您在此次压制中的排名为第%d名获得如下奖励",
"content": "<color= #000000>恭喜小将军军团上下一心已成功压制boss%d您在此次压制中的排名为第%d名获得如下奖励</color>",
"time": 24
},
{
"id": 10,
"content": "小将军,您在上周军团练兵场中有奖励尚未领取,奖励如下:",
"content": "<color= #000000>小将军,您在上周军团练兵场中有奖励尚未领取,奖励如下:</color>",
"time": 24
},
{
"id": 11,
"content": "小将军,%d赠送您一个%d请查收",
"content": "<color= #000000>小将军,%d赠送您一个%d请查收</color>",
"time": 24
},
{
"id": 12,
"content": "亲爱的小将军,您在%d赛季结算奖励如下:",
"content": "<color= #000000>亲爱的小将军,您在%d赛季结算奖励如下:</color>",
"time": 24
},
{
"id": 13,
"content": "恭喜小将军,您在%d赛季最终获得了第%d名获得如下奖励",
"content": "<color= #000000>恭喜小将军,您在%d赛季最终获得了第%d名获得如下奖励</color>",
"time": 24
},
{
"id": 14,
"content": "亲爱的小将军,您昨日的军团活动奖励忘记领取了,现已通过邮件发放,请查收:",
"content": "<color= #000000>亲爱的小将军,您参与军团活动奖励已通过邮件发放,请查收:</color>",
"time": 24
},
{
"id": 15,
"content": "小将军很抱歉,您在拍卖行的出价已被超过,元宝退还给您,请查收:",
"content": "<color= #000000>小将军很抱歉,您在拍卖行的出价已被超过,元宝退还给您,请查收:</color>",
"time": 24
},
{
"id": 16,
"content": "恭喜小将军,您已在拍卖行成功拍下以下物品,请查收:",
"content": "<color= #000000>恭喜小将军,您已在拍卖行成功拍下以下物品,请查收:</color>",
"time": 24
},
{
"id": 17,
"content": "<color= #000000>亲爱的小将军,您昨日的拍卖分红忘记领取了,现已通过邮件发放,请查收</color>",
"time": 24
}
]

View File

@@ -14,7 +14,7 @@
"fobiddenCharactor": "&",
"victoryInfoInUI": "消灭所有敌军",
"loseInfoInUI": "我方全部阵亡",
"starInfoInUI": "1.我方无人阵亡;\r\n2.在5回合内获得胜利",
"starInfoInUI": "1.我方无人阵亡;\n2.在5回合内获得胜利",
"cost": 0,
"recommendedPower": 19875,
"previousGk": 104,
@@ -29,7 +29,7 @@
"war_id": 5010,
"dispatchJsonId": 5010,
"bg_img_id": 560,
"script_id": 0,
"script_id": "S_5010",
"fixReward": "11004&1|17002&10|17007&2|17008&3",
"conditionReward": "1&1&0|31002&50&0|31002&100&1",
"warType": 6,
@@ -40,7 +40,7 @@
"fobiddenCharactor": "&",
"victoryInfoInUI": "消灭所有敌军",
"loseInfoInUI": "我方全部阵亡",
"starInfoInUI": "1.我方无人阵亡;\r\n2.在6回合内获得胜利",
"starInfoInUI": "1.我方无人阵亡;\n2.在6回合内获得胜利",
"cost": 0,
"recommendedPower": 22684,
"previousGk": 104,
@@ -54,8 +54,8 @@
{
"war_id": 5020,
"dispatchJsonId": 5020,
"bg_img_id": 550,
"script_id": 0,
"bg_img_id": 570,
"script_id": "S_5020",
"fixReward": "11004&4|17002&8|17007&6|17008&5",
"conditionReward": "1&1&0|31002&50&0|31002&100&1",
"warType": 6,
@@ -66,16 +66,16 @@
"fobiddenCharactor": "&",
"victoryInfoInUI": "消灭所有敌军",
"loseInfoInUI": "我方全部阵亡",
"starInfoInUI": "1.我方无人阵亡;\r\n2.在7回合内获得胜利",
"starInfoInUI": "1.我方无人阵亡;\n2.在7回合内获得胜利",
"cost": 0,
"recommendedPower": 24963,
"previousGk": 208,
"previousGk": 104,
"lvLimted": 1,
"heroInUI": "2&10",
"detailUIBg": "dengeon1",
"heroInUI": "2&7",
"detailUIBg": "1_1",
"iconName": "city",
"iconInMap": "city&3",
"bossSkill": "18&19"
"bossSkill": "43&65"
},
{
"war_id": 5030,
@@ -92,7 +92,7 @@
"fobiddenCharactor": "&",
"victoryInfoInUI": "消灭所有敌军",
"loseInfoInUI": "我方全部阵亡",
"starInfoInUI": "1.我方无人阵亡;\r\n2.在8回合内获得胜利",
"starInfoInUI": "1.我方无人阵亡;\n2.在8回合内获得胜利",
"cost": 0,
"recommendedPower": 27853,
"previousGk": 220,
@@ -118,7 +118,7 @@
"fobiddenCharactor": "&",
"victoryInfoInUI": "消灭所有敌军",
"loseInfoInUI": "我方全部阵亡",
"starInfoInUI": "1.我方无人阵亡;\r\n2.在9回合内获得胜利",
"starInfoInUI": "1.我方无人阵亡;\n2.在9回合内获得胜利",
"cost": 0,
"recommendedPower": 31335,
"previousGk": 304,
@@ -144,7 +144,7 @@
"fobiddenCharactor": "&",
"victoryInfoInUI": "消灭所有敌军",
"loseInfoInUI": "我方全部阵亡",
"starInfoInUI": "1.我方无人阵亡;\r\n2.在10回合内获得胜利",
"starInfoInUI": "1.我方无人阵亡;\n2.在10回合内获得胜利",
"cost": 0,
"recommendedPower": 35698,
"previousGk": 310,
@@ -170,7 +170,7 @@
"fobiddenCharactor": "&",
"victoryInfoInUI": "消灭所有敌军",
"loseInfoInUI": "我方全部阵亡",
"starInfoInUI": "1.我方无人阵亡;\r\n2.在11回合内获得胜利",
"starInfoInUI": "1.我方无人阵亡;\n2.在11回合内获得胜利",
"cost": 0,
"recommendedPower": 45673,
"previousGk": 320,

File diff suppressed because it is too large Load Diff