]>
Commit | Line | Data |
---|---|---|
7bec4aeb | 1 | /* miscreply.c */ |
2 | ||
7bec4aeb | 3 | #include "miscreply.h" |
7bec4aeb | 4 | #include "../core/error.h" |
a7697869 | 5 | #include "../core/config.h" |
7bec4aeb | 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> | |
a7697869 | 13 | #include <string.h> |
7bec4aeb | 14 | |
15 | /* module version */ | |
a7697869 | 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 | * | |
7bec4aeb | 33 | */ |
34 | ||
35 | ||
36 | ||
a7697869 | 37 | /* admin info */ |
38 | sstring *admin1; | |
39 | sstring *admin2; | |
40 | sstring *admin3; | |
41 | ||
42 | ||
43 | ||
7bec4aeb | 44 | /* init */ |
45 | void _init() { | |
a7697869 | 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 | ||
7bec4aeb | 54 | /* add server handlers */ |
a7697869 | 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 */ | |
7bec4aeb | 64 | |
65 | } | |
66 | ||
67 | ||
68 | ||
69 | /* fini */ | |
70 | void _fini() { | |
71 | ||
72 | /* remove server handlers */ | |
a7697869 | 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) { | |
7bec4aeb | 92 | |
a7697869 | 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; | |
7bec4aeb | 115 | } |
116 | ||
117 | ||
118 | ||
119 | /* needmoreparams | |
a7697869 | 120 | * reply error to source user |
121 | * log error | |
7bec4aeb | 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 | */ | |
a7697869 | 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); | |
7bec4aeb | 130 | } |
131 | ||
132 | ||
133 | ||
134 | /* findserver | |
a7697869 | 135 | * if found return server longnumeric |
136 | * else return -1 and log error | |
7bec4aeb | 137 | */ |
a7697869 | 138 | long miscreply_findserver(char *sourcenum, char *command) { |
139 | long i = numerictolong(sourcenum, 2); | |
7bec4aeb | 140 | |
a7697869 | 141 | /* check source is a valid server numeric */ |
142 | if (!from_server(sourcenum, command)) | |
7bec4aeb | 143 | return -1; |
7bec4aeb | 144 | |
a7697869 | 145 | if (serverlist[i].linkstate != LS_INVALID) |
146 | return i; | |
7bec4aeb | 147 | |
a7697869 | 148 | Error("miscreply", ERR_WARNING, "Received %s request from unknown server numeric %s", command, sourcenum); |
149 | return -1; | |
7bec4aeb | 150 | } |
151 | ||
152 | ||
153 | ||
154 | /* findservermatch | |
a7697869 | 155 | * if found return server longnumeric |
156 | * else return -1 and reply error to source user | |
7bec4aeb | 157 | */ |
a7697869 | 158 | long miscreply_findservermatch(char *sourcenum, char *servermask) { |
159 | long i; | |
7bec4aeb | 160 | |
161 | /* go over all servers */ | |
162 | for (i = 0; i < MAXSERVERS; i++) { | |
a7697869 | 163 | if (serverlist[i].linkstate == LS_INVALID) /* not linked */ |
7bec4aeb | 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 | */ | |
a7697869 | 174 | irc_send("%s 402 %s %s :No such server", getmynumeric(), sourcenum, servermask); |
7bec4aeb | 175 | |
176 | return -1; | |
177 | } | |
178 | ||
179 | ||
180 | ||
a7697869 | 181 | /* finduser |
182 | * if found return nick for source numeric | |
183 | * else return NULL and log error | |
7bec4aeb | 184 | */ |
185 | nick *miscreply_finduser(char *sourcenum, char *command) { | |
186 | nick *nick; | |
187 | ||
a7697869 | 188 | /* check source is a valid user numeric */ |
189 | if (!from_user(sourcenum, command)) | |
190 | return NULL; | |
7bec4aeb | 191 | |
a7697869 | 192 | if ((nick = getnickbynumericstr(sourcenum))) |
193 | return nick; | |
7bec4aeb | 194 | |
a7697869 | 195 | Error("miscreply", ERR_WARNING, "Received %s request from unknown user numeric %s", command, sourcenum); |
196 | return NULL; | |
7bec4aeb | 197 | } |