|
@@ -4,7 +4,8 @@
|
4
|
4
|
package irc
|
5
|
5
|
|
6
|
6
|
import (
|
7
|
|
- "bytes"
|
|
7
|
+ "fmt"
|
|
8
|
+ "strings"
|
8
|
9
|
|
9
|
10
|
"github.com/oragono/oragono/irc/history"
|
10
|
11
|
"github.com/oragono/oragono/irc/modes"
|
|
@@ -16,7 +17,7 @@ const (
|
16
|
17
|
sceneNickMask = "=Scene=!%s@npc.fakeuser.invalid"
|
17
|
18
|
)
|
18
|
19
|
|
19
|
|
-func sendRoleplayMessage(server *Server, client *Client, source string, targetString string, isAction bool, messageParts []string, rb *ResponseBuffer) {
|
|
20
|
+func sendRoleplayMessage(server *Server, client *Client, source string, targetString string, isScene, isAction bool, messageParts []string, rb *ResponseBuffer) {
|
20
|
21
|
config := server.Config()
|
21
|
22
|
if !config.Roleplay.Enabled {
|
22
|
23
|
rb.Add(nil, client.server.name, ERR_CANNOTSENDRP, targetString, client.t("Roleplaying has been disabled by the server administrators"))
|
|
@@ -27,12 +28,26 @@ func sendRoleplayMessage(server *Server, client *Client, source string, targetSt
|
27
|
28
|
return
|
28
|
29
|
}
|
29
|
30
|
|
|
31
|
+ var sourceMask string
|
|
32
|
+ if isScene {
|
|
33
|
+ sourceMask = fmt.Sprintf(sceneNickMask, client.Nick())
|
|
34
|
+ } else {
|
|
35
|
+ cfSource, cfSourceErr := CasefoldName(source)
|
|
36
|
+ skelSource, skelErr := Skeleton(source)
|
|
37
|
+ if cfSourceErr != nil || skelErr != nil ||
|
|
38
|
+ restrictedCasefoldedNicks.Has(cfSource) || restrictedSkeletons.Has(skelSource) {
|
|
39
|
+ rb.Add(nil, client.server.name, ERR_CANNOTSENDRP, targetString, client.t("Invalid roleplay name"))
|
|
40
|
+ return
|
|
41
|
+ }
|
|
42
|
+ sourceMask = fmt.Sprintf(npcNickMask, source, client.Nick())
|
|
43
|
+ }
|
|
44
|
+
|
30
|
45
|
// block attempts to send CTCP messages to Tor clients
|
31
|
46
|
if len(messageParts) > 0 && len(messageParts[0]) > 0 && messageParts[0][0] == '\x01' {
|
32
|
47
|
return
|
33
|
48
|
}
|
34
|
49
|
|
35
|
|
- var buf bytes.Buffer
|
|
50
|
+ var buf strings.Builder
|
36
|
51
|
if isAction {
|
37
|
52
|
buf.WriteString("\x01ACTION ")
|
38
|
53
|
}
|
|
@@ -80,9 +95,9 @@ func sendRoleplayMessage(server *Server, client *Client, source string, targetSt
|
80
|
95
|
// of roleplay commands, so send them a copy whether they have echo-message
|
81
|
96
|
// or not
|
82
|
97
|
if rb.session == session {
|
83
|
|
- rb.AddSplitMessageFromClient(source, "", nil, "PRIVMSG", targetString, splitMessage)
|
|
98
|
+ rb.AddSplitMessageFromClient(sourceMask, "", nil, "PRIVMSG", targetString, splitMessage)
|
84
|
99
|
} else {
|
85
|
|
- session.sendSplitMsgFromClientInternal(false, source, "*", nil, "PRIVMSG", targetString, splitMessage)
|
|
100
|
+ session.sendSplitMsgFromClientInternal(false, sourceMask, "*", nil, "PRIVMSG", targetString, splitMessage)
|
86
|
101
|
}
|
87
|
102
|
}
|
88
|
103
|
}
|
|
@@ -90,7 +105,7 @@ func sendRoleplayMessage(server *Server, client *Client, source string, targetSt
|
90
|
105
|
channel.AddHistoryItem(history.Item{
|
91
|
106
|
Type: history.Privmsg,
|
92
|
107
|
Message: splitMessage,
|
93
|
|
- Nick: source,
|
|
108
|
+ Nick: sourceMask,
|
94
|
109
|
}, client.Account())
|
95
|
110
|
} else {
|
96
|
111
|
target, err := CasefoldName(targetString)
|
|
@@ -108,7 +123,7 @@ func sendRoleplayMessage(server *Server, client *Client, source string, targetSt
|
108
|
123
|
cnick := client.Nick()
|
109
|
124
|
tnick := user.Nick()
|
110
|
125
|
for _, session := range user.Sessions() {
|
111
|
|
- session.sendSplitMsgFromClientInternal(false, source, "*", nil, "PRIVMSG", tnick, splitMessage)
|
|
126
|
+ session.sendSplitMsgFromClientInternal(false, sourceMask, "*", nil, "PRIVMSG", tnick, splitMessage)
|
112
|
127
|
}
|
113
|
128
|
if away, awayMessage := user.Away(); away {
|
114
|
129
|
//TODO(dan): possibly implement cooldown of away notifications to users
|