package user import ( "bdgrp_go/db" "bdgrp_go/pbutil" "bdgrp_go/routes" "bdgrp_go/utils" "fmt" "maps" "os" "time" "github.com/google/uuid" "github.com/gofiber/fiber/v2" ) func init() { path := routes.PathOf() routes.Register(func(app *fiber.App) { app.Post(path, login) fmt.Println("Loaded:", path) }) } func login(c *fiber.Ctx) error { server := os.Getenv("SERVER") decrypted, err := utils.Decrypt(c.Body()) if err != nil { fmt.Println(err) } decoded, err := pbutil.Decode("UserLogin", decrypted) if err != nil { fmt.Println(err) } user := db.FindUser(fmt.Sprintf("%v", decoded["bid"]), db.Bid) if user == nil { hash := uuid.New().String() users := db.DB.Users[server] nextId := 1001 if len(users) > 0 { last := users[len(users)-1] if id, ok := last["userId"].(float64); ok { nextId = int(id) + 1 } } newUser := map[string]any{ "bid": decoded["bid"].(string), "userId": nextId, "hash": hash, "userName": "新手工作人员", "clientVersion": decoded["clientVersion"].(string), "platform": decoded["platform"].(string), "deviceModel": decoded["deviceModel"].(string), "operatingSystem": decoded["operatingSystem"].(string), "birthMonth": "199001", "tutorialStatus": "end", "introduction": "请多多关照!", "unknownString": "standard", "tutorialEndedAt": time.Now().UnixMilli(), } newGamedata := map[string]any{ "rank": 114, "exp": 67, "coin": 114514, "mainDeck": 1, "paidStar": 0, "freeStar": 514, "seal": 0, "degree": []any{100, nil}, "publishTotalDeckPowerFlg": false, "publishBandRankFlg": false, "publishMusicClearedFlg": false, "publishMusicFullComboFlg": false, "publishHighScoreRatingFlg": false, "pooledExp": 0, "totalExp": 0, "nextExp": 0, "publishUpdatedAtFlg": true, "startDashLoginBonusReceiveFlg": false, "publishMusicAllPerfectFlg": false, "publishDeckRankFlg": false, "publishStageAchievementConditionsFlg": false, "publishStageFriendRankingFlg": true, "publishCharacterRankFlg": false, "loginDays": 0, "useProfileSettingDegree": true, "useProfileSettingSituation": true, "selectedCharacterType": "character_situation", } maps.Copy(newUser, newGamedata) db.DB.Users[server] = append(db.DB.Users[server], newUser) db.Save() user = newUser } data := map[string]any{ "userId": fmt.Sprintf("%v", user["userId"]), "hash": user["hash"], "userName": user["userName"], "clientVersion": user["clientVersion"], "platform": user["platform"], "deviceModel": user["deviceModel"], "operatingSystem": user["operatingSystem"], "tutorialStatus": user["tutorialStatus"], "introduction": user["introduction"], "tutorialEndedAt": fmt.Sprintf("%v", user["tutorialEndedAt"]), } encoded, err := pbutil.Encode("UserRegistration", data) if err != nil { fmt.Println(err) } encrypted, err := utils.Encrypt(encoded) if err != nil { fmt.Println(err) } return c.Send(encrypted) }