+
+void serverlist_pingservers(void *arg) {
+ int i;
+ server *from, *to;
+ char fnum[10], tnum[10];
+ struct timeval tv;
+
+ if (!mynick)
+ return;
+
+ for(i=0;i<MAXSERVERS;i++) {
+ to = &serverlist[i];
+
+ if (to->parent == -1)
+ continue;
+
+ from = &serverlist[to->parent];
+
+ if (to->linkstate != LS_LINKED || from->linkstate != LS_LINKED)
+ continue;
+
+ strcpy(fnum, longtonumeric(to->parent,2));
+ strcpy(tnum, longtonumeric(i, 2));
+
+ if (from->parent == -1) { /* Are we the source? */
+ (void) gettimeofday(&tv, NULL);
+ irc_send("%s RI %s %s %jd %jd :RP", mynumeric->content, tnum, longtonumeric(mynick->numeric,5), (intmax_t)tv.tv_sec, (intmax_t)tv.tv_usec);
+ } else {
+ strcpy(fnum, longtonumeric(to->parent,2));
+ strcpy(tnum, longtonumeric(i, 2));
+ irc_send("%s RI %s %s :RP", longtonumeric(mynick->numeric,5), to->name->content, fnum);
+ }
+ }
+}
+
+int serverlist_rpong(void *source, int cargc, char **cargv) {
+ int to, lag;
+ struct timeval tv;
+
+ if (cargc < 4)
+ return CMD_ERROR;
+
+ if (cargc == 5) { /* From target to source server */
+ if (strcmp(cargv[4], "RP") != 0)
+ return CMD_OK;
+
+ to = numerictolong(source, 2);
+
+ (void) gettimeofday(&tv, NULL);
+ lag = (tv.tv_sec - strtoull(cargv[2], NULL, 10)) * 1000 + (tv.tv_usec - strtoull(cargv[3], NULL, 10)) / 1000;
+ } else { /* From source server to client */
+ if (strcmp(cargv[3], "RP") != 0)
+ return CMD_OK;
+
+ to = findserver(cargv[1]);
+
+ if (to == -1)
+ return CMD_ERROR;
+
+ lag = atoi(cargv[2]);
+ }
+
+ serverinfo[to].lag = lag;
+
+ return CMD_OK;
+}
+