home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / in4wjcxu / other / irc / ircd / s_err.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-14  |  12.3 KB  |  338 lines

  1. /************************************************************************
  2.  *   IRC - Internet Relay Chat, ircd/s_err.c
  3.  *   Copyright (C) 1992 Darren Reed
  4.  *
  5.  *   This program is free software; you can redistribute it and/or modify
  6.  *   it under the terms of the GNU General Public License as published by
  7.  *   the Free Software Foundation; either version 1, or (at your option)
  8.  *   any later version.
  9.  *
  10.  *   This program is distributed in the hope that it will be useful,
  11.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *   GNU General Public License for more details.
  14.  *
  15.  *   You should have received a copy of the GNU General Public License
  16.  *   along with this program; if not, write to the Free Software
  17.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include "struct.h"
  21. #include "numeric.h"
  22.  
  23. #ifndef lint
  24. static  char sccsid[] = "@(#)s_err.c    1.12 11/1/93 (C) 1992 Darren Reed";
  25. #endif
  26.  
  27. typedef    struct    {
  28.     int    num_val;
  29.     char    *num_form;
  30. } Numeric;
  31.  
  32. static    char    *prepbuf PROTO((char *, int, char *));
  33. static    char    numbuff[512];
  34. static    char    numbers[] = "0123456789";
  35.  
  36. static    Numeric    local_replies[] = {
  37. /* 000 */    0, (char *)NULL,
  38. /* 001 */    RPL_WELCOME, ":Welcome to the Internet Relay Network %s",
  39. /* 002 */    RPL_YOURHOST, ":Your host is %s, running version %s",
  40. /* 003 */    RPL_CREATED, ":This server was created %s",
  41. /* 004 */    RPL_MYINFO, "%s %s oiws biklmnopstv",
  42.         0, (char *)NULL
  43. };
  44.  
  45. static    Numeric    numeric_errors[] = {
  46. /* 401 */    ERR_NOSUCHNICK, "%s :No such nick/channel",
  47. /* 402 */    ERR_NOSUCHSERVER, "%s :No such server",
  48. /* 402 */    ERR_NOSUCHCHANNEL, "%s :No such channel",
  49. /* 402 */    ERR_CANNOTSENDTOCHAN, "%s :Cannot send to channel",
  50. /* 402 */    ERR_TOOMANYCHANNELS, "%s :You have joined too many channels",
  51. /* 402 */    ERR_WASNOSUCHNICK, "%s :There was no such nickname",
  52. /* 402 */    ERR_TOOMANYTARGETS,
  53.         "%s :Duplicate recipients. No message delivered",
  54. /* 402 */    ERR_NOSUCHSERVICE, (char *)NULL,
  55. /* 402 */    ERR_NOORIGIN, ":No origin specified",
  56.         0, (char *)NULL,
  57. /* 411 */    ERR_NORECIPIENT, ":No recipient given (%s)",
  58. /* 411 */    ERR_NOTEXTTOSEND, ":No text to send",
  59. /* 411 */    ERR_NOTOPLEVEL, "%s :No toplevel domain specified",
  60. /* 411 */    ERR_WILDTOPLEVEL, "%s :Wildcard in toplevel Domain",
  61.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  62.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  63. /* 421 */    ERR_UNKNOWNCOMMAND, "%s :Unknown command",
  64. /* 422 */    ERR_NOMOTD, ":MOTD File is missing",
  65. /* 422 */    ERR_NOADMININFO,
  66.         "%s :No administrative info available",
  67. /* 422 */    ERR_FILEERROR, ":File error doing %s on %s",
  68.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  69.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  70. /* 431 */    ERR_NONICKNAMEGIVEN, ":No nickname given",
  71. /* 432 */    ERR_ERRONEUSNICKNAME, "%s :Erroneus Nickname",
  72. /* 433 */    ERR_NICKNAMEINUSE, "%s :Nickname is already in use.",
  73. /* 434 */    ERR_SERVICENAMEINUSE, (char *)NULL,
  74. /* 435 */    ERR_SERVICECONFUSED, (char *)NULL,
  75. /* 436 */    ERR_NICKCOLLISION, "%s :Nickname collision KILL",
  76.         0, (char *)NULL, 0, (char *)NULL,
  77.         0, (char *)NULL, 0, (char *)NULL,
  78.         ERR_USERNOTINCHANNEL, "%s %s :They aren't on that channel",
  79.         ERR_NOTONCHANNEL, "%s :You're not on that channel",
  80. /* 443 */    ERR_USERONCHANNEL, "%s %s :is already on channel",
  81. /* 444 */    ERR_NOLOGIN, "%s :User not logged in",
  82. #ifndef    ENABLE_SUMMON
  83. /* 445 */    ERR_SUMMONDISABLED, ":SUMMON has been disabled",
  84. #else
  85.         0, (char *)NULL,
  86. #endif
  87. #ifndef    ENABLE_USERS
  88. /* 446 */    ERR_USERSDISABLED, ":USERS has been disabled",
  89. #else
  90.         0, (char *)NULL,
  91. #endif
  92.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  93.         0, (char *)NULL,
  94. /* 451 */    ERR_NOTREGISTERED, ":You have not registered",
  95.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  96.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  97.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  98. /* 461 */    ERR_NEEDMOREPARAMS, "%s :Not enough parameters",
  99. /* 462 */    ERR_ALREADYREGISTRED, ":You may not reregister",
  100. /* 463 */    ERR_NOPERMFORHOST, ":Your host isn't among the privileged",
  101. /* 464 */    ERR_PASSWDMISMATCH, ":Password Incorrect",
  102. /* 465 */    ERR_YOUREBANNEDCREEP, ":You are banned from this server",
  103. /* 466 */    ERR_YOUWILLBEBANNED, (char *)NULL,
  104. /* 467 */    ERR_KEYSET, "%s :Channel key already set",
  105.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  106. /* 471 */    ERR_CHANNELISFULL, "%s :Cannot join channel (+l)",
  107. /* 472 */    ERR_UNKNOWNMODE  , "%c :is unknown mode char to me",
  108. /* 473 */    ERR_INVITEONLYCHAN, "%s :Cannot join channel (+i)",
  109. /* 474 */    ERR_BANNEDFROMCHAN, "%s :Cannot join channel (+b)",
  110. /* 475 */    ERR_BADCHANNELKEY, "%s :Cannot join channel (+k)",
  111. /* 476 */    ERR_BADCHANMASK, "%s :Bad Channel Mask",
  112.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  113.         0, (char *)NULL,
  114. /* 481 */    ERR_NOPRIVILEGES,
  115.         ":Permission Denied- You're not an IRC operator",
  116. /* 482 */    ERR_CHANOPRIVSNEEDED, "%s :You're not channel operator",
  117. /* 483 */    ERR_CANTKILLSERVER, ":You cant kill a server!",
  118.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  119.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  120.         0, (char *)NULL,
  121. /* 491 */    ERR_NOOPERHOST, ":No O-lines for your host",
  122. /* 492 */    ERR_NOSERVICEHOST, (char *)NULL,
  123.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  124.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  125.         0, (char *)NULL, 0, (char *)NULL,
  126. /* 501 */    ERR_UMODEUNKNOWNFLAG, ":Unknown MODE flag",
  127. /* 502 */    ERR_USERSDONTMATCH, ":Cant change mode for other users",
  128.         0, (char *)NULL
  129. };
  130.  
  131. static    Numeric    numeric_replies[] = {
  132. /* 300 */    RPL_NONE, (char *)NULL,
  133. /* 301 */    RPL_AWAY, "%s :%s",
  134. /* 302 */    RPL_USERHOST, ":",
  135. /* 303 */    RPL_ISON, ":",
  136. /* 304 */    RPL_TEXT, (char *)NULL,
  137. /* 305 */    RPL_UNAWAY, ":You are no longer marked as being away",
  138. /* 306 */    RPL_NOWAWAY, ":You have been marked as being away",
  139.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  140.         0, (char *)NULL,
  141. /* 311 */    RPL_WHOISUSER, "%s %s %s * :%s",
  142. /* 312 */    RPL_WHOISSERVER, "%s %s :%s",
  143. /* 313 */    RPL_WHOISOPERATOR, "%s :is an IRC Operator",
  144. /* 314 */    RPL_WHOWASUSER, "%s %s %s * :%s",
  145. /* 315 */    RPL_ENDOFWHO, "%s :End of /WHO list.",
  146. /* 316 */    RPL_WHOISCHANOP, (char *)NULL,
  147. /* 317 */    RPL_WHOISIDLE, "%s %ld :seconds idle",
  148. /* 318 */    RPL_ENDOFWHOIS, "%s :End of /WHOIS list.",
  149. /* 319 */    RPL_WHOISCHANNELS, "%s :%s",
  150.         0, (char *)NULL,
  151. /* 321 */    RPL_LISTSTART, "Channel :Users  Name",
  152. /* 322 */    RPL_LIST, "%s %d :%s",
  153. /* 323 */    RPL_LISTEND, ":End of /LIST",
  154. /* 324 */    RPL_CHANNELMODEIS, "%s %s %s",
  155.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  156.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  157. /* 331 */    RPL_NOTOPIC, "%s :No topic is set.",
  158. /* 332 */    RPL_TOPIC, "%s :%s",
  159.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  160.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  161.         0, (char *)NULL, 0, (char *)NULL,
  162. /* 341 */    RPL_INVITING, "%s %s",
  163. /* 342 */    RPL_SUMMONING, "%s :User summoned to irc",
  164.         0, (char *)NULL, 0, (char *)NULL,
  165.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  166.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  167. /* 351 */    RPL_VERSION, "%s.%s %s :%s",
  168. /* 352 */    RPL_WHOREPLY, "%s %s %s %s %s %s :%d %s",
  169. /* 353 */    RPL_NAMREPLY, "%s",
  170.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  171.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  172.         0, (char *)NULL,
  173. /* 361 */    RPL_KILLDONE, (char *)NULL,
  174. /* 362 */    RPL_CLOSING, "%s :Closed. Status = %d",
  175. /* 363 */    RPL_CLOSEEND, "%d: Connections Closed",
  176. /* 364 */    RPL_LINKS, "%s %s :%d %s",
  177. /* 365 */    RPL_ENDOFLINKS, "%s :End of /LINKS list.",
  178. /* 366 */    RPL_ENDOFNAMES, "%s :End of /NAMES list.",
  179. /* 367 */    RPL_BANLIST, "%s %s",
  180. /* 368 */    RPL_ENDOFBANLIST, "%s :End of Channel Ban List",
  181. /* 369 */    RPL_ENDOFWHOWAS, "%s :End of WHOWAS",
  182.         0, (char *)NULL,
  183. /* 371 */    RPL_INFO, ":%s",
  184. /* 372 */    RPL_MOTD, ":- %s",
  185. /* 373 */    RPL_INFOSTART, ":Server INFO",
  186. /* 374 */    RPL_ENDOFINFO, ":End of /INFO list.",
  187. /* 375 */    RPL_MOTDSTART, ":- %s Message of the Day - ",
  188. /* 376 */    RPL_ENDOFMOTD, ":End of /MOTD command.",
  189.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  190.         0, (char *)NULL,
  191. /* 381 */    RPL_YOUREOPER, ":You are now an IRC Operator",
  192. /* 382 */    RPL_REHASHING, "%s :Rehashing",
  193. /* 383 */    RPL_YOURESERVICE, (char *)NULL,
  194. /* 384 */    RPL_MYPORTIS, "%d :Port to local server is\r\n",
  195. /* 385 */    RPL_NOTOPERANYMORE, (char *)NULL,
  196.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  197.         0, (char *)NULL, 0, (char *)NULL,
  198. /* 391 */    RPL_TIME, "%s :%s",
  199. #ifdef    ENABLE_USERS
  200. /* 392 */    RPL_USERSSTART, ":UserID   Terminal  Host",
  201. /* 393 */    RPL_USERS, ":%-8s %-9s %-8s",
  202. /* 394 */    RPL_ENDOFUSERS, ":End of Users",
  203. /* 395 */    RPL_NOUSERS, ":Nobody logged in.",
  204. #else
  205.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  206.         0, (char *)NULL,
  207. #endif
  208.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  209.         0, (char *)NULL,
  210. /* 200 */    RPL_TRACELINK, "Link %s%s %s %s",
  211. /* 201 */    RPL_TRACECONNECTING, "Try. %d %s",
  212. /* 202 */    RPL_TRACEHANDSHAKE, "H.S. %d %s",
  213. /* 203 */    RPL_TRACEUNKNOWN, "???? %d %s",
  214. /* 204 */    RPL_TRACEOPERATOR, "Oper %d %s",
  215. /* 205 */    RPL_TRACEUSER, "User %d %s",
  216. /* 206 */    RPL_TRACESERVER, "Serv %d %dS %dC %s %s!%s@%s",
  217. /* 207 */    RPL_TRACESERVICE, "Service %d %s",
  218. /* 208 */    RPL_TRACENEWTYPE, "<newtype> 0 %s",
  219. /* 209 */    RPL_TRACECLASS, "Class %d %d",
  220.         0, (char *)NULL,
  221. /* 211 */    RPL_STATSLINKINFO, (char *)NULL,
  222. /* 212 */    RPL_STATSCOMMANDS, "%s %u %u",
  223. /* 213 */    RPL_STATSCLINE, "%c %s * %s %d %d",
  224. /* 214 */    RPL_STATSNLINE, "%c %s * %s %d %d",
  225. /* 215 */    RPL_STATSILINE, "%c %s * %s %d %d",
  226. /* 216 */    RPL_STATSKLINE, "%c %s %s %s %d %d",
  227. /* 217 */    RPL_STATSQLINE, "%c %s * %s %d %d",
  228. /* 218 */    RPL_STATSYLINE, "%c %d %d %d %d %ld",
  229. /* 219 */    RPL_ENDOFSTATS, "%c :End of /STATS report",
  230.         0, (char *)NULL,
  231. /* 221 */    RPL_UMODEIS, "%s",
  232.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  233.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  234.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  235. /* 231 */    RPL_SERVICEINFO, (char *)NULL,
  236. /* 232 */    RPL_ENDOFSERVICES, (char *)NULL,
  237. /* 233 */    RPL_SERVICE, (char *)NULL,
  238. /* 234 */    RPL_SERVLIST, (char *)NULL,
  239. /* 235 */    RPL_SERVLISTEND, (char *)NULL,
  240.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  241.         0, (char *)NULL, 0, (char *)NULL,
  242. /* 241 */    RPL_STATSLLINE, "%c %s * %s %d %d",
  243. /* 242 */    RPL_STATSUPTIME, ":Server Up %d days, %d:%02d:%02d",
  244. /* 243 */    RPL_STATSOLINE, "%c %s * %s %d %d",
  245. /* 244 */    RPL_STATSHLINE, "%c %s * %s %d %d", 
  246. /* 245 */    RPL_STATSSLINE, "%c %s * %s %d %d", 
  247.         0, (char *)NULL, 0, (char *)NULL, 0, (char *)NULL,
  248.         0, (char *)NULL, 0, (char *)NULL,
  249. /* 251 */    RPL_LUSERCLIENT,
  250.         ":There are %d users and %d invisible on %d servers",
  251. /* 252 */    RPL_LUSEROP, "%d :operator(s) online",
  252. /* 253 */    RPL_LUSERUNKNOWN, "%d :unknown connection(s)",
  253. /* 254 */    RPL_LUSERCHANNELS, "%d :channels formed",
  254. /* 255 */    RPL_LUSERME, ":I have %d clients and %d servers",
  255. /* 256 */    RPL_ADMINME, ":Administrative info about %s",
  256. /* 257 */    RPL_ADMINLOC1, ":%s",
  257. /* 258 */    RPL_ADMINLOC2, ":%s",
  258. /* 259 */    RPL_ADMINEMAIL, ":%s",
  259.         0, (char *)NULL,
  260. /* 261 */    RPL_TRACELOG, "File %s %d",
  261.         0, (char *)NULL
  262. };
  263.  
  264. char    *err_str(numeric)
  265. int    numeric;
  266. {
  267.     Reg1    Numeric    *nptr;
  268.     Reg2    int    num = numeric;
  269.  
  270.     num -= numeric_errors[0].num_val;
  271.     if (num < 0 || num > ERR_USERSDONTMATCH)
  272.         (void)sprintf(numbuff,
  273.             ":%%s %d %%s :INTERNAL ERROR: BAD NUMERIC! %d",
  274.             numeric, num);
  275.     else
  276.         {
  277.         nptr = &numeric_errors[num];
  278.         if (!nptr->num_form || !nptr->num_val)
  279.             (void)sprintf(numbuff,
  280.                 ":%%s %d %%s :NO ERROR FOR NUMERIC ERROR %d",
  281.                 numeric, num);
  282.         else
  283.             (void)prepbuf(numbuff, nptr->num_val, nptr->num_form);
  284.         }
  285.     return numbuff;
  286. }
  287.  
  288.  
  289. char    *rpl_str(numeric)
  290. int    numeric;
  291. {
  292.     Reg1    Numeric    *nptr;
  293.     Reg2    int    num = numeric;
  294.  
  295.     if (num > 4)
  296.         num -= (num > 300) ? 300 : 100;
  297.  
  298.     if (num < 0 || num > 200)
  299.         (void)sprintf(numbuff,
  300.             ":%%s %d %%s :INTERNAL REPLY ERROR: BAD NUMERIC! %d",
  301.             numeric, num);
  302.     else
  303.         {
  304.         if (numeric > 99)
  305.             nptr = &numeric_replies[num];
  306.         else
  307.             nptr = &local_replies[num];
  308.         Debug((DEBUG_NUM, "rpl_str: numeric %d num %d nptr %x %d %x",
  309.             numeric, num, nptr, nptr->num_val, nptr->num_form));
  310.         if (!nptr->num_form || !nptr->num_val)
  311.             (void)sprintf(numbuff,
  312.                 ":%%s %d %%s :NO REPLY FOR NUMERIC ERROR %d",
  313.                 numeric, num);
  314.         else
  315.             (void)prepbuf(numbuff, nptr->num_val, nptr->num_form);
  316.         }
  317.     return numbuff;
  318. }
  319.  
  320. static    char    *prepbuf(buffer, num, tail)
  321. char    *buffer;
  322. Reg1    int    num;
  323. char    *tail;
  324. {
  325.     Reg1    char    *s;
  326.  
  327.     (void)strcpy(buffer, ":%s ");
  328.     s = buffer + 4;
  329.  
  330.     *s++ = numbers[num/100];
  331.     num %= 100;
  332.     *s++ = numbers[num/10];
  333.     *s++ = numbers[num%10];
  334.     (void)strcpy(s, " %s ");
  335.     (void)strcpy(s+4, tail);
  336.     return buffer;
  337. }
  338.