Implement session module

Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
2025-08-15 19:24:36 +08:00
parent 985895a780
commit 80a686849f
29 changed files with 837 additions and 694 deletions
+14 -12
View File
@@ -1,10 +1,9 @@
package handler package handler
import ( import (
"encoding/json"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/session"
"honoka-chan/internal/utils" "honoka-chan/internal/utils"
"net/http"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -15,16 +14,22 @@ type AlbumRes struct {
} }
func AlbumSeriesAll(ctx *gin.Context) { func AlbumSeriesAll(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
var albumIds []int var albumIds []int
err := MainEng.Table("album_series_m").Select("album_series_id").Find(&albumIds) err := ss.MainEng.Table("album_series_m").Select("album_series_id").Find(&albumIds)
utils.CheckErr(err) if ss.CheckErr(err) {
// fmt.Println(albumIds) return
}
albumSeriesAllRes := []model.AlbumSeriesRes{} albumSeriesAllRes := []model.AlbumSeriesRes{}
for _, albumId := range albumIds { for _, albumId := range albumIds {
unitList := []AlbumRes{} unitList := []AlbumRes{}
err = MainEng.Table("unit_m").Where("album_series_id = ?", albumId).Cols("unit_id,rarity").Find(&unitList) err = ss.MainEng.Table("unit_m").Where("album_series_id = ?", albumId).Cols("unit_id,rarity").Find(&unitList)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
albumSeriesAll := []model.AlbumResult{} albumSeriesAll := []model.AlbumResult{}
for _, unit := range unitList { for _, unit := range unitList {
@@ -70,14 +75,11 @@ func AlbumSeriesAll(ctx *gin.Context) {
}) })
} }
albumResp := model.AlbumSeriesResp{ resp := model.AlbumSeriesResp{
ResponseData: albumSeriesAllRes, ResponseData: albumSeriesAllRes,
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(albumResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(resp)
ctx.String(http.StatusOK, string(resp))
} }
+6 -7
View File
@@ -1,9 +1,8 @@
package handler package handler
import ( import (
"encoding/json"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/session"
"html/template" "html/template"
"net/http" "net/http"
"time" "time"
@@ -21,7 +20,10 @@ func AnnounceIndex(ctx *gin.Context) {
} }
func AnnounceCheckState(ctx *gin.Context) { func AnnounceCheckState(ctx *gin.Context) {
announceResp := model.AnnounceResp{ ss := session.New(ctx)
defer ss.Finalize()
resp := model.AnnounceResp{
ResponseData: model.AnnounceRes{ ResponseData: model.AnnounceRes{
HasUnreadAnnounce: false, HasUnreadAnnounce: false,
ServerTimestamp: time.Now().Unix(), ServerTimestamp: time.Now().Unix(),
@@ -29,9 +31,6 @@ func AnnounceCheckState(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(announceResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(resp)
ctx.String(http.StatusOK, string(resp))
} }
+254 -211
View File
@@ -2,10 +2,10 @@ package handler
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"honoka-chan/config" "honoka-chan/config"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/session"
"honoka-chan/internal/tools" "honoka-chan/internal/tools"
"honoka-chan/internal/utils" "honoka-chan/internal/utils"
honokautils "honoka-chan/pkg/utils" honokautils "honoka-chan/pkg/utils"
@@ -39,16 +39,17 @@ type MuseumRes struct {
} }
func Api(ctx *gin.Context) { func Api(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
apiReq := []model.ApiReq{} apiReq := []model.ApiReq{}
err := json.Unmarshal([]byte(ctx.GetString("request_data")), &apiReq) err := json.Unmarshal([]byte(ctx.GetString("request_data")), &apiReq)
if err != nil { if ss.CheckErr(err) {
fmt.Println(err)
return return
} }
results := []any{} results := []any{}
for _, v := range apiReq { for _, v := range apiReq {
var res []byte
var err error
// fmt.Println(v) // fmt.Println(v)
// fmt.Println(v.Module, v.Action) // fmt.Println(v.Module, v.Action)
@@ -90,8 +91,7 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(topInfoResp) results = append(results, topInfoResp)
utils.CheckErr(err)
case "topInfoOnce": case "topInfoOnce":
// key = "login_topinfo_once_result" // key = "login_topinfo_once_result"
topInfoOnceResp := model.TopInfoOnceResp{ topInfoOnceResp := model.TopInfoOnceResp{
@@ -122,8 +122,9 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(topInfoOnceResp) results = append(results, topInfoOnceResp)
utils.CheckErr(err) default:
err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "live": case "live":
switch v.Action { switch v.Action {
@@ -131,8 +132,10 @@ func Api(ctx *gin.Context) {
// key = "live_status_result" // key = "live_status_result"
var liveDifficultyId []int var liveDifficultyId []int
normalLives := []model.NormalLiveStatusList{} normalLives := []model.NormalLiveStatusList{}
err = MainEng.Table("normal_live_m").Cols("live_difficulty_id").OrderBy("live_difficulty_id ASC").Find(&liveDifficultyId) err = ss.MainEng.Table("normal_live_m").Cols("live_difficulty_id").OrderBy("live_difficulty_id ASC").Find(&liveDifficultyId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
for _, id := range liveDifficultyId { for _, id := range liveDifficultyId {
normalLive := model.NormalLiveStatusList{ normalLive := model.NormalLiveStatusList{
LiveDifficultyID: id, LiveDifficultyID: id,
@@ -146,8 +149,10 @@ func Api(ctx *gin.Context) {
} }
specialLives := []model.SpecialLiveStatusList{} specialLives := []model.SpecialLiveStatusList{}
err = MainEng.Table("special_live_m").Cols("live_difficulty_id").OrderBy("live_difficulty_id ASC").Find(&liveDifficultyId) err = ss.MainEng.Table("special_live_m").Cols("live_difficulty_id").OrderBy("live_difficulty_id ASC").Find(&liveDifficultyId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
for _, id := range liveDifficultyId { for _, id := range liveDifficultyId {
specialLive := model.SpecialLiveStatusList{ specialLive := model.SpecialLiveStatusList{
LiveDifficultyID: id, LiveDifficultyID: id,
@@ -173,14 +178,15 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(LiveStatusResp) results = append(results, LiveStatusResp)
utils.CheckErr(err)
case "schedule": case "schedule":
// key = "live_list_result" // key = "live_list_result"
var liveDifficultyId []int var liveDifficultyId []int
specialLives := []model.SpecialLiveStatusList{} specialLives := []model.SpecialLiveStatusList{}
err = MainEng.Table("special_live_m").Cols("live_difficulty_id").OrderBy("live_difficulty_id ASC").Find(&liveDifficultyId) err = ss.MainEng.Table("special_live_m").Cols("live_difficulty_id").OrderBy("live_difficulty_id ASC").Find(&liveDifficultyId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
for _, id := range liveDifficultyId { for _, id := range liveDifficultyId {
specialLive := model.SpecialLiveStatusList{ specialLive := model.SpecialLiveStatusList{
LiveDifficultyID: id, LiveDifficultyID: id,
@@ -216,24 +222,24 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(liveListResp) results = append(results, liveListResp)
utils.CheckErr(err)
default: default:
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "unit": case "unit":
if v.Action == "unitAll" { switch v.Action {
case "unitAll":
// key = "unit_list_result" // key = "unit_list_result"
unitsData := []model.Active{} unitsData := []model.Active{}
err = MainEng.Table("common_unit_m").Find(&unitsData) err = ss.MainEng.Table("common_unit_m").Find(&unitsData)
if err != nil { if ss.CheckErr(err) {
panic(err) return
} }
userUnits := []model.Active{} userUnits := []model.Active{}
err = UserEng.Table("user_unit_m").Where("user_id = ?", ctx.GetString("userid")).Find(&userUnits) err = ss.UserEng.Table("user_unit_m").Where("user_id = ?", ctx.GetString("userid")).Find(&userUnits)
if err != nil { if ss.CheckErr(err) {
panic(err) return
} }
unitsData = append(unitsData, userUnits...) unitsData = append(unitsData, userUnits...)
@@ -246,19 +252,22 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(unitListResp) results = append(results, unitListResp)
utils.CheckErr(err) case "deckInfo":
} else if v.Action == "deckInfo" {
// key = "unit_deck_result" // key = "unit_deck_result"
userDeck := []model.UserDeckData{} userDeck := []model.UserDeckData{}
err = UserEng.Table("user_deck_m").Where("user_id = ?", ctx.GetString("userid")).Asc("deck_id").Find(&userDeck) err = ss.UserEng.Table("user_deck_m").Where("user_id = ?", ctx.GetString("userid")).Asc("deck_id").Find(&userDeck)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
unitDeckInfo := []model.UnitDeckInfoRes{} unitDeckInfo := []model.UnitDeckInfoRes{}
for _, deck := range userDeck { for _, deck := range userDeck {
deckUnit := []model.UnitDeckData{} deckUnit := []model.UnitDeckData{}
err = UserEng.Table("deck_unit_m").Where("user_deck_id = ?", deck.ID).Asc("position").Find(&deckUnit) err = ss.UserEng.Table("deck_unit_m").Where("user_deck_id = ?", deck.ID).Asc("position").Find(&deckUnit)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
oUids := []model.UnitOwningUserIds{} oUids := []model.UnitOwningUserIds{}
for _, unit := range deckUnit { for _, unit := range deckUnit {
@@ -285,9 +294,8 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(unitDeckResp) results = append(results, unitDeckResp)
utils.CheckErr(err) case "supporterAll":
} else if v.Action == "supporterAll" {
// key = "unit_support_result" // key = "unit_support_result"
unitSupportResp := model.UnitSupportResp{ unitSupportResp := model.UnitSupportResp{
Result: model.UnitSupportRes{ Result: model.UnitSupportRes{
@@ -297,18 +305,21 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(unitSupportResp) results = append(results, unitSupportResp)
utils.CheckErr(err) case "removableSkillInfo":
} else if v.Action == "removableSkillInfo" {
// key = "owning_equip_result" // key = "owning_equip_result"
var skillEquipCount []model.SkillEquipCount var skillEquipCount []model.SkillEquipCount
err := UserEng.Table("skill_equip_m").Where("user_id = ?", ctx.GetString("userid")).Select("unit_removable_skill_id,COUNT(*) AS ct"). err := ss.UserEng.Table("skill_equip_m").Where("user_id = ?", ctx.GetString("userid")).Select("unit_removable_skill_id,COUNT(*) AS ct").
GroupBy("unit_removable_skill_id").Find(&skillEquipCount) GroupBy("unit_removable_skill_id").Find(&skillEquipCount)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
var rmSkillIds []int var rmSkillIds []int
err = MainEng.Table("unit_removable_skill_m").Where("effect_range = 1").Cols("unit_removable_skill_id").Find(&rmSkillIds) err = ss.MainEng.Table("unit_removable_skill_m").Where("effect_range = 1").Cols("unit_removable_skill_id").Find(&rmSkillIds)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
owingInfo := []model.OwningInfo{} owingInfo := []model.OwningInfo{}
for _, id := range rmSkillIds { for _, id := range rmSkillIds {
@@ -328,15 +339,19 @@ func Api(ctx *gin.Context) {
} }
var unitOwningIds []int var unitOwningIds []int
err = UserEng.Table("skill_equip_m").Where("user_id = ?", ctx.GetString("userid")).Cols("unit_owning_user_id").GroupBy("unit_owning_user_id").Find(&unitOwningIds) err = ss.UserEng.Table("skill_equip_m").Where("user_id = ?", ctx.GetString("userid")).Cols("unit_owning_user_id").GroupBy("unit_owning_user_id").Find(&unitOwningIds)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
equipInfo := map[int]any{} equipInfo := map[int]any{}
for _, v := range unitOwningIds { for _, v := range unitOwningIds {
detail := []model.SkillEquipDetail{} detail := []model.SkillEquipDetail{}
err = UserEng.Table("skill_equip_m").Where("user_id = ? AND unit_owning_user_id = ?", ctx.GetString("userid"), v). err = ss.UserEng.Table("skill_equip_m").Where("user_id = ? AND unit_owning_user_id = ?", ctx.GetString("userid"), v).
Cols("unit_removable_skill_id").Find(&detail) Cols("unit_removable_skill_id").Find(&detail)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
equipInfo[v] = model.SkillEquipList{ equipInfo[v] = model.SkillEquipList{
UnitOwningUserID: v, UnitOwningUserID: v,
@@ -353,13 +368,14 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(rmSkillResp) results = append(results, rmSkillResp)
utils.CheckErr(err) case "accessoryAll":
} else if v.Action == "accessoryAll" {
// key = "unit_accessory_result" // key = "unit_accessory_result"
accessoryList := []model.AccessoryList{} accessoryList := []model.AccessoryList{}
err := MainEng.Table("common_accessory_m").Find(&accessoryList) err := ss.MainEng.Table("common_accessory_m").Find(&accessoryList)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
for k := range accessoryList { for k := range accessoryList {
accessoryList[k].NextExp = 0 accessoryList[k].NextExp = 0
accessoryList[k].Level = 8 accessoryList[k].Level = 8
@@ -368,8 +384,10 @@ func Api(ctx *gin.Context) {
accessoryList[k].FavoriteFlag = true accessoryList[k].FavoriteFlag = true
} }
wearingInfo := []model.WearingInfo{} wearingInfo := []model.WearingInfo{}
err = UserEng.Table("accessory_wear_m").Where("user_id = ?", ctx.GetString("userid")).Find(&wearingInfo) err = ss.UserEng.Table("accessory_wear_m").Where("user_id = ?", ctx.GetString("userid")).Find(&wearingInfo)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
unitAccResp := model.UnitAccessoryAllResp{ unitAccResp := model.UnitAccessoryAllResp{
Result: model.UnitAccessoryAllResult{ Result: model.UnitAccessoryAllResult{
AccessoryList: accessoryList, AccessoryList: accessoryList,
@@ -380,12 +398,9 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(unitAccResp) results = append(results, unitAccResp)
utils.CheckErr(err) default:
} else { err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
// case "accessoryTab":
// case "accessoryMaterialAll":
fmt.Println("Invalid action: ", v.Module, v.Action)
} }
case "costume": case "costume":
if v.Action == "costumeList" { if v.Action == "costumeList" {
@@ -398,18 +413,20 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(costumeListResp) results = append(results, costumeListResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "album": case "album":
if v.Action == "albumAll" { if v.Action == "albumAll" {
// key = "album_unit_result" // key = "album_unit_result"
albumLists := []model.AlbumResult{} albumLists := []model.AlbumResult{}
unitList := []AlbumRes{} unitList := []AlbumRes{}
err = MainEng.Table("unit_m").Cols("unit_id,rarity").OrderBy("unit_id ASC").Find(&unitList) err = ss.MainEng.Table("unit_m").Cols("unit_id,rarity").OrderBy("unit_id ASC").Find(&unitList)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
for _, unit := range unitList { for _, unit := range unitList {
albumList := model.AlbumResult{ albumList := model.AlbumResult{
RankMaxFlag: true, RankMaxFlag: true,
@@ -451,18 +468,20 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(albumResp) results = append(results, albumResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "scenario": case "scenario":
if v.Action == "scenarioStatus" { if v.Action == "scenarioStatus" {
// key = "scenario_status_result" // key = "scenario_status_result"
var scenarioIds []int var scenarioIds []int
scenarioLists := []model.ScenarioStatusList{} scenarioLists := []model.ScenarioStatusList{}
err = MainEng.Table("scenario_m").Cols("scenario_id").OrderBy("scenario_id ASC").Find(&scenarioIds) err = ss.MainEng.Table("scenario_m").Cols("scenario_id").OrderBy("scenario_id ASC").Find(&scenarioIds)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
for _, id := range scenarioIds { for _, id := range scenarioIds {
scenarioLists = append(scenarioLists, model.ScenarioStatusList{ scenarioLists = append(scenarioLists, model.ScenarioStatusList{
ScenarioID: id, ScenarioID: id,
@@ -477,18 +496,20 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(scenarioResp) results = append(results, scenarioResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "subscenario": case "subscenario":
if v.Action == "subscenarioStatus" { if v.Action == "subscenarioStatus" {
// key = "subscenario_status_result" // key = "subscenario_status_result"
var subScenarioIds []int var subScenarioIds []int
subScenarioLists := []model.SubscenarioStatusList{} subScenarioLists := []model.SubscenarioStatusList{}
err = MainEng.Table("subscenario_m").Cols("subscenario_id").OrderBy("subscenario_id ASC").Find(&subScenarioIds) err = ss.MainEng.Table("subscenario_m").Cols("subscenario_id").OrderBy("subscenario_id ASC").Find(&subScenarioIds)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
for _, id := range subScenarioIds { for _, id := range subScenarioIds {
subScenarioLists = append(subScenarioLists, model.SubscenarioStatusList{ subScenarioLists = append(subScenarioLists, model.SubscenarioStatusList{
SubscenarioID: id, SubscenarioID: id,
@@ -504,24 +525,29 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(subScenarioResp) results = append(results, subScenarioResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "eventscenario": case "eventscenario":
if v.Action == "status" { if v.Action == "status" {
// key = "event_scenario_result" // key = "event_scenario_result"
var eventIds []int var eventIds []int
eventsList := []model.EventScenarioList{} eventsList := []model.EventScenarioList{}
err = MainEng.Table("event_scenario_m").Cols("event_id").GroupBy("event_id").OrderBy("event_id DESC").Find(&eventIds) err = ss.MainEng.Table("event_scenario_m").Cols("event_id").GroupBy("event_id").OrderBy("event_id DESC").Find(&eventIds)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
for _, id := range eventIds { for _, id := range eventIds {
eventRes := []EventRes{} eventRes := []EventRes{}
chapsList := []model.EventScenarioChapterList{} chapsList := []model.EventScenarioChapterList{}
err = MainEng.Table("event_scenario_m").Where("event_id = ?", id).Cols("event_scenario_id,chapter,chapter_asset,open_date"). err = ss.MainEng.Table("event_scenario_m").Where("event_id = ?", id).Cols("event_scenario_id,chapter,chapter_asset,open_date").
OrderBy("chapter DESC").Find(&eventRes) OrderBy("chapter DESC").Find(&eventRes)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
for _, res := range eventRes { for _, res := range eventRes {
chapList := model.EventScenarioChapterList{ chapList := model.EventScenarioChapterList{
EventScenarioID: res.EventScenarioId, EventScenarioID: res.EventScenarioId,
@@ -563,25 +589,29 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(eventScenarioResp) results = append(results, eventScenarioResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "multiunit": case "multiunit":
if v.Action == "multiunitscenarioStatus" { if v.Action == "multiunitscenarioStatus" {
// key = "multi_unit_scenario_result" // key = "multi_unit_scenario_result"
var multiIds []int var multiIds []int
multiUnitsList := []model.MultiUnitScenarioStatusList{} multiUnitsList := []model.MultiUnitScenarioStatusList{}
err = MainEng.Table("multi_unit_scenario_m").Cols("multi_unit_id").GroupBy("multi_unit_id").OrderBy("multi_unit_id ASC").Find(&multiIds) err = ss.MainEng.Table("multi_unit_scenario_m").Cols("multi_unit_id").GroupBy("multi_unit_id").OrderBy("multi_unit_id ASC").Find(&multiIds)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
for _, id := range multiIds { for _, id := range multiIds {
multiRes := MultiRes{} multiRes := MultiRes{}
_, err = MainEng.Table("multi_unit_scenario_m"). _, err = ss.MainEng.Table("multi_unit_scenario_m").
Join("LEFT", "multi_unit_scenario_open_m", "multi_unit_scenario_m.multi_unit_id = multi_unit_scenario_open_m.multi_unit_id"). Join("LEFT", "multi_unit_scenario_open_m", "multi_unit_scenario_m.multi_unit_id = multi_unit_scenario_open_m.multi_unit_id").
Cols("multi_unit_scenario_btn_asset,open_date,multi_unit_scenario_id,chapter"). Cols("multi_unit_scenario_btn_asset,open_date,multi_unit_scenario_id,chapter").
Where("multi_unit_scenario_m.multi_unit_id = ?", id).Get(&multiRes) Where("multi_unit_scenario_m.multi_unit_id = ?", id).Get(&multiRes)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
multiUnitsList = append(multiUnitsList, model.MultiUnitScenarioStatusList{ multiUnitsList = append(multiUnitsList, model.MultiUnitScenarioStatusList{
MultiUnitID: id, MultiUnitID: id,
@@ -606,10 +636,9 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(unitsResp) results = append(results, unitsResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "payment": case "payment":
if v.Action == "productList" { if v.Action == "productList" {
@@ -634,10 +663,9 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(productResp) results = append(results, productResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "banner": case "banner":
if v.Action == "bannerList" { if v.Action == "bannerList" {
@@ -707,10 +735,9 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(bannerResp) results = append(results, bannerResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "notice": case "notice":
if v.Action == "noticeMarquee" { if v.Action == "noticeMarquee" {
@@ -724,18 +751,20 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(marqueeResp) results = append(results, marqueeResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "user": case "user":
switch v.Action { switch v.Action {
case "getNavi": case "getNavi":
// key = "user_intro_result" // key = "user_intro_result"
var uId, oId int var uId, oId int
_, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Cols("user_id,unit_owning_user_id").Get(&uId, &oId) _, err := ss.UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Cols("user_id,unit_owning_user_id").Get(&uId, &oId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
userIntroResp := model.UserNaviResp{ userIntroResp := model.UserNaviResp{
Result: model.UserNaviRes{ Result: model.UserNaviRes{
User: model.User{ User: model.User{
@@ -747,15 +776,18 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(userIntroResp) results = append(results, userIntroResp)
utils.CheckErr(err)
case "userInfo": case "userInfo":
userId, err := strconv.Atoi(ctx.GetString("userid")) userId, err := strconv.Atoi(ctx.GetString("userid"))
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
pref := tools.UserPref{} pref := tools.UserPref{}
exists, err := UserEng.Table("user_preference_m").Where("user_id = ?", userId).Get(&pref) exists, err := ss.UserEng.Table("user_preference_m").Where("user_id = ?", userId).Get(&pref)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
if !exists { if !exists {
ctx.String(http.StatusForbidden, ErrorMsg) ctx.String(http.StatusForbidden, ErrorMsg)
return return
@@ -796,10 +828,9 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(userInfoResp) results = append(results, userInfoResp)
utils.CheckErr(err)
default: default:
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "navigation": case "navigation":
if v.Action == "specialCutin" { if v.Action == "specialCutin" {
@@ -812,20 +843,24 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(cutinResp) results = append(results, cutinResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "award": case "award":
if v.Action == "awardInfo" { if v.Action == "awardInfo" {
// key = "award_result" // key = "award_result"
var aIdList []int var aIdList []int
err := MainEng.Table("award_m").Cols("award_id").Find(&aIdList) err := ss.MainEng.Table("award_m").Cols("award_id").Find(&aIdList)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
var aId int var aId int
_, err = UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Cols("award_id").Get(&aId) _, err = ss.UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Cols("award_id").Get(&aId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
awardsList := []model.AwardInfo{} awardsList := []model.AwardInfo{}
for _, id := range aIdList { for _, id := range aIdList {
@@ -848,20 +883,24 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(awardResp) results = append(results, awardResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "background": case "background":
if v.Action == "backgroundInfo" { if v.Action == "backgroundInfo" {
// key = "background_result" // key = "background_result"
var bIdList []int var bIdList []int
err := MainEng.Table("background_m").Cols("background_id").Find(&bIdList) err := ss.MainEng.Table("background_m").Cols("background_id").Find(&bIdList)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
var bId int var bId int
_, err = UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Cols("background_id").Get(&bId) _, err = ss.UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Cols("background_id").Get(&bId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
backgroundsList := []model.BackgroundInfo{} backgroundsList := []model.BackgroundInfo{}
for _, id := range bIdList { for _, id := range bIdList {
@@ -884,10 +923,9 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(backgroundResp) results = append(results, backgroundResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "stamp": case "stamp":
if v.Action == "stampInfo" { if v.Action == "stampInfo" {
@@ -895,19 +933,23 @@ func Api(ctx *gin.Context) {
stampResp := honokautils.ReadAllText("assets/serverdata/stamp.json") stampResp := honokautils.ReadAllText("assets/serverdata/stamp.json")
var mStampResp any var mStampResp any
err = json.Unmarshal([]byte(stampResp), &mStampResp) err = json.Unmarshal([]byte(stampResp), &mStampResp)
utils.CheckErr(err) if ss.CheckErr(err) {
res, err = json.Marshal(mStampResp) return
utils.CheckErr(err) }
results = append(results, mStampResp)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "exchange": case "exchange":
if v.Action == "owningPoint" { if v.Action == "owningPoint" {
// key = "exchange_point_result" // key = "exchange_point_result"
var exchangeIds []int var exchangeIds []int
exPointsList := []model.ExchangePointList{} exPointsList := []model.ExchangePointList{}
err = MainEng.Table("exchange_point_m").Cols("exchange_point_id").OrderBy("exchange_point_id ASC").Find(&exchangeIds) err = ss.MainEng.Table("exchange_point_m").Cols("exchange_point_id").OrderBy("exchange_point_id ASC").Find(&exchangeIds)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
for _, id := range exchangeIds { for _, id := range exchangeIds {
exPointsList = append(exPointsList, model.ExchangePointList{ exPointsList = append(exPointsList, model.ExchangePointList{
Rarity: id, Rarity: id,
@@ -922,10 +964,9 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(exPointsResp) results = append(results, exPointsResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "livese": case "livese":
if v.Action == "liveseInfo" { if v.Action == "liveseInfo" {
@@ -938,10 +979,9 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(liveSeResp) results = append(results, liveSeResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "liveicon": case "liveicon":
if v.Action == "liveiconInfo" { if v.Action == "liveiconInfo" {
@@ -954,10 +994,9 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(liveIconResp) results = append(results, liveIconResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "item": case "item":
if v.Action == "list" { if v.Action == "list" {
@@ -965,11 +1004,12 @@ func Api(ctx *gin.Context) {
itemResp := honokautils.ReadAllText("assets/serverdata/item.json") itemResp := honokautils.ReadAllText("assets/serverdata/item.json")
var mItemResp any var mItemResp any
err = json.Unmarshal([]byte(itemResp), &mItemResp) err = json.Unmarshal([]byte(itemResp), &mItemResp)
utils.CheckErr(err) if ss.CheckErr(err) {
res, err = json.Marshal(mItemResp) return
utils.CheckErr(err) }
results = append(results, mItemResp)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "marathon": case "marathon":
if v.Action == "marathonInfo" { if v.Action == "marathonInfo" {
@@ -980,10 +1020,9 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(marathonResp) results = append(results, marathonResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "challenge": case "challenge":
if v.Action == "challengeInfo" { if v.Action == "challengeInfo" {
@@ -994,10 +1033,9 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(challengeResp) results = append(results, challengeResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "museum": case "museum":
if v.Action == "info" { if v.Action == "info" {
@@ -1005,9 +1043,12 @@ func Api(ctx *gin.Context) {
museumRes := []MuseumRes{} museumRes := []MuseumRes{}
var museumIds []int var museumIds []int
var smileBuff, pureBuff, coolBuff int var smileBuff, pureBuff, coolBuff int
err = MainEng.Table("museum_contents_m").Cols("museum_contents_id,smile_buff,pure_buff,cool_buff"). err = ss.MainEng.Table("museum_contents_m").Cols("museum_contents_id,smile_buff,pure_buff,cool_buff").
OrderBy("museum_contents_id ASC").Find(&museumRes) OrderBy("museum_contents_id ASC").Find(&museumRes)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
for _, res := range museumRes { for _, res := range museumRes {
smileBuff += res.SmileBuff smileBuff += res.SmileBuff
pureBuff += res.PureBuff pureBuff += res.PureBuff
@@ -1029,10 +1070,9 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(museumInfoResp) results = append(results, museumInfoResp)
utils.CheckErr(err)
} else { } else {
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
} }
case "profile": case "profile":
switch v.Action { switch v.Action {
@@ -1065,45 +1105,57 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(difficultyResp) results = append(results, difficultyResp)
utils.CheckErr(err)
case "cardRanking": case "cardRanking":
// key = "profile_card_ranking_result" // key = "profile_card_ranking_result"
var result []any var result []any
love := honokautils.ReadAllText("assets/serverdata/love.json") love := honokautils.ReadAllText("assets/serverdata/love.json")
err := json.Unmarshal([]byte(love), &result) err := json.Unmarshal([]byte(love), &result)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
loveResp := model.LoveResp{ loveResp := model.LoveResp{
Result: result, Result: result,
Status: 200, Status: 200,
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(loveResp) results = append(results, loveResp)
utils.CheckErr(err)
case "profileInfo": case "profileInfo":
// key = "profile_info_result" // key = "profile_info_result"
pref := tools.UserPref{} pref := tools.UserPref{}
exists, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Get(&pref) exists, err := ss.UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Get(&pref)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
if !exists { if !exists {
ctx.String(http.StatusForbidden, ErrorMsg) ctx.String(http.StatusForbidden, ErrorMsg)
return return
} }
commonUnit, err := MainEng.Table("common_unit_m").Count() commonUnit, err := ss.MainEng.Table("common_unit_m").Count()
utils.CheckErr(err) if ss.CheckErr(err) {
userUnit, err := UserEng.Table("user_unit_m").Where("user_id = ?", ctx.GetString("userid")).Count() return
utils.CheckErr(err) }
userUnit, err := ss.UserEng.Table("user_unit_m").Where("user_id = ?", ctx.GetString("userid")).Count()
if ss.CheckErr(err) {
return
}
unitData := model.UnitData{} unitData := model.UnitData{}
exists, err = MainEng.Table("common_unit_m").Where("unit_owning_user_id = ?", pref.UnitOwningUserID).Get(&unitData) exists, err = ss.MainEng.Table("common_unit_m").Where("unit_owning_user_id = ?", pref.UnitOwningUserID).Get(&unitData)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
isCommon := true isCommon := true
if !exists { if !exists {
_, err = UserEng.Table("user_unit_m"). _, err = ss.UserEng.Table("user_unit_m").
Where("unit_owning_user_id = ? AND user_id = ?", pref.UnitOwningUserID, ctx.GetString("userid")).Get(&unitData) Where("unit_owning_user_id = ? AND user_id = ?", pref.UnitOwningUserID, ctx.GetString("userid")).Get(&unitData)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
isCommon = false isCommon = false
} }
@@ -1111,7 +1163,7 @@ func Api(ctx *gin.Context) {
var smileMax, pureMax, coolMax int var smileMax, pureMax, coolMax int
if isCommon { if isCommon {
// 公共卡片仅为100级属性 // 公共卡片仅为100级属性
_, err = MainEng.Table("unit_m").Where("unit_id = ?", unitData.UnitID). _, err = ss.MainEng.Table("unit_m").Where("unit_id = ?", unitData.UnitID).
Cols("attribute_id,hp_max,smile_max,pure_max,cool_max").Get(&attrId, &maxHp, &baseSmile, &basePure, &baseCool) Cols("attribute_id,hp_max,smile_max,pure_max,cool_max").Get(&attrId, &maxHp, &baseSmile, &basePure, &baseCool)
utils.CheckErr(err) utils.CheckErr(err)
@@ -1125,12 +1177,16 @@ func Api(ctx *gin.Context) {
} }
var accessoryOwningId, accessoryId, exp int var accessoryOwningId, accessoryId, exp int
_, err = UserEng.Table("accessory_wear_m").Where("unit_owning_user_id = ? AND user_id = ?", pref.UnitOwningUserID, ctx.GetString("userid")). _, err = ss.UserEng.Table("accessory_wear_m").Where("unit_owning_user_id = ? AND user_id = ?", pref.UnitOwningUserID, ctx.GetString("userid")).
Cols("accessory_owning_user_id").Get(&accessoryOwningId) Cols("accessory_owning_user_id").Get(&accessoryOwningId)
utils.CheckErr(err) if ss.CheckErr(err) {
_, err = MainEng.Table("common_accessory_m").Where("accessory_owning_user_id = ?", accessoryOwningId). return
}
_, err = ss.MainEng.Table("common_accessory_m").Where("accessory_owning_user_id = ?", accessoryOwningId).
Cols("accessory_id,exp").Get(&accessoryId, &exp) Cols("accessory_id,exp").Get(&accessoryId, &exp)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
accessoryInfo := model.AccessoryInfo{ accessoryInfo := model.AccessoryInfo{
AccessoryOwningUserID: accessoryOwningId, AccessoryOwningUserID: accessoryOwningId,
AccessoryID: accessoryId, AccessoryID: accessoryId,
@@ -1143,12 +1199,17 @@ func Api(ctx *gin.Context) {
} }
removeSkillIds := []int{} removeSkillIds := []int{}
err = UserEng.Table("skill_equip_m").Where("unit_owning_user_id = ? AND user_id = ?", pref.UnitOwningUserID, ctx.GetString("userid")). err = ss.UserEng.Table("skill_equip_m").Where("unit_owning_user_id = ? AND user_id = ?", pref.UnitOwningUserID, ctx.GetString("userid")).
Cols("unit_removable_skill_id").Find(&removeSkillIds) Cols("unit_removable_skill_id").Find(&removeSkillIds)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
userId, err := strconv.Atoi(config.Conf.UserPrefs.InviteCode) userId, err := strconv.Atoi(config.Conf.UserPrefs.InviteCode)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
profileResp := model.ProfileResp{ profileResp := model.ProfileResp{
Result: model.ProfileRes{ Result: model.ProfileRes{
UserInfo: model.ProfileUserInfo{ UserInfo: model.ProfileUserInfo{
@@ -1240,42 +1301,24 @@ func Api(ctx *gin.Context) {
CommandNum: false, CommandNum: false,
TimeStamp: time.Now().Unix(), TimeStamp: time.Now().Unix(),
} }
res, err = json.Marshal(profileResp) results = append(results, profileResp)
utils.CheckErr(err)
default: default:
fmt.Println("Invalid action: ", v.Module, v.Action) err = fmt.Errorf("unimplemented: %s", v.Module+":"+v.Action)
}
case "secretbox":
if v.Action == "all" {
res = []byte(honokautils.ReadAllText("111.json"))
// fmt.Println(apiReq)
} else {
fmt.Println("Invalid action: ", v.Module, v.Action)
} }
default: default:
// fmt.Println(ErrorMsg) err = fmt.Errorf("unimplemented: %s", v.Module)
// fmt.Println(v)
err = errors.New("invalid option")
utils.CheckErr(err)
} }
var result any
err = json.Unmarshal([]byte(res), &result)
utils.CheckErr(err)
results = append(results, result)
} }
// fmt.Println(results)
b, err := json.Marshal(results) if ss.CheckErr(err) {
utils.CheckErr(err) return
rp := model.ApiResp{ }
ResponseData: b,
apiResp := model.ApiResp{
ResponseData: results,
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
b, err = json.Marshal(rp)
utils.CheckErr(err)
// fmt.Println(string(b))
ctx.Header("X-Message-Sign", utils.GenXMS(b)) ss.Respond(apiResp)
ctx.String(http.StatusOK, string(b))
} }
+11 -9
View File
@@ -1,31 +1,33 @@
package handler package handler
import ( import (
"encoding/json"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/session"
"honoka-chan/internal/tools" "honoka-chan/internal/tools"
"honoka-chan/internal/utils"
"net/http"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
func AwardSet(ctx *gin.Context) { func AwardSet(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
req := gjson.Parse(ctx.PostForm("request_data")) req := gjson.Parse(ctx.PostForm("request_data"))
pref := tools.UserPref{ pref := tools.UserPref{
AwardID: int(req.Get("award_id").Int()), AwardID: int(req.Get("award_id").Int()),
} }
_, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref)
utils.CheckErr(err) _, err := ss.UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref)
if ss.CheckErr(err) {
return
}
awardResp := model.AwardSetResp{ awardResp := model.AwardSetResp{
ResponseData: []any{}, ResponseData: []any{},
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(awardResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(awardResp)
ctx.String(http.StatusOK, string(resp))
} }
+11 -9
View File
@@ -1,31 +1,33 @@
package handler package handler
import ( import (
"encoding/json"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/session"
"honoka-chan/internal/tools" "honoka-chan/internal/tools"
"honoka-chan/internal/utils"
"net/http"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
func BackgroundSet(ctx *gin.Context) { func BackgroundSet(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
req := gjson.Parse(ctx.PostForm("request_data")) req := gjson.Parse(ctx.PostForm("request_data"))
pref := tools.UserPref{ pref := tools.UserPref{
BackgroundID: int(req.Get("background_id").Int()), BackgroundID: int(req.Get("background_id").Int()),
} }
_, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref)
utils.CheckErr(err) _, err := ss.UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref)
if ss.CheckErr(err) {
return
}
backgroundResp := model.BackgroundSetResp{ backgroundResp := model.BackgroundSetResp{
ResponseData: []any{}, ResponseData: []any{},
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(backgroundResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(backgroundResp)
ctx.String(http.StatusOK, string(resp))
} }
+49 -35
View File
@@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"honoka-chan/config" "honoka-chan/config"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/session"
"io" "io"
"net/http" "net/http"
"strings" "strings"
@@ -21,18 +21,25 @@ type PkgInfo struct {
} }
func DownloadAdditional(ctx *gin.Context) { func DownloadAdditional(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
downloadReq := model.AdditionalReq{} downloadReq := model.AdditionalReq{}
if err := json.Unmarshal([]byte(ctx.GetString("request_data")), &downloadReq); err != nil { err := json.Unmarshal([]byte(ctx.GetString("request_data")), &downloadReq)
panic(err) if ss.CheckErr(err) {
return
} }
pkgList := []model.AdditionalRes{} pkgList := []model.AdditionalRes{}
if SifCdnServer != "" { if SifCdnServer != "" {
pkgType, pkgId := downloadReq.PackageType, downloadReq.PackageID pkgType, pkgId := downloadReq.PackageType, downloadReq.PackageID
var pkgInfo []PkgInfo var pkgInfo []PkgInfo
err := MainEng.Table("download_m").Where("pkg_type = ? AND pkg_id = ? AND pkg_os = ?", pkgType, pkgId, downloadReq.TargetOs). err := ss.MainEng.Table("download_m").Where("pkg_type = ? AND pkg_id = ? AND pkg_os = ?", pkgType, pkgId, downloadReq.TargetOs).
Cols("pkg_id,pkg_order,pkg_size"). Cols("pkg_id,pkg_order,pkg_size").
OrderBy("pkg_id ASC, pkg_order ASC").Find(&pkgInfo) OrderBy("pkg_id ASC, pkg_order ASC").Find(&pkgInfo)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
for _, pkg := range pkgInfo { for _, pkg := range pkgInfo {
pkgList = append(pkgList, model.AdditionalRes{ pkgList = append(pkgList, model.AdditionalRes{
@@ -47,26 +54,30 @@ func DownloadAdditional(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(addResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(addResp)
ctx.String(http.StatusOK, string(resp))
} }
func DownloadBatch(ctx *gin.Context) { func DownloadBatch(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
downloadReq := model.BatchReq{} downloadReq := model.BatchReq{}
if err := json.Unmarshal([]byte(ctx.GetString("request_data")), &downloadReq); err != nil { err := json.Unmarshal([]byte(ctx.GetString("request_data")), &downloadReq)
panic(err) if ss.CheckErr(err) {
return
} }
pkgList := []model.BatchRes{} pkgList := []model.BatchRes{}
if downloadReq.ClientVersion == config.PackageVersion && SifCdnServer != "" { if downloadReq.ClientVersion == config.PackageVersion && SifCdnServer != "" {
pkgType := downloadReq.PackageType pkgType := downloadReq.PackageType
var pkgInfo []PkgInfo var pkgInfo []PkgInfo
err := MainEng.Table("download_m").Where(builder.NotIn("pkg_id", downloadReq.ExcludedPackageIds)).Where("pkg_type = ? AND pkg_os = ?", pkgType, downloadReq.Os). err := ss.MainEng.Table("download_m").Where(builder.NotIn("pkg_id", downloadReq.ExcludedPackageIds)).Where("pkg_type = ? AND pkg_os = ?", pkgType, downloadReq.Os).
Cols("pkg_id,pkg_order,pkg_size"). Cols("pkg_id,pkg_order,pkg_size").
OrderBy("pkg_id ASC, pkg_order ASC").Find(&pkgInfo) OrderBy("pkg_id ASC, pkg_order ASC").Find(&pkgInfo)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
for _, pkg := range pkgInfo { for _, pkg := range pkgInfo {
pkgList = append(pkgList, model.BatchRes{ pkgList = append(pkgList, model.BatchRes{
@@ -81,26 +92,30 @@ func DownloadBatch(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(batchResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(batchResp)
ctx.String(http.StatusOK, string(resp))
} }
func DownloadUpdate(ctx *gin.Context) { func DownloadUpdate(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
downloadReq := model.UpdateReq{} downloadReq := model.UpdateReq{}
if err := json.Unmarshal([]byte(ctx.GetString("request_data")), &downloadReq); err != nil { err := json.Unmarshal([]byte(ctx.GetString("request_data")), &downloadReq)
panic(err) if ss.CheckErr(err) {
return
} }
pkgList := []model.UpdateRes{} pkgList := []model.UpdateRes{}
if downloadReq.ExternalVersion != config.PackageVersion && SifCdnServer != "" { if downloadReq.ExternalVersion != config.PackageVersion && SifCdnServer != "" {
pkgType := 99 pkgType := 99
var pkgInfo []PkgInfo var pkgInfo []PkgInfo
err := MainEng.Table("download_m").Where("pkg_type = ? AND pkg_os = ?", pkgType, downloadReq.TargetOs). err := ss.MainEng.Table("download_m").Where("pkg_type = ? AND pkg_os = ?", pkgType, downloadReq.TargetOs).
Cols("pkg_id,pkg_order,pkg_size"). Cols("pkg_id,pkg_order,pkg_size").
OrderBy("pkg_id ASC, pkg_order ASC").Find(&pkgInfo) OrderBy("pkg_id ASC, pkg_order ASC").Find(&pkgInfo)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
for _, pkg := range pkgInfo { for _, pkg := range pkgInfo {
pkgList = append(pkgList, model.UpdateRes{ pkgList = append(pkgList, model.UpdateRes{
@@ -130,20 +145,22 @@ func DownloadUpdate(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(updateResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(updateResp)
ctx.String(http.StatusOK, string(resp))
} }
func DownloadUrl(ctx *gin.Context) { func DownloadUrl(ctx *gin.Context) {
// Extract SQL: SELECT CAST(pkg_type AS TEXT) || '_' || CAST(pkg_id AS TEXT) || '_' || CAST(pkg_order AS TEXT) || '.zip' AS zip_name FROM download_m ORDER BY pkg_type ASC,pkg_id ASC, pkg_order ASC; // Extract SQL: SELECT CAST(pkg_type AS TEXT) || '_' || CAST(pkg_id AS TEXT) || '_' || CAST(pkg_order AS TEXT) || '.zip' AS zip_name FROM download_m ORDER BY pkg_type ASC,pkg_id ASC, pkg_order ASC;
// Extract Cmd: cat list.txt | while read line; do; unzip -o $line; done // Extract Cmd: cat list.txt | while read line; do; unzip -o $line; done
ss := session.New(ctx)
defer ss.Finalize()
downloadReq := model.UrlReq{} downloadReq := model.UrlReq{}
if err := json.Unmarshal([]byte(ctx.GetString("request_data")), &downloadReq); err != nil { err := json.Unmarshal([]byte(ctx.GetString("request_data")), &downloadReq)
panic(err) if ss.CheckErr(err) {
return
} }
urlList := []string{} urlList := []string{}
for _, v := range downloadReq.PathList { for _, v := range downloadReq.PathList {
urlList = append(urlList, fmt.Sprintf("%s/%s/extracted/%s", SifCdnServer, downloadReq.Os, strings.ReplaceAll(v, "\\", ""))) urlList = append(urlList, fmt.Sprintf("%s/%s/extracted/%s", SifCdnServer, downloadReq.Os, strings.ReplaceAll(v, "\\", "")))
@@ -155,22 +172,19 @@ func DownloadUrl(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(urlResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(urlResp)
ctx.String(http.StatusOK, string(resp))
} }
func DownloadEvent(ctx *gin.Context) { func DownloadEvent(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
eventResp := model.EventResp{ eventResp := model.EventResp{
ResponseData: []any{}, ResponseData: []any{},
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(eventResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(eventResp)
ctx.String(http.StatusOK, string(resp))
} }
+6 -8
View File
@@ -1,18 +1,19 @@
package handler package handler
import ( import (
"encoding/json"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/session"
"net/http"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func EventList(ctx *gin.Context) { func EventList(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
targets := []model.TargetList{} targets := []model.TargetList{}
for i := 0; i < 6; i++ { for i := range 6 {
targets = append(targets, model.TargetList{ targets = append(targets, model.TargetList{
Position: i + 1, Position: i + 1,
IsDisplayable: false, IsDisplayable: false,
@@ -26,9 +27,6 @@ func EventList(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(eventsResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(eventsResp)
ctx.String(http.StatusOK, string(resp))
} }
+5 -7
View File
@@ -1,16 +1,17 @@
package handler package handler
import ( import (
"encoding/json"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/session"
"net/http"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func Gdpr(ctx *gin.Context) { func Gdpr(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
gdprResp := model.GdprResp{ gdprResp := model.GdprResp{
ResponseData: model.GdprRes{ ResponseData: model.GdprRes{
EnableGdpr: true, EnableGdpr: true,
@@ -20,9 +21,6 @@ func Gdpr(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(gdprResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(gdprResp)
ctx.String(http.StatusOK, string(resp))
} }
-9
View File
@@ -2,22 +2,13 @@ package handler
import ( import (
"honoka-chan/config" "honoka-chan/config"
"honoka-chan/pkg/db"
"xorm.io/xorm"
) )
var ( var (
SifCdnServer string SifCdnServer string
AsCdnServer string
ErrorMsg = `{"code":20001,"message":""}` ErrorMsg = `{"code":20001,"message":""}`
MainEng *xorm.Engine
UserEng *xorm.Engine
) )
func init() { func init() {
SifCdnServer = config.Conf.Settings.SifCdnServer SifCdnServer = config.Conf.Settings.SifCdnServer
MainEng = db.MainEng
UserEng = db.UserEng
} }
+5 -8
View File
@@ -1,16 +1,17 @@
package handler package handler
import ( import (
"encoding/json"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/session"
"net/http"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func LBonusExecute(ctx *gin.Context) { func LBonusExecute(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
weeks := map[string]int{ weeks := map[string]int{
"Monday": 1, "Monday": 1,
"Tuesday": 2, "Tuesday": 2,
@@ -148,9 +149,5 @@ func LBonusExecute(ctx *gin.Context) {
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(LbRes) ss.Respond(LbRes)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp))
ctx.String(http.StatusOK, string(resp))
} }
+149 -80
View File
@@ -2,13 +2,13 @@ package handler
import ( import (
"encoding/json" "encoding/json"
"fmt"
"honoka-chan/config" "honoka-chan/config"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/session"
"honoka-chan/pkg/db" "honoka-chan/pkg/db"
honokautils "honoka-chan/pkg/utils" honokautils "honoka-chan/pkg/utils"
"math" "math"
"net/http"
"strconv" "strconv"
"time" "time"
@@ -17,34 +17,52 @@ import (
) )
func PartyList(ctx *gin.Context) { func PartyList(ctx *gin.Context) {
resp := honokautils.ReadAllText("assets/serverdata/partylist.json") ss := session.New(ctx)
defer ss.Finalize()
ctx.Header("X-Message-Sign", utils.GenXMS([]byte(resp))) data := honokautils.ReadAllText("assets/serverdata/partylist.json")
ctx.String(http.StatusOK, resp) var partyResp map[string]any
err := json.Unmarshal([]byte(data), &partyResp)
if ss.CheckErr(err) {
return
}
ss.Respond(partyResp)
} }
func PlayLive(ctx *gin.Context) { func PlayLive(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
playReq := model.PlayReq{} playReq := model.PlayReq{}
err := json.Unmarshal([]byte(ctx.GetString("request_data")), &playReq) err := json.Unmarshal([]byte(ctx.GetString("request_data")), &playReq)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
tDifficultyId := playReq.LiveDifficultyID tDifficultyId := playReq.LiveDifficultyID
difficultyId, err := strconv.Atoi(tDifficultyId) difficultyId, err := strconv.Atoi(tDifficultyId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
deckId := playReq.UnitDeckID deckId := playReq.UnitDeckID
// Save Deck Id for /live/reward // Save Deck Id for /live/reward
key := "live_deck_" + ctx.GetString("userid") key := "live_deck_" + ctx.GetString("userid")
err = db.DB.Set([]byte(key), []byte(strconv.Itoa(deckId))) err = db.DB.Set([]byte(key), []byte(strconv.Itoa(deckId)))
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
// Song type: normal / special // Song type: normal / special
// sqlite3 doesn't support FULL OUTER JOIN so use UNION ALL here. // sqlite3 doesn't support FULL OUTER JOIN so use UNION ALL here.
sql := `SELECT notes_setting_asset,c_rank_score,b_rank_score,a_rank_score,s_rank_score,ac_flag,swing_flag FROM live_setting_m WHERE live_setting_id IN (SELECT live_setting_id FROM normal_live_m WHERE live_difficulty_id = ? UNION ALL SELECT live_setting_id FROM special_live_m WHERE live_difficulty_id = ?)` sql := `SELECT notes_setting_asset,c_rank_score,b_rank_score,a_rank_score,s_rank_score,ac_flag,swing_flag FROM live_setting_m WHERE live_setting_id IN (SELECT live_setting_id FROM normal_live_m WHERE live_difficulty_id = ? UNION ALL SELECT live_setting_id FROM special_live_m WHERE live_difficulty_id = ?)`
var notes_setting_asset string var notes_setting_asset string
var c_rank_score, b_rank_score, a_rank_score, s_rank_score, ac_flag, swing_flag int var c_rank_score, b_rank_score, a_rank_score, s_rank_score, ac_flag, swing_flag int
err = MainEng.DB().QueryRow(sql, difficultyId, difficultyId).Scan(&notes_setting_asset, &c_rank_score, &b_rank_score, &a_rank_score, &s_rank_score, &ac_flag, &swing_flag) err = ss.MainEng.DB().QueryRow(sql, difficultyId, difficultyId).Scan(&notes_setting_asset, &c_rank_score, &b_rank_score, &a_rank_score, &s_rank_score, &ac_flag, &swing_flag)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
// fmt.Println(notes_setting_asset) // fmt.Println(notes_setting_asset)
// fmt.Println(c_rank_score, b_rank_score, a_rank_score, s_rank_score) // fmt.Println(c_rank_score, b_rank_score, a_rank_score, s_rank_score)
@@ -53,7 +71,9 @@ func PlayLive(ctx *gin.Context) {
// fmt.Println("./assets/notes/" + notes_setting_asset) // fmt.Println("./assets/notes/" + notes_setting_asset)
notes_list := honokautils.ReadAllText("./assets/serverdata/notes/" + notes_setting_asset) notes_list := honokautils.ReadAllText("./assets/serverdata/notes/" + notes_setting_asset)
err = json.Unmarshal([]byte(notes_list), &notes) err = json.Unmarshal([]byte(notes_list), &notes)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
ranks := []model.RankInfo{} ranks := []model.RankInfo{}
ranks = append(ranks, model.RankInfo{ ranks = append(ranks, model.RankInfo{
@@ -78,69 +98,88 @@ func PlayLive(ctx *gin.Context) {
RankMax: 0, RankMax: 0,
}) })
// UserEng.ShowSQL(true) // ss.UserEng.ShowSQL(true)
// MainEng.ShowSQL(true) // ss.MainEng.ShowSQL(true)
owningIdList := []int{} owningIdList := []int{}
err = UserEng.Table("deck_unit_m").Join("LEFT", "user_deck_m", "deck_unit_m.user_deck_id = user_deck_m.id"). err = ss.UserEng.Table("deck_unit_m").Join("LEFT", "user_deck_m", "deck_unit_m.user_deck_id = user_deck_m.id").
Where("user_id = ? AND deck_id = ?", ctx.GetString("userid"), deckId).Cols("unit_owning_user_id"). Where("user_id = ? AND deck_id = ?", ctx.GetString("userid"), deckId).Cols("unit_owning_user_id").
OrderBy("deck_unit_m.position ASC").Find(&owningIdList) OrderBy("deck_unit_m.position ASC").Find(&owningIdList)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
unitList := []model.UnitList{} unitList := []model.UnitList{}
var totalSmile, totalPure, totalCool, maxLove float64 var totalSmile, totalPure, totalCool, maxLove float64
var totalHp int var totalHp int
for _, owningId := range owningIdList { for _, owningId := range owningIdList {
var uId int var uId int
exists, err := MainEng.Table("common_unit_m").Where("unit_owning_user_id = ?", owningId).Cols("unit_id").Get(&uId) exists, err := ss.MainEng.Table("common_unit_m").Where("unit_owning_user_id = ?", owningId).Cols("unit_id").Get(&uId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
var maxHp, attrId, unitTypeId int var maxHp, attrId, unitTypeId int
var baseSmile, basePure, baseCool, smileMax, pureMax, coolMax float64 var baseSmile, basePure, baseCool, smileMax, pureMax, coolMax float64
if exists { if exists {
// 公共卡片仅为100级属性 // 公共卡片仅为100级属性
_, err = MainEng.Table("unit_m").Where("unit_id = ?", uId). _, err = ss.MainEng.Table("unit_m").Where("unit_id = ?", uId).
Join("LEFT", "unit_rarity_m", "unit_m.rarity = unit_rarity_m.rarity"). Join("LEFT", "unit_rarity_m", "unit_m.rarity = unit_rarity_m.rarity").
Cols("attribute_id,hp_max,smile_max,pure_max,cool_max,after_love_max,unit_type_id"). Cols("attribute_id,hp_max,smile_max,pure_max,cool_max,after_love_max,unit_type_id").
Get(&attrId, &maxHp, &baseSmile, &basePure, &baseCool, &maxLove, &unitTypeId) Get(&attrId, &maxHp, &baseSmile, &basePure, &baseCool, &maxLove, &unitTypeId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
} else { } else {
// 用户卡片暂时固定为满级350级 // 用户卡片暂时固定为满级350级
exists, err := UserEng.Table("user_unit_m").Where("unit_owning_user_id = ?", owningId).Cols("unit_id").Get(&uId) exists, err := ss.UserEng.Table("user_unit_m").Where("unit_owning_user_id = ?", owningId).Cols("unit_id").Get(&uId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
if exists { if exists {
// 卡片100级基础属性 // 卡片100级基础属性
_, err = MainEng.Table("unit_m").Where("unit_id = ?", uId). _, err = ss.MainEng.Table("unit_m").Where("unit_id = ?", uId).
Join("LEFT", "unit_rarity_m", "unit_m.rarity = unit_rarity_m.rarity"). Join("LEFT", "unit_rarity_m", "unit_m.rarity = unit_rarity_m.rarity").
Cols("attribute_id,hp_max,smile_max,pure_max,cool_max,after_love_max,unit_type_id"). Cols("attribute_id,hp_max,smile_max,pure_max,cool_max,after_love_max,unit_type_id").
Get(&attrId, &maxHp, &baseSmile, &basePure, &baseCool, &maxLove, &unitTypeId) Get(&attrId, &maxHp, &baseSmile, &basePure, &baseCool, &maxLove, &unitTypeId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
// 增量属性 // 增量属性
var diffSmile, diffPure, diffCool float64 var diffSmile, diffPure, diffCool float64
_, err = MainEng.Table("unit_level_limit_pattern_m").Where("unit_level_limit_id = 1 AND unit_level = 350"). _, err = ss.MainEng.Table("unit_level_limit_pattern_m").Where("unit_level_limit_id = 1 AND unit_level = 350").
Cols("smile_diff,pure_diff,cool_diff").Get(&diffSmile, &diffPure, &diffCool) Cols("smile_diff,pure_diff,cool_diff").Get(&diffSmile, &diffPure, &diffCool)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
// 更新卡片属性(注意这里是负数,要用减号) // 更新卡片属性(注意这里是负数,要用减号)
baseSmile -= diffSmile baseSmile -= diffSmile
basePure -= diffPure basePure -= diffPure
baseCool -= diffCool baseCool -= diffCool
} else { } else {
panic("no such unit") err = fmt.Errorf("no such unit owning id: %d", owningId)
}
if ss.CheckErr(err) {
return
} }
} }
// 饰品属性加成(满级) // 饰品属性加成(满级)
var accessoryOwningId int var accessoryOwningId int
_, err = UserEng.Table("accessory_wear_m").Where("unit_owning_user_id = ?", owningId). _, err = ss.UserEng.Table("accessory_wear_m").Where("unit_owning_user_id = ?", owningId).
Cols("accessory_owning_user_id").Get(&accessoryOwningId) Cols("accessory_owning_user_id").Get(&accessoryOwningId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
var smileAccessory, pureAccessory, coolAccessory float64 var smileAccessory, pureAccessory, coolAccessory float64
_, err = MainEng.Table("common_accessory_m").Join("LEFT", "accessory_m", "common_accessory_m.accessory_id = accessory_m.accessory_id"). _, err = ss.MainEng.Table("common_accessory_m").Join("LEFT", "accessory_m", "common_accessory_m.accessory_id = accessory_m.accessory_id").
Where("accessory_owning_user_id = ?", accessoryOwningId).Cols("smile_max,pure_max,cool_max"). Where("accessory_owning_user_id = ?", accessoryOwningId).Cols("smile_max,pure_max,cool_max").
Get(&smileAccessory, &pureAccessory, &coolAccessory) Get(&smileAccessory, &pureAccessory, &coolAccessory)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
// fmt.Println("基础属性:", baseSmile, basePure, baseCool) // fmt.Println("基础属性:", baseSmile, basePure, baseCool)
// 饰品属性加成(该加成会影响个宝等百分比宝石属性加成的计算,故先计算。) // 饰品属性加成(该加成会影响个宝等百分比宝石属性加成的计算,故先计算。)
@@ -152,8 +191,10 @@ func PlayLive(ctx *gin.Context) {
// 回忆画廊属性加成(该加成会影响个宝等百分比宝石属性加成的计算,故先计算。) // 回忆画廊属性加成(该加成会影响个宝等百分比宝石属性加成的计算,故先计算。)
var smileBuff, pureBuff, coolBuff float64 var smileBuff, pureBuff, coolBuff float64
_, err = MainEng.Table("museum_contents_m").Select("SUM(smile_buff),SUM(pure_buff),SUM(cool_buff)").Get(&smileBuff, &pureBuff, &coolBuff) _, err = ss.MainEng.Table("museum_contents_m").Select("SUM(smile_buff),SUM(pure_buff),SUM(cool_buff)").Get(&smileBuff, &pureBuff, &coolBuff)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
baseSmile += smileBuff baseSmile += smileBuff
basePure += pureBuff basePure += pureBuff
baseCool += coolBuff baseCool += coolBuff
@@ -180,18 +221,22 @@ func PlayLive(ctx *gin.Context) {
// 宝石加成(满级) // 宝石加成(满级)
removableSkillIds := []int{} removableSkillIds := []int{}
err = UserEng.Table("skill_equip_m").Where("unit_owning_user_id = ? AND user_id = ?", owningId, ctx.GetString("userid")). err = ss.UserEng.Table("skill_equip_m").Where("unit_owning_user_id = ? AND user_id = ?", owningId, ctx.GetString("userid")).
Cols("unit_removable_skill_id").Find(&removableSkillIds) Cols("unit_removable_skill_id").Find(&removableSkillIds)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
for _, sk := range removableSkillIds { for _, sk := range removableSkillIds {
// 判断宝石效果类型(效果范围、效果类型、效果值、是否固定数值) // 判断宝石效果类型(效果范围、效果类型、效果值、是否固定数值)
var effectRange, effectType, fixedValueFlag, refType int var effectRange, effectType, fixedValueFlag, refType int
var effectValue float64 var effectValue float64
_, err = MainEng.Table("unit_removable_skill_m").Where("unit_removable_skill_id = ?", sk). _, err = ss.MainEng.Table("unit_removable_skill_m").Where("unit_removable_skill_id = ?", sk).
Cols("effect_range,effect_type,effect_value,fixed_value_flag,target_reference_type"). Cols("effect_range,effect_type,effect_value,fixed_value_flag,target_reference_type").
Get(&effectRange, &effectType, &effectValue, &fixedValueFlag, &refType) Get(&effectRange, &effectType, &effectValue, &fixedValueFlag, &refType)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
if fixedValueFlag == 1 { if fixedValueFlag == 1 {
// 吻、眼神属性加成(固定数值) // 吻、眼神属性加成(固定数值)
@@ -244,19 +289,23 @@ func PlayLive(ctx *gin.Context) {
// 主唱技能加成 // 主唱技能加成
var myCenterUnitId int var myCenterUnitId int
_, err = UserEng.Table("deck_unit_m").Join("LEFT", "user_deck_m", "deck_unit_m.user_deck_id = user_deck_m.id"). _, err = ss.UserEng.Table("deck_unit_m").Join("LEFT", "user_deck_m", "deck_unit_m.user_deck_id = user_deck_m.id").
Where("user_deck_m.deck_id = ? AND user_deck_m.user_id = ? AND deck_unit_m.position = 5", playReq.UnitDeckID, ctx.GetString("userid")). Where("user_deck_m.deck_id = ? AND user_deck_m.user_id = ? AND deck_unit_m.position = 5", playReq.UnitDeckID, ctx.GetString("userid")).
Cols("deck_unit_m.unit_id").Get(&myCenterUnitId) Cols("deck_unit_m.unit_id").Get(&myCenterUnitId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
// 主唱技能加成:主C技能(这里不使用新C技能,即以某属性的百分比提升另一属性) // 主唱技能加成:主C技能(这里不使用新C技能,即以某属性的百分比提升另一属性)
var myAttrId int var myAttrId int
var myEffectValue float64 var myEffectValue float64
_, err = MainEng.Table("unit_m"). _, err = ss.MainEng.Table("unit_m").
Join("LEFT", "unit_leader_skill_m", "unit_m.default_leader_skill_id = unit_leader_skill_m.unit_leader_skill_id"). Join("LEFT", "unit_leader_skill_m", "unit_m.default_leader_skill_id = unit_leader_skill_m.unit_leader_skill_id").
Where("unit_m.unit_id = ?", myCenterUnitId). Where("unit_m.unit_id = ?", myCenterUnitId).
Cols("unit_m.attribute_id,unit_leader_skill_m.effect_value").Get(&myAttrId, &myEffectValue) Cols("unit_m.attribute_id,unit_leader_skill_m.effect_value").Get(&myAttrId, &myEffectValue)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
var myCenterSmile, myCenterPure, myCenterCool float64 var myCenterSmile, myCenterPure, myCenterCool float64
switch myAttrId { switch myAttrId {
case 1: case 1:
@@ -271,15 +320,19 @@ func PlayLive(ctx *gin.Context) {
// 主唱技能加成:副C技能 // 主唱技能加成:副C技能
var mySubEffectValue float64 var mySubEffectValue float64
var myMemberTagId int var myMemberTagId int
_, err = MainEng.Table("unit_m"). _, err = ss.MainEng.Table("unit_m").
Join("LEFT", "unit_leader_skill_extra_m", "unit_m.default_leader_skill_id = unit_leader_skill_extra_m.unit_leader_skill_id"). Join("LEFT", "unit_leader_skill_extra_m", "unit_m.default_leader_skill_id = unit_leader_skill_extra_m.unit_leader_skill_id").
Where("unit_m.unit_id = ?", myCenterUnitId). Where("unit_m.unit_id = ?", myCenterUnitId).
Cols("unit_leader_skill_extra_m.effect_value,unit_leader_skill_extra_m.member_tag_id").Get(&mySubEffectValue, &myMemberTagId) Cols("unit_leader_skill_extra_m.effect_value,unit_leader_skill_extra_m.member_tag_id").Get(&mySubEffectValue, &myMemberTagId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
exists, err = MainEng.Table("unit_type_member_tag_m"). exists, err = ss.MainEng.Table("unit_type_member_tag_m").
Where("unit_type_id = ? AND member_tag_id = ?", unitTypeId, myMemberTagId).Exist() Where("unit_type_id = ? AND member_tag_id = ?", unitTypeId, myMemberTagId).Exist()
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
var mySubSmile, mySubPure, mySubCool float64 var mySubSmile, mySubPure, mySubCool float64
if exists { if exists {
switch myAttrId { switch myAttrId {
@@ -309,11 +362,13 @@ func PlayLive(ctx *gin.Context) {
// 好友主唱技能加成:主C技能(这里不使用新C技能,即以某属性的百分比提升另一属性) // 好友主唱技能加成:主C技能(这里不使用新C技能,即以某属性的百分比提升另一属性)
var tomoAttrId int var tomoAttrId int
var tomoEffectValue float64 var tomoEffectValue float64
_, err = MainEng.Table("unit_m"). _, err = ss.MainEng.Table("unit_m").
Join("LEFT", "unit_leader_skill_m", "unit_m.default_leader_skill_id = unit_leader_skill_m.unit_leader_skill_id"). Join("LEFT", "unit_leader_skill_m", "unit_m.default_leader_skill_id = unit_leader_skill_m.unit_leader_skill_id").
Where("unit_m.unit_id = ?", tomoUnitId). Where("unit_m.unit_id = ?", tomoUnitId).
Cols("unit_m.attribute_id,unit_leader_skill_m.effect_value").Get(&tomoAttrId, &tomoEffectValue) Cols("unit_m.attribute_id,unit_leader_skill_m.effect_value").Get(&tomoAttrId, &tomoEffectValue)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
var tomoCenterSmile, tomoCenterPure, tomoCenterCool float64 var tomoCenterSmile, tomoCenterPure, tomoCenterCool float64
switch myAttrId { switch myAttrId {
case 1: case 1:
@@ -328,15 +383,19 @@ func PlayLive(ctx *gin.Context) {
// 好友主唱技能加成:副C技能 // 好友主唱技能加成:副C技能
var tomoSubEffectValue float64 var tomoSubEffectValue float64
var tomoMemberTagId int var tomoMemberTagId int
_, err = MainEng.Table("unit_m"). _, err = ss.MainEng.Table("unit_m").
Join("LEFT", "unit_leader_skill_extra_m", "unit_m.default_leader_skill_id = unit_leader_skill_extra_m.unit_leader_skill_id"). Join("LEFT", "unit_leader_skill_extra_m", "unit_m.default_leader_skill_id = unit_leader_skill_extra_m.unit_leader_skill_id").
Where("unit_m.unit_id = ?", tomoUnitId). Where("unit_m.unit_id = ?", tomoUnitId).
Cols("unit_leader_skill_extra_m.effect_value,unit_leader_skill_extra_m.member_tag_id").Get(&tomoSubEffectValue, &tomoMemberTagId) Cols("unit_leader_skill_extra_m.effect_value,unit_leader_skill_extra_m.member_tag_id").Get(&tomoSubEffectValue, &tomoMemberTagId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
exists, err = MainEng.Table("unit_type_member_tag_m"). exists, err = ss.MainEng.Table("unit_type_member_tag_m").
Where("unit_type_id = ? AND member_tag_id = ?", unitTypeId, tomoMemberTagId).Exist() Where("unit_type_id = ? AND member_tag_id = ?", unitTypeId, tomoMemberTagId).Exist()
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
var tomoSubSmile, tomoSubPure, tomoSubCool float64 var tomoSubSmile, tomoSubPure, tomoSubCool float64
if exists { if exists {
switch myAttrId { switch myAttrId {
@@ -412,42 +471,47 @@ func PlayLive(ctx *gin.Context) {
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(playResp) ss.Respond(playResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp))
ctx.String(http.StatusOK, string(resp))
} }
func GameOver(ctx *gin.Context) { func GameOver(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
overResp := model.GameOverResp{ overResp := model.GameOverResp{
ResponseData: []any{}, ResponseData: []any{},
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(overResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(overResp)
ctx.String(http.StatusOK, string(resp))
} }
func PlayScore(ctx *gin.Context) { func PlayScore(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
playScoreReq := model.PlayScoreReq{} playScoreReq := model.PlayScoreReq{}
err := json.Unmarshal([]byte(ctx.GetString("request_data")), &playScoreReq) err := json.Unmarshal([]byte(ctx.GetString("request_data")), &playScoreReq)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
tDifficultyId := playScoreReq.LiveDifficultyID tDifficultyId := playScoreReq.LiveDifficultyID
difficultyId, err := strconv.Atoi(tDifficultyId) difficultyId, err := strconv.Atoi(tDifficultyId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
// Song type: normal / special // Song type: normal / special
// sqlite3 doesn't support FULL OUTER JOIN so use UNION ALL here. // sqlite3 doesn't support FULL OUTER JOIN so use UNION ALL here.
sql := `SELECT notes_setting_asset,c_rank_score,b_rank_score,a_rank_score,s_rank_score,ac_flag,swing_flag FROM live_setting_m WHERE live_setting_id IN (SELECT live_setting_id FROM normal_live_m WHERE live_difficulty_id = ? UNION ALL SELECT live_setting_id FROM special_live_m WHERE live_difficulty_id = ?)` sql := `SELECT notes_setting_asset,c_rank_score,b_rank_score,a_rank_score,s_rank_score,ac_flag,swing_flag FROM live_setting_m WHERE live_setting_id IN (SELECT live_setting_id FROM normal_live_m WHERE live_difficulty_id = ? UNION ALL SELECT live_setting_id FROM special_live_m WHERE live_difficulty_id = ?)`
var notes_setting_asset string var notes_setting_asset string
var c_rank_score, b_rank_score, a_rank_score, s_rank_score, ac_flag, swing_flag int var c_rank_score, b_rank_score, a_rank_score, s_rank_score, ac_flag, swing_flag int
err = MainEng.DB().QueryRow(sql, difficultyId, difficultyId).Scan(&notes_setting_asset, &c_rank_score, &b_rank_score, &a_rank_score, &s_rank_score, &ac_flag, &swing_flag) err = ss.MainEng.DB().QueryRow(sql, difficultyId, difficultyId).Scan(&notes_setting_asset, &c_rank_score, &b_rank_score, &a_rank_score, &s_rank_score, &ac_flag, &swing_flag)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
// fmt.Println(notes_setting_asset) // fmt.Println(notes_setting_asset)
// fmt.Println(c_rank_score, b_rank_score, a_rank_score, s_rank_score) // fmt.Println(c_rank_score, b_rank_score, a_rank_score, s_rank_score)
@@ -456,7 +520,9 @@ func PlayScore(ctx *gin.Context) {
// fmt.Println("./assets/notes/" + notes_setting_asset) // fmt.Println("./assets/notes/" + notes_setting_asset)
notes_list := honokautils.ReadAllText("./assets/serverdata/notes/" + notes_setting_asset) notes_list := honokautils.ReadAllText("./assets/serverdata/notes/" + notes_setting_asset)
err = json.Unmarshal([]byte(notes_list), &notes) err = json.Unmarshal([]byte(notes_list), &notes)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
ranks := []model.RankInfo{} ranks := []model.RankInfo{}
ranks = append(ranks, model.RankInfo{ ranks = append(ranks, model.RankInfo{
@@ -511,17 +577,18 @@ func PlayScore(ctx *gin.Context) {
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(playResp) ss.Respond(playResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp))
ctx.String(http.StatusOK, string(resp))
} }
func PlayReward(ctx *gin.Context) { func PlayReward(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
playRewardReq := model.PlayRewardReq{} playRewardReq := model.PlayRewardReq{}
err := json.Unmarshal([]byte(ctx.GetString("request_data")), &playRewardReq) err := json.Unmarshal([]byte(ctx.GetString("request_data")), &playRewardReq)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
difficultyId := playRewardReq.LiveDifficultyID difficultyId := playRewardReq.LiveDifficultyID
@@ -529,16 +596,22 @@ func PlayReward(ctx *gin.Context) {
// sqlite3 doesn't support FULL OUTER JOIN so use UNION ALL here. // sqlite3 doesn't support FULL OUTER JOIN so use UNION ALL here.
sql := `SELECT c_rank_score,b_rank_score,a_rank_score,s_rank_score,c_rank_combo,b_rank_combo,a_rank_combo,s_rank_combo,ac_flag,swing_flag FROM live_setting_m WHERE live_setting_id IN (SELECT live_setting_id FROM normal_live_m WHERE live_difficulty_id = ? UNION ALL SELECT live_setting_id FROM special_live_m WHERE live_difficulty_id = ?)` sql := `SELECT c_rank_score,b_rank_score,a_rank_score,s_rank_score,c_rank_combo,b_rank_combo,a_rank_combo,s_rank_combo,ac_flag,swing_flag FROM live_setting_m WHERE live_setting_id IN (SELECT live_setting_id FROM normal_live_m WHERE live_difficulty_id = ? UNION ALL SELECT live_setting_id FROM special_live_m WHERE live_difficulty_id = ?)`
var c_rank_score, b_rank_score, a_rank_score, s_rank_score, c_rank_combo, b_rank_combo, a_rank_combo, s_rank_combo, ac_flag, swing_flag int var c_rank_score, b_rank_score, a_rank_score, s_rank_score, c_rank_combo, b_rank_combo, a_rank_combo, s_rank_combo, ac_flag, swing_flag int
err = MainEng.DB().QueryRow(sql, difficultyId, difficultyId).Scan(&c_rank_score, &b_rank_score, &a_rank_score, &s_rank_score, &c_rank_combo, &b_rank_combo, &a_rank_combo, &s_rank_combo, &ac_flag, &swing_flag) err = ss.MainEng.DB().QueryRow(sql, difficultyId, difficultyId).Scan(&c_rank_score, &b_rank_score, &a_rank_score, &s_rank_score, &c_rank_combo, &b_rank_combo, &a_rank_combo, &s_rank_combo, &ac_flag, &swing_flag)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
key := "live_deck_" + ctx.GetString("userid") key := "live_deck_" + ctx.GetString("userid")
deckId, err := db.DB.Get([]byte(key)) deckId, err := db.DB.Get([]byte(key))
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
unitsList := []model.PlayRewardUnitList{} unitsList := []model.PlayRewardUnitList{}
err = UserEng.Table("deck_unit_m").Join("LEFT", "user_deck_m", "deck_unit_m.user_deck_id = user_deck_m.id"). err = ss.UserEng.Table("deck_unit_m").Join("LEFT", "user_deck_m", "deck_unit_m.user_deck_id = user_deck_m.id").
Where("user_id = ? AND deck_id = ?", ctx.GetString("userid"), string(deckId)).Find(&unitsList) Where("user_id = ? AND deck_id = ?", ctx.GetString("userid"), string(deckId)).Find(&unitsList)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
totalScore := playRewardReq.ScoreSmile + playRewardReq.ScoreCool + playRewardReq.ScoreCute totalScore := playRewardReq.ScoreSmile + playRewardReq.ScoreCool + playRewardReq.ScoreCute
playResp := model.RewardResp{ playResp := model.RewardResp{
@@ -692,9 +765,5 @@ func PlayReward(ctx *gin.Context) {
playResp.ResponseData.Rank = 5 playResp.ResponseData.Rank = 5
} }
resp, err := json.Marshal(playResp) ss.Respond(playResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp))
ctx.String(http.StatusOK, string(resp))
} }
+16 -14
View File
@@ -1,11 +1,9 @@
package handler package handler
import ( import (
"encoding/json"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/session"
"honoka-chan/pkg/db" "honoka-chan/pkg/db"
"net/http"
"strconv" "strconv"
"time" "time"
@@ -13,6 +11,9 @@ import (
) )
func AuthKey(ctx *gin.Context) { func AuthKey(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
authResp := model.AuthKeyResp{ authResp := model.AuthKeyResp{
ResponseData: model.AuthKeyRes{ ResponseData: model.AuthKeyRes{
AuthorizeToken: ctx.GetString("authorize_token"), AuthorizeToken: ctx.GetString("authorize_token"),
@@ -21,18 +22,20 @@ func AuthKey(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(authResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(authResp)
ctx.JSON(http.StatusOK, authResp)
} }
func Login(ctx *gin.Context) { func Login(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
loginKey := ctx.GetString("login_key") loginKey := ctx.GetString("login_key")
var userId int var userId int
exists, err := UserEng.Table("user_key").Where("key = ?", loginKey).Cols("userid").Get(&userId) exists, err := ss.UserEng.Table("user_key").Where("key = ?", loginKey).Cols("userid").Get(&userId)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
if !exists || userId == 0 { if !exists || userId == 0 {
userId = 9999999 userId = 9999999
@@ -40,7 +43,9 @@ func Login(ctx *gin.Context) {
ctx.Set("userid", userId) ctx.Set("userid", userId)
err = db.DB.Set([]byte(strconv.Itoa(userId)), []byte(ctx.GetString("authorize_token"))) err = db.DB.Set([]byte(strconv.Itoa(userId)), []byte(ctx.GetString("authorize_token")))
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
loginResp := model.LoginResp{ loginResp := model.LoginResp{
ResponseData: model.LoginRes{ ResponseData: model.LoginRes{
@@ -52,9 +57,6 @@ func Login(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(loginResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(loginResp)
ctx.JSON(http.StatusOK, loginResp)
} }
+8 -7
View File
@@ -3,17 +3,21 @@ package handler
import ( import (
"encoding/json" "encoding/json"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/session"
"net/http"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func MultiUnitStartUp(ctx *gin.Context) { func MultiUnitStartUp(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
startReq := model.MultiUnitStartUpReq{} startReq := model.MultiUnitStartUpReq{}
err := json.Unmarshal([]byte(ctx.PostForm("request_data")), &startReq) err := json.Unmarshal([]byte(ctx.PostForm("request_data")), &startReq)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
startResp := model.MultiUnitStartUpResp{ startResp := model.MultiUnitStartUpResp{
ResponseData: model.MultiUnitStartUpRes{ ResponseData: model.MultiUnitStartUpRes{
@@ -24,9 +28,6 @@ func MultiUnitStartUp(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(startResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(startResp)
ctx.String(http.StatusOK, string(resp))
} }
+10 -9
View File
@@ -1,10 +1,8 @@
package handler package handler
import ( import (
"encoding/json"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/session"
"net/http"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@@ -18,9 +16,15 @@ type MuseumContent struct {
} }
func MuseumInfo(ctx *gin.Context) { func MuseumInfo(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
var contents []MuseumContent var contents []MuseumContent
err := MainEng.Table("museum_contents_m").Cols("museum_contents_id,smile_buff,pure_buff,cool_buff").Find(&contents) err := ss.MainEng.Table("museum_contents_m").Cols("museum_contents_id,smile_buff,pure_buff,cool_buff").Find(&contents)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
var smileBuff, pureBuff, coolBuff int var smileBuff, pureBuff, coolBuff int
var contentsList []int var contentsList []int
for _, content := range contents { for _, content := range contents {
@@ -44,9 +48,6 @@ func MuseumInfo(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(museumResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(museumResp)
ctx.String(http.StatusOK, string(resp))
} }
+13 -15
View File
@@ -1,16 +1,17 @@
package handler package handler
import ( import (
"encoding/json"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/session"
"net/http"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func NoticeFriendVariety(ctx *gin.Context) { func NoticeFriendVariety(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
noticeResp := model.NoticeFriendVarietyResp{ noticeResp := model.NoticeFriendVarietyResp{
ResponseData: model.NoticeFriendVarietyRes{ ResponseData: model.NoticeFriendVarietyRes{
ItemCount: 1, ItemCount: 1,
@@ -20,14 +21,14 @@ func NoticeFriendVariety(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(noticeResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(noticeResp)
ctx.String(http.StatusOK, string(resp))
} }
func NoticeFriendGreeting(ctx *gin.Context) { func NoticeFriendGreeting(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
noticeResp := model.NoticeFriendGreetingResp{ noticeResp := model.NoticeFriendGreetingResp{
ResponseData: model.NoticeFriendGreetingRes{ ResponseData: model.NoticeFriendGreetingRes{
NextId: 0, NextId: 0,
@@ -37,14 +38,14 @@ func NoticeFriendGreeting(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(noticeResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(noticeResp)
ctx.String(http.StatusOK, string(resp))
} }
func NoticeUserGreeting(ctx *gin.Context) { func NoticeUserGreeting(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
noticeResp := model.NoticeUserGreetingResp{ noticeResp := model.NoticeUserGreetingResp{
ResponseData: model.NoticeUserGreetingRes{ ResponseData: model.NoticeUserGreetingRes{
ItemCount: 0, ItemCount: 0,
@@ -55,9 +56,6 @@ func NoticeUserGreeting(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(noticeResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(noticeResp)
ctx.String(http.StatusOK, string(resp))
} }
+5 -7
View File
@@ -1,16 +1,17 @@
package handler package handler
import ( import (
"encoding/json"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/session"
"net/http"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func ProductList(ctx *gin.Context) { func ProductList(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
prodReesp := model.ProductResp{ prodReesp := model.ProductResp{
ResponseData: model.ProductRes{ ResponseData: model.ProductRes{
RestrictionInfo: model.RestrictionInfo{ RestrictionInfo: model.RestrictionInfo{
@@ -31,9 +32,6 @@ func ProductList(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(prodReesp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(prodReesp)
ctx.String(http.StatusOK, string(resp))
} }
+5 -7
View File
@@ -1,16 +1,17 @@
package handler package handler
import ( import (
"encoding/json"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/session"
"net/http"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func PersonalNotice(ctx *gin.Context) { func PersonalNotice(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
noticeResp := model.PersonalNoticeResp{ noticeResp := model.PersonalNoticeResp{
ResponseData: model.PersonalNoticeRes{ ResponseData: model.PersonalNoticeRes{
HasNotice: false, HasNotice: false,
@@ -23,9 +24,6 @@ func PersonalNotice(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(noticeResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(noticeResp)
ctx.String(http.StatusOK, string(resp))
} }
+4 -4
View File
@@ -224,7 +224,7 @@ func LoginAuto(ctx *gin.Context) {
} }
var userId, ticket string var userId, ticket string
_, err = UserEng.Table("users").Cols("userid,ticket").Where("autokey = ?", autoKey).Get(&userId, &ticket) _, err = db.UserEng.Table("users").Cols("userid,ticket").Where("autokey = ?", autoKey).Get(&userId, &ticket)
utils.CheckErr(err) utils.CheckErr(err)
var resp string var resp string
@@ -312,7 +312,7 @@ func AccountLogin(ctx *gin.Context) {
// "key" INTEGER // "key" INTEGER
// );` // );`
var pass, autoKey, ticket, userId string var pass, autoKey, ticket, userId string
_, err = UserEng.Table("users").Cols("password,autokey,ticket,userid").Where("phone = ?", phone). _, err = db.UserEng.Table("users").Cols("password,autokey,ticket,userid").Where("phone = ?", phone).
Get(&pass, &autoKey, &ticket, &userId) Get(&pass, &autoKey, &ticket, &userId)
utils.CheckErr(err) utils.CheckErr(err)
@@ -322,7 +322,7 @@ func AccountLogin(ctx *gin.Context) {
loginTime := time.Now().Unix() loginTime := time.Now().Unix()
if pass == "" { if pass == "" {
// 未注册 - 自动注册 // 未注册 - 自动注册
session := UserEng.NewSession() session := db.UserEng.NewSession()
defer session.Close() defer session.Close()
// 开始会话 // 开始会话
@@ -393,7 +393,7 @@ func AccountLogin(ctx *gin.Context) {
loginResp.Userid = userId // 实际登录用的账号 loginResp.Userid = userId // 实际登录用的账号
// 更新信息 // 更新信息
userStmt, err := UserEng.DB().Prepare("UPDATE users SET autokey=?,ticket=?,last_login_time=? WHERE userid=?") userStmt, err := db.UserEng.DB().Prepare("UPDATE users SET autokey=?,ticket=?,last_login_time=? WHERE userid=?")
utils.CheckErr(err) utils.CheckErr(err)
defer userStmt.Close() defer userStmt.Close()
+11 -9
View File
@@ -1,31 +1,33 @@
package handler package handler
import ( import (
"encoding/json"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/session"
"honoka-chan/internal/tools" "honoka-chan/internal/tools"
"honoka-chan/internal/utils"
"net/http"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
func ProfileRegister(ctx *gin.Context) { func ProfileRegister(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
req := gjson.Parse(ctx.PostForm("request_data")) req := gjson.Parse(ctx.PostForm("request_data"))
pref := tools.UserPref{ pref := tools.UserPref{
UserDesc: req.Get("introduction").String(), UserDesc: req.Get("introduction").String(),
} }
_, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref)
utils.CheckErr(err) _, err := ss.UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref)
if ss.CheckErr(err) {
return
}
profileResp := model.ProfileRegisterResp{ profileResp := model.ProfileRegisterResp{
ResponseData: []any{}, ResponseData: []any{},
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(profileResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(profileResp)
ctx.String(http.StatusOK, string(resp))
} }
+18 -19
View File
@@ -1,23 +1,24 @@
package handler package handler
import ( import (
"encoding/base64"
"encoding/json" "encoding/json"
"fmt"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/session"
"honoka-chan/pkg/encrypt"
honokautils "honoka-chan/pkg/utils" honokautils "honoka-chan/pkg/utils"
"net/http"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func ScenarioStartup(ctx *gin.Context) { func ScenarioStartup(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
startReq := model.ScenarioReq{} startReq := model.ScenarioReq{}
err := json.Unmarshal([]byte(ctx.PostForm("request_data")), &startReq) err := json.Unmarshal([]byte(ctx.PostForm("request_data")), &startReq)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
startResp := model.ScenarioResp{ startResp := model.ScenarioResp{
ResponseData: model.ScenarioRes{ ResponseData: model.ScenarioRes{
@@ -28,22 +29,20 @@ func ScenarioStartup(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(startResp)
utils.CheckErr(err)
nonce := ctx.GetInt("nonce") ss.Respond(startResp)
nonce++
ctx.Header("user_id", ctx.GetString("userid"))
ctx.Header("authorize", fmt.Sprintf("consumerKey=lovelive_test&timeStamp=%d&version=1.1&token=%s&nonce=%d&user_id=%s&requestTimeStamp=%d", time.Now().Unix(), ctx.GetString("token"), nonce, ctx.GetString("userid"), ctx.GetInt64("req_time")))
ctx.Header("X-Message-Sign", base64.StdEncoding.EncodeToString(encrypt.RSASignSHA1(resp)))
ctx.String(http.StatusOK, string(resp))
} }
func ScenarioReward(ctx *gin.Context) { func ScenarioReward(ctx *gin.Context) {
resp := honokautils.ReadAllText("assets/serverdata/reward.json") ss := session.New(ctx)
defer ss.Finalize()
ctx.Header("X-Message-Sign", utils.GenXMS([]byte(resp))) data := honokautils.ReadAllText("assets/serverdata/reward.json")
ctx.String(http.StatusOK, resp) var resp map[string]any
err := json.Unmarshal([]byte(data), &resp)
if ss.CheckErr(err) {
return
}
ss.Respond(resp)
} }
+18 -19
View File
@@ -1,23 +1,24 @@
package handler package handler
import ( import (
"encoding/base64"
"encoding/json" "encoding/json"
"fmt"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/session"
"honoka-chan/pkg/encrypt"
honokautils "honoka-chan/pkg/utils" honokautils "honoka-chan/pkg/utils"
"net/http"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func SubScenarioStartup(ctx *gin.Context) { func SubScenarioStartup(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
startReq := model.SubScenarioReq{} startReq := model.SubScenarioReq{}
err := json.Unmarshal([]byte(ctx.PostForm("request_data")), &startReq) err := json.Unmarshal([]byte(ctx.PostForm("request_data")), &startReq)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
startResp := model.SubScenarioResp{ startResp := model.SubScenarioResp{
ResponseData: model.SubScenarioRes{ ResponseData: model.SubScenarioRes{
@@ -28,22 +29,20 @@ func SubScenarioStartup(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(startResp)
utils.CheckErr(err)
nonce := ctx.GetInt("nonce") ss.Respond(startResp)
nonce++
ctx.Header("user_id", ctx.GetString("userid"))
ctx.Header("authorize", fmt.Sprintf("consumerKey=lovelive_test&timeStamp=%d&version=1.1&token=%s&nonce=%d&user_id=%s&requestTimeStamp=%d", time.Now().Unix(), ctx.GetString("token"), nonce, ctx.GetString("userid"), ctx.GetInt64("req_time")))
ctx.Header("X-Message-Sign", base64.StdEncoding.EncodeToString(encrypt.RSASignSHA1(resp)))
ctx.String(http.StatusOK, string(resp))
} }
func SubScenarioReward(ctx *gin.Context) { func SubScenarioReward(ctx *gin.Context) {
resp := honokautils.ReadAllText("assets/serverdata/subreward.json") ss := session.New(ctx)
defer ss.Finalize()
ctx.Header("X-Message-Sign", utils.GenXMS([]byte(resp))) data := honokautils.ReadAllText("assets/serverdata/subreward.json")
ctx.String(http.StatusOK, resp) var resp map[string]any
err := json.Unmarshal([]byte(data), &resp)
if ss.CheckErr(err) {
return
}
ss.Respond(resp)
} }
+5 -7
View File
@@ -1,16 +1,17 @@
package handler package handler
import ( import (
"encoding/json"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/session"
"net/http"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func TosCheck(ctx *gin.Context) { func TosCheck(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
tosResp := model.TosResp{ tosResp := model.TosResp{
ResponseData: model.TosRes{ ResponseData: model.TosRes{
TosID: 1, TosID: 1,
@@ -21,9 +22,6 @@ func TosCheck(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(tosResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(tosResp)
ctx.String(http.StatusOK, string(resp))
} }
+100 -141
View File
@@ -2,9 +2,10 @@ package handler
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/session"
"net/http" "net/http"
"strconv" "strconv"
"time" "time"
@@ -13,56 +14,50 @@ import (
) )
func SetDisplayRank(ctx *gin.Context) { func SetDisplayRank(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
dispResp := model.SetDisplayRankResp{ dispResp := model.SetDisplayRankResp{
ResponseData: []any{}, ResponseData: []any{},
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(dispResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(dispResp)
ctx.String(http.StatusOK, string(resp))
} }
func SetDeck(ctx *gin.Context) { func SetDeck(ctx *gin.Context) {
userId, err := strconv.Atoi(ctx.GetString("userid")) ss := session.New(ctx)
utils.CheckErr(err) defer ss.Finalize()
deckReq := model.UnitDeckReq{} userId, err := strconv.Atoi(ctx.GetString("userid"))
if err := json.Unmarshal([]byte(ctx.PostForm("request_data")), &deckReq); err != nil { if ss.CheckErr(err) {
panic(err) return
} }
// 开始事务 deckReq := model.UnitDeckReq{}
// UserEng.ShowSQL(true) err = json.Unmarshal([]byte(ctx.PostForm("request_data")), &deckReq)
session := UserEng.NewSession() if ss.CheckErr(err) {
defer session.Close() return
if err := session.Begin(); err != nil {
session.Rollback()
panic(err)
} }
// 原有队伍信息 // 原有队伍信息
var userDeckId []int var userDeckId []int
err = session.Table("user_deck_m").Cols("id").Where("user_id = ?", userId).Find(&userDeckId) err = ss.UserEng.Table("user_deck_m").Cols("id").Where("user_id = ?", userId).Find(&userDeckId)
if err != nil { if ss.CheckErr(err) {
session.Rollback() return
panic(err)
} }
// 删除全部原有队伍成员 // 删除全部原有队伍成员
_, err = session.Table("deck_unit_m").In("user_deck_id", userDeckId).Delete() _, err = ss.UserEng.Table("deck_unit_m").In("user_deck_id", userDeckId).Delete()
if err != nil { if ss.CheckErr(err) {
session.Rollback() return
panic(err)
} }
// 删除全部原有队伍 // 删除全部原有队伍
_, err = session.Table("user_deck_m").In("id", userDeckId).Delete() _, err = ss.UserEng.Table("user_deck_m").In("id", userDeckId).Delete()
if err != nil { if ss.CheckErr(err) {
session.Rollback() return
panic(err)
} }
// 遍历新队伍 // 遍历新队伍
@@ -75,10 +70,9 @@ func SetDeck(ctx *gin.Context) {
UserID: userId, UserID: userId,
InsertDate: time.Now().Unix(), InsertDate: time.Now().Unix(),
} }
_, err = session.Table("user_deck_m").Insert(&userDeck) _, err = ss.UserEng.Table("user_deck_m").Insert(&userDeck)
if err != nil { if ss.CheckErr(err) {
session.Rollback() return
panic(err)
} }
userDeckId := userDeck.ID userDeckId := userDeck.ID
// fmt.Println("新队伍 ID:", userDeckId) // fmt.Println("新队伍 ID:", userDeckId)
@@ -87,35 +81,33 @@ func SetDeck(ctx *gin.Context) {
for _, unit := range deck.UnitDeckDetail { for _, unit := range deck.UnitDeckDetail {
// 成员信息 // 成员信息
newUnitData := model.UnitData{} newUnitData := model.UnitData{}
exists, err := session.Table("user_unit_m").Where("unit_owning_user_id = ?", unit.UnitOwningUserID).Exist() exists, err := ss.UserEng.Table("user_unit_m").Where("unit_owning_user_id = ?", unit.UnitOwningUserID).Exist()
if err != nil { if ss.CheckErr(err) {
session.Rollback() return
panic(err)
} }
if exists { if exists {
// fmt.Println("新成员为用户增加成员") // fmt.Println("新成员为用户增加成员")
_, err = session.Table("user_unit_m").Where("unit_owning_user_id = ?", unit.UnitOwningUserID).Get(&newUnitData) _, err = ss.UserEng.Table("user_unit_m").Where("unit_owning_user_id = ?", unit.UnitOwningUserID).Get(&newUnitData)
if err != nil { if ss.CheckErr(err) {
session.Rollback() return
panic(err)
} }
} else { } else {
exists, err := MainEng.Table("common_unit_m").Where("unit_owning_user_id = ?", unit.UnitOwningUserID).Exist() exists, err := ss.MainEng.Table("common_unit_m").Where("unit_owning_user_id = ?", unit.UnitOwningUserID).Exist()
if err != nil { if ss.CheckErr(err) {
session.Rollback() return
panic(err)
} }
if exists { if exists {
// fmt.Println("新成员为公共成员") // fmt.Println("新成员为公共成员")
_, err = MainEng.Table("common_unit_m").Where("unit_owning_user_id = ?", unit.UnitOwningUserID).Get(&newUnitData) _, err = ss.MainEng.Table("common_unit_m").Where("unit_owning_user_id = ?", unit.UnitOwningUserID).Get(&newUnitData)
if err != nil { if ss.CheckErr(err) {
session.Rollback() return
panic(err)
} }
} else { } else {
// fmt.Println("新成员不存在") // fmt.Println("新成员不存在")
session.Rollback() err = errors.New("新成员不存在")
panic("unexpected operation") }
if ss.CheckErr(err) {
return
} }
} }
// fmt.Println("新的成员信息:", newUnitData) // fmt.Println("新的成员信息:", newUnitData)
@@ -123,56 +115,53 @@ func SetDeck(ctx *gin.Context) {
// 插入新成员信息 // 插入新成员信息
newUnitDeckData := model.UnitDeckData{} newUnitDeckData := model.UnitDeckData{}
b, err := json.Marshal(newUnitData) b, err := json.Marshal(newUnitData)
if err != nil { if ss.CheckErr(err) {
session.Rollback() return
panic(err)
} }
if err = json.Unmarshal(b, &newUnitDeckData); err != nil { err = json.Unmarshal(b, &newUnitDeckData)
session.Rollback() if ss.CheckErr(err) {
panic(err) return
} }
newUnitDeckData.BeforeLove = newUnitDeckData.MaxLove newUnitDeckData.BeforeLove = newUnitDeckData.MaxLove
newUnitDeckData.Position = unit.Position newUnitDeckData.Position = unit.Position
newUnitDeckData.UserDeckID = userDeckId newUnitDeckData.UserDeckID = userDeckId
newUnitDeckData.InsertData = time.Now().Unix() newUnitDeckData.InsertData = time.Now().Unix()
_, err = session.Table("deck_unit_m").Insert(&newUnitDeckData) _, err = ss.UserEng.Table("deck_unit_m").Insert(&newUnitDeckData)
if err != nil { if ss.CheckErr(err) {
session.Rollback() return
panic(err)
} }
} }
} }
// 结束事务
if err = session.Commit(); err != nil {
session.Rollback()
panic(err)
}
dispResp := model.SetDeckResp{ dispResp := model.SetDeckResp{
ResponseData: []any{}, ResponseData: []any{},
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(dispResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(dispResp)
ctx.String(http.StatusOK, string(resp))
} }
func SetDeckName(ctx *gin.Context) { func SetDeckName(ctx *gin.Context) {
userId, err := strconv.Atoi(ctx.GetString("userid")) ss := session.New(ctx)
utils.CheckErr(err) defer ss.Finalize()
deckReq := model.DeckNameReq{} userId, err := strconv.Atoi(ctx.GetString("userid"))
if err := json.Unmarshal([]byte(ctx.PostForm("request_data")), &deckReq); err != nil { if ss.CheckErr(err) {
panic(err) return
} }
exists, err := UserEng.Table("user_deck_m").Where("user_id = ? AND deck_id = ?", userId, deckReq.UnitDeckID).Exist() deckReq := model.DeckNameReq{}
utils.CheckErr(err) err = json.Unmarshal([]byte(ctx.PostForm("request_data")), &deckReq)
if ss.CheckErr(err) {
return
}
exists, err := ss.UserEng.Table("user_deck_m").Where("user_id = ? AND deck_id = ?", userId, deckReq.UnitDeckID).Exist()
if ss.CheckErr(err) {
return
}
if !exists { if !exists {
ctx.String(http.StatusForbidden, ErrorMsg) ctx.String(http.StatusForbidden, ErrorMsg)
return return
@@ -180,49 +169,41 @@ func SetDeckName(ctx *gin.Context) {
userDeck := model.UserDeckData{ userDeck := model.UserDeckData{
DeckName: deckReq.DeckName, DeckName: deckReq.DeckName,
} }
_, err = UserEng.Table("user_deck_m").Update(&userDeck, &model.UserDeckData{ _, err = ss.UserEng.Table("user_deck_m").Update(&userDeck, &model.UserDeckData{
UserID: userId, UserID: userId,
DeckID: deckReq.UnitDeckID, DeckID: deckReq.UnitDeckID,
}) })
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
dispResp := model.SetDeckResp{ dispResp := model.SetDeckResp{
ResponseData: []any{}, ResponseData: []any{},
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(dispResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(dispResp)
ctx.String(http.StatusOK, string(resp))
} }
func WearAccessory(ctx *gin.Context) { func WearAccessory(ctx *gin.Context) {
fmt.Println(ctx.PostForm("request_data")) ss := session.New(ctx)
req := model.WearAccessoryReq{} defer ss.Finalize()
if err := json.Unmarshal([]byte(ctx.PostForm("request_data")), &req); err != nil {
panic(err)
}
// UserEng.ShowSQL(true) req := model.WearAccessoryReq{}
// 开始事务 err := json.Unmarshal([]byte(ctx.PostForm("request_data")), &req)
session := UserEng.NewSession() if ss.CheckErr(err) {
defer session.Close() return
if err := session.Begin(); err != nil {
session.Rollback()
panic(err)
} }
// 取下饰品 // 取下饰品
for _, v := range req.Remove { for _, v := range req.Remove {
fmt.Println("Remove:", v.AccessoryOwningUserID, v.UnitOwningUserID) fmt.Println("Remove:", v.AccessoryOwningUserID, v.UnitOwningUserID)
_, err := session.Table("accessory_wear_m"). _, err := ss.UserEng.Table("accessory_wear_m").
Where("accessory_owning_user_id = ? AND unit_owning_user_id = ? AND user_id = ?", v.AccessoryOwningUserID, v.UnitOwningUserID, ctx.GetString("userid")). Where("accessory_owning_user_id = ? AND unit_owning_user_id = ? AND user_id = ?", v.AccessoryOwningUserID, v.UnitOwningUserID, ctx.GetString("userid")).
Delete() Delete()
if err != nil { if ss.CheckErr(err) {
session.Rollback() return
panic(err)
} }
} }
@@ -234,14 +215,10 @@ func WearAccessory(ctx *gin.Context) {
UnitOwningUserID: v.UnitOwningUserID, UnitOwningUserID: v.UnitOwningUserID,
UserId: ctx.GetString("userid"), UserId: ctx.GetString("userid"),
} }
_, err := session.Table("accessory_wear_m").Insert(&data) _, err := ss.UserEng.Table("accessory_wear_m").Insert(&data)
utils.CheckErr(err) if ss.CheckErr(err) {
} return
}
// 结束事务
if err := session.Commit(); err != nil {
session.Rollback()
panic(err)
} }
wearResp := model.AwardSetResp{ wearResp := model.AwardSetResp{
@@ -249,38 +226,28 @@ func WearAccessory(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(wearResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(wearResp)
ctx.String(http.StatusOK, string(resp))
} }
func RemoveSkillEquip(ctx *gin.Context) { func RemoveSkillEquip(ctx *gin.Context) {
fmt.Println(ctx.PostForm("request_data")) ss := session.New(ctx)
req := model.SkillEquipReq{} defer ss.Finalize()
if err := json.Unmarshal([]byte(ctx.PostForm("request_data")), &req); err != nil {
panic(err)
}
// UserEng.ShowSQL(true) req := model.SkillEquipReq{}
// 开始事务 err := json.Unmarshal([]byte(ctx.PostForm("request_data")), &req)
session := UserEng.NewSession() if ss.CheckErr(err) {
defer session.Close() return
if err := session.Begin(); err != nil {
session.Rollback()
panic(err)
} }
// 取下宝石 // 取下宝石
for _, v := range req.Remove { for _, v := range req.Remove {
fmt.Println("Remove:", v.UnitOwningUserID, v.UnitRemovableSkillID) fmt.Println("Remove:", v.UnitOwningUserID, v.UnitRemovableSkillID)
_, err := session.Table("skill_equip_m"). _, err := ss.UserEng.Table("skill_equip_m").
Where("unit_removable_skill_id = ? AND unit_owning_user_id = ? AND user_id = ?", v.UnitRemovableSkillID, v.UnitOwningUserID, ctx.GetString("userid")). Where("unit_removable_skill_id = ? AND unit_owning_user_id = ? AND user_id = ?", v.UnitRemovableSkillID, v.UnitOwningUserID, ctx.GetString("userid")).
Delete() Delete()
if err != nil { if ss.CheckErr(err) {
session.Rollback() return
panic(err)
} }
} }
@@ -292,14 +259,10 @@ func RemoveSkillEquip(ctx *gin.Context) {
UnitOwningUserID: v.UnitOwningUserID, UnitOwningUserID: v.UnitOwningUserID,
UserId: ctx.GetString("userid"), UserId: ctx.GetString("userid"),
} }
_, err := session.Table("skill_equip_m").Insert(&data) _, err := ss.UserEng.Table("skill_equip_m").Insert(&data)
utils.CheckErr(err) if ss.CheckErr(err) {
} return
}
// 结束事务
if err := session.Commit(); err != nil {
session.Rollback()
panic(err)
} }
wearResp := model.AwardSetResp{ wearResp := model.AwardSetResp{
@@ -307,10 +270,6 @@ func RemoveSkillEquip(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(wearResp)
utils.CheckErr(err)
fmt.Println(string(resp))
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(wearResp)
ctx.String(http.StatusOK, string(resp))
} }
+26 -20
View File
@@ -1,10 +1,9 @@
package handler package handler
import ( import (
"encoding/json"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/session"
"honoka-chan/internal/tools" "honoka-chan/internal/tools"
"honoka-chan/internal/utils"
"net/http" "net/http"
"time" "time"
@@ -13,42 +12,50 @@ import (
) )
func SetNotificationToken(ctx *gin.Context) { func SetNotificationToken(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
notifResp := model.NotificationResp{ notifResp := model.NotificationResp{
ResponseData: []any{}, ResponseData: []any{},
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(notifResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(notifResp)
ctx.String(http.StatusOK, string(resp))
} }
func ChangeNavi(ctx *gin.Context) { func ChangeNavi(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
req := gjson.Parse(ctx.PostForm("request_data")) req := gjson.Parse(ctx.PostForm("request_data"))
pref := tools.UserPref{ pref := tools.UserPref{
UnitOwningUserID: int(req.Get("unit_owning_user_id").Int()), UnitOwningUserID: int(req.Get("unit_owning_user_id").Int()),
} }
_, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref) _, err := ss.UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
naviResp := model.UserNaviChangeResp{ naviResp := model.UserNaviChangeResp{
ResponseData: []any{}, ResponseData: []any{},
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(naviResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(naviResp)
ctx.String(http.StatusOK, string(resp))
} }
func ChangeName(ctx *gin.Context) { func ChangeName(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
req := gjson.Parse(ctx.PostForm("request_data")) req := gjson.Parse(ctx.PostForm("request_data"))
var oldName string var oldName string
exists, err := UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Cols("user_name").Get(&oldName) exists, err := ss.UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Cols("user_name").Get(&oldName)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
if !exists { if !exists {
ctx.String(http.StatusForbidden, ErrorMsg) ctx.String(http.StatusForbidden, ErrorMsg)
return return
@@ -56,8 +63,10 @@ func ChangeName(ctx *gin.Context) {
pref := tools.UserPref{ pref := tools.UserPref{
UserName: req.Get("name").String(), UserName: req.Get("name").String(),
} }
_, err = UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref) _, err = ss.UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
nameResp := model.UserNameChangeResp{ nameResp := model.UserNameChangeResp{
ResponseData: model.UserNameChangeRes{ ResponseData: model.UserNameChangeRes{
BeforeName: oldName, BeforeName: oldName,
@@ -67,9 +76,6 @@ func ChangeName(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(nameResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(nameResp)
ctx.String(http.StatusOK, string(resp))
} }
+12 -9
View File
@@ -1,11 +1,10 @@
package handler package handler
import ( import (
"encoding/json"
"honoka-chan/config" "honoka-chan/config"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/session"
"honoka-chan/internal/tools" "honoka-chan/internal/tools"
"honoka-chan/internal/utils"
"net/http" "net/http"
"strconv" "strconv"
"time" "time"
@@ -14,12 +13,19 @@ import (
) )
func UserInfo(ctx *gin.Context) { func UserInfo(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
userId, err := strconv.Atoi(ctx.GetString("userid")) userId, err := strconv.Atoi(ctx.GetString("userid"))
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
pref := tools.UserPref{} pref := tools.UserPref{}
exists, err := UserEng.Table("user_preference_m").Where("user_id = ?", userId).Get(&pref) exists, err := ss.UserEng.Table("user_preference_m").Where("user_id = ?", userId).Get(&pref)
utils.CheckErr(err) if ss.CheckErr(err) {
return
}
if !exists { if !exists {
ctx.String(http.StatusForbidden, ErrorMsg) ctx.String(http.StatusForbidden, ErrorMsg)
return return
@@ -66,9 +72,6 @@ func UserInfo(ctx *gin.Context) {
ReleaseInfo: []any{}, ReleaseInfo: []any{},
StatusCode: 200, StatusCode: 200,
} }
resp, err := json.Marshal(userResp)
utils.CheckErr(err)
ctx.Header("X-Message-Sign", utils.GenXMS(resp)) ss.Respond(userResp)
ctx.String(http.StatusOK, string(resp))
} }
+5 -4
View File
@@ -4,6 +4,7 @@ import (
"encoding/csv" "encoding/csv"
"honoka-chan/internal/model" "honoka-chan/internal/model"
"honoka-chan/internal/utils" "honoka-chan/internal/utils"
"honoka-chan/pkg/db"
"net/http" "net/http"
"os" "os"
"path" "path"
@@ -35,7 +36,7 @@ func WebLogin(ctx *gin.Context) {
userName := " " + area + "-" + user userName := " " + area + "-" + user
var userId int var userId int
exists, err := UserEng.Table("users").Where("phone = ? AND password = ?", userName, openssl.Md5ToString(pass)).Cols("userid").Get(&userId) exists, err := db.UserEng.Table("users").Where("phone = ? AND password = ?", userName, openssl.Md5ToString(pass)).Cols("userid").Get(&userId)
utils.CheckErr(err) utils.CheckErr(err)
if !exists { if !exists {
ctx.JSON(http.StatusOK, model.Msg{ ctx.JSON(http.StatusOK, model.Msg{
@@ -80,7 +81,7 @@ func Upload(ctx *gin.Context) {
err = ctx.SaveUploadedFile(file, tmpPath) err = ctx.SaveUploadedFile(file, tmpPath)
utils.CheckErr(err) utils.CheckErr(err)
session := UserEng.NewSession() session := db.UserEng.NewSession()
defer session.Close() defer session.Close()
if err = session.Begin(); err != nil { if err = session.Begin(); err != nil {
session.Rollback() session.Rollback()
@@ -113,7 +114,7 @@ func Upload(ctx *gin.Context) {
} }
var unitId, unitExp, unitRarity, unitHp, unitSigned int var unitId, unitExp, unitRarity, unitHp, unitSigned int
exists, err := MainEng.Table("common_unit_m").Join("LEFT", "unit_m", "common_unit_m.unit_id = unit_m.unit_id"). exists, err := db.MainEng.Table("common_unit_m").Join("LEFT", "unit_m", "common_unit_m.unit_id = unit_m.unit_id").
Where("unit_m.unit_number = ?", rr[0]). Where("unit_m.unit_number = ?", rr[0]).
Cols("common_unit_m.unit_id,common_unit_m.exp,unit_m.rarity,common_unit_m.max_hp,common_unit_m.is_signed"). Cols("common_unit_m.unit_id,common_unit_m.exp,unit_m.rarity,common_unit_m.max_hp,common_unit_m.is_signed").
Get(&unitId, &unitExp, &unitRarity, &unitHp, &unitSigned) Get(&unitId, &unitExp, &unitRarity, &unitHp, &unitSigned)
@@ -138,7 +139,7 @@ func Upload(ctx *gin.Context) {
} }
var diffExp, diffSmile, diffPure, diffCool int var diffExp, diffSmile, diffPure, diffCool int
_, err = MainEng.Table("unit_level_limit_pattern_m").Where("unit_level_limit_id = 1 AND unit_level = 350"). _, err = db.MainEng.Table("unit_level_limit_pattern_m").Where("unit_level_limit_id = 1 AND unit_level = 350").
Cols("next_exp,smile_diff,pure_diff,cool_diff").Get(&diffExp, &diffSmile, &diffPure, &diffCool) Cols("next_exp,smile_diff,pure_diff,cool_diff").Get(&diffExp, &diffSmile, &diffPure, &diffCool)
utils.CheckErr(err) utils.CheckErr(err)
+3 -5
View File
@@ -1,7 +1,5 @@
package model package model
import "encoding/json"
// ApiReq ... // ApiReq ...
type ApiReq struct { type ApiReq struct {
Module string `json:"module"` Module string `json:"module"`
@@ -11,9 +9,9 @@ type ApiReq struct {
// ApiResp ... // ApiResp ...
type ApiResp struct { type ApiResp struct {
ResponseData json.RawMessage `json:"response_data"` ResponseData any `json:"response_data"`
ReleaseInfo []any `json:"release_info"` ReleaseInfo any `json:"release_info"`
StatusCode int `json:"status_code"` StatusCode int `json:"status_code"`
} }
// ApiUserInfoResp ... // ApiUserInfoResp ...
+65
View File
@@ -0,0 +1,65 @@
package session
import (
"encoding/json"
"honoka-chan/internal/utils"
"honoka-chan/pkg/db"
"github.com/gin-gonic/gin"
"xorm.io/xorm"
)
type Session struct {
Ctx *gin.Context
MainEng *xorm.Session
UserEng *xorm.Session
}
func New(ctx *gin.Context) *Session {
ss := &Session{
Ctx: ctx,
}
ss.MainEng = db.MainEng.NewSession()
ss.UserEng = db.UserEng.NewSession()
ss.UserEng.Begin()
return ss
}
func (ss *Session) Finalize() {
ss.MainEng.Close()
ss.UserEng.Commit()
ss.UserEng.Close()
}
func (ss *Session) Abort(err error) {
ss.MainEng.Close()
ss.UserEng.Rollback()
ss.UserEng.Close()
ss.Ctx.JSON(500, gin.H{"error": err.Error()})
ss.Ctx.Abort()
}
func (ss *Session) CheckErr(err error) bool {
if err != nil {
ss.Abort(err)
return true
}
return false
}
func (ss *Session) Respond(resp any) {
data, err := json.Marshal(resp)
if err != nil {
ss.Abort(err)
return
}
ss.Ctx.Header("X-Message-Sign", utils.GenXMS(data))
ss.Ctx.String(200, string(data))
}
+3 -3
View File
@@ -70,7 +70,7 @@ func InitUserData(userId int) {
} }
_, err = session.Table("user_preference_m").Insert(&userPref) _, err = session.Table("user_preference_m").Insert(&userPref)
utils.CheckErr(err) utils.CheckErr(err)
fmt.Println("UserPref ID", userPref.ID) // fmt.Println("UserPref ID", userPref.ID)
} }
// 检查用户卡组配置 // 检查用户卡组配置
@@ -94,7 +94,7 @@ func InitUserData(userId int) {
panic(err) panic(err)
} }
userDeckId := userDeck.ID userDeckId := userDeck.ID
fmt.Println("New UserDeck:", userDeckId) // fmt.Println("New UserDeck:", userDeckId)
// 默认卡组 // 默认卡组
unitIds := []int{} unitIds := []int{}
@@ -137,7 +137,7 @@ func InitUserData(userId int) {
session.Rollback() session.Rollback()
panic(err) panic(err)
} }
fmt.Println("New DeckUnit:", unitDeckData.ID) // fmt.Println("New DeckUnit:", unitDeckData.ID)
position++ position++
} }