Draft: idk wtf was modified

This commit is contained in:
2025-10-16 05:04:26 +08:00
parent 85fa3dfe73
commit d55f333027
6 changed files with 19 additions and 11 deletions

View File

@@ -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 {

View File

@@ -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