]>
Commit | Line | Data |
---|---|---|
1 | /* miscreply.c */ | |
2 | ||
3 | #include "miscreply.h" | |
4 | #include "../core/error.h" | |
5 | #include "../core/config.h" | |
6 | #include "../irc/irc.h" | |
7 | #include "../lib/irc_string.h" | |
8 | #include "../lib/version.h" | |
9 | #include "../nick/nick.h" | |
10 | ||
11 | #include <stdarg.h> | |
12 | #include <stdio.h> | |
13 | #include <string.h> | |
14 | ||
15 | /* module version */ | |
16 | MODULE_VERSION(MISCREPLY_VERSION); | |
17 | ||
18 | ||
19 | ||
20 | /* | |
21 | * This module handles the following remote IRC commands | |
22 | * | |
23 | * ADMIN | |
24 | * PRIVS | |
25 | * RPING | |
26 | * RPONG | |
27 | * STATS | |
28 | * TRACE | |
29 | * TIME | |
30 | * VERSION | |
31 | * WHOIS | |
32 | * | |
33 | */ | |
34 | ||
35 | ||
36 | ||
37 | /* admin info */ | |
38 | sstring *admin1; | |
39 | sstring *admin2; | |
40 | sstring *admin3; | |
41 | ||
42 | ||
43 | ||
44 | /* init */ | |
45 | void _init() { | |
46 | ||
47 | /* get the admin info from the config | |
48 | * mix in some references to Quake and Doom in the defaults | |
49 | */ | |
50 | admin1 = getcopyconfigitem("miscreply", "admin1", "Located at the Union Aerospace Corp. facility, Stroggos", BUFSIZE); | |
51 | admin2 = getcopyconfigitem("miscreply", "admin2", "Network IRC Service", BUFSIZE); | |
52 | admin3 = getcopyconfigitem("miscreply", "admin3", "No administrative info available", BUFSIZE); | |
53 | ||
54 | /* add server handlers */ | |
55 | registerserverhandler("AD", &handleadminmsg, 1); /* ADMIN */ | |
56 | registerserverhandler("PR", &handleprivsmsg, 1); /* PRIVS */ | |
57 | registerserverhandler("RI", &handlerpingmsg, 3); /* RPING */ | |
58 | registerserverhandler("RO", &handlerpongmsg, 4); /* RPONG */ | |
59 | registerserverhandler("R", &handlestatsmsg, 2); /* STATS */ | |
60 | registerserverhandler("TI", &handletimemsg, 1); /* TIME */ | |
61 | registerserverhandler("TR", &handletracemsg, 2); /* TRACE */ | |
62 | registerserverhandler("V", &handleversionmsg, 1); /* VERSION */ | |
63 | registerserverhandler("W", &handlewhoismsg, 2); /* WHOIS */ | |
64 | ||
65 | } | |
66 | ||
67 | ||
68 | ||
69 | /* fini */ | |
70 | void _fini() { | |
71 | ||
72 | /* remove server handlers */ | |
73 | deregisterserverhandler("AD", &handleadminmsg); /* ADMIN */ | |
74 | deregisterserverhandler("PR", &handleprivsmsg); /* PRIVS */ | |
75 | deregisterserverhandler("RI", &handlerpingmsg); /* RPING */ | |
76 | deregisterserverhandler("RO", &handlerpongmsg); /* RPONG */ | |
77 | deregisterserverhandler("R", &handlestatsmsg); /* STATS */ | |
78 | deregisterserverhandler("TI", &handletimemsg); /* TIME */ | |
79 | deregisterserverhandler("TR", &handletracemsg); /* TRACE */ | |
80 | deregisterserverhandler("V", &handleversionmsg); /* VERSION */ | |
81 | deregisterserverhandler("W", &handlewhoismsg); /* WHOIS */ | |
82 | ||
83 | } | |
84 | ||
85 | ||
86 | ||
87 | /* from_server | |
88 | * if valid server numeric return 1 | |
89 | * else return 0 and log error | |
90 | */ | |
91 | static int from_server(char *sourcenum, char *command) { | |
92 | ||
93 | /* valid server numeric */ | |
94 | if (strlen(sourcenum) == 2) | |
95 | return 1; | |
96 | ||
97 | Error("miscreply", ERR_WARNING, "Received %s request from non-server numeric %s", command, sourcenum); | |
98 | return 0; | |
99 | } | |
100 | ||
101 | ||
102 | ||
103 | /* from_user | |
104 | * if valid user numeric return 1 | |
105 | * else return 0 and log error | |
106 | */ | |
107 | static int from_user(char *sourcenum, char *command) { | |
108 | ||
109 | /* valid user numeric */ | |
110 | if (strlen(sourcenum) == 5) | |
111 | return 1; | |
112 | ||
113 | Error("miscreply", ERR_WARNING, "Received %s request from non-user numeric %s", command, sourcenum); | |
114 | return 0; | |
115 | } | |
116 | ||
117 | ||
118 | ||
119 | /* needmoreparams | |
120 | * reply error to source user | |
121 | * log error | |
122 | */ | |
123 | void miscreply_needmoreparams(char *sourcenum, char *command) { | |
124 | /* | |
125 | * 461 ERR_NEEDMOREPARAMS "source 461 target command :Not enough parameters" | |
126 | * "irc.netsplit.net 461 foobar JOIN :Not enough parameters" | |
127 | */ | |
128 | irc_send("%s 461 %s %s :Not enough parameters", getmynumeric(), sourcenum, command); | |
129 | Error("miscreply", ERR_WARNING, "Received %s request without enough parameters from %s", command, sourcenum); | |
130 | } | |
131 | ||
132 | ||
133 | ||
134 | /* findserver | |
135 | * if found return server longnumeric | |
136 | * else return -1 and log error | |
137 | */ | |
138 | long miscreply_findserver(char *sourcenum, char *command) { | |
139 | long i = numerictolong(sourcenum, 2); | |
140 | ||
141 | /* check source is a valid server numeric */ | |
142 | if (!from_server(sourcenum, command)) | |
143 | return -1; | |
144 | ||
145 | if (serverlist[i].linkstate != LS_INVALID) | |
146 | return i; | |
147 | ||
148 | Error("miscreply", ERR_WARNING, "Received %s request from unknown server numeric %s", command, sourcenum); | |
149 | return -1; | |
150 | } | |
151 | ||
152 | ||
153 | ||
154 | /* findservermatch | |
155 | * if found return server longnumeric | |
156 | * else return -1 and reply error to source user | |
157 | */ | |
158 | long miscreply_findservermatch(char *sourcenum, char *servermask) { | |
159 | long i; | |
160 | ||
161 | /* go over all servers */ | |
162 | for (i = 0; i < MAXSERVERS; i++) { | |
163 | if (serverlist[i].linkstate == LS_INVALID) /* not linked */ | |
164 | continue; | |
165 | if (!match2strings(servermask, serverlist[i].name->content)) /* no match */ | |
166 | continue; | |
167 | return i; | |
168 | } | |
169 | ||
170 | /* | |
171 | * 402 RPL_NOSUCHSERVER "source 402 target server :No such server" | |
172 | * "irc.netsplit.net 402 foobar hub* :No such server" | |
173 | */ | |
174 | irc_send("%s 402 %s %s :No such server", getmynumeric(), sourcenum, servermask); | |
175 | ||
176 | return -1; | |
177 | } | |
178 | ||
179 | ||
180 | ||
181 | /* finduser | |
182 | * if found return nick for source numeric | |
183 | * else return NULL and log error | |
184 | */ | |
185 | nick *miscreply_finduser(char *sourcenum, char *command) { | |
186 | nick *nick; | |
187 | ||
188 | /* check source is a valid user numeric */ | |
189 | if (!from_user(sourcenum, command)) | |
190 | return NULL; | |
191 | ||
192 | if ((nick = getnickbynumericstr(sourcenum))) | |
193 | return nick; | |
194 | ||
195 | Error("miscreply", ERR_WARNING, "Received %s request from unknown user numeric %s", command, sourcenum); | |
196 | return NULL; | |
197 | } |