mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-13 12:51:54 +00:00
move maplist from quakefs.c to console/maplist.c. Unfortunatly, until the
client console plugin is usable, this means the clients link maplist.o directly.
This commit is contained in:
parent
460b53e9ee
commit
15b381909e
10 changed files with 238 additions and 149 deletions
|
@ -128,4 +128,6 @@ void Con_Shutdown (void);
|
|||
|
||||
void Con_ProcessInput (void);
|
||||
|
||||
void Con_Maplist_f (void);
|
||||
|
||||
#endif // __console_h
|
||||
|
|
|
@ -38,6 +38,31 @@
|
|||
|
||||
#define MAX_OSPATH 128 // max length of a filesystem pathname
|
||||
|
||||
/*
|
||||
In-memory pack file structs
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
char name[MAX_QPATH];
|
||||
int filepos, filelen;
|
||||
} packfile_t;
|
||||
|
||||
typedef struct pack_s {
|
||||
char filename[MAX_OSPATH];
|
||||
VFile *handle;
|
||||
int numfiles;
|
||||
packfile_t *files;
|
||||
struct hashtab_s *file_hash;
|
||||
} pack_t;
|
||||
|
||||
typedef struct searchpath_s {
|
||||
char filename[MAX_OSPATH];
|
||||
pack_t *pack; // only one of filename / pack will be used
|
||||
struct searchpath_s *next;
|
||||
} searchpath_t;
|
||||
|
||||
extern searchpath_t *com_searchpaths;
|
||||
|
||||
extern struct cvar_s *fs_userpath;
|
||||
extern struct cvar_s *fs_sharepath;
|
||||
extern struct cvar_s *fs_basegame;
|
||||
|
@ -74,7 +99,6 @@ void COM_Gamedir (const char *dir);
|
|||
void COM_Filesystem_Init (void);
|
||||
void COM_Filesystem_Init_Cvars (void);
|
||||
void COM_Path_f (void);
|
||||
void COM_Maplist_f (void);
|
||||
void COM_CreateGameDirectory (const char *gamename);
|
||||
|
||||
#endif // __quakefs_h
|
||||
|
|
|
@ -3,7 +3,7 @@ INCLUDES= -I$(top_srcdir)/include
|
|||
lib_LTLIBRARIES= libQFconsole.la
|
||||
plugin_LTLIBRARIES= libconsole_server.la #libconsole_client.la
|
||||
|
||||
common_sources= buffer.c complete.c console.c inputline.c list.c
|
||||
common_sources= buffer.c complete.c console.c inputline.c list.c maplist.c
|
||||
client_sources= client.c
|
||||
server_sources= server.c
|
||||
|
||||
|
|
203
libs/console/maplist.c
Normal file
203
libs/console/maplist.c
Normal file
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
maplist.c
|
||||
|
||||
maplist command
|
||||
|
||||
Copyright (C) 1996-1997 Id Software, Inc.
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef HAVE_FNMATCH_H
|
||||
# define model_t sunmodel_t
|
||||
# include <fnmatch.h>
|
||||
# undef model_t
|
||||
#else
|
||||
# ifdef WIN32
|
||||
# include "fnmatch.h"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_IO_H
|
||||
# include <io.h>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define _POSIX_
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "QF/cmd.h"
|
||||
#include "QF/console.h" //FIXME maplist really shouldn't be in here
|
||||
#include "QF/cvar.h"
|
||||
#include "QF/hash.h"
|
||||
#include "QF/qargs.h"
|
||||
#include "QF/qendian.h"
|
||||
#include "QF/qtypes.h"
|
||||
#include "QF/sys.h"
|
||||
#include "QF/va.h"
|
||||
#include "QF/vfs.h"
|
||||
#include "QF/zone.h"
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
#ifndef HAVE_FNMATCH_PROTO
|
||||
int fnmatch (const char *__pattern, const char *__string, int __flags);
|
||||
#endif
|
||||
|
||||
struct maplist {
|
||||
char **list;
|
||||
int count;
|
||||
int size;
|
||||
};
|
||||
|
||||
static struct maplist *
|
||||
maplist_new (void)
|
||||
{
|
||||
return calloc (1, sizeof (struct maplist));
|
||||
}
|
||||
|
||||
static void
|
||||
maplist_free (struct maplist *maplist)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < maplist->count; i++)
|
||||
free (maplist->list[i]);
|
||||
free (maplist->list);
|
||||
free (maplist);
|
||||
}
|
||||
|
||||
static void
|
||||
maplist_add_map (struct maplist *maplist, char *fname)
|
||||
{
|
||||
char **new_list;
|
||||
|
||||
if (maplist->count == maplist->size) {
|
||||
maplist->size += 32;
|
||||
new_list = realloc (maplist->list, maplist->size * sizeof (char *));
|
||||
|
||||
if (!new_list) {
|
||||
maplist->size -= 32;
|
||||
return;
|
||||
}
|
||||
maplist->list = new_list;
|
||||
}
|
||||
fname = strdup (fname);
|
||||
*strstr (fname, ".bsp") = 0;
|
||||
maplist->list[maplist->count++] = fname;
|
||||
}
|
||||
|
||||
static int
|
||||
maplist_cmp (const void *_a, const void *_b)
|
||||
{
|
||||
char *a = *(char **) _a;
|
||||
char *b = *(char **) _b;
|
||||
|
||||
return strcmp (a, b);
|
||||
}
|
||||
|
||||
static void
|
||||
maplist_print (struct maplist *maplist)
|
||||
{
|
||||
int i;
|
||||
const char **list;
|
||||
|
||||
if (maplist->count) {
|
||||
qsort (maplist->list, maplist->count, sizeof (char *), maplist_cmp);
|
||||
|
||||
list = (const char **)malloc (maplist->count + 1);
|
||||
list[maplist->count] = 0;
|
||||
for (i = 0; i < maplist->count; i++)
|
||||
list[i] = maplist->list[i];
|
||||
Con_DisplayList (list, con_linewidth);
|
||||
free (list);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Con_Maplist_f
|
||||
|
||||
List map files in gamepaths.
|
||||
*/
|
||||
void
|
||||
Con_Maplist_f (void)
|
||||
{
|
||||
searchpath_t *search;
|
||||
DIR *dir_ptr;
|
||||
struct dirent *dirent;
|
||||
char buf[MAX_OSPATH];
|
||||
|
||||
for (search = com_searchpaths; search != NULL; search = search->next) {
|
||||
if (search->pack) {
|
||||
int i;
|
||||
pack_t *pak = search->pack;
|
||||
struct maplist *maplist = maplist_new ();
|
||||
|
||||
Sys_Printf ("Looking in %s...\n", search->pack->filename);
|
||||
for (i = 0; i < pak->numfiles; i++) {
|
||||
char *name = pak->files[i].name;
|
||||
|
||||
if (!fnmatch ("maps/*.bsp", name, FNM_PATHNAME)
|
||||
|| !fnmatch ("maps/*.bsp.gz", name, FNM_PATHNAME))
|
||||
maplist_add_map (maplist, name + 5);
|
||||
}
|
||||
maplist_print (maplist);
|
||||
maplist_free (maplist);
|
||||
} else {
|
||||
struct maplist *maplist = maplist_new ();
|
||||
|
||||
snprintf (buf, sizeof (buf), "%s/maps", search->filename);
|
||||
dir_ptr = opendir (buf);
|
||||
Sys_Printf ("Looking in %s...\n", buf);
|
||||
if (!dir_ptr)
|
||||
continue;
|
||||
while ((dirent = readdir (dir_ptr)))
|
||||
if (!fnmatch ("*.bsp", dirent->d_name, 0)
|
||||
|| !fnmatch ("*.bsp.gz", dirent->d_name, 0))
|
||||
maplist_add_map (maplist, dirent->d_name);
|
||||
closedir (dir_ptr);
|
||||
maplist_print (maplist);
|
||||
maplist_free (maplist);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -67,7 +67,6 @@ static const char rcsid[] =
|
|||
#include <limits.h>
|
||||
|
||||
#include "QF/cmd.h"
|
||||
#include "QF/console.h" //FIXME maplist really shouldn't be in here
|
||||
#include "QF/cvar.h"
|
||||
#include "QF/hash.h"
|
||||
#include "QF/qargs.h"
|
||||
|
@ -120,23 +119,6 @@ cvar_t *fs_skinbase;
|
|||
|
||||
int com_filesize;
|
||||
|
||||
/*
|
||||
In-memory pack file structs
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
char name[MAX_QPATH];
|
||||
int filepos, filelen;
|
||||
} packfile_t;
|
||||
|
||||
typedef struct pack_s {
|
||||
char filename[MAX_OSPATH];
|
||||
VFile *handle;
|
||||
int numfiles;
|
||||
packfile_t *files;
|
||||
hashtab_t *file_hash;
|
||||
} pack_t;
|
||||
|
||||
/*
|
||||
Structs for pack files on disk
|
||||
*/
|
||||
|
@ -155,13 +137,6 @@ typedef struct {
|
|||
|
||||
char com_gamedir[MAX_OSPATH];
|
||||
|
||||
typedef struct searchpath_s {
|
||||
char filename[MAX_OSPATH];
|
||||
pack_t *pack; // only one of filename / pack will
|
||||
// be used
|
||||
struct searchpath_s *next;
|
||||
} searchpath_t;
|
||||
|
||||
searchpath_t *com_searchpaths;
|
||||
searchpath_t *com_base_searchpaths; // without gamedirs
|
||||
|
||||
|
@ -242,124 +217,6 @@ COM_Path_f (void)
|
|||
}
|
||||
}
|
||||
|
||||
struct maplist {
|
||||
char **list;
|
||||
int count;
|
||||
int size;
|
||||
};
|
||||
|
||||
static struct maplist *
|
||||
maplist_new (void)
|
||||
{
|
||||
return calloc (1, sizeof (struct maplist));
|
||||
}
|
||||
|
||||
static void
|
||||
maplist_free (struct maplist *maplist)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < maplist->count; i++)
|
||||
free (maplist->list[i]);
|
||||
free (maplist->list);
|
||||
free (maplist);
|
||||
}
|
||||
|
||||
static void
|
||||
maplist_add_map (struct maplist *maplist, char *fname)
|
||||
{
|
||||
char **new_list;
|
||||
|
||||
if (maplist->count == maplist->size) {
|
||||
maplist->size += 32;
|
||||
new_list = realloc (maplist->list, maplist->size * sizeof (char *));
|
||||
|
||||
if (!new_list) {
|
||||
maplist->size -= 32;
|
||||
return;
|
||||
}
|
||||
maplist->list = new_list;
|
||||
}
|
||||
fname = strdup (fname);
|
||||
*strstr (fname, ".bsp") = 0;
|
||||
maplist->list[maplist->count++] = fname;
|
||||
}
|
||||
|
||||
static int
|
||||
maplist_cmp (const void *_a, const void *_b)
|
||||
{
|
||||
char *a = *(char **) _a;
|
||||
char *b = *(char **) _b;
|
||||
|
||||
return strcmp (a, b);
|
||||
}
|
||||
|
||||
static void
|
||||
maplist_print (struct maplist *maplist)
|
||||
{
|
||||
int i;
|
||||
const char **list;
|
||||
|
||||
if (maplist->count) {
|
||||
qsort (maplist->list, maplist->count, sizeof (char *), maplist_cmp);
|
||||
|
||||
list = (const char **)malloc (maplist->count + 1);
|
||||
list[maplist->count] = 0;
|
||||
for (i = 0; i < maplist->count; i++)
|
||||
list[i] = maplist->list[i];
|
||||
Con_DisplayList (list, con_linewidth);
|
||||
free (list);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
COM_Maplist_f
|
||||
|
||||
List map files in gamepaths.
|
||||
*/
|
||||
void
|
||||
COM_Maplist_f (void)
|
||||
{
|
||||
searchpath_t *search;
|
||||
DIR *dir_ptr;
|
||||
struct dirent *dirent;
|
||||
char buf[MAX_OSPATH];
|
||||
|
||||
for (search = com_searchpaths; search != NULL; search = search->next) {
|
||||
if (search->pack) {
|
||||
int i;
|
||||
pack_t *pak = search->pack;
|
||||
struct maplist *maplist = maplist_new ();
|
||||
|
||||
Sys_Printf ("Looking in %s...\n", search->pack->filename);
|
||||
for (i = 0; i < pak->numfiles; i++) {
|
||||
char *name = pak->files[i].name;
|
||||
|
||||
if (!fnmatch ("maps/*.bsp", name, FNM_PATHNAME)
|
||||
|| !fnmatch ("maps/*.bsp.gz", name, FNM_PATHNAME))
|
||||
maplist_add_map (maplist, name + 5);
|
||||
}
|
||||
maplist_print (maplist);
|
||||
maplist_free (maplist);
|
||||
} else {
|
||||
struct maplist *maplist = maplist_new ();
|
||||
|
||||
snprintf (buf, sizeof (buf), "%s/maps", search->filename);
|
||||
dir_ptr = opendir (buf);
|
||||
Sys_Printf ("Looking in %s...\n", buf);
|
||||
if (!dir_ptr)
|
||||
continue;
|
||||
while ((dirent = readdir (dir_ptr)))
|
||||
if (!fnmatch ("*.bsp", dirent->d_name, 0)
|
||||
|| !fnmatch ("*.bsp.gz", dirent->d_name, 0))
|
||||
maplist_add_map (maplist, dirent->d_name);
|
||||
closedir (dir_ptr);
|
||||
maplist_print (maplist);
|
||||
maplist_free (maplist);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
COM_WriteFile
|
||||
|
||||
|
|
|
@ -63,7 +63,8 @@ EXTRA_libqfnet_la_SOURCES= \
|
|||
client_LIBFILES= \
|
||||
$(top_builddir)/libs/video/targets/libQFjs.la \
|
||||
$(top_builddir)/libs/audio/libQFcd.la \
|
||||
$(top_builddir)/libs/audio/libQFsound.la
|
||||
$(top_builddir)/libs/audio/libQFsound.la \
|
||||
$(top_builddir)/libs/console/maplist.o
|
||||
|
||||
server_LIBFILES= \
|
||||
$(top_builddir)/libs/models/libQFmodels.la \
|
||||
|
|
|
@ -738,7 +738,7 @@ CL_Init (void)
|
|||
Cmd_AddCommand ("stop", CL_Stop_f, "No Description");
|
||||
Cmd_AddCommand ("playdemo", CL_PlayDemo_f, "No Description");
|
||||
Cmd_AddCommand ("timedemo", CL_TimeDemo_f, "No Description");
|
||||
Cmd_AddCommand ("maplist", COM_Maplist_f, "No Description");
|
||||
Cmd_AddCommand ("maplist", Con_Maplist_f, "No Description");
|
||||
Cmd_AddCommand ("force_centerview", Force_CenterView_f, "force the view "
|
||||
"to be level");
|
||||
|
||||
|
|
|
@ -103,6 +103,7 @@ qf_client_LIBS= \
|
|||
$(top_builddir)/libs/gamecode/builtins/libQFgamecode_builtins.la \
|
||||
$(top_builddir)/libs/audio/libQFcd.la \
|
||||
$(top_builddir)/libs/audio/libQFsound.la \
|
||||
$(top_builddir)/libs/console/maplist.o \
|
||||
$(top_builddir)/libs/util/libQFutil.la
|
||||
|
||||
client_LIBS= libqfnet.la libasm.la $(qf_client_LIBS) $(NET_LIBS)
|
||||
|
|
|
@ -1130,7 +1130,7 @@ CL_Init (void)
|
|||
Cmd_AddCommand ("playdemo", CL_PlayDemo_f, "Play a recorded demo");
|
||||
Cmd_AddCommand ("timedemo", CL_TimeDemo_f, "Play a demo as fast as your "
|
||||
"hardware can. Useful for benchmarking.");
|
||||
Cmd_AddCommand ("maplist", COM_Maplist_f, "List maps available");
|
||||
Cmd_AddCommand ("maplist", Con_Maplist_f, "List maps available");
|
||||
Cmd_AddCommand ("quit", CL_Quit_f, "Exit the program");
|
||||
Cmd_AddCommand ("connect", CL_Connect_f, "Connect to a server 'connect "
|
||||
"hostname:port'");
|
||||
|
|
|
@ -41,6 +41,7 @@ static const char rcsid[] =
|
|||
#include <ctype.h>
|
||||
|
||||
#include "QF/cmd.h"
|
||||
#include "QF/console.h"
|
||||
#include "QF/cvar.h"
|
||||
#include "QF/msg.h"
|
||||
#include "QF/qargs.h"
|
||||
|
@ -1202,7 +1203,7 @@ SV_InitOperatorCommands (void)
|
|||
Cmd_AddCommand ("floodprotmsg", SV_Floodprotmsg_f, "Sets the message "
|
||||
"displayed after flood protection is invoked (floodprotmsg "
|
||||
"message)");
|
||||
Cmd_AddCommand ("maplist", COM_Maplist_f, "List all maps on the server");
|
||||
Cmd_AddCommand ("maplist", Con_Maplist_f, "List all maps on the server");
|
||||
Cmd_AddCommand ("say", SV_ConSay_f, "Say something to everyone on the "
|
||||
"server. Will show up as the name 'Console' (or 'Admin') "
|
||||
"in game");
|
||||
|
|
Loading…
Reference in a new issue