]>
Commit | Line | Data |
---|---|---|
7bec4aeb | 1 | /* rping.c */ |
2 | ||
3 | #include "miscreply.h" | |
4 | #include "msg.h" | |
5 | #include "numeric.h" | |
6 | #include "../irc/irc.h" | |
7 | #include "../core/error.h" | |
8 | #include "../nick/nick.h" | |
9 | #include "../server/server.h" | |
10 | ||
11 | #include <stdio.h> | |
12 | #include <string.h> | |
13 | #include <sys/time.h> | |
14 | ||
15 | ||
16 | ||
17 | /* handle remote rping request | |
18 | * | |
19 | * RPING from requesting user to start server: | |
20 | * <user numeric> RPING/RI <server> <target server numeric> :<comment> | |
21 | * | |
22 | * cargv[0] = server | |
23 | * server(mask) as given by user | |
24 | * a * indicates the request is for all servers (possible snircd extension) | |
25 | * cargv[1] = target server numeric | |
26 | * cargv[2] = comment | |
27 | * | |
28 | * | |
29 | * RPING from start server to destination server: | |
30 | * <start server numeric> RPING/RI <target server numeric> <requesting user numeric> <start seconds> <start milliseconds> :<comment> | |
31 | * | |
32 | * cargv[0] = target server numeric | |
33 | * can be a * in which case the request is for all servers (possible snircd extension) | |
34 | * cargv[1] = requesting user numeric | |
35 | * cargv[2] = start time in seconds | |
36 | * cargv[3] = start time in milliseconds | |
37 | * cargv[4] = comment | |
38 | * | |
39 | */ | |
40 | int handlerpingmsg(void *source, int cargc, char **cargv) { | |
41 | ||
42 | nick *snick; /* struct nick for source (oper) nick */ | |
43 | ||
44 | int i; /* index for serverlist[] */ | |
45 | int m; /* result of myserver lookup */ | |
46 | char *sourcenum = (char *)source; /* source numeric */ | |
47 | char *targetnum = getmynumeric(); /* target server numeric */ | |
48 | char *server; /* target server parameter */ | |
49 | char *servername = myserver->content; /* servername */ | |
50 | char *destserver; /* destination server mask */ | |
51 | char *destnum; /* destination server numeric */ | |
52 | char *sourceoper; /* requesting oper numeric */ | |
53 | char *time_s; /* time in seconds */ | |
54 | char *time_us; /* time in milliseconds */ | |
55 | char *comment; /* comment by client */ | |
56 | struct timeval tv; /* get start time in seconds and milliseconds */ | |
57 | ||
58 | /* from server */ | |
59 | if (IsServer(sourcenum)) { | |
60 | ||
61 | /* check parameters */ | |
62 | if (cargc < 5) { | |
63 | miscreply_needmoreparams(sourcenum, "RPING"); | |
64 | return CMD_OK; | |
65 | } | |
66 | ||
67 | /* set the parameters */ | |
68 | server = cargv[0]; | |
69 | sourceoper = cargv[1]; | |
70 | time_s = cargv[2]; | |
71 | time_us = cargv[3]; | |
72 | comment = cargv[4]; | |
73 | ||
74 | /* find source server */ | |
75 | if (miscreply_findserver(sourcenum, "RPING") == -1) | |
76 | return CMD_OK; | |
77 | ||
78 | /* find source user */ | |
79 | if (!(snick = miscreply_finduser(sourceoper, "RPING"))) | |
80 | return CMD_OK; | |
81 | ||
82 | /* request is not for * (all servers) */ | |
83 | if (!(server[0] == '*' && server[1] == '\0')) { | |
84 | ||
85 | /* destination server not found */ | |
86 | if ((i = miscreply_findservernum(sourceoper, server, "RPING")) == -1) | |
87 | return CMD_OK; | |
88 | ||
89 | targetnum = longtonumeric(i, 2); | |
90 | servername = serverlist[i].name->content; | |
91 | ||
92 | /* not me, tell user */ | |
93 | if (!IsMeNum(targetnum)) | |
94 | send_snotice(sourceoper, "RPING: Server %s is not a real server.", servername); | |
95 | } | |
96 | ||
97 | /* send */ | |
98 | irc_send("%s %s %s %s %s %s :%s", targetnum, TOK_RPONG, sourcenum, | |
99 | sourceoper, time_s, time_us, comment); | |
100 | } | |
101 | ||
102 | /* from user */ | |
103 | else if (IsUser(sourcenum)) { | |
104 | ||
105 | /* check parameters */ | |
106 | if (cargc < 3) { | |
107 | miscreply_needmoreparams(sourcenum, "RPING"); | |
108 | return CMD_OK; | |
109 | } | |
110 | ||
111 | /* set the parameters */ | |
112 | destserver = cargv[0]; | |
113 | server = cargv[1]; | |
114 | comment = cargv[2]; | |
115 | ||
116 | /* find source user */ | |
117 | if (!(snick = miscreply_finduser(sourcenum, "RPING"))) | |
118 | return CMD_OK; | |
119 | ||
120 | /* request is for * (all servers) */ | |
121 | if ((destserver[0] == '*' && destserver[1] == '\0')) | |
122 | destnum = "*"; | |
123 | ||
124 | /* find destination server */ | |
125 | else if ((i = miscreply_findservermatch(sourcenum, destserver)) == -1) | |
126 | return CMD_OK; | |
127 | ||
128 | /* destination one of my servers? */ | |
129 | else if ((m = miscreply_myserver(i))) { | |
130 | servername = serverlist[i].name->content; | |
131 | ||
132 | /* tell user, and return RPONG with delay 0 */ | |
133 | if (m == 1) | |
134 | send_snotice(sourcenum, "RPING: Server %s is me.", servername); | |
135 | else | |
136 | send_snotice(sourcenum, "RPING: Server %s is not a real server.", servername); | |
137 | irc_send("%s %s %s %s 0 :%s", targetnum, TOK_RPONG, sourcenum, servername, comment); | |
138 | return CMD_OK; | |
139 | } | |
140 | ||
141 | /* found valid destination server */ | |
142 | else | |
143 | destnum = longtonumeric(i, 2); | |
144 | ||
145 | /* get starttime */ | |
146 | gettimeofday(&tv, NULL); | |
147 | ||
148 | /* send */ | |
149 | irc_send("%s %s %s %s %lu %lu :%s", targetnum, TOK_RPING, destnum, | |
150 | sourcenum, tv.tv_sec, tv.tv_usec, comment); | |
151 | } | |
152 | ||
153 | ||
154 | /* trouble not from server and not from user numeric? */ | |
155 | else { | |
156 | Error("miscreply", ERR_WARNING, | |
157 | "RPING from odd numeric source %s (not a server and not user numeric)", sourcenum); | |
158 | return CMD_OK; | |
159 | } | |
160 | ||
161 | return CMD_OK; | |
162 | } |