diff options
| author | historia <[not public]> | 2026-06-25 04:46:40 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-25 04:46:40 -0400 |
| commit | 2725e2927a1595c7b100d942d1f14146252adeb7 (patch) | |
| tree | e8bc2292634a2d686c751981ddb3097517cccc6a /internal/game/cmd_global.go | |
| parent | 94a06fbbe682701ca4d4bd2a70cd74d8df29c932 (diff) | |
| download | thehouseoficarus-2725e2927a1595c7b100d942d1f14146252adeb7.tar.gz | |
feat: who, global chat, removed redundant YAML IDs
Diffstat (limited to 'internal/game/cmd_global.go')
| -rw-r--r-- | internal/game/cmd_global.go | 36 |
1 files changed, 36 insertions, 0 deletions
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 <message> — 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))) + } +} |
