Skip to content

Commit

Permalink
updated osu-parser and slight refactors in bss as a result of those
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeveelution committed Jan 21, 2024
1 parent a6dde55 commit cc84a27
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 60 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21.5
require github.com/go-sql-driver/mysql v1.6.0

require (
github.com/Waffle-osu/osu-parser v0.0.0-20240114162210-c75428189f46
github.com/Waffle-osu/osu-parser v0.0.0-20240121103527-7fc25d444484
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/Waffle-osu/osu-parser v0.0.0-20240114162210-c75428189f46 h1:7pCW28FTKvyiS+gtgeJ/KnW4OpxQqSgBGW4hNxekxVY=
github.com/Waffle-osu/osu-parser v0.0.0-20240114162210-c75428189f46/go.mod h1:S2DZzqsx56KQaRWSN/26agcry2t9VmXeYDV3I3JwLqU=
github.com/Waffle-osu/osu-parser v0.0.0-20240121103527-7fc25d444484 h1:mFmHTJ1BoVK89+K0xurtmHbladDXY3CbbdbBU/yml1A=
github.com/Waffle-osu/osu-parser v0.0.0-20240121103527-7fc25d444484/go.mod h1:S2DZzqsx56KQaRWSN/26agcry2t9VmXeYDV3I3JwLqU=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
Expand Down
37 changes: 37 additions & 0 deletions web/bss/common_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bss

import (
"Waffle/database"
"Waffle/utils"
"database/sql"
"math"

Expand Down Expand Up @@ -133,3 +134,39 @@ func GetNextBssBeatmapId() int64 {

return result
}

func InsertIntoBeatmaps(file osu_parser.OsuFile, setId int64, userId int32, filename string) error {
newBeatmapId := GetNextBssBeatmapId()

minVersion := utils.VersionOsuFile(file)

insertBeatmapSql := "INSERT INTO beatmaps (beatmap_id, beatmapset_id, creator_id, filename, beatmap_md5, version, total_length, drain_time, count_objects, count_normal, count_slider, count_spinner, diff_hp, diff_cs, diff_od, diff_stars, playmode, ranking_status, last_update, submit_date, approve_date, beatmap_source, status_valid_from_version, status_valid_to_version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), '1000-01-01 00:00:00.000000', ?, ?, ?)"

_, insertBeatmapErr :=
database.Database.Query(
insertBeatmapSql,
newBeatmapId,
setId,
-userId,
filename,
file.Md5Hash,
file.Metadata.Version,
file.Length,
file.DrainLength,
len(file.HitObjects.List),
file.HitObjects.CountNormal,
file.HitObjects.CountSlider,
file.HitObjects.CountSpinner,
file.Difficulty.HPDrainRate,
file.Difficulty.CircleSize,
file.Difficulty.OverallDifficulty,
-1,
byte(file.General.Mode),
0,
1,
minVersion,
99999999,
)

return insertBeatmapErr
}
81 changes: 22 additions & 59 deletions web/bss/osu_bmsubmit_getid5.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"Waffle/database"
"Waffle/helpers"
"Waffle/utils"
"crypto/md5"
"crypto/sha256"
"database/sql"
"encoding/hex"
Expand All @@ -16,52 +15,6 @@ import (
"github.com/gin-gonic/gin"
)

func getMapInfo(currentOsu osu_parser.OsuFile, fileData []byte) (beatmapMd5 string, countObjects int32, countNormal int32, countSlider int32, countSpinner int32, totalLength int32, drainTime int32, minVersion int64) {
fileHashedBytes := md5.Sum(fileData)
beatmapMd5 = hex.EncodeToString(fileHashedBytes[:])

hitObjectCount := len(currentOsu.HitObjects.HitObjects)
totalLength = int32((currentOsu.HitObjects.HitObjects[hitObjectCount-1].Time - currentOsu.HitObjects.HitObjects[0].Time) / 1000)

breakTime := int32(0)

for _, event := range currentOsu.Events.Events {
if event.EventType == osu_parser.EventTypeBreak {
breakTime += event.BreakTimeEnd - event.BreakTimeBegin
}
}

breakTime /= 1000

countNormal = int32(0)
countSlider = int32(0)
countSpinner = int32(0)

for _, object := range currentOsu.HitObjects.HitObjects {
if (int32(object.Type) & int32(osu_parser.HitObjectTypeCircle)) > 0 {
countNormal++
}

if (int32(object.Type) & int32(osu_parser.HitObjectTypeSlider)) > 0 {
countSlider++
}

if (int32(object.Type) & int32(osu_parser.HitObjectTypeSpinner)) > 0 {
countSpinner++
}

if (int32(object.Type) & int32(osu_parser.HitObjectTypeHold)) > 0 {
countSlider++
}
}

drainTime = totalLength - breakTime

minVersion = utils.VersionOsuFile(currentOsu)

return beatmapMd5, countObjects, countNormal, countSlider, countSpinner, totalLength, drainTime, minVersion
}

func isASCII(s string) bool {
for _, c := range s {
if c > unicode.MaxASCII {
Expand Down Expand Up @@ -353,9 +306,26 @@ func HandleGetId5(ctx *gin.Context) {
version = ?
`

beatmapMd5, countObjects, countNormal, countSlider, countSpinner, totalLength, drainTime, minVersion := getMapInfo(ticket.ParsedOsu, ticket.FileData)

_, updateDiffErr := database.Database.Exec(updateDiffSql, beatmapMd5, totalLength, drainTime, countObjects, countNormal, countSlider, countSpinner, diff.HPDrainRate, diff.CircleSize, diff.OverallDifficulty, ticket.ParsedOsu.General.Mode, minVersion, uploadRequest.BeatmapsetId, ticket.ParsedOsu.Metadata.Version)
minVersion := utils.VersionOsuFile(ticket.ParsedOsu)

_, updateDiffErr :=
database.Database.Exec(
updateDiffSql,
ticket.ParsedOsu.Md5Hash,
ticket.ParsedOsu.Length,
ticket.ParsedOsu.DrainLength,
len(ticket.ParsedOsu.HitObjects.List),
ticket.ParsedOsu.HitObjects.CountNormal,
ticket.ParsedOsu.HitObjects.CountSlider,
ticket.ParsedOsu.HitObjects.CountSpinner,
diff.HPDrainRate,
diff.CircleSize,
diff.OverallDifficulty,
ticket.ParsedOsu.General.Mode,
minVersion,
uploadRequest.BeatmapsetId,
ticket.ParsedOsu.Metadata.Version,
)

if updateDiffErr != nil {
ctx.String(500, "Internal Queries Failed")
Expand All @@ -377,12 +347,8 @@ func HandleGetId5(ctx *gin.Context) {

for _, ticket := range toInsert {
currentOsu := ticket.ParsedOsu
newBeatmapId := GetNextBssBeatmapId()

beatmapMd5, countObjects, countNormal, countSlider, countSpinner, totalLength, drainTime, minVersion := getMapInfo(currentOsu, ticket.FileData)

insertBeatmapSql := "INSERT INTO beatmaps (beatmap_id, beatmapset_id, creator_id, filename, beatmap_md5, version, total_length, drain_time, count_objects, count_normal, count_slider, count_spinner, diff_hp, diff_cs, diff_od, diff_stars, playmode, ranking_status, last_update, submit_date, approve_date, beatmap_source, status_valid_from_version, status_valid_to_version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), '1000-01-01 00:00:00.000000', ?, ?, ?)"
_, insertBeatmapErr := database.Database.Query(insertBeatmapSql, newBeatmapId, uploadRequest.BeatmapsetId, -userId, ticket.Filename, beatmapMd5, currentOsu.Metadata.Version, totalLength, drainTime, countObjects, countNormal, countSlider, countSpinner, currentOsu.Difficulty.HPDrainRate, currentOsu.Difficulty.CircleSize, currentOsu.Difficulty.OverallDifficulty, -1, byte(currentOsu.General.Mode), 0, 1, minVersion, 99999999)
insertBeatmapErr := InsertIntoBeatmaps(currentOsu, uploadRequest.BeatmapsetId, -userId, ticket.Filename)

if insertBeatmapErr != nil {
ctx.String(500, "Internal queries failed")
Expand Down Expand Up @@ -415,10 +381,7 @@ func HandleGetId5(ctx *gin.Context) {

currentOsu := ticket.ParsedOsu

beatmapMd5, countObjects, countNormal, countSlider, countSpinner, totalLength, drainTime, minVersion := getMapInfo(currentOsu, ticket.FileData)

insertBeatmapSql := "INSERT INTO beatmaps (beatmap_id, beatmapset_id, creator_id, filename, beatmap_md5, version, total_length, drain_time, count_objects, count_normal, count_slider, count_spinner, diff_hp, diff_cs, diff_od, diff_stars, playmode, ranking_status, last_update, submit_date, approve_date, beatmap_source, status_valid_from_version, status_valid_to_version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), '1000-01-01 00:00:00.000000', ?, ?, ?)"
_, insertBeatmapErr := database.Database.Query(insertBeatmapSql, newBeatmapId, uploadRequest.BeatmapsetId, -userId, ticket.Filename, beatmapMd5, currentOsu.Metadata.Version, totalLength, drainTime, countObjects, countNormal, countSlider, countSpinner, currentOsu.Difficulty.HPDrainRate, currentOsu.Difficulty.CircleSize, currentOsu.Difficulty.OverallDifficulty, -1, byte(currentOsu.General.Mode), 0, 1, minVersion, 99999999)
insertBeatmapErr := InsertIntoBeatmaps(currentOsu, uploadRequest.BeatmapsetId, -userId, ticket.Filename)

if insertBeatmapErr != nil {
ctx.String(500, "Internal queries failed")
Expand Down

0 comments on commit cc84a27

Please sign in to comment.