]>
jfr.im git - irc/quakenet/newserv.git/blob - miscreply/miscreply.c
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"
16 MODULE_VERSION(MISCREPLY_VERSION
);
21 * This module handles the following remote IRC commands
47 /* get the admin info from the config
48 * mix in some references to Quake and Doom in the defaults
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
);
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 */
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 */
88 * if valid server numeric return 1
89 * else return 0 and log error
91 static int from_server(char *sourcenum
, char *command
) {
93 /* valid server numeric */
94 if (strlen(sourcenum
) == 2)
97 Error("miscreply", ERR_WARNING
, "Received %s request from non-server numeric %s", command
, sourcenum
);
104 * if valid user numeric return 1
105 * else return 0 and log error
107 static int from_user(char *sourcenum
, char *command
) {
109 /* valid user numeric */
110 if (strlen(sourcenum
) == 5)
113 Error("miscreply", ERR_WARNING
, "Received %s request from non-user numeric %s", command
, sourcenum
);
120 * reply error to source user
123 void miscreply_needmoreparams(char *sourcenum
, char *command
) {
125 * 461 ERR_NEEDMOREPARAMS "source 461 target command :Not enough parameters"
126 * "irc.netsplit.net 461 foobar JOIN :Not enough parameters"
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
);
135 * if found return server longnumeric
136 * else return -1 and log error
138 long miscreply_findserver(char *sourcenum
, char *command
) {
139 long i
= numerictolong(sourcenum
, 2);
141 /* check source is a valid server numeric */
142 if (!from_server(sourcenum
, command
))
145 if (serverlist
[i
].linkstate
!= LS_INVALID
)
148 Error("miscreply", ERR_WARNING
, "Received %s request from unknown server numeric %s", command
, sourcenum
);
155 * if found return server longnumeric
156 * else return -1 and reply error to source user
158 long miscreply_findservermatch(char *sourcenum
, char *servermask
) {
161 /* go over all servers */
162 for (i
= 0; i
< MAXSERVERS
; i
++) {
163 if (serverlist
[i
].linkstate
== LS_INVALID
) /* not linked */
165 if (!match2strings(servermask
, serverlist
[i
].name
->content
)) /* no match */
171 * 402 RPL_NOSUCHSERVER "source 402 target server :No such server"
172 * "irc.netsplit.net 402 foobar hub* :No such server"
174 irc_send("%s 402 %s %s :No such server", getmynumeric(), sourcenum
, servermask
);
182 * if found return nick for source numeric
183 * else return NULL and log error
185 nick
*miscreply_finduser(char *sourcenum
, char *command
) {
188 /* check source is a valid user numeric */
189 if (!from_user(sourcenum
, command
))
192 if ((nick
= getnickbynumericstr(sourcenum
)))
195 Error("miscreply", ERR_WARNING
, "Received %s request from unknown user numeric %s", command
, sourcenum
);