1 | /* |
1 | /* |
2 | * static char *rcsid_metaserver_c = |
2 | * static char *rcsid_metaserver_c = |
3 | * "$Id: metaserver.c,v 1.2 2006/02/12 13:09:15 root Exp $"; |
3 | * "$Id: metaserver.c,v 1.8 2006/07/16 18:01:32 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
118 | * Updates our info in the metaserver |
118 | * Updates our info in the metaserver |
119 | */ |
119 | */ |
120 | void metaserver_update(void) |
120 | void metaserver_update(void) |
121 | { |
121 | { |
122 | char data[MAX_BUF], num_players=0; |
122 | char data[MAX_BUF], num_players=0; |
123 | #define CAT2_SUXX |
|
|
124 | #ifdef CAT2_SUXX |
|
|
125 | num_players += 18 + rand() % 5; |
|
|
126 | #endif |
|
|
127 | player *pl; |
123 | player *pl; |
128 | |
124 | |
129 | if (metafd == -1) return; /* No valid connection */ |
125 | if (metafd == -1) return; /* No valid connection */ |
130 | |
126 | |
131 | /* We could use socket_info.nconns, but that is not quite as accurate, |
127 | /* We could use socket_info.nconns, but that is not quite as accurate, |
132 | * as connections in the progress of being established, are listening |
128 | * as connections in the progress of being established, are listening |
133 | * but don't have a player, etc. This operation below should not be that |
129 | * but don't have a player, etc. The checks below are basically the |
134 | * costly. |
130 | * same as for the who commands with the addition that WIZ, AFK, and BOT |
|
|
131 | * players are not counted. |
135 | */ |
132 | */ |
136 | for (pl=first_player; pl!=NULL; pl=pl->next) { |
133 | for (pl=first_player; pl!=NULL; pl=pl->next) { |
137 | if (!pl->hidden) num_players++; |
134 | if (pl->ob->map == NULL) continue; |
|
|
135 | if (pl->hidden) continue; |
|
|
136 | if (QUERY_FLAG(pl->ob, FLAG_WIZ)) continue; |
|
|
137 | if (QUERY_FLAG(pl->ob, FLAG_AFK)) continue; |
|
|
138 | if (pl->state != ST_PLAYING && pl->state != ST_GET_PARTY_PASSWORD) continue; |
|
|
139 | if (pl->socket.is_bot) continue; |
|
|
140 | num_players++; |
138 | } |
141 | } |
139 | |
142 | |
140 | sprintf(data,"%s|%d|%s|%s|%d|%d|%ld", settings.meta_host, num_players, VERSION, |
143 | sprintf(data,"%s|%d|%s|%s|%d|%d|%ld", settings.meta_host, num_players, VERSION "+", |
141 | settings.meta_comment, cst_tot.ibytes, cst_tot.obytes, |
144 | settings.meta_comment, cst_tot.ibytes, cst_tot.obytes, |
142 | (long)time(NULL) - cst_tot.time_start); |
145 | (long)time(NULL) - cst_tot.time_start); |
143 | if (sendto(metafd, data, strlen(data), 0, (struct sockaddr *)&sock, sizeof(sock))<0) { |
146 | if (sendto(metafd, data, strlen(data), 0, (struct sockaddr *)&sock, sizeof(sock))<0) { |
144 | LOG(llevDebug,"metaserver_update: sendto failed, err = %d\n", errno); |
147 | LOG(llevDebug,"metaserver_update: sendto failed, err = %d\n", errno); |
145 | } |
148 | } |