當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Player.SendMessage方法代碼示例

本文整理匯總了Golang中github.com/minero/minero/server/player.Player.SendMessage方法的典型用法代碼示例。如果您正苦於以下問題:Golang Player.SendMessage方法的具體用法?Golang Player.SendMessage怎麽用?Golang Player.SendMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/minero/minero/server/player.Player的用法示例。


在下文中一共展示了Player.SendMessage方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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)
}
開發者ID:KellyLSB,項目名稱:minero-go,代碼行數:40,代碼來源:handle_03.go

示例2: Kick

// Kick kicks a player from the server
func (s *Server) Kick(p *player.Player) {
	p.SendMessage("You were kicked from the server.")
	msg := fmt.Sprintf("Player %q was kicked from the server.", p.Name)
	s.BroadcastMessage(msg)
}
開發者ID:KellyLSB,項目名稱:minero-go,代碼行數:6,代碼來源:server.go


注:本文中的github.com/minero/minero/server/player.Player.SendMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。