diff --git a/encrypt/rsa.go b/encrypt/rsa.go index 9089d2b..7537155 100644 --- a/encrypt/rsa.go +++ b/encrypt/rsa.go @@ -73,6 +73,7 @@ func RSA_Gen(bits int) { //3. save to file pem.Encode(publickeyfile, &publickeyblock) } + func RSA_Encrypt(plainText []byte, publickeypath string) []byte { //open publickeyfile publickeyfile, err := os.Open(publickeypath) diff --git a/handler/album.go b/handler/album.go index d7ea68a..943c0bf 100644 --- a/handler/album.go +++ b/handler/album.go @@ -10,10 +10,9 @@ import ( "time" "github.com/gin-gonic/gin" - _ "github.com/mattn/go-sqlite3" ) -type AlbumSearchResult struct { +type AlbumRes struct { UnitId int `xorm:"unit_id"` Rarity int `xorm:"rarity"` } @@ -26,7 +25,7 @@ func AlbumSeriesAll(ctx *gin.Context) { albumSeriesAllRes := []model.AlbumSeriesRes{} for _, albumId := range albumIds { - unitList := []AlbumSearchResult{} + unitList := []AlbumRes{} err = MainEng.Table("unit_m").Where("album_series_id = ?", albumId).Cols("unit_id,rarity").Find(&unitList) CheckErr(err) @@ -62,9 +61,7 @@ func AlbumSeriesAll(ctx *gin.Context) { albumSeries.HighestLovePerUnit = 1000 // IsSigned - exists, err := MainEng.Table("unit_sign_asset_m").Where("unit_id = ?", unit.UnitId).Exist() - CheckErr(err) - albumSeries.SignFlag = exists + albumSeries.SignFlag = IsSigned(unit.UnitId) } albumSeriesAll = append(albumSeriesAll, albumSeries) diff --git a/handler/api.go b/handler/api.go index 1e4a7fb..a7311c2 100644 --- a/handler/api.go +++ b/handler/api.go @@ -17,6 +17,27 @@ import ( "github.com/gin-gonic/gin" ) +type EventRes struct { + EventScenarioId int `xorm:"event_scenario_id"` + Chapter int `xorm:"chapter"` + ChapterAsset string `xorm:"chapter_asset"` + OpenDate string `xorm:"open_date"` +} + +type MultiRes struct { + MultiUnitScenarioId int `xorm:"multi_unit_scenario_id"` + Chapter int `xorm:"chapter"` + MultiUnitScenarioBtnAsset string `xorm:"multi_unit_scenario_btn_asset"` + OpenDate string `xorm:"open_date"` +} + +type MuseumRes struct { + MuseumContentsId int `xorm:"museum_contents_id"` + SmileBuff int `xorm:"smile_buff"` + PureBuff int `xorm:"pure_buff"` + CoolBuff int `xorm:"cool_buff"` +} + func Api(ctx *gin.Context) { apiReq := []model.ApiReq{} err := json.Unmarshal([]byte(ctx.GetString("request_data")), &apiReq) @@ -226,13 +247,13 @@ func Api(ctx *gin.Context) { CheckErr(err) case "deckInfo": // key = "unit_deck_result" - userDeck := []tools.UserDeckData{} + userDeck := []model.UserDeckData{} err = UserEng.Table("user_deck_m").Where("user_id = ?", ctx.GetString("userid")).Asc("deck_id").Find(&userDeck) CheckErr(err) unitDeckInfo := []model.UnitDeckInfoRes{} for _, deck := range userDeck { - deckUnit := []tools.UnitDeckData{} + deckUnit := []model.UnitDeckData{} err = UserEng.Table("deck_unit_m").Where("user_deck_id = ?", deck.ID).Asc("position").Find(&deckUnit) CheckErr(err) @@ -379,7 +400,7 @@ func Api(ctx *gin.Context) { case "album": // key = "album_unit_result" albumLists := []model.AlbumResult{} - unitList := []AlbumSearchResult{} + unitList := []AlbumRes{} err = MainEng.Table("unit_m").Cols("unit_id,rarity").OrderBy("unit_id ASC").Find(&unitList) CheckErr(err) for _, unit := range unitList { @@ -411,9 +432,7 @@ func Api(ctx *gin.Context) { albumList.TotalLove = 1000 // IsSigned - exists, err := MainEng.Table("unit_sign_asset_m").Where("unit_id = ?", unit.UnitId).Exist() - CheckErr(err) - albumList.SignFlag = exists + albumList.SignFlag = IsSigned(unit.UnitId) } albumLists = append(albumLists, albumList) } @@ -478,20 +497,16 @@ func Api(ctx *gin.Context) { err = MainEng.Table("event_scenario_m").Cols("event_id").GroupBy("event_id").OrderBy("event_id DESC").Find(&eventIds) CheckErr(err) for _, id := range eventIds { - sql := `SELECT event_scenario_id,chapter,chapter_asset,open_date FROM event_scenario_m WHERE event_id = ? ORDER BY chapter DESC` - chaps, err := MainEng.DB().Query(sql, id) - CheckErr(err) - defer chaps.Close() + eventRes := []EventRes{} chapsList := []model.EventScenarioChapterList{} - var open_date string - for chaps.Next() { - var event_scenario_id, chapter int - var chapter_asset interface{} - err = chaps.Scan(&event_scenario_id, &chapter, &chapter_asset, &open_date) - CheckErr(err) + err = MainEng.Table("event_scenario_m").Where("event_id = ?", id).Cols("event_scenario_id,chapter,chapter_asset,open_date"). + OrderBy("chapter DESC").Find(&eventRes) + CheckErr(err) + for _, res := range eventRes { chapList := model.EventScenarioChapterList{ - EventScenarioID: event_scenario_id, - Chapter: chapter, + EventScenarioID: res.EventScenarioId, + Chapter: res.Chapter, + ChapterAsset: res.ChapterAsset, Status: 2, OpenFlashFlag: 0, IsReward: false, @@ -499,16 +514,12 @@ func Api(ctx *gin.Context) { ItemID: 1200, Amount: 1, } - if chapter_asset != nil { - chapList.ChapterAsset = chapter_asset.(string) - } - chapsList = append(chapsList, chapList) } eventList := model.EventScenarioList{ EventID: id, - OpenDate: strings.ReplaceAll(open_date, "/", "-"), + OpenDate: strings.ReplaceAll(eventRes[0].OpenDate, "/", "-"), ChapterList: chapsList, } @@ -525,7 +536,7 @@ func Api(ctx *gin.Context) { } eventScenarioResp := model.EventScenarioStatusResp{ Result: model.EventScenarioStatusRes{ - EventScenarioList: eventsList, // + EventScenarioList: eventsList, }, Status: 200, CommandNum: false, @@ -540,26 +551,22 @@ func Api(ctx *gin.Context) { err = MainEng.Table("multi_unit_scenario_m").Cols("multi_unit_id").GroupBy("multi_unit_id").OrderBy("multi_unit_id ASC").Find(&multiIds) CheckErr(err) for _, id := range multiIds { - sql := `SELECT multi_unit_scenario_btn_asset,open_date,multi_unit_scenario_id,chapter FROM multi_unit_scenario_m a LEFT JOIN multi_unit_scenario_open_m b ON a.multi_unit_id = b.multi_unit_id WHERE a.multi_unit_id = ?` - units, err := MainEng.DB().Query(sql, id) + multiRes := MultiRes{} + _, err = 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"). + Cols("multi_unit_scenario_btn_asset,open_date,multi_unit_scenario_id,chapter"). + Where("multi_unit_scenario_m.multi_unit_id = ?", id).Get(&multiRes) CheckErr(err) - defer units.Close() - var multi_unit_scenario_id, chapter int - var multi_unit_scenario_btn_asset, open_date string - for units.Next() { - err = units.Scan(&multi_unit_scenario_btn_asset, &open_date, &multi_unit_scenario_id, &chapter) - CheckErr(err) - } multiUnitsList = append(multiUnitsList, model.MultiUnitScenarioStatusList{ MultiUnitID: id, Status: 2, - MultiUnitScenarioBtnAsset: multi_unit_scenario_btn_asset, - OpenDate: strings.ReplaceAll(open_date, "/", "-"), + MultiUnitScenarioBtnAsset: multiRes.MultiUnitScenarioBtnAsset, + OpenDate: strings.ReplaceAll(multiRes.OpenDate, "/", "-"), ChapterList: []model.MultiUnitScenarioChapterList{ { - MultiUnitScenarioID: multi_unit_scenario_id, - Chapter: chapter, + MultiUnitScenarioID: multiRes.MultiUnitScenarioId, + Chapter: multiRes.Chapter, Status: 2, }, }, @@ -827,31 +834,27 @@ func Api(ctx *gin.Context) { CheckErr(err) case "museum": // key = "museum_result" - sql := `SELECT museum_contents_id,smile_buff,pure_buff,cool_buff FROM museum_contents_m ORDER BY museum_contents_id ASC` - rows, err := MainEng.DB().Query(sql) + museumRes := []MuseumRes{} + var museumIds []int + var smileBuff, pureBuff, coolBuff int + err = MainEng.Table("museum_contents_m").Cols("museum_contents_id,smile_buff,pure_buff,cool_buff"). + OrderBy("museum_contents_id ASC").Find(&museumRes) CheckErr(err) - defer rows.Close() - var smileBuf, pureBuf, coolBuf int - var mIds []int - for rows.Next() { - var museum_contents_id, smile_buff, pure_buff, cool_buff int - err = rows.Scan(&museum_contents_id, &smile_buff, &pure_buff, &cool_buff) - CheckErr(err) - smileBuf += smile_buff - pureBuf += pure_buff - coolBuf += cool_buff - mIds = append(mIds, museum_contents_id) + for _, res := range museumRes { + smileBuff += res.SmileBuff + pureBuff += res.PureBuff + coolBuff += res.CoolBuff + museumIds = append(museumIds, res.MuseumContentsId) } - museumInfoResp := model.MuseumInfoResp{ Result: model.MuseumInfoRes{ MuseumInfo: model.Museum{ Parameter: model.MuseumParameter{ - Smile: smileBuf, - Pure: pureBuf, - Cool: coolBuf, + Smile: smileBuff, + Pure: pureBuff, + Cool: coolBuff, }, - ContentsIDList: mIds, + ContentsIDList: museumIds, }, }, Status: 200, @@ -863,8 +866,8 @@ func Api(ctx *gin.Context) { case "profile": if v.Action == "liveCnt" { // key = "profile_livecnt_result" - difficultyResp := tools.DifficultyResp{ - Result: []tools.DifficultyResult{ + difficultyResp := model.DifficultyResp{ + Result: []model.DifficultyRes{ { Difficulty: 1, ClearCnt: 315, @@ -898,7 +901,7 @@ func Api(ctx *gin.Context) { love := utils.ReadAllText("assets/love.json") err := json.Unmarshal([]byte(love), &result) CheckErr(err) - loveResp := tools.LoveResp{ + loveResp := model.LoveResp{ Result: result, Status: 200, CommandNum: false, @@ -921,7 +924,7 @@ func Api(ctx *gin.Context) { userUnit, err := UserEng.Table("user_unit_m").Where("user_id = ?", ctx.GetString("userid")).Count() CheckErr(err) - unitData := tools.UnitData{} + unitData := model.UnitData{} exists, err = MainEng.Table("common_unit_m").Where("unit_owning_user_id = ?", pref.UnitOwningUserID).Get(&unitData) CheckErr(err) isCommon := true @@ -956,7 +959,7 @@ func Api(ctx *gin.Context) { _, err = MainEng.Table("common_accessory_m").Where("accessory_owning_user_id = ?", accessoryOwningId). Cols("accessory_id,exp").Get(&accessoryId, &exp) CheckErr(err) - accessoryInfo := tools.AccessoryInfo{ + accessoryInfo := model.AccessoryInfo{ AccessoryOwningUserID: accessoryOwningId, AccessoryID: accessoryId, Exp: exp, @@ -972,9 +975,9 @@ func Api(ctx *gin.Context) { Cols("unit_removable_skill_id").Find(&removeSkillIds) CheckErr(err) - profileResp := tools.ProfileResp{ - Result: tools.ProfileResult{ - UserInfo: tools.UserInfo{ + profileResp := model.ProfileResp{ + Result: model.ProfileRes{ + UserInfo: model.ProfileUserInfo{ UserID: pref.UserID, Name: pref.UserName, Level: pref.UserLevel, @@ -987,7 +990,7 @@ func Api(ctx *gin.Context) { ElapsedTimeFromLogin: "14\u5c0f\u65f6\u524d", Introduction: pref.UserDesc, }, - CenterUnitInfo: tools.CenterUnitInfo{ + CenterUnitInfo: model.CenterUnitInfo{ UnitOwningUserID: unitData.UnitOwningUserID, UnitID: unitData.UnitID, Exp: unitData.Exp, @@ -1017,13 +1020,13 @@ func Api(ctx *gin.Context) { SettingAwardID: pref.AwardID, RemovableSkillIds: removeSkillIds, AccessoryInfo: accessoryInfo, - Costume: tools.Costume{}, + Costume: model.Costume{}, TotalSmile: smileMax, TotalCute: pureMax, TotalCool: coolMax, TotalHp: maxHp, }, - NaviUnitInfo: tools.NaviUnitInfo{ + NaviUnitInfo: model.NaviUnitInfo{ UnitOwningUserID: unitData.UnitOwningUserID, UnitID: unitData.UnitID, Exp: unitData.Exp, diff --git a/handler/download.go b/handler/download.go index 1bf8954..60fc5a5 100644 --- a/handler/download.go +++ b/handler/download.go @@ -12,7 +12,6 @@ import ( "time" "github.com/gin-gonic/gin" - _ "github.com/mattn/go-sqlite3" "xorm.io/builder" ) diff --git a/handler/global.go b/handler/global.go index b5b27d3..51e8f84 100644 --- a/handler/global.go +++ b/handler/global.go @@ -27,3 +27,10 @@ func CheckErr(err error) { panic(err) } } + +func IsSigned(unitId int) bool { + exists, err := MainEng.Table("unit_sign_asset_m").Where("unit_id = ?", unitId).Exist() + CheckErr(err) + + return exists +} diff --git a/handler/live.go b/handler/live.go index 1957cc1..04bb527 100644 --- a/handler/live.go +++ b/handler/live.go @@ -14,7 +14,6 @@ import ( "time" "github.com/gin-gonic/gin" - _ "github.com/mattn/go-sqlite3" "github.com/tidwall/gjson" ) diff --git a/handler/login.go b/handler/login.go index 32b8abe..d6f2fde 100644 --- a/handler/login.go +++ b/handler/login.go @@ -12,7 +12,6 @@ import ( "time" "github.com/gin-gonic/gin" - _ "github.com/mattn/go-sqlite3" ) func AuthKey(ctx *gin.Context) { diff --git a/handler/multiunit.go b/handler/multiunit.go index 7af77bf..cb6665a 100644 --- a/handler/multiunit.go +++ b/handler/multiunit.go @@ -5,40 +5,20 @@ import ( "encoding/json" "fmt" "honoka-chan/encrypt" + "honoka-chan/model" "net/http" "time" "github.com/gin-gonic/gin" ) -type MultiUnitStartUpResp struct { - ResponseData MultiUnitStartUpData `json:"response_data"` - ReleaseInfo []interface{} `json:"release_info"` - StatusCode int `json:"status_code"` -} - -type MultiUnitStartUpData struct { - MultiUnitScenarioID int `json:"multi_unit_scenario_id"` - ScenarioAdjustment int `json:"scenario_adjustment"` - ServerTimestamp int64 `json:"server_timestamp"` -} - -type MultiUnitStartUpReq struct { - Module string `json:"module"` - Action string `json:"action"` - TimeStamp int `json:"timeStamp"` - Mgd int `json:"mgd"` - MultiUnitScenarioID int `json:"multi_unit_scenario_id"` - CommandNum string `json:"commandNum"` -} - func MultiUnitStartUp(ctx *gin.Context) { - startReq := MultiUnitStartUpReq{} + startReq := model.MultiUnitStartUpReq{} err := json.Unmarshal([]byte(ctx.PostForm("request_data")), &startReq) CheckErr(err) - startResp := MultiUnitStartUpResp{ - ResponseData: MultiUnitStartUpData{ + startResp := model.MultiUnitStartUpResp{ + ResponseData: model.MultiUnitStartUpRes{ MultiUnitScenarioID: startReq.MultiUnitScenarioID, ScenarioAdjustment: 50, ServerTimestamp: time.Now().Unix(), diff --git a/handler/payment.go b/handler/payment.go index b7f5ffc..b2e4f9e 100644 --- a/handler/payment.go +++ b/handler/payment.go @@ -5,43 +5,20 @@ import ( "encoding/json" "fmt" "honoka-chan/encrypt" + "honoka-chan/model" "net/http" "time" "github.com/gin-gonic/gin" ) -type ProductResp struct { - ResponseData ProductData `json:"response_data"` - ReleaseInfo []interface{} `json:"release_info"` - StatusCode int `json:"status_code"` -} -type RestrictionInfo struct { - Restricted bool `json:"restricted"` -} -type UnderAgeInfo struct { - BirthSet bool `json:"birth_set"` - HasLimit bool `json:"has_limit"` - LimitAmount interface{} `json:"limit_amount"` - MonthUsed int `json:"month_used"` -} -type ProductData struct { - RestrictionInfo RestrictionInfo `json:"restriction_info"` - UnderAgeInfo UnderAgeInfo `json:"under_age_info"` - SnsProductList []interface{} `json:"sns_product_list"` - ProductList []interface{} `json:"product_list"` - SubscriptionList []interface{} `json:"subscription_list"` - ShowPointShop bool `json:"show_point_shop"` - ServerTimestamp int64 `json:"server_timestamp"` -} - func ProductList(ctx *gin.Context) { - prodReesp := ProductResp{ - ResponseData: ProductData{ - RestrictionInfo: RestrictionInfo{ + prodReesp := model.ProductResp{ + ResponseData: model.ProductRes{ + RestrictionInfo: model.RestrictionInfo{ Restricted: false, }, - UnderAgeInfo: UnderAgeInfo{ + UnderAgeInfo: model.UnderAgeInfo{ BirthSet: true, HasLimit: false, LimitAmount: nil, diff --git a/handler/private.go b/handler/private.go index 73c23cb..3a70a46 100644 --- a/handler/private.go +++ b/handler/private.go @@ -17,7 +17,6 @@ import ( "github.com/forgoer/openssl" "github.com/gin-gonic/gin" - _ "github.com/mattn/go-sqlite3" ) type LoginResp struct { @@ -50,7 +49,7 @@ type LoginAutoResp struct { Result int `json:"result"` Message string `json:"message"` Autokey string `json:"autokey"` - Userid string `json:"userid"` + UserId string `json:"userid"` Ticket string `json:"ticket"` } @@ -222,21 +221,17 @@ func LoginAuto(ctx *gin.Context) { return } - stmt, err := UserEng.DB().Prepare("SELECT userid,ticket AS ct FROM users WHERE autokey = ?") - CheckErr(err) - defer stmt.Close() - - var userid, ticket string - err = stmt.QueryRow(autoKey).Scan(&userid, &ticket) + var userId, ticket string + _, err = UserEng.Table("users").Cols("userid,ticket").Where("autokey = ?", autoKey).Get(&userId, &ticket) CheckErr(err) var resp string - if userid != "" { + if userId != "" { autoResp := LoginAutoResp{ Result: 0, Message: "ok", Autokey: autoKey, - Userid: userid, + UserId: userId, Ticket: ticket, } data, err := json.Marshal(autoResp) @@ -314,18 +309,10 @@ func AccountLogin(ctx *gin.Context) { // "userid" INTEGER, // "key" INTEGER // );` - stmt, err := UserEng.DB().Prepare("SELECT password,autokey,ticket,userid FROM users WHERE phone = ?") + var pass, autoKey, ticket, userId string + _, err = UserEng.Table("users").Cols("password,autokey,ticket,userid").Where("phone = ?", phone). + Get(&pass, &autoKey, &ticket, &userId) CheckErr(err) - defer stmt.Close() - - var pass, autokey, ticket, userid string - rows, err := stmt.Query(phone) - CheckErr(err) - defer rows.Close() - for rows.Next() { - err = rows.Scan(&pass, &autokey, &ticket, &userid) - CheckErr(err) - } loginResp := LoginResp{} loginCode := 0 @@ -336,15 +323,16 @@ func AccountLogin(ctx *gin.Context) { session := UserEng.NewSession() defer session.Close() + // 开始会话 if err = session.Begin(); err != nil { session.Rollback() panic(err) } pass = openssl.Md5ToString(password) - autokey = "AUTO" + strings.ToUpper(utils.RandomStr(32)) - userid = strconv.Itoa(int(loginTime)) - ticket = "9999999" + userid + userid + autoKey = "AUTO" + strings.ToUpper(utils.RandomStr(32)) + userId = strconv.Itoa(int(loginTime)) + ticket = "9999999" + userId + userId userStmt, err := session.DB().Prepare("INSERT INTO users(phone,password,autokey,ticket,userid,last_login_time) VALUES (?,?,?,?,?,?)") if err != nil { session.Rollback() @@ -352,7 +340,7 @@ func AccountLogin(ctx *gin.Context) { } defer userStmt.Close() - _, err = userStmt.Exec(phone, pass, autokey, ticket, userid, loginTime) + _, err = userStmt.Exec(phone, pass, autoKey, ticket, userId, loginTime) if err != nil { session.Rollback() panic(err) @@ -367,12 +355,13 @@ func AccountLogin(ctx *gin.Context) { } // 方便起见初始化 userid 和 key 一样 // 注意:user_key 表中的 key 是上文生成的用于登录的 userid,而 userid 则是用于 Authorize Token 生成用的 - _, err = keyStmt.Exec(userid, userid) + _, err = keyStmt.Exec(userId, userId) if err != nil { session.Rollback() panic(err) } + // 结束会话 if err = session.Commit(); err != nil { session.Rollback() panic(err) @@ -381,32 +370,32 @@ func AccountLogin(ctx *gin.Context) { tools.InitUserData(int(loginTime)) // Login Response - loginResp.Autokey = autokey + loginResp.Autokey = autoKey loginResp.HasRealInfo = 1 loginResp.Message = "ok" loginResp.RealInfoForce = 1 loginResp.Ticket = ticket loginResp.UserAttribute = "0" - loginResp.Userid = userid + loginResp.Userid = userId } else { // 已注册 if openssl.Md5ToString(password) == pass { // 密码正确 // Login Response - loginResp.Autokey = autokey // 注意:更换设备(deviceId 发生变化)应重新生成 autokey + loginResp.Autokey = autoKey // 注意:更换设备(deviceId 发生变化)应重新生成 autokey loginResp.HasRealInfo = 1 loginResp.Message = "ok" loginResp.RealInfoForce = 1 - loginResp.Ticket = "9999999" + userid + strconv.Itoa(int(loginTime)) // 实际登录用的密码(每次登录都会重新生成新的) + loginResp.Ticket = "9999999" + userId + strconv.Itoa(int(loginTime)) // 实际登录用的密码(每次登录都会重新生成新的) loginResp.UserAttribute = "0" - loginResp.Userid = userid // 实际登录用的账号 + loginResp.Userid = userId // 实际登录用的账号 // 更新信息 userStmt, err := UserEng.DB().Prepare("UPDATE users SET autokey=?,ticket=?,last_login_time=? WHERE userid=?") CheckErr(err) defer userStmt.Close() - _, err = userStmt.Exec(autokey, ticket, loginTime, userid) + _, err = userStmt.Exec(autoKey, ticket, loginTime, userId) CheckErr(err) // aff, _ := res.RowsAffected() // fmt.Println("RowsAffected:", aff) diff --git a/handler/scenario.go b/handler/scenario.go index 0d383ee..df3ed25 100644 --- a/handler/scenario.go +++ b/handler/scenario.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "honoka-chan/encrypt" + "honoka-chan/model" "honoka-chan/utils" "net/http" "time" @@ -12,34 +13,13 @@ import ( "github.com/gin-gonic/gin" ) -type ScenarioResp struct { - ResponseData ScenarioData `json:"response_data"` - ReleaseInfo []interface{} `json:"release_info"` - StatusCode int `json:"status_code"` -} - -type ScenarioData struct { - ScenarioID int `json:"scenario_id"` - ScenarioAdjustment int `json:"scenario_adjustment"` - ServerTimestamp int64 `json:"server_timestamp"` -} - -type ScenarioReq struct { - Module string `json:"module"` - Action string `json:"action"` - TimeStamp int `json:"timeStamp"` - Mgd int `json:"mgd"` - CommandNum string `json:"commandNum"` - ScenarioID int `json:"scenario_id"` -} - func ScenarioStartup(ctx *gin.Context) { - startReq := ScenarioReq{} + startReq := model.ScenarioReq{} err := json.Unmarshal([]byte(ctx.PostForm("request_data")), &startReq) CheckErr(err) - startResp := ScenarioResp{ - ResponseData: ScenarioData{ + startResp := model.ScenarioResp{ + ResponseData: model.ScenarioRes{ ScenarioID: startReq.ScenarioID, ScenarioAdjustment: 50, ServerTimestamp: time.Now().Unix(), diff --git a/handler/subscenario.go b/handler/subscenario.go index e69a28b..cea22da 100644 --- a/handler/subscenario.go +++ b/handler/subscenario.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "honoka-chan/encrypt" + "honoka-chan/model" "honoka-chan/utils" "net/http" "time" @@ -12,34 +13,13 @@ import ( "github.com/gin-gonic/gin" ) -type SubScenarioResp struct { - ResponseData SubScenarioData `json:"response_data"` - ReleaseInfo []interface{} `json:"release_info"` - StatusCode int `json:"status_code"` -} - -type SubScenarioData struct { - SubscenarioID int `json:"subscenario_id"` - ScenarioAdjustment int `json:"scenario_adjustment"` - ServerTimestamp int64 `json:"server_timestamp"` -} - -type SubScenarioReq struct { - Module string `json:"module"` - Action string `json:"action"` - TimeStamp int `json:"timeStamp"` - SubscenarioID int `json:"subscenario_id"` - Mgd int `json:"mgd"` - CommandNum string `json:"commandNum"` -} - func SubScenarioStartup(ctx *gin.Context) { - startReq := SubScenarioReq{} + startReq := model.SubScenarioReq{} err := json.Unmarshal([]byte(ctx.PostForm("request_data")), &startReq) CheckErr(err) - startResp := SubScenarioResp{ - ResponseData: SubScenarioData{ + startResp := model.SubScenarioResp{ + ResponseData: model.SubScenarioRes{ SubscenarioID: startReq.SubscenarioID, ScenarioAdjustment: 50, ServerTimestamp: time.Now().Unix(), diff --git a/handler/unit.go b/handler/unit.go index 5868ed4..57eb919 100644 --- a/handler/unit.go +++ b/handler/unit.go @@ -6,7 +6,6 @@ import ( "fmt" "honoka-chan/encrypt" "honoka-chan/model" - "honoka-chan/tools" "net/http" "strconv" "time" @@ -76,7 +75,7 @@ func SetDeck(ctx *gin.Context) { // 遍历新队伍 for _, deck := range deckReq.UnitDeckList { // 新队伍信息 - userDeck := tools.UserDeckData{ + userDeck := model.UserDeckData{ DeckID: deck.UnitDeckID, MainFlag: deck.MainFlag, DeckName: deck.DeckName, @@ -94,7 +93,7 @@ func SetDeck(ctx *gin.Context) { // 队伍成员信息 for _, unit := range deck.UnitDeckDetail { // 成员信息 - newUnitData := tools.UnitData{} + newUnitData := model.UnitData{} exists, err := session.Table("user_unit_m").Where("unit_owning_user_id = ?", unit.UnitOwningUserID).Exist() if err != nil { session.Rollback() @@ -129,7 +128,7 @@ func SetDeck(ctx *gin.Context) { // fmt.Println("新的成员信息:", newUnitData) // 插入新成员信息 - newUnitDeckData := tools.UnitDeckData{} + newUnitDeckData := model.UnitDeckData{} b, err := json.Marshal(newUnitData) if err != nil { session.Rollback() @@ -191,10 +190,10 @@ func SetDeckName(ctx *gin.Context) { ctx.String(http.StatusForbidden, ErrorMsg) return } - userDeck := tools.UserDeckData{ + userDeck := model.UserDeckData{ DeckName: deckReq.DeckName, } - _, err = UserEng.Table("user_deck_m").Update(&userDeck, &tools.UserDeckData{ + _, err = UserEng.Table("user_deck_m").Update(&userDeck, &model.UserDeckData{ UserID: userId, DeckID: deckReq.UnitDeckID, }) @@ -245,6 +244,7 @@ func WearAccessory(ctx *gin.Context) { panic(err) } } + // 佩戴饰品 for _, v := range req.Wear { fmt.Println("Wear:", v.AccessoryOwningUserID, v.UnitOwningUserID) @@ -256,6 +256,8 @@ func WearAccessory(ctx *gin.Context) { _, err := session.Table("accessory_wear_m").Insert(&data) CheckErr(err) } + + // 结束事务 if err := session.Commit(); err != nil { session.Rollback() panic(err) @@ -306,6 +308,7 @@ func RemoveSkillEquip(ctx *gin.Context) { panic(err) } } + // 佩戴宝石 for _, v := range req.Equip { fmt.Println("Equip:", v.UnitOwningUserID, v.UnitRemovableSkillID) @@ -317,6 +320,8 @@ func RemoveSkillEquip(ctx *gin.Context) { _, err := session.Table("skill_equip_m").Insert(&data) CheckErr(err) } + + // 结束事务 if err := session.Commit(); err != nil { session.Rollback() panic(err) diff --git a/handler/user.go b/handler/user.go index dd616c5..7cf35e7 100644 --- a/handler/user.go +++ b/handler/user.go @@ -14,14 +14,8 @@ import ( "github.com/tidwall/gjson" ) -type NotificationResp struct { - ResponseData []interface{} `json:"response_data"` - ReleaseInfo []interface{} `json:"release_info"` - StatusCode int `json:"status_code"` -} - func SetNotificationToken(ctx *gin.Context) { - notifResp := NotificationResp{ + notifResp := model.NotificationResp{ ResponseData: []interface{}{}, ReleaseInfo: []interface{}{}, StatusCode: 200, diff --git a/handler/webui.go b/handler/webui.go index 2813aa2..43a60a2 100644 --- a/handler/webui.go +++ b/handler/webui.go @@ -3,7 +3,6 @@ package handler import ( "encoding/json" "honoka-chan/model" - "honoka-chan/tools" "honoka-chan/utils" "net/http" "path" @@ -130,7 +129,7 @@ func Upload(ctx *gin.Context) { skillExp = 29900 } - unitData := tools.UnitData{ + unitData := model.UnitData{ UserID: ctx.GetInt("userid"), UnitID: unitId, Exp: unitExp + diffExp, diff --git a/model/banner.go b/model/banner.go index 9552c3c..fa3b703 100644 --- a/model/banner.go +++ b/model/banner.go @@ -1,6 +1,6 @@ package model -// module: banner, action: bannerList +// BannerList ... type BannerList struct { BannerType int `json:"banner_type"` TargetID int `json:"target_id"` diff --git a/model/llhelper.go b/model/llhelper.go index 4e327d4..0383c28 100644 --- a/model/llhelper.go +++ b/model/llhelper.go @@ -1,5 +1,6 @@ package model +// Data ... type Data struct { Version int `json:"version"` Team []Team `json:"team"` @@ -7,11 +8,13 @@ type Data struct { Submember []interface{} `json:"submember"` } +// Accessory ... type Accessory struct { ID string `json:"id"` Level int `json:"level"` } +// Team ... type Team struct { Hp int `json:"hp"` Smile int `json:"smile"` diff --git a/model/multiunit.go b/model/multiunit.go index 0574663..1faf5ed 100644 --- a/model/multiunit.go +++ b/model/multiunit.go @@ -29,3 +29,27 @@ type MultiUnitScenarioStatusResp struct { CommandNum bool `json:"commandNum"` TimeStamp int64 `json:"timeStamp"` } + +// MultiUnitStartUpResp ... +type MultiUnitStartUpResp struct { + ResponseData MultiUnitStartUpRes `json:"response_data"` + ReleaseInfo []interface{} `json:"release_info"` + StatusCode int `json:"status_code"` +} + +// MultiUnitStartUpRes ... +type MultiUnitStartUpRes struct { + MultiUnitScenarioID int `json:"multi_unit_scenario_id"` + ScenarioAdjustment int `json:"scenario_adjustment"` + ServerTimestamp int64 `json:"server_timestamp"` +} + +// MultiUnitStartUpReq ... +type MultiUnitStartUpReq struct { + Module string `json:"module"` + Action string `json:"action"` + TimeStamp int `json:"timeStamp"` + Mgd int `json:"mgd"` + MultiUnitScenarioID int `json:"multi_unit_scenario_id"` + CommandNum string `json:"commandNum"` +} diff --git a/model/payment.go b/model/payment.go index 1fa7f20..5fe3005 100644 --- a/model/payment.go +++ b/model/payment.go @@ -134,3 +134,21 @@ type ProductListResp struct { CommandNum bool `json:"commandNum"` TimeStamp int64 `json:"timeStamp"` } + +// ProductResp ... +type ProductResp struct { + ResponseData ProductRes `json:"response_data"` + ReleaseInfo []interface{} `json:"release_info"` + StatusCode int `json:"status_code"` +} + +// ProductRes ... +type ProductRes struct { + RestrictionInfo RestrictionInfo `json:"restriction_info"` + UnderAgeInfo UnderAgeInfo `json:"under_age_info"` + SnsProductList []interface{} `json:"sns_product_list"` + ProductList []interface{} `json:"product_list"` + SubscriptionList []interface{} `json:"subscription_list"` + ShowPointShop bool `json:"show_point_shop"` + ServerTimestamp int64 `json:"server_timestamp"` +} diff --git a/model/scenario.go b/model/scenario.go index c78480c..6b5540d 100644 --- a/model/scenario.go +++ b/model/scenario.go @@ -72,3 +72,27 @@ type EventScenarioStatusResp struct { CommandNum bool `json:"commandNum"` TimeStamp int64 `json:"timeStamp"` } + +// ScenarioResp ... +type ScenarioResp struct { + ResponseData ScenarioRes `json:"response_data"` + ReleaseInfo []interface{} `json:"release_info"` + StatusCode int `json:"status_code"` +} + +// ScenarioRes ... +type ScenarioRes struct { + ScenarioID int `json:"scenario_id"` + ScenarioAdjustment int `json:"scenario_adjustment"` + ServerTimestamp int64 `json:"server_timestamp"` +} + +// ScenarioReq ... +type ScenarioReq struct { + Module string `json:"module"` + Action string `json:"action"` + TimeStamp int `json:"timeStamp"` + Mgd int `json:"mgd"` + CommandNum string `json:"commandNum"` + ScenarioID int `json:"scenario_id"` +} diff --git a/model/subscenario.go b/model/subscenario.go new file mode 100644 index 0000000..e4d8249 --- /dev/null +++ b/model/subscenario.go @@ -0,0 +1,25 @@ +package model + +// SubScenarioResp ... +type SubScenarioResp struct { + ResponseData SubScenarioRes `json:"response_data"` + ReleaseInfo []interface{} `json:"release_info"` + StatusCode int `json:"status_code"` +} + +// SubScenarioRes ... +type SubScenarioRes struct { + SubscenarioID int `json:"subscenario_id"` + ScenarioAdjustment int `json:"scenario_adjustment"` + ServerTimestamp int64 `json:"server_timestamp"` +} + +// SubScenarioReq ... +type SubScenarioReq struct { + Module string `json:"module"` + Action string `json:"action"` + TimeStamp int `json:"timeStamp"` + SubscenarioID int `json:"subscenario_id"` + Mgd int `json:"mgd"` + CommandNum string `json:"commandNum"` +} diff --git a/model/tools.go b/model/tools.go new file mode 100644 index 0000000..156fa61 --- /dev/null +++ b/model/tools.go @@ -0,0 +1,200 @@ +package model + +// UnitData ... +type UnitData struct { + UnitOwningUserID int `xorm:"unit_owning_user_id pk autoincr" json:"unit_owning_user_id"` + UserID int `xorm:"user_id" json:"-"` + UnitID int `xorm:"unit_id" json:"unit_id"` + Exp int `xorm:"exp" json:"exp"` + NextExp int `xorm:"next_exp" json:"next_exp"` + Level int `xorm:"level" json:"level"` + MaxLevel int `xorm:"max_level" json:"max_level"` + LevelLimitID int `xorm:"level_limit_id" json:"level_limit_id"` + Rank int `xorm:"rank" json:"rank"` + MaxRank int `xorm:"max_rank" json:"max_rank"` + Love int `xorm:"love" json:"love"` + MaxLove int `xorm:"max_love" json:"max_love"` + UnitSkillExp int `xorm:"unit_skill_exp" json:"unit_skill_exp"` + UnitSkillLevel int `xorm:"unit_skill_level" json:"unit_skill_level"` + MaxHp int `xorm:"max_hp" json:"max_hp"` + UnitRemovableSkillCapacity int `xorm:"unit_removable_skill_capacity" json:"unit_removable_skill_capacity"` + FavoriteFlag bool `xorm:"favorite_flag" json:"favorite_flag"` + DisplayRank int `xorm:"display_rank" json:"display_rank"` + IsRankMax bool `xorm:"is_rank_max" json:"is_rank_max"` + IsLoveMax bool `xorm:"is_love_max" json:"is_love_max"` + IsLevelMax bool `xorm:"is_level_max" json:"is_level_max"` + IsSigned bool `xorm:"is_signed" json:"is_signed"` + IsSkillLevelMax bool `xorm:"is_skill_level_max" json:"is_skill_level_max"` + IsRemovableSkillCapacityMax bool `xorm:"is_removable_skill_capacity_max" json:"is_removable_skill_capacity_max"` + InsertDate string `xorm:"insert_date" json:"insert_date"` +} + +// UserDeckData ... +type UserDeckData struct { + ID int `xorm:"id pk autoincr"` + DeckID int `xorm:"deck_id"` + MainFlag int `xorm:"main_flag"` + DeckName string `xorm:"deck_name"` + UserID int `xorm:"user_id"` + InsertDate int64 `xorm:"insert_date"` +} + +// UnitDeckData ... +type UnitDeckData struct { + ID int `xorm:"id pk autoincr" json:"-"` + UserDeckID int `xorm:"user_deck_id" json:"-"` + UnitOwningUserID int `xorm:"unit_owning_user_id" json:"unit_owning_user_id"` + UnitID int `xorm:"unit_id" json:"unit_id"` + Position int `xorm:"position" json:"position"` + Level int `xorm:"level" json:"level"` + LevelLimitID int `xorm:"level_limit_id" json:"level_limit_id"` + DisplayRank int `xorm:"display_rank" json:"display_rank"` + Love int `xorm:"love" json:"love"` + UnitSkillLevel int `xorm:"unit_skill_level" json:"unit_skill_level"` + IsRankMax bool `xorm:"is_rank_max" json:"is_rank_max"` + IsLoveMax bool `xorm:"is_love_max" json:"is_love_max"` + IsLevelMax bool `xorm:"is_level_max" json:"is_level_max"` + IsSigned bool `xorm:"is_signed" json:"is_signed"` + BeforeLove int `xorm:"before_love" json:"before_love"` + MaxLove int `xorm:"max_love" json:"max_love"` + InsertData int64 `xorm:"insert_date" json:"-"` +} + +// DifficultyRes ... +type DifficultyRes struct { + Difficulty int `json:"difficulty"` + ClearCnt int `json:"clear_cnt"` +} + +// DifficultyResp ... +type DifficultyResp struct { + Result []DifficultyRes `json:"result"` + Status int `json:"status"` + CommandNum bool `json:"commandNum"` + TimeStamp int64 `json:"timeStamp"` +} + +// LoveResp ... +type LoveResp struct { + Result []interface{} `json:"result"` + Status int `json:"status"` + CommandNum bool `json:"commandNum"` + TimeStamp int64 `json:"timeStamp"` +} + +// AccessoryInfo ... +type AccessoryInfo struct { + AccessoryOwningUserID int `json:"accessory_owning_user_id"` + AccessoryID int `json:"accessory_id"` + Exp int `json:"exp"` + NextExp int `json:"next_exp"` + Level int `json:"level"` + MaxLevel int `json:"max_level"` + RankUpCount int `json:"rank_up_count"` + FavoriteFlag bool `json:"favorite_flag"` +} + +// ProfileUserInfo ... +type ProfileUserInfo struct { + UserID int `json:"user_id"` + Name string `json:"name"` + Level int `json:"level"` + CostMax int `json:"cost_max"` + UnitMax int `json:"unit_max"` + EnergyMax int `json:"energy_max"` + FriendMax int `json:"friend_max"` + UnitCnt int `json:"unit_cnt"` + InviteCode string `json:"invite_code"` + ElapsedTimeFromLogin string `json:"elapsed_time_from_login"` + Introduction string `json:"introduction"` +} + +// CenterUnitInfo ... +type CenterUnitInfo struct { + UnitOwningUserID int `json:"unit_owning_user_id"` + UnitID int `json:"unit_id"` + Exp int `json:"exp"` + NextExp int `json:"next_exp"` + Level int `json:"level"` + LevelLimitID int `json:"level_limit_id"` + MaxLevel int `json:"max_level"` + Rank int `json:"rank"` + MaxRank int `json:"max_rank"` + Love int `json:"love"` + MaxLove int `json:"max_love"` + UnitSkillLevel int `json:"unit_skill_level"` + MaxHp int `json:"max_hp"` + FavoriteFlag bool `json:"favorite_flag"` + DisplayRank int `json:"display_rank"` + UnitSkillExp int `json:"unit_skill_exp"` + UnitRemovableSkillCapacity int `json:"unit_removable_skill_capacity"` + Attribute int `json:"attribute"` + Smile int `json:"smile"` + Cute int `json:"cute"` + Cool int `json:"cool"` + IsLoveMax bool `json:"is_love_max"` + IsLevelMax bool `json:"is_level_max"` + IsRankMax bool `json:"is_rank_max"` + IsSigned bool `json:"is_signed"` + IsSkillLevelMax bool `json:"is_skill_level_max"` + SettingAwardID int `json:"setting_award_id"` + RemovableSkillIds []int `json:"removable_skill_ids"` + AccessoryInfo AccessoryInfo `json:"accessory_info"` + Costume Costume `json:"costume"` + TotalSmile int `json:"total_smile"` + TotalCute int `json:"total_cute"` + TotalCool int `json:"total_cool"` + TotalHp int `json:"total_hp"` +} + +// NaviUnitInfo ... +type NaviUnitInfo struct { + UnitOwningUserID int `json:"unit_owning_user_id"` + UnitID int `json:"unit_id"` + Exp int `json:"exp"` + NextExp int `json:"next_exp"` + Level int `json:"level"` + MaxLevel int `json:"max_level"` + LevelLimitID int `json:"level_limit_id"` + Rank int `json:"rank"` + MaxRank int `json:"max_rank"` + Love int `json:"love"` + MaxLove int `json:"max_love"` + UnitSkillExp int `json:"unit_skill_exp"` + UnitSkillLevel int `json:"unit_skill_level"` + MaxHp int `json:"max_hp"` + UnitRemovableSkillCapacity int `json:"unit_removable_skill_capacity"` + FavoriteFlag bool `json:"favorite_flag"` + DisplayRank int `json:"display_rank"` + IsRankMax bool `json:"is_rank_max"` + IsLoveMax bool `json:"is_love_max"` + IsLevelMax bool `json:"is_level_max"` + IsSigned bool `json:"is_signed"` + IsSkillLevelMax bool `json:"is_skill_level_max"` + IsRemovableSkillCapacityMax bool `json:"is_removable_skill_capacity_max"` + InsertDate string `json:"insert_date"` + TotalSmile int `json:"total_smile"` + TotalCute int `json:"total_cute"` + TotalCool int `json:"total_cool"` + TotalHp int `json:"total_hp"` + RemovableSkillIds []int `json:"removable_skill_ids"` +} + +// ProfileRes ... +type ProfileRes struct { + UserInfo ProfileUserInfo `json:"user_info"` + CenterUnitInfo CenterUnitInfo `json:"center_unit_info"` + NaviUnitInfo NaviUnitInfo `json:"navi_unit_info"` + IsAlliance bool `json:"is_alliance"` + FriendStatus int `json:"friend_status"` + SettingAwardID int `json:"setting_award_id"` + SettingBackgroundID int `json:"setting_background_id"` +} + +// ProfileResp ... +type ProfileResp struct { + Result ProfileRes `json:"result"` + Status int `json:"status"` + CommandNum bool `json:"commandNum"` + TimeStamp int64 `json:"timeStamp"` +} diff --git a/model/user.go b/model/user.go index 1a1f21b..7e017f0 100644 --- a/model/user.go +++ b/model/user.go @@ -39,3 +39,10 @@ type UserNaviResp struct { CommandNum bool `json:"commandNum"` TimeStamp int64 `json:"timeStamp"` } + +// NotificationResp ... +type NotificationResp struct { + ResponseData []interface{} `json:"response_data"` + ReleaseInfo []interface{} `json:"release_info"` + StatusCode int `json:"status_code"` +} diff --git a/model/webui.go b/model/webui.go index 368cd49..fd2bc09 100644 --- a/model/webui.go +++ b/model/webui.go @@ -1,5 +1,6 @@ package model +// Msg ... type Msg struct { Code int `json:"code"` Message string `json:"message"` diff --git a/tools/accessory.go b/tools/accessory.go deleted file mode 100644 index f4ccf2e..0000000 --- a/tools/accessory.go +++ /dev/null @@ -1,45 +0,0 @@ -package tools - -import "fmt" - -type AccessoryData struct { - AccessoryId int `xorm:"accessory_id"` - SmileMax int `xorm:"smile_max"` - PureMax int `xorm:"pure_max"` - CoolMax int `xorm:"cool_max"` -} - -type CommonAccessoryData struct { - AccessoryOwningUserId int `xorm:"accessory_owning_user_id pk autoincr"` - AccessoryId int `xorm:"accessory_id"` - Exp int `xorm:"exp"` -} - -func ProcessAccessoryData() { - var accessoryData []AccessoryData - err := MainEng.Table("accessory_m").Where("max_level = 8 AND rarity = 4").Cols("accessory_id,smile_max,pure_max,cool_max").Find(&accessoryData) - CheckErr(err) - - for _, data := range accessoryData { - var exp int - exists, err := MainEng.Table("accessory_level_m").Where("accessory_id = ?", data.AccessoryId).Select("MAX(next_exp)").Get(&exp) - CheckErr(err) - if !exists { - fmt.Println("LOL") - continue - } - commonData := CommonAccessoryData{ - AccessoryId: data.AccessoryId, - Exp: exp, - } - // fmt.Println(commonData) - // 每种饰品生成9个 - for i := 0; i < 9; i++ { - affected, err := MainEng.Table("common_accessory_m").Insert(&commonData) - CheckErr(err) - fmt.Printf("Time: %d, Aff: %d\n", i, affected) - - commonData.AccessoryOwningUserId += i + 1 - } - } -} diff --git a/tools/create.go b/tools/create.go deleted file mode 100644 index 501ec09..0000000 --- a/tools/create.go +++ /dev/null @@ -1,273 +0,0 @@ -package tools - -import ( - "encoding/json" - "fmt" - "honoka-chan/model" - "time" - - _ "github.com/mattn/go-sqlite3" -) - -type UnitData struct { - UnitOwningUserID int `xorm:"unit_owning_user_id pk autoincr" json:"unit_owning_user_id"` - UserID int `xorm:"user_id" json:"-"` - UnitID int `xorm:"unit_id" json:"unit_id"` - Exp int `xorm:"exp" json:"exp"` - NextExp int `xorm:"next_exp" json:"next_exp"` - Level int `xorm:"level" json:"level"` - MaxLevel int `xorm:"max_level" json:"max_level"` - LevelLimitID int `xorm:"level_limit_id" json:"level_limit_id"` - Rank int `xorm:"rank" json:"rank"` - MaxRank int `xorm:"max_rank" json:"max_rank"` - Love int `xorm:"love" json:"love"` - MaxLove int `xorm:"max_love" json:"max_love"` - UnitSkillExp int `xorm:"unit_skill_exp" json:"unit_skill_exp"` - UnitSkillLevel int `xorm:"unit_skill_level" json:"unit_skill_level"` - MaxHp int `xorm:"max_hp" json:"max_hp"` - UnitRemovableSkillCapacity int `xorm:"unit_removable_skill_capacity" json:"unit_removable_skill_capacity"` - FavoriteFlag bool `xorm:"favorite_flag" json:"favorite_flag"` - DisplayRank int `xorm:"display_rank" json:"display_rank"` - IsRankMax bool `xorm:"is_rank_max" json:"is_rank_max"` - IsLoveMax bool `xorm:"is_love_max" json:"is_love_max"` - IsLevelMax bool `xorm:"is_level_max" json:"is_level_max"` - IsSigned bool `xorm:"is_signed" json:"is_signed"` - IsSkillLevelMax bool `xorm:"is_skill_level_max" json:"is_skill_level_max"` - IsRemovableSkillCapacityMax bool `xorm:"is_removable_skill_capacity_max" json:"is_removable_skill_capacity_max"` - InsertDate string `xorm:"insert_date" json:"insert_date"` -} - -type UserDeckData struct { - ID int `xorm:"id pk autoincr"` - DeckID int `xorm:"deck_id"` - MainFlag int `xorm:"main_flag"` - DeckName string `xorm:"deck_name"` - UserID int `xorm:"user_id"` - InsertDate int64 `xorm:"insert_date"` -} - -type UnitDeckData struct { - ID int `xorm:"id pk autoincr" json:"-"` - UserDeckID int `xorm:"user_deck_id" json:"-"` - UnitOwningUserID int `xorm:"unit_owning_user_id" json:"unit_owning_user_id"` - UnitID int `xorm:"unit_id" json:"unit_id"` - Position int `xorm:"position" json:"position"` - Level int `xorm:"level" json:"level"` - LevelLimitID int `xorm:"level_limit_id" json:"level_limit_id"` - DisplayRank int `xorm:"display_rank" json:"display_rank"` - Love int `xorm:"love" json:"love"` - UnitSkillLevel int `xorm:"unit_skill_level" json:"unit_skill_level"` - IsRankMax bool `xorm:"is_rank_max" json:"is_rank_max"` - IsLoveMax bool `xorm:"is_love_max" json:"is_love_max"` - IsLevelMax bool `xorm:"is_level_max" json:"is_level_max"` - IsSigned bool `xorm:"is_signed" json:"is_signed"` - BeforeLove int `xorm:"before_love" json:"before_love"` - MaxLove int `xorm:"max_love" json:"max_love"` - InsertData int64 `xorm:"insert_date" json:"-"` -} - -type AlbumSeries struct { - UnitID int `json:"unit_id"` - AlbumSeriesID int `json:"album_series_id"` - Rarity int `json:"rarity"` - RankMin int `json:"rank_min"` - RankMax int `json:"rank_max"` - HpMax int `json:"hp_max"` - DefaultRemovableSkillCapacity int `json:"default_removable_skill_capacity"` -} - -func GenCommonUnitData2() { - sql := `SELECT unit_id,album_series_id,rarity,rank_min,rank_max,hp_max,default_removable_skill_capacity FROM unit_m WHERE unit_id NOT IN (SELECT unit_id FROM unit_m WHERE unit_type_id IN (SELECT unit_type_id FROM unit_type_m WHERE image_button_asset IS NULL AND (background_color = 'dcdbe3' AND original_attribute_id IS NULL) OR (unit_type_id IN (10,110,127,128,129) OR unit_type_id BETWEEN 131 AND 140))) ORDER BY unit_number ASC` - rows, err := MainEng.QueryInterface(sql) - CheckErr(err) - - rb, err := json.Marshal(rows) - CheckErr(err) - // fmt.Println(string(rb)) - - // 默认卡组 - userDeck := UserDeckData{ - DeckID: 1, - MainFlag: 1, - DeckName: "Default deck", - UserID: 1, - InsertDate: time.Now().Unix(), - } - _, err = UserEng.Table("user_deck_m").Insert(&userDeck) - CheckErr(err) - userDeckId := userDeck.ID - fmt.Println("userDeckId:", userDeckId) - - position := 1 - - albums := []AlbumSeries{} - if err = json.Unmarshal(rb, &albums); err != nil { - panic(err) - } - - startTime := time.Now().Add(-time.Hour * 24 * 30) - for _, v := range albums { - unitData := UnitData{} - startTime = startTime.Add(time.Second * 3) - - unitData.UnitID = v.UnitID - unitData.NextExp = 0 - unitData.Rank = v.RankMin - unitData.MaxRank = v.RankMax - unitData.MaxHp = v.HpMax - unitData.DisplayRank = 2 - unitData.UnitSkillLevel = 8 - unitData.FavoriteFlag = true - unitData.IsRankMax = true - unitData.IsLevelMax = true - unitData.IsLoveMax = true - unitData.IsSkillLevelMax = true - unitData.IsRemovableSkillCapacityMax = true - unitData.InsertDate = startTime.Local().Format("2006-01-02 03:04:05") - if v.Rarity != 4 { - unitData.LevelLimitID = 0 - unitData.UnitRemovableSkillCapacity = v.DefaultRemovableSkillCapacity - unitData.IsSigned = false - switch v.Rarity { - case 1: - // N - unitData.Exp = 8000 - unitData.Level = 40 - unitData.MaxLevel = 40 - unitData.Love = 50 - unitData.MaxLove = 50 - unitData.UnitSkillExp = 0 - unitData.UnitSkillLevel = 0 - unitData.FavoriteFlag = false - unitData.IsRankMax = false - unitData.IsLevelMax = false - unitData.IsLoveMax = false - unitData.IsSkillLevelMax = false - unitData.IsRemovableSkillCapacityMax = false - case 2: - // R - unitData.Exp = 13500 - unitData.Level = 60 - unitData.MaxLevel = 60 - unitData.Love = 200 - unitData.MaxLove = 200 - unitData.UnitSkillExp = 490 - case 3: - // SR - unitData.Exp = 36800 - unitData.Level = 80 - unitData.MaxLevel = 80 - unitData.Love = 500 - unitData.MaxLove = 500 - unitData.UnitSkillExp = 4900 - case 5: - // SSR - unitData.Exp = 56657 - unitData.Level = 90 - unitData.MaxLevel = 90 - unitData.Love = 750 - unitData.MaxLove = 750 - unitData.UnitSkillExp = 12700 - } - } else { - // UR - unitData.Exp = 79700 - unitData.Level = 100 - unitData.MaxLevel = 100 - unitData.LevelLimitID = 1 - unitData.Love = 1000 - unitData.MaxLove = 1000 - unitData.UnitSkillExp = 29900 - unitData.UnitRemovableSkillCapacity = 8 - - stmt, err := MainEng.DB().Prepare("SELECT COUNT(*) AS ct FROM unit_sign_asset_m WHERE unit_id = ?") - CheckErr(err) - defer stmt.Close() - - var ct int - err = stmt.QueryRow(v.UnitID).Scan(&ct) - CheckErr(err) - - if ct > 0 { - unitData.IsSigned = true - } else { - unitData.IsSigned = false - } - } - - _, err = MainEng.Table("common_unit_m").Insert(&unitData) - CheckErr(err) - // fmt.Println("Inserted ID:", unitData.UnitOwningUserID) - - // 默认卡组 - if v.AlbumSeriesID == 615 { // 仆光套 - unitDeckData := UnitDeckData{ - UserDeckID: userDeckId, - UnitOwningUserID: unitData.UnitOwningUserID, - UnitID: v.UnitID, - Position: position, - Level: 100, - LevelLimitID: 1, - DisplayRank: 2, - Love: 1000, - UnitSkillLevel: 8, - IsRankMax: true, - IsLoveMax: true, - IsLevelMax: true, - IsSigned: unitData.IsSigned, - BeforeLove: 1000, - MaxLove: 1000, - InsertData: time.Now().Unix(), - } - - // 入库 - _, err = UserEng.Table("deck_unit_m").Insert(&unitDeckData) - CheckErr(err) - deckUnitId := unitDeckData.ID - fmt.Println("deckUnitId:", deckUnitId) - - // - position++ - } - } -} - -func GenCommonUnitData3() { - uId := 1681205441 // Hardcode for now - userDeck := []UserDeckData{} - err := UserEng.Table("user_deck_m").Where("user_id = ?", uId).Asc("deck_id").Find(&userDeck) - CheckErr(err) - - unitDeckInfo := []model.UnitDeckInfoRes{} - for _, deck := range userDeck { - deckUnit := []UnitDeckData{} - err = UserEng.Table("deck_unit_m").Where("user_deck_id = ?", deck.ID).Asc("position").Find(&deckUnit) - CheckErr(err) - - oUids := []model.UnitOwningUserIds{} - for _, unit := range deckUnit { - oUids = append(oUids, model.UnitOwningUserIds{ - Position: unit.Position, - UnitOwningUserID: unit.UnitOwningUserID, - }) - } - - mainFlag := false - if deck.MainFlag == 1 { - mainFlag = true - } - unitDeckInfo = append(unitDeckInfo, model.UnitDeckInfoRes{ - UnitDeckID: deck.DeckID, - MainFlag: mainFlag, - DeckName: deck.DeckName, - UnitOwningUserIds: oUids, - }) - } - - b, err := json.Marshal(unitDeckInfo) - CheckErr(err) - fmt.Println(string(b)) -} - -func GenCommonUnitData() { -} diff --git a/tools/download.go b/tools/download.go deleted file mode 100644 index 647ca3f..0000000 --- a/tools/download.go +++ /dev/null @@ -1,72 +0,0 @@ -package tools - -import ( - "fmt" - "os" - "strings" - - _ "github.com/mattn/go-sqlite3" -) - -func GenDownloadDb() { - // Create table - // CREATE TABLE "download_m" ( - // "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, - // "pkg_type" integer, - // "pkg_id" integer, - // "pkg_order" integer, - // "pkg_size" integer, - // "pkg_os" TEXT - // ); - fileLists, err := os.ReadDir("F:/sif_dl/list_CN_Android") - CheckErr(err) - for _, v := range fileLists { - if v.IsDir() { - panic(err) - } - fileList := "F:/sif_dl/list_CN_Android/" + v.Name() - fileStat, err := os.Stat(fileList) - CheckErr(err) - pkgSize := fileStat.Size() - fileInfo := strings.Split(strings.ReplaceAll(v.Name(), ".zip", ""), "_") - pkgType, pkgId, pkgOrder := fileInfo[0], fileInfo[1], fileInfo[2] - fmt.Printf("Android: %s - %s - %s - %d\n", pkgType, pkgId, pkgOrder, pkgSize) - - stmt, err := MainEng.DB().Prepare("INSERT INTO download_m(pkg_type,pkg_id,pkg_order,pkg_size,pkg_os) VALUES (?,?,?,?,?)") - CheckErr(err) - defer stmt.Close() - - res, err := stmt.Exec(pkgType, pkgId, pkgOrder, pkgSize, "Android") - CheckErr(err) - - id, err := res.LastInsertId() - CheckErr(err) - fmt.Println("LastInsertId:", id) - } - - fileLists, err = os.ReadDir("F:/sif_dl/list_CN_iOS") - CheckErr(err) - for _, v := range fileLists { - if v.IsDir() { - panic(err) - } - fileList := "F:/sif_dl/list_CN_iOS/" + v.Name() - fileStat, err := os.Stat(fileList) - CheckErr(err) - pkgSize := fileStat.Size() - fileInfo := strings.Split(strings.ReplaceAll(v.Name(), ".zip", ""), "_") - pkgType, pkgId, pkgOrder := fileInfo[0], fileInfo[1], fileInfo[2] - fmt.Printf("iOS: %s - %s - %s - %d\n", pkgType, pkgId, pkgOrder, pkgSize) - - stmt, err := MainEng.DB().Prepare("INSERT INTO download_m(pkg_type,pkg_id,pkg_order,pkg_size,pkg_os) VALUES (?,?,?,?,?)") - CheckErr(err) - defer stmt.Close() - - res, err := stmt.Exec(pkgType, pkgId, pkgOrder, pkgSize, "iOS") - CheckErr(err) - - id, err := res.LastInsertId() - CheckErr(err) - fmt.Println("LastInsertId:", id) - } -} diff --git a/tools/gen.go b/tools/gen.go deleted file mode 100644 index 4cd4b2b..0000000 --- a/tools/gen.go +++ /dev/null @@ -1,1134 +0,0 @@ -package tools - -import ( - "encoding/json" - "fmt" - "honoka-chan/model" - "honoka-chan/utils" - "strings" - "time" - - _ "github.com/mattn/go-sqlite3" -) - -type DifficultyResult struct { - Difficulty int `json:"difficulty"` - ClearCnt int `json:"clear_cnt"` -} - -type DifficultyResp struct { - Result []DifficultyResult `json:"result"` - Status int `json:"status"` - CommandNum bool `json:"commandNum"` - TimeStamp int64 `json:"timeStamp"` -} - -type LoveResp struct { - Result []interface{} `json:"result"` - Status int `json:"status"` - CommandNum bool `json:"commandNum"` - TimeStamp int64 `json:"timeStamp"` -} - -type UserInfo struct { - UserID int `json:"user_id"` - Name string `json:"name"` - Level int `json:"level"` - CostMax int `json:"cost_max"` - UnitMax int `json:"unit_max"` - EnergyMax int `json:"energy_max"` - FriendMax int `json:"friend_max"` - UnitCnt int `json:"unit_cnt"` - InviteCode string `json:"invite_code"` - ElapsedTimeFromLogin string `json:"elapsed_time_from_login"` - Introduction string `json:"introduction"` -} - -type AccessoryInfo struct { - AccessoryOwningUserID int `json:"accessory_owning_user_id"` - AccessoryID int `json:"accessory_id"` - Exp int `json:"exp"` - NextExp int `json:"next_exp"` - Level int `json:"level"` - MaxLevel int `json:"max_level"` - RankUpCount int `json:"rank_up_count"` - FavoriteFlag bool `json:"favorite_flag"` -} - -type Costume struct { - UnitID int `json:"unit_id"` - IsRankMax bool `json:"is_rank_max"` - IsSigned bool `json:"is_signed"` -} - -type CenterUnitInfo struct { - UnitOwningUserID int `json:"unit_owning_user_id"` - UnitID int `json:"unit_id"` - Exp int `json:"exp"` - NextExp int `json:"next_exp"` - Level int `json:"level"` - LevelLimitID int `json:"level_limit_id"` - MaxLevel int `json:"max_level"` - Rank int `json:"rank"` - MaxRank int `json:"max_rank"` - Love int `json:"love"` - MaxLove int `json:"max_love"` - UnitSkillLevel int `json:"unit_skill_level"` - MaxHp int `json:"max_hp"` - FavoriteFlag bool `json:"favorite_flag"` - DisplayRank int `json:"display_rank"` - UnitSkillExp int `json:"unit_skill_exp"` - UnitRemovableSkillCapacity int `json:"unit_removable_skill_capacity"` - Attribute int `json:"attribute"` - Smile int `json:"smile"` - Cute int `json:"cute"` - Cool int `json:"cool"` - IsLoveMax bool `json:"is_love_max"` - IsLevelMax bool `json:"is_level_max"` - IsRankMax bool `json:"is_rank_max"` - IsSigned bool `json:"is_signed"` - IsSkillLevelMax bool `json:"is_skill_level_max"` - SettingAwardID int `json:"setting_award_id"` - RemovableSkillIds []int `json:"removable_skill_ids"` - AccessoryInfo AccessoryInfo `json:"accessory_info"` - Costume Costume `json:"costume"` - TotalSmile int `json:"total_smile"` - TotalCute int `json:"total_cute"` - TotalCool int `json:"total_cool"` - TotalHp int `json:"total_hp"` -} - -type NaviUnitInfo struct { - UnitOwningUserID int `json:"unit_owning_user_id"` - UnitID int `json:"unit_id"` - Exp int `json:"exp"` - NextExp int `json:"next_exp"` - Level int `json:"level"` - MaxLevel int `json:"max_level"` - LevelLimitID int `json:"level_limit_id"` - Rank int `json:"rank"` - MaxRank int `json:"max_rank"` - Love int `json:"love"` - MaxLove int `json:"max_love"` - UnitSkillExp int `json:"unit_skill_exp"` - UnitSkillLevel int `json:"unit_skill_level"` - MaxHp int `json:"max_hp"` - UnitRemovableSkillCapacity int `json:"unit_removable_skill_capacity"` - FavoriteFlag bool `json:"favorite_flag"` - DisplayRank int `json:"display_rank"` - IsRankMax bool `json:"is_rank_max"` - IsLoveMax bool `json:"is_love_max"` - IsLevelMax bool `json:"is_level_max"` - IsSigned bool `json:"is_signed"` - IsSkillLevelMax bool `json:"is_skill_level_max"` - IsRemovableSkillCapacityMax bool `json:"is_removable_skill_capacity_max"` - InsertDate string `json:"insert_date"` - TotalSmile int `json:"total_smile"` - TotalCute int `json:"total_cute"` - TotalCool int `json:"total_cool"` - TotalHp int `json:"total_hp"` - RemovableSkillIds []int `json:"removable_skill_ids"` -} - -type ProfileResult struct { - UserInfo UserInfo `json:"user_info"` - CenterUnitInfo CenterUnitInfo `json:"center_unit_info"` - NaviUnitInfo NaviUnitInfo `json:"navi_unit_info"` - IsAlliance bool `json:"is_alliance"` - FriendStatus int `json:"friend_status"` - SettingAwardID int `json:"setting_award_id"` - SettingBackgroundID int `json:"setting_background_id"` -} - -type ProfileResp struct { - Result ProfileResult `json:"result"` - Status int `json:"status"` - CommandNum bool `json:"commandNum"` - TimeStamp int64 `json:"timeStamp"` -} - -var ( - CenterId = 41674 -) - -func GenApi1Data() { - // global - var respAll []interface{} - - // live_status_result - var liveDifficultyId int - normalLives := []model.NormalLiveStatusList{} - sql := `SELECT live_difficulty_id FROM normal_live_m ORDER BY live_difficulty_id ASC` - rows, err := MainEng.DB().Query(sql) - CheckErr(err) - for rows.Next() { - err = rows.Scan(&liveDifficultyId) - CheckErr(err) - - normalLive := model.NormalLiveStatusList{ - LiveDifficultyID: liveDifficultyId, - Status: 1, - HiScore: 0, - HiComboCount: 0, - ClearCnt: 0, - AchievedGoalIDList: []int{}, - } - - normalLives = append(normalLives, normalLive) - } - - specialLives := []model.SpecialLiveStatusList{} - sql = `SELECT live_difficulty_id FROM special_live_m ORDER BY live_difficulty_id ASC` - rows, err = MainEng.DB().Query(sql) - CheckErr(err) - for rows.Next() { - err = rows.Scan(&liveDifficultyId) - CheckErr(err) - - specialLive := model.SpecialLiveStatusList{ - LiveDifficultyID: liveDifficultyId, - Status: 1, - HiScore: 0, - HiComboCount: 0, - ClearCnt: 0, - AchievedGoalIDList: []int{}, - } - - specialLives = append(specialLives, specialLive) - } - - LiveStatusResp := model.LiveStatusResp{ - // _ = model.LiveStatusResp{ - Result: model.LiveStatusRes{ - NormalLiveStatusList: normalLives, - SpecialLiveStatusList: specialLives, - TrainingLiveStatusList: []model.TrainingLiveStatusList{}, - MarathonLiveStatusList: []interface{}{}, - FreeLiveStatusList: []interface{}{}, - CanResumeLive: false, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, LiveStatusResp) - - // live_list_result - livesList := []model.LiveList{} - for _, v := range specialLives { - livesList = append(livesList, model.LiveList{ - LiveDifficultyID: v.LiveDifficultyID, - StartDate: "2023-01-01 00:00:00", - EndDate: "2037-01-01 00:00:00", - IsRandom: false, - }) - } - liveListResp := model.LiveScheduleResp{ - // _ = model.LiveScheduleResp{ - Result: model.LiveScheduleRes{ - EventList: []interface{}{}, - LiveList: livesList, - LimitedBonusList: []interface{}{}, - LimitedBonusCommonList: []model.LimitedBonusCommonList{}, // 特效道具 - RandomLiveList: []model.RandomLiveList{}, // 随机歌曲 - FreeLiveList: []interface{}{}, - TrainingLiveList: []model.TrainingLiveList{}, // 挑战歌曲 - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, liveListResp) - - // unit_list_result - unitsData := []model.Active{} - err = MainEng.Table("common_unit_m").Select("*").Find(&unitsData) - if err != nil { - panic(err) - } - - userUnits := []model.Active{} - err = UserEng.Table("user_unit_m").Select("*").Find(&userUnits) - if err != nil { - panic(err) - } - - unitsData = append(unitsData, userUnits...) - - unitListResp := model.UnitAllResp{ - // _ = model.UnitAllResp{ - Result: model.UnitAllRes{ - Active: unitsData, - Waiting: []model.Waiting{}, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, unitListResp) - - // unit_deck_result - uId := 1681205441 // Hardcode for now - userDeck := []UserDeckData{} - err = UserEng.Table("user_deck_m").Where("user_id = ?", uId).Asc("deck_id").Find(&userDeck) - CheckErr(err) - - unitDeckInfo := []model.UnitDeckInfoRes{} - for _, deck := range userDeck { - deckUnit := []UnitDeckData{} - err = UserEng.Table("deck_unit_m").Where("user_deck_id = ?", deck.ID).Asc("position").Find(&deckUnit) - CheckErr(err) - - oUids := []model.UnitOwningUserIds{} - for _, unit := range deckUnit { - oUids = append(oUids, model.UnitOwningUserIds{ - Position: unit.Position, - UnitOwningUserID: unit.UnitOwningUserID, - }) - } - - mainFlag := false - if deck.MainFlag == 1 { - mainFlag = true - } - unitDeckInfo = append(unitDeckInfo, model.UnitDeckInfoRes{ - UnitDeckID: deck.DeckID, - MainFlag: mainFlag, - DeckName: deck.DeckName, - UnitOwningUserIds: oUids, - }) - } - unitDeckResp := model.UnitDeckInfoResp{ - // _ = model.UnitDeckInfoResp{ - Result: unitDeckInfo, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, unitDeckResp) - - // unit_support_result - unitSupportResp := model.UnitSupportResp{ - // _ = model.UnitSupportResp{ - Result: model.UnitSupportRes{ - UnitSupportList: []model.UnitSupportList{}, - }, // 练习道具 - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, unitSupportResp) - - // owning_equip_result - rmSkillResp := model.RemovableSkillResp{ - // _ = model.RemovableSkillResp{ - Result: model.RemovableSkillRes{ - OwningInfo: []model.OwningInfo{}, - EquipmentInfo: map[int]interface{}{}, - }, // 宝石 - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, rmSkillResp) - - // costume_list_result - costumeListResp := model.CostumeListResp{ - // _ = model.CostumeListResp{ - Result: model.CostumeListRes{ - CostumeList: []model.CostumeList{}, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, costumeListResp) - - // album_unit_result - albumLists := []model.AlbumResult{} - sql = `SELECT unit_id,rarity FROM unit_m ORDER BY unit_id ASC` - rows, err = MainEng.DB().Query(sql) - CheckErr(err) - defer rows.Close() - for rows.Next() { - albumList := model.AlbumResult{ - RankMaxFlag: true, - LoveMaxFlag: true, - RankLevelMaxFlag: true, - AllMaxFlag: true, - FavoritePoint: 1000, - } - var uid, rit int - err = rows.Scan(&uid, &rit) - CheckErr(err) - albumList.UnitID = uid - if rit != 4 { - albumList.SignFlag = false - if rit == 1 { - albumList.HighestLovePerUnit = 50 - albumList.TotalLove = 50 - } else if rit == 2 { - albumList.HighestLovePerUnit = 200 - albumList.TotalLove = 200 - } else if rit == 3 { - albumList.HighestLovePerUnit = 500 - albumList.TotalLove = 500 - } else if rit == 5 { - albumList.HighestLovePerUnit = 750 - albumList.TotalLove = 750 - } - } else { - albumList.HighestLovePerUnit = 1000 - albumList.TotalLove = 1000 - - stmt, err := MainEng.DB().Prepare("SELECT COUNT(*) AS ct FROM unit_sign_asset_m WHERE unit_id = ?") - CheckErr(err) - defer stmt.Close() - - var count int - err = stmt.QueryRow(uid).Scan(&count) - CheckErr(err) - - if count > 0 { - albumList.SignFlag = true - } else { - albumList.SignFlag = false - } - } - - albumLists = append(albumLists, albumList) - } - - albumResp := model.AlbumResp{ - // _ = model.AlbumResp{ - Result: albumLists, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, albumResp) - - // scenario_status_result - sql = `SELECT scenario_id FROM scenario_m ORDER BY scenario_id ASC` - rows, err = MainEng.DB().Query(sql) - CheckErr(err) - defer rows.Close() - scenarioLists := []model.ScenarioStatusList{} - for rows.Next() { - var sid int - err = rows.Scan(&sid) - CheckErr(err) - scenarioLists = append(scenarioLists, model.ScenarioStatusList{ - ScenarioID: sid, - Status: 2, - }) - } - scenarioResp := model.ScenarioStatusResp{ - // _ = model.ScenarioStatusResp{ - Result: model.ScenarioStatusRes{ - ScenarioStatusList: scenarioLists, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, scenarioResp) - - // subscenario_status_result - sql = `SELECT subscenario_id FROM subscenario_m ORDER BY subscenario_id ASC` - rows, err = MainEng.DB().Query(sql) - CheckErr(err) - defer rows.Close() - subScenarioLists := []model.SubscenarioStatusList{} - for rows.Next() { - var sid int - err = rows.Scan(&sid) - CheckErr(err) - subScenarioLists = append(subScenarioLists, model.SubscenarioStatusList{ - SubscenarioID: sid, - Status: 2, - }) - } - subScenarioResp := model.SubscenarioStatusResp{ - // _ = model.SubscenarioStatusResp{ - Result: model.SubscenarioStatusRes{ - SubscenarioStatusList: subScenarioLists, - UnlockedSubscenarioIds: []interface{}{}, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, subScenarioResp) - - // event_scenario_result - eventsList := []model.EventScenarioList{} - sql = `SELECT event_id FROM event_scenario_m GROUP BY event_id ORDER BY event_id DESC` - rows, err = MainEng.DB().Query(sql) - CheckErr(err) - defer rows.Close() - for rows.Next() { - var eventId int - err = rows.Scan(&eventId) - CheckErr(err) - - sql = `SELECT event_scenario_id,chapter,chapter_asset,open_date FROM event_scenario_m WHERE event_id = ? ORDER BY chapter DESC` - chaps, err := MainEng.DB().Query(sql, eventId) - CheckErr(err) - defer chaps.Close() - chapsList := []model.EventScenarioChapterList{} - var open_date string - for chaps.Next() { - var event_scenario_id, chapter int - var chapter_asset interface{} - err = chaps.Scan(&event_scenario_id, &chapter, &chapter_asset, &open_date) - CheckErr(err) - chapList := model.EventScenarioChapterList{ - EventScenarioID: event_scenario_id, - Chapter: chapter, - Status: 2, - OpenFlashFlag: 0, - IsReward: false, - CostType: 1000, - ItemID: 1200, - Amount: 1, - } - if chapter_asset != nil { - chapList.ChapterAsset = chapter_asset.(string) - } - - chapsList = append(chapsList, chapList) - } - - eventList := model.EventScenarioList{ - EventID: eventId, - OpenDate: strings.ReplaceAll(open_date, "/", "-"), - ChapterList: chapsList, - } - - // HACK event_scenario_btn_asset - if eventId == 10001 { - eventList.EventScenarioBtnAsset = "assets/image/ui/eventscenario/38_se_ba_t.png" - } else if eventId == 221 { - eventList.EventScenarioBtnAsset = "assets/image/ui/eventscenario/215_se_ba_t.png" - } else { - eventList.EventScenarioBtnAsset = fmt.Sprintf("assets/image/ui/eventscenario/%d_se_ba_t.png", eventId) - } - - eventsList = append(eventsList, eventList) - } - eventScenarioResp := model.EventScenarioStatusResp{ - // _ = model.EventScenarioStatusResp{ - Result: model.EventScenarioStatusRes{ - EventScenarioList: eventsList, // - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, eventScenarioResp) - - // multi_unit_scenario_result - sql = `SELECT multi_unit_id FROM multi_unit_scenario_m GROUP BY multi_unit_id ORDER BY multi_unit_id ASC` - rows, err = MainEng.DB().Query(sql) - CheckErr(err) - defer rows.Close() - var mId int - multiUnitsList := []model.MultiUnitScenarioStatusList{} - for rows.Next() { - err = rows.Scan(&mId) - CheckErr(err) - - sql = `SELECT multi_unit_scenario_btn_asset,open_date,multi_unit_scenario_id,chapter FROM multi_unit_scenario_m a LEFT JOIN multi_unit_scenario_open_m b ON a.multi_unit_id = b.multi_unit_id WHERE a.multi_unit_id = ?` - units, err := MainEng.DB().Query(sql, mId) - CheckErr(err) - defer units.Close() - var multi_unit_scenario_id, chapter int - var multi_unit_scenario_btn_asset, open_date string - for units.Next() { - err = units.Scan(&multi_unit_scenario_btn_asset, &open_date, &multi_unit_scenario_id, &chapter) - CheckErr(err) - } - - multiUnitsList = append(multiUnitsList, model.MultiUnitScenarioStatusList{ - MultiUnitID: mId, - Status: 2, - MultiUnitScenarioBtnAsset: multi_unit_scenario_btn_asset, - OpenDate: strings.ReplaceAll(open_date, "/", "-"), - ChapterList: []model.MultiUnitScenarioChapterList{ - { - MultiUnitScenarioID: multi_unit_scenario_id, - Chapter: chapter, - Status: 2, - }, - }, - }) - } - unitsResp := model.MultiUnitScenarioStatusResp{ - // _ = model.MultiUnitScenarioStatusResp{ - Result: model.MultiUnitScenarioStatusRes{ - MultiUnitScenarioStatusList: multiUnitsList, - UnlockedMultiUnitScenarioIds: []interface{}{}, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, unitsResp) - - // product_result - productResp := model.ProductListResp{ - // _ = model.ProductListResp{ - Result: model.ProductListRes{ - RestrictionInfo: model.RestrictionInfo{ - Restricted: false, - }, - UnderAgeInfo: model.UnderAgeInfo{ - BirthSet: false, - HasLimit: false, - LimitAmount: nil, - MonthUsed: 0, - }, - SnsProductList: []model.SnsProductList{}, - ProductList: []model.ProductList{}, - SubscriptionList: []model.SubscriptionList{}, - ShowPointShop: false, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, productResp) - - // banner_result - bannerResp := model.BannerListResp{ - // _ = model.BannerListResp{ - Result: model.BannerListRes{ - TimeLimit: "2037-12-31 23:59:59", - BannerList: []model.BannerList{ - { - BannerType: 1, - TargetID: 1743, - AssetPath: "assets/image/secretbox/icon/s_ba_1743_1.png", - FixedFlag: false, - BackSide: false, - BannerID: 101151, - StartDate: "2013-04-15 00:00:00", - EndDate: "2037-12-31 23:59:59", - AddUnitStartDate: "2022-01-01 00:00:00", - }, - { - BannerType: 2, - TargetID: 1, - AssetPath: "assets/image/webview/wv_ba_01.png", - WebviewURL: "/manga", - FixedFlag: false, - BackSide: true, - BannerID: 200001, - StartDate: "2016-10-15 15:00:00", - EndDate: "2037-12-31 23:59:59", - }, - }, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, bannerResp) - - // item_marquee_result - marqueeResp := model.NoticeMarqueeResp{ - // _ = model.NoticeMarqueeResp{ - Result: model.NoticeMarqueeRes{ - ItemCount: 0, - MarqueeList: []interface{}{}, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, marqueeResp) - - // user_intro_result - userIntroResp := model.UserNaviResp{ - // _ = model.UserNaviResp{ - Result: model.UserNaviRes{ - User: model.User{ - UserID: 9999999, - UnitOwningUserID: CenterId, - }, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, userIntroResp) - - // special_cutin_result - cutinResp := model.SpecialCutinResp{ - // _ = model.SpecialCutinResp{ - Result: model.SpecialCutinRes{ - SpecialCutinList: []interface{}{}, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, cutinResp) - - // award_result - sql = `SELECT award_id FROM award_m ORDER BY award_id ASC` - rows, err = MainEng.DB().Query(sql) - CheckErr(err) - defer rows.Close() - awardsList := []model.AwardInfo{} - for rows.Next() { - var aId int - err = rows.Scan(&aId) - CheckErr(err) - isSet := false - if aId == 113 { // 极推穗乃果 - isSet = true - } - awardsList = append(awardsList, model.AwardInfo{ - AwardID: aId, - IsSet: isSet, - InsertDate: time.Now().Format("2006-01-02 03:04:05"), - }) - } - awardResp := model.AwardInfoResp{ - // _ = model.AwardInfoResp{ - Result: model.AwardInfoRes{ - AwardInfo: awardsList, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, awardResp) - - // background_result - sql = `SELECT background_id FROM background_m ORDER BY background_id ASC` - rows, err = MainEng.DB().Query(sql) - CheckErr(err) - defer rows.Close() - backgroundsList := []model.BackgroundInfo{} - for rows.Next() { - var bId int - err = rows.Scan(&bId) - CheckErr(err) - isSet := false - if bId == 143 { // 穗乃果的房间[情人节] - isSet = true - } - backgroundsList = append(backgroundsList, model.BackgroundInfo{ - BackgroundID: bId, - IsSet: isSet, - InsertDate: time.Now().Format("2006-01-02 03:04:05"), - }) - } - backgroundResp := model.BackgroundInfoResp{ - // _ = model.BackgroundInfoResp{ - Result: model.BackgroundInfoRes{ - BackgroundInfo: backgroundsList, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, backgroundResp) - - // stamp_result 使用不到的功能就不弄了 - stampResp := utils.ReadAllText("assets/stamp.json") - var mStampResp interface{} - err = json.Unmarshal([]byte(stampResp), &mStampResp) - CheckErr(err) - // _ = utils.ReadAllText("assets/stamp.json") - respAll = append(respAll, mStampResp) - - // exchange_point_result - sql = `SELECT exchange_point_id FROM exchange_point_m ORDER BY exchange_point_id ASC` - rows, err = MainEng.DB().Query(sql) - CheckErr(err) - defer rows.Close() - exPointsList := []model.ExchangePointList{} - for rows.Next() { - var eId int - err = rows.Scan(&eId) - CheckErr(err) - exPointsList = append(exPointsList, model.ExchangePointList{ - Rarity: eId, - ExchangePoint: 9999, - }) - } - exPointsResp := model.ExchangePointResp{ - // _ = model.ExchangePointResp{ - Result: model.ExchangePointRes{ - ExchangePointList: exPointsList, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, exPointsResp) - - // live_se_result - liveSeResp := model.LiveSeInfoResp{ - // _ = model.LiveSeInfoResp{ - Result: model.LiveSeInfoRes{ - LiveSeList: []int{1, 2, 3}, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, liveSeResp) - - // live_icon_result - liveIconResp := model.LiveIconInfoResp{ - // _ = model.LiveIconInfoResp{ - Result: model.LiveIconInfoRes{ - LiveNotesIconList: []int{1, 2, 3}, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, liveIconResp) - - // item_list_result 暂时不知道部分字段啥逻辑 - itemResp := utils.ReadAllText("assets/item.json") - // _ = utils.ReadAllText("assets/item.json") - var mItemResp interface{} - err = json.Unmarshal([]byte(itemResp), &mItemResp) - CheckErr(err) - respAll = append(respAll, mItemResp) - - // marathon_result - marathonResp := model.MarathonInfoResp{ - // _ = model.MarathonInfoResp{ - Result: []interface{}{}, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, marathonResp) - - // challenge_result - challengeResp := model.ChallengeInfoResp{ - // _ = model.ChallengeInfoResp{ - Result: []interface{}{}, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, challengeResp) - - // Final - k, err := json.Marshal(respAll) - CheckErr(err) - resp := model.ApiResp{ - ResponseData: k, - ReleaseInfo: []interface{}{}, - StatusCode: 200, - } - k, err = json.Marshal(resp) - CheckErr(err) - // fmt.Println(string(k)) - - utils.WriteAllText("assets/api1.json", string(k)) -} - -func GenApi2Data() { - // global - var respAll []interface{} - - // login_topinfo_result - topInfoResp := model.TopInfoResp{ - // _ = model.TopInfoResp{ - Result: model.TopInfoRes{ - FriendActionCnt: 0, - FriendGreetCnt: 0, - FriendVarietyCnt: 0, - FriendNewCnt: 0, - PresentCnt: 0, - SecretBoxBadgeFlag: false, - ServerDatetime: time.Now().Format("2006-01-02 15:04:05"), - ServerTimestamp: time.Now().Unix(), - NoticeFriendDatetime: time.Now().Format("2006-01-02 15:04:05"), - NoticeMailDatetime: "2000-01-01 12:00:00", - FriendsApprovalWaitCnt: 0, - FriendsRequestCnt: 0, - IsTodayBirthday: false, - LicenseInfo: model.TopInfoLicenseInfo{ - LicenseList: []interface{}{}, - LicensedInfo: []interface{}{}, - ExpiredInfo: []interface{}{}, - BadgeFlag: false, - }, - UsingBuffInfo: []interface{}{}, - IsKlabIDTaskFlag: false, - KlabIDTaskCanSync: false, - HasUnreadAnnounce: false, - ExchangeBadgeCnt: []int{0, 0, 0}, - AdFlag: false, - HasAdReward: false, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, topInfoResp) - - // login_topinfo_once_result - topInfoOnceResp := model.TopInfoOnceResp{ - // _ = model.TopInfoOnceResp{ - Result: model.TopInfoOnceRes{ - NewAchievementCnt: 0, - UnaccomplishedAchievementCnt: 0, - LiveDailyRewardExist: false, - TrainingEnergy: 10, - TrainingEnergyMax: 10, - Notification: model.TopInfoOnceNotification{ - Push: false, - Lp: false, - UpdateInfo: false, - Campaign: false, - Live: false, - Lbonus: false, - Event: false, - Secretbox: false, - Birthday: true, - }, - OpenArena: true, - CostumeStatus: true, - OpenAccessory: true, - ArenaSiSkillUniqueCheck: true, - OpenV98: true, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, topInfoOnceResp) - - // unit_accessory_result - unitAccResp := model.UnitAccessoryAllResp{ - // _ = model.UnitAccessoryAllResp{ - Result: model.UnitAccessoryAllResult{ - AccessoryList: []model.AccessoryList{}, - WearingInfo: []model.WearingInfo{}, - EspecialCreateFlag: false, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, unitAccResp) - - // museum_result - sql := `SELECT museum_contents_id,smile_buff,pure_buff,cool_buff FROM museum_contents_m ORDER BY museum_contents_id ASC` - rows, err := MainEng.DB().Query(sql) - CheckErr(err) - defer rows.Close() - var smileBuf, pureBuf, coolBuf int - var mIds []int - for rows.Next() { - var museum_contents_id, smile_buff, pure_buff, cool_buff int - err = rows.Scan(&museum_contents_id, &smile_buff, &pure_buff, &cool_buff) - CheckErr(err) - smileBuf += smile_buff - pureBuf += pure_buff - coolBuf += cool_buff - mIds = append(mIds, museum_contents_id) - } - - museumInfoResp := model.MuseumInfoResp{ - Result: model.MuseumInfoRes{ - MuseumInfo: model.Museum{ - Parameter: model.MuseumParameter{ - Smile: smileBuf, - Pure: pureBuf, - Cool: coolBuf, - }, - ContentsIDList: mIds, - }, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, museumInfoResp) - - // Final - k, err := json.Marshal(respAll) - CheckErr(err) - resp := model.ApiResp{ - ResponseData: k, - ReleaseInfo: []interface{}{}, - StatusCode: 200, - } - k, err = json.Marshal(resp) - CheckErr(err) - // fmt.Println(string(k)) - - utils.WriteAllText("assets/api2.json", string(k)) -} - -func GenApi3Data() { - // global - var respAll []interface{} - - // profile_livecnt_result - difficultyResp := DifficultyResp{ - // _ = DifficultyResp{ - Result: []DifficultyResult{ - { - Difficulty: 1, - ClearCnt: 315, - }, - { - Difficulty: 2, - ClearCnt: 310, - }, - { - Difficulty: 3, - ClearCnt: 314, - }, - { - Difficulty: 4, - ClearCnt: 455, - }, - { - Difficulty: 6, - ClearCnt: 233, - }, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, difficultyResp) - - // profile_card_ranking_result - var result []interface{} - love := utils.ReadAllText("assets/love.json") - err := json.Unmarshal([]byte(love), &result) - CheckErr(err) - loveResp := LoveResp{ - // _ = LoveResp{ - Result: result, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, loveResp) - - // profile_info_result - profileResp := ProfileResp{ - Result: ProfileResult{ - UserInfo: UserInfo{ - UserID: 9999999, // 3241988 - Name: "\u68a6\u8def @\u65c5\u7acb\u3061\u306e\u65e5\u306b", - Level: 1028, - CostMax: 100, - UnitMax: 5000, - EnergyMax: 417, - FriendMax: 99, - UnitCnt: 3898, - InviteCode: "377385143", - ElapsedTimeFromLogin: "14\u5c0f\u65f6\u524d", - Introduction: "\u5728\u4e0d\u77e5\u4e0d\u89c9\u4e2d \u65f6\u5149\u4ece\u4e0d\u505c\u7559\\n\u5982\u4eca\u7684\u6211\u4eec \u6bd5\u4e1a\u518d\u56de\u9996\\n\u8ffd\u68a6\u7684\u670b\u53cb\u4eec\u4e00\u540c \u8e0f\u4e0a\u4e86\u65b0\u7684\u5f81\u9014\\n\u5728\u4e0d\u4e45\u7684\u4eca\u540e \u5728\u672a\u77e5\u7684\u67d0\u5904\\n \u6211\u4eec\u4e00\u5b9a\u4f1a\u518d\u4e00\u6b21\u9082\u9005\\n \u8bf7\u4e0d\u8981\u5fd8\u8bb0\u6211\u4eec \u66fe\u7ecf\u7684\u7b11\u5bb9\r", - }, - CenterUnitInfo: CenterUnitInfo{ - UnitOwningUserID: CenterId, - UnitID: 3927, - Exp: 79700, - NextExp: 0, - Level: 100, - LevelLimitID: 1, - MaxLevel: 100, - Rank: 2, - MaxRank: 2, - Love: 1000, - MaxLove: 1000, - UnitSkillLevel: 8, - MaxHp: 6, - FavoriteFlag: true, - DisplayRank: 2, - UnitSkillExp: 29900, - UnitRemovableSkillCapacity: 8, - Attribute: 1, - Smile: 1, - Cute: 1, - Cool: 1, - IsLoveMax: true, - IsLevelMax: true, - IsRankMax: true, - IsSigned: true, - IsSkillLevelMax: true, - SettingAwardID: 113, - RemovableSkillIds: []int{}, - AccessoryInfo: AccessoryInfo{}, - Costume: Costume{}, - TotalSmile: 1, - TotalCute: 1, - TotalCool: 1, - TotalHp: 6, - }, - NaviUnitInfo: NaviUnitInfo{ - UnitOwningUserID: CenterId, - UnitID: 3927, - Exp: 79700, - NextExp: 0, - Level: 100, - MaxLevel: 100, - LevelLimitID: 1, - Rank: 2, - MaxRank: 2, - Love: 1000, - MaxLove: 1000, - UnitSkillExp: 29900, - UnitSkillLevel: 8, - MaxHp: 6, - UnitRemovableSkillCapacity: 8, - FavoriteFlag: true, - DisplayRank: 2, - IsLoveMax: true, - IsLevelMax: true, - IsRankMax: true, - IsSigned: true, - IsSkillLevelMax: true, - IsRemovableSkillCapacityMax: true, - InsertDate: "2016-10-11 10:33:03", - TotalSmile: 1, - TotalCute: 1, - TotalCool: 1, - TotalHp: 6, - RemovableSkillIds: []int{}, - }, - IsAlliance: false, - FriendStatus: 0, - SettingAwardID: 113, - SettingBackgroundID: 143, - }, - Status: 200, - CommandNum: false, - TimeStamp: time.Now().Unix(), - } - respAll = append(respAll, profileResp) - - // Final - k, err := json.Marshal(respAll) - CheckErr(err) - resp := model.ApiResp{ - ResponseData: k, - ReleaseInfo: []interface{}{}, - StatusCode: 200, - } - k, err = json.Marshal(resp) - CheckErr(err) - // fmt.Println(string(k)) - - utils.WriteAllText("assets/api3.json", string(k)) -} diff --git a/tools/init.go b/tools/init.go index f67df93..ef353dd 100644 --- a/tools/init.go +++ b/tools/init.go @@ -2,6 +2,8 @@ package tools import ( "fmt" + "honoka-chan/config" + "honoka-chan/model" "time" ) @@ -30,14 +32,14 @@ type UserPref struct { func InitUserData(userId int) { userList := []UserData{} if userId != 0 { - err := UserEng.Table("users").Where("userid = ?", userId).Find(&userList) + err := config.UserEng.Table("users").Where("userid = ?", userId).Find(&userList) CheckErr(err) } else { - err := UserEng.Table("users").Asc("id").Find(&userList) + err := config.UserEng.Table("users").Asc("id").Find(&userList) CheckErr(err) } - session := UserEng.NewSession() + session := config.UserEng.NewSession() defer session.Close() if err := session.Begin(); err != nil { @@ -46,13 +48,13 @@ func InitUserData(userId int) { for _, user := range userList { // 检查用户配置 - exists, err := UserEng.Table("user_preference_m").Where("user_id = ?", user.UserID).Exist() + exists, err := config.UserEng.Table("user_preference_m").Where("user_id = ?", user.UserID).Exist() CheckErr(err) if !exists { // 默认中心成员() var oId int - _, err = MainEng.Table("common_unit_m").Cols("unit_owning_user_id").Where("unit_id = ?", 31).Get(&oId) + _, err = config.MainEng.Table("common_unit_m").Cols("unit_owning_user_id").Where("unit_id = ?", 31).Get(&oId) CheckErr(err) fmt.Println("Center UnitOwningUserID:", oId) userPref := UserPref{ @@ -71,12 +73,12 @@ func InitUserData(userId int) { } // 检查用户卡组配置 - exists, err = UserEng.Table("user_deck_m").Where("user_id = ?", user.UserID).Asc("deck_id").Exist() + exists, err = config.UserEng.Table("user_deck_m").Where("user_id = ?", user.UserID).Asc("deck_id").Exist() CheckErr(err) fmt.Println("UserDeck exists:", exists) if !exists { - userDeck := UserDeckData{ + userDeck := model.UserDeckData{ DeckID: 1, MainFlag: 1, DeckName: "队伍A", @@ -95,14 +97,14 @@ func InitUserData(userId int) { // 默认卡组 unitIds := []int{} - err = MainEng.Table("unit_m").Cols("unit_id").Where("album_series_id = ?", 615).Find(&unitIds) + err = config.MainEng.Table("unit_m").Cols("unit_id").Where("album_series_id = ?", 615).Find(&unitIds) if err != nil { session.Rollback() panic(err) } - unitData := []UnitData{} - err = MainEng.Table("common_unit_m").In("unit_id", unitIds).Find(&unitData) + unitData := []model.UnitData{} + err = config.MainEng.Table("common_unit_m").In("unit_id", unitIds).Find(&unitData) if err != nil { session.Rollback() panic(err) @@ -111,7 +113,7 @@ func InitUserData(userId int) { position := 1 for _, unit := range unitData { - unitDeckData := UnitDeckData{ + unitDeckData := model.UnitDeckData{ UserDeckID: userDeckId, UnitOwningUserID: unit.UnitOwningUserID, UnitID: unit.UnitID, diff --git a/tools/notes.go b/tools/notes.go deleted file mode 100644 index 9a55d91..0000000 --- a/tools/notes.go +++ /dev/null @@ -1,97 +0,0 @@ -package tools - -import ( - "fmt" - "honoka-chan/utils" - "io" - "net/http" - "os" - "path" - "regexp" - "strings" - "time" - - _ "github.com/mattn/go-sqlite3" - "github.com/tidwall/gjson" -) - -func SyncNotesList() { - defer func() { - fmt.Println("Sync notes list done!") - }() - - sql := `SELECT live_setting_id,notes_setting_asset FROM live_setting_m ORDER BY live_setting_id ASC` - rows, err := MainEng.DB().Query(sql) - CheckErr(err) - defer rows.Close() - - liveList := make(map[int]string) - - for rows.Next() { - var id int - var asset string - err = rows.Scan(&id, &asset) - if err != nil { - fmt.Println(err) - continue - } - liveList[id] = asset - } - rows.Close() - - // fmt.Println(liveList) - - for _, asset := range liveList { - url := "https://card.niconi.co.ni/live/" + asset - fmt.Println(url) - - res, err := http.Get(url) - if err != nil { - fmt.Println(err) - continue - } - if res.StatusCode == http.StatusNotFound { - fmt.Println(res.StatusCode) - continue - } - body, err := io.ReadAll(res.Body) - if err != nil { - fmt.Println(err) - continue - } - _ = res.Body.Close() - // fmt.Println(string(body)) - - regex := regexp.MustCompile("var lives = (.*?)\n") - matchs := regex.FindSubmatch(body) - match := string(matchs[len(matchs)-1]) - - match = strings.ReplaceAll(match, "{\\\"", "{\"") - match = strings.ReplaceAll(match, "\\\":", "\":") - match = strings.ReplaceAll(match, ",\\\"", ",\"") - match = strings.ReplaceAll(match, "notes_list\":\"", "notes_list\":") - match = strings.ReplaceAll(match, "]\"}]", "]}]") - - var notesList string - gjson.Parse(match).ForEach(func(key, value gjson.Result) bool { - notesList = value.Get("notes_list").String() - return true - }) - // fmt.Println(notesList) - - if notesList == "" { - fmt.Println("notes_list is null") - continue - } - - notesDir := "./assets/notes" - _, err = os.Stat(notesDir) - if err != nil { - err = os.MkdirAll(notesDir, 0755) - CheckErr(err) - } - utils.WriteAllText(path.Join(notesDir, asset), notesList) - - time.Sleep(time.Second) - } -} diff --git a/tools/tools.go b/tools/tools.go index 1d641c5..f67cc82 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -1,25 +1,7 @@ package tools -import ( - "honoka-chan/config" - - "xorm.io/xorm" -) - -var ( - MainEng *xorm.Engine - UserEng *xorm.Engine -) - func init() { - MainEng = config.MainEng - UserEng = config.UserEng - - // go SyncNotesList() - // GenDownloadDb() - // GenCommonUnitData() InitUserData(0) - // ProcessAccessoryData() } func CheckErr(err error) {