Draft: idk wtf was modified
This commit is contained in:
@@ -15,11 +15,11 @@ var (
|
||||
)
|
||||
|
||||
type Room struct {
|
||||
ID string `json:"id"`
|
||||
Creater string `json:"creater"`
|
||||
ID string `json:"id"`
|
||||
Creater string `json:"creater"`
|
||||
Status RoomStatus `json:"status"`
|
||||
Players []string `json:"players"`
|
||||
Addr string `json:"-"`
|
||||
Players []string `json:"players"`
|
||||
Addr string `json:"-"`
|
||||
}
|
||||
|
||||
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 {
|
||||
conn, err := net.Dial("udp", endpoint)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to dial endpoint")
|
||||
return fmt.Errorf("failed to dial endpoint, %w", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
_, err = conn.Write([]byte(data))
|
||||
b, err := msgpack.Marshal(UDPPayload{
|
||||
MagicNumber: MAGIC_NUMBER,
|
||||
Data: data,
|
||||
})
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user