]> jfr.im git - irc/quakenet/newserv.git/blobdiff - miscreply/miscreply.c
CHANSERV: remove accidental sendemail from SETEMAIL command.
[irc/quakenet/newserv.git] / miscreply / miscreply.c
index bc50c70fac3e40207d2f52f0bd95dfcf3f4f377d..4022f222c3cb223777f8a2c8949efe6af119d3d5 100644 (file)
@@ -1,10 +1,8 @@
 /* miscreply.c */
 
-
 #include "miscreply.h"
-#include "msg.h"
-#include "numeric.h"
 #include "../core/error.h"
+#include "../core/config.h"
 #include "../irc/irc.h"
 #include "../lib/irc_string.h"
 #include "../lib/version.h"
 
 #include <stdarg.h>
 #include <stdio.h>
+#include <string.h>
 
 /* module version */
-MODULE_VERSION("0.0.1");
-
-/* TODO: what module name? miscreply remotereply .. ? */
-/* TODO: what includes are required ? */
-/* TODO: add proper descriptions, maybe readme file ? */
-/* TODO: use serve instead of accessing serverlist[] directly ? */
-/* TODO: default.c handle there all remote requests we dont support ? */
-/* TODO: how to handle remote requests not for ourself but for other servers we have (juped ones or whatever) ? */
-/* TODO: check requests we receive are for me or my servers ? */
-/* TODO: remote requests:
- *       ASLL CHECK CONNECT INFO LUSERS MOTD NAMES UPING WHOWAS
- *       ADMIN LINKS PRIVS RPING RPONG STATS TRACE TIME VERSION WHOIS (done)
- *       GLINE JUPE SETTIME (already handled in other places)
+MODULE_VERSION(MISCREPLY_VERSION);
+
+
+
+/*
+ * This module handles the following remote IRC commands
+ *
+ *  ADMIN
+ *  PRIVS
+ *  RPING
+ *  RPONG
+ *  STATS
+ *  TRACE
+ *  TIME
+ *  VERSION 
+ *  WHOIS
+ *
  */
 
 
 
+/* admin info */
+sstring *admin1;
+sstring *admin2;
+sstring *admin3;
+
+
+
 /* init */
 void _init() {
-  
+
+  /* get the admin info from the config
+   *   mix in some references to Quake and Doom in the defaults
+   */
+  admin1 = getcopyconfigitem("miscreply", "admin1", "Located at the Union Aerospace Corp. facility, Stroggos", BUFSIZE);
+  admin2 = getcopyconfigitem("miscreply", "admin2", "Network IRC Service", BUFSIZE);
+  admin3 = getcopyconfigitem("miscreply", "admin3", "No administrative info available", BUFSIZE);
+
   /* add server handlers */
-  registerserverhandler(TOK_ADMIN, &handleadminmsg, 1);      /* ADMIN   */
-  registerserverhandler(TOK_LINKS, &handlelinksmsg, 2);      /* LINKS   */
-  registerserverhandler(TOK_PRIVS, &handleprivsmsg, 1);      /* PRIVS   */
-  registerserverhandler(TOK_RPING, &handlerpingmsg, 3);      /* RPING   */
-  registerserverhandler(TOK_RPONG, &handlerpongmsg, 4);      /* RPONG   */
-  registerserverhandler(TOK_STATS, &handlestatsmsg, 2);      /* STATS   */
-  registerserverhandler(TOK_TIME, &handletimemsg, 1);        /* TIME    */
-  registerserverhandler(TOK_TRACE, &handletracemsg, 2);      /* TRACE   */
-  registerserverhandler(TOK_VERSION, &handleversionmsg, 1);  /* VERSION */
-  registerserverhandler(TOK_WHOIS, &handlewhoismsg, 2);      /* WHOIS   */
+  registerserverhandler("AD", &handleadminmsg, 1);   /* ADMIN   */
+  registerserverhandler("PR", &handleprivsmsg, 1);   /* PRIVS   */
+  registerserverhandler("RI", &handlerpingmsg, 3);   /* RPING   */
+  registerserverhandler("RO", &handlerpongmsg, 4);   /* RPONG   */
+  registerserverhandler("R",  &handlestatsmsg, 2);   /* STATS   */
+  registerserverhandler("TI", &handletimemsg, 1);    /* TIME    */
+  registerserverhandler("TR", &handletracemsg, 2);   /* TRACE   */
+  registerserverhandler("V",  &handleversionmsg, 1); /* VERSION */
+  registerserverhandler("W",  &handlewhoismsg, 2);   /* WHOIS   */
 
 }
 
