- store when a server was last up, display this date in red if it's more than

three days older than the last refresh. Necessary change to ~/.qf/srvinfo.gz
  is backward and forward compatible.
- util function timet2string, it has yet to be verified this one works on
  none-linux system too.
- use setlocale(LC_ALL, "");


git-svn-id: http://svn.code.sf.net/p/xqf/code/trunk@391 d2ac09be-c843-0410-8b1f-f8a84130e0ec
This commit is contained in:
Ludwig Nussel 2002-11-21 20:01:30 +00:00 committed by l-n
parent 8c848c303a
commit ba2ad8fc44
9 changed files with 130 additions and 30 deletions

View File

@ -1,3 +1,11 @@
Nov 21, 2002: Ludwig Nussel <l-n@users.sourceforge.net>
- store when a server was last up, display this date in red if it's more than
three days older than the last refresh. Necessary change to ~/.qf/srvinfo.gz
is backward and forward compatible.
- util function timet2string, it has yet to be verified this one works on
none-linux system too.
- use setlocale(LC_ALL, "");
Nov 20, 2002: Ludwig Nussel <l-n@users.sourceforge.net>
- fix wrong pointer passed to userver_ref

View File

@ -3228,7 +3228,7 @@ static void quake_save_info (FILE *f, struct server *s) {
if (!s->name && !s->map && !s->players && !s->info && s->ping < 0)
return;
fprintf (f, "%ld\n", s->refreshed);
fprintf (f, "%ld %ld\n", s->refreshed, s->last_answer);
switch (s->type) {

View File

@ -326,9 +326,8 @@ static GtkWidget *server_info_page (struct server *s) {
struct server_props *props;
char buf[32];
GList *cfgs;
char *time_str;
char *tmp;
int slots_buffer;
guint row = 0;
@ -339,7 +338,7 @@ static GtkWidget *server_info_page (struct server *s) {
/* Address */
table = gtk_table_new (4, 4, FALSE);
table = gtk_table_new (5, 4, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 4);
gtk_table_set_col_spacings (GTK_TABLE (table), 8);
gtk_box_pack_start (GTK_BOX (page_vbox), table, FALSE, FALSE, 0);
@ -348,56 +347,95 @@ static GtkWidget *server_info_page (struct server *s) {
label = gtk_label_new (_("IP Address:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 0, 1);
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, row, row+1);
gtk_widget_show (label);
label = gtk_label_new (inet_ntoa (s->host->ip));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 2, 0, 1);
gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 2, row, row+1);
gtk_widget_show (label);
label = gtk_label_new (_("Port:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach_defaults (GTK_TABLE (table), label, 2, 3, 0, 1);
gtk_table_attach_defaults (GTK_TABLE (table), label, 2, 3, row, row+1);
gtk_widget_show (label);
g_snprintf (buf, 32, "%d", s->port);
label = gtk_label_new (buf);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach_defaults (GTK_TABLE (table), label, 3, 4, 0, 1);
gtk_table_attach_defaults (GTK_TABLE (table), label, 3, 4, row, row+1);
gtk_widget_show (label);
row++;
label = gtk_label_new (_("Host Name:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 1, 2);
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, row, row+1);
gtk_widget_show (label);
if (s->host->name) {
label = gtk_label_new (s->host->name);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 4, 1, 2);
gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 4, row, row+1);
gtk_widget_show (label);
}
row++;
label = gtk_label_new (_("Refreshed:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 2, 3);
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, row, row+1);
gtk_widget_show (label);
if (s->refreshed) {
time_str = ctime (&s->refreshed);
char* str = timet2string(&s->refreshed);
tmp = strchr (time_str, '\n');
if (tmp)
*tmp = '\0';
label = gtk_label_new (time_str);
label = gtk_label_new (str);
g_free(str);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 4, 2, 3);
gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 4, row, row+1);
gtk_widget_show (label);
}
row++;
// translator: last time and date the server answered the query
label = gtk_label_new (_("Last answer:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, row, row+1);
gtk_widget_show (label);
if (s->last_answer) {
GtkStyle *style;
GdkColor color;
guint max_days = 3; // XXX: hardcoded, has to be configurable some time
char* str = timet2string(&s->last_answer);
label = gtk_label_new (str);
g_free(str);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 4, row, row+1);
if(s->last_answer + max_days*24*60*60 < s->refreshed)
{
// XXX: I don't know if that is the correct way, it's undocumented :-(
style = gtk_widget_get_style(label);
gdk_color_parse("red",&color);
style->fg [GTK_STATE_NORMAL] = color;
style->fg [GTK_STATE_ACTIVE] = color;
style->fg [GTK_STATE_PRELIGHT] = color;
style->fg [GTK_STATE_SELECTED] = color;
style->fg [GTK_STATE_INSENSITIVE] = color;
gtk_widget_set_style (label, style);
}
gtk_widget_show (label);
}
row++;
/*pulp*/ /*Reserved Slots spin widget*/
@ -422,7 +460,7 @@ static GtkWidget *server_info_page (struct server *s) {
label = gtk_label_new (_("Reserved Slots:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 3, 4);
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, row, row+1);
gtk_widget_show (label);
@ -430,7 +468,7 @@ static GtkWidget *server_info_page (struct server *s) {
spinner = gtk_spin_button_new (adj, 0, 0);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinner), TRUE);
gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON (spinner), GTK_UPDATE_IF_VALID);
gtk_table_attach_defaults (GTK_TABLE (table), spinner, 1, 2, 3, 4);
gtk_table_attach_defaults (GTK_TABLE (table), spinner, 1, 2, row, row+1);
gtk_widget_show (spinner);

View File

@ -439,6 +439,11 @@ static struct server *parse_server (char *token[], int n, time_t refreshed,
}
}
if(!saved && server->ping<MAX_PING)
{
server->last_answer = server->refreshed;
}
return server;
}
@ -530,19 +535,43 @@ void parse_saved_server (GSList *strings) {
struct server *server;
char *token[16];
int n;
time_t refreshed;
time_t refreshed = 0;
time_t last_answer = 0;
char *endptr;
char** refreshdata = NULL;
if (!strings || !strings->next)
return;
refreshed = strtoul ((char *) strings->data, &endptr, 10);
// first line contains seconds of last refresh and last answer
refreshdata = g_strsplit(strings->data," ",2);
if (endptr == strings->data) /* It's not a number */
if(!refreshdata || !refreshdata[0])
{
debug(0,"refreshdata empty");
return;
}
refreshed = strtoul (refreshdata[0], &endptr, 10);
if (endptr == refreshdata[0]) /* It's not a number */
return;
if(refreshdata[1]) // post 0.9.10 format
{
last_answer = strtoul (refreshdata[1], &endptr, 10);
if (endptr == refreshdata[1]) /* It's not a number */
return;
}
g_strfreev(refreshdata);
refreshdata = NULL;
strings = strings->next;
debug (6, "parse_saved_server() -- ");
if(!strings) return;
n = tokenize_bychar ((char *) strings->data, token, 16, QSTAT_DELIM);
if (n < 3)
return;
@ -557,6 +586,7 @@ void parse_saved_server (GSList *strings) {
if (server) {
server_ref (server);
parse_qstat_record_part2 (strings->next, server);
server->last_answer=last_answer;
server_unref (server);
}
}

View File

@ -16,6 +16,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include "gnuconfig.h"
#include <sys/types.h> /* getpwnam, readdir, dirent */
#include <stdio.h> /* FILE, putc */
#include <string.h> /* strlen, strncpy, strcmp, strspn, strcspn, strchr */
@ -32,6 +34,7 @@
#include "utils.h"
#include "debug.h"
#include "i18n.h"
short strtosh (const char *str) {
@ -750,3 +753,22 @@ char* resolve_path(const char* path)
return dir;
}
// return locale's string representation of t. must be freed manually
char* timet2string(const time_t* t)
{
enum { timebuf_len = 128 };
char timebuf[timebuf_len] = {0};
struct tm tm_s;
char* str;
gmtime_r(t,&tm_s);
if(!strftime(timebuf,timebuf_len,"%c",&tm_s))
{
// error converting time to string representation, shouldn't happen
str=_("<error>");
}
else
str = timebuf;
return strdup(str);
}

View File

@ -21,6 +21,7 @@
#include <sys/types.h>
#include <stdio.h> /* FILE */
#include <time.h>
#include <glib.h>
@ -90,4 +91,9 @@ char* find_file_in_path(const char* files);
*/
GSList* slist_sort_remove_dups(GSList* list, GCompareFunc compare_func, void (*unref_func)(void*));
/**
* return locale's string representation of t. must be freed manually
*/
char* timet2string(const time_t* t);
#endif /* __UTILS_H__ */

View File

@ -3226,12 +3226,7 @@ int main (int argc, char *argv[]) {
redialserver=0;
#ifdef ENABLE_NLS
# ifdef HAVE_LC_MESSAGES
setlocale(LC_CTYPE, "");
setlocale(LC_MESSAGES, "");
# else
setlocale(LC_ALL, "");
# endif
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
#endif

View File

@ -183,6 +183,7 @@ struct server {
unsigned private_client; /* number of private clients */
time_t refreshed;
time_t last_answer;
int ref_count;
};

View File

@ -49,7 +49,7 @@ rm -rf $RPM_BUILD_ROOT
%defattr (-,root,root)
%doc AUTHORS BUGS COPYING ChangeLog NEWS README TODO
%doc docs/*html
%{_prefix}/bin/xqf
%{_prefix}/bin/*
%{_mandir}/man?/xqf.*
%{_prefix}/share/locale/*/LC_MESSAGES/xqf.mo