1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
package game
import (
"fmt"
"strings"
"thehouseoficarus/internal/net"
)
func (g *Game) executeSay(sess *net.Session, args []string, rawInput string) {
if len(args) == 0 {
sess.WriteLine("Say what?")
} else {
msgStart := strings.Index(strings.ToLower(rawInput), "say ") + 4
if msgStart >= 4 && msgStart < len(rawInput) {
g.doSay(sess, rawInput[msgStart:])
} else {
g.doSay(sess, strings.Join(args, " "))
}
}
}
func (g *Game) doSay(sess *net.Session, msg string) {
p := sess.Player
roomID := p.RoomID
for _, other := range g.Hub.PlayersInRoom(roomID) {
if other == sess {
other.WriteLine(fmt.Sprintf("You say: %s", g.colorize(sess, "say", msg)))
} else {
other.WriteLine(fmt.Sprintf("%s says: %s", g.colorize(other, "player_name", p.Name), g.colorize(other, "say", msg)))
}
}
}
|