3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

encapsulate client replies in method

This commit is contained in:
Jeremy Latt 2014-02-22 11:40:32 -08:00
parent c12ed4bada
commit 1283bd35c7
4 changed files with 25 additions and 22 deletions

View File

@ -111,7 +111,7 @@ func (channel *Channel) Join(client *Client, key string) {
reply := RplJoin(client, channel)
for member := range channel.members {
member.replies <- reply
member.Reply(reply)
}
channel.GetTopic(client)
channel.Names(client)
@ -125,7 +125,7 @@ func (channel *Channel) Part(client *Client, message string) {
reply := RplPart(client, channel, message)
for member := range channel.members {
member.replies <- reply
member.Reply(reply)
}
channel.Quit(client)
@ -164,7 +164,7 @@ func (channel *Channel) SetTopic(client *Client, topic string) {
reply := RplTopicMsg(client, channel)
for member := range channel.members {
member.replies <- reply
member.Reply(reply)
}
}
@ -177,7 +177,7 @@ func (channel *Channel) PrivMsg(client *Client, message string) {
if member == client {
continue
}
member.replies <- RplPrivMsg(client, channel, message)
member.Reply(RplPrivMsg(client, channel, message))
}
}
@ -247,7 +247,7 @@ func (channel *Channel) Mode(client *Client, changes ChannelModeChanges) {
continue
}
target := channel.server.clients[change.arg]
target := channel.server.clients.Get(change.arg)
if target == nil {
// TODO err reply
continue
@ -272,7 +272,7 @@ func (channel *Channel) Mode(client *Client, changes ChannelModeChanges) {
if len(applied) > 0 {
for member := range channel.members {
member.replies <- RplChannelMode(client, channel, applied)
member.Reply(RplChannelMode(client, channel, applied))
}
}
}
@ -286,7 +286,7 @@ func (channel *Channel) Notice(client *Client, message string) {
if member == client {
continue
}
member.replies <- RplNotice(client, channel, message)
member.Reply(RplNotice(client, channel, message))
}
}
@ -311,7 +311,7 @@ func (channel *Channel) Kick(client *Client, target *Client, comment string) {
reply := RplKick(channel, client, target, comment)
for member := range channel.members {
member.replies <- reply
member.Reply(reply)
}
channel.Quit(target)
}

View File

@ -128,10 +128,6 @@ func (client *Client) writeReplies() {
}
}
client.socket.Close()
for _ = range client.replies {
// discard
}
}
//
@ -175,7 +171,7 @@ func (client *Client) Touch() {
}
func (client *Client) Idle() {
client.replies <- RplPing(client)
client.Reply(RplPing(client))
if client.quitTimer == nil {
client.quitTimer = time.AfterFunc(QUIT_TIMEOUT, client.connectionTimeout)
@ -295,17 +291,24 @@ func (client *Client) ChangeNickname(nickname string) {
client.nick = nickname
client.server.clients.Add(client)
for friend := range client.Friends() {
friend.replies <- reply
friend.Reply(reply)
}
}
func (client *Client) Reply(reply string) {
if client.hasQuit {
return
}
client.replies <- reply
}
func (client *Client) Quit(message string) {
if client.hasQuit {
return
}
client.replies <- RplError("connection closed")
client.replies <- EOF
client.Reply(RplError("connection closed"))
client.Reply(EOF)
client.hasQuit = true
friends := client.Friends()
@ -315,7 +318,7 @@ func (client *Client) Quit(message string) {
if len(friends) > 0 {
reply := RplQuit(client, message)
for friend := range friends {
friend.replies <- reply
friend.Reply(reply)
}
}
}

View File

@ -27,7 +27,7 @@ func NewNumericReply(target *Client, code NumericCode,
func (target *Client) NumericReply(code NumericCode,
format string, args ...interface{}) {
target.replies <- NewNumericReply(target, code, format, args...)
target.Reply(NewNumericReply(target, code, format, args...))
}
//

View File

@ -340,7 +340,7 @@ func (m *PassCommand) HandleServer(s *Server) {
}
func (m *PingCommand) HandleServer(s *Server) {
m.Client().replies <- RplPong(m.Client())
m.Client().Reply(RplPong(m.Client()))
}
func (m *PongCommand) HandleServer(s *Server) {
@ -443,7 +443,7 @@ func (msg *PrivMsgCommand) HandleServer(server *Server) {
client.ErrNoSuchNick(msg.target)
return
}
target.replies <- RplPrivMsg(client, target, msg.message)
target.Reply(RplPrivMsg(client, target, msg.message))
if target.flags[Away] {
target.RplAway(client)
}
@ -488,7 +488,7 @@ func (m *ModeCommand) HandleServer(s *Server) {
// Who should get these replies?
if len(changes) > 0 {
client.replies <- RplMode(client, target, changes)
client.Reply(RplMode(client, target, changes))
}
}
@ -648,7 +648,7 @@ func (msg *NoticeCommand) HandleServer(server *Server) {
client.ErrNoSuchNick(msg.target)
return
}
target.replies <- RplNotice(client, target, msg.message)
target.Reply(RplNotice(client, target, msg.message))
}
func (msg *KickCommand) HandleServer(server *Server) {