Make realname Kill blocks more predictable, and add username="x" field.
[ircu2.10.12-pk.git] / ircd / s_err.c
index 4daadd77d2247e1d3fb7352b0cc54774b1b2d0d1..4b03b3ddffd5b75262f40900aeee929dc0da8ae1 100644 (file)
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
  */
+/** @file
+ * @brief Error handling support.
+ * @version $Id$
+ */
+#include "config.h"
+
 #include "numeric.h"
+#include "ircd_log.h"
 #include "s_debug.h"
-#include "sprintf_irc.h"
 
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
 #include <string.h>
 
+/** Array of Numeric replies, indexed by numeric. */
 static Numeric replyTable[] = {
 /* 000 */
   { 0 },
 /* 001 */
-  { RPL_WELCOME, ":Welcome to the Internet Relay Network %s", "001" },
+  { RPL_WELCOME, ":Welcome to the %s IRC Network%s%s, %s", "001" },
 /* 002 */
   { RPL_YOURHOST, ":Your host is %s, running version %s", "002" },
 /* 003 */
   { RPL_CREATED, ":This server was created %s", "003" },
 /* 004 */
-  { RPL_MYINFO, "%s %s dioswkg biklmnopstv", "004" },
+  { RPL_MYINFO, "%s %s %s %s %s", "004" },
 /* 005 */
   { RPL_ISUPPORT, "%s :are supported by this server", "005" },
 /* 006 */
@@ -45,13 +50,9 @@ static Numeric replyTable[] = {
 /* 008 */
   { RPL_SNOMASK, "%d :: Server notice mask (%#x)", "008" },
 /* 009 */
-  { RPL_STATMEMTOT, "%u %u :Bytes Blocks", "009" },
+  { 0 },
 /* 010 */
-#ifdef MEMSIZESTATS
-  { RPL_STATMEM, "%u %u %s %u", "010" },
-#else
-  { RPL_STATMEM, "%u %u %s", "010" },
-#endif
+  { 0 },
 /* 011 */
   { 0 },
 /* 012 */
@@ -91,11 +92,11 @@ static Numeric replyTable[] = {
 /* 029 */
   { 0 },
 /* 030 */
-  { 0 },
+  { RPL_APASSWARN_SET, ":Channel Admin password (+A) set to '%s'.  Are you SURE you want to use this as Admin password? You will NOT be able to change this password anymore once the channel is more than 48 hours old!", "030" },
 /* 031 */
-  { 0 },
+  { RPL_APASSWARN_SECRET, ":Use \"/MODE %s -A %s\" to remove the password and then immediately set a new one.  IMPORTANT: YOU CANNOT RECOVER THIS PASSWORD, EVER; WRITE THE PASSWORD DOWN (don't store this rescue password on disk)! Now set the channel user password (+U).", "031" },
 /* 032 */
-  { 0 },
+  { RPL_APASSWARN_CLEAR, ":WARNING: You removed the channel Admin password (+A). If you disconnect or leave the channel without setting a new password then you will not be able to set it again!  SET A NEW PASSWORD NOW!", "032" },
 /* 033 */
   { 0 },
 /* 034 */
@@ -431,29 +432,25 @@ static Numeric replyTable[] = {
 /* 199 */
   { 0 },
 /* 200 */
-#ifndef GODMODE
-  { RPL_TRACELINK, "Link %s%s %s %s", "200" },
-#else /* GODMODE */
-  { RPL_TRACELINK, "Link %s%s %s %s " TIME_T_FMT, "200" },
-#endif /* GODMODE */
+  { RPL_TRACELINK, "Link %s.%s %s %s", "200" },
 /* 201 */
-  { RPL_TRACECONNECTING, "Try. %d %s", "201" },
+  { RPL_TRACECONNECTING, "Try. %s %s", "201" },
 /* 202 */
-  { RPL_TRACEHANDSHAKE, "H.S. %d %s", "202" },
+  { RPL_TRACEHANDSHAKE, "H.S. %s %s", "202" },
 /* 203 */
-  { RPL_TRACEUNKNOWN, "???? %d %s", "203" },
+  { RPL_TRACEUNKNOWN, "???? %s %s", "203" },
 /* 204 */
-  { RPL_TRACEOPERATOR, "Oper %d %s %ld", "204" },
+  { RPL_TRACEOPERATOR, "Oper %s %s %ld", "204" },
 /* 205 */
-  { RPL_TRACEUSER, "User %d %s %ld", "205" },
+  { RPL_TRACEUSER, "User %s %s %ld", "205" },
 /* 206 */
-  { RPL_TRACESERVER, "Serv %d %dS %dC %s %s!%s@%s %ld %ld", "206" },
+  { RPL_TRACESERVER, "Serv %s %dS %dC %s %s!%s@%s %ld %ld", "206" },
 /* 207 */
   { 0 },
 /* 208 */
   { RPL_TRACENEWTYPE, "<newtype> 0 %s", "208" },
 /* 209 */
-  { RPL_TRACECLASS, "Class %d %d", "209" },
+  { RPL_TRACECLASS, "Class %s %d", "209" },
 /* 210 */
   { 0 },
 /* 211 */
@@ -461,25 +458,25 @@ static Numeric replyTable[] = {
 /* 212 */
   { RPL_STATSCOMMANDS, "%s %u %u", "212" },
 /* 213 */
-  { RPL_STATSCLINE, "%c %s * %s %d %d", "213" },
+  { RPL_STATSCLINE, "C %s %s%s %d %d %s %s", "213" },
 /* 214 */
-  { RPL_STATSNLINE, "%c %s * %s %d %d", "214" },
+  { 0 },
 /* 215 */
-  { RPL_STATSILINE, "%c %s * %s %d %d", "215" },
+  { RPL_STATSILINE, "I %s %d %s%s %d %s", "215" },
 /* 216 */
-  { RPL_STATSKLINE, "%c %s \"%s\" %s 0 0", "216" },
+  { RPL_STATSKLINE, "%c %s@%s \"%s\" \"%s\" 0 0", "216" },
 /* 217 */
   { RPL_STATSPLINE, "P %d %d %s %s", "217" },
 /* 218 */
-  { RPL_STATSYLINE, "%c %d %d %d %d %ld %d", "218" },
+  { RPL_STATSYLINE, "%c %s %d %d %d %ld %d", "218" },
 /* 219 */
-  { RPL_ENDOFSTATS, "%c :End of /STATS report", "219" },
+  { RPL_ENDOFSTATS, "%s :End of /STATS report", "219" },
 /* 220 */
   { 0 },
 /* 221 */
   { RPL_UMODEIS, "%s", "221" },
 /* 222 */
-  { 0 },
+  { RPL_STATSJLINE, "J %s", "222" },
 /* 223 */
   { 0 },
 /* 224 */
@@ -487,11 +484,11 @@ static Numeric replyTable[] = {
 /* 225 */
   { 0 },
 /* 226 */
-  { 0 },
+  { RPL_STATSALINE, "%s", "226" },
 /* 227 */
   { 0 },
 /* 228 */
-  { 0 },
+  { RPL_STATSQLINE, "Q %s :%s", "228" },
 /* 229 */
   { 0 },
 /* 230 */
@@ -507,9 +504,9 @@ static Numeric replyTable[] = {
 /* 235 */
   { RPL_SERVLISTEND, 0, "235" },
 /* 236 */
-  { 0 },
+  { RPL_STATSVERBOSE, "V :Sent as explicit", "236" },
 /* 237 */
-  { 0 },
+  { RPL_STATSENGINE, "%s :Event loop engine", "237" },
 /* 238 */
   { RPL_STATSFLINE, "%c %s %s", "238" },
 /* 239 */
@@ -517,21 +514,21 @@ static Numeric replyTable[] = {
 /* 240 */
   { 0 },
 /* 241 */
-  { RPL_STATSLLINE, "%c %s * %s %d %d", "241" },
+  { RPL_STATSLLINE, "Module Description EntryPoint", "241" },
 /* 242 */
   { RPL_STATSUPTIME, ":Server Up %d days, %d:%02d:%02d", "242" },
 /* 243 */
-  { RPL_STATSOLINE, "%c %s * %s %d %d", "243" },
+  { RPL_STATSOLINE, "O %s@%s * %s %s", "243" },
 /* 244 */
-  { RPL_STATSHLINE, "%c %s * %s %d %d", "244" },
+  { 0 },
 /* 245 */
   { 0 },
 /* 246 */
   { RPL_STATSTLINE, "%c %s %s", "246" },
 /* 247 */
-  { RPL_STATSGLINE, "%c %s@%s " TIME_T_FMT " :%s", "247" },
+  { RPL_STATSGLINE, "%c %s%s%s %Tu :%s", "247" },
 /* 248 */
-  { RPL_STATSULINE, "%c %s %s %s %d %d", "248" },
+  { RPL_STATSULINE, "U %s", "248" },
 /* 249 */
   { RPL_STATSDEBUG, 0, "249" },
 /* 250 */
@@ -559,7 +556,7 @@ static Numeric replyTable[] = {
 /* 261 */
   { RPL_TRACELOG, "File %s %d", "261" },
 /* 262 */
-  { RPL_TRACEPING, "Ping %s %s", "262" },
+  { RPL_TRACEEND, ":End of TRACE", "262" },
 /* 263 */
   { 0 },
 /* 264 */
@@ -575,9 +572,9 @@ static Numeric replyTable[] = {
 /* 269 */
   { 0 },
 /* 270 */
-  { 0 },
+  { RPL_PRIVS, "%s :", "270" },
 /* 271 */
-  { RPL_SILELIST, "%s %s", "271" },
+  { RPL_SILELIST, "%s %s%s", "271" },
 /* 272 */
   { RPL_ENDOFSILELIST, "%s :End of Silence List", "272" },
 /* 273 */
@@ -587,7 +584,7 @@ static Numeric replyTable[] = {
 /* 275 */
   { RPL_STATSDLINE, "%c %s %s", "275" },
 /* 276 */
-  { 0 },
+  { RPL_STATSRLINE, "%-9s %-9s %-10s %s", "276" },
 /* 277 */
   { 0 },
 /* 278 */
@@ -595,11 +592,11 @@ static Numeric replyTable[] = {
 /* 279 */
   { 0 },
 /* 280 */
-  { RPL_GLIST, "%s%s%s " TIME_T_FMT " %s %c :%s", "280" },
+  { RPL_GLIST, "%s%s%s %Tu %s %c :%s", "280" },
 /* 281 */
   { RPL_ENDOFGLIST, ":End of G-line List", "281" },
 /* 282 */
-  { RPL_JUPELIST, "%s " TIME_T_FMT " %s %c :%s", "282" },
+  { RPL_JUPELIST, "%s %Tu %s %c :%s", "282" },
 /* 283 */
   { RPL_ENDOFJUPELIST, ":End of Jupe List", "283" },
 /* 284 */
@@ -649,7 +646,7 @@ static Numeric replyTable[] = {
 /* 306 */
   { RPL_NOWAWAY, ":You have been marked as being away", "306" },
 /* 307 */
-  { RPL_USERIP, ":", "307" },
+  { 0 },
 /* 308 */
   { 0 },
 /* 309 */
@@ -693,15 +690,15 @@ static Numeric replyTable[] = {
 /* 328 */
   { 0 },
 /* 329 */
-  { RPL_CREATIONTIME, "%s " TIME_T_FMT, "329" },
+  { RPL_CREATIONTIME, "%s %Tu", "329" },
 /* 330 */
-  { 0 },
+  { RPL_WHOISACCOUNT, "%s %s :is logged in as", "330" },
 /* 331 */
   { RPL_NOTOPIC, "%s :No topic is set.", "331" },
 /* 332 */
   { RPL_TOPIC, "%s :%s", "332" },
 /* 333 */
-  { RPL_TOPICWHOTIME, "%s %s " TIME_T_FMT, "333" },
+  { RPL_TOPICWHOTIME, "%s %s %Tu", "333" },
 /* 334 */
   { RPL_LISTUSAGE, ":%s", "334" },
 /* 335 */
@@ -711,11 +708,11 @@ static Numeric replyTable[] = {
 /* 337 */
   { 0 },
 /* 338 */
-  { 0 },
+  { RPL_WHOISACTUALLY, "%s %s@%s %s :Actual user@host, Actual IP", "338" },
 /* 339 */
   { 0 },
 /* 340 */
-  { 0 },
+  { RPL_USERIP, ":", "340" },
 /* 341 */
   { RPL_INVITING, "%s %s", "341" },
 /* 342 */
@@ -725,7 +722,7 @@ static Numeric replyTable[] = {
 /* 344 */
   { 0 },
 /* 345 */
-  { 0 },
+  { RPL_ISSUEDINVITE, "%s %s %s :%s has been invited by %s", "345" },
 /* 346 */
   { RPL_INVITELIST, ":%s", "346" },
 /* 347 */
@@ -745,7 +742,7 @@ static Numeric replyTable[] = {
 /* 354 */
   { RPL_WHOSPCRPL, "%s", "354" },
 /* 355 */
-  { 0 },
+  { RPL_DELNAMREPLY, "%s", "355" },
 /* 356 */
   { 0 },
 /* 357 */
@@ -763,17 +760,13 @@ static Numeric replyTable[] = {
 /* 363 */
   { RPL_CLOSEEND, "%d :Connections Closed", "363" },
 /* 364 */
-#ifndef GODMODE
   { RPL_LINKS, "%s %s :%d P%u %s", "364" },
-#else /* GODMODE */
-  { RPL_LINKS, "%s %s :%d P%u " TIME_T_FMT " (%s) %s", "364" },
-#endif /* GODMODE */
 /* 365 */
   { RPL_ENDOFLINKS, "%s :End of /LINKS list.", "365" },
 /* 366 */
   { RPL_ENDOFNAMES, "%s :End of /NAMES list.", "366" },
 /* 367 */
-  { RPL_BANLIST, "%s %s %s " TIME_T_FMT, "367" },
+  { RPL_BANLIST, "%s %s %s %Tu", "367" },
 /* 368 */
   { RPL_ENDOFBANLIST, "%s :End of Channel Ban List", "368" },
 /* 369 */
@@ -821,7 +814,7 @@ static Numeric replyTable[] = {
 /* 390 */
   { 0 },
 /* 391 */
-  { RPL_TIME, "%s " TIME_T_FMT " %ld :%s", "391" },
+  { RPL_TIME, "%s %Tu %ld :%s", "391" },
 /* 392 */
   { 0 },
 /* 393 */
@@ -831,7 +824,7 @@ static Numeric replyTable[] = {
 /* 395 */
   { 0 },
 /* 396 */
-  { 0 },
+  { RPL_HOSTHIDDEN, "%s :is now your hidden host", "396" },
 /* 397 */
   { 0 },
 /* 398 */
@@ -859,7 +852,7 @@ static Numeric replyTable[] = {
 /* 409 */
   { ERR_NOORIGIN, ":No origin specified", "409" },
 /* 410 */
-  { 0 },
+  { ERR_UNKNOWNCAPCMD, "%s :Unknown CAP subcommand", "410" },
 /* 411 */
   { ERR_NORECIPIENT, ":No recipient given (%s)", "411" },
 /* 412 */
@@ -913,13 +906,13 @@ static Numeric replyTable[] = {
 /* 436 */
   { ERR_NICKCOLLISION, "%s :Nickname collision KILL", "436" },
 /* 437 */
-  { ERR_BANNICKCHANGE, "%s :Cannot change nickname while banned on channel", "437" },
+  { ERR_BANNICKCHANGE, "%s :Cannot change nickname while banned on channel or channel is moderated", "437" },
 /* 438 */
   { ERR_NICKTOOFAST, "%s :Nick change too fast. Please wait %d seconds.", "438" },
 /* 439 */
   { ERR_TARGETTOOFAST, "%s :Target change too fast. Please wait %d seconds.", "439" },
 /* 440 */
-  { 0 },
+  { ERR_SERVICESDOWN, "%s :Services are currently unavailable.", "440" },
 /* 441 */
   { ERR_USERNOTINCHANNEL, "%s %s :They aren't on that channel", "441" },
 /* 442 */
@@ -993,7 +986,7 @@ static Numeric replyTable[] = {
 /* 476 */
   { ERR_BADCHANMASK, "%s :Bad Channel Mask", "476" },
 /* 477 */
-  { 0 },
+  { ERR_NEEDREGGEDNICK, "%s :Cannot join channel (+r)", "477" },
 /* 478 */
   { ERR_BANLISTFULL, "%s %s :Channel ban/ignore list is full", "478" },
 /* 479 */
@@ -1001,13 +994,13 @@ static Numeric replyTable[] = {
 /* 480 */
   { 0 },
 /* 481 */
-  { ERR_NOPRIVILEGES, ":Permission Denied: You're not an IRC operator", "481" },
+  { ERR_NOPRIVILEGES, ":Permission Denied: Insufficient privileges", "481" },
 /* 482 */
   { ERR_CHANOPRIVSNEEDED, "%s :You're not channel operator", "482" },
 /* 483 */
   { ERR_CANTKILLSERVER, ":You cant kill a server!", "483" },
 /* 484 */
-  { ERR_ISCHANSERVICE, "%s %s :Cannot kill, kick or deop channel service", "484" },
+  { ERR_ISCHANSERVICE, "%s %s :Cannot kill, kick or deop a network service", "484" },
 /* 485 */
   { 0 },
 /* 486 */
@@ -1027,13 +1020,13 @@ static Numeric replyTable[] = {
 /* 493 */
   { ERR_NOFEATURE, "%s :No such feature", "493" },
 /* 494 */
-  { ERR_BADLOGTYPE, "%s :No such log type", "494" },
+  { ERR_BADFEATVALUE, "%s :Bad value for feature %s", "494" },
 /* 495 */
-  { ERR_BADLOGSYS, "%s :No such log subsystem", "495" },
+  { ERR_BADLOGTYPE, "%s :No such log type", "495" },
 /* 496 */
-  { ERR_BADLOGVALUE, "%s :Bad value for log type", "496" },
+  { ERR_BADLOGSYS, "%s :No such log subsystem", "496" },
 /* 497 */
-  { 0 },
+  { ERR_BADLOGVALUE, "%s :Bad value for log type", "497" },
 /* 498 */
   { ERR_ISOPERLCHAN, "%s %s :Cannot kick or deop an IRC Operator on a local channel", "498" },
 /* 499 */
@@ -1041,7 +1034,7 @@ static Numeric replyTable[] = {
 /* 500 */
   { 0 },
 /* 501 */
-  { ERR_UMODEUNKNOWNFLAG, ":Unknown MODE flag", "501" },
+  { ERR_UMODEUNKNOWNFLAG, "%c :Unknown user MODE flag", "501" },
 /* 502 */
   { ERR_USERSDONTMATCH, ":Cant change mode for other users", "502" },
 /* 503 */
@@ -1069,17 +1062,17 @@ static Numeric replyTable[] = {
 /* 514 */
   { ERR_NOSUCHJUPE, "%s :No such jupe", "514" },
 /* 515 */
-  { ERR_BADEXPIRE, TIME_T_FMT " :Bad expire time", "515" },
+  { ERR_BADEXPIRE, "%Tu :Bad expire time", "515" },
 /* 516 */
   { ERR_DONTCHEAT, " :Don't Cheat.", "516" },
 /* 517 */
   { ERR_DISABLED, "%s :Command disabled.", "517" },
 /* 518 */
-  { 0 },
+  { ERR_LONGMASK, " :Mask is too long", "518" },
 /* 519 */
-  { 0 },
+  { ERR_TOOMANYUSERS, "%d :Too many users affected by mask", "519" },
 /* 520 */
-  { 0 },
+  { ERR_MASKTOOWIDE, "%s :Mask is too wide", "520" },
 /* 521 */
   { 0 },
 /* 522 */
@@ -1087,7 +1080,7 @@ static Numeric replyTable[] = {
 /* 523 */
   { 0 },
 /* 524 */
-  { 0 },
+  { ERR_QUARANTINED, "%s :Channel is quarantined : %s", "524" },
 /* 525 */
   { 0 },
 /* 526 */
@@ -1139,19 +1132,19 @@ static Numeric replyTable[] = {
 /* 549 */
   { 0 },
 /* 550 */
-  { 0 },
+  { ERR_NOTLOWEROPLEVEL, "%s %s %hu %hu :Cannot %s someone with %s op-level", "550" },
 /* 551 */
-  { 0 },
+  { ERR_NOTMANAGER, "%s :You must be channel Admin to add or remove a password. Use /JOIN %s <AdminPass>.", "551" },
 /* 552 */
-  { 0 },
+  { ERR_CHANSECURED, "%s :Channel is older than 48 hours and secured. Cannot change Admin pass anymore", "552" },
 /* 553 */
-  { 0 },
+  { ERR_UPASSSET, "%s :Cannot remove Admin pass (+A) while User pass (+U) is still set.  First use /MODE %s -U <userpass>", "553" },
 /* 554 */
-  { 0 },
+  { ERR_UPASSNOTSET, "%s :Cannot set user pass (+U) until Admin pass (+A) is set.  First use /MODE %s +A <adminpass>", "554" },
 /* 555 */
-  { 0 },
+  { ERR_NOMANAGER_LONG, "%s :Re-create the channel.  The channel must be *empty* for 48 continuous hours before it can be recreated.", "555" },
 /* 556 */
-  { 0 },
+  { ERR_NOMANAGER_SHORT, "%s :Re-create the channel.  The channel must be *empty* for a minute or two before it can be recreated.", "556" },
 /* 557 */
   { 0 },
 /* 558 */
@@ -1240,6 +1233,10 @@ static Numeric replyTable[] = {
   { 0 }
 };
 
+/** Return a pointer to the Numeric for a particular code.
+ * @param n %Numeric to look up.
+ * @return Numeric structure.
+ */
 const struct Numeric* get_error_numeric(int n)
 {
   assert(0 < n);
@@ -1249,37 +1246,13 @@ const struct Numeric* get_error_numeric(int n)
   return &replyTable[n];
 }
 
-static char numbuff[512];
-
-/* "inline" */
-#define prepbuf(buffer, num, tail)                      \
-{                                                       \
-  char *s = buffer + 4;                 \
-  const char *ap = atoi_tab + (num << 2);       \
-                                                        \
-  strcpy(buffer, ":%s 000 %s ");                        \
-  *s++ = *ap++;                                         \
-  *s++ = *ap++;                                         \
-  *s = *ap;                                             \
-  strcpy(s + 5, tail);                                  \
-}
-
-char* err_str(int n)
-{
-  Numeric* p;
-
-  assert(0 < n);
-  assert(n < ERR_LASTERROR);
-  assert(0 != replyTable[n].value);
-
-  p = &replyTable[n];
-  prepbuf(numbuff, p->value, p->format);
-
-  return numbuff;
-}
-
+/** Return a format string for a numeric response.
+ * @param n %Numeric to look up.
+ * @return Pointer to a static buffer containing the format string.
+ */
 char* rpl_str(int n)
 {
+  static char numbuff[512];
   Numeric* p;
 
   assert(0 < n);
@@ -1287,7 +1260,13 @@ char* rpl_str(int n)
   assert(0 != replyTable[n].value);
 
   p = &replyTable[n];
-  prepbuf(numbuff, p->value, p->format);
+  strcpy(numbuff, ":%s 000 %s ");
+  if (p->str) {
+    numbuff[4] = p->str[0];
+    numbuff[5] = p->str[1];
+    numbuff[6] = p->str[2];
+    strcpy(numbuff + 11, p->format);
+  }
 
   return numbuff;
 }