26 struct irc_conn_callbacks _conn_callbacks = { |
26 struct irc_conn_callbacks _conn_callbacks = { |
27 .on_registered = &irc_net_conn_registered, |
27 .on_registered = &irc_net_conn_registered, |
28 }; |
28 }; |
29 |
29 |
30 /** |
30 /** |
31 * :nm JOIN <channel> |
31 * Propagate the command to the appropriate irc_chan based on the given name |
32 */ |
32 */ |
33 static void irc_net_on_JOIN (const struct irc_line *line, void *arg) |
33 static void irc_net_propagate_chan (struct irc_net *net, const struct irc_line *line, const char *channel) |
34 { |
34 { |
35 struct irc_net *net = arg; |
|
36 struct irc_chan *chan; |
35 struct irc_chan *chan; |
37 |
36 |
38 // look up channel |
37 // look up channel |
39 if ((chan = irc_net_get_chan(net, line->args[0])) == NULL) { |
38 if ((chan = irc_net_get_chan(net, channel)) == NULL) { |
40 log_warn("unkown channel: %s", line->args[0]); |
39 log_warn("unknown channel: %s", channel); |
41 return; |
40 return; |
42 } |
41 } |
43 |
42 |
44 // propagate |
43 // propagate |
45 irc_cmd_invoke(&chan->handlers, line); |
44 irc_cmd_invoke(&chan->handlers, line); |
46 } |
45 } |
47 |
46 |
48 /** |
47 /** |
|
48 * Propagate line to irc_chan based on args[0] |
|
49 */ |
|
50 static void irc_net_on_chan0 (const struct irc_line *line, void *arg) |
|
51 { |
|
52 struct irc_net *net = arg; |
|
53 |
|
54 irc_net_propagate_chan(net, line, line->args[0]); |
|
55 } |
|
56 |
|
57 /** |
|
58 * :nm PRIVMSG <target> <message> |
|
59 * |
|
60 * Either propagate to channel if found, otherwise handle as a privmsg |
|
61 */ |
|
62 static void irc_net_on_PRIVMSG (const struct irc_line *line, void *arg) |
|
63 { |
|
64 struct irc_net *net = arg; |
|
65 |
|
66 // XXX: does two lookups |
|
67 if (irc_net_get_chan(net, line->args[0])) { |
|
68 // short-circuit to on_chan0 |
|
69 irc_net_on_chan0(line, arg); |
|
70 |
|
71 } else { |
|
72 // XXX: callbacks for privmsgs |
|
73 |
|
74 } |
|
75 } |
|
76 |
|
77 /** |
49 * Our irc_cmd handler list |
78 * Our irc_cmd handler list |
50 */ |
79 */ |
51 static struct irc_cmd_handler _cmd_handlers[] = { |
80 static struct irc_cmd_handler _cmd_handlers[] = { |
52 { "JOIN", &irc_net_on_JOIN }, |
81 { "JOIN", &irc_net_on_chan0 }, |
|
82 { "PRIVMSG", &irc_net_on_PRIVMSG }, |
53 { NULL, NULL } |
83 { NULL, NULL } |
54 }; |
84 }; |
55 |
85 |
56 err_t irc_net_create (struct irc_net **net_ptr, const struct irc_net_info *info, struct error_info *err) |
86 err_t irc_net_create (struct irc_net **net_ptr, const struct irc_net_info *info, struct error_info *err) |
57 { |
87 { |