3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

roleplay: More fixes and checks

This commit is contained in:
Daniel Oaks 2016-11-02 00:42:25 +10:00
parent 07e4728c15
commit d32ccdc572
2 changed files with 26 additions and 1 deletions

View File

@ -150,6 +150,7 @@ const (
ERR_UMODEUNKNOWNFLAG = "501"
ERR_USERSDONTMATCH = "502"
ERR_HELPNOTFOUND = "524"
ERR_CANNOTSENDRP = "573"
RPL_HELPSTART = "704"
RPL_HELPTXT = "705"
RPL_ENDOFHELP = "706"

View File

@ -10,7 +10,7 @@ import (
)
const (
npcNickMask = "%s!%s@npc.fakeuser.invalid"
npcNickMask = "*%s*!%s@npc.fakeuser.invalid"
sceneNickMask = "=Scene=!%s@npc.fakeuser.invalid"
)
@ -30,6 +30,13 @@ func npcHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
target := msg.Params[0]
fakeSource := msg.Params[1]
message := msg.Params[2]
_, err := CasefoldName(fakeSource)
if err != nil {
client.Send(nil, client.server.name, ERR_CANNOTSENDRP, target, "Fake source must be a valid nickname")
return false
}
sourceString := fmt.Sprintf(npcNickMask, fakeSource, client.nick)
sendRoleplayMessage(server, client, sourceString, target, false, message)
@ -44,6 +51,12 @@ func npcaHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
message := msg.Params[2]
sourceString := fmt.Sprintf(npcNickMask, fakeSource, client.nick)
_, err := CasefoldName(fakeSource)
if err != nil {
client.Send(nil, client.server.name, ERR_CANNOTSENDRP, target, "Fake source must be a valid nickname")
return false
}
sendRoleplayMessage(server, client, sourceString, target, true, message)
return false
@ -69,6 +82,11 @@ func sendRoleplayMessage(server *Server, client *Client, source string, targetSt
return
}
if !channel.flags[ChanRoleplaying] {
client.Send(nil, client.server.name, ERR_CANNOTSENDRP, channel.name, "Channel doesn't have roleplaying mode available")
return
}
for member := range channel.members {
if member == client && !client.capabilities[EchoMessage] {
continue
@ -82,6 +100,12 @@ func sendRoleplayMessage(server *Server, client *Client, source string, targetSt
client.Send(nil, server.name, ERR_NOSUCHNICK, target, "No such nick")
return
}
if !user.flags[UserRoleplaying] {
client.Send(nil, client.server.name, ERR_CANNOTSENDRP, user.nick, "User doesn't have roleplaying mode enabled")
return
}
user.Send(nil, source, "PRIVMSG", user.nick, message)
if client.capabilities[EchoMessage] {
client.Send(nil, source, "PRIVMSG", user.nick, message)