|
@@ -15,8 +15,14 @@ func joinedLen(names []string) int {
|
15
|
15
|
}
|
16
|
16
|
|
17
|
17
|
type BaseReply struct {
|
18
|
|
- source Identifier
|
|
18
|
+ id string
|
19
|
19
|
message string
|
|
20
|
+ source Identifier
|
|
21
|
+}
|
|
22
|
+
|
|
23
|
+func (reply *BaseReply) SetSource(source Identifier) {
|
|
24
|
+ reply.id = source.Id()
|
|
25
|
+ reply.source = source
|
20
|
26
|
}
|
21
|
27
|
|
22
|
28
|
func (reply *BaseReply) Source() Identifier {
|
|
@@ -33,22 +39,22 @@ func NewStringReply(source Identifier, code string,
|
33
|
39
|
reply := &StringReply{
|
34
|
40
|
code: code,
|
35
|
41
|
}
|
|
42
|
+ reply.SetSource(source)
|
36
|
43
|
reply.message = fmt.Sprintf(format, args...)
|
37
|
|
- reply.source = source
|
38
|
44
|
return reply
|
39
|
45
|
}
|
40
|
46
|
|
41
|
47
|
func (reply *StringReply) Format(client *Client) []string {
|
42
|
48
|
message := fmt.Sprintf("%s %s", reply.code, reply.message)
|
43
|
49
|
if Identifier(client.server) != reply.source {
|
44
|
|
- message = fmt.Sprintf(":%s %s", reply.source.Id(), message)
|
|
50
|
+ message = fmt.Sprintf(":%s %s", reply.id, message)
|
45
|
51
|
}
|
46
|
52
|
return []string{message}
|
47
|
53
|
}
|
48
|
54
|
|
49
|
55
|
func (reply *StringReply) String() string {
|
50
|
56
|
return fmt.Sprintf("Reply(source=%s, code=%s, message=%s)",
|
51
|
|
- reply.source, reply.code, reply.message)
|
|
57
|
+ reply.id, reply.code, reply.message)
|
52
|
58
|
}
|
53
|
59
|
|
54
|
60
|
type NumericReply struct {
|
|
@@ -61,8 +67,8 @@ func NewNumericReply(source Identifier, code int, format string,
|
61
|
67
|
reply := &NumericReply{
|
62
|
68
|
code: code,
|
63
|
69
|
}
|
|
70
|
+ reply.SetSource(source)
|
64
|
71
|
reply.message = fmt.Sprintf(format, args...)
|
65
|
|
- reply.source = source
|
66
|
72
|
return reply
|
67
|
73
|
}
|
68
|
74
|
|
|
@@ -70,14 +76,14 @@ func (reply *NumericReply) Format(client *Client) []string {
|
70
|
76
|
message := fmt.Sprintf("%03d %s %s",
|
71
|
77
|
reply.code, client.Nick(), reply.message)
|
72
|
78
|
if Identifier(client.server) != reply.source {
|
73
|
|
- message = fmt.Sprintf(":%s %s", reply.source.Id(), message)
|
|
79
|
+ message = fmt.Sprintf(":%s %s", reply.id, message)
|
74
|
80
|
}
|
75
|
81
|
return []string{message}
|
76
|
82
|
}
|
77
|
83
|
|
78
|
84
|
func (reply *NumericReply) String() string {
|
79
|
85
|
return fmt.Sprintf("Reply(source=%s, code=%d, message=%s)",
|
80
|
|
- reply.source, reply.code, reply.message)
|
|
86
|
+ reply.id, reply.code, reply.message)
|
81
|
87
|
}
|
82
|
88
|
|
83
|
89
|
// names reply
|
|
@@ -88,12 +94,11 @@ type NamesReply struct {
|
88
|
94
|
}
|
89
|
95
|
|
90
|
96
|
func NewNamesReply(channel *Channel) Reply {
|
91
|
|
- return &NamesReply{
|
92
|
|
- BaseReply: &BaseReply{
|
93
|
|
- source: channel,
|
94
|
|
- },
|
|
97
|
+ reply := &NamesReply{
|
95
|
98
|
channel: channel,
|
96
|
99
|
}
|
|
100
|
+ reply.SetSource(channel)
|
|
101
|
+ return reply
|
97
|
102
|
}
|
98
|
103
|
|
99
|
104
|
func (reply *NamesReply) Format(client *Client) []string {
|
|
@@ -401,3 +406,7 @@ func ErrChanOPrivIsNeeded(channel *Channel) Reply {
|
401
|
406
|
func ErrNoMOTD(server *Server) Reply {
|
402
|
407
|
return NewNumericReply(server, ERR_NOMOTD, ":MOTD File is missing")
|
403
|
408
|
}
|
|
409
|
+
|
|
410
|
+func ErrNoNicknameGiven(server *Server) Reply {
|
|
411
|
+ return NewNumericReply(server, ERR_NONICKNAMEGIVEN, ":No nickname given")
|
|
412
|
+}
|