-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
73 lines (63 loc) · 1.64 KB
/
helpers.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
package handler
import (
"fmt"
"github.com/bnch/lan/packets"
)
// SendUsers sends to this session all the online users.
func (s Session) SendUsers() {
defer func() {
if err := recover(); err != nil {
fmt.Println("critical:", err)
}
}()
// Simpler demonstration: https://play.golang.org/p/QKp3emL58a
const chunkSize = 512
c := Sessions.AllUserIDs()
for i := 0; i < (len(c)/chunkSize + 1); i++ {
start := chunkSize * i
end := start + chunkSize
if end > len(c) {
end = len(c)
}
if len(c[start:end]) > 0 {
s.Send(&packets.BanchoUserPresenceBundle{IDs: c[start:end]})
}
}
}
// ToUserPresence converts a session to a packets.BanchoUserPresence
func (s Session) ToUserPresence() *packets.BanchoUserPresence {
return &packets.BanchoUserPresence{
ID: s.UserID,
Name: s.Username,
UTCOffset: 24,
Country: 0,
Privileges: uint8(s.Permissions()),
Rank: s.UserID,
}
}
// ToHandleUserUpdate converts a session to a packets.BanchoHandleUserUpdate
func (s Session) ToHandleUserUpdate() *packets.BanchoHandleUserUpdate {
return &packets.BanchoHandleUserUpdate{
ID: s.UserID,
Action: s.State.Action,
ActionText: s.State.Text,
ActionMapMD5: s.State.MapMD5,
ActionMods: s.State.Mods,
ActionGameMode: s.State.GameMode,
ActionBeatmapID: s.State.BeatmapID,
RankedScore: 0,
TotalScore: 0,
Rank: s.UserID,
}
}
// Start runs all initialisations required for this package.
func Start() {
AddChannel(Channel{
"#osu",
"General discussion about everything",
})
AddChannel(Channel{
"#announce",
"Probably not so important announcements.",
})
}