diff --git a/config/json.go b/config/json.go index cb06c5c..3853281 100644 --- a/config/json.go +++ b/config/json.go @@ -9,8 +9,9 @@ import ( ) type AppConfigs struct { - AppName string `json:"app_name"` - Settings Settings `json:"settings"` + AppName string `json:"app_name"` + Settings Settings `json:"settings"` + UserPrefs UserPrefs `json:"user_prefs"` } type Settings struct { @@ -18,6 +19,18 @@ type Settings struct { AsCdnServer string `json:"as_cdn_server"` } +type UserPrefs struct { + Name string `json:"name"` // 用户名 + Level int `json:"level"` // 用户等级 + ExpNumerator int `json:"exp_numerator"` // Exp 分子 + ExpDenominator int `json:"exp_denominator"` // Exp 分母 + GameCoin int `json:"game_coin"` // 游戏金币 + SnsCoin int `json:"sns_coin"` // 游戏爱心 + EnergyMax int `json:"energy_max"` // 体力上限 + OverMaxEnergy int `json:"over_max_energy"` // 实际体力,为 0 时与 EnergyMax 一致 + InviteCode string `json:"invite_code"` // 用户 ID +} + func DefaultConfigs() *AppConfigs { return &AppConfigs{ AppName: "honoka-chan", @@ -25,6 +38,17 @@ func DefaultConfigs() *AppConfigs { SifCdnServer: "http://192.168.1.123/static", AsCdnServer: "http://192.168.1.123/static", }, + UserPrefs: UserPrefs{ + Name: "梦路 @bilibili", + Level: 1028, + ExpNumerator: 1089696, + ExpDenominator: 1207185, + GameCoin: 112124104, + SnsCoin: 0, + EnergyMax: 417, + OverMaxEnergy: 0, + InviteCode: "377385143", + }, } } diff --git a/handler/api.go b/handler/api.go index c3a0ae3..5d5cfc9 100644 --- a/handler/api.go +++ b/handler/api.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "honoka-chan/config" "honoka-chan/encrypt" "honoka-chan/model" "honoka-chan/tools" @@ -975,18 +976,20 @@ func Api(ctx *gin.Context) { Cols("unit_removable_skill_id").Find(&removeSkillIds) CheckErr(err) + userId, err := strconv.Atoi(config.Conf.UserPrefs.InviteCode) + CheckErr(err) profileResp := model.ProfileResp{ Result: model.ProfileRes{ UserInfo: model.ProfileUserInfo{ - UserID: pref.UserID, + UserID: userId, Name: pref.UserName, - Level: pref.UserLevel, + Level: config.Conf.UserPrefs.Level, CostMax: 100, UnitMax: 5000, - EnergyMax: 1000, + EnergyMax: config.Conf.UserPrefs.EnergyMax, FriendMax: 99, UnitCnt: int(commonUnit + userUnit), - InviteCode: strconv.Itoa(pref.UserID), + InviteCode: config.Conf.UserPrefs.InviteCode, ElapsedTimeFromLogin: "14\u5c0f\u65f6\u524d", Introduction: pref.UserDesc, }, diff --git a/handler/userinfo.go b/handler/userinfo.go index 81890e4..4145312 100644 --- a/handler/userinfo.go +++ b/handler/userinfo.go @@ -4,8 +4,10 @@ import ( "encoding/base64" "encoding/json" "fmt" + "honoka-chan/config" "honoka-chan/encrypt" "honoka-chan/model" + "honoka-chan/tools" "net/http" "strconv" "time" @@ -17,31 +19,39 @@ func UserInfo(ctx *gin.Context) { userId, err := strconv.Atoi(ctx.GetString("userid")) CheckErr(err) + pref := tools.UserPref{} + exists, err := UserEng.Table("user_preference_m").Where("user_id = ?", userId).Get(&pref) + CheckErr(err) + if !exists { + ctx.String(http.StatusForbidden, ErrorMsg) + return + } + userResp := model.UserInfoResp{ ResponseData: model.UserInfoRes{ User: model.UserInfo{ UserID: userId, - Name: "\u68a6\u8def @\u65c5\u7acb\u3061\u306e\u65e5\u306b", - Level: 1028, - Exp: 28824396, - PreviousExp: 27734700, - NextExp: 28941885, - GameCoin: 112124104, - SnsCoin: 0, + Name: pref.UserName, + Level: config.Conf.UserPrefs.Level, + Exp: config.Conf.UserPrefs.ExpNumerator, + PreviousExp: 0, + NextExp: config.Conf.UserPrefs.ExpDenominator, + GameCoin: config.Conf.UserPrefs.GameCoin, + SnsCoin: config.Conf.UserPrefs.SnsCoin, FreeSnsCoin: 0, PaidSnsCoin: 0, SocialPoint: 1438395, UnitMax: 5000, WaitingUnitMax: 1000, - EnergyMax: 417, + EnergyMax: config.Conf.UserPrefs.EnergyMax, EnergyFullTime: "2023-03-20 03:58:55", LicenseLiveEnergyRecoverlyTime: 60, EnergyFullNeedTime: 0, - OverMaxEnergy: 0, + OverMaxEnergy: config.Conf.UserPrefs.OverMaxEnergy, TrainingEnergy: 100, TrainingEnergyMax: 100, FriendMax: 99, - InviteCode: "377385143", + InviteCode: config.Conf.UserPrefs.InviteCode, InsertDate: "2015-08-10 18:58:30", UpdateDate: "2018-08-09 18:13:12", TutorialState: -1,