141 lines
3.7 KiB
Go
141 lines
3.7 KiB
Go
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, postUser)
|
|
fmt.Println("Loaded:", path)
|
|
})
|
|
}
|
|
|
|
func postUser(c *fiber.Ctx) error {
|
|
server := os.Getenv("SERVER")
|
|
decrypted, err := utils.Decrypt(c.Body())
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
decoded, err := pbutil.Decode("UserPostRequest", decrypted)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
|
|
var (
|
|
userName string
|
|
introduction string
|
|
)
|
|
|
|
switch server {
|
|
case "TW":
|
|
userName = "新人工作人員"
|
|
introduction = "你好!"
|
|
case "JP":
|
|
userName = "新人スタッフ"
|
|
introduction = "よろしくお願いします!"
|
|
case "GL":
|
|
userName = "New Staff"
|
|
introduction = "Nice to meet you!"
|
|
}
|
|
|
|
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{
|
|
"userId": nextId,
|
|
"hash": hash,
|
|
"userName": userName,
|
|
"clientVersion": decoded["clientVersion"].(string),
|
|
"platform": decoded["platform"].(string),
|
|
"deviceModel": decoded["deviceModel"].(string),
|
|
"operatingSystem": decoded["operatingSystem"].(string),
|
|
"birthMonth": "199001",
|
|
"tutorialStatus": "end",
|
|
"introduction": 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()
|
|
|
|
data := map[string]any{
|
|
"userId": fmt.Sprintf("%v", newUser["userId"]),
|
|
"hash": newUser["hash"],
|
|
"userName": newUser["userName"],
|
|
"clientVersion": newUser["clientVersion"],
|
|
"platform": newUser["platform"],
|
|
"deviceModel": newUser["deviceModel"],
|
|
"operatingSystem": newUser["operatingSystem"],
|
|
"tutorialStatus": newUser["tutorialStatus"],
|
|
"introduction": newUser["introduction"],
|
|
"tutorialEndedAt": fmt.Sprintf("%v", newUser["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)
|
|
}
|