diff options
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))) + } +} |
