fixed lots of bugs

This commit is contained in:
2026-09-07 20:44:56 +08:00
parent 66235cf663
commit d0f0120271
30 changed files with 2442 additions and 212 deletions

View File

@@ -0,0 +1,64 @@
package album
import (
"bdgrp_go/master"
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"fmt"
"strconv"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Get(path, albumMap)
fmt.Println("Loaded:", path)
})
}
func albumMap(c *fiber.Ctx) error {
characterid, _ := strconv.Atoi(c.Params("characterid"))
m := master.GetMaster()
entries := map[string]any{}
if asm, ok := m["masterActionSetMap"].(map[string]any); ok {
for key, v := range asm["entries"].(map[string]any) {
item, ok := v.(map[string]any)
if !ok {
continue
}
charIds, ok := item["characterIds"].([]any)
if !ok {
continue
}
for _, cid := range charIds {
if int(cid.(float64)) == characterid {
entry := map[string]any{
"actionSetId": item["actionSetId"],
"balloonText": item["balloonText"],
}
if _, ok := item["endSeason"]; ok {
entry["isMemorial"] = true
}
entries[key] = entry
break
}
}
}
}
encoded, err := pbutil.Encode("UserActionSetAlbumMap", map[string]any{"entries": entries})
if err != nil {
return c.Status(500).SendString(err.Error())
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
return c.Status(500).SendString(err.Error())
}
return c.Send(encrypted)
}

View File

@@ -0,0 +1,51 @@
package genericanimation
import (
"bdgrp_go/master"
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Post(path, animation)
fmt.Println("Loaded:", path)
})
}
func animation(c *fiber.Ctx) error {
userid := c.Params("userid")
m := master.GetMaster()
entries := map[string]any{}
if gam, ok := m["masterGenericAnimationMap"].(map[string]any); ok {
for id := range gam["entries"].(map[string]any) {
entries[id] = map[string]any{
"userId": userid,
"genericAnimationId": id,
"status": "already_read",
}
}
}
data := map[string]any{
"userGenericAnimationMap": map[string]any{"entries": entries},
}
encoded, err := pbutil.Encode("SuiteUserGetResponse", data)
if err != nil {
return c.Status(500).SendString(err.Error())
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
return c.Status(500).SendString(err.Error())
}
return c.Send(encrypted)
}

View File

