diff --git a/irc/channel.go b/irc/channel.go index ba93a452..73191dbc 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -1011,9 +1011,11 @@ func (channel *Channel) Invite(invitee *Client, inviter *Client, rb *ResponseBuf } } - rb.Add(nil, inviter.server.name, RPL_INVITING, inviter.Nick(), invitee.Nick(), chname) - invitee.Send(nil, inviter.nickMaskString, "INVITE", invitee.nick, chname) + cnick := inviter.Nick() + tnick := invitee.Nick() + rb.Add(nil, inviter.server.name, RPL_INVITING, cnick, tnick, chname) + invitee.Send(nil, inviter.NickMaskString(), "INVITE", tnick, chname) if invitee.HasMode(modes.Away) { - rb.Add(nil, inviter.server.name, RPL_AWAY, invitee.nick, invitee.awayMessage) + rb.Add(nil, inviter.server.name, RPL_AWAY, cnick, tnick, invitee.AwayMessage()) } } diff --git a/irc/getters.go b/irc/getters.go index 7eb3e546..4a6a3627 100644 --- a/irc/getters.go +++ b/irc/getters.go @@ -143,6 +143,19 @@ func (client *Client) SetRegistered() { client.stateMutex.Unlock() } +func (client *Client) AwayMessage() (result string) { + client.stateMutex.RLock() + result = client.awayMessage + client.stateMutex.RUnlock() + return +} + +func (client *Client) SetAwayMessage(message string) { + client.stateMutex.Lock() + client.awayMessage = message + client.stateMutex.Unlock() +} + func (client *Client) Destroyed() bool { client.stateMutex.RLock() defer client.stateMutex.RUnlock() diff --git a/irc/handlers.go b/irc/handlers.go index 740fc9a9..31944827 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -408,18 +408,18 @@ func authExternalHandler(server *Server, client *Client, mechanism string, value // AWAY [] func awayHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool { var isAway bool - var text string + var awayMessage string if len(msg.Params) > 0 { isAway = true - text = msg.Params[0] + awayMessage = msg.Params[0] awayLen := server.Limits().AwayLen - if len(text) > awayLen { - text = text[:awayLen] + if len(awayMessage) > awayLen { + awayMessage = awayMessage[:awayLen] } } client.SetMode(modes.Away, isAway) - client.awayMessage = text + client.SetAwayMessage(awayMessage) var op modes.ModeOp if isAway { @@ -439,7 +439,7 @@ func awayHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp // dispatch away-notify for friend := range client.Friends(caps.AwayNotify) { if isAway { - friend.SendFromClient("", client, nil, "AWAY", client.awayMessage) + friend.SendFromClient("", client, nil, "AWAY", awayMessage) } else { friend.SendFromClient("", client, nil, "AWAY") } @@ -1777,6 +1777,7 @@ func monitorClearHandler(server *Server, client *Client, msg ircmsg.IrcMessage, // MONITOR L func monitorListHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool { + nick := client.Nick() monitorList := server.monitorManager.List(client) var nickList []string @@ -1790,10 +1791,10 @@ func monitorListHandler(server *Server, client *Client, msg ircmsg.IrcMessage, r } for _, line := range utils.ArgsToStrings(maxLastArgLength, nickList, ",") { - rb.Add(nil, server.name, RPL_MONLIST, client.Nick(), line) + rb.Add(nil, server.name, RPL_MONLIST, nick, line) } - rb.Add(nil, server.name, RPL_ENDOFMONLIST, "End of MONITOR list") + rb.Add(nil, server.name, RPL_ENDOFMONLIST, nick, "End of MONITOR list") return false } @@ -2089,6 +2090,7 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R // split privmsg splitMsg := utils.MakeSplitMessage(message, !client.capabilities.Has(caps.MaxLine)) + cnick := client.Nick() for i, targetString := range targets { // max of four targets per privmsg if i > maxTargets-1 { @@ -2106,7 +2108,7 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R if err == nil { channel := server.channels.Get(target) if channel == nil { - rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, targetString, client.t("No such channel")) + rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, cnick, targetString, client.t("No such channel")) continue } if !channel.CanSpeak(client) { @@ -2124,7 +2126,7 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R user := server.clients.Get(target) if err != nil || user == nil { if len(target) > 0 { - client.Send(nil, server.name, ERR_NOSUCHNICK, client.nick, target, "No such nick") + client.Send(nil, server.name, ERR_NOSUCHNICK, cnick, target, "No such nick") } continue } @@ -2144,7 +2146,7 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R } if user.HasMode(modes.Away) { //TODO(dan): possibly implement cooldown of away notifications to users - rb.Add(nil, server.name, RPL_AWAY, user.nick, user.awayMessage) + rb.Add(nil, server.name, RPL_AWAY, cnick, user.Nick(), user.AwayMessage()) } user.history.Add(history.Item{ @@ -2343,6 +2345,7 @@ func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re targets := strings.Split(msg.Params[0], ",") + cnick := client.Nick() for i, targetString := range targets { // max of four targets per privmsg if i > maxTargets-1 { @@ -2360,7 +2363,7 @@ func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re if err == nil { channel := server.channels.Get(target) if channel == nil { - rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, targetString, client.t("No such channel")) + rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, cnick, targetString, client.t("No such channel")) continue } if !channel.CanSpeak(client) { @@ -2375,7 +2378,7 @@ func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re user := server.clients.Get(target) if err != nil || user == nil { if len(target) > 0 { - client.Send(nil, server.name, ERR_NOSUCHNICK, client.nick, target, client.t("No such nick")) + client.Send(nil, server.name, ERR_NOSUCHNICK, cnick, target, client.t("No such nick")) } continue } @@ -2391,7 +2394,7 @@ func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re } if user.HasMode(modes.Away) { //TODO(dan): possibly implement cooldown of away notifications to users - rb.Add(nil, server.name, RPL_AWAY, user.nick, user.awayMessage) + rb.Add(nil, server.name, RPL_AWAY, cnick, user.Nick(), user.AwayMessage()) } } } diff --git a/irc/roleplay.go b/irc/roleplay.go index 80d39b19..a2cc376d 100644 --- a/irc/roleplay.go +++ b/irc/roleplay.go @@ -63,13 +63,15 @@ func sendRoleplayMessage(server *Server, client *Client, source string, targetSt return } - user.Send(nil, source, "PRIVMSG", user.nick, message) + cnick := client.Nick() + tnick := user.Nick() + user.Send(nil, source, "PRIVMSG", tnick, message) if client.capabilities.Has(caps.EchoMessage) { - rb.Add(nil, source, "PRIVMSG", user.nick, message) + rb.Add(nil, source, "PRIVMSG", tnick, message) } if user.HasMode(modes.Away) { //TODO(dan): possibly implement cooldown of away notifications to users - rb.Add(nil, server.name, RPL_AWAY, user.nick, user.awayMessage) + rb.Add(nil, server.name, RPL_AWAY, cnick, tnick, user.AwayMessage()) } } }