mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-23 11:12:44 +01:00
roleplay: More fixes and checks
This commit is contained in:
parent
07e4728c15
commit
d32ccdc572
@ -150,6 +150,7 @@ const (
|
|||||||
ERR_UMODEUNKNOWNFLAG = "501"
|
ERR_UMODEUNKNOWNFLAG = "501"
|
||||||
ERR_USERSDONTMATCH = "502"
|
ERR_USERSDONTMATCH = "502"
|
||||||
ERR_HELPNOTFOUND = "524"
|
ERR_HELPNOTFOUND = "524"
|
||||||
|
ERR_CANNOTSENDRP = "573"
|
||||||
RPL_HELPSTART = "704"
|
RPL_HELPSTART = "704"
|
||||||
RPL_HELPTXT = "705"
|
RPL_HELPTXT = "705"
|
||||||
RPL_ENDOFHELP = "706"
|
RPL_ENDOFHELP = "706"
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
npcNickMask = "%s!%s@npc.fakeuser.invalid"
|
npcNickMask = "*%s*!%s@npc.fakeuser.invalid"
|
||||||
sceneNickMask = "=Scene=!%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]
|
target := msg.Params[0]
|
||||||
fakeSource := msg.Params[1]
|
fakeSource := msg.Params[1]
|
||||||
message := msg.Params[2]
|
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)
|
sourceString := fmt.Sprintf(npcNickMask, fakeSource, client.nick)
|
||||||
|
|
||||||
sendRoleplayMessage(server, client, sourceString, target, false, message)
|
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]
|
message := msg.Params[2]
|
||||||
sourceString := fmt.Sprintf(npcNickMask, fakeSource, client.nick)
|
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)
|
sendRoleplayMessage(server, client, sourceString, target, true, message)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@ -69,6 +82,11 @@ func sendRoleplayMessage(server *Server, client *Client, source string, targetSt
|
|||||||
return
|
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 {
|
for member := range channel.members {
|
||||||
if member == client && !client.capabilities[EchoMessage] {
|
if member == client && !client.capabilities[EchoMessage] {
|
||||||
continue
|
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")
|
client.Send(nil, server.name, ERR_NOSUCHNICK, target, "No such nick")
|
||||||
return
|
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)
|
user.Send(nil, source, "PRIVMSG", user.nick, message)
|
||||||
if client.capabilities[EchoMessage] {
|
if client.capabilities[EchoMessage] {
|
||||||
client.Send(nil, source, "PRIVMSG", user.nick, message)
|
client.Send(nil, source, "PRIVMSG", user.nick, message)
|
||||||
|
Loading…
Reference in New Issue
Block a user