@@ -17,64 +17,23 @@ import (
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Get(path, handle)
app.Get(path, getMemorialStory)
fmt.Println("Loaded:", path)
})
}
func handle(c *fiber.Ctx) error {
func getMemorialStory(c *fiber.Ctx) error {
userid := c.Params("userid")
m := master.GetMaster()
server := os.Getenv("SERVER")
// 讀 pastEvents/{SERVER}.json
pastPath := filepath.Join("pastEvents", os.Getenv("SERVER")+".json")
pastData, err := os.ReadFile(pastPath)
if err != nil {
return c.Status(500).SendString("no past events")
}
pastData, _ := os.ReadFile(filepath.Join("pastEvents", server+".json"))
var past map[string]any
json.Unmarshal(pastData, &past)
// masterEventStoryMemorialConfigMap.entries
configMap := m["masterEventStoryMemorialConfigMap"].(map[string]any)
entries := configMap["entries"].(map[string]any)
// pastEventStoryMap.entries
pastStoryMap := past["pastEventStoryMap"].(map[string]any)
pastEntries := pastStoryMap["entries"].(map[string]any)
// Object.fromEntries(Object.entries(...).map(...))
resultEntries := map[string]any{}
for eventId := range entries {
// Array.from({ length: ... }, (_, i) => ...)
var storyList []any
if pastEvent, ok := pastEntries[eventId].(map[string]any); ok {
if innerEntries, ok := pastEvent["entries"].([]any); ok {
for i := range innerEntries {
storyList = append(storyList, map[string]any{
"userId": userid,
"eventId": eventId,
"seq": i,
"status": "already_read",
})
}
}
}
resultEntries[eventId] = map[string]any{
"eventId": eventId,
"userEventStoryList": map[string]any{
"entries": storyList,
},
"isExistUnReadStory": false,
"isLocked": false,
}
}
// 合併 past(等同 ...past)
data := map[string]any{
"userEventStoryMemorialMap": map[string]any{
"entries": resultEntries,
"entries": utils.BuildEventStoryMemorialMap(userid, m, past),
},
}
maps.Copy(data, past)
@@ -83,11 +42,9 @@ func handle(c *fiber.Ctx) error {
if err != nil {
return c.Status(500).SendString(err.Error())
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
return c.Status(500).SendString(err.Error())
}
return c.Send(encrypted)
}

View File

@@ -0,0 +1,99 @@
package profile
import (
"bdgrp_go/db"
"bdgrp_go/master"
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Put(path, profile)
fmt.Println("Loaded:", path)
})
}
func profile(c *fiber.Ctx) error {
userid := c.Params("usrid")
user := db.FindUser(userid)
m := master.GetMaster()
userSituations := utils.BuildUserSituations(userid, m, user)
situationMap := map[string]any{}
for _, sit := range userSituations {
s := sit.(map[string]any)
situationMap[fmt.Sprintf("%v", s["situationId"])] = s
}
decks := user["decks"].([]any)
mainDeckIdx := 1
if md, ok := user["mainDeck"].(float64); ok {
mainDeckIdx = int(md)
}
mainDeck := decks[mainDeckIdx-1].(map[string]any)
situationIdFields := []string{"leader", "member1", "member2", "member3", "member4"}
var mainDeckSituations []any
for _, field := range situationIdFields {
if sid, ok := mainDeck[field]; ok && sid != nil {
sidStr := fmt.Sprintf("%v", sid)
if s, ok := situationMap[sidStr]; ok {
mainDeckSituations = append(mainDeckSituations, s)
}
}
}
userProfileDegree := utils.BuildUserProfileDegree(userid, user)
musicScore, _ := user["musicScore"].(map[string]any)
data := map[string]any{
"userName": user["userName"],
"rank": user["rank"],
"degree": 100,
"introduction": user["introduction"],
"searchableFlg": true,
"publishUpdatedAtFlg": true,
"friendApplicableFlg": true,
"publishStageChallengeFriendRankingFlg": true,
"mainDeckUserSituations": map[string]any{"entries": mainDeckSituations},
"enabledUserAreaItems": map[string]any{},
"bandRankMap": map[string]any{"entries": utils.BandRankMap},
"userHighScoreRating": map[string]any{
"userPoppinPartyHighScoreMusicList": map[string]any{},
"userPastelPalettesHighScoreMusicList": map[string]any{},
"userRoseliaHighScoreMusicList": map[string]any{},
"userOtherHighScoreMusicList": map[string]any{},
"userMorfonicaHighScoreMusicList": map[string]any{},
"userRaiseASuilenHighScoreMusicList": map[string]any{},
"userMyGOScoreMusicList": map[string]any{},
},
"mainUserDeck": mainDeck,
"userProfileSituation": map[string]any{},
"userProfileDegreeMap": map[string]any{"entries": userProfileDegree},
"userTwitter": map[string]any{},
"userDeckTotalRatingMap": map[string]any{"entries": utils.DeckRatingMap},
"stageChallengeAchievementConditionsMap": map[string]any{},
"userMusicClearInfoMap": utils.ComputeMusicClearInfo(musicScore),
"userCharacterRankMap": utils.BuildCharacterRankMap(),
}
encoded, err := pbutil.Encode("UserProfile", data)
if err != nil {
fmt.Println(err)
return c.Status(500).SendString(err.Error())
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
fmt.Println(err)
return c.Status(500).SendString(err.Error())
}
return c.Send(encrypted)
}

View File

