/* * ms_rping - server message handler * -- by Run * * parv[0] = sender (sptr->name thus) * if sender is a person: (traveling towards start server) * parv[1] = pinged server[mask] * parv[2] = start server (current target) * parv[3] = optional remark * if sender is a server: (traveling towards pinged server) * parv[1] = pinged server (current target) * parv[2] = original sender (person) * parv[3] = start time in s * parv[4] = start time in us * parv[5] = the optional remark */ int ms_rping(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { struct Client* destination = 0; assert(0 != cptr); assert(0 != sptr); assert(IsServer(cptr)); /* * shouldn't happen */ if (!IsPrivileged(sptr)) return 0; if (IsServer(sptr)) { if (parc < 6) { /* * PROTOCOL ERROR */ return need_more_params(sptr, "RPING"); } if ((destination = FindNServer(parv[1]))) { /* * if it's not for me, pass it on */ if (IsMe(destination)) sendcmdto_one(&me, CMD_RPONG, sptr, "%s %s %s %s :%s", cli_name(sptr), parv[2], parv[3], parv[4], parv[5]); else sendcmdto_one(sptr, CMD_RPING, destination, "%C %s %s %s :%s", destination, parv[2], parv[3], parv[4], parv[5]); } } else { if (parc < 3) { return need_more_params(sptr, "RPING"); } /* * Haven't made it to the start server yet, if I'm not the start server * pass it on. */ if (hunt_server_cmd(sptr, CMD_RPING, cptr, 1, "%s %C :%s", 2, parc, parv) != HUNTED_ISME) return 0; /* * otherwise ping the destination from here */ if ((destination = find_match_server(parv[1]))) { assert(IsServer(destination) || IsMe(destination)); sendcmdto_one(&me, CMD_RPING, destination, "%C %C %s :%s", destination, sptr, militime(0, 0), parv[3]); } else send_reply(sptr, ERR_NOSUCHSERVER, parv[1]); } return 0; }
/** Handle an RPONG message from a server * -- by Run too :) * * This message is used for reporting the results of remotely * initiated pings. See ms_rping() for the theory of operation. * * Going from the rping target to the rping source, \a parv has the * following elements: * \li \a parv[1] is the rping source's name (numnick is also allowed) * \li \a parv[2] is the rping requester's numnick * \li \a parv[3] is the rping start time (seconds part) * \li \a parv[4] is the rping start time (microseconds part) * \li \a parv[5] is the requester's remark * * Going from the rping source to the rping requester, \a parv has the * following elements: * \li \a parv[1] is the rping source's name (numnick is also allowed) * \li \a parv[2] is the rping requester's numnick * \li \a parv[3] is the rping round trip time in milliseconds * \li \a parv[4] is the requester's remark * * See @ref m_functions for discussion of the arguments. * @param[in] cptr Client that sent us the message. * @param[in] sptr Original source of message. * @param[in] parc Number of arguments. * @param[in] parv Argument vector. */ int ms_rpong(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { struct Client *acptr; if (!IsServer(sptr)) return 0; if (parc < 5) { /* * PROTOCOL ERROR */ return need_more_params(sptr, "RPONG"); } if (parc == 6) { /* * from pinged server to source server */ if (!(acptr = FindServer(parv[1])) && !(acptr = FindNServer(parv[1]))) return 0; if (IsMe(acptr)) { if (!(acptr = findNUser(parv[2]))) return 0; sendcmdto_one(&me, CMD_RPONG, acptr, "%C %s %s :%s", acptr, cli_name(sptr), militime(parv[3], parv[4]), parv[5]); } else sendcmdto_one(sptr, CMD_RPONG, acptr, "%s %s %s %s :%s", parv[1], parv[2], parv[3], parv[4], parv[5]); } else { /* * returned from source server to client */ if (!(acptr = findNUser(parv[1]))) return 0; sendcmdto_one(sptr, CMD_RPONG, acptr, "%C %s %s :%s", acptr, parv[2], parv[3], parv[4]); } return 0; }
/* * mo_rping - oper message handler * -- by Run * * * Receive: * RPING blah.* * RPING blah.* :<start time> * RPING blah.* server.* :<start time> * * parv[0] = sender (sptr->name thus) * parv[1] = pinged server name or mask (required) * parv[2] = start server name or mask (optional, defaults to me) * parv[3] = client start time (optional) * * Send: NumNick(sptr) RPING blah.* server.net :<start time> (hunt_server) * NumServ(&me) RPING NumServ(blah.bar.net) NumNick(sptr) :<start time> (here) */ int mo_rping(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { struct Client* acptr = 0; const char* start_time = "<No client start time>"; assert(0 != cptr); assert(0 != sptr); assert(cptr == sptr); assert(IsAnOper(sptr)); if (parc < 2) return need_more_params(sptr, "RPING"); if (parc > 2) { if ((acptr = find_match_server(parv[2])) && !IsMe(acptr)) { parv[2] = cli_name(acptr); if (3 == parc) { /* * const_cast<char*>(start_time); */ parv[parc++] = (char*) start_time; } hunt_server_cmd(sptr, CMD_RPING, cptr, 1, "%s %C :%s", 2, parc, parv); return 0; } else start_time = parv[2]; } if ((acptr = find_match_server(parv[1]))) { assert(IsServer(acptr) || IsMe(acptr)); sendcmdto_one(&me, CMD_RPING, acptr, "%C %C %s :%s", acptr, sptr, militime(0, 0), start_time); } else send_reply(sptr, ERR_NOSUCHSERVER, parv[1]); return 0; }