/[LeafOK_CVS]/pvpgn-1.7.4/src/bnetd/tracker.c
ViewVC logotype

Contents of /pvpgn-1.7.4/src/bnetd/tracker.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Tue Jun 6 03:41:37 2006 UTC (19 years, 9 months ago) by sysadm
Branch point for: GNU, MAIN
Content type: text/x-csrc
Initial revision

1 /*
2 * Copyright (C) 1999 Mark Baysinger (mbaysing@ucsd.edu)
3 * Copyright (C) 1999 Ross Combs (rocombs@cs.nmsu.edu)
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19 #define TRACKER_INTERNAL_ACCESS
20 #define SERVER_INTERNAL_ACCESS
21 #include "common/setup_before.h"
22 #ifdef HAVE_STDDEF_H
23 # include <stddef.h>
24 #else
25 # ifndef NULL
26 # define NULL ((void *)0)
27 # endif
28 #endif
29 #ifdef HAVE_STRING_H
30 # include <string.h>
31 #else
32 # ifdef HAVE_STRINGS_H
33 # include <strings.h>
34 # endif
35 # ifdef HAVE_MEMORY_H
36 # include <memory.h>
37 # endif
38 #endif
39 #include "compat/memset.h"
40 #include <errno.h>
41 #include "compat/strerror.h"
42 #ifdef TIME_WITH_SYS_TIME
43 # include <sys/time.h>
44 # include <time.h>
45 #else
46 # ifdef HAVE_SYS_TIME_H
47 # include <sys/time.h>
48 # else
49 # include <time.h>
50 # endif
51 #endif
52 #ifdef HAVE_SYS_UTSNAME_H
53 # include <sys/utsname.h>
54 #endif
55 #include "compat/uname.h"
56 #ifdef HAVE_SYS_TYPES_H
57 # include <sys/types.h>
58 #endif
59 #ifdef HAVE_SYS_SOCKET_H
60 # include <sys/socket.h>
61 #endif
62 #include "compat/socket.h"
63 #include "compat/send.h"
64 #ifdef HAVE_SYS_PARAM_H
65 # include <sys/param.h>
66 #endif
67 #ifdef HAVE_NETINET_IN_H
68 # include <netinet/in.h>
69 #endif
70 #include "compat/netinet_in.h"
71 #include "compat/psock.h"
72 #include "common/eventlog.h"
73 #include "connection.h"
74 #include "channel.h"
75 #include "prefs.h"
76 #include "game.h"
77 #include "common/version.h"
78 #include "server.h"
79 #include "common/addr.h"
80 #include "common/list.h"
81 #include "common/tracker.h"
82 #include "common/setup_after.h"
83
84
85 static t_addrlist * track_servers=NULL;
86
87
88 extern int tracker_set_servers(char const * servers)
89 {
90 t_addr const * addr;
91 t_elem const * curr;
92 char temp[32];
93
94 if (track_servers && addrlist_destroy(track_servers)<0)
95 eventlog(eventlog_level_error,__FUNCTION__,"unable to destroy tracker list");
96
97 if (!servers)
98 {
99 track_servers = NULL;
100 return 0;
101 }
102
103 if (!(track_servers = addrlist_create(servers,INADDR_LOOPBACK,BNETD_TRACK_PORT)))
104 {
105 eventlog(eventlog_level_error,__FUNCTION__,"could not create tracking server list");
106 return -1;
107 }
108
109 LIST_TRAVERSE_CONST(track_servers,curr)
110 {
111 addr = elem_get_data(curr);
112 if (!addr_get_addr_str(addr,temp,sizeof(temp)))
113 strcpy(temp,"x.x.x.x:x");
114 eventlog(eventlog_level_info,__FUNCTION__,"tracking packets will be sent to %s",temp);
115 }
116
117 return 0;
118 }
119
120
121 extern int tracker_send_report(t_addrlist const * laddrs)
122 {
123 t_addr const * addrl;
124 t_elem const * currl;
125 t_addr const * addrt;
126 t_elem const * currt;
127 t_trackpacket packet;
128 struct utsname utsbuf;
129 struct sockaddr_in tempaddr;
130 t_laddr_info * laddr_info;
131 char tempa[64];
132 char tempb[64];
133
134 if (addrlist_get_length(track_servers)>0)
135 {
136 packet.packet_version = htons((unsigned short)TRACK_VERSION);
137 /* packet.port is set below */
138 packet.flags = 0;
139 strncpy(packet.server_location,
140 prefs_get_location(),
141 sizeof(packet.server_location));
142 packet.server_location[sizeof(packet.server_location)-1] = '\0';
143 strncpy(packet.software,
144 PVPGN_SOFTWARE,
145 sizeof(packet.software));
146 strncpy(packet.version,
147 PVPGN_VERSION,
148 sizeof(packet.version));
149 strncpy(packet.server_desc,
150 prefs_get_description(),
151 sizeof(packet.server_desc));
152 packet.server_desc[sizeof(packet.server_desc)-1] = '\0';
153 strncpy(packet.server_url,
154 prefs_get_url(),
155 sizeof(packet.server_url));
156 packet.server_url[sizeof(packet.server_url)-1] = '\0';
157 strncpy(packet.contact_name,
158 prefs_get_contact_name(),
159 sizeof(packet.contact_name));
160 packet.contact_name[sizeof(packet.contact_name)-1] = '\0';
161 strncpy(packet.contact_email,
162 prefs_get_contact_email(),
163 sizeof(packet.contact_email));
164 packet.contact_email[sizeof(packet.contact_email)-1] = '\0';
165 packet.users = htonl(connlist_login_get_length());
166 packet.channels = htonl(channellist_get_length());
167 packet.games = htonl(gamelist_get_length());
168 packet.uptime = htonl(server_get_uptime());
169 packet.total_logins = htonl(connlist_total_logins());
170 packet.total_games = htonl(gamelist_total_games());
171
172 if (uname(&utsbuf)<0)
173 {
174 eventlog(eventlog_level_warn,__FUNCTION__,"could not get platform info (uname: %s)",pstrerror(errno));
175 strncpy(packet.platform,"",sizeof(packet.platform));
176 }
177 else
178 {
179 strncpy(packet.platform,
180 utsbuf.sysname,
181 sizeof(packet.platform));
182 packet.platform[sizeof(packet.platform)-1] = '\0';
183 }
184
185 LIST_TRAVERSE_CONST(laddrs,currl)
186 {
187 addrl = elem_get_data(currl);
188
189 if (!(laddr_info = addr_get_data(addrl).p))
190 {
191 eventlog(eventlog_level_error,__FUNCTION__,"address data is NULL");
192 continue;
193 }
194 if (laddr_info->type!=laddr_type_bnet)
195 continue; /* don't report IRC, telnet, and other non-game ports */
196
197 packet.port = htons(addr_get_port(addrl));
198
199 LIST_TRAVERSE_CONST(track_servers,currt)
200 {
201 addrt = elem_get_data(currt);
202
203 memset(&tempaddr,0,sizeof(tempaddr));
204 tempaddr.sin_family = PSOCK_AF_INET;
205 tempaddr.sin_port = htons(addr_get_port(addrt));
206 tempaddr.sin_addr.s_addr = htonl(addr_get_ip(addrt));
207
208 if (!addr_get_addr_str(addrl,tempa,sizeof(tempa)))
209 strcpy(tempa,"x.x.x.x:x");
210 if (!addr_get_addr_str(addrt,tempb,sizeof(tempb)))
211 strcpy(tempa,"x.x.x.x:x");
212 /* eventlog(eventlog_level_debug,__FUNCTION__,"sending tracking info from %s to %s",tempa,tempb); */
213
214 if (psock_sendto(laddr_info->usocket,&packet,sizeof(packet),0,(struct sockaddr *)&tempaddr,(psock_t_socklen)sizeof(tempaddr))<0)
215 eventlog(eventlog_level_warn,__FUNCTION__,"could not send tracking information from %s to %s (psock_sendto: %s)",tempa,tempb,pstrerror(errno));
216 }
217 }
218 }
219
220 return 0;
221 }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1