mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-22 03:31:34 +00:00
start working on server connections. can add, list and delete servers
This commit is contained in:
parent
ac67a50a9a
commit
e303db1687
5 changed files with 199 additions and 2 deletions
qtv
|
@ -1,4 +1,4 @@
|
||||||
## Process this file with automake to produce Makefile.in
|
## Process this file with automake to produce Makefile.in
|
||||||
AUTOMAKE_OPTIONS= foreign
|
AUTOMAKE_OPTIONS= foreign
|
||||||
|
|
||||||
EXTRA_DIST =
|
EXTRA_DIST = server.h
|
||||||
|
|
45
qtv/include/server.h
Normal file
45
qtv/include/server.h
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
#FILENAME#
|
||||||
|
|
||||||
|
#DESCRIPTION#
|
||||||
|
|
||||||
|
Copyright (C) 2004 #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
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __server_h
|
||||||
|
#define __server_h
|
||||||
|
|
||||||
|
#include "netchan.h"
|
||||||
|
|
||||||
|
typedef struct server_s {
|
||||||
|
const char *name;
|
||||||
|
const char *address;
|
||||||
|
netchan_t netchan;
|
||||||
|
} server_t;
|
||||||
|
|
||||||
|
void Server_Init (void);
|
||||||
|
|
||||||
|
#endif//__server_h
|
|
@ -43,7 +43,7 @@ qtv_LIBS= \
|
||||||
$(top_builddir)/libs/console/libQFconsole.la \
|
$(top_builddir)/libs/console/libQFconsole.la \
|
||||||
$(top_builddir)/libs/util/libQFutil.la
|
$(top_builddir)/libs/util/libQFutil.la
|
||||||
|
|
||||||
qtv_SOURCES= qtv.c
|
qtv_SOURCES= qtv.c server.c
|
||||||
qtv_LDADD= $(qtv_LIBS) $(NET_LIBS) $(DL_LIBS) $(CURSES_LIBS)
|
qtv_LDADD= $(qtv_LIBS) $(NET_LIBS) $(DL_LIBS) $(CURSES_LIBS)
|
||||||
qtv_LDFLAGS= $(common_ldflags)
|
qtv_LDFLAGS= $(common_ldflags)
|
||||||
qtv_DEPENDENCIES= $(qtv_LIBS)
|
qtv_DEPENDENCIES= $(qtv_LIBS)
|
||||||
|
|
|
@ -49,6 +49,7 @@ static __attribute__ ((unused)) const char rcsid[] =
|
||||||
#include "QF/zone.h"
|
#include "QF/zone.h"
|
||||||
|
|
||||||
#include "netchan.h"
|
#include "netchan.h"
|
||||||
|
#include "server.h"
|
||||||
|
|
||||||
SERVER_PLUGIN_PROTOS
|
SERVER_PLUGIN_PROTOS
|
||||||
static plugin_list_t server_plugin_list[] = {
|
static plugin_list_t server_plugin_list[] = {
|
||||||
|
@ -80,6 +81,13 @@ qtv_memory_init (void)
|
||||||
Memory_Init (mem_base, mem_size);
|
Memory_Init (mem_base, mem_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
qtv_shutdown (void)
|
||||||
|
{
|
||||||
|
NET_Shutdown ();
|
||||||
|
Con_Shutdown ();
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
qtv_quit_f (void)
|
qtv_quit_f (void)
|
||||||
{
|
{
|
||||||
|
@ -92,6 +100,8 @@ qtv_init (void)
|
||||||
{
|
{
|
||||||
qtv_cbuf = Cbuf_New (&id_interp);
|
qtv_cbuf = Cbuf_New (&id_interp);
|
||||||
|
|
||||||
|
Sys_RegisterShutdown (qtv_shutdown);
|
||||||
|
|
||||||
Cvar_Init_Hash ();
|
Cvar_Init_Hash ();
|
||||||
Cmd_Init_Hash ();
|
Cmd_Init_Hash ();
|
||||||
Cvar_Init ();
|
Cvar_Init ();
|
||||||
|
@ -137,6 +147,8 @@ qtv_init (void)
|
||||||
Cmd_StuffCmds (qtv_cbuf);
|
Cmd_StuffCmds (qtv_cbuf);
|
||||||
Cbuf_Execute_Sets (qtv_cbuf);
|
Cbuf_Execute_Sets (qtv_cbuf);
|
||||||
|
|
||||||
|
Server_Init ();
|
||||||
|
|
||||||
Cmd_AddCommand ("quit", qtv_quit_f, "Shut down qtv");
|
Cmd_AddCommand ("quit", qtv_quit_f, "Shut down qtv");
|
||||||
|
|
||||||
Cmd_StuffCmds (qtv_cbuf);
|
Cmd_StuffCmds (qtv_cbuf);
|
||||||
|
|
140
qtv/source/server.c
Normal file
140
qtv/source/server.c
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
/*
|
||||||
|
#FILENAME#
|
||||||
|
|
||||||
|
#DESCRIPTION#
|
||||||
|
|
||||||
|
Copyright (C) 2004 #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__ ((unused)) const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
|
|
||||||
|
#ifdef HAVE_STRING_H
|
||||||
|
# include <string.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_STRINGS_H
|
||||||
|
# include <strings.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "QF/cmd.h"
|
||||||
|
#include "QF/console.h"
|
||||||
|
#include "QF/hash.h"
|
||||||
|
|
||||||
|
#include "server.h"
|
||||||
|
|
||||||
|
static hashtab_t *servers;
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
server_get_key (void *sv, void *unused)
|
||||||
|
{
|
||||||
|
return ((server_t *) sv)->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
server_free (void *_sv, void *unused)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
server_compare (const void *a, const void *b)
|
||||||
|
{
|
||||||
|
return strcmp ((*(server_t **) a)->name, (*(server_t **) b)->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sv_new_f (void)
|
||||||
|
{
|
||||||
|
const char *name;
|
||||||
|
const char *address;
|
||||||
|
server_t *sv;
|
||||||
|
|
||||||
|
if (Cmd_Argc () != 3) {
|
||||||
|
Con_Printf ("Usage: sv_new <name> <address>\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
name = Cmd_Argv (1);
|
||||||
|
if (Hash_Find (servers, name)) {
|
||||||
|
Con_Printf ("sv_new: %s already exists\n", name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
address = Cmd_Argv (2);
|
||||||
|
sv = calloc (1, sizeof (server_t));
|
||||||
|
sv->name = strdup (name);
|
||||||
|
sv->address = strdup (address);
|
||||||
|
Hash_Add (servers, sv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sv_del_f (void)
|
||||||
|
{
|
||||||
|
const char *name;
|
||||||
|
server_t *sv;
|
||||||
|
|
||||||
|
if (Cmd_Argc () != 2) {
|
||||||
|
Con_Printf ("Usage: sv_del <name>\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
name = Cmd_Argv (1);
|
||||||
|
if (!(sv = Hash_Del (servers, name))) {
|
||||||
|
Con_Printf ("sv_new: %s unkown\n", name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Hash_Free (servers, sv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sv_list_f (void)
|
||||||
|
{
|
||||||
|
server_t **list, **l, *sv;
|
||||||
|
int count;
|
||||||
|
|
||||||
|
list = (server_t **) Hash_GetList (servers);
|
||||||
|
for (l = list, count = 0; *l; l++)
|
||||||
|
count++;
|
||||||
|
if (!count) {
|
||||||
|
Con_Printf ("no servers\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qsort (list, count, sizeof (*list), server_compare);
|
||||||
|
for (l = list; *l; l++) {
|
||||||
|
sv = *l;
|
||||||
|
Con_Printf ("%-20s %s\n", sv->name, sv->address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Server_Init (void)
|
||||||
|
{
|
||||||
|
servers = Hash_NewTable (61, server_get_key, server_free, 0);
|
||||||
|
Cmd_AddCommand ("sv_new", sv_new_f, "Add a new server");
|
||||||
|
Cmd_AddCommand ("sv_del", sv_del_f, "Remove an existing server");
|
||||||
|
Cmd_AddCommand ("sv_list", sv_list_f, "List available servers");
|
||||||
|
}
|
Loading…
Reference in a new issue