2 * IRC - Internet Relay Chat, ircd/m_relay.c
3 * Written by David Herrmann.
14 #include "ircd_chattr.h"
15 #include "ircd_features.h"
16 #include "ircd_reply.h"
17 #include "ircd_string.h"
31 static void loc_handler_LR(const char *num, char *parv[], signed int parc) {
32 if(num[0] != '!') return;
34 auth_loc_reply(&num[3], NULL, NULL, NULL, 0);
36 auth_loc_reply(&num[3], NULL, NULL, &parv[0] , parc);
39 static void loc_handler_LA(const char *num, char *parv[], signed int parc) {
40 if(num[0] != '!' || parc < 1) return;
41 char *fakehost = NULL;
42 if (parc > 1 && strcmp(parv[1], "0") != 0) // 0 = no fakehost
46 auth_loc_reply(&num[3], parv[0], fakehost, &parv[2] , parc - 2);
48 auth_loc_reply(&num[3], parv[0], fakehost, NULL, 0);
50 auth_loc_reply(&num[3], parv[0], NULL, NULL, 0);
54 static void mode_a_join(struct Client* cptr, char *channel, int flags) {
55 struct Channel *chptr;
56 if (!(chptr = FindChannel(channel))) {
57 if (((channel[0] == '&') && !feature_bool(FEAT_LOCAL_CHANNELS)) || strlen(channel) > IRCD_MIN(CHANNELLEN, feature_int(FEAT_CHANNELLEN))) {
58 //we don't send an error message here - that would be very strange for the user, because they normaly don't know that mode +F is set
59 } else if ((chptr = get_channel(cptr, channel, CGT_CREATE))) {
60 struct JoinBuf create;
61 joinbuf_init(&create, cptr, cptr, JOINBUF_TYPE_CREATE, 0, TStime());
62 joinbuf_join(&create, chptr, CHFL_CHANOP | CHFL_CHANNEL_MANAGER);
63 do_names(cptr, chptr, NAMES_ALL|NAMES_EON);
64 joinbuf_flush(&create);
68 if(find_member_link(chptr, cptr))
69 return; //we have already joined this channel
70 joinbuf_init(&join, cptr, cptr, JOINBUF_TYPE_JOIN, 0, 0);
71 joinbuf_join(&join, chptr, flags);
72 del_invite(cptr, chptr);
73 if (chptr->topic[0]) {
74 send_reply(cptr, RPL_TOPIC, chptr->chname, chptr->topic);
75 send_reply(cptr, RPL_TOPICWHOTIME, chptr->chname, chptr->topic_nick, chptr->topic_time);
77 do_names(cptr, chptr, NAMES_ALL|NAMES_EON); /* send /names list */
82 static void mode_a_check_altchan(struct Client* sptr, char *channel) {
83 struct Channel *chptrb;
84 if (!(chptrb = FindChannel(channel))) {
85 if (((channel[0] == '&') && !feature_bool(FEAT_LOCAL_CHANNELS)) || strlen(channel) > IRCD_MIN(CHANNELLEN, feature_int(FEAT_CHANNELLEN))) {
86 //we don't send an error message here - that would be very strange for the user, because they normaly don't know that mode +F is set
87 } else if ((chptrb = get_channel(sptr, channel, CGT_CREATE))) {
88 struct JoinBuf create;
89 joinbuf_init(&create, sptr, sptr, JOINBUF_TYPE_CREATE, 0, TStime());
90 joinbuf_join(&create, chptrb, CHFL_CHANOP | CHFL_CHANNEL_MANAGER);
91 do_names(sptr, chptrb, NAMES_ALL|NAMES_EON);
92 joinbuf_flush(&create);
95 if(find_member_link(chptrb, sptr))
96 return; //we have already joined this channel
97 //first of all check if we may even join this channel
100 if (chptrb->users == 0 && !chptrb->mode.apass[0] && !(chptrb->mode.mode & MODE_PERSIST)) {
101 /* Joining a zombie channel (zannel): give ops and increment TS. */
103 chptrb->creationtime++;
104 } else if (IsInvited(sptr, chptrb)) {
105 /* Invites and key=OVERRIDE bypass these other checks. */
106 } else if (chptrb->mode.mode & MODE_INVITEONLY)
107 err2 = ERR_INVITEONLYCHAN;
108 else if (chptrb->mode.limit && (chptrb->users >= chptrb->mode.limit))
109 err2 = ERR_CHANNELISFULL;
110 else if ((chptrb->mode.mode & MODE_REGONLY) && !IsAccount(sptr))
111 err2 = ERR_NEEDREGGEDNICK;
112 else if ((chptrb->mode.mode & MODE_SSLCHAN) && !IsSSL(sptr))
113 err2 = ERR_SSLCHANNEL;
114 else if (find_ban(sptr, chptrb->banlist))
115 err2 = ERR_BANNEDFROMCHAN;
116 else if (*chptrb->mode.key) //Fix this!
117 err2 = ERR_BADCHANNELKEY;
120 joinbuf_init(&join, sptr, sptr, JOINBUF_TYPE_JOIN, 0, 0);
121 joinbuf_join(&join, chptrb, flags);
122 del_invite(sptr, chptrb);
123 if (chptrb->topic[0]) {
124 send_reply(sptr, RPL_TOPIC, chptrb->chname, chptrb->topic);
125 send_reply(sptr, RPL_TOPICWHOTIME, chptrb->chname, chptrb->topic_nick, chptrb->topic_time);
127 do_names(sptr, chptrb, NAMES_ALL|NAMES_EON); /* send /names list */
128 joinbuf_flush(&join);
134 * The RELAY command has a special purpose. It is always built the following way:
135 * <sender> RELAY <destination> <command>[ <list of parameters>]
136 * The <sender> is a single numeric nick of a server or user. <destination> can be:
137 * - a numeric-nick of a server (2 characters long): eg., AD
138 * - a numeric-nick of a user (5 characters long): eg., ADAAB
139 * - a numeric-nick of an unregistered user (6 characters long): eg., !ADAAB
140 * <command> is a subcommdn of RELAY.
142 * If we receive such a message, we relay the message to the server of <destination>.
143 * If we are the target, we check <command> and call the related subcommand handler.
145 * Therefore, this interface can be used to relay messages through the network without
146 * specifying new commands.
148 /* ms_relay - server message handler
150 * parv[0] = sender prefix
152 * parv[2] = subcommand
153 * parv[3-X] = NULL or a list of parameters.
155 signed int ms_relay(struct Client* cptr, struct Client* sptr, signed int parc, char* parv[]) {
156 struct Client *server;
158 char buf[3], *act, *m, buffer[513];
161 return protocol_violation(cptr, "Too few arguments for RELAY");
164 /* Check <destination>. */
165 len = strlen(parv[1]);
169 server = FindNServer(parv[1]);
174 server = FindNServer(buf);
179 server = FindNServer(buf);
182 /* Invalid destination. Ignore. */
186 if(!server) return 0;
190 for(i = 3; i < (parc - 1); ++i) {
192 while((*act++ = *m++)) /* empty loop */ ;
197 while((*act++ = *m++)) /* empty loop */ ;
198 sendcmdto_one(sptr, CMD_RELAY, server, "%s %s %s", parv[1], parv[2], buffer);
200 else sendcmdto_one(sptr, CMD_RELAY, server, "%s %s", parv[1], parv[2]);
204 /* Call subcommand handler. */
205 if(strcmp("LR", parv[2]) == 0)
206 loc_handler_LR(parv[1], &parv[3], parc - 3);
207 else if(strcmp("LA", parv[2]) == 0 && parc > 3)
208 loc_handler_LA(parv[1], &parv[3], parc - 3);
209 else if(strcmp("SM", parv[2]) == 0 && parc > 3) {
210 #ifndef UNRESTRICTED_SERV
211 struct Client *acptr;
212 if(acptr = findNUser(parv[3])) {
213 if (IsChannelPrefix(*parv[4]))
214 relay_channel_message(acptr, parv[4], parv[parc - 1], 1);
216 relay_private_message(acptr, parv[4], parv[parc - 1]);
219 } else if(strcmp("UC", parv[2]) == 0 && parc > 3) {
220 struct Client *acptr;
221 if(acptr = findNUser(parv[3]))
222 send_reply(acptr, ERR_UNKNOWNCOMMAND, parv[4]);
223 } else if(strcmp("SI", parv[2]) == 0 && parc > 3) {
224 #ifndef UNRESTRICTED_SERV
225 struct Client *acptr;
226 if(acptr = findNUser(parv[3]))
227 parse_simul_client(acptr, parv[parc - 1]);
229 } else if(strcmp("JAA", parv[2]) == 0 && parc > 2) {
230 struct Client *acptr;
231 if(acptr = findNUser(parv[1]))
232 mode_a_join(acptr,parv[3],strtoul(parv[4], 0, 10));
233 } else if(strcmp("JAR", parv[2]) == 0 && parc > 2) {
234 struct Client *acptr;
235 struct Channel *chptr;
236 if(acptr = findNUser(parv[1])) {
237 if(IsChannelName(parv[3]) && strIsIrcCh(parv[3]) &&
238 (chptr = FindChannel(parv[3])) && chptr->mode.altchan &&
239 IsChannelName(chptr->mode.altchan) && strIsIrcCh(chptr->mode.altchan))
240 mode_a_check_altchan(acptr,chptr->mode.altchan);
241 send_reply(acptr, ERR_JOINACCESS, parv[3], feature_str(FEAT_ERR_JOINACCESS));
243 } else if(strcmp("KC", parv[2]) == 0 && parc > 2) {
244 struct Client *acptr;
245 if(acptr = findNUser(parv[1])) {
251 set_user_mode(sptr, acptr, 4, args, ALLOWMODES_ANY);