本文整理匯總了Golang中github.com/minero/minero/server/player.Player.BroadcastMessage方法的典型用法代碼示例。如果您正苦於以下問題:Golang Player.BroadcastMessage方法的具體用法?Golang Player.BroadcastMessage怎麽用?Golang Player.BroadcastMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/minero/minero/server/player.Player
的用法示例。
在下文中一共展示了Player.BroadcastMessage方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Handle03
// Handle03 handles incoming requests of packet 0x03: ChatMessage
func Handle03(server *Server, sender *player.Player) {
pkt := new(packet.ChatMessage)
pkt.ReadFrom(sender.Conn)
log.Printf("ChatMessage: %+v", pkt)
// Messages prefixed with / are treated like commands
if strings.HasPrefix(pkt.Message, "/") {
var parts = strings.Fields(pkt.Message[1:])
// Empty commands are noops.
if len(parts) == 0 {
return
}
var cmdName, cmdArgs = parts[0], parts[1:]
var cmd cmd.Cmder
var ok bool
// Command not found
if cmd, ok = server.Cmds[cmdName]; !ok {
msg := fmt.Sprintf("Unknown command %q.", cmdName)
log.Println(msg)
sender.SendMessage(msg)
return
}
ok = cmd.Do(sender, cmdArgs)
if !ok {
msg := "An error ocurred executing command %q."
log.Println(msg)
sender.SendMessage(msg)
return
}
}
// Send message to all other players
msg := fmt.Sprintf("<%s> %s", sender.Name, pkt.Message)
sender.BroadcastMessage(server.Players.Copy(), msg)
}