Skip to content

Commit 93c8b0a

Browse files
committed
Implement twitch connection status packet
1 parent 1279470 commit 93c8b0a

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

db/users.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package db
22

33
import (
4+
"database/sql"
45
"example.com/Quaver/Z/common"
56
"example.com/Quaver/Z/config"
67
"fmt"
@@ -10,20 +11,21 @@ import (
1011
)
1112

1213
type User struct {
13-
Id int `db:"id"`
14-
SteamId string `db:"steam_id"`
15-
Username string `db:"username"`
16-
Allowed bool `db:"allowed"`
17-
Privileges common.Privileges `db:"privileges"`
18-
UserGroups common.UserGroups `db:"usergroups"`
19-
MuteEndTime int64 `db:"mute_endtime"`
20-
Country string `db:"country"`
21-
AvatarUrl string `db:"avatar_url"`
14+
Id int `db:"id"`
15+
SteamId string `db:"steam_id"`
16+
Username string `db:"username"`
17+
Allowed bool `db:"allowed"`
18+
Privileges common.Privileges `db:"privileges"`
19+
UserGroups common.UserGroups `db:"usergroups"`
20+
MuteEndTime int64 `db:"mute_endtime"`
21+
Country string `db:"country"`
22+
AvatarUrl string `db:"avatar_url"`
23+
TwitchUsername sql.NullString `db:"twitch_username"`
2224
}
2325

2426
// GetUserBySteamId Retrieves a user from the database by their Steam id
2527
func GetUserBySteamId(steamId string) (*User, error) {
26-
query := "SELECT id, steam_id, username, allowed, privileges, usergroups, mute_endtime, country, avatar_url FROM users WHERE steam_id = ? LIMIT 1"
28+
query := "SELECT id, steam_id, username, allowed, privileges, usergroups, mute_endtime, country, avatar_url, twitch_username FROM users WHERE steam_id = ? LIMIT 1"
2729

2830
var user User
2931
err := SQL.Get(&user, query, steamId)

handlers/login.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ func sendLoginPackets(user *sessions.User) error {
335335
}
336336

337337
sessions.SendPacketToUser(packets.NewServerFriendsList(friends), user)
338-
339-
// Twitch Connection
338+
sessions.SendPacketToUser(packets.NewServerTwitchConnection(user.Info.TwitchUsername.String), user)
339+
340340
// Join Chat Channels
341341
// Broadcast Online Status
342342
// Alert that they're muted

packets/ServerTwitchConnection.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package packets
2+
3+
type ServerTwitchConnection struct {
4+
Packet
5+
Connected bool `json:"c"`
6+
Username *string `json:"u,omitempty"`
7+
}
8+
9+
func NewServerTwitchConnection(username string) *ServerTwitchConnection {
10+
return &ServerTwitchConnection{
11+
Packet: Packet{Id: PacketIdServerTwitchConnection},
12+
Connected: username != "",
13+
Username: &username,
14+
}
15+
}

0 commit comments

Comments
 (0)