-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler_score_submit.go
84 lines (68 loc) · 1.61 KB
/
handler_score_submit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package score
import (
"crypto/cipher"
"encoding/base64"
"fmt"
"strings"
"github.com/gorilla/schema"
"github.com/labstack/echo"
"github.com/nsogame/common"
)
var (
MaxMemory int64 = 1234567
Decoder = schema.NewDecoder()
)
type ScoreSubmission struct {
ScoreEnc string `schema:"score"`
IV string `schema:"iv"`
Password string `schema:"pass"`
OsuVer string `schema:"osuver"`
Bmk string `schema:"bmk"`
C1 string `schema:"c1"`
Fs string `schema:"fs"`
Ft string `schema:"ft"`
I string `schema:"i"`
S string `schema:"s"`
X string `schema:"x"`
}
func (score *ScoreServer) SubmitModularHandler(c echo.Context) (err error) {
// files := c.MultipartForm()
form, err := c.FormParams()
if err != nil {
return
}
var data ScoreSubmission
err = Decoder.Decode(&data, form)
if err != nil {
return
}
fmt.Println("data", data)
// decrypt the score with AES-CBC
var key []byte
key = []byte(fmt.Sprintf("osu!-scoreburgr---------%s", data.OsuVer))
iv, err := base64.StdEncoding.DecodeString(data.IV)
if err != nil {
return
}
scoreEnc, err := base64.StdEncoding.DecodeString(data.ScoreEnc)
if err != nil {
return
}
block, err := common.NewCipher(key)
if err != nil {
return
}
mode := cipher.NewCBCDecrypter(block, iv)
scoreBytes := make([]byte, len(scoreEnc))
mode.CryptBlocks(scoreBytes, scoreEnc)
scoreData := strings.Split(string(scoreBytes), ":")
// fileChecksum := scoreData[0]
username := strings.Trim(scoreData[1], " ")
// pull user out of the db
user, err := score.db.GetUserByName(username)
if err != nil {
return
}
fmt.Println("user", user)
return
}