Skip to content

Commit 838076d

Browse files
committed
Handle ClientStartSpectatingPlayer packet
1 parent e4f3332 commit 838076d

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package handlers
2+
3+
import (
4+
"example.com/Quaver/Z/packets"
5+
"example.com/Quaver/Z/sessions"
6+
"example.com/Quaver/Z/spectator"
7+
)
8+
9+
// Handles when the client requests to start spectating a player.
10+
func handleClientStartSpectatingPlayer(user *sessions.User, packet *packets.ClientStartSpectatingPlayer) {
11+
if packet == nil {
12+
return
13+
}
14+
15+
spectatee := sessions.GetUserById(packet.UserId)
16+
17+
if spectatee == nil {
18+
return
19+
}
20+
21+
spectUser := spectator.GetUser(user)
22+
spectUser.StopSpectatingAll()
23+
24+
spectator.GetUser(spectatee).AddSpectator(spectUser)
25+
}

handlers/packets.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ func HandleIncomingPackets(conn net.Conn, msg string) {
104104
handleClientUnlinkTwitch(user, unmarshalPacket[packets.ClientUnlinkTwitch](msg))
105105
case packets.PacketIdClientGameDifficultyRatings:
106106
handleClientGameDifficultyRatings(user, unmarshalPacket[packets.ClientGameDifficultyRatings](msg))
107+
case packets.PacketIdClientStartSpectatePlayer:
108+
handleClientStartSpectatingPlayer(user, unmarshalPacket[packets.ClientStartSpectatingPlayer](msg))
107109
default:
108110
log.Println(fmt.Errorf("unknown packet: %v", msg))
109111
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package packets
2+
3+
type ClientStartSpectatingPlayer struct {
4+
Packet
5+
UserId int `json:"u"`
6+
}

0 commit comments

Comments
 (0)