@@ -0,0 +1,109 @@
package search
import (
"bdgrp_go/db"
"bdgrp_go/master"
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Put(path, profileSearch)
fmt.Println("Loaded:", path)
})
}
func profileSearch(c *fiber.Ctx) error {
targetid := c.Params("targetid")
user := db.FindUser(targetid)
var data map[string]any
if user == nil {
data = map[string]any{"searchSuccessFlg": false}
} else {
m := master.GetMaster()
userid := fmt.Sprintf("%v", user["userId"])
userSituations := utils.BuildUserSituations(userid, m, user)
situationMap := map[string]any{}
for _, sit := range userSituations {
s := sit.(map[string]any)
situationMap[fmt.Sprintf("%v", s["situationId"])] = s
}
decks := user["decks"].([]any)
mainDeckIdx := 1
if md, ok := user["mainDeck"].(float64); ok {
mainDeckIdx = int(md)
}
mainDeck := decks[mainDeckIdx-1].(map[string]any)
situationIdFields := []string{"leader", "member1", "member2", "member3", "member4"}
var mainDeckSituations []any
for _, field := range situationIdFields {
if sid, ok := mainDeck[field]; ok && sid != nil {
sidStr := fmt.Sprintf("%v", sid)
if s, ok := situationMap[sidStr]; ok {
mainDeckSituations = append(mainDeckSituations, s)
}
}
}
userProfileDegree := utils.BuildUserProfileDegree(userid, user)
musicScore, _ := user["musicScore"].(map[string]any)
data = map[string]any{
"userProfile": map[string]any{
"userName": user["userName"],
"rank": user["rank"],
"degree": 100,
"introduction": user["introduction"],
"searchableFlg": true,
"publishUpdatedAtFlg": true,
"friendApplicableFlg": true,
"publishStageChallengeFriendRankingFlg": true,
"mainDeckUserSituations": map[string]any{"entries": mainDeckSituations},
"enabledUserAreaItems": map[string]any{},
"bandRankMap": map[string]any{"entries": utils.BandRankMap},
"userHighScoreRating": map[string]any{
"userPoppinPartyHighScoreMusicList": map[string]any{},
"userPastelPalettesHighScoreMusicList": map[string]any{},
"userRoseliaHighScoreMusicList": map[string]any{},
"userOtherHighScoreMusicList": map[string]any{},
"userMorfonicaHighScoreMusicList": map[string]any{},
"userRaiseASuilenHighScoreMusicList": map[string]any{},
"userMyGOScoreMusicList": map[string]any{},
},
"mainUserDeck": mainDeck,
"userProfileSituation": map[string]any{},
"userProfileDegreeMap": map[string]any{"entries": userProfileDegree},
"userTwitter": map[string]any{},
"userDeckTotalRatingMap": map[string]any{"entries": utils.DeckRatingMap},
"stageChallengeAchievementConditionsMap": map[string]any{},
"userMusicClearInfoMap": utils.ComputeMusicClearInfo(musicScore),
"userCharacterRankMap": utils.BuildCharacterRankMap(),
},
}
}
encoded, err := pbutil.Encode("UserProfileSearchResponse", data)
if err != nil {
fmt.Println(err)
return c.Status(500).SendString(err.Error())
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
fmt.Println(err)
return c.Status(500).SendString(err.Error())
}
return c.Send(encrypted)
}

View File

@@ -0,0 +1,112 @@
package illust
import (
"bdgrp_go/db"
"bdgrp_go/master"
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Put(path, setIllust)
fmt.Println("Loaded:", path)
})
}
func setIllust(c *fiber.Ctx) error {
userid := c.Params("userid")
situationid := c.Params("situationid")
illust := c.Params("illust")
user := db.FindUser(userid)
situationIllust, _ := user["situationIllust"].(map[string]any)
if situationIllust == nil {
situationIllust = map[string]any{}
user["situationIllust"] = situationIllust
}
situationIllust[situationid] = illust
db.Save()
m := master.GetMaster()
charSituationMap := m["masterCharacterSituationMap"].(map[string]any)["entries"].(map[string]any)
var sit map[string]any
for _, v := range charSituationMap {
s := v.(map[string]any)
if fmt.Sprintf("%v", s["situationId"]) == situationid {
sit = s
break
}
}
if sit == nil {
return c.Status(404).SendString("situation not found")
}
maxLevel := 0
if paramMap, ok := sit["parameterMap"].(map[string]any); ok {
for k := range paramMap {
var level int
fmt.Sscanf(k, "%d", &level)
if level > maxLevel {
maxLevel = level
}
}
}
rarity, _ := sit["rarity"].(float64)
hasTraining := rarity >= 3
data := map[string]any{
"userId": userid,
"situationId": sit["situationId"],
"level": maxLevel,
"exp": 0,
"createdAt": sit["releasedAt"],
"addExp": 0,
"trainingStatus": map[bool]string{true: "done", false: "not_doing"}[hasTraining],
"duplicateCount": 0,
"illust": illust,
"skillExp": 0,
"skillLevel": 5,
"limitBreakRank": 0,
}
if hasTraining {
training, _ := sit["training"].(map[string]any)
appendParam := map[string]any{
"userId": userid,
"situationId": sit["situationId"],
"characterPotentialPerformance": 30,
"characterPotentialTechnique": 30,
"characterPotentialVisual": 30,
"characterBonusPerformance": 30,
"characterBonusTechnique": 30,
"characterBonusVisual": 30,
}
if training != nil {
appendParam["performance"] = training["trainingPerformance"]
appendParam["technique"] = training["trainingTechnique"]
appendParam["visual"] = training["trainingVisual"]
}
data["userAppendParameter"] = appendParam
}
encoded, err := pbutil.Encode("UserSituation", data)
if err != nil {
return c.Status(500).SendString(err.Error())
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
return c.Status(500).SendString(err.Error())
}
return c.Send(encrypted)
}