@@ -54,87 +70,97 @@ void _init() {
 void _fini() {
 
   /* remove server handlers */
-  deregisterserverhandler(TOK_ADMIN, &handleadminmsg);      /* ADMIN   */
-  deregisterserverhandler(TOK_LINKS, &handlelinksmsg);      /* LINKS   */
-  deregisterserverhandler(TOK_PRIVS, &handleprivsmsg);      /* PRIVS   */
-  deregisterserverhandler(TOK_RPING, &handlerpingmsg);      /* RPING   */
-  deregisterserverhandler(TOK_RPONG, &handlerpongmsg);      /* RPONG   */
-  deregisterserverhandler(TOK_STATS, &handlestatsmsg);      /* STATS   */
-  deregisterserverhandler(TOK_TIME, &handletimemsg);        /* TIME    */
-  deregisterserverhandler(TOK_TRACE, &handletracemsg);      /* TRACE   */
-  deregisterserverhandler(TOK_VERSION, &handleversionmsg);  /* VERSION */
-  deregisterserverhandler(TOK_WHOIS, &handlewhoismsg);      /* WHOIS   */
+  deregisterserverhandler("AD", &handleadminmsg);   /* ADMIN   */
+  deregisterserverhandler("PR", &handleprivsmsg);   /* PRIVS   */
+  deregisterserverhandler("RI", &handlerpingmsg);   /* RPING   */
+  deregisterserverhandler("RO", &handlerpongmsg);   /* RPONG   */
+  deregisterserverhandler("R",  &handlestatsmsg);   /* STATS   */
+  deregisterserverhandler("TI", &handletimemsg);    /* TIME    */
+  deregisterserverhandler("TR", &handletracemsg);   /* TRACE   */
+  deregisterserverhandler("V",  &handleversionmsg); /* VERSION */
+  deregisterserverhandler("W",  &handlewhoismsg);   /* WHOIS   */
+
+}
+
+
+
+/* from_server
+ *   if valid server numeric return 1
+ *   else return 0 and log error
+ */
+static int from_server(char *sourcenum, char *command) {
 
+   /* valid server numeric */
+  if (strlen(sourcenum) == 2)
+    return 1;
+
+  Error("miscreply", ERR_WARNING, "Received %s request from non-server numeric %s", command, sourcenum);
+  return 0;
+}
+
+
+
+/* from_user
+ *   if valid user numeric return 1
+ *   else return 0 and log error
+ */
+static int from_user(char *sourcenum, char *command) {
+
+  /* valid user numeric */
+  if (strlen(sourcenum) == 5)
+    return 1;
+
+  Error("miscreply", ERR_WARNING, "Received %s request from non-user numeric %s", command, sourcenum);
+  return 0;
 }
 
 
 
 /* needmoreparams
- * return error to source user and log if we did not get enough parameters
+ *   reply error to source user
+ *   log error
  */
 void miscreply_needmoreparams(char *sourcenum, char *command) {
   /*
    * 461 ERR_NEEDMOREPARAMS "source 461 target command :Not enough parameters"
    *                        "irc.netsplit.net 461 foobar JOIN :Not enough parameters"
    */
-  send_reply(getmynumeric(), ERR_NEEDMOREPARAMS, sourcenum, "%s :Not enough parameters", command);
-  Error("miscreply", ERR_WARNING, "%s request without enough parameters from %s", command, sourcenum);
+  irc_send("%s 461 %s %s :Not enough parameters", getmynumeric(), sourcenum, command);
+  Error("miscreply", ERR_WARNING, "Received %s request without enough parameters from %s", command, sourcenum);
 }
 
 
 
 /* findserver
- * return error to log if source server numeric cannot be found
- * returns server longnumeric
- * returns -1 when not found
+ *   if found return server longnumeric
+ *   else return -1 and log error
  */
-int miscreply_findserver(char *sourcenum, char *command) {
-  int i = numerictolong(sourcenum, 2);
+long miscreply_findserver(char *sourcenum, char *command) {
+  long i = numerictolong(sourcenum, 2);
 
-  if (serverlist[i].maxusernum == 0) {
-    Error("miscreply", ERR_WARNING, "%s request from unknown server numeric %s", command, sourcenum);
+  /* check source is a valid server numeric */
+  if (!from_server(sourcenum, command))
     return -1;
-  }
-
-  return i;
-}
-
 
+  if (serverlist[i].linkstate != LS_INVALID)
+    return i;
 
-/* findservernum
- * return error to source user and log if server numeric cannot be found
- * returns server longnumeric
- * returns -1 when not found
- */
-int miscreply_findservernum(char *sourcenum, char *servernum, char *command) {
-  int i = numerictolong(servernum, 2);
-
-  if (serverlist[i].maxusernum == 0) {
-    /*
-     * 402 RPL_NOSUCHSERVER "source 402 target * :Server has disconnected"
-     *                      "irc.netsplit.net 402 foobar * :Server has disconnected"
-     */
-    send_reply(getmynumeric(), ERR_NOSUCHSERVER, sourcenum, "* :Server has disconnected");
-    Error("miscreply", ERR_WARNING, "%s request for unknown server numeric %s from numeric %s", command, servernum, sourcenum);
-    return -1;
-  }
-
-  return i;
+  Error("miscreply", ERR_WARNING, "Received %s request from unknown server numeric %s", command, sourcenum);
+  return -1;
 }
 
 
 
 /* findservermatch
- * return error to source user if no servers matching the servermask can be found
- * returns server longnumeric
- * returns -1 when not found
+ *   if found return server longnumeric
+ *   else return -1 and reply error to source user
  */
-int miscreply_findservermatch(char *sourcenum, char *servermask) {
-  int i;
+long miscreply_findservermatch(char *sourcenum, char *servermask) {
+  long i;
 
   /* go over all servers */
   for (i = 0; i < MAXSERVERS; i++) {
-    if (serverlist[i].maxusernum == 0)   /* not linked */
+    if (serverlist[i].linkstate == LS_INVALID)   /* not linked */
       continue;
     if (!match2strings(servermask, serverlist[i].name->content))   /* no match */
       continue;
@@ -145,101 +171,27 @@ int miscreply_findservermatch(char *sourcenum, char *servermask) {
    * 402 RPL_NOSUCHSERVER "source 402 target server :No such server"
    *                      "irc.netsplit.net 402 foobar hub* :No such server"
    */
-  send_reply(getmynumeric(), ERR_NOSUCHSERVER, sourcenum, "%s :No such server", servermask);
+  irc_send("%s 402 %s %s :No such server", getmynumeric(), sourcenum, servermask);
 
   return -1;
 }
 
 
 
-/* finduser 
- * return error to log if user numeric cannot be found 
+/* finduser
+ *   if found return nick for source numeric
+ *   else return NULL and log error
  */
 nick *miscreply_finduser(char *sourcenum, char *command) {
   nick *nick;
 
-  if (!(nick = getnickbynumericstr(sourcenum)))
-    Error("miscreply", ERR_WARNING, "%s request from unknown user numeric %s", command, sourcenum);
-
-  return nick;
-}
-
-
-
-/* TODO: should it be long intead of int ? */
-/* myserver
- *
- * return 2 if the server is one of my downlinks (juped servers?),
- * return 1 if the server is me, else
- * return 0 
- */
-int miscreply_myserver(int numeric) {
-
-  /* it is me */
-  if (IsMeLong(numeric))
-    return 1;
-
-  /* while parent server is not me */
-  while (!IsMeLong(serverlist[numeric].parent))
-    numeric = serverlist[numeric].parent;
-
-  /* numeric is my hub,
-   *   so the start server is behind it,
-   *   and not one of mine
-   */
-  if (numeric == myhub)
-    return 0;
-
-  return 2;
-}
-
-
-
-/* send_reply
- *
- * send server numeric reply to user
- *
- */
-void send_reply(char *sourcenum, int numeric, char *targetnum, char *pattern, ...) {
-  char buf[BUFSIZE];
-  va_list val;
-
-  /* negative numeric? */
-  if (numeric < 0)
-    return;
-
-  va_start(val, pattern);
-  vsnprintf(buf, sizeof(buf), pattern, val);
-  va_end(val);
-
-  /*
-   * Reserve numerics 000-099 for server-client connections where the client
-   * is local to the server. If any server is passed a numeric in this range
-   * from another server then it is remapped to 100-199. -avalon
-   *
-   *  from ircu ircd/numeric.h
-   */
-  /* just in case we are about to send a numeric in the reserved range, remap it */
-  if (numeric < 100)
-    numeric =+ 100;
-
-  irc_send("%s %d %s %s", sourcenum, numeric, targetnum, buf);
-}
-
-
-
-/* send_snotice
- *
- * send server notice to user
- *
- */
-void send_snotice(char *targetnum, char *pattern, ...) {
-  char buf[BUFSIZE];
-  va_list val;
+  /* check source is a valid user numeric */
+  if (!from_user(sourcenum, command))
+    return NULL;
 
-  va_start(val, pattern);
-  vsnprintf(buf, sizeof(buf), pattern, val);
-  va_end(val);
+  if ((nick = getnickbynumericstr(sourcenum)))
+    return nick;
 
-  irc_send("%s %s %s :%s", getmynumeric(), TOK_NOTICE, targetnum, buf);
+  Error("miscreply", ERR_WARNING, "Received %s request from unknown user numeric %s", command, sourcenum);
+  return NULL;
 }