diff --git a/qtv/include/client.h b/qtv/include/client.h index e1d87e7ab..cc281f0c5 100644 --- a/qtv/include/client.h +++ b/qtv/include/client.h @@ -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 diff --git a/qtv/include/qtv.h b/qtv/include/qtv.h index 9e0b4b3cb..fb1d5204b 100644 --- a/qtv/include/qtv.h +++ b/qtv/include/qtv.h @@ -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 diff --git a/qtv/include/server.h b/qtv/include/server.h index 4552977ea..6701025f2 100644 --- a/qtv/include/server.h +++ b/qtv/include/server.h @@ -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 diff --git a/qtv/source/Makefile.am b/qtv/source/Makefile.am index 1c8719211..79cad8ec8 100644 --- a/qtv/source/Makefile.am +++ b/qtv/source/Makefile.am @@ -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) diff --git a/qtv/source/client.c b/qtv/source/client.c index 370f00388..5bc526a6b 100644 --- a/qtv/source/client.c +++ b/qtv/source/client.c @@ -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); } diff --git a/qtv/source/qtv.c b/qtv/source/qtv.c index 34756bca4..d1bf77549 100644 --- a/qtv/source/qtv.c +++ b/qtv/source/qtv.c @@ -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; } diff --git a/qtv/source/sbar.c b/qtv/source/sbar.c new file mode 100644 index 000000000..ce6a7a3a8 --- /dev/null +++ b/qtv/source/sbar.c @@ -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); +} diff --git a/qtv/source/server.c b/qtv/source/server.c index b7ebd0662..253fbf119 100644 --- a/qtv/source/server.c +++ b/qtv/source/server.c @@ -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);