added gnutls backend and moved backend code into new files
[ircu2.10.12-pk.git] / ircd / m_pong.c
index 74b4fcb0258125f6e541b91d90e08dfd5d069b59..df29b9f6714ace850041b1f669e08094c62e2226 100644 (file)
 #include "client.h"
 #include "hash.h"
 #include "ircd.h"
+#include "ircd_log.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
 #include "msg.h"
 #include "numeric.h"
 #include "numnicks.h"
+#include "opercmds.h"
+#include "s_auth.h"
 #include "s_user.h"
 #include "send.h"
 
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
 #include <string.h>
 #include <stdlib.h>
 
 /*
- * ms_pong - server message handler template
+ * ms_pong - server message handler
  *
  * parv[0] = sender prefix
  * parv[1] = origin
@@ -116,15 +119,33 @@ int ms_pong(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   }
   origin      = parv[1];
   destination = parv[2];
-  cli_flags(cptr) &= ~FLAGS_PINGSENT;
-  cli_flags(sptr) &= ~FLAGS_PINGSENT;
+  ClearPingSent(cptr);
+  ClearPingSent(sptr);
   cli_lasttime(cptr) = CurrentTime;
 
-  if (!EmptyString(destination) && 0 != ircd_strcmp(destination, cli_name(&me))) {
+  if (parc > 5)
+  {
+    /* AsLL pong */
+    cli_serv(cptr)->asll_rtt = atoi(militime_float(parv[3]));
+    cli_serv(cptr)->asll_to = atoi(parv[4]);
+    cli_serv(cptr)->asll_from = atoi(militime_float(parv[5]));
+    cli_serv(cptr)->asll_last = CurrentTime;
+    return 0;
+  }
+  
+  if (EmptyString(destination))
+    return 0;
+  
+  if (*destination == '!')
+  {
+    /* AsLL ping reply from a non-AsLL server */
+    cli_serv(cptr)->asll_rtt = atoi(militime_float(destination + 1));
+  }
+  else if (0 != ircd_strcmp(destination, cli_name(&me)))
+  {
     struct Client* acptr;
-    if ((acptr = FindClient(destination))) {
+    if ((acptr = FindClient(destination)))
       sendcmdto_one(sptr, CMD_PONG, acptr, "%s %s", origin, destination);
-    }
   }
   return 0;
 }
@@ -142,26 +163,8 @@ int mr_pong(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   assert(cptr == sptr);
   assert(!IsRegistered(sptr));
 
-  cli_flags(cptr) &= ~FLAGS_PINGSENT;
-  cli_lasttime(cptr) = CurrentTime;
-  /*
-   * Check to see if this is a PONG :cookie reply from an
-   * unregistered user.  If so, process it. -record
-   */
-  if (0 != cli_cookie(sptr) && COOKIE_VERIFIED != cli_cookie(sptr)) {
-    if (parc > 1 && cli_cookie(sptr) == atol(parv[parc - 1])) {
-      cli_cookie(sptr) = COOKIE_VERIFIED;
-      if (cli_user(sptr) && *(cli_user(sptr))->host && (cli_name(sptr))[0])
-        /*
-         * NICK and USER OK
-         */
-        return register_user(cptr, sptr, cli_name(sptr), cli_user(sptr)->username);
-    }
-    else  
-      send_reply(sptr, SND_EXPLICIT | ERR_BADPING,
-                ":To connect, type /QUOTE PONG %u", cli_cookie(sptr));
-  }
-  return 0;
+  ClearPingSent(cptr);
+  return (parc > 1) ? auth_set_pong(cli_auth(sptr), strtoul(parv[parc - 1], NULL, 10)) : 0;
 }
 
 /*
@@ -175,7 +178,8 @@ int m_pong(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {
   assert(0 != cptr);
   assert(cptr == sptr);
-  cli_flags(cptr) &= ~FLAGS_PINGSENT;
+
+  ClearPingSent(cptr);
   cli_lasttime(cptr) = CurrentTime;
   return 0;
 }