Add some info to the qtv status bar.

For now, server and client counts.
This commit is contained in:
Bill Currie 2010-12-21 18:15:31 +09:00
parent 7853366697
commit 676e9a2292
8 changed files with 117 additions and 1 deletions

View file

@ -77,4 +77,6 @@ void Client_SendMessages (client_t *cl);
void Client_New (client_t *cl);
void Client_Frame (void);
extern int client_count;
#endif//__client_h

View file

@ -89,6 +89,9 @@ void qtv_begin_redirect (redirect_t rd, struct client_s *cl);
*/
void qtv_end_redirect (void);
void qtv_sbar_init (void);
//@}
#endif//__qtv_h

View file

@ -119,4 +119,6 @@ struct qmsg_s;
void sv_parse (server_t *sv, struct msg_s *msg, int reliable);
void sv_stringcmd (server_t *sv, struct msg_s *msg);
extern int server_count;
#endif//__server_h

View file

@ -44,7 +44,7 @@ qtv_LIBS= \
$(top_builddir)/libs/console/libQFconsole.la \
$(top_builddir)/libs/util/libQFutil.la
qtv_SOURCES= client.c connection.c qtv.c server.c sv_parse.c
qtv_SOURCES= client.c connection.c qtv.c sbar.c server.c sv_parse.c
qtv_LDADD= $(qtv_LIBS) $(NET_LIBS) $(DL_LIBS) $(CURSES_LIBS)
qtv_LDFLAGS= $(common_ldflags)
qtv_DEPENDENCIES= $(qtv_LIBS)

View file

@ -63,6 +63,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include "qtv.h"
#include "server.h"
int client_count;
static client_t *clients;
typedef struct ucmd_s {
@ -1146,6 +1147,7 @@ client_connect (connection_t *con, void *object)
}
cl = calloc (1, sizeof (client_t));
client_count++;
Netchan_Setup (&cl->netchan, con->address, qport, NC_READ_QPORT);
cl->clnext = clients;
clients = cl;
@ -1245,6 +1247,7 @@ delete_client (client_t *cl)
Server_Disconnect (cl);
Connection_Del (cl->con);
Info_Destroy (cl->userinfo);
client_count--;
free (cl);
}

View file

@ -296,6 +296,8 @@ qtv_init (void)
con_module->data->console->cbuf = qtv_cbuf;
Sys_SetStdPrintf (qtv_print);
qtv_sbar_init ();
Netchan_Init_Cvars ();
Cmd_StuffCmds (qtv_cbuf);
@ -380,6 +382,8 @@ qtv_read_packets (void)
int
main (int argc, const char *argv[])
{
int frame = 0;
COM_InitArgv (argc, argv);
qtv_init ();
@ -398,6 +402,11 @@ main (int argc, const char *argv[])
Server_Frame ();
Client_Frame ();
if (++frame == 100) {
frame = 0;
Con_DrawConsole ();
}
}
return 0;
}

94
qtv/source/sbar.c Normal file
View file

@ -0,0 +1,94 @@
/*
#FILENAME#
#DESCRIPTION#
Copyright (C) 2007 #AUTHOR#
Author: #AUTHOR#
Date: #DATE#
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
static __attribute__ ((used)) const char rcsid[] =
"$Id: template.c 11394 2007-03-17 03:23:39Z taniwha $";
#include "QF/console.h"
#include "QF/plugin.h"
#include "QF/view.h"
#include "QF/va.h"
#include "client.h"
#include "server.h"
#include "sv_console.h"
#include "qtv.h"
static void
draw_clients (view_t *view)
{
sv_view_t *sv_view = view->data;
sv_sbar_t *sb = sv_view->obj;
const char *str;
const char *s;
char *d;
str = va ("[CL: %3d]", client_count);
for (s = str, d = sb->text + view->xrel; *s; s++)
*d++ = *s;
}
static void
draw_servers (view_t *view)
{
sv_view_t *sv_view = view->data;
sv_sbar_t *sb = sv_view->obj;
const char *str;
const char *s;
char *d;
str = va ("[SV: %2d]", server_count);
for (s = str, d = sb->text + view->xrel; *s; s++)
*d++ = *s;
}
void
qtv_sbar_init (void)
{
view_t *status;
view_t *view;
if (!con_module || !con_module->data->console->status_view)
return;
status = con_module->data->console->status_view;
view = view_new (0, 0, 8, 1, grav_northwest);
view->draw = draw_servers;
view->data = status->data;
view_add (status, view);
view = view_new (8, 0, 9, 1, grav_northwest);
view->draw = draw_clients;
view->data = status->data;
view_add (status, view);
}

View file

@ -62,6 +62,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include "qtv.h"
#include "server.h"
int server_count;
static hashtab_t *server_hash;
static server_t *servers;
@ -108,6 +109,7 @@ server_free (void *_sv, void *unused)
cl->server = 0;
cl->connected = 0;
}
server_count--;
free (sv);
}
@ -444,6 +446,7 @@ sv_new_f (void)
adr.port = BigShort (27500);
sv = calloc (1, sizeof (server_t));
server_count++;
sv->next = servers;
servers = sv;
sv->name = strdup (name);