Overhaul [1/n]

Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
2026-01-29 02:42:28 +08:00
parent 989acd6ff1
commit c77241a883
2267 changed files with 7158 additions and 5583 deletions
@@ -1,39 +1,38 @@
package handler
package album
import (
"honoka-chan/internal/model"
"honoka-chan/internal/middleware"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/album"
"honoka-chan/internal/session"
"honoka-chan/internal/utils"
"github.com/gin-gonic/gin"
)
type AlbumRes struct {
UnitId int `xorm:"unit_id"`
Rarity int `xorm:"rarity"`
}
func AlbumSeriesAll(ctx *gin.Context) {
ss := session.New(ctx)
func seriesAll(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
var albumIds []int
err := ss.MainEng.Table("album_series_m").Select("album_series_id").Find(&albumIds)
var albumID []int
err := ss.MainEng.Table("album_series_m").Select("album_series_id").Find(&albumID)
if ss.CheckErr(err) {
return
}
albumSeriesAllRes := []model.AlbumSeriesRes{}
for _, albumId := range albumIds {
unitList := []AlbumRes{}
err = ss.MainEng.Table("unit_m").Where("album_series_id = ?", albumId).Cols("unit_id,rarity").Find(&unitList)
albumSeriesAllRes := []album.SeriesAllData{}
for _, id := range albumID {
var unitList []struct {
UnitId int `xorm:"unit_id"`
Rarity int `xorm:"rarity"`
}
err = ss.MainEng.Table("unit_m").Where("album_series_id = ?", id).Cols("unit_id,rarity").Find(&unitList)
if ss.CheckErr(err) {
return
}
albumSeriesAll := []model.AlbumResult{}
albumSeriesAll := []album.UnitList{}
for _, unit := range unitList {
albumSeries := model.AlbumResult{
albumSeries := album.UnitList{
UnitID: unit.UnitId,
RankMaxFlag: true,
LoveMaxFlag: true,
@@ -63,23 +62,29 @@ func AlbumSeriesAll(ctx *gin.Context) {
albumSeries.HighestLovePerUnit = 1000
// IsSigned
albumSeries.SignFlag = utils.IsSigned(unit.UnitId)
albumSeries.SignFlag, err = ss.MainEng.Table("unit_sign_asset_m").Where("unit_id = ?", unit.UnitId).Exist()
if ss.CheckErr(err) {
return
}
}
albumSeriesAll = append(albumSeriesAll, albumSeries)
}
albumSeriesAllRes = append(albumSeriesAllRes, model.AlbumSeriesRes{
SeriesID: albumId,
albumSeriesAllRes = append(albumSeriesAllRes, album.SeriesAllData{
SeriesID: id,
UnitList: albumSeriesAll,
})
}
resp := model.AlbumSeriesResp{
ss.Respond(album.SeriesAllResp{
ResponseData: albumSeriesAllRes,
ReleaseInfo: []any{},
StatusCode: 200,
}
})
}
ss.Respond(resp)
func init() {
router.AddHandler("main.php", "POST", "/album/seriesAll", middleware.Common, seriesAll)
}
+29
View File
@@ -0,0 +1,29 @@
package announce
import (
"honoka-chan/internal/middleware"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/announce"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func checkState(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
ss.Respond(announce.CheckStateDataResp{
ResponseData: announce.CheckStateData{
HasUnreadAnnounce: false,
ServerTimestamp: time.Now().Unix(),
},
ReleaseInfo: []any{},
StatusCode: 200,
})
}
func init() {
router.AddHandler("main.php", "POST", "/announce/checkState", middleware.Common, checkState)
}
@@ -1,16 +1,14 @@
package handler
package announce
import (
"honoka-chan/internal/model"
"honoka-chan/internal/session"
"honoka-chan/internal/router"
"html/template"
"net/http"
"time"
"github.com/gin-gonic/gin"
)
func AnnounceIndex(ctx *gin.Context) {
func index(ctx *gin.Context) {
ctx.HTML(http.StatusOK, "common/announce.html", gin.H{
"title": "Love Live! 学园偶像祭 本地服务器",
"content": template.HTML(`目前开发完毕的功能包括<br><ul><li>登录</li><li>相册</li><li>编队</li><li>饰品</li><li>宝石</li><li>Live</li><li>个人信息设置</li><li>官方漫画</li><ul><br>
@@ -19,18 +17,6 @@ func AnnounceIndex(ctx *gin.Context) {
})
}
func AnnounceCheckState(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
resp := model.AnnounceResp{
ResponseData: model.AnnounceRes{
HasUnreadAnnounce: false,
ServerTimestamp: time.Now().Unix(),
},
ReleaseInfo: []any{},
StatusCode: 200,
}
ss.Respond(resp)
func init() {
router.AddHandler("webview.php", "GET", "/announce/index", index)
}
File diff suppressed because it is too large Load Diff
+17
View File
@@ -0,0 +1,17 @@
package album
import (
"fmt"
"github.com/gin-gonic/gin"
)
func AlbumApi(ctx *gin.Context, action string) (res any, err error) {
switch action {
case "albumAll":
res, err = albumAll(ctx)
default:
err = fmt.Errorf("unimplemented action: album: %s", action)
}
return res, err
}
+70
View File
@@ -0,0 +1,70 @@
package album
import (
"honoka-chan/internal/schema/api/album"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func albumAll(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
albumLists := []album.UnitList{}
var unitList []struct {
UnitId int `xorm:"unit_id"`
Rarity int `xorm:"rarity"`
}
err = ss.MainEng.Table("unit_m").Cols("unit_id,rarity").OrderBy("unit_id ASC").Find(&unitList)
if err != nil {
return nil, err
}
for _, unit := range unitList {
albumList := album.UnitList{
RankMaxFlag: true,
LoveMaxFlag: true,
RankLevelMaxFlag: true,
AllMaxFlag: true,
FavoritePoint: 1000,
}
albumList.UnitID = unit.UnitId
if unit.Rarity != 4 {
albumList.SignFlag = false
switch unit.Rarity {
case 1:
albumList.HighestLovePerUnit = 50
albumList.TotalLove = 50
case 2:
albumList.HighestLovePerUnit = 200
albumList.TotalLove = 200
case 3:
albumList.HighestLovePerUnit = 500
albumList.TotalLove = 500
case 5:
albumList.HighestLovePerUnit = 750
albumList.TotalLove = 750
}
} else {
albumList.HighestLovePerUnit = 1000
albumList.TotalLove = 1000
// IsSigned
albumList.SignFlag, err = ss.MainEng.Table("unit_sign_asset_m").Where("unit_id = ?", unit.UnitId).Exist()
if err != nil {
return nil, err
}
}
albumLists = append(albumLists, albumList)
}
res = album.AllResp{
Result: albumLists,
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+125
View File
@@ -0,0 +1,125 @@
package api
import (
"encoding/json"
"fmt"
"honoka-chan/internal/handler/api/album"
"honoka-chan/internal/handler/api/award"
"honoka-chan/internal/handler/api/background"
"honoka-chan/internal/handler/api/banner"
"honoka-chan/internal/handler/api/challenge"
"honoka-chan/internal/handler/api/costume"
"honoka-chan/internal/handler/api/eventscenario"
"honoka-chan/internal/handler/api/exchange"
"honoka-chan/internal/handler/api/item"
"honoka-chan/internal/handler/api/live"
"honoka-chan/internal/handler/api/liveicon"
"honoka-chan/internal/handler/api/livese"
"honoka-chan/internal/handler/api/login"
"honoka-chan/internal/handler/api/marathon"
"honoka-chan/internal/handler/api/multiunit"
"honoka-chan/internal/handler/api/museum"
"honoka-chan/internal/handler/api/navigation"
"honoka-chan/internal/handler/api/notice"
"honoka-chan/internal/handler/api/payment"
"honoka-chan/internal/handler/api/profile"
"honoka-chan/internal/handler/api/scenario"
"honoka-chan/internal/handler/api/stamp"
"honoka-chan/internal/handler/api/subscenario"
"honoka-chan/internal/handler/api/unit"
"honoka-chan/internal/handler/api/user"
"honoka-chan/internal/middleware"
"honoka-chan/internal/router"
apischema "honoka-chan/internal/schema/api"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
)
func api(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
apiReq := []apischema.ApiReq{}
err := json.Unmarshal([]byte(ctx.MustGet("request_data").(string)), &apiReq)
if ss.CheckErr(err) {
return
}
var result any
var results []any
for _, v := range apiReq {
// fmt.Println(v.Module, v.Action)
switch v.Module {
case "album":
result, err = album.AlbumApi(ctx, v.Action)
case "award":
result, err = award.AwardApi(ctx, v.Action)
case "background":
result, err = background.BackgroundApi(ctx, v.Action)
case "banner":
result, err = banner.BannerApi(v.Action)
case "challenge":
result, err = challenge.ChallengeApi(v.Action)
case "costume":
result, err = costume.CostumeApi(v.Action)
case "eventscenario":
result, err = eventscenario.EventScenarioApi(ctx, v.Action)
case "exchange":
result, err = exchange.ExchangeApi(ctx, v.Action)
case "item":
result, err = item.ItemApi(v.Action)
case "live":
result, err = live.LiveApi(ctx, v.Action)
case "liveicon":
result, err = liveicon.LiveIconApi(v.Action)
case "livese":
result, err = livese.LiveSeApi(v.Action)
case "login":
result, err = login.LoginApi(v.Action)
case "marathon":
result, err = marathon.MarathonApi(v.Action)
case "multiunit":
result, err = multiunit.MultiUnitApi(ctx, v.Action)
case "museum":
result, err = museum.MuseumApi(ctx, v.Action)
case "navigation":
result, err = navigation.NavigationApi(v.Action)
case "notice":
result, err = notice.NoticeApi(v.Action)
case "payment":
result, err = payment.PaymentApi(v.Action)
case "profile":
result, err = profile.ProfileApi(ctx, v.Action)
case "scenario":
result, err = scenario.ScenarioApi(ctx, v.Action)
case "stamp":
result, err = stamp.StampApi(v.Action)
case "subscenario":
result, err = subscenario.SubscenarioApi(ctx, v.Action)
case "unit":
result, err = unit.UnitApi(ctx, v.Action)
case "user":
result, err = user.UserApi(ctx, v.Action)
default:
err = fmt.Errorf("unimplemented api module: %s", v.Module)
}
if ss.CheckErr(err) {
return
}
results = append(results, result)
}
apiResp := apischema.ApiResp{
ResponseData: results,
ReleaseInfo: []any{},
StatusCode: 200,
}
ss.Respond(apiResp)
}
func init() {
router.AddHandler("main.php", "POST", "/api", middleware.Common, api)
}
+17
View File
@@ -0,0 +1,17 @@
package award
import (
"fmt"
"github.com/gin-gonic/gin"
)
func AwardApi(ctx *gin.Context, action string) (res any, err error) {
switch action {
case "awardInfo":
res, err = awardInfo(ctx)
default:
err = fmt.Errorf("unimplemented action: award: %s", action)
}
return res, err
}
+49
View File
@@ -0,0 +1,49 @@
package award
import (
"honoka-chan/internal/schema/api/award"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func awardInfo(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
var awardList []int
err = ss.MainEng.Table("award_m").Cols("award_id").Find(&awardList)
if ss.CheckErr(err) {
return
}
var awardID int
_, err = ss.UserEng.Table("user_pref").Where("user_id = ?", ss.UserID).Cols("award_id").Get(&awardID)
if ss.CheckErr(err) {
return
}
awardsList := []award.Info{}
for _, id := range awardList {
isSet := false
if id == awardID {
isSet = true
}
awardsList = append(awardsList, award.Info{
AwardID: id,
IsSet: isSet,
InsertDate: time.Now().Format("2006-01-02 03:04:05"),
})
}
res = award.InfoResp{
Result: award.InfoData{
AwardInfo: awardsList,
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
@@ -0,0 +1,17 @@
package background
import (
"fmt"
"github.com/gin-gonic/gin"
)
func BackgroundApi(ctx *gin.Context, action string) (res any, err error) {
switch action {
case "backgroundInfo":
res, err = backgroundInfo(ctx)
default:
err = fmt.Errorf("unimplemented action: background: %s", action)
}
return res, err
}
+49
View File
@@ -0,0 +1,49 @@
package background
import (
"honoka-chan/internal/schema/api/background"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func backgroundInfo(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
var backgroundList []int
err = ss.MainEng.Table("background_m").Cols("background_id").Find(&backgroundList)
if ss.CheckErr(err) {
return
}
var backgroundID int
_, err = ss.UserEng.Table("user_pref").Where("user_id = ?", ss.UserID).Cols("background_id").Get(&backgroundID)
if ss.CheckErr(err) {
return
}
backgroundsList := []background.Info{}
for _, id := range backgroundList {
isSet := false
if id == backgroundID {
isSet = true
}
backgroundsList = append(backgroundsList, background.Info{
BackgroundID: id,
IsSet: isSet,
InsertDate: time.Now().Format("2006-01-02 03:04:05"),
})
}
res = background.InfoResp{
Result: background.InfoData{
BackgroundInfo: backgroundsList,
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+13
View File
@@ -0,0 +1,13 @@
package banner
import "fmt"
func BannerApi(action string) (res any, err error) {
switch action {
case "bannerList":
res, err = bannerList()
default:
err = fmt.Errorf("unimplemented action: banner: %s", action)
}
return res, err
}
+76
View File
@@ -0,0 +1,76 @@
package banner
import (
"honoka-chan/internal/schema/api/banner"
"time"
)
func bannerList() (res any, err error) {
res = banner.ListResp{
Result: banner.ListData{
TimeLimit: "2037-12-31 23:59:59",
BannerList: []banner.BannerList{
{
BannerType: 1,
TargetID: 1743,
AssetPath: "assets/image/secretbox/icon/s_ba_1718_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: 1,
TargetID: 1741,
AssetPath: "assets/image/secretbox/icon/s_ba_1719_1.png",
FixedFlag: false,
BackSide: false,
BannerID: 101150,
StartDate: "2013-04-15 00:00:00",
EndDate: "2037-12-31 23:59:59",
AddUnitStartDate: "2022-01-01 00:00:00",
},
{
BannerType: 1,
TargetID: 1740,
AssetPath: "assets/image/secretbox/icon/s_ba_1720_1.png",
FixedFlag: false,
BackSide: false,
BannerID: 101149,
StartDate: "2013-04-15 00:00:00",
EndDate: "2037-12-31 23:59:59",
AddUnitStartDate: "2022-01-01 00:00:00",
},
{
BannerType: 1,
TargetID: 1739,
AssetPath: "assets/image/secretbox/icon/s_ba_1721_1.png",
FixedFlag: false,
BackSide: false,
BannerID: 101144,
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(),
}
return res, err
}
@@ -0,0 +1,15 @@
package challenge
import (
"fmt"
)
func ChallengeApi(action string) (res any, err error) {
switch action {
case "challengeInfo":
res, err = challengeInfo()
default:
err = fmt.Errorf("unimplemented action: challenge: %s", action)
}
return res, err
}
+16
View File
@@ -0,0 +1,16 @@
package challenge
import (
"honoka-chan/internal/schema/api/challenge"
"time"
)
func challengeInfo() (res any, err error) {
res = challenge.InfoResp{
Result: []any{},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+13
View File
@@ -0,0 +1,13 @@
package costume
import "fmt"
func CostumeApi(action string) (res any, err error) {
switch action {
case "costumeList":
res, err = costumeList()
default:
err = fmt.Errorf("unimplemented action: costume: %s", action)
}
return res, err
}
+19
View File
@@ -0,0 +1,19 @@
package costume
import (
"honoka-chan/internal/schema/api/costume"
"time"
)
func costumeList() (res any, err error) {
res = costume.ListResp{
Result: costume.ListData{
CostumeList: []costume.CostumeList{},
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
@@ -0,0 +1,17 @@
package eventscenario
import (
"fmt"
"github.com/gin-gonic/gin"
)
func EventScenarioApi(ctx *gin.Context, action string) (res any, err error) {
switch action {
case "status":
res, err = eventScenarioStatus(ctx)
default:
err = fmt.Errorf("unimplemented action: costume: %s", action)
}
return res, err
}
@@ -0,0 +1,80 @@
package eventscenario
import (
"fmt"
"honoka-chan/internal/schema/api/eventscenario"
"honoka-chan/internal/session"
"strings"
"time"
"github.com/gin-gonic/gin"
)
func eventScenarioStatus(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
var eventID []int
eventsList := []eventscenario.EventScenarioList{}
err = ss.MainEng.Table("event_scenario_m").Cols("event_id").GroupBy("event_id").OrderBy("event_id DESC").Find(&eventID)
if ss.CheckErr(err) {
return
}
for _, id := range eventID {
var eventRes []struct {
EventScenarioId int `xorm:"event_scenario_id"`
Chapter int `xorm:"chapter"`
ChapterAsset string `xorm:"chapter_asset"`
OpenDate string `xorm:"open_date"`
}
chapsList := []eventscenario.ChapterList{}
err = ss.MainEng.Table("event_scenario_m").Where("event_id = ?", id).Cols("event_scenario_id,chapter,chapter_asset,open_date").
OrderBy("chapter DESC").Find(&eventRes)
if ss.CheckErr(err) {
return
}
for _, res := range eventRes {
chapList := eventscenario.ChapterList{
EventScenarioID: res.EventScenarioId,
Chapter: res.Chapter,
ChapterAsset: res.ChapterAsset,
Status: 2,
OpenFlashFlag: 0,
IsReward: false,
CostType: 1000,
ItemID: 1200,
Amount: 1,
}
chapsList = append(chapsList, chapList)
}
event := eventscenario.EventScenarioList{
EventID: id,
OpenDate: strings.ReplaceAll(eventRes[0].OpenDate, "/", "-"),
ChapterList: chapsList,
}
// HACK event_scenario_btn_asset
switch id {
case 10001:
event.EventScenarioBtnAsset = "assets/image/ui/eventscenario/38_se_ba_t.png"
case 221:
event.EventScenarioBtnAsset = "assets/image/ui/eventscenario/215_se_ba_t.png"
default:
event.EventScenarioBtnAsset = fmt.Sprintf("assets/image/ui/eventscenario/%d_se_ba_t.png", id)
}
eventsList = append(eventsList, event)
}
res = eventscenario.StatusResp{
Result: eventscenario.StatusData{
EventScenarioList: eventsList,
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+17
View File
@@ -0,0 +1,17 @@
package exchange
import (
"fmt"
"github.com/gin-gonic/gin"
)
func ExchangeApi(ctx *gin.Context, action string) (res any, err error) {
switch action {
case "owningPoint":
res, err = owningPoint(ctx)
default:
err = fmt.Errorf("unimplemented action: exchange: %s", action)
}
return res, err
}
@@ -0,0 +1,37 @@
package exchange
import (
"honoka-chan/internal/schema/api/exchange"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func owningPoint(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
var exchangeID []int
exPointsList := []exchange.ExchangePointList{}
err = ss.MainEng.Table("exchange_point_m").Cols("exchange_point_id").OrderBy("exchange_point_id ASC").Find(&exchangeID)
if ss.CheckErr(err) {
return
}
for _, id := range exchangeID {
exPointsList = append(exPointsList, exchange.ExchangePointList{
Rarity: id,
ExchangePoint: 9999,
})
}
res = exchange.OwningPointResp{
Result: exchange.OwningPointData{
ExchangePointList: exPointsList,
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+13
View File
@@ -0,0 +1,13 @@
package item
import "fmt"
func ItemApi(action string) (res any, err error) {
switch action {
case "list":
res, err = itemList()
default:
err = fmt.Errorf("unimplemented action: item: %s", action)
}
return res, err
}
+13
View File
@@ -0,0 +1,13 @@
package item
import (
"encoding/json"
honokautils "honoka-chan/pkg/utils"
)
func itemList() (res any, err error) {
itemResp := honokautils.ReadAllText("assets/serverdata/item.json")
err = json.Unmarshal([]byte(itemResp), &res)
return res, err
}
+19
View File
@@ -0,0 +1,19 @@
package live
import (
"fmt"
"github.com/gin-gonic/gin"
)
func LiveApi(ctx *gin.Context, action string) (res any, err error) {
switch action {
case "liveStatus":
res, err = liveStatus(ctx)
case "schedule":
res, err = liveSchedule(ctx)
default:
err = fmt.Errorf("unimplemented action: live: %s", action)
}
return res, err
}
+57
View File
@@ -0,0 +1,57 @@
package live
import (
"honoka-chan/internal/schema/api/live"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func liveSchedule(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
var liveDifficultyID []int
specialLives := []live.SpecialLiveStatusList{}
err = ss.MainEng.Table("special_live_m").Cols("live_difficulty_id").OrderBy("live_difficulty_id ASC").Find(&liveDifficultyID)
if ss.CheckErr(err) {
return
}
for _, id := range liveDifficultyID {
specialLive := live.SpecialLiveStatusList{
LiveDifficultyID: id,
Status: 1,
HiScore: 0,
HiComboCount: 0,
ClearCnt: 0,
AchievedGoalIDList: []int{},
}
specialLives = append(specialLives, specialLive)
}
livesList := []live.LiveList{}
for _, v := range specialLives {
livesList = append(livesList, live.LiveList{
LiveDifficultyID: v.LiveDifficultyID,
StartDate: "2023-01-01 00:00:00",
EndDate: "2037-01-01 00:00:00",
IsRandom: false,
})
}
res = live.ScheduleResp{
Result: live.ScheduleData{
EventList: []any{},
LiveList: livesList,
LimitedBonusList: []any{},
LimitedBonusCommonList: []live.LimitedBonusCommonList{}, // 特效道具
RandomLiveList: []live.RandomLiveList{}, // 随机歌曲
FreeLiveList: []any{},
TrainingLiveList: []live.TrainingLiveList{}, // 挑战歌曲
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+64
View File
@@ -0,0 +1,64 @@
package live
import (
"honoka-chan/internal/schema/api/live"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func liveStatus(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
var liveDifficultyID []int
normalLives := []live.NormalLiveStatusList{}
err = ss.MainEng.Table("normal_live_m").Cols("live_difficulty_id").OrderBy("live_difficulty_id ASC").Find(&liveDifficultyID)
if ss.CheckErr(err) {
return
}
for _, id := range liveDifficultyID {
normalLive := live.NormalLiveStatusList{
LiveDifficultyID: id,
Status: 1,
HiScore: 0,
HiComboCount: 0,
ClearCnt: 0,
AchievedGoalIDList: []int{},
}
normalLives = append(normalLives, normalLive)
}
specialLives := []live.SpecialLiveStatusList{}
err = ss.MainEng.Table("special_live_m").Cols("live_difficulty_id").OrderBy("live_difficulty_id ASC").Find(&liveDifficultyID)
if ss.CheckErr(err) {
return
}
for _, id := range liveDifficultyID {
specialLive := live.SpecialLiveStatusList{
LiveDifficultyID: id,
Status: 1,
HiScore: 0,
HiComboCount: 0,
ClearCnt: 0,
AchievedGoalIDList: []int{},
}
specialLives = append(specialLives, specialLive)
}
res = live.StatusResp{
Result: live.StatusData{
NormalLiveStatusList: normalLives,
SpecialLiveStatusList: specialLives,
TrainingLiveStatusList: []live.TrainingLiveStatusList{},
MarathonLiveStatusList: []any{},
FreeLiveStatusList: []any{},
CanResumeLive: false,
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+19
View File
@@ -0,0 +1,19 @@
package liveicon
import (
"honoka-chan/internal/schema/api/liveicon"
"time"
)
func liveIconInfo() (res any, err error) {
res = liveicon.InfoResp{
Result: liveicon.InfoData{
LiveNotesIconList: []int{1, 2, 3},
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+13
View File
@@ -0,0 +1,13 @@
package liveicon
import "fmt"
func LiveIconApi(action string) (res any, err error) {
switch action {
case "liveiconInfo":
res, err = liveIconInfo()
default:
err = fmt.Errorf("unimplemented action: liveicon: %s", action)
}
return res, err
}
+19
View File
@@ -0,0 +1,19 @@
package livese
import (
"honoka-chan/internal/schema/api/livese"
"time"
)
func LiveSeInfo() (res any, err error) {
res = livese.InfoResp{
Result: livese.InfoData{
LiveSeList: []int{1, 2, 3},
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+13
View File
@@ -0,0 +1,13 @@
package livese
import "fmt"
func LiveSeApi(action string) (res any, err error) {
switch action {
case "liveseInfo":
res, err = LiveSeInfo()
default:
err = fmt.Errorf("unimplemented action: livese: %s", action)
}
return res, err
}
+17
View File
@@ -0,0 +1,17 @@
package login
import (
"fmt"
)
func LoginApi(action string) (res any, err error) {
switch action {
case "topInfo":
res, err = loginTopInfo()
case "topInfoOnce":
res, err = loginTopInfoOnce()
default:
err = fmt.Errorf("unimplemented action: login: %s", action)
}
return res, err
}
+44
View File
@@ -0,0 +1,44 @@
package login
import (
"honoka-chan/internal/schema/api/login"
"time"
)
func loginTopInfo() (res any, err error) {
res = login.TopInfoResp{
Result: login.TopInfoData{
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: login.LicenseInfo{
LicenseList: []any{},
LicensedInfo: []any{},
ExpiredInfo: []any{},
BadgeFlag: false,
},
UsingBuffInfo: []any{},
IsKlabIDTaskFlag: false,
KlabIDTaskCanSync: false,
HasUnreadAnnounce: false,
ExchangeBadgeCnt: []int{0, 0, 0},
AdFlag: false,
HasAdReward: false,
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+39
View File
@@ -0,0 +1,39 @@
package login
import (
"honoka-chan/internal/schema/api/login"
"time"
)
func loginTopInfoOnce() (res any, err error) {
res = login.TopInfoOnceResp{
Result: login.TopInfoOnceData{
NewAchievementCnt: 0,
UnaccomplishedAchievementCnt: 0,
LiveDailyRewardExist: false,
TrainingEnergy: 10,
TrainingEnergyMax: 10,
Notification: login.Notification{
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(),
}
return res, err
}
+17
View File
@@ -0,0 +1,17 @@
package marathon
import (
"honoka-chan/internal/schema/api/marathon"
"time"
)
func marathonInfo() (res any, err error) {
res = marathon.InfoResp{
Result: []any{},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+13
View File
@@ -0,0 +1,13 @@
package marathon
import "fmt"
func MarathonApi(action string) (res any, err error) {
switch action {
case "marathonInfo":
res, err = marathonInfo()
default:
err = fmt.Errorf("unimplemented action: marathon: %s", action)
}
return res, err
}
@@ -0,0 +1,17 @@
package multiunit
import (
"fmt"
"github.com/gin-gonic/gin"
)
func MultiUnitApi(ctx *gin.Context, action string) (res any, err error) {
switch action {
case "multiunitscenarioStatus":
res, err = MultiUnitScenarioStatus(ctx)
default:
err = fmt.Errorf("unimplemented action: multiunit: %s", action)
}
return res, err
}
@@ -0,0 +1,62 @@
package multiunit
import (
"honoka-chan/internal/schema/api/multiunit"
"honoka-chan/internal/session"
"strings"
"time"
"github.com/gin-gonic/gin"
)
func MultiUnitScenarioStatus(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
var statusID []int
multiUnitsList := []multiunit.StatusList{}
err = ss.MainEng.Table("multi_unit_scenario_m").Cols("multi_unit_id").GroupBy("multi_unit_id").OrderBy("multi_unit_id ASC").Find(&statusID)
if ss.CheckErr(err) {
return
}
for _, id := range statusID {
var 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"`
}
_, err = ss.MainEng.Table("multi_unit_scenario_m").
Join("LEFT", "multi_unit_scenario_open_m", "multi_unit_scenario_m.multi_unit_id = multi_unit_scenario_open_m.multi_unit_id").
Cols("multi_unit_scenario_btn_asset,open_date,multi_unit_scenario_id,chapter").
Where("multi_unit_scenario_m.multi_unit_id = ?", id).Get(&multiRes)
if ss.CheckErr(err) {
return
}
multiUnitsList = append(multiUnitsList, multiunit.StatusList{
MultiUnitID: id,
Status: 2,
MultiUnitScenarioBtnAsset: multiRes.MultiUnitScenarioBtnAsset,
OpenDate: strings.ReplaceAll(multiRes.OpenDate, "/", "-"),
ChapterList: []multiunit.ChapterList{
{
MultiUnitScenarioID: multiRes.MultiUnitScenarioId,
Chapter: multiRes.Chapter,
Status: 2,
},
},
})
}
res = multiunit.StatusResp{
Result: multiunit.StatusData{
MultiUnitScenarioStatusList: multiUnitsList,
UnlockedMultiUnitScenarioIds: []any{},
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+51
View File
@@ -0,0 +1,51 @@
package museum
import (
"honoka-chan/internal/schema/api/museum"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func museumInfo(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
var museumRes []struct {
MuseumContentsId int `xorm:"museum_contents_id"`
SmileBuff int `xorm:"smile_buff"`
PureBuff int `xorm:"pure_buff"`
CoolBuff int `xorm:"cool_buff"`
}
var museumID []int
var smileBuff, pureBuff, coolBuff int
err = ss.MainEng.Table("museum_contents_m").Cols("museum_contents_id,smile_buff,pure_buff,cool_buff").
OrderBy("museum_contents_id ASC").Find(&museumRes)
if ss.CheckErr(err) {
return
}
for _, res := range museumRes {
smileBuff += res.SmileBuff
pureBuff += res.PureBuff
coolBuff += res.CoolBuff
museumID = append(museumID, res.MuseumContentsId)
}
res = museum.InfoResp{
Result: museum.InfoData{
MuseumInfo: museum.Info{
Parameter: museum.Parameter{
Smile: smileBuff,
Pure: pureBuff,
Cool: coolBuff,
},
ContentsIDList: museumID,
},
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+17
View File
@@ -0,0 +1,17 @@
package museum
import (
"fmt"
"github.com/gin-gonic/gin"
)
func MuseumApi(ctx *gin.Context, action string) (res any, err error) {
switch action {
case "info":
res, err = museumInfo(ctx)
default:
err = fmt.Errorf("unimplemented action: museum: %s", action)
}
return res, err
}
@@ -0,0 +1,15 @@
package navigation
import (
"fmt"
)
func NavigationApi(action string) (res any, err error) {
switch action {
case "specialCutin":
res, err = SpecialCutin()
default:
err = fmt.Errorf("unimplemented action: navigation: %s", action)
}
return res, err
}
@@ -0,0 +1,19 @@
package navigation
import (
"honoka-chan/internal/schema/api/navigation"
"time"
)
func SpecialCutin() (res any, err error) {
res = navigation.SpecialCutinResp{
Result: navigation.SpecialCutinData{
SpecialCutinList: []any{},
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+20
View File
@@ -0,0 +1,20 @@
package notice
import (
"honoka-chan/internal/schema/api/notice"
"time"
)
func noticeMarquee() (res any, err error) {
res = notice.MarqueeResp{
Result: notice.MarqueeData{
ItemCount: 0,
MarqueeList: []any{},
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+13
View File
@@ -0,0 +1,13 @@
package notice
import "fmt"
func NoticeApi(action string) (res any, err error) {
switch action {
case "noticeMarquee":
res, err = noticeMarquee()
default:
err = fmt.Errorf("unimplemented action: notice: %s", action)
}
return res, err
}
+13
View File
@@ -0,0 +1,13 @@
package payment
import "fmt"
func PaymentApi(action string) (res any, err error) {
switch action {
case "productList":
res, err = productList()
default:
err = fmt.Errorf("unimplemented action: payment: %s", action)
}
return res, err
}
@@ -0,0 +1,31 @@
package payment
import (
"honoka-chan/internal/schema/api/payment"
"time"
)
func productList() (res any, err error) {
res = payment.ProductListResp{
Result: payment.ProductListData{
RestrictionInfo: payment.RestrictionInfo{
Restricted: false,
},
UnderAgeInfo: payment.UnderAgeInfo{
BirthSet: false,
HasLimit: false,
LimitAmount: nil,
MonthUsed: 0,
},
SnsProductList: []payment.SnsProduct{},
ProductList: []payment.Product{},
SubscriptionList: []payment.Subscription{},
ShowPointShop: false,
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
@@ -0,0 +1,26 @@
package profile
import (
"encoding/json"
"honoka-chan/internal/schema/api/profile"
honokautils "honoka-chan/pkg/utils"
"time"
)
func cardRanking() (res any, err error) {
var result []any
love := honokautils.ReadAllText("assets/serverdata/love.json")
err = json.Unmarshal([]byte(love), &result)
if err != nil {
return nil, err
}
res = profile.CardRankingResp{
Result: result,
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+188
View File
@@ -0,0 +1,188 @@
package profile
import (
"honoka-chan/internal/model/user"
"honoka-chan/internal/schema/api/profile"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func profileInfo(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
pref := user.UserPref{}
_, err = ss.UserEng.Table("user_pref").Where("user_id = ?", ss.UserID).Get(&pref)
if err != nil {
return nil, err
}
commonUnit, err := ss.MainEng.Table("common_unit_m").Count()
if err != nil {
return nil, err
}
userUnit, err := ss.UserEng.Table("user_unit").Where("user_id = ?", ss.UserID).Count()
if err != nil {
return nil, err
}
unitData := profile.UnitData{}
exists, err := ss.MainEng.Table("common_unit_m").Where("unit_owning_user_id = ?", pref.UnitOwningUserID).Get(&unitData)
if err != nil {
return nil, err
}
isCommon := true
if !exists {
_, err = ss.UserEng.Table("user_unit").
Where("unit_owning_user_id = ? AND user_id = ?", pref.UnitOwningUserID, ss.UserID).Get(&unitData)
if err != nil {
return nil, err
}
isCommon = false
}
var attrId, maxHp, baseSmile, basePure, baseCool int
var smileMax, pureMax, coolMax int
if isCommon {
// 公共卡片仅为100级属性
_, err = ss.MainEng.Table("unit_m").Where("unit_id = ?", unitData.UnitID).
Cols("attribute_id,hp_max,smile_max,pure_max,cool_max").Get(&attrId, &maxHp, &baseSmile, &basePure, &baseCool)
if err != nil {
return nil, err
}
// 偷懒起见不计算饰品、宝石、回忆画廊等属性加成
smileMax = baseSmile
pureMax = basePure
coolMax = baseCool
// } else {
// // 用户卡片需要根据等级计算属性
// // TODO
}
var accessoryOwningId, accessoryId, exp int
_, err = ss.UserEng.Table("user_accessory_wear").Where("unit_owning_user_id = ? AND user_id = ?", pref.UnitOwningUserID, ss.UserID).
Cols("accessory_owning_user_id").Get(&accessoryOwningId)
if err != nil {
return nil, err
}
_, err = ss.MainEng.Table("common_accessory_m").Where("accessory_owning_user_id = ?", accessoryOwningId).
Cols("accessory_id,exp").Get(&accessoryId, &exp)
if err != nil {
return nil, err
}
accessoryInfo := profile.AccessoryInfo{
AccessoryOwningUserID: accessoryOwningId,
AccessoryID: accessoryId,
Exp: exp,
NextExp: 0,
Level: 8,
MaxLevel: 8,
RankUpCount: 4,
FavoriteFlag: true,
}
removeSkillIds := []int{}
err = ss.UserEng.Table("user_unit_skill_equip").Where("unit_owning_user_id = ? AND user_id = ?", pref.UnitOwningUserID, ss.UserID).
Cols("unit_removable_skill_id").Find(&removeSkillIds)
if err != nil {
return nil, err
}
res = profile.InfoResp{
Result: profile.InfoData{
UserInfo: profile.UserInfo{
UserID: pref.UserID,
Name: pref.UserName,
Level: pref.UserLevel,
CostMax: 100,
UnitMax: 5000,
EnergyMax: 417,
FriendMax: 99,
UnitCnt: int(commonUnit + userUnit),
InviteCode: pref.InviteCode,
ElapsedTimeFromLogin: "14\u5c0f\u65f6\u524d",
Introduction: pref.UserDesc,
},
CenterUnitInfo: profile.CenterUnitInfo{
UnitOwningUserID: unitData.UnitOwningUserID,
UnitID: unitData.UnitID,
Exp: unitData.Exp,
NextExp: unitData.NextExp,
Level: unitData.Level,
LevelLimitID: unitData.LevelLimitID,
MaxLevel: unitData.MaxLevel,
Rank: unitData.Rank,
MaxRank: unitData.MaxRank,
Love: unitData.Love,
MaxLove: unitData.MaxLove,
UnitSkillLevel: unitData.UnitSkillLevel,
MaxHp: unitData.MaxHp,
FavoriteFlag: unitData.FavoriteFlag,
DisplayRank: unitData.DisplayRank,
UnitSkillExp: unitData.UnitSkillExp,
UnitRemovableSkillCapacity: unitData.UnitRemovableSkillCapacity,
Attribute: attrId,
Smile: baseSmile,
Cute: basePure,
Cool: baseCool,
IsLoveMax: unitData.IsLoveMax,
IsLevelMax: unitData.IsLevelMax,
IsRankMax: unitData.IsRankMax,
IsSigned: unitData.IsSigned,
IsSkillLevelMax: unitData.IsSkillLevelMax,
SettingAwardID: pref.AwardID,
RemovableSkillIds: removeSkillIds,
AccessoryInfo: accessoryInfo,
Costume: profile.Costume{},
TotalSmile: smileMax,
TotalCute: pureMax,
TotalCool: coolMax,
TotalHp: maxHp,
},
NaviUnitInfo: profile.NaviUnitInfo{
UnitOwningUserID: unitData.UnitOwningUserID,
UnitID: unitData.UnitID,
Exp: unitData.Exp,
NextExp: unitData.NextExp,
Level: unitData.Level,
MaxLevel: unitData.MaxLevel,
LevelLimitID: unitData.LevelLimitID,
Rank: unitData.Rank,
MaxRank: unitData.MaxRank,
Love: unitData.Love,
MaxLove: unitData.MaxLove,
UnitSkillExp: unitData.UnitSkillExp,
UnitSkillLevel: unitData.UnitSkillLevel,
MaxHp: unitData.MaxHp,
UnitRemovableSkillCapacity: unitData.UnitRemovableSkillCapacity,
FavoriteFlag: unitData.FavoriteFlag,
DisplayRank: unitData.DisplayRank,
IsLoveMax: unitData.IsLoveMax,
IsLevelMax: unitData.IsLevelMax,
IsRankMax: unitData.IsRankMax,
IsSigned: unitData.IsSigned,
IsSkillLevelMax: unitData.IsSkillLevelMax,
IsRemovableSkillCapacityMax: unitData.IsRemovableSkillCapacityMax,
InsertDate: "2016-10-11 10:33:03",
TotalSmile: smileMax,
TotalCute: pureMax,
TotalCool: coolMax,
TotalHp: maxHp,
RemovableSkillIds: removeSkillIds,
},
IsAlliance: false,
FriendStatus: 0,
SettingAwardID: pref.AwardID,
SettingBackgroundID: pref.BackgroundID,
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+38
View File
@@ -0,0 +1,38 @@
package profile
import (
"honoka-chan/internal/schema/api/profile"
"time"
)
func liveCnt() (res any, err error) {
res = profile.LiveCntResp{
Result: []profile.LiveCntData{
{
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(),
}
return res, err
}
+21
View File
@@ -0,0 +1,21 @@
package profile
import (
"fmt"
"github.com/gin-gonic/gin"
)
func ProfileApi(ctx *gin.Context, action string) (res any, err error) {
switch action {
case "cardRanking":
res, err = cardRanking()
case "liveCnt":
res, err = liveCnt()
case "profileInfo":
res, err = profileInfo(ctx)
default:
err = fmt.Errorf("unimplemented action: profile: %s", action)
}
return res, err
}
+17
View File
@@ -0,0 +1,17 @@
package scenario
import (
"fmt"
"github.com/gin-gonic/gin"
)
func ScenarioApi(ctx *gin.Context, action string) (res any, err error) {
switch action {
case "scenarioStatus":
res, err = scenarioStatus(ctx)
default:
err = fmt.Errorf("unimplemented action: scenario: %s", action)
}
return res, err
}
+37
View File
@@ -0,0 +1,37 @@
package scenario
import (
"honoka-chan/internal/schema/api/scenario"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func scenarioStatus(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
var scenarioID []int
scenarioLists := []scenario.StatusList{}
err = ss.MainEng.Table("scenario_m").Cols("scenario_id").OrderBy("scenario_id ASC").Find(&scenarioID)
if ss.CheckErr(err) {
return
}
for _, id := range scenarioID {
scenarioLists = append(scenarioLists, scenario.StatusList{
ScenarioID: id,
Status: 2,
})
}
res = scenario.StatusResp{
Result: scenario.StatusData{
ScenarioStatusList: scenarioLists,
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+13
View File
@@ -0,0 +1,13 @@
package stamp
import (
"encoding/json"
honokautils "honoka-chan/pkg/utils"
)
func stampInfo() (res any, err error) {
stampResp := honokautils.ReadAllText("assets/serverdata/stamp.json")
err = json.Unmarshal([]byte(stampResp), &res)
return res, err
}
+13
View File
@@ -0,0 +1,13 @@
package stamp
import "fmt"
func StampApi(action string) (res any, err error) {
switch action {
case "stampInfo":
res, err = stampInfo()
default:
err = fmt.Errorf("unimplemented action: stamp: %s", action)
}
return res, err
}
@@ -0,0 +1,38 @@
package subscenario
import (
"honoka-chan/internal/schema/api/subscenario"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func subscenarioStatus(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
var subScenarioID []int
subScenarioLists := []subscenario.StatusList{}
err = ss.MainEng.Table("subscenario_m").Cols("subscenario_id").OrderBy("subscenario_id ASC").Find(&subScenarioID)
if ss.CheckErr(err) {
return
}
for _, id := range subScenarioID {
subScenarioLists = append(subScenarioLists, subscenario.StatusList{
SubscenarioID: id,
Status: 2,
})
}
res = subscenario.StatusResp{
Result: subscenario.StatusData{
SubscenarioStatusList: subScenarioLists,
UnlockedSubscenarioIds: []any{},
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
@@ -0,0 +1,17 @@
package subscenario
import (
"fmt"
"github.com/gin-gonic/gin"
)
func SubscenarioApi(ctx *gin.Context, action string) (res any, err error) {
switch action {
case "subscenarioStatus":
res, err = subscenarioStatus(ctx)
default:
err = fmt.Errorf("unimplemented action: subscenario: %s", action)
}
return res, err
}
+43
View File
@@ -0,0 +1,43 @@
package unit
import (
"honoka-chan/internal/schema/api/unit"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func unitAccessoryAll(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
accessoryList := []unit.AccessoryList{}
err = ss.MainEng.Table("common_accessory_m").Find(&accessoryList)
if ss.CheckErr(err) {
return
}
for k := range accessoryList {
accessoryList[k].NextExp = 0
accessoryList[k].Level = 8
accessoryList[k].MaxLevel = 8
accessoryList[k].RankUpCount = 4
accessoryList[k].FavoriteFlag = true
}
wearingInfo := []unit.WearingInfo{}
err = ss.UserEng.Table("user_accessory_wear").Where("user_id = ?", ss.UserID).Find(&wearingInfo)
if ss.CheckErr(err) {
return
}
res = unit.AccessoryAllResp{
Result: unit.AccessoryAllData{
AccessoryList: accessoryList,
WearingInfo: wearingInfo,
EspecialCreateFlag: false,
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+38
View File
@@ -0,0 +1,38 @@
package unit
import (
"honoka-chan/internal/schema/api/unit"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func unitAll(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
unitsData := []unit.Active{}
err = ss.MainEng.Table("common_unit_m").Find(&unitsData)
if ss.CheckErr(err) {
return
}
userUnits := []unit.Active{}
err = ss.UserEng.Table("user_unit").Where("user_id = ?", ss.UserID).Find(&userUnits)
if ss.CheckErr(err) {
return
}
unitsData = append(unitsData, userUnits...)
res = unit.AllResp{
Result: unit.AllData{
Active: unitsData,
Waiting: []unit.Waiting{},
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+55
View File
@@ -0,0 +1,55 @@
package unit
import (
"honoka-chan/internal/schema/api/unit"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func unitDeckInfo(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
userDeck := []unit.UserDeckData{}
err = ss.UserEng.Table("user_deck").Where("user_id = ?", ss.UserID).Asc("deck_id").Find(&userDeck)
if ss.CheckErr(err) {
return
}
unitDeckInfo := []unit.DeckInfoData{}
for _, deck := range userDeck {
deckUnit := []unit.UnitDeckData{}
err = ss.UserEng.Table("user_deck_unit").Where("user_deck_id = ?", deck.ID).Asc("position").Find(&deckUnit)
if ss.CheckErr(err) {
return
}
oUID := []unit.UnitOwningUserIds{}
for _, u := range deckUnit {
oUID = append(oUID, unit.UnitOwningUserIds{
Position: u.Position,
UnitOwningUserID: u.UnitOwningUserID,
})
}
mainFlag := false
if deck.MainFlag == 1 {
mainFlag = true
}
unitDeckInfo = append(unitDeckInfo, unit.DeckInfoData{
UnitDeckID: deck.DeckID,
MainFlag: mainFlag,
DeckName: deck.DeckName,
UnitOwningUserIds: oUID,
})
}
res = unit.DeckInfoResp{
Result: unitDeckInfo,
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
@@ -0,0 +1,76 @@
package unit
import (
"honoka-chan/internal/schema/api/unit"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func unitRemovableSkillInfo(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
var skillEquipCount []unit.SkillEquipCount
err = ss.UserEng.Table("user_unit_skill_equip").Where("user_id = ?", ss.UserID).Select("unit_removable_skill_id,COUNT(*) AS ct").
GroupBy("unit_removable_skill_id").Find(&skillEquipCount)
if ss.CheckErr(err) {
return
}
var rmSkillIds []int
err = ss.MainEng.Table("unit_removable_skill_m").Where("effect_range = 1").Cols("unit_removable_skill_id").Find(&rmSkillIds)
if ss.CheckErr(err) {
return
}
owingInfo := []unit.OwningInfo{}
for _, id := range rmSkillIds {
info := unit.OwningInfo{
UnitRemovableSkillID: id,
TotalAmount: 9,
EquippedAmount: 0,
InsertDate: "2023-01-01 12:00:00",
}
for _, sk := range skillEquipCount {
if id == sk.UnitRemovableSkillId {
info.EquippedAmount = sk.Count
break
}
}
owingInfo = append(owingInfo, info)
}
var unitOwningIds []int
err = ss.UserEng.Table("user_unit_skill_equip").Where("user_id = ?", ss.UserID).Cols("unit_owning_user_id").GroupBy("unit_owning_user_id").Find(&unitOwningIds)
if ss.CheckErr(err) {
return
}
equipInfo := map[int]any{}
for _, v := range unitOwningIds {
detail := []unit.SkillEquipDetail{}
err = ss.UserEng.Table("user_unit_skill_equip").Where("user_id = ? AND unit_owning_user_id = ?", ss.UserID, v).
Cols("unit_removable_skill_id").Find(&detail)
if ss.CheckErr(err) {
return
}
equipInfo[v] = unit.SkillEquipList{
UnitOwningUserID: v,
Detail: detail,
}
}
res = unit.RemovableSkillInfoResp{
Result: unit.RemovableSkillInfoData{
OwningInfo: owingInfo,
EquipmentInfo: equipInfo,
}, // 宝石
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+19
View File
@@ -0,0 +1,19 @@
package unit
import (
"honoka-chan/internal/schema/api/unit"
"time"
)
func unitSupporterAll() (res any, err error) {
res = unit.SupporterAllResp{
Result: unit.SupporterAllData{
UnitSupportList: []unit.SupporterList{},
}, // 练习道具
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+25
View File
@@ -0,0 +1,25 @@
package unit
import (
"fmt"
"github.com/gin-gonic/gin"
)
func UnitApi(ctx *gin.Context, action string) (res any, err error) {
switch action {
case "accessoryAll":
res, err = unitAccessoryAll(ctx)
case "deckInfo":
res, err = unitDeckInfo(ctx)
case "removableSkillInfo":
res, err = unitRemovableSkillInfo(ctx)
case "supporterAll":
res, err = unitSupporterAll()
case "unitAll":
res, err = unitAll(ctx)
default:
err = fmt.Errorf("unimplemented action: unit: %s", action)
}
return res, err
}
+33
View File
@@ -0,0 +1,33 @@
package user
import (
"honoka-chan/internal/schema/api/user"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func userGetNavi(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
var uID, oID int
_, err = ss.UserEng.Table("user_pref").Where("user_id = ?", ss.UserID).Cols("user_id,unit_owning_user_id").Get(&uID, &oID)
if ss.CheckErr(err) {
return
}
res = user.GetNaviResp{
Result: user.GetNaviData{
User: user.User{
UserID: uID,
UnitOwningUserID: oID,
},
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+58
View File
@@ -0,0 +1,58 @@
package user
import (
"honoka-chan/internal/model/user"
userapischema "honoka-chan/internal/schema/api/user"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func userInfo(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
pref := user.UserPref{}
_, err = ss.UserEng.Table("user_pref").Where("user_id = ?", ss.UserID).Get(&pref)
if err != nil {
return nil, err
}
res = userapischema.InfoResp{
Result: userapischema.UserInfo{
UserID: ss.UserID,
Name: pref.UserName,
Level: pref.UserLevel,
Exp: 1089696,
PreviousExp: 0,
NextExp: 1207185,
GameCoin: 999999999,
SnsCoin: 100000,
FreeSnsCoin: 50000,
PaidSnsCoin: 50000,
SocialPoint: 1438395,
UnitMax: 5000,
WaitingUnitMax: 1000,
EnergyMax: 417,
EnergyFullTime: "2023-03-20 03:58:55",
LicenseLiveEnergyRecoverlyTime: 60,
EnergyFullNeedTime: 0,
OverMaxEnergy: 417,
TrainingEnergy: 100,
TrainingEnergyMax: 100,
FriendMax: 99,
InviteCode: pref.InviteCode,
InsertDate: "2015-08-10 18:58:30",
UpdateDate: "2018-08-09 18:13:12",
TutorialState: -1,
DiamondCoin: 0,
CrystalCoin: 0,
LpRecoveryItem: []userapischema.LpRecoveryItem{},
},
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}
return res, err
}
+19
View File
@@ -0,0 +1,19 @@
package user
import (
"fmt"
"github.com/gin-gonic/gin"
)
func UserApi(ctx *gin.Context, action string) (res any, err error) {
switch action {
case "getNavi":
res, err = userGetNavi(ctx)
case "userInfo":
res, err = userInfo(ctx)
default:
err = fmt.Errorf("unimplemented action: user: %s", action)
}
return res, err
}
-33
View File
@@ -1,33 +0,0 @@
package handler
import (
"honoka-chan/internal/model"
"honoka-chan/internal/session"
"honoka-chan/internal/tools"
"github.com/gin-gonic/gin"
"github.com/tidwall/gjson"
)
func AwardSet(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
req := gjson.Parse(ctx.PostForm("request_data"))
pref := tools.UserPref{
AwardID: int(req.Get("award_id").Int()),
}
_, err := ss.UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref)
if ss.CheckErr(err) {
return
}
awardResp := model.AwardSetResp{
ResponseData: []any{},
ReleaseInfo: []any{},
StatusCode: 200,
}
ss.Respond(awardResp)
}
+37
View File
@@ -0,0 +1,37 @@
package award
import (
"honoka-chan/internal/middleware"
"honoka-chan/internal/model/user"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/award"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
"github.com/tidwall/gjson"
)
func set(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
reqData := gjson.Parse(ctx.MustGet("request_data").(string))
pref := user.UserPref{
AwardID: int(reqData.Get("award_id").Int()),
}
_, err := ss.UserEng.Table("user_pref").Where("user_id = ?", ss.UserID).Update(&pref)
if ss.CheckErr(err) {
return
}
ss.Respond(award.SetResp{
ResponseData: []any{},
ReleaseInfo: []any{},
StatusCode: 200,
})
}
func init() {
router.AddHandler("main.php", "POST", "/award/set", middleware.Common, set)
}
-33
View File
@@ -1,33 +0,0 @@
package handler
import (
"honoka-chan/internal/model"
"honoka-chan/internal/session"
"honoka-chan/internal/tools"
"github.com/gin-gonic/gin"
"github.com/tidwall/gjson"
)
func BackgroundSet(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
req := gjson.Parse(ctx.PostForm("request_data"))
pref := tools.UserPref{
BackgroundID: int(req.Get("background_id").Int()),
}
_, err := ss.UserEng.Table("user_preference_m").Where("user_id = ?", ctx.GetString("userid")).Update(&pref)
if ss.CheckErr(err) {
return
}
backgroundResp := model.BackgroundSetResp{
ResponseData: []any{},
ReleaseInfo: []any{},
StatusCode: 200,
}
ss.Respond(backgroundResp)
}
+37
View File
@@ -0,0 +1,37 @@
package background
import (
"honoka-chan/internal/middleware"
"honoka-chan/internal/model/user"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/background"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
"github.com/tidwall/gjson"
)
func set(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
reqData := gjson.Parse(ctx.MustGet("request_data").(string))
pref := user.UserPref{
BackgroundID: int(reqData.Get("background_id").Int()),
}
_, err := ss.UserEng.Table("user_pref").Where("user_id = ?", ss.UserID).Update(&pref)
if ss.CheckErr(err) {
return
}
ss.Respond(background.SetResp{
ResponseData: []any{},
ReleaseInfo: []any{},
StatusCode: 200,
})
}
func init() {
router.AddHandler("main.php", "POST", "/background/set", middleware.Common, set)
}
-196
View File
@@ -1,196 +0,0 @@
package handler
import (
"encoding/json"
"fmt"
"honoka-chan/config"
"honoka-chan/internal/model"
"honoka-chan/internal/session"
"io"
"net/http"
"strings"
"github.com/gin-gonic/gin"
"xorm.io/builder"
)
type PkgInfo struct {
Id int `xorm:"pkg_id"`
Order int `xorm:"pkg_order"`
Size int `xorm:"pkg_size"`
}
func DownloadAdditional(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
downloadReq := model.AdditionalReq{}
err := json.Unmarshal([]byte(ctx.GetString("request_data")), &downloadReq)
if ss.CheckErr(err) {
return
}
pkgList := []model.AdditionalRes{}
pkgType, pkgId := downloadReq.PackageType, downloadReq.PackageID
var pkgInfo []PkgInfo
err = ss.MainEng.Table("download_m").Where("pkg_type = ? AND pkg_id = ? AND pkg_os = ?", pkgType, pkgId, downloadReq.TargetOs).
Cols("pkg_id,pkg_order,pkg_size").
OrderBy("pkg_id ASC, pkg_order ASC").Find(&pkgInfo)
if ss.CheckErr(err) {
return
}
for _, pkg := range pkgInfo {
pkgList = append(pkgList, model.AdditionalRes{
Size: pkg.Size,
URL: fmt.Sprintf("%s/%s/archives/%d_%d_%d.zip",
config.Conf.Settings.CdnServer, downloadReq.TargetOs, pkgType, pkg.Id, pkg.Order),
})
}
addResp := model.AdditionalResp{
ResponseData: pkgList,
ReleaseInfo: []any{},
StatusCode: 200,
}
ss.Respond(addResp)
}
func DownloadBatch(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
downloadReq := model.BatchReq{}
err := json.Unmarshal([]byte(ctx.GetString("request_data")), &downloadReq)
if ss.CheckErr(err) {
return
}
pkgList := []model.BatchRes{}
if downloadReq.ClientVersion == config.PackageVersion {
pkgType := downloadReq.PackageType
var pkgInfo []PkgInfo
err := ss.MainEng.Table("download_m").Where(builder.NotIn("pkg_id", downloadReq.ExcludedPackageIds)).Where("pkg_type = ? AND pkg_os = ?", pkgType, downloadReq.Os).
Cols("pkg_id,pkg_order,pkg_size").
OrderBy("pkg_id ASC, pkg_order ASC").Find(&pkgInfo)
if ss.CheckErr(err) {
return
}
for _, pkg := range pkgInfo {
pkgList = append(pkgList, model.BatchRes{
Size: pkg.Size,
URL: fmt.Sprintf("%s/%s/archives/%d_%d_%d.zip",
config.Conf.Settings.CdnServer, downloadReq.Os, pkgType, pkg.Id, pkg.Order),
})
}
}
batchResp := model.BatchResp{
ResponseData: pkgList,
ReleaseInfo: []any{},
StatusCode: 200,
}
ss.Respond(batchResp)
}
func DownloadUpdate(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
downloadReq := model.UpdateReq{}
err := json.Unmarshal([]byte(ctx.GetString("request_data")), &downloadReq)
if ss.CheckErr(err) {
return
}
pkgList := []model.UpdateRes{}
if downloadReq.ExternalVersion != config.PackageVersion {
pkgType := 99
var pkgInfo []PkgInfo
err := ss.MainEng.Table("download_m").Where("pkg_type = ? AND pkg_os = ?", pkgType, downloadReq.TargetOs).
Cols("pkg_id,pkg_order,pkg_size").
OrderBy("pkg_id ASC, pkg_order ASC").Find(&pkgInfo)
if ss.CheckErr(err) {
return
}
for _, pkg := range pkgInfo {
pkgList = append(pkgList, model.UpdateRes{
Size: pkg.Size,
URL: fmt.Sprintf("%s/%s/archives/%d_%d_%d.zip",
config.Conf.Settings.CdnServer, downloadReq.TargetOs, pkgType, pkg.Id, pkg.Order),
Version: config.PackageVersion,
})
}
patchFileUrl := fmt.Sprintf("%s/%s/archives/99_0_115.zip",
config.Conf.Settings.CdnServer, downloadReq.TargetOs)
resp, err := http.Get(patchFileUrl)
if err == nil {
res, err := io.ReadAll(resp.Body)
if err == nil {
pkgList = append(pkgList, model.UpdateRes{
Size: len(res),
URL: patchFileUrl,
Version: config.PackageVersion,
})
}
defer resp.Body.Close()
}
}
updateResp := model.UpdateResp{
ResponseData: pkgList,
ReleaseInfo: []any{},
StatusCode: 200,
}
ss.Respond(updateResp)
}
func DownloadUrl(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
downloadReq := model.UrlReq{}
err := json.Unmarshal([]byte(ctx.GetString("request_data")), &downloadReq)
if ss.CheckErr(err) {
return
}
cdnServer := config.Conf.Settings.BackupCdnServer
if cdnServer == "" {
cdnServer = config.Conf.Settings.CdnServer
}
urlList := []string{}
for _, v := range downloadReq.PathList {
urlList = append(urlList, fmt.Sprintf("%s/%s/extracted/%s",
cdnServer, downloadReq.Os, strings.ReplaceAll(v, "\\", "")))
}
urlResp := model.UrlResp{
ResponseData: model.UrlRes{
UrlList: urlList,
},
ReleaseInfo: []any{},
StatusCode: 200,
}
ss.Respond(urlResp)
}
func DownloadEvent(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
eventResp := model.EventResp{
ResponseData: []any{},
ReleaseInfo: []any{},
StatusCode: 200,
}
ss.Respond(eventResp)
}
+58
View File
@@ -0,0 +1,58 @@
package download
import (
"encoding/json"
"fmt"
"honoka-chan/config"
"honoka-chan/internal/middleware"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/download"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
)
type PkgInfo struct {
Id int `xorm:"pkg_id"`
Order int `xorm:"pkg_order"`
Size int `xorm:"pkg_size"`
}
func additional(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
downloadReq := download.AdditionalReq{}
err := json.Unmarshal([]byte(ctx.MustGet("request_data").(string)), &downloadReq)
if ss.CheckErr(err) {
return
}
pkgList := []download.AdditionalData{}
pkgType, pkgId := downloadReq.PackageType, downloadReq.PackageID
var pkgInfo []PkgInfo
err = ss.MainEng.Table("download_m").Where("pkg_type = ? AND pkg_id = ? AND pkg_os = ?", pkgType, pkgId, downloadReq.TargetOs).
Cols("pkg_id,pkg_order,pkg_size").
OrderBy("pkg_id ASC, pkg_order ASC").Find(&pkgInfo)
if ss.CheckErr(err) {
return
}
for _, pkg := range pkgInfo {
pkgList = append(pkgList, download.AdditionalData{
Size: pkg.Size,
URL: fmt.Sprintf("%s/%s/archives/%d_%d_%d.zip",
config.Conf.Settings.CdnServer, downloadReq.TargetOs, pkgType, pkg.Id, pkg.Order),
})
}
ss.Respond(download.AdditionalResp{
ResponseData: pkgList,
ReleaseInfo: []any{},
StatusCode: 200,
})
}
func init() {
router.AddHandler("main.php", "POST", "/download/additional", middleware.Common, additional)
}
+55
View File
@@ -0,0 +1,55 @@
package download
import (
"encoding/json"
"fmt"
"honoka-chan/config"
"honoka-chan/internal/middleware"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/download"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
"xorm.io/builder"
)
func batch(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
downloadReq := download.BatchReq{}
err := json.Unmarshal([]byte(ctx.MustGet("request_data").(string)), &downloadReq)
if ss.CheckErr(err) {
return
}
pkgList := []download.BatchData{}
if downloadReq.ClientVersion == config.PackageVersion {
pkgType := downloadReq.PackageType
var pkgInfo []PkgInfo
err := ss.MainEng.Table("download_m").Where(builder.NotIn("pkg_id", downloadReq.ExcludedPackageIds)).Where("pkg_type = ? AND pkg_os = ?", pkgType, downloadReq.Os).
Cols("pkg_id,pkg_order,pkg_size").
OrderBy("pkg_id ASC, pkg_order ASC").Find(&pkgInfo)
if ss.CheckErr(err) {
return
}
for _, pkg := range pkgInfo {
pkgList = append(pkgList, download.BatchData{
Size: pkg.Size,
URL: fmt.Sprintf("%s/%s/archives/%d_%d_%d.zip",
config.Conf.Settings.CdnServer, downloadReq.Os, pkgType, pkg.Id, pkg.Order),
})
}
}
ss.Respond(download.BatchResp{
ResponseData: pkgList,
ReleaseInfo: []any{},
StatusCode: 200,
})
}
func init() {
router.AddHandler("main.php", "POST", "/download/batch", middleware.Common, batch)
}
+25
View File
@@ -0,0 +1,25 @@
package download
import (
"honoka-chan/internal/middleware"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/download"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
)
func event(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
ss.Respond(download.EventResp{
ResponseData: []any{},
ReleaseInfo: []any{},
StatusCode: 200,
})
}
func init() {
router.AddHandler("main.php", "POST", "/download/event", middleware.Common, event)
}
+72
View File
@@ -0,0 +1,72 @@
package download
import (
"encoding/json"
"fmt"
"honoka-chan/config"
"honoka-chan/internal/middleware"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/download"
"honoka-chan/internal/session"
"io"
"net/http"
"github.com/gin-gonic/gin"
)
func update(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
downloadReq := download.UpdateReq{}
err := json.Unmarshal([]byte(ctx.MustGet("request_data").(string)), &downloadReq)
if ss.CheckErr(err) {
return
}
pkgList := []download.UpdateData{}
if downloadReq.ExternalVersion != config.PackageVersion {
pkgType := 99
var pkgInfo []PkgInfo
err := ss.MainEng.Table("download_m").Where("pkg_type = ? AND pkg_os = ?", pkgType, downloadReq.TargetOs).
Cols("pkg_id,pkg_order,pkg_size").
OrderBy("pkg_id ASC, pkg_order ASC").Find(&pkgInfo)
if ss.CheckErr(err) {
return
}
for _, pkg := range pkgInfo {
pkgList = append(pkgList, download.UpdateData{
Size: pkg.Size,
URL: fmt.Sprintf("%s/%s/archives/%d_%d_%d.zip",
config.Conf.Settings.CdnServer, downloadReq.TargetOs, pkgType, pkg.Id, pkg.Order),
Version: config.PackageVersion,
})
}
patchFileURL := fmt.Sprintf("%s/%s/archives/99_0_115.zip",
config.Conf.Settings.CdnServer, downloadReq.TargetOs)
resp, err := http.Get(patchFileURL)
if err == nil {
res, err := io.ReadAll(resp.Body)
if err == nil {
pkgList = append(pkgList, download.UpdateData{
Size: len(res),
URL: patchFileURL,
Version: config.PackageVersion,
})
}
defer resp.Body.Close()
}
}
ss.Respond(download.UpdateResp{
ResponseData: pkgList,
ReleaseInfo: []any{},
StatusCode: 200,
})
}
func init() {
router.AddHandler("main.php", "POST", "/download/update", middleware.Common, update)
}
+48
View File
@@ -0,0 +1,48 @@
package download
import (
"encoding/json"
"fmt"
"honoka-chan/config"
"honoka-chan/internal/middleware"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/download"
"honoka-chan/internal/session"
"strings"
"github.com/gin-gonic/gin"
)
func url(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
downloadReq := download.UrlReq{}
err := json.Unmarshal([]byte(ctx.MustGet("request_data").(string)), &downloadReq)
if ss.CheckErr(err) {
return
}
cdnServer := config.Conf.Settings.BackupCdnServer
if cdnServer == "" {
cdnServer = config.Conf.Settings.CdnServer
}
urlList := []string{}
for _, v := range downloadReq.PathList {
urlList = append(urlList, fmt.Sprintf("%s/%s/extracted/%s",
cdnServer, downloadReq.Os, strings.ReplaceAll(v, "\\", "")))
}
ss.Respond(download.UrlResp{
ResponseData: download.UrlData{
UrlList: urlList,
},
ReleaseInfo: []any{},
StatusCode: 200,
})
}
func init() {
router.AddHandler("main.php", "POST", "/download/url", middleware.Common, url)
}
-32
View File
@@ -1,32 +0,0 @@
package handler
import (
"honoka-chan/internal/model"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func EventList(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
targets := []model.TargetList{}
for i := range 6 {
targets = append(targets, model.TargetList{
Position: i + 1,
IsDisplayable: false,
})
}
eventsResp := model.EventsResp{
ResponseData: model.EventsRes{
TargetList: targets,
ServerTimestamp: time.Now().Unix(),
},
ReleaseInfo: []any{},
StatusCode: 200,
}
ss.Respond(eventsResp)
}
+45
View File
@@ -0,0 +1,45 @@
package event
import (
"honoka-chan/internal/middleware"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/event"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func list(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
targets := []event.TargetList{}
for i := range 6 {
targets = append(targets, event.TargetList{
Position: i + 1,
IsDisplayable: false,
})
}
// ss.Respond(event.ListResp{
// ResponseData: map[string]int{
// "error_code": 10004,
// },
// ReleaseInfo: []any{},
// StatusCode: 600,
// })
ss.Respond(event.ListResp{
ResponseData: event.ListData{
TargetList: targets,
ServerTimestamp: time.Now().Unix(),
},
ReleaseInfo: []any{},
StatusCode: 200,
})
}
func init() {
router.AddHandler("main.php", "POST", "/event/eventList", middleware.Common, list)
}
-26
View File
@@ -1,26 +0,0 @@
package handler
import (
"honoka-chan/internal/model"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func Gdpr(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
gdprResp := model.GdprResp{
ResponseData: model.GdprRes{
EnableGdpr: true,
IsEea: false,
ServerTimestamp: time.Now().Unix(),
},
ReleaseInfo: []any{},
StatusCode: 200,
}
ss.Respond(gdprResp)
}
+30
View File
@@ -0,0 +1,30 @@
package gdpr
import (
"honoka-chan/internal/middleware"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/gdpr"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func get(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
ss.Respond(gdpr.GetResp{
ResponseData: gdpr.GetData{
EnableGdpr: true,
IsEea: false,
ServerTimestamp: time.Now().Unix(),
},
ReleaseInfo: []any{},
StatusCode: 200,
})
}
func init() {
router.AddHandler("main.php", "POST", "/gdpr/get", middleware.Common, get)
}
+27
View File
@@ -0,0 +1,27 @@
package account
import (
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
)
func active(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
ss.Respond(ghome.ActiveResp{
Code: 0,
Msg: "ok",
Data: ghome.ActiveData{
Message: "ok",
Result: 0,
},
})
}
func init() {
router.AddHandler("v1", "POST", "/account/active", active)
}
@@ -0,0 +1,50 @@
package account
import (
"encoding/base64"
"encoding/json"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
"strings"
"github.com/gin-gonic/gin"
"github.com/go-think/openssl"
)
func initialize(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
initData := ghome.InitializeData{
BrandLogo: "http://gskd.sdo.com/ghome/ztc/logo/og/logo_xhdpi.png",
BrandName: "盛趣游戏",
ForceShowAgreement: 1,
GreportLogLevel: "off",
LogLevel: "off",
LoginButton: []string{"official"},
LoginIcon: []any{},
NeedFloatWindowPermission: 1,
NewDeviceIDServer: strings.ToUpper(openssl.Md5ToString(ss.GetDeviceID())),
ShowGuestConfirm: 1,
VoicetipButton: 1,
}
data, err := json.Marshal(initData)
if ss.CheckErr(err) {
return
}
encryptedData, err := openssl.Des3ECBEncrypt([]byte(data), ss.GetRandKey()[0:24], openssl.PKCS7_PADDING)
if ss.CheckErr(err) {
return
}
ss.Respond(ghome.InitializeResp{
Code: 0,
Msg: "ok",
Data: base64.StdEncoding.EncodeToString(encryptedData),
})
}
func init() {
router.AddHandler("v1", "POST", "/account/initialize", initialize)
}
+248
View File
@@ -0,0 +1,248 @@
package account
import (
"encoding/base64"
"encoding/json"
"fmt"
"honoka-chan/internal/model/user"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/api/profile"
"honoka-chan/internal/schema/api/unit"
ghomeschema "honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
honokautils "honoka-chan/pkg/utils"
"net/url"
"strconv"
"strings"
"time"
"github.com/gin-gonic/gin"
"github.com/go-think/openssl"
)
func login(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
data, err := ctx.GetRawData()
if ss.CheckErr(err) {
return
}
data, err = base64.StdEncoding.DecodeString(string(data))
if ss.CheckErr(err) {
return
}
randKey := ss.GetRandKey()
decryptedData, err := openssl.Des3ECBDecrypt(data, randKey[0:24], openssl.PKCS7_PADDING)
if ss.CheckErr(err) {
return
}
queryStr, _ := url.QueryUnescape(string(decryptedData))
params, _ := url.ParseQuery(queryStr)
phone, password := params.Get("phone"), params.Get("password")
var userID int
var pass, autoKey, ticket string
_, err = ss.UserEng.Table("users").Cols("password,autokey,ticket,user_id").
Where("phone = ?", phone).Get(&pass, &autoKey, &ticket, &userID)
if ss.CheckErr(err) {
return
}
loginData := ghomeschema.LoginData{}
loginCode := 0
loginMsg := "ok"
loginTime := time.Now().Unix()
if pass == "" {
// 未注册 - 自动注册
// 检查是否 userID 已经注册
userID, _ = checkUserID(ss, int(loginTime))
pass = openssl.Md5ToString(password)
autoKey = "AUTO" + strings.ToUpper(honokautils.RandomStr(32))
ticket = fmt.Sprintf("9999999%d%d", userID, userID)
userData := user.Users{
Phone: phone,
Password: pass,
Autokey: autoKey,
Ticket: ticket,
UserID: userID,
LastLoginTime: loginTime,
}
_, err = ss.UserEng.Table("users").Insert(&userData)
if ss.CheckErr(err) {
return
}
// 方便起见初始化 userid 和 key 一样
// 注意:user_key 表中的 key 是上文生成的用于登录的 userid,而 userid 则是用于 Authorize Token 生成用的
userKey := user.UserKey{
UserID: userID,
Key: userID,
}
_, err = ss.UserEng.Table("user_key").Insert(&userKey)
if ss.CheckErr(err) {
return
}
// 检查用户配置
exists, err := ss.UserEng.Table("user_pref").Where("user_id = ?", userID).Exist()
if ss.CheckErr(err) {
return
}
if !exists {
// 默认中心成员
var unitOwningUserID int
_, err = ss.MainEng.Table("common_unit_m").Cols("unit_owning_user_id").Where("unit_id = ?", 31).Get(&unitOwningUserID)
if ss.CheckErr(err) {
return
}
userPref := user.UserPref{
UserID: userID,
AwardID: 1, // 音乃木坂学生
BackgroundID: 1, // 初始背景
UnitOwningUserID: unitOwningUserID,
UserName: "音乃木坂学生",
UserLevel: 1,
UserDesc: "你好。",
InviteCode: strconv.Itoa(userID),
UpdateTime: time.Now().Unix(),
}
_, err = ss.UserEng.Table("user_pref").Insert(&userPref)
if ss.CheckErr(err) {
return
}
}
// 检查用户卡组配置
exists, err = ss.UserEng.Table("user_deck").Where("user_id = ?", userID).Exist()
if ss.CheckErr(err) {
return
}
if !exists {
// 默认队伍
userDeck := unit.UserDeckData{
DeckID: 1,
MainFlag: 1,
DeckName: "队伍A",
UserID: userID,
InsertDate: time.Now().Unix(),
}
_, err = ss.UserEng.Table("user_deck").Insert(&userDeck)
userDeckID := userDeck.ID
// 默认卡组 - 仆光
unitID := []int{}
err = ss.MainEng.Table("unit_m").Cols("unit_id").Where("album_series_id = ?", 615).Find(&unitID)
if ss.CheckErr(err) {
return
}
unitData := []profile.UnitData{}
err = ss.MainEng.Table("common_unit_m").In("unit_id", unitID).Find(&unitData)
if ss.CheckErr(err) {
return
}
position := 1
for _, u := range unitData {
unitDeckData := unit.UnitDeckData{
UserDeckID: userDeckID,
UnitOwningUserID: u.UnitOwningUserID,
UnitID: u.UnitID,
Position: position,
Level: 100,
LevelLimitID: 1,
DisplayRank: 2,
Love: 1000,
UnitSkillLevel: 8,
IsRankMax: true,
IsLoveMax: true,
IsLevelMax: true,
IsSigned: u.IsSigned,
BeforeLove: 1000,
MaxLove: 1000,
InsertData: time.Now().Unix(),
}
_, err = ss.UserEng.Table("user_deck_unit").Insert(&unitDeckData)
if ss.CheckErr(err) {
return
}
position++
}
}
loginData.Autokey = autoKey
loginData.HasRealInfo = 1
loginData.Message = "ok"
loginData.RealInfoForce = 1
loginData.Ticket = ticket
loginData.UserAttribute = "0"
loginData.UserID = userID
} else {
// 已注册 - 检查密码
if pass != openssl.Md5ToString(password) {
loginCode = 31
loginMsg = "账号不存在或者密码有误!"
} else {
userData := user.Users{
Autokey: autoKey,
Ticket: ticket,
LastLoginTime: loginTime,
}
_, err = ss.UserEng.Table("users").Where("user_id = ?", userID).Update(&userData)
if ss.CheckErr(err) {
return
}
loginData.Autokey = autoKey // 注意:更换设备(deviceId 发生变化)应重新生成 autokey
loginData.HasRealInfo = 1
loginData.Message = "ok"
loginData.RealInfoForce = 1
loginData.Ticket = fmt.Sprintf("9999999%d%d", userID, loginTime) // 实际登录用的密码(每次登录都会重新生成新的)
loginData.UserAttribute = "0"
loginData.UserID = userID // 实际登录用的账号
}
}
data, err = json.Marshal(loginData)
if ss.CheckErr(err) {
return
}
encryptedData, err := openssl.Des3ECBEncrypt([]byte(data), randKey[0:24], openssl.PKCS7_PADDING)
if ss.CheckErr(err) {
return
}
ss.Respond(ghomeschema.LoginResp{
Code: loginCode,
Msg: loginMsg,
Data: base64.StdEncoding.EncodeToString(encryptedData),
})
}
func checkUserID(ss *session.Session, userID int) (int, bool) {
exist, err := ss.UserEng.Table("users").Where("user_id = ?", userID).Exist()
if ss.CheckErr(err) {
return 0, false
}
if exist {
userID = int(time.Now().Unix())
return checkUserID(ss, userID)
}
return userID, true
}
func init() {
router.AddHandler("v1", "POST", "/account/login", login)
}
@@ -0,0 +1,83 @@
package account
import (
"encoding/base64"
"encoding/json"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
"net/url"
"github.com/gin-gonic/gin"
"github.com/go-think/openssl"
)
func loginAuto(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
data, err := ctx.GetRawData()
if ss.CheckErr(err) {
return
}
data, err = base64.StdEncoding.DecodeString(string(data))
if ss.CheckErr(err) {
return
}
randKey := ss.GetRandKey()
decryptedData, err := openssl.Des3ECBDecrypt(data, randKey[0:24], openssl.PKCS7_PADDING)
if ss.CheckErr(err) {
return
}
queryStr, _ := url.QueryUnescape(string(decryptedData))
params, _ := url.ParseQuery(queryStr)
autoKey := params.Get("autokey")
var uid, ticket string
_, err = ss.UserEng.Table("users").Cols("user_id,ticket").Where("autokey = ?", autoKey).Get(&uid, &ticket)
if ss.CheckErr(err) {
return
}
loginAutoData := ghome.LoginAutoData{}
loginAutoCode := 0
loginAutoMsg := "ok"
if uid != "" {
loginAutoData = ghome.LoginAutoData{
Result: loginAutoCode,
Message: loginAutoMsg,
Autokey: autoKey,
UserId: uid,
Ticket: ticket,
}
} else {
loginAutoCode = 31
loginAutoMsg = "账号不存在或者登陆状态已过期!"
loginAutoData = ghome.LoginAutoData{
Result: loginAutoCode,
Message: loginAutoMsg,
}
}
data, err = json.Marshal(loginAutoData)
if ss.CheckErr(err) {
return
}
encryptedData, err := openssl.Des3ECBEncrypt([]byte(data), randKey[0:24], openssl.PKCS7_PADDING)
if ss.CheckErr(err) {
return
}
ss.Respond(ghome.LoginAutoResp{
Code: loginAutoCode,
Msg: loginAutoMsg,
Data: base64.StdEncoding.EncodeToString(encryptedData),
})
}
func init() {
router.AddHandler("v1", "POST", "/account/loginauto", loginAuto)
}
@@ -0,0 +1,33 @@
package account
import (
"encoding/base64"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
"github.com/go-think/openssl"
)
func reportRole(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
randKey := ss.GetRandKey()
token := `{"message":"ok"}`
encryptedToken, err := openssl.Des3ECBEncrypt([]byte(token), randKey[0:24], openssl.PKCS7_PADDING)
if ss.CheckErr(err) {
return
}
ss.Respond(ghome.ReportRoleResp{
Code: 0,
Msg: "ok",
Data: base64.StdEncoding.EncodeToString(encryptedToken),
})
}
func init() {
router.AddHandler("v1", "POST", "/account/reportRole", reportRole)
}
+33
View File
@@ -0,0 +1,33 @@
package basic
import (
"encoding/json"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
)
func getCode(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
codeArray := `{"codeArray":[{"btntext":"好的","code":"-10264022","msg_from":2,"text":"","title":"短信验证码被阻止","type":1},{"btntext":"","code":"-10869623","msg_from":2,"text":"","title":"网络连接失败,无法一键登录","type":2},{"btntext":"","code":"10298300","msg_from":2,"text":"","title":"","type":3},{"btntext":"","code":"10298311","msg_from":2,"text":"","title":"","type":3},{"btntext":"","code":"10298312","msg_from":2,"text":"","title":"","type":3},{"btntext":"","code":"10298313","msg_from":2,"text":"","title":"","type":1},{"btntext":"","code":"10298321","msg_from":2,"text":"","title":"","type":3},{"btntext":"","code":"10298322","msg_from":2,"text":"","title":"","type":3}],"codeVersion":"1.0.5"}`
getCodeData := map[string]any{}
err := json.Unmarshal([]byte(codeArray), &getCodeData)
if ss.CheckErr(err) {
return
}
ss.Respond(ghome.GetCodeResp{
Code: 0,
Msg: "ok",
Data: getCodeData,
})
}
func init() {
router.AddHandler("v1", "GET", "/basic/getcode", getCode)
router.AddHandler("v1", "POST", "/basic/getcode", getCode)
}
@@ -0,0 +1,29 @@
package basic
import (
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
)
func getProductList(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
getProductListData := ghome.GetProductListData{
Message: []string{},
Result: 0,
}
ss.Respond(ghome.GetProductListResp{
Code: 1,
Msg: "ok",
Data: getProductListData,
})
}
func init() {
router.AddHandler("v1", "POST", "/basic/getProductList", getProductList)
}
+60
View File
@@ -0,0 +1,60 @@
package basic
import (
"encoding/base64"
"fmt"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
"honoka-chan/pkg/db"
"honoka-chan/pkg/encrypt"
honokautils "honoka-chan/pkg/utils"
"net/url"
"strings"
"github.com/gin-gonic/gin"
"github.com/go-think/openssl"
)
func handshake(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
data, err := ctx.GetRawData()
if ss.CheckErr(err) {
return
}
data, err = base64.StdEncoding.DecodeString(string(data))
if ss.CheckErr(err) {
return
}
decryptedData := encrypt.RSADecrypt(data)
params, _ := url.ParseQuery(string(decryptedData))
randKey := []byte(params.Get("randkey"))
deviceID := ss.GetDeviceID()
err = db.Ldb.Set([]byte(deviceID), randKey)
if ss.CheckErr(err) {
return
}
token := fmt.Sprintf(`{"message":"ok","result":0,"token":"%s"}`, strings.ToUpper(honokautils.RandomStr(33)))
encryptedToken, err := openssl.Des3ECBEncrypt([]byte(token), randKey[0:24], openssl.PKCS7_PADDING)
if ss.CheckErr(err) {
return
}
ss.Respond(ghome.HandshakeResp{
Code: 0,
Msg: "ok",
Data: base64.StdEncoding.EncodeToString(encryptedToken),
})
}
func init() {
router.AddHandler("v1", "POST", "/basic/handshake", handshake)
}
+26
View File
@@ -0,0 +1,26 @@
package basic
import (
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
)
func loginArea(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
ss.Respond(ghome.LoginAreaResp{
Code: 0,
Msg: "ok",
Data: ghome.LoginAreaData{
UserID: ctx.PostForm("userid"),
},
})
}
func init() {
router.AddHandler("v1", "POST", "/basic/loginarea", loginArea)
}
+45
View File
@@ -0,0 +1,45 @@
package basic
import (
"encoding/base64"
"encoding/pem"
"honoka-chan/config"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
honokautils "honoka-chan/pkg/utils"
"github.com/gin-gonic/gin"
)
func publicKey(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
publicKeyCode := 0
publicKeyMsg := "ok"
publicKeyData := ghome.PublicKeyData{
Result: publicKeyCode,
Message: publicKeyMsg,
}
publicKey := honokautils.ReadAllText(config.PublicKeyPath)
block, _ := pem.Decode([]byte(publicKey))
if block == nil || block.Type != "PUBLIC KEY" {
publicKeyMsg = "公钥读取失败!"
publicKeyCode = 31
} else {
publicKeyData.Key = base64.StdEncoding.EncodeToString(block.Bytes)
publicKeyData.Method = "rsa"
}
ss.Respond(ghome.PublicKeyResp{
Code: publicKeyCode,
Msg: publicKeyMsg,
Data: publicKeyData,
})
}
func init() {
router.AddHandler("v1", "POST", "/basic/publickey", publicKey)
}
+8
View File
@@ -0,0 +1,8 @@
package ghome
import (
_ "honoka-chan/internal/handler/ghome/account"
_ "honoka-chan/internal/handler/ghome/basic"
_ "honoka-chan/internal/handler/ghome/guest"
_ "honoka-chan/internal/handler/ghome/misc"
)
+29
View File
@@ -0,0 +1,29 @@
package guest
import (
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
)
func status(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
ss.Respond(ghome.GuestStatusResp{
Code: 0,
Msg: "ok",
Data: ghome.GuestStatusData{
Disablead: 1,
Loginswitch: 1,
Message: "ok",
Result: 0,
},
})
}
func init() {
router.AddHandler("v1", "POST", "/guest/status", status)
}
+25
View File
@@ -0,0 +1,25 @@
package misc
import (
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
)
func agreement(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
ss.Respond(ghome.AgreementResp{
ReturnCode: 0,
ErrorType: 0,
ReturnMessage: "",
Data: ghome.AgreementData{},
})
}
func init() {
router.AddHandler("/", "GET", "/agreement/all", agreement)
}
@@ -0,0 +1,26 @@
package misc
import (
"honoka-chan/internal/router"
"honoka-chan/internal/schema/ghome"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
)
func appReport(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
ss.Respond(ghome.AppReportResp{
Code: 0,
Msg: "",
Data: ghome.AppReportData{
NeedReport: 0,
},
})
}
func init() {
router.AddHandler("/", "GET", "/integration/appReport/initialize", appReport)
}
+16
View File
@@ -0,0 +1,16 @@
package misc
import (
"honoka-chan/internal/router"
"net/http"
"github.com/gin-gonic/gin"
)
func report(ctx *gin.Context) {
ctx.Status(http.StatusOK)
}
func init() {
router.AddHandler("/", "POST", "/report/ge/app", report)
}
+25 -2
View File
@@ -1,5 +1,28 @@
package handler
var (
ErrorMsg = `{"code":20001,"message":""}`
import (
_ "honoka-chan/internal/handler/album"
_ "honoka-chan/internal/handler/announce"
_ "honoka-chan/internal/handler/api"
_ "honoka-chan/internal/handler/award"
_ "honoka-chan/internal/handler/background"
_ "honoka-chan/internal/handler/download"
_ "honoka-chan/internal/handler/event"
_ "honoka-chan/internal/handler/gdpr"
_ "honoka-chan/internal/handler/ghome"
_ "honoka-chan/internal/handler/lbonus"
_ "honoka-chan/internal/handler/live"
_ "honoka-chan/internal/handler/login"
_ "honoka-chan/internal/handler/multiunit"
_ "honoka-chan/internal/handler/museum"
_ "honoka-chan/internal/handler/notice"
_ "honoka-chan/internal/handler/payment"
_ "honoka-chan/internal/handler/personalnotice"
_ "honoka-chan/internal/handler/profile"
_ "honoka-chan/internal/handler/scenario"
_ "honoka-chan/internal/handler/subscenario"
_ "honoka-chan/internal/handler/tos"
_ "honoka-chan/internal/handler/unit"
_ "honoka-chan/internal/handler/user"
_ "honoka-chan/internal/handler/webui"
)
@@ -1,15 +1,17 @@
package handler
package lbonus
import (
"honoka-chan/internal/model"
"honoka-chan/internal/middleware"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/lbonus"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func LBonusExecute(ctx *gin.Context) {
ss := session.New(ctx)
func execute(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
weeks := map[string]int{
@@ -33,7 +35,7 @@ func LBonusExecute(ctx *gin.Context) {
d2 := d1.AddDate(0, 1, -1)
// fmt.Println(d2)
weeksList := []model.LbDays{}
weeksList := []lbonus.Day{}
for c := d1; ; c = c.AddDate(0, 0, 1) {
_, _, rd := c.Date()
received := false
@@ -41,14 +43,14 @@ func LBonusExecute(ctx *gin.Context) {
received = true
}
rw := weeks[c.Weekday().String()]
weeksList = append(weeksList, model.LbDays{
weeksList = append(weeksList, lbonus.Day{
Day: rd,
DayOfTheWeek: rw,
SpecialDay: false,
SpecialImageAsset: "",
Received: received,
AdReceived: false,
Item: model.LbDayItem{
Item: lbonus.Item{
ItemID: 4,
AddType: 3001,
Amount: 1,
@@ -70,18 +72,18 @@ func LBonusExecute(ctx *gin.Context) {
d2 = d1.AddDate(0, 1, -1)
// fmt.Println(d2)
nextWeeksList := []model.LbDays{}
nextWeeksList := []lbonus.Day{}
for c := d1; ; c = c.AddDate(0, 0, 1) {
_, _, rd := c.Date()
rw := weeks[c.Weekday().String()]
nextWeeksList = append(nextWeeksList, model.LbDays{
nextWeeksList = append(nextWeeksList, lbonus.Day{
Day: rd,
DayOfTheWeek: rw,
SpecialDay: false,
SpecialImageAsset: "",
Received: false,
AdReceived: false,
Item: model.LbDayItem{
Item: lbonus.Item{
ItemID: 4,
AddType: 3001,
Amount: 1,
@@ -92,26 +94,26 @@ func LBonusExecute(ctx *gin.Context) {
}
}
LbRes := model.LbResp{
ResponseData: model.LbRes{
resp := lbonus.ExecuteResp{
ResponseData: lbonus.ExecuteData{
Sheets: []any{},
CalendarInfo: model.CalendarInfo{
CalendarInfo: lbonus.CalendarInfo{
CurrentDate: time.Now().Format("2006-01-02 03:04:05"),
CurrentMonth: model.LbMonth{
CurrentMonth: lbonus.Month{
Year: y,
Month: int(cm),
Days: weeksList,
},
NextMonth: model.LbMonth{
NextMonth: lbonus.Month{
Year: y,
Month: int(m),
Days: nextWeeksList,
},
},
TotalLoginInfo: model.TotalLoginInfo{
TotalLoginInfo: lbonus.TotalLoginInfo{
LoginCount: 2626,
RemainingCount: 74,
Reward: []model.Reward{
Reward: []lbonus.Reward{
{
ItemID: 5,
AddType: 1000,
@@ -120,8 +122,8 @@ func LBonusExecute(ctx *gin.Context) {
},
},
LicenseLbonusList: []any{},
ClassSystem: model.LbClassSystem{
RankInfo: model.LbRankInfo{
ClassSystem: lbonus.ClassSystem{
RankInfo: lbonus.RankInfo{
BeforeClassRankID: 10,
AfterClassRankID: 10,
RankUpDate: "2020-02-12 11:57:15",
@@ -131,17 +133,17 @@ func LBonusExecute(ctx *gin.Context) {
IsVisible: true,
},
StartDashSheets: []any{},
EffortPoint: []model.EffortPoint{
EffortPoint: []lbonus.EffortPoint{
{
LiveEffortPointBoxSpecID: 5,
Capacity: 4000000,
Before: 1400116,
After: 1400116,
Rewards: []model.Rewards{},
Rewards: []lbonus.Rewards{},
},
},
LimitedEffortBox: []any{},
MuseumInfo: model.Museum{},
MuseumInfo: lbonus.Museum{},
ServerTimestamp: time.Now().Unix(),
PresentCnt: 0,
},
@@ -149,5 +151,9 @@ func LBonusExecute(ctx *gin.Context) {
StatusCode: 200,
}
ss.Respond(LbRes)
ss.Respond(resp)
}
func init() {
router.AddHandler("main.php", "POST", "/lbonus/execute", middleware.Common, execute)
}
+25
View File
@@ -0,0 +1,25 @@
package live
import (
"honoka-chan/internal/middleware"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/live"
"honoka-chan/internal/session"
"github.com/gin-gonic/gin"
)
func gameOver(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
ss.Respond(live.GameOverResp{
ResponseData: []any{},
ReleaseInfo: []any{},
StatusCode: 200,
})
}
func init() {
router.AddHandler("main.php", "POST", "/live/gameover", middleware.Common, gameOver)
}
+29
View File
@@ -0,0 +1,29 @@
package live
import (
"encoding/json"
"honoka-chan/internal/middleware"
"honoka-chan/internal/router"
"honoka-chan/internal/session"
honokautils "honoka-chan/pkg/utils"
"github.com/gin-gonic/gin"
)
func partyList(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
data := honokautils.ReadAllText("assets/serverdata/partylist.json")
var partyResp map[string]any
err := json.Unmarshal([]byte(data), &partyResp)
if ss.CheckErr(err) {
return
}
ss.Respond(partyResp)
}
func init() {
router.AddHandler("main.php", "POST", "/live/partyList", middleware.Common, partyList)
}
@@ -1,10 +1,11 @@
package handler
package live
import (
"encoding/json"
"fmt"
"honoka-chan/config"
"honoka-chan/internal/model"
"honoka-chan/internal/middleware"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/live"
"honoka-chan/internal/session"
"honoka-chan/pkg/db"
honokautils "honoka-chan/pkg/utils"
@@ -16,26 +17,12 @@ import (
"github.com/tidwall/gjson"
)
func PartyList(ctx *gin.Context) {
ss := session.New(ctx)
func play(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
data := honokautils.ReadAllText("assets/serverdata/partylist.json")
var partyResp map[string]any
err := json.Unmarshal([]byte(data), &partyResp)
if ss.CheckErr(err) {
return
}
ss.Respond(partyResp)
}
func PlayLive(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
playReq := model.PlayReq{}
err := json.Unmarshal([]byte(ctx.GetString("request_data")), &playReq)
playReq := live.PlayReq{}
err := json.Unmarshal([]byte(ctx.MustGet("request_data").(string)), &playReq)
if ss.CheckErr(err) {
return
}
@@ -48,8 +35,8 @@ func PlayLive(ctx *gin.Context) {
deckId := playReq.UnitDeckID
// Save Deck Id for /live/reward
key := "live_deck_" + ctx.GetString("userid")
err = db.DB.Set([]byte(key), []byte(strconv.Itoa(deckId)))
key := "live_deck_" + strconv.Itoa(ss.UserID)
err = db.Ldb.Set([]byte(key), []byte(strconv.Itoa(deckId)))
if ss.CheckErr(err) {
return
}
@@ -67,32 +54,32 @@ func PlayLive(ctx *gin.Context) {
// fmt.Println(notes_setting_asset)
// fmt.Println(c_rank_score, b_rank_score, a_rank_score, s_rank_score)
notes := []model.NotesList{}
// fmt.Println("./assets/notes/" + notes_setting_asset)
notes_list := honokautils.ReadAllText("./assets/serverdata/notes/" + notes_setting_asset)
notes := []live.NotesList{}
// fmt.Println("./assets/serverdata/beatmaps/" + notes_setting_asset)
notes_list := honokautils.ReadAllText("./assets/serverdata/beatmaps/" + notes_setting_asset)
err = json.Unmarshal([]byte(notes_list), &notes)
if ss.CheckErr(err) {
return
}
ranks := []model.RankInfo{}
ranks = append(ranks, model.RankInfo{
ranks := []live.RankInfo{}
ranks = append(ranks, live.RankInfo{
Rank: 5,
RankMin: 0,
RankMax: c_rank_score,
}, model.RankInfo{
}, live.RankInfo{
Rank: 4,
RankMin: c_rank_score + 1,
RankMax: b_rank_score,
}, model.RankInfo{
}, live.RankInfo{
Rank: 3,
RankMin: b_rank_score + 1,
RankMax: a_rank_score,
}, model.RankInfo{
}, live.RankInfo{
Rank: 2,
RankMin: a_rank_score + 1,
RankMax: s_rank_score,
}, model.RankInfo{
}, live.RankInfo{
Rank: 1,
RankMin: s_rank_score + 1,
RankMax: 0,
@@ -101,14 +88,14 @@ func PlayLive(ctx *gin.Context) {
// ss.UserEng.ShowSQL(true)
// ss.MainEng.ShowSQL(true)
owningIdList := []int{}
err = ss.UserEng.Table("deck_unit_m").Join("LEFT", "user_deck_m", "deck_unit_m.user_deck_id = user_deck_m.id").
Where("user_id = ? AND deck_id = ?", ctx.GetString("userid"), deckId).Cols("unit_owning_user_id").
OrderBy("deck_unit_m.position ASC").Find(&owningIdList)
err = ss.UserEng.Table("user_deck_unit").Join("LEFT", "user_deck", "user_deck_unit.user_deck_id = user_deck.id").
Where("user_id = ? AND deck_id = ?", ss.UserID, deckId).Cols("unit_owning_user_id").
OrderBy("user_deck_unit.position ASC").Find(&owningIdList)
if ss.CheckErr(err) {
return
}
unitList := []model.UnitList{}
unitList := []live.UnitList{}
var totalSmile, totalPure, totalCool, maxLove float64
var totalHp int
for _, owningId := range owningIdList {
@@ -131,7 +118,7 @@ func PlayLive(ctx *gin.Context) {
}
} else {
// 用户卡片暂时固定为满级350级
exists, err := ss.UserEng.Table("user_unit_m").Where("unit_owning_user_id = ?", owningId).Cols("unit_id").Get(&uId)
exists, err := ss.UserEng.Table("user_unit").Where("unit_owning_user_id = ?", owningId).Cols("unit_id").Get(&uId)
if ss.CheckErr(err) {
return
}
@@ -168,7 +155,7 @@ func PlayLive(ctx *gin.Context) {
// 饰品属性加成(满级)
var accessoryOwningId int
_, err = ss.UserEng.Table("accessory_wear_m").Where("unit_owning_user_id = ?", owningId).
_, err = ss.UserEng.Table("user_accessory_wear").Where("unit_owning_user_id = ?", owningId).
Cols("accessory_owning_user_id").Get(&accessoryOwningId)
if ss.CheckErr(err) {
return
@@ -221,7 +208,7 @@ func PlayLive(ctx *gin.Context) {
// 宝石加成(满级)
removableSkillIds := []int{}
err = ss.UserEng.Table("skill_equip_m").Where("unit_owning_user_id = ? AND user_id = ?", owningId, ctx.GetString("userid")).
err = ss.UserEng.Table("user_unit_skill_equip").Where("unit_owning_user_id = ? AND user_id = ?", owningId, ss.UserID).
Cols("unit_removable_skill_id").Find(&removableSkillIds)
if ss.CheckErr(err) {
return
@@ -289,9 +276,9 @@ func PlayLive(ctx *gin.Context) {
// 主唱技能加成
var myCenterUnitId int
_, err = ss.UserEng.Table("deck_unit_m").Join("LEFT", "user_deck_m", "deck_unit_m.user_deck_id = user_deck_m.id").
Where("user_deck_m.deck_id = ? AND user_deck_m.user_id = ? AND deck_unit_m.position = 5", playReq.UnitDeckID, ctx.GetString("userid")).
Cols("deck_unit_m.unit_id").Get(&myCenterUnitId)
_, err = ss.UserEng.Table("user_deck_unit").Join("LEFT", "user_deck", "user_deck_unit.user_deck_id = user_deck.id").
Where("user_deck.deck_id = ? AND user_deck.user_id = ? AND user_deck_unit.position = 5", playReq.UnitDeckID, ss.UserID).
Cols("user_deck_unit.unit_id").Get(&myCenterUnitId)
if ss.CheckErr(err) {
return
}
@@ -421,7 +408,7 @@ func PlayLive(ctx *gin.Context) {
fixedCoolMax := int(coolMax)
// fmt.Println("单卡属性:", fixedSmileMax, fixedPureMax, fixedCoolMax)
unitList = append(unitList, model.UnitList{
unitList = append(unitList, live.UnitList{
Smile: fixedSmileMax,
Cute: fixedPureMax,
Cool: fixedCoolMax,
@@ -434,16 +421,16 @@ func PlayLive(ctx *gin.Context) {
fixedTotalCool := int(math.Ceil(totalCool))
// fmt.Println("全卡组属性:", fixedTotalSmile, fixedTotalPure, fixedTotalCool)
lives := []model.PlayLiveList{}
lives = append(lives, model.PlayLiveList{
LiveInfo: model.LiveInfo{
lives := []live.PlayLiveList{}
lives = append(lives, live.PlayLiveList{
LiveInfo: live.LiveInfo{
LiveDifficultyID: difficultyId,
IsRandom: false,
AcFlag: ac_flag,
SwingFlag: swing_flag,
NotesList: notes,
},
DeckInfo: model.DeckInfo{
DeckInfo: live.DeckInfo{
UnitDeckID: deckId,
TotalSmile: fixedTotalSmile,
TotalCute: fixedTotalPure,
@@ -454,8 +441,8 @@ func PlayLive(ctx *gin.Context) {
},
})
playResp := model.PlayResp{
ResponseData: model.PlayRes{
playResp := live.PlayResp{
ResponseData: live.PlayData{
RankInfo: ranks,
EnergyFullTime: "2023-03-20 01:28:55",
OverMaxEnergy: 0,
@@ -474,296 +461,6 @@ func PlayLive(ctx *gin.Context) {
ss.Respond(playResp)
}
func GameOver(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
overResp := model.GameOverResp{
ResponseData: []any{},
ReleaseInfo: []any{},
StatusCode: 200,
}
ss.Respond(overResp)
}
func PlayScore(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
playScoreReq := model.PlayScoreReq{}
err := json.Unmarshal([]byte(ctx.GetString("request_data")), &playScoreReq)
if ss.CheckErr(err) {
return
}
tDifficultyId := playScoreReq.LiveDifficultyID
difficultyId, err := strconv.Atoi(tDifficultyId)
if ss.CheckErr(err) {
return
}
// Song type: normal / special
// sqlite3 doesn't support FULL OUTER JOIN so use UNION ALL here.
sql := `SELECT notes_setting_asset,c_rank_score,b_rank_score,a_rank_score,s_rank_score,ac_flag,swing_flag FROM live_setting_m WHERE live_setting_id IN (SELECT live_setting_id FROM normal_live_m WHERE live_difficulty_id = ? UNION ALL SELECT live_setting_id FROM special_live_m WHERE live_difficulty_id = ?)`
var notes_setting_asset string
var c_rank_score, b_rank_score, a_rank_score, s_rank_score, ac_flag, swing_flag int
err = ss.MainEng.DB().QueryRow(sql, difficultyId, difficultyId).Scan(&notes_setting_asset, &c_rank_score, &b_rank_score, &a_rank_score, &s_rank_score, &ac_flag, &swing_flag)
if ss.CheckErr(err) {
return
}
// fmt.Println(notes_setting_asset)
// fmt.Println(c_rank_score, b_rank_score, a_rank_score, s_rank_score)
notes := []model.NotesList{}
// fmt.Println("./assets/notes/" + notes_setting_asset)
notes_list := honokautils.ReadAllText("./assets/serverdata/notes/" + notes_setting_asset)
err = json.Unmarshal([]byte(notes_list), &notes)
if ss.CheckErr(err) {
return
}
ranks := []model.RankInfo{}
ranks = append(ranks, model.RankInfo{
Rank: 5,
RankMin: 0,
RankMax: c_rank_score,
}, model.RankInfo{
Rank: 4,
RankMin: c_rank_score + 1,
RankMax: b_rank_score,
}, model.RankInfo{
Rank: 3,
RankMin: b_rank_score + 1,
RankMax: a_rank_score,
}, model.RankInfo{
Rank: 2,
RankMin: a_rank_score + 1,
RankMax: s_rank_score,
}, model.RankInfo{
Rank: 1,
RankMin: s_rank_score + 1,
RankMax: 0,
})
playResp := model.PlayScoreResp{
ResponseData: model.PlayScoreRes{
On: model.On{
HasRecord: false,
LiveInfo: model.LiveInfo{
LiveDifficultyID: difficultyId,
IsRandom: false,
AcFlag: ac_flag,
SwingFlag: swing_flag,
NotesList: notes,
},
},
Off: model.Off{
HasRecord: false,
LiveInfo: model.LiveInfo{
LiveDifficultyID: difficultyId,
IsRandom: false,
AcFlag: ac_flag,
SwingFlag: swing_flag,
NotesList: notes,
},
},
RankInfo: ranks,
CanActivateEffect: true,
ServerTimestamp: time.Now().Unix(),
},
ReleaseInfo: []any{},
StatusCode: 200,
}
ss.Respond(playResp)
}
func PlayReward(ctx *gin.Context) {
ss := session.New(ctx)
defer ss.Finalize()
playRewardReq := model.PlayRewardReq{}
err := json.Unmarshal([]byte(ctx.GetString("request_data")), &playRewardReq)
if ss.CheckErr(err) {
return
}
difficultyId := playRewardReq.LiveDifficultyID
// Song type: normal / special
// sqlite3 doesn't support FULL OUTER JOIN so use UNION ALL here.
sql := `SELECT c_rank_score,b_rank_score,a_rank_score,s_rank_score,c_rank_combo,b_rank_combo,a_rank_combo,s_rank_combo,ac_flag,swing_flag FROM live_setting_m WHERE live_setting_id IN (SELECT live_setting_id FROM normal_live_m WHERE live_difficulty_id = ? UNION ALL SELECT live_setting_id FROM special_live_m WHERE live_difficulty_id = ?)`
var c_rank_score, b_rank_score, a_rank_score, s_rank_score, c_rank_combo, b_rank_combo, a_rank_combo, s_rank_combo, ac_flag, swing_flag int
err = ss.MainEng.DB().QueryRow(sql, difficultyId, difficultyId).Scan(&c_rank_score, &b_rank_score, &a_rank_score, &s_rank_score, &c_rank_combo, &b_rank_combo, &a_rank_combo, &s_rank_combo, &ac_flag, &swing_flag)
if ss.CheckErr(err) {
return
}
key := "live_deck_" + ctx.GetString("userid")
deckId, err := db.DB.Get([]byte(key))
if ss.CheckErr(err) {
return
}
unitsList := []model.PlayRewardUnitList{}
err = ss.UserEng.Table("deck_unit_m").Join("LEFT", "user_deck_m", "deck_unit_m.user_deck_id = user_deck_m.id").
Where("user_id = ? AND deck_id = ?", ctx.GetString("userid"), string(deckId)).Find(&unitsList)
if ss.CheckErr(err) {
return
}
totalScore := playRewardReq.ScoreSmile + playRewardReq.ScoreCool + playRewardReq.ScoreCute
playResp := model.RewardResp{
ResponseData: model.RewardRes{
LiveInfo: []model.RewardLiveInfo{
{
LiveDifficultyID: difficultyId,
IsRandom: false,
AcFlag: ac_flag,
SwingFlag: swing_flag,
},
},
TotalLove: 0,
IsHighScore: true,
HiScore: totalScore,
BaseRewardInfo: model.BaseRewardInfo{
PlayerExp: 0,
PlayerExpUnitMax: model.PlayerExpUnitMax{
Before: 0,
After: 0,
},
PlayerExpFriendMax: model.PlayerExpFriendMax{
Before: 99,
After: 99,
},
PlayerExpLpMax: model.PlayerExpLpMax{
Before: config.Conf.UserPrefs.EnergyMax,
After: config.Conf.UserPrefs.EnergyMax,
},
GameCoin: 0,
GameCoinRewardBoxFlag: false,
SocialPoint: 0,
},
RewardUnitList: model.RewardUnitList{
LiveClear: []model.LiveClear{},
LiveRank: []model.LiveRank{},
LiveCombo: []any{},
},
UnlockedSubscenarioIds: []any{},
UnlockedMultiUnitScenarioIds: []any{},
EffortPoint: []model.EffortPoint{},
IsEffortPointVisible: false,
LimitedEffortBox: []any{},
UnitList: unitsList,
BeforeUserInfo: model.BeforeUserInfo{
Level: config.Conf.UserPrefs.Level,
Exp: config.Conf.UserPrefs.ExpNumerator,
PreviousExp: 0,
NextExp: config.Conf.UserPrefs.ExpDenominator,
GameCoin: config.Conf.UserPrefs.GameCoin,
SnsCoin: config.Conf.UserPrefs.SnsCoin,
FreeSnsCoin: config.Conf.UserPrefs.SnsCoin,
PaidSnsCoin: 0,
SocialPoint: 1438165,
UnitMax: 5000,
WaitingUnitMax: 1000,
CurrentEnergy: config.Conf.UserPrefs.EnergyMax,
EnergyMax: config.Conf.UserPrefs.EnergyMax,
TrainingEnergy: 9,
TrainingEnergyMax: 10,
EnergyFullTime: "2023-03-20 01:28:55",
LicenseLiveEnergyRecoverlyTime: 60,
FriendMax: 99,
TutorialState: -1,
OverMaxEnergy: config.Conf.UserPrefs.OverMaxEnergy,
UnlockRandomLiveMuse: 1,
UnlockRandomLiveAqours: 1,
},
AfterUserInfo: model.AfterUserInfo{
Level: config.Conf.UserPrefs.Level,
Exp: config.Conf.UserPrefs.ExpNumerator,
PreviousExp: 0,
NextExp: config.Conf.UserPrefs.ExpDenominator,
GameCoin: config.Conf.UserPrefs.GameCoin,
SnsCoin: config.Conf.UserPrefs.SnsCoin,
FreeSnsCoin: config.Conf.UserPrefs.SnsCoin,
PaidSnsCoin: 0,
SocialPoint: 1438375,
UnitMax: 5000,
WaitingUnitMax: 1000,
CurrentEnergy: config.Conf.UserPrefs.EnergyMax,
EnergyMax: config.Conf.UserPrefs.EnergyMax,
TrainingEnergy: 9,
TrainingEnergyMax: 10,
EnergyFullTime: "2023-03-20 01:28:55",
LicenseLiveEnergyRecoverlyTime: 60,
FriendMax: 99,
TutorialState: -1,
OverMaxEnergy: config.Conf.UserPrefs.OverMaxEnergy,
UnlockRandomLiveMuse: 1,
UnlockRandomLiveAqours: 1,
},
NextLevelInfo: []model.NextLevelInfo{
{
Level: config.Conf.UserPrefs.Level,
FromExp: config.Conf.UserPrefs.ExpNumerator,
},
},
GoalAccompInfo: model.GoalAccompInfo{
AchievedIds: []any{},
Rewards: []any{},
},
SpecialRewardInfo: []any{},
EventInfo: []any{},
DailyRewardInfo: []any{},
CanSendFriendRequest: false,
UsingBuffInfo: []any{},
ClassSystem: model.ClassSystem{
RankInfo: model.RewardRankInfo{
BeforeClassRankID: 10,
AfterClassRankID: 10,
RankUpDate: "2020-02-12 11:57:15",
},
CompleteFlag: false,
IsOpened: true,
IsVisible: true,
},
AccomplishedAchievementList: []model.AccomplishedAchievementList{},
UnaccomplishedAchievementCnt: 0,
AddedAchievementList: []any{},
MuseumInfo: model.Museum{},
UnitSupportList: []model.RewardUnitSupportList{},
ServerTimestamp: time.Now().Unix(),
PresentCnt: 0,
},
ReleaseInfo: []any{},
StatusCode: 200,
}
if playRewardReq.MaxCombo > s_rank_combo {
playResp.ResponseData.ComboRank = 1
} else if playRewardReq.MaxCombo > a_rank_combo {
playResp.ResponseData.ComboRank = 2
} else if playRewardReq.MaxCombo > b_rank_combo {
playResp.ResponseData.ComboRank = 3
} else if playRewardReq.MaxCombo > c_rank_combo {
playResp.ResponseData.ComboRank = 4
} else {
playResp.ResponseData.ComboRank = 5
}
if totalScore > s_rank_score {
playResp.ResponseData.Rank = 1
} else if totalScore > a_rank_score {
playResp.ResponseData.Rank = 2
} else if totalScore > b_rank_score {
playResp.ResponseData.Rank = 3
} else if totalScore > c_rank_score {
playResp.ResponseData.Rank = 4
} else {
playResp.ResponseData.Rank = 5
}
ss.Respond(playResp)
func init() {
router.AddHandler("main.php", "POST", "/live/play", middleware.Common, play)
}
+111
View File
@@ -0,0 +1,111 @@
package live
import (
"encoding/json"
"honoka-chan/internal/middleware"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/live"
"honoka-chan/internal/session"
honokautils "honoka-chan/pkg/utils"
"strconv"
"time"
"github.com/gin-gonic/gin"
)
func preciseScore(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
playScoreReq := live.PlayScoreReq{}
err := json.Unmarshal([]byte(ctx.MustGet("request_data").(string)), &playScoreReq)
if ss.CheckErr(err) {
return
}
tDifficultyId := playScoreReq.LiveDifficultyID
difficultyId, err := strconv.Atoi(tDifficultyId)
if ss.CheckErr(err) {
return
}
// Song type: normal / special
// sqlite3 doesn't support FULL OUTER JOIN so use UNION ALL here.
sql := `SELECT notes_setting_asset,c_rank_score,b_rank_score,a_rank_score,s_rank_score,ac_flag,swing_flag FROM live_setting_m WHERE live_setting_id IN (SELECT live_setting_id FROM normal_live_m WHERE live_difficulty_id = ? UNION ALL SELECT live_setting_id FROM special_live_m WHERE live_difficulty_id = ?)`
var notes_setting_asset string
var c_rank_score, b_rank_score, a_rank_score, s_rank_score, ac_flag, swing_flag int
err = ss.MainEng.DB().QueryRow(sql, difficultyId, difficultyId).Scan(&notes_setting_asset, &c_rank_score, &b_rank_score, &a_rank_score, &s_rank_score, &ac_flag, &swing_flag)
if ss.CheckErr(err) {
return
}
// fmt.Println(notes_setting_asset)
// fmt.Println(c_rank_score, b_rank_score, a_rank_score, s_rank_score)
notes := []live.NotesList{}
// fmt.Println("./assets/serverdata/beatmaps/" + notes_setting_asset)
notes_list := honokautils.ReadAllText("./assets/serverdata/beatmaps/" + notes_setting_asset)
err = json.Unmarshal([]byte(notes_list), &notes)
if ss.CheckErr(err) {
return
}
ranks := []live.RankInfo{}
ranks = append(ranks, live.RankInfo{
Rank: 5,
RankMin: 0,
RankMax: c_rank_score,
}, live.RankInfo{
Rank: 4,
RankMin: c_rank_score + 1,
RankMax: b_rank_score,
}, live.RankInfo{
Rank: 3,
RankMin: b_rank_score + 1,
RankMax: a_rank_score,
}, live.RankInfo{
Rank: 2,
RankMin: a_rank_score + 1,
RankMax: s_rank_score,
}, live.RankInfo{
Rank: 1,
RankMin: s_rank_score + 1,
RankMax: 0,
})
playResp := live.PreciseScoreResp{
ResponseData: live.PreciseScoreData{
On: live.On{
HasRecord: false,
LiveInfo: live.LiveInfo{
LiveDifficultyID: difficultyId,
IsRandom: false,
AcFlag: ac_flag,
SwingFlag: swing_flag,
NotesList: notes,
},
},
Off: live.Off{
HasRecord: false,
LiveInfo: live.LiveInfo{
LiveDifficultyID: difficultyId,
IsRandom: false,
AcFlag: ac_flag,
SwingFlag: swing_flag,
NotesList: notes,
},
},
RankInfo: ranks,
CanActivateEffect: true,
ServerTimestamp: time.Now().Unix(),
},
ReleaseInfo: []any{},
StatusCode: 200,
}
ss.Respond(playResp)
}
func init() {
router.AddHandler("main.php", "POST", "/live/preciseScore", middleware.Common, preciseScore)
}
+213
View File
@@ -0,0 +1,213 @@
package live
import (
"encoding/json"
"honoka-chan/internal/middleware"
"honoka-chan/internal/model/user"
"honoka-chan/internal/router"
"honoka-chan/internal/schema/live"
"honoka-chan/internal/session"
"honoka-chan/pkg/db"
"strconv"
"time"
"github.com/gin-gonic/gin"
)
func reward(ctx *gin.Context) {
ss := session.Get(ctx)
defer ss.Finalize()
playRewardReq := live.RewardReq{}
err := json.Unmarshal([]byte(ctx.MustGet("request_data").(string)), &playRewardReq)
if ss.CheckErr(err) {
return
}
difficultyId := playRewardReq.LiveDifficultyID
// Song type: normal / special
// sqlite3 doesn't support FULL OUTER JOIN so use UNION ALL here.
sql := `SELECT c_rank_score,b_rank_score,a_rank_score,s_rank_score,c_rank_combo,b_rank_combo,a_rank_combo,s_rank_combo,ac_flag,swing_flag FROM live_setting_m WHERE live_setting_id IN (SELECT live_setting_id FROM normal_live_m WHERE live_difficulty_id = ? UNION ALL SELECT live_setting_id FROM special_live_m WHERE live_difficulty_id = ?)`
var c_rank_score, b_rank_score, a_rank_score, s_rank_score, c_rank_combo, b_rank_combo, a_rank_combo, s_rank_combo, ac_flag, swing_flag int
err = ss.MainEng.DB().QueryRow(sql, difficultyId, difficultyId).Scan(&c_rank_score, &b_rank_score, &a_rank_score, &s_rank_score, &c_rank_combo, &b_rank_combo, &a_rank_combo, &s_rank_combo, &ac_flag, &swing_flag)
if ss.CheckErr(err) {
return
}
key := "live_deck_" + strconv.Itoa(ss.UserID)
deckId, err := db.Ldb.Get([]byte(key))
if ss.CheckErr(err) {
return
}
unitsList := []live.PlayRewardUnitList{}
err = ss.UserEng.Table("user_deck_unit").Join("LEFT", "user_deck", "user_deck_unit.user_deck_id = user_deck.id").
Where("user_id = ? AND deck_id = ?", ss.UserID, string(deckId)).Find(&unitsList)
if ss.CheckErr(err) {
return
}
pref := user.UserPref{}
_, err = ss.UserEng.Table("user_pref").Where("user_id = ?", ss.UserID).Get(&pref)
if ss.CheckErr(err) {
return
}
totalScore := playRewardReq.ScoreSmile + playRewardReq.ScoreCool + playRewardReq.ScoreCute
playResp := live.RewardResp{
ResponseData: live.RewardData{
LiveInfo: []live.RewardLiveInfo{
{
LiveDifficultyID: difficultyId,
IsRandom: false,
AcFlag: ac_flag,
SwingFlag: swing_flag,
},
},
TotalLove: 0,
IsHighScore: true,
HiScore: totalScore,
BaseRewardInfo: live.BaseRewardInfo{
PlayerExp: 0,
PlayerExpUnitMax: live.PlayerExpUnitMax{
Before: 0,
After: 0,
},
PlayerExpFriendMax: live.PlayerExpFriendMax{
Before: 99,
After: 99,
},
PlayerExpLpMax: live.PlayerExpLpMax{
Before: 417,
After: 417,
},
GameCoin: 0,
GameCoinRewardBoxFlag: false,
SocialPoint: 0,
},
RewardUnitList: live.RewardUnitList{
LiveClear: []live.LiveClear{},
LiveRank: []live.LiveRank{},
LiveCombo: []any{},
},
UnlockedSubscenarioIds: []any{},
UnlockedMultiUnitScenarioIds: []any{},
EffortPoint: []live.EffortPoint{},
IsEffortPointVisible: false,
LimitedEffortBox: []any{},
UnitList: unitsList,
BeforeUserInfo: live.BeforeUserInfo{
Level: pref.UserLevel,
Exp: 1089696,
PreviousExp: 0,
NextExp: 1207185,
GameCoin: 999999999,
SnsCoin: 10000,
FreeSnsCoin: 50000,
PaidSnsCoin: 50000,
SocialPoint: 1438165,
UnitMax: 5000,
WaitingUnitMax: 1000,
CurrentEnergy: 417,
EnergyMax: 417,
TrainingEnergy: 9,
TrainingEnergyMax: 10,
EnergyFullTime: "2023-03-20 01:28:55",
LicenseLiveEnergyRecoverlyTime: 60,
FriendMax: 99,
TutorialState: -1,
OverMaxEnergy: 417,
UnlockRandomLiveMuse: 1,
UnlockRandomLiveAqours: 1,
},
AfterUserInfo: live.AfterUserInfo{
Level: pref.UserLevel,
Exp: 1089696,
PreviousExp: 0,
NextExp: 1207185,
GameCoin: 999999999,
SnsCoin: 100000,
FreeSnsCoin: 50000,
PaidSnsCoin: 50000,
SocialPoint: 1438375,
UnitMax: 5000,
WaitingUnitMax: 1000,
CurrentEnergy: 417,
EnergyMax: 417,
TrainingEnergy: 9,
TrainingEnergyMax: 10,
EnergyFullTime: "2023-03-20 01:28:55",
LicenseLiveEnergyRecoverlyTime: 60,
FriendMax: 99,
TutorialState: -1,
OverMaxEnergy: 417,
UnlockRandomLiveMuse: 1,
UnlockRandomLiveAqours: 1,
},
NextLevelInfo: []live.NextLevelInfo{
{
Level: pref.UserLevel,
FromExp: 1089696,
},
},
GoalAccompInfo: live.GoalAccompInfo{
AchievedIds: []any{},
Rewards: []any{},
},
SpecialRewardInfo: []any{},
EventInfo: []any{},
DailyRewardInfo: []any{},
CanSendFriendRequest: false,
UsingBuffInfo: []any{},
ClassSystem: live.ClassSystem{
RankInfo: live.RewardRankInfo{
BeforeClassRankID: 10,
AfterClassRankID: 10,
RankUpDate: "2020-02-12 11:57:15",
},
CompleteFlag: false,
IsOpened: true,
IsVisible: true,
},
AccomplishedAchievementList: []live.AccomplishedAchievementList{},
UnaccomplishedAchievementCnt: 0,
AddedAchievementList: []any{},
MuseumInfo: live.Museum{},
UnitSupportList: []live.RewardUnitSupportList{},
ServerTimestamp: time.Now().Unix(),
PresentCnt: 0,
},
ReleaseInfo: []any{},
StatusCode: 200,
}
if playRewardReq.MaxCombo > s_rank_combo {
playResp.ResponseData.ComboRank = 1
} else if playRewardReq.MaxCombo > a_rank_combo {
playResp.ResponseData.ComboRank = 2
} else if playRewardReq.MaxCombo > b_rank_combo {
playResp.ResponseData.ComboRank = 3
} else if playRewardReq.MaxCombo > c_rank_combo {
playResp.ResponseData.ComboRank = 4
} else {
playResp.ResponseData.ComboRank = 5
}
if totalScore > s_rank_score {
playResp.ResponseData.Rank = 1
} else if totalScore > a_rank_score {
playResp.ResponseData.Rank = 2
} else if totalScore > b_rank_score {
playResp.ResponseData.Rank = 3
} else if totalScore > c_rank_score {
playResp.ResponseData.Rank = 4
} else {
playResp.ResponseData.Rank = 5
}
ss.Respond(playResp)
}
func init() {
router.AddHandler("main.php", "POST", "/live/reward", middleware.Common, reward)
}

Some files were not shown because too many files have changed in this diff Show More