server/social_actions.go (1181B)
1 package main 2 3 import ( 4 "encoding/binary" 5 "fmt" 6 ) 7 8 func (server *server) handleSocialAction(client *worldClient, body []byte) error { 9 if len(body) != 28 { 10 return fmt.Errorf("invalid social action length") 11 } 12 // Unverified SocialActionCmd requests carry an arbitrary command reference. 13 action := binary.BigEndian.Uint32(body[24:28]) 14 if !client.target || binary.BigEndian.Uint32(body[4:8]) != 50000 || binary.BigEndian.Uint32(body[8:12]) != client.id || 15 binary.BigEndian.Uint32(body[12:16]) != 1 || binary.BigEndian.Uint32(body[16:20]) != 0 || action < 1 || action > 63 { 16 return nil 17 } 18 player := server.characters[client.id] 19 if server.clients[client.id] != client { 20 return nil 21 } 22 verification := uint32(1) 23 if !client.ready || client.loading || player.health == 0 || player.movement.components[0] == 4 { 24 verification = 2 25 } 26 playfield := player.playfield 27 28 // Verification completes the owner's pending command without replaying it. 29 response := n3Packet(0x3b290771, 50000, client.id, body[16:]) 30 binary.BigEndian.PutUint32(response[36:40], verification) 31 if verification == 1 { 32 server.broadcast(playfield, client.id, response) 33 } 34 return client.send(response) 35 }