ソースを参照

away modes

tags/v0.1.0
Jeremy Latt 10年前
コミット
08d9d5ab79
6個のファイルの変更79行の追加24行の削除
  1. 4
    2
      irc/channel.go
  2. 18
    17
      irc/client.go
  3. 22
    0
      irc/commands.go
  4. 17
    2
      irc/reply.go
  5. 17
    2
      irc/server.go
  6. 1
    1
      irc/types.go

+ 4
- 2
irc/channel.go ファイルの表示

@@ -55,11 +55,13 @@ func (channel *Channel) Destroy() error {
55 55
 	return nil
56 56
 }
57 57
 
58
-func (channel *Channel) Reply(reply Reply) error {
58
+func (channel *Channel) Reply(replies ...Reply) error {
59 59
 	if channel.replies == nil {
60 60
 		return ErrAlreadyDestroyed
61 61
 	}
62
-	channel.replies <- reply
62
+	for _, reply := range replies {
63
+		channel.replies <- reply
64
+	}
63 65
 	return nil
64 66
 }
65 67
 

+ 18
- 17
irc/client.go ファイルの表示

@@ -11,23 +11,24 @@ import (
11 11
 )
12 12
 
13 13
 type Client struct {
14
-	away       bool
15
-	channels   ChannelSet
16
-	conn       net.Conn
17
-	hostname   string
18
-	idleTimer  *time.Timer
19
-	invisible  bool
20
-	nick       string
21
-	operator   bool
22
-	quitTimer  *time.Timer
23
-	realname   string
24
-	recv       *bufio.Reader
25
-	registered bool
26
-	replies    chan<- Reply
27
-	send       *bufio.Writer
28
-	server     *Server
29
-	serverPass bool
30
-	username   string
14
+	away        bool
15
+	awayMessage string
16
+	channels    ChannelSet
17
+	conn        net.Conn
18
+	hostname    string
19
+	idleTimer   *time.Timer
20
+	invisible   bool
21
+	nick        string
22
+	operator    bool
23
+	quitTimer   *time.Timer
24
+	realname    string
25
+	recv        *bufio.Reader
26
+	registered  bool
27
+	replies     chan<- Reply
28
+	send        *bufio.Writer
29
+	server      *Server
30
+	serverPass  bool
31
+	username    string
31 32
 }
32 33
 
33 34
 func NewClient(server *Server, conn net.Conn) *Client {

+ 22
- 0
irc/commands.go ファイルの表示

@@ -18,6 +18,7 @@ var (
18 18
 	NotEnoughArgsError = errors.New("not enough arguments")
19 19
 	ErrParseCommand    = errors.New("failed to parse message")
20 20
 	parseCommandFuncs  = map[string]parseCommandFunc{
21
+		"AWAY":    NewAwayCommand,
21 22
 		"CAP":     NewCapCommand,
22 23
 		"JOIN":    NewJoinCommand,
23 24
 		"MODE":    NewModeCommand,
@@ -609,3 +610,24 @@ func NewProxyCommand(args []string) (editableCommand, error) {
609 610
 		destPort:   args[4],
610 611
 	}, nil
611 612
 }
613
+
614
+type AwayCommand struct {
615
+	BaseCommand
616
+	text string
617
+	away bool
618
+}
619
+
620
+func (msg *AwayCommand) String() string {
621
+	return fmt.Sprintf("AWAY(%s)", msg.text)
622
+}
623
+
624
+func NewAwayCommand(args []string) (editableCommand, error) {
625
+	cmd := &AwayCommand{}
626
+
627
+	if len(args) > 0 {
628
+		cmd.text = args[0]
629
+		cmd.away = true
630
+	}
631
+
632
+	return cmd, nil
633
+}

+ 17
- 2
irc/reply.go ファイルの表示

@@ -252,8 +252,23 @@ func RplBanList(channel *Channel, ban UserMask) Reply {
252 252
 }
253 253
 
254 254
 func RplEndOfBanList(channel *Channel) Reply {
255
-	return NewNumericReply(channel.server, RPL_ENDOFBANLIST, "%s :End of channel ban list",
256
-		channel.name)
255
+	return NewNumericReply(channel.server, RPL_ENDOFBANLIST,
256
+		"%s :End of channel ban list", channel.name)
257
+}
258
+
259
+func RplNowAway(server *Server) Reply {
260
+	return NewNumericReply(server, RPL_NOWAWAY,
261
+		":You have been marked as being away")
262
+}
263
+
264
+func RplUnAway(server *Server) Reply {
265
+	return NewNumericReply(server, RPL_UNAWAY,
266
+		":You are no longer marked as being away")
267
+}
268
+
269
+func RplAway(server *Server, client *Client) Reply {
270
+	return NewNumericReply(server, RPL_AWAY,
271
+		"%s :%s", client.nick, client.awayMessage)
257 272
 }
258 273
 
259 274
 // errors (also numeric)

+ 17
- 2
irc/server.go ファイルの表示

@@ -147,12 +147,12 @@ func (s *Server) tryRegister(c *Client) {
147 147
 			RplYourHost(s),
148 148
 			RplCreated(s),
149 149
 			RplMyInfo(s))
150
-		server.MOTD(c)
150
+		s.MOTD(c)
151 151
 	}
152 152
 }
153 153
 
154 154
 func (server *Server) MOTD(client *Client) {
155
-	c.Reply(ErrNoMOTD(server))
155
+	client.Reply(ErrNoMOTD(server))
156 156
 }
157 157
 
158 158
 func (s *Server) Id() string {
@@ -305,6 +305,9 @@ func (m *PrivMsgCommand) HandleServer(s *Server) {
305 305
 		return
306 306
 	}
307 307
 	target.Reply(RplPrivMsg(m.Client(), target, m.message))
308
+	if target.away {
309
+		m.Client().Reply(RplAway(s, target))
310
+	}
308 311
 }
309 312
 
310 313
 func (m *ModeCommand) HandleServer(s *Server) {
@@ -407,3 +410,15 @@ func (msg *CapCommand) HandleServer(server *Server) {
407 410
 func (msg *ProxyCommand) HandleServer(server *Server) {
408 411
 	msg.Client().hostname = LookupHostname(msg.sourceIP)
409 412
 }
413
+
414
+func (msg *AwayCommand) HandleServer(server *Server) {
415
+	client := msg.Client()
416
+	client.away = msg.away
417
+	client.awayMessage = msg.text
418
+
419
+	if client.away {
420
+		client.Reply(RplNowAway(server))
421
+	} else {
422
+		client.Reply(RplUnAway(server))
423
+	}
424
+}

+ 1
- 1
irc/types.go ファイルの表示

@@ -108,7 +108,7 @@ type Identifier interface {
108 108
 }
109 109
 
110 110
 type Replier interface {
111
-	Reply(Reply) error
111
+	Reply(...Reply) error
112 112
 }
113 113
 
114 114
 type Reply interface {

読み込み中…
キャンセル
保存