-
Notifications
You must be signed in to change notification settings - Fork 0
/
opLogin.go
59 lines (50 loc) · 1.32 KB
/
opLogin.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
package main
import (
"encoding/base64"
"github.com/vikebot/vbdb"
"go.uber.org/zap"
)
type loginObj struct {
RoundTicket *string `json:"roundticket"`
}
type loginPacket struct {
Type string `json:"type"`
Obj loginObj `json:"obj"`
}
func opLogin(c *ntcpclient, packet loginPacket) {
if packet.Obj.RoundTicket == nil {
c.Respond("Invalid packet. '.obj.roundticket' missing")
return
}
v, exists, success := vbdb.RoundentryFromRoundticketCtx(*packet.Obj.RoundTicket, c.Log)
if !success {
c.Respond(statusInternalServerError)
return
}
if !exists {
c.Respond("Your rounticket doesn't reference any game.")
return
}
if config.Battle.RoundID != v.RoundID {
c.Respond("Your roundticket references an already finished game.")
c.Log.Warn("valid watchtoken references invalid round",
zap.Int("config_round_id", config.Battle.RoundID),
zap.Int("watchtoken_round_id", v.RoundID))
return
}
c.UserID = v.UserID
keybuf, err := base64.StdEncoding.DecodeString(*v.AESKey)
if err != nil {
c.Log.Error("failed to decode base64 string", zap.String("aeskey", *v.AESKey))
c.Respond(statusInternalServerError)
return
}
err = c.InitAes(keybuf)
if err != nil {
c.Log.Error("failed to init AES from key buffer", zap.Error(err))
c.Respond(statusInternalServerError)
return
}
c.LoginDone = true
c.RespondNil()
}