Skip to content

Commit 2aca06f

Browse files
committed
Implement notification packet
1 parent 229b46c commit 2aca06f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

packets/ServerNotification.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package packets
2+
3+
type ServerNotification struct {
4+
Packet
5+
Type ServerNotificationType `json:"t"`
6+
Content string `json:"c"`
7+
}
8+
9+
type ServerNotificationType int
10+
11+
const (
12+
ServerNotificationTypeError = iota
13+
ServerNotificationTypeSuccess
14+
ServerNotificationTypeInfo
15+
)
16+
17+
func NewServerNotification(notificationType ServerNotificationType, content string) *ServerNotification {
18+
return &ServerNotification{
19+
Packet: Packet{Id: PacketIdServerNotification},
20+
Type: notificationType,
21+
Content: content,
22+
}
23+
}
24+
25+
func NewServerNotificationError(content string) *ServerNotification {
26+
return NewServerNotification(ServerNotificationTypeError, content)
27+
}
28+
29+
func NewServerNotificationSuccess(content string) *ServerNotification {
30+
return NewServerNotification(ServerNotificationTypeSuccess, content)
31+
}
32+
33+
func NewServerNotificationInfo(content string) *ServerNotification {
34+
return NewServerNotification(ServerNotificationTypeInfo, content)
35+
}

0 commit comments

Comments
 (0)