server/information.go (2346B)
1 package main 2 3 import ( 4 "ao/server/gamedata" 5 "encoding/binary" 6 "slices" 7 "time" 8 ) 9 10 func informationText(definition *gamedata.Item) string { 11 if definition == nil || definition.RecordType != 1000020 || definition.Undecoded != nil || definition.HeaderWords[0] != 51005 || 12 definition.Quality == nil || *definition.Quality != 1 || itemStat(definition, 0) != 0x80023203 || itemStat(definition, 30) != 8 || 13 len(definition.Sections) != 1 { 14 return "" 15 } 16 section := definition.Sections[0] 17 if section.Type != 2 || section.Subtype != 0 || section.Functions == nil || len(*section.Functions) != 1 || 18 section.Entries != nil || section.Stats != nil || section.Actions != nil { 19 return "" 20 } 21 function := (*section.Functions)[0] 22 if function.ID != 53044 || function.HeaderWords != [2]uint32{0, 4} || function.ArgumentHeader != 9 || function.Target != 2 || 23 len(function.Requirements) != 0 || function.TickCount != 1 || function.TickInterval != 0 || len(function.Arguments) != 2 { 24 return "" 25 } 26 if function.Arguments[0].String == nil || *function.Arguments[0].String == "" || 27 function.Arguments[1].BytesHex == nil || *function.Arguments[1].BytesHex != "0000000000000000000000000000000000000000" { 28 return "" 29 } 30 return *function.Arguments[0].String 31 } 32 33 func (server *server) useInformation(client *worldClient, body []byte) error { 34 player := server.characters[client.id] 35 placement := gamedata.InformationItems[binary.BigEndian.Uint32(body[44:48])] 36 text := informationText(gamedata.ItemTemplates[placement.Template]) 37 position := predictedPosition(player, time.Now()) 38 x, y, z := position[0]-placement.Position[0], position[1]-placement.Position[1], position[2]-placement.Position[2] 39 accepted := client.target && player.playfield == placement.Playfield && x*x+y*y+z*z <= 25 && text != "" 40 41 // A successful Use displays the authored hint only to its requesting player. 42 reply := slices.Clone(body[16:]) 43 binary.BigEndian.PutUint32(reply, 2) 44 if accepted { 45 binary.BigEndian.PutUint32(reply, 1) 46 } 47 if err := client.send(n3Packet(0x52526858, 50000, client.id, reply)); err != nil { 48 return err 49 } 50 if !accepted { 51 return nil 52 } 53 feedback := binary.BigEndian.AppendUint32(nil, uint32(len(text))) 54 feedback = append(feedback, text...) 55 feedback = append(feedback, 0, 0) 56 return client.send(n3Packet(0x5f4b442a, 50000, client.id, feedback)) 57 }