コード例 #1
0
ファイル: handle_03.go プロジェクト: KellyLSB/minero-go
// 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)
}
コード例 #2
0
ファイル: server.go プロジェクト: KellyLSB/minero-go
// 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)
}