From 2725e2927a1595c7b100d942d1f14146252adeb7 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Thu, 25 Jun 2026 04:46:40 -0400 Subject: feat: who, global chat, removed redundant YAML IDs --- internal/game/cmd_global.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 internal/game/cmd_global.go (limited to 'internal/game/cmd_global.go') diff --git a/internal/game/cmd_global.go b/internal/game/cmd_global.go new file mode 100644 index 0000000..d06a233 --- /dev/null +++ b/internal/game/cmd_global.go @@ -0,0 +1,36 @@ +package game + +import ( + "fmt" + "strings" + + "thehouseoficarus/internal/net" +) + +func (g *Game) executeGlobal(sess *net.Session, args []string, rawInput string) { + if len(args) == 0 { + sess.WriteLine("Usage: global — sends a message to everyone on the world.") + return + } + + msgStart := strings.Index(strings.ToLower(rawInput), "global ") + 7 + if msgStart >= 7 && msgStart < len(rawInput) { + g.doGlobal(sess, rawInput[msgStart:]) + } else { + g.doGlobal(sess, strings.Join(args, " ")) + } +} + +func (g *Game) doGlobal(sess *net.Session, msg string) { + p := sess.Player + + for _, other := range g.Hub.AllSessions() { + if other.Player == nil { + continue + } + other.WriteLine(fmt.Sprintf("\n%s%s: %s", + g.colorize(other, "global", "[Global] "), + g.colorize(other, "player_name", p.Name), + g.colorize(other, "global", msg))) + } +} -- cgit v1.2.3