Draft: idk wtf was modified
This commit is contained in:
@@ -15,11 +15,11 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Room struct {
|
type Room struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Creater string `json:"creater"`
|
Creater string `json:"creater"`
|
||||||
Status RoomStatus `json:"status"`
|
Status RoomStatus `json:"status"`
|
||||||
Players []string `json:"players"`
|
Players []string `json:"players"`
|
||||||
Addr string `json:"-"`
|
Addr string `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self Room) View() string {
|
func (self Room) View() string {
|
||||||
|
|||||||
14
utils/udp.go
14
utils/udp.go
@@ -64,13 +64,21 @@ func ListenUDP(
|
|||||||
func SendPayload(endpoint, data string) error {
|
func SendPayload(endpoint, data string) error {
|
||||||
conn, err := net.Dial("udp", endpoint)
|
conn, err := net.Dial("udp", endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to dial endpoint")
|
return fmt.Errorf("failed to dial endpoint, %w", err)
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
_, err = conn.Write([]byte(data))
|
b, err := msgpack.Marshal(UDPPayload{
|
||||||
|
MagicNumber: MAGIC_NUMBER,
|
||||||
|
Data: data,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to send payload")
|
return fmt.Errorf("failed to marshal payload, %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = conn.Write(b)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to send payload, %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user