2017-03-27 14:15:02 +02:00
|
|
|
// Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
|
2016-11-01 14:56:21 +01:00
|
|
|
// released under the MIT license
|
|
|
|
|
|
|
|
package irc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2017-09-29 04:07:52 +02:00
|
|
|
"github.com/oragono/oragono/irc/caps"
|
2018-02-03 11:21:32 +01:00
|
|
|
"github.com/oragono/oragono/irc/modes"
|
2016-11-01 14:56:21 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2016-11-01 15:42:25 +01:00
|
|
|
npcNickMask = "*%s*!%s@npc.fakeuser.invalid"
|
2016-11-01 14:56:21 +01:00
|
|
|
sceneNickMask = "=Scene=!%s@npc.fakeuser.invalid"
|
|
|
|
)
|
|
|
|
|
2018-02-05 15:21:08 +01:00
|
|
|
func sendRoleplayMessage(server *Server, client *Client, source string, targetString string, isAction bool, message string, rb *ResponseBuffer) {
|
2016-11-01 14:56:21 +01:00
|
|
|
if isAction {
|
|
|
|
message = fmt.Sprintf("\x01ACTION %s (%s)\x01", message, client.nick)
|
|
|
|
} else {
|
2019-02-26 03:50:43 +01:00
|
|
|
// block attempts to send CTCP messages to Tor clients
|
|
|
|
// TODO(#395) clean this up
|
|
|
|
if len(message) != 0 && message[0] == '\x01' {
|
|
|
|
return
|
|
|
|
}
|
2016-11-01 14:56:21 +01:00
|
|
|
message = fmt.Sprintf("%s (%s)", message, client.nick)
|
|
|
|
}
|
|
|
|
|
|
|
|
target, cerr := CasefoldChannel(targetString)
|
|
|
|
if cerr == nil {
|
|
|
|
channel := server.channels.Get(target)
|
|
|
|
if channel == nil {
|
2018-02-05 15:21:08 +01:00
|
|
|
rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, targetString, client.t("No such channel"))
|
2016-11-01 14:56:21 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !channel.CanSpeak(client) {
|
2018-02-05 15:21:08 +01:00
|
|
|
rb.Add(nil, client.server.name, ERR_CANNOTSENDTOCHAN, channel.name, client.t("Cannot send to channel"))
|
2016-11-01 14:56:21 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-04-23 00:47:10 +02:00
|
|
|
if !channel.flags.HasMode(modes.ChanRoleplaying) {
|
2018-02-05 15:21:08 +01:00
|
|
|
rb.Add(nil, client.server.name, ERR_CANNOTSENDRP, channel.name, client.t("Channel doesn't have roleplaying mode available"))
|
2016-11-01 15:42:25 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-10-23 01:50:16 +02:00
|
|
|
for _, member := range channel.Members() {
|
2019-04-12 06:08:46 +02:00
|
|
|
for _, session := range member.Sessions() {
|
2020-03-19 17:19:42 +01:00
|
|
|
// see discussion on #865: clients do not understand how to do local echo
|
|
|
|
// of roleplay commands, so send them a copy whether they have echo-message
|
|
|
|
// or not
|
|
|
|
if rb.session == session {
|
2019-04-12 06:08:46 +02:00
|
|
|
rb.Add(nil, source, "PRIVMSG", channel.name, message)
|
2020-03-19 17:19:42 +01:00
|
|
|
} else {
|
2019-04-12 06:08:46 +02:00
|
|
|
session.Send(nil, source, "PRIVMSG", channel.name, message)
|
|
|
|
}
|
2018-02-05 15:21:08 +01:00
|
|
|
}
|
2016-11-01 14:56:21 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
target, err := CasefoldName(targetString)
|
|
|
|
user := server.clients.Get(target)
|
|
|
|
if err != nil || user == nil {
|
2018-02-05 15:21:08 +01:00
|
|
|
rb.Add(nil, server.name, ERR_NOSUCHNICK, client.nick, target, client.t("No such nick"))
|
2016-11-01 14:56:21 +01:00
|
|
|
return
|
|
|
|
}
|
2016-11-01 15:42:25 +01:00
|
|
|
|
2018-04-23 00:47:10 +02:00
|
|
|
if !user.HasMode(modes.UserRoleplaying) {
|
2018-02-05 15:21:08 +01:00
|
|
|
rb.Add(nil, client.server.name, ERR_CANNOTSENDRP, user.nick, client.t("User doesn't have roleplaying mode enabled"))
|
2016-11-01 15:42:25 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-02-17 20:29:04 +01:00
|
|
|
cnick := client.Nick()
|
|
|
|
tnick := user.Nick()
|
|
|
|
user.Send(nil, source, "PRIVMSG", tnick, message)
|
2019-04-12 06:08:46 +02:00
|
|
|
if rb.session.capabilities.Has(caps.EchoMessage) {
|
2019-02-17 20:29:04 +01:00
|
|
|
rb.Add(nil, source, "PRIVMSG", tnick, message)
|
2016-11-01 14:56:21 +01:00
|
|
|
}
|
2019-04-28 21:10:03 +02:00
|
|
|
if user.Away() {
|
2016-11-01 14:56:21 +01:00
|
|
|
//TODO(dan): possibly implement cooldown of away notifications to users
|
2019-02-17 20:29:04 +01:00
|
|
|
rb.Add(nil, server.name, RPL_AWAY, cnick, tnick, user.AwayMessage())
|
2016-11-01 14:56:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|