]>
Commit | Line | Data |
---|---|---|
189935b1 | 1 | /* |
2 | * IRC - Internet Relay Chat, ircd/m_pseudo.c | |
3 | * Copyright (C) 2002 - 2003 Zoot <zoot@gamesurge.net> | |
4 | * | |
5 | * See file AUTHORS in IRC package for additional names of | |
6 | * the programmers. | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 1, or (at your option) | |
11 | * any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | * | |
22 | * $Id: m_pseudo.c,v 1.2 2004/12/11 05:13:48 klmitch Exp $ | |
23 | */ | |
24 | ||
25 | /* | |
26 | * m_functions execute protocol messages on this server: | |
27 | * | |
28 | * cptr is always NON-NULL, pointing to a *LOCAL* client | |
29 | * structure (with an open socket connected!). This | |
30 | * identifies the physical socket where the message | |
31 | * originated (or which caused the m_function to be | |
32 | * executed--some m_functions may call others...). | |
33 | * | |
34 | * sptr is the source of the message, defined by the | |
35 | * prefix part of the message if present. If not | |
36 | * or prefix not found, then sptr==cptr. | |
37 | * | |
38 | * (!IsServer(cptr)) => (cptr == sptr), because | |
39 | * prefixes are taken *only* from servers... | |
40 | * | |
41 | * (IsServer(cptr)) | |
42 | * (sptr == cptr) => the message didn't | |
43 | * have the prefix. | |
44 | * | |
45 | * (sptr != cptr && IsServer(sptr) means | |
46 | * the prefix specified servername. (?) | |
47 | * | |
48 | * (sptr != cptr && !IsServer(sptr) means | |
49 | * that message originated from a remote | |
50 | * user (not local). | |
51 | * | |
52 | * combining | |
53 | * | |
54 | * (!IsServer(sptr)) means that, sptr can safely | |
55 | * taken as defining the target structure of the | |
56 | * message in this server. | |
57 | * | |
58 | * *Always* true (if 'parse' and others are working correct): | |
59 | * | |
60 | * 1) sptr->from == cptr (note: cptr->from == cptr) | |
61 | * | |
62 | * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr | |
63 | * *cannot* be a local connection, unless it's | |
64 | * actually cptr!). [MyConnect(x) should probably | |
65 | * be defined as (x == x->from) --msa ] | |
66 | * | |
67 | * parc number of variable parameter strings (if zero, | |
68 | * parv is allowed to be NULL) | |
69 | * | |
70 | * parv a NULL terminated list of parameter pointers, | |
71 | * | |
72 | * parv[0], sender (prefix string), if not present | |
73 | * this points to an empty string. | |
74 | * parv[1], pointer to "extra" data (service mapping) | |
75 | * parv[2]...parv[parc-1] | |
76 | * pointers to additional parameters | |
77 | * parv[parc] == NULL, *always* | |
78 | * | |
79 | * note: it is guaranteed that parv[0]..parv[parc-1] are all | |
80 | * non-NULL pointers. | |
81 | */ | |
82 | #include "config.h" | |
83 | ||
84 | #include "client.h" | |
85 | #include "hash.h" | |
86 | #include "ircd.h" | |
87 | #include "ircd_features.h" | |
88 | #include "ircd_log.h" | |
89 | #include "ircd_relay.h" | |
90 | #include "ircd_reply.h" | |
91 | #include "ircd_string.h" | |
92 | #include "ircd_snprintf.h" | |
93 | #include "msg.h" | |
94 | #include "numeric.h" | |
95 | #include "numnicks.h" | |
96 | #include "s_conf.h" | |
97 | #include "s_user.h" | |
98 | ||
99 | /* #include <assert.h> -- Now using assert in ircd_log.h */ | |
100 | ||
101 | /* | |
102 | * m_pseudo - generic service message handler | |
103 | * | |
104 | * parv[0] = sender prefix | |
105 | * parv[1] = service mapping (s_map * disguised as char *) | |
106 | * parv[2] = message | |
107 | */ | |
108 | int m_pseudo(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) | |
109 | { | |
110 | char *text, buffer[BUFSIZE]; | |
111 | struct s_map *map; | |
112 | struct nick_host *nh; | |
113 | ||
114 | assert(0 != cptr); | |
115 | assert(cptr == sptr); | |
116 | assert(0 != cli_user(sptr)); | |
117 | ||
118 | /* By default, relay the message straight through. */ | |
119 | text = parv[parc - 1]; | |
120 | ||
121 | if (parc < 3 || EmptyString(text)) | |
122 | return send_reply(sptr, ERR_NOTEXTTOSEND); | |
123 | ||
124 | /* HACK! HACK! HACK! HACK! Yes. It's icky, but | |
125 | * it's the only way. */ | |
126 | map = (struct s_map *)parv[1]; | |
127 | assert(0 != map); | |
128 | ||
129 | if (map->prepend) { | |
130 | ircd_snprintf(0, buffer, sizeof(buffer) - 1, "%s%s", map->prepend, text); | |
131 | buffer[sizeof(buffer) - 1] = 0; | |
132 | text = buffer; | |
133 | } | |
134 | ||
135 | for (nh = map->services; nh; nh = nh->next) { | |
136 | struct Client *target, *server; | |
137 | ||
138 | if (NULL == (server = FindServer(nh->nick + nh->nicklen + 1))) | |
139 | continue; | |
140 | nh->nick[nh->nicklen] = '\0'; | |
141 | if ((NULL == (target = FindUser(nh->nick))) | |
142 | || (server != cli_user(target)->server)) | |
143 | continue; | |
144 | nh->nick[nh->nicklen] = '@'; | |
145 | relay_directed_message(sptr, nh->nick, nh->nick + nh->nicklen, text); | |
146 | return 0; | |
147 | } | |
148 | ||
149 | return send_reply(sptr, ERR_SERVICESDOWN, map->name); | |
150 | } |