spingle/source/host_cmd.c

2343 lines
50 KiB
C
Raw Permalink Normal View History

2019-11-24 20:45:15 -08:00
/*
Copyright (C) 1996-2001 Id Software, Inc.
Copyright (C) 2002-2009 John Fitzgibbons and others
Copyright (C) 2007-2008 Kristian Duske
Copyright (C) 2010-2014 QuakeSpasm developers
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 the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
2019-12-02 07:07:37 -08:00
#include "q_defs.h"
2019-12-02 04:24:20 -08:00
#if !PLATFORM_IS(WINDOWS)
2019-11-24 20:45:15 -08:00
#include <dirent.h>
#endif
2019-11-25 17:40:18 -08:00
extern cvar_t pausable;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
int32_t current_skill;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
void Mod_Print(void);
2019-11-24 20:45:15 -08:00
/*
==================
Host_Quit_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Quit_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(key_dest != key_console && cls.state != ca_dedicated)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
M_Menu_Quit_f();
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
CL_Disconnect();
2019-11-24 20:45:15 -08:00
Host_ShutdownServer(false);
2019-11-25 17:40:18 -08:00
Sys_Quit();
2019-11-24 20:45:15 -08:00
}
//==============================================================================
//johnfitz -- extramaps management
//==============================================================================
/*
==================
FileList_Add
==================
*/
2019-11-25 17:40:18 -08:00
void FileList_Add(const char *name, filelist_item_t **list)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
filelist_item_t *item, *cursor, *prev;
2019-11-24 20:45:15 -08:00
// ignore duplicate
2019-11-25 17:40:18 -08:00
for(item = *list; item; item = item->next)
2019-11-24 20:45:15 -08:00
{
2019-12-07 09:27:26 -08:00
if(!strcmp(name, item->name))
2019-11-24 20:45:15 -08:00
return;
}
item = (filelist_item_t *) Z_Malloc(sizeof(filelist_item_t));
2019-11-25 17:40:18 -08:00
q_strlcpy(item->name, name, sizeof(item->name));
2019-11-24 20:45:15 -08:00
// insert each entry in alphabetical order
2019-11-25 17:40:18 -08:00
if(*list == NULL ||
q_strcasecmp(item->name, (*list)->name) < 0) //insert at front
2019-11-24 20:45:15 -08:00
{
item->next = *list;
*list = item;
}
else //insert later
{
prev = *list;
cursor = (*list)->next;
2019-11-25 17:40:18 -08:00
while(cursor && (q_strcasecmp(item->name, cursor->name) > 0))
2019-11-24 20:45:15 -08:00
{
prev = cursor;
cursor = cursor->next;
}
item->next = prev->next;
prev->next = item;
}
}
2019-11-25 17:40:18 -08:00
static void FileList_Clear(filelist_item_t **list)
2019-11-24 20:45:15 -08:00
{
filelist_item_t *blah;
2019-11-24 22:55:47 -08:00
2019-11-25 17:40:18 -08:00
while(*list)
2019-11-24 20:45:15 -08:00
{
blah = (*list)->next;
Z_Free(*list);
*list = blah;
}
}
2019-11-25 17:40:18 -08:00
filelist_item_t *extralevels;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
void ExtraMaps_Add(const char *name)
2019-11-24 20:45:15 -08:00
{
FileList_Add(name, &extralevels);
}
2019-11-25 17:40:18 -08:00
void ExtraMaps_Init(void)
2019-11-24 20:45:15 -08:00
{
2019-12-02 04:24:20 -08:00
#if PLATFORM_IS(WINDOWS)
2019-11-25 17:40:18 -08:00
WIN32_FIND_DATA fdat;
HANDLE fhnd;
2019-11-24 20:45:15 -08:00
#else
2019-11-25 17:40:18 -08:00
DIR *dir_p;
struct dirent *dir_t;
2019-11-24 20:45:15 -08:00
#endif
2019-11-25 17:40:18 -08:00
char filestring[MAX_OSPATH];
char mapname[32];
char ignorepakdir[32];
searchpath_t *search;
pack_t *pak;
int32_t i;
2019-11-24 20:45:15 -08:00
// we don't want to list the maps in id1 pakfiles,
// because these are not "add-on" levels
2019-11-25 17:40:18 -08:00
q_snprintf(ignorepakdir, sizeof(ignorepakdir), "/%s/", GAMENAME);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
for(search = com_searchpaths; search; search = search->next)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(*search->filename) //directory
2019-11-24 20:45:15 -08:00
{
2019-12-02 04:24:20 -08:00
#if PLATFORM_IS(WINDOWS)
2019-11-25 17:40:18 -08:00
q_snprintf(filestring, sizeof(filestring), "%s/maps/*.bsp", search->filename);
2019-11-24 20:45:15 -08:00
fhnd = FindFirstFile(filestring, &fdat);
2019-11-25 17:40:18 -08:00
if(fhnd == INVALID_HANDLE_VALUE)
2019-11-24 20:45:15 -08:00
continue;
do
{
COM_StripExtension(fdat.cFileName, mapname, sizeof(mapname));
2019-11-25 17:40:18 -08:00
ExtraMaps_Add(mapname);
}
while(FindNextFile(fhnd, &fdat));
2019-11-24 20:45:15 -08:00
FindClose(fhnd);
#else
2019-11-25 17:40:18 -08:00
q_snprintf(filestring, sizeof(filestring), "%s/maps/", search->filename);
2019-11-24 20:45:15 -08:00
dir_p = opendir(filestring);
2019-11-25 17:40:18 -08:00
if(dir_p == NULL)
2019-11-24 20:45:15 -08:00
continue;
2019-11-25 17:40:18 -08:00
while((dir_t = readdir(dir_p)) != NULL)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(COM_FileGetExtension(dir_t->d_name), "bsp") != 0)
2019-11-24 20:45:15 -08:00
continue;
COM_StripExtension(dir_t->d_name, mapname, sizeof(mapname));
2019-11-25 17:40:18 -08:00
ExtraMaps_Add(mapname);
2019-11-24 20:45:15 -08:00
}
closedir(dir_p);
#endif
}
else //pakfile
{
2019-11-25 17:40:18 -08:00
if(!strstr(search->pack->filename, ignorepakdir))
{
//don't list standard id maps
for(i = 0, pak = search->pack; i < pak->numfiles; i++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(!strcmp(COM_FileGetExtension(pak->files[i].name), "bsp"))
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(pak->files[i].filelen > 32 * 1024)
{
// don't list files under 32k (ammo boxes etc)
2019-11-24 20:45:15 -08:00
COM_StripExtension(pak->files[i].name + 5, mapname, sizeof(mapname));
2019-11-25 17:40:18 -08:00
ExtraMaps_Add(mapname);
2019-11-24 20:45:15 -08:00
}
}
}
}
}
}
}
2019-11-25 17:40:18 -08:00
static void ExtraMaps_Clear(void)
2019-11-24 20:45:15 -08:00
{
FileList_Clear(&extralevels);
}
2019-11-25 17:40:18 -08:00
void ExtraMaps_NewGame(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
ExtraMaps_Clear();
ExtraMaps_Init();
2019-11-24 20:45:15 -08:00
}
/*
==================
Host_Maps_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Maps_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 16:49:58 -08:00
int32_t i;
2019-11-25 17:40:18 -08:00
filelist_item_t *level;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
for(level = extralevels, i = 0; level; level = level->next, i++)
Con_SafePrintf(" %s\n", level->name);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(i)
Con_SafePrintf("%" PRIi32 " map(s)\n", i);
2019-11-24 20:45:15 -08:00
else
2019-11-25 17:40:18 -08:00
Con_SafePrintf("no maps found\n");
2019-11-24 20:45:15 -08:00
}
//==============================================================================
//johnfitz -- modlist management
//==============================================================================
2019-11-25 17:40:18 -08:00
filelist_item_t *modlist;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
void Modlist_Add(const char *name)
2019-11-24 20:45:15 -08:00
{
FileList_Add(name, &modlist);
}
2019-12-02 04:24:20 -08:00
#if PLATFORM_IS(WINDOWS)
2019-11-25 17:40:18 -08:00
void Modlist_Init(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
WIN32_FIND_DATA fdat;
HANDLE fhnd;
DWORD attribs;
char dir_string[MAX_OSPATH], mod_string[MAX_OSPATH];
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
q_snprintf(dir_string, sizeof(dir_string), "%s/*", com_basedir);
2019-11-24 20:45:15 -08:00
fhnd = FindFirstFile(dir_string, &fdat);
2019-11-25 17:40:18 -08:00
if(fhnd == INVALID_HANDLE_VALUE)
2019-11-24 20:45:15 -08:00
return;
do
{
2019-11-25 17:40:18 -08:00
if(!strcmp(fdat.cFileName, ".") || !strcmp(fdat.cFileName, ".."))
2019-11-24 20:45:15 -08:00
continue;
2019-11-25 17:40:18 -08:00
q_snprintf(mod_string, sizeof(mod_string), "%s/%s", com_basedir, fdat.cFileName);
attribs = GetFileAttributes(mod_string);
if(attribs != INVALID_FILE_ATTRIBUTES && (attribs & FILE_ATTRIBUTE_DIRECTORY))
{
2019-11-24 20:45:15 -08:00
/* don't bother testing for pak files / progs.dat */
Modlist_Add(fdat.cFileName);
}
2019-11-25 17:40:18 -08:00
}
while(FindNextFile(fhnd, &fdat));
2019-11-24 20:45:15 -08:00
FindClose(fhnd);
}
#else
2019-11-25 17:40:18 -08:00
void Modlist_Init(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
DIR *dir_p, *mod_dir_p;
struct dirent *dir_t;
char dir_string[MAX_OSPATH], mod_string[MAX_OSPATH];
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
q_snprintf(dir_string, sizeof(dir_string), "%s/", com_basedir);
2019-11-24 20:45:15 -08:00
dir_p = opendir(dir_string);
2019-11-25 17:40:18 -08:00
if(dir_p == NULL)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
while((dir_t = readdir(dir_p)) != NULL)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(!strcmp(dir_t->d_name, ".") || !strcmp(dir_t->d_name, ".."))
2019-11-24 20:45:15 -08:00
continue;
2019-11-25 17:40:18 -08:00
if(!q_strcasecmp(COM_FileGetExtension(dir_t->d_name), "app")) // skip .app bundles on macOS
2019-11-24 20:45:15 -08:00
continue;
q_snprintf(mod_string, sizeof(mod_string), "%s%s/", dir_string, dir_t->d_name);
mod_dir_p = opendir(mod_string);
2019-11-25 17:40:18 -08:00
if(mod_dir_p == NULL)
2019-11-24 20:45:15 -08:00
continue;
/* don't bother testing for pak files / progs.dat */
Modlist_Add(dir_t->d_name);
closedir(mod_dir_p);
}
closedir(dir_p);
}
#endif
//==============================================================================
//ericw -- demo list management
//==============================================================================
2019-11-25 17:40:18 -08:00
filelist_item_t *demolist;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
static void DemoList_Clear(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
FileList_Clear(&demolist);
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
void DemoList_Rebuild(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
DemoList_Clear();
DemoList_Init();
2019-11-24 20:45:15 -08:00
}
// TODO: Factor out to a general-purpose file searching function
2019-11-25 17:40:18 -08:00
void DemoList_Init(void)
2019-11-24 20:45:15 -08:00
{
2019-12-02 04:24:20 -08:00
#if PLATFORM_IS(WINDOWS)
2019-11-25 17:40:18 -08:00
WIN32_FIND_DATA fdat;
HANDLE fhnd;
2019-11-24 20:45:15 -08:00
#else
2019-11-25 17:40:18 -08:00
DIR *dir_p;
struct dirent *dir_t;
2019-11-24 20:45:15 -08:00
#endif
2019-11-25 17:40:18 -08:00
char filestring[MAX_OSPATH];
char demname[32];
char ignorepakdir[32];
searchpath_t *search;
pack_t *pak;
int32_t i;
2019-11-24 22:55:47 -08:00
2019-11-24 20:45:15 -08:00
// we don't want to list the demos in id1 pakfiles,
// because these are not "add-on" demos
2019-11-25 17:40:18 -08:00
q_snprintf(ignorepakdir, sizeof(ignorepakdir), "/%s/", GAMENAME);
2019-11-24 22:55:47 -08:00
2019-11-25 17:40:18 -08:00
for(search = com_searchpaths; search; search = search->next)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(*search->filename) //directory
2019-11-24 20:45:15 -08:00
{
2019-12-02 04:24:20 -08:00
#if PLATFORM_IS(WINDOWS)
2019-11-25 17:40:18 -08:00
q_snprintf(filestring, sizeof(filestring), "%s/*.dem", search->filename);
2019-11-24 20:45:15 -08:00
fhnd = FindFirstFile(filestring, &fdat);
2019-11-25 17:40:18 -08:00
if(fhnd == INVALID_HANDLE_VALUE)
2019-11-24 20:45:15 -08:00
continue;
do
{
COM_StripExtension(fdat.cFileName, demname, sizeof(demname));
2019-11-25 17:40:18 -08:00
FileList_Add(demname, &demolist);
}
while(FindNextFile(fhnd, &fdat));
2019-11-24 20:45:15 -08:00
FindClose(fhnd);
#else
2019-11-25 17:40:18 -08:00
q_snprintf(filestring, sizeof(filestring), "%s/", search->filename);
2019-11-24 20:45:15 -08:00
dir_p = opendir(filestring);
2019-11-25 17:40:18 -08:00
if(dir_p == NULL)
2019-11-24 20:45:15 -08:00
continue;
2019-11-25 17:40:18 -08:00
while((dir_t = readdir(dir_p)) != NULL)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(COM_FileGetExtension(dir_t->d_name), "dem") != 0)
2019-11-24 20:45:15 -08:00
continue;
COM_StripExtension(dir_t->d_name, demname, sizeof(demname));
2019-11-25 17:40:18 -08:00
FileList_Add(demname, &demolist);
2019-11-24 20:45:15 -08:00
}
closedir(dir_p);
#endif
}
else //pakfile
{
2019-11-25 17:40:18 -08:00
if(!strstr(search->pack->filename, ignorepakdir))
{
//don't list standard id demos
for(i = 0, pak = search->pack; i < pak->numfiles; i++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(!strcmp(COM_FileGetExtension(pak->files[i].name), "dem"))
2019-11-24 20:45:15 -08:00
{
COM_StripExtension(pak->files[i].name, demname, sizeof(demname));
2019-11-25 17:40:18 -08:00
FileList_Add(demname, &demolist);
2019-11-24 20:45:15 -08:00
}
}
}
}
}
}
/*
==================
Host_Mods_f -- johnfitz
list all potential mod directories (contain either a pak file or a progs.dat)
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Mods_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 16:49:58 -08:00
int32_t i;
2019-11-25 17:40:18 -08:00
filelist_item_t *mod;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
for(mod = modlist, i = 0; mod; mod = mod->next, i++)
Con_SafePrintf(" %s\n", mod->name);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(i)
Con_SafePrintf("%" PRIi32 " mod(s)\n", i);
2019-11-24 20:45:15 -08:00
else
2019-11-25 17:40:18 -08:00
Con_SafePrintf("no mods found\n");
2019-11-24 20:45:15 -08:00
}
//==============================================================================
/*
=============
Host_Mapname_f -- johnfitz
=============
*/
2019-11-25 17:40:18 -08:00
void Host_Mapname_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(sv.active)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("\"mapname\" is \"%s\"\n", sv.name);
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
if(cls.state == ca_connected)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("\"mapname\" is \"%s\"\n", cl.mapname);
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
Con_Printf("no map loaded\n");
2019-11-24 20:45:15 -08:00
}
/*
==================
Host_Status_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Status_f(void)
2019-11-24 20:45:15 -08:00
{
2019-12-02 07:01:47 -08:00
void (*print_fn)(const char *fmt, ...) FUNCP_PRINTF(1, 2);
2019-11-25 17:40:18 -08:00
client_t *client;
int32_t seconds;
int32_t minutes;
int32_t hours = 0;
int32_t j;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(!sv.active)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Cmd_ForwardToServer();
2019-11-24 20:45:15 -08:00
return;
}
print_fn = Con_Printf;
}
else
print_fn = SV_ClientPrintf;
2019-11-25 17:40:18 -08:00
print_fn("host: %s\n", Cvar_VariableString("hostname"));
print_fn("version: " VERSION "\n");
if(tcpipAvailable)
print_fn("tcp/ip: %s\n", my_tcpip_address);
if(ipxAvailable)
print_fn("ipx: %s\n", my_ipx_address);
print_fn("map: %s\n", sv.name);
print_fn("players: %" PRIi32 " active (%" PRIi32 " max)\n\n", net_activeconnections, svs.maxclients);
for(j = 0, client = svs.clients; j < svs.maxclients; j++, client++)
{
if(!client->active)
2019-11-24 20:45:15 -08:00
continue;
2019-11-25 16:49:58 -08:00
seconds = (int32_t)(net_time - NET_QSocketGetTime(client->netconnection));
2019-11-24 20:45:15 -08:00
minutes = seconds / 60;
2019-11-25 17:40:18 -08:00
if(minutes)
2019-11-24 20:45:15 -08:00
{
seconds -= (minutes * 60);
hours = minutes / 60;
2019-11-25 17:40:18 -08:00
if(hours)
2019-11-24 20:45:15 -08:00
minutes -= (hours * 60);
}
else
hours = 0;
print_fn("#%-2" PRIu32 " %-16.16s %3" PRIi32 " %2" PRIi32 ":%02" PRIi32 ":%02" PRIi32 "n", j + 1, client->name, (int32_t)ED_Float(client->edict, ED_frags), hours, minutes, seconds);
2019-11-25 17:40:18 -08:00
print_fn(" %s\n", NET_QSocketGetAddressString(client->netconnection));
2019-11-24 20:45:15 -08:00
}
}
/*
==================
Host_God_f
Sets client to godmode
==================
*/
2019-11-25 17:40:18 -08:00
void Host_God_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Cmd_ForwardToServer();
2019-11-24 20:45:15 -08:00
return;
}
if(G_Float(GBL_deathmatch))
2019-11-24 20:45:15 -08:00
return;
//johnfitz -- allow user to explicitly set god mode to on or off
2019-11-25 17:40:18 -08:00
switch(Cmd_Argc())
2019-11-24 20:45:15 -08:00
{
case 1:
ED_Float(sv_player, ED_flags) = (int32_t)ED_Float(sv_player, ED_flags) ^ FL_GODMODE;
if(!((int32_t)ED_Float(sv_player, ED_flags) & FL_GODMODE))
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("godmode OFF\n");
2019-11-24 20:45:15 -08:00
else
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("godmode ON\n");
2019-11-24 20:45:15 -08:00
break;
case 2:
2019-12-07 09:27:26 -08:00
if(atof(Cmd_Argv(1)))
2019-11-24 20:45:15 -08:00
{
ED_Float(sv_player, ED_flags) = (int32_t)ED_Float(sv_player, ED_flags) | FL_GODMODE;
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("godmode ON\n");
2019-11-24 20:45:15 -08:00
}
else
{
ED_Float(sv_player, ED_flags) = (int32_t)ED_Float(sv_player, ED_flags) & ~FL_GODMODE;
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("godmode OFF\n");
2019-11-24 20:45:15 -08:00
}
break;
default:
Con_Printf("god [value] : toggle god mode. values: 0 = off, 1 = on\n");
break;
}
//johnfitz
}
/*
==================
Host_Notarget_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Notarget_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Cmd_ForwardToServer();
2019-11-24 20:45:15 -08:00
return;
}
if(G_Float(GBL_deathmatch))
2019-11-24 20:45:15 -08:00
return;
//johnfitz -- allow user to explicitly set notarget to on or off
2019-11-25 17:40:18 -08:00
switch(Cmd_Argc())
2019-11-24 20:45:15 -08:00
{
case 1:
ED_Float(sv_player, ED_flags) = (int32_t)ED_Float(sv_player, ED_flags) ^ FL_NOTARGET;
if(!((int32_t)ED_Float(sv_player, ED_flags) & FL_NOTARGET))
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("notarget OFF\n");
2019-11-24 20:45:15 -08:00
else
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("notarget ON\n");
2019-11-24 20:45:15 -08:00
break;
case 2:
2019-12-07 09:27:26 -08:00
if(atof(Cmd_Argv(1)))
2019-11-24 20:45:15 -08:00
{
ED_Float(sv_player, ED_flags) = (int32_t)ED_Float(sv_player, ED_flags) | FL_NOTARGET;
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("notarget ON\n");
2019-11-24 20:45:15 -08:00
}
else
{
ED_Float(sv_player, ED_flags) = (int32_t)ED_Float(sv_player, ED_flags) & ~FL_NOTARGET;
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("notarget OFF\n");
2019-11-24 20:45:15 -08:00
}
break;
default:
Con_Printf("notarget [value] : toggle notarget mode. values: 0 = off, 1 = on\n");
break;
}
//johnfitz
}
2019-11-25 15:28:38 -08:00
bool noclip_anglehack;
2019-11-24 20:45:15 -08:00
/*
==================
Host_Noclip_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Noclip_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Cmd_ForwardToServer();
2019-11-24 20:45:15 -08:00
return;
}
if(G_Float(GBL_deathmatch))
2019-11-24 20:45:15 -08:00
return;
//johnfitz -- allow user to explicitly set noclip to on or off
2019-11-25 17:40:18 -08:00
switch(Cmd_Argc())
2019-11-24 20:45:15 -08:00
{
case 1:
if(ED_Float(sv_player, ED_movetype) != MOVETYPE_NOCLIP)
2019-11-24 20:45:15 -08:00
{
noclip_anglehack = true;
ED_Float(sv_player, ED_movetype) = MOVETYPE_NOCLIP;
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("noclip ON\n");
2019-11-24 20:45:15 -08:00
}
else
{
noclip_anglehack = false;
ED_Float(sv_player, ED_movetype) = MOVETYPE_WALK;
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("noclip OFF\n");
2019-11-24 20:45:15 -08:00
}
break;
case 2:
2019-12-07 09:27:26 -08:00
if(atof(Cmd_Argv(1)))
2019-11-24 20:45:15 -08:00
{
noclip_anglehack = true;
ED_Float(sv_player, ED_movetype) = MOVETYPE_NOCLIP;
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("noclip ON\n");
2019-11-24 20:45:15 -08:00
}
else
{
noclip_anglehack = false;
ED_Float(sv_player, ED_movetype) = MOVETYPE_WALK;
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("noclip OFF\n");
2019-11-24 20:45:15 -08:00
}
break;
default:
Con_Printf("noclip [value] : toggle noclip mode. values: 0 = off, 1 = on\n");
break;
}
//johnfitz
}
/*
====================
Host_SetPos_f
adapted from fteqw, originally by Alex Shadowalker
====================
*/
void Host_SetPos_f(void)
{
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Cmd_ForwardToServer();
2019-11-24 20:45:15 -08:00
return;
}
2019-11-24 22:55:47 -08:00
if(G_Float(GBL_deathmatch))
2019-11-24 20:45:15 -08:00
return;
2019-11-24 22:55:47 -08:00
2019-11-25 17:40:18 -08:00
if(Cmd_Argc() != 7 && Cmd_Argc() != 4)
2019-11-24 20:45:15 -08:00
{
SV_ClientPrintf("usage:\n");
SV_ClientPrintf(" setpos <x> <y> <z>\n");
SV_ClientPrintf(" setpos <x> <y> <z> <pitch> <yaw> <roll>\n");
SV_ClientPrintf("current values:\n");
2019-11-25 16:56:15 -08:00
SV_ClientPrintf(" %" PRIi32 " %" PRIi32 " %" PRIi32 " %" PRIi32 " %" PRIi32 " %" PRIi32 "\n",
(int32_t)ED_Vector(sv_player, ED_origin)[0],
(int32_t)ED_Vector(sv_player, ED_origin)[1],
(int32_t)ED_Vector(sv_player, ED_origin)[2],
(int32_t)ED_Vector(sv_player, ED_v_angle)[0],
(int32_t)ED_Vector(sv_player, ED_v_angle)[1],
(int32_t)ED_Vector(sv_player, ED_v_angle)[2]);
2019-11-24 20:45:15 -08:00
return;
}
2019-11-24 22:55:47 -08:00
if(ED_Float(sv_player, ED_movetype) != MOVETYPE_NOCLIP)
2019-11-24 20:45:15 -08:00
{
noclip_anglehack = true;
ED_Float(sv_player, ED_movetype) = MOVETYPE_NOCLIP;
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("noclip ON\n");
2019-11-24 20:45:15 -08:00
}
2019-11-24 22:55:47 -08:00
2019-11-24 20:45:15 -08:00
//make sure they're not going to whizz away from it
ED_Vector(sv_player, ED_velocity)[0] = 0;
ED_Vector(sv_player, ED_velocity)[1] = 0;
ED_Vector(sv_player, ED_velocity)[2] = 0;
2019-11-24 22:55:47 -08:00
ED_Vector(sv_player, ED_origin)[0] = atof(Cmd_Argv(1));
ED_Vector(sv_player, ED_origin)[1] = atof(Cmd_Argv(2));
ED_Vector(sv_player, ED_origin)[2] = atof(Cmd_Argv(3));
2019-11-24 22:55:47 -08:00
2019-11-25 17:40:18 -08:00
if(Cmd_Argc() == 7)
2019-11-24 20:45:15 -08:00
{
ED_Vector(sv_player, ED_angles)[0] = atof(Cmd_Argv(4));
ED_Vector(sv_player, ED_angles)[1] = atof(Cmd_Argv(5));
ED_Vector(sv_player, ED_angles)[2] = atof(Cmd_Argv(6));
ED_Float(sv_player, ED_fixangle) = 1;
2019-11-24 20:45:15 -08:00
}
2019-11-24 22:55:47 -08:00
2019-11-25 17:40:18 -08:00
SV_LinkEdict(sv_player, false);
2019-11-24 20:45:15 -08:00
}
/*
==================
Host_Fly_f
Sets client to flymode
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Fly_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Cmd_ForwardToServer();
2019-11-24 20:45:15 -08:00
return;
}
if(G_Float(GBL_deathmatch))
2019-11-24 20:45:15 -08:00
return;
//johnfitz -- allow user to explicitly set noclip to on or off
2019-11-25 17:40:18 -08:00
switch(Cmd_Argc())
2019-11-24 20:45:15 -08:00
{
case 1:
if(ED_Float(sv_player, ED_movetype) != MOVETYPE_FLY)
2019-11-24 20:45:15 -08:00
{
ED_Float(sv_player, ED_movetype) = MOVETYPE_FLY;
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("flymode ON\n");
2019-11-24 20:45:15 -08:00
}
else
{
ED_Float(sv_player, ED_movetype) = MOVETYPE_WALK;
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("flymode OFF\n");
2019-11-24 20:45:15 -08:00
}
break;
case 2:
2019-12-07 09:27:26 -08:00
if(atof(Cmd_Argv(1)))
2019-11-24 20:45:15 -08:00
{
ED_Float(sv_player, ED_movetype) = MOVETYPE_FLY;
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("flymode ON\n");
2019-11-24 20:45:15 -08:00
}
else
{
ED_Float(sv_player, ED_movetype) = MOVETYPE_WALK;
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("flymode OFF\n");
2019-11-24 20:45:15 -08:00
}
break;
default:
Con_Printf("fly [value] : toggle fly mode. values: 0 = off, 1 = on\n");
break;
}
//johnfitz
}
/*
==================
Host_Ping_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Ping_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t i, j;
float total;
client_t *client;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Cmd_ForwardToServer();
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("Client ping times:\n");
for(i = 0, client = svs.clients; i < svs.maxclients; i++, client++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(!client->active)
2019-11-24 20:45:15 -08:00
continue;
total = 0;
2019-11-25 17:40:18 -08:00
for(j = 0; j < NUM_PING_TIMES; j++)
total += client->ping_times[j];
2019-11-24 20:45:15 -08:00
total /= NUM_PING_TIMES;
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("%4" PRIi32 " %s\n", (int32_t)(total * 1000), client->name);
2019-11-24 20:45:15 -08:00
}
}
/*
===============================================================================
SERVER TRANSITIONS
===============================================================================
*/
/*
======================
Host_Map_f
handle a
map <servername>
command from the console. Active clients are kicked off.
======================
*/
2019-11-25 17:40:18 -08:00
void Host_Map_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t i;
char name[MAX_QPATH], *p;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(Cmd_Argc() < 2) //no map name given
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(cls.state == ca_dedicated)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(sv.active)
Con_Printf("Current map: %s\n", sv.name);
2019-11-24 20:45:15 -08:00
else
2019-11-25 17:40:18 -08:00
Con_Printf("Server not active\n");
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
else if(cls.state == ca_connected)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("Current map: %s ( %s )\n", cl.levelname, cl.mapname);
2019-11-24 20:45:15 -08:00
}
else
{
2019-11-25 17:40:18 -08:00
Con_Printf("map <levelname>: start a new server\n");
2019-11-24 20:45:15 -08:00
}
return;
}
2019-11-25 17:40:18 -08:00
if(cmd_source != src_command)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
cls.demonum = -1; // stop demo loop in case this fails
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
CL_Disconnect();
2019-11-24 20:45:15 -08:00
Host_ShutdownServer(false);
2019-11-25 17:40:18 -08:00
if(cls.state != ca_dedicated)
2019-11-24 20:45:15 -08:00
IN_Activate();
2019-11-25 17:40:18 -08:00
key_dest = key_game; // remove console or menu
SCR_BeginLoadingPlaque();
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
svs.serverflags = 0; // haven't completed an episode yet
q_strlcpy(name, Cmd_Argv(1), sizeof(name));
2019-11-24 20:45:15 -08:00
// remove (any) trailing ".bsp" from mapname -- S.A.
p = strstr(name, ".bsp");
2019-11-25 17:40:18 -08:00
if(p && p[4] == '\0')
2019-11-24 20:45:15 -08:00
*p = '\0';
2019-11-25 17:40:18 -08:00
SV_SpawnServer(name);
if(!sv.active)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
if(cls.state != ca_dedicated)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
memset(cls.spawnparms, 0, MAX_MAPSTRING);
for(i = 2; i < Cmd_Argc(); i++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
q_strlcat(cls.spawnparms, Cmd_Argv(i), MAX_MAPSTRING);
q_strlcat(cls.spawnparms, " ", MAX_MAPSTRING);
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
Cmd_ExecuteString("connect local", src_command);
2019-11-24 20:45:15 -08:00
}
}
/*
======================
Host_Randmap_f
Loads a random map from the "maps" list.
======================
*/
2019-11-25 17:40:18 -08:00
void Host_Randmap_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t i, randlevel, numlevels;
filelist_item_t *level;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(cmd_source != src_command)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
for(level = extralevels, numlevels = 0; level; level = level->next)
2019-11-24 20:45:15 -08:00
numlevels++;
2019-11-25 17:40:18 -08:00
if(numlevels == 0)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("no maps\n");
2019-11-24 20:45:15 -08:00
return;
}
randlevel = (rand() % numlevels);
2019-11-25 17:40:18 -08:00
for(level = extralevels, i = 0; level; level = level->next, i++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(i == randlevel)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("Starting map %s...\n", level->name);
Cbuf_AddText(va("map %s\n", level->name));
2019-11-24 20:45:15 -08:00
return;
}
}
}
/*
==================
Host_Changelevel_f
Goes to a new map, taking all clients along
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Changelevel_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
char level[MAX_QPATH];
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(Cmd_Argc() != 2)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("changelevel <levelname> : continue game on a new level\n");
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
if(!sv.active || cls.demoplayback)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("Only the server may changelevel\n");
2019-11-24 20:45:15 -08:00
return;
}
//johnfitz -- check for client having map before anything else
2019-11-25 17:40:18 -08:00
q_snprintf(level, sizeof(level), "maps/%s.bsp", Cmd_Argv(1));
if(!COM_FileExists(level, NULL))
Host_Error("cannot find map %s", level);
2019-11-24 20:45:15 -08:00
//johnfitz
2019-11-25 17:40:18 -08:00
if(cls.state != ca_dedicated)
IN_Activate(); // -- S.A.
key_dest = key_game; // remove console or menu
SV_SaveSpawnparms();
q_strlcpy(level, Cmd_Argv(1), sizeof(level));
SV_SpawnServer(level);
2019-11-24 20:45:15 -08:00
// also issue an error if spawn failed -- O.S.
2019-11-25 17:40:18 -08:00
if(!sv.active)
Host_Error("cannot run map %s", level);
2019-11-24 20:45:15 -08:00
}
/*
==================
Host_Restart_f
Restarts the current server for a dead player
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Restart_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
char mapname[MAX_QPATH];
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(cls.demoplayback || !sv.active)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
if(cmd_source != src_command)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
q_strlcpy(mapname, sv.name, sizeof(mapname)); // mapname gets cleared in spawnserver
SV_SpawnServer(mapname);
if(!sv.active)
Host_Error("cannot restart map %s", mapname);
2019-11-24 20:45:15 -08:00
}
/*
==================
Host_Reconnect_f
This command causes the client to wait for the signon messages again.
This is sent just before a server changes levels
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Reconnect_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(cls.demoplayback) // cross-map demo playback fix from Baker
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
SCR_BeginLoadingPlaque();
cls.signon = 0; // need new connection messages
2019-11-24 20:45:15 -08:00
}
/*
=====================
Host_Connect_f
User command to connect to server
=====================
*/
2019-11-25 17:40:18 -08:00
void Host_Connect_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
char name[MAX_QPATH];
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
cls.demonum = -1; // stop demo loop in case this fails
if(cls.demoplayback)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
CL_StopPlayback();
CL_Disconnect();
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
q_strlcpy(name, Cmd_Argv(1), sizeof(name));
CL_EstablishConnection(name);
Host_Reconnect_f();
2019-11-24 20:45:15 -08:00
}
/*
===============================================================================
LOAD / SAVE GAME
===============================================================================
*/
2019-11-25 17:40:18 -08:00
#define SAVEGAME_VERSION 5
2019-11-24 20:45:15 -08:00
/*
===============
Host_SavegameComment
Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
===============
*/
2019-11-25 17:40:18 -08:00
void Host_SavegameComment(char *text)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t i;
char kills[20];
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
for(i = 0; i < SAVEGAME_COMMENT_LENGTH; i++)
2019-11-24 20:45:15 -08:00
text[i] = ' ';
2019-11-25 17:40:18 -08:00
memcpy(text, cl.levelname, q_min(strlen(cl.levelname), 22)); //johnfitz -- only copy 22 chars.
sprintf(kills, "kills:%3" PRIi32 "/%3" PRIi32, cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
2019-11-25 17:40:18 -08:00
memcpy(text + 22, kills, strlen(kills));
2019-11-24 20:45:15 -08:00
// convert space to _ to make stdio happy
2019-11-25 17:40:18 -08:00
for(i = 0; i < SAVEGAME_COMMENT_LENGTH; i++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(text[i] == ' ')
2019-11-24 20:45:15 -08:00
text[i] = '_';
}
text[SAVEGAME_COMMENT_LENGTH] = '\0';
}
/*
===============
Host_Savegame_f
===============
*/
2019-11-25 17:40:18 -08:00
void Host_Savegame_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
char name[MAX_OSPATH];
FILE *f;
int32_t i;
char comment[SAVEGAME_COMMENT_LENGTH + 1];
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(cmd_source != src_command)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
if(!sv.active)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("Not playing a local game.\n");
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
if(cl.intermission)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("Can't save in intermission.\n");
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
if(svs.maxclients != 1)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("Can't save multiplayer games.\n");
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
if(Cmd_Argc() != 2)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("save <savename> : save a game\n");
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
if(strstr(Cmd_Argv(1), ".."))
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("Relative pathnames are not allowed.\n");
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
for(i = 0 ; i < svs.maxclients ; i++)
2019-11-24 20:45:15 -08:00
{
if(svs.clients[i].active && ED_Float(svs.clients[i].edict, ED_health) <= 0)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("Can't savegame with a dead player\n");
2019-11-24 20:45:15 -08:00
return;
}
}
2019-11-25 17:40:18 -08:00
q_snprintf(name, sizeof(name), "%s/%s", com_gamedir, Cmd_Argv(1));
COM_AddExtension(name, ".sav", sizeof(name));
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
Con_Printf("Saving game to %s...\n", name);
f = fopen(name, "w");
if(!f)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("ERROR: couldn't open.\n");
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
fprintf(f, "%" PRIi32 "\n", SAVEGAME_VERSION);
Host_SavegameComment(comment);
fprintf(f, "%s\n", comment);
for(i = 0; i < NUM_SPAWN_PARMS; i++)
fprintf(f, "%f\n", svs.clients->spawn_parms[i]);
fprintf(f, "%" PRIi32 "\n", current_skill);
fprintf(f, "%s\n", sv.name);
fprintf(f, "%f\n", sv.time);
2019-11-24 20:45:15 -08:00
// write the light styles
2019-11-25 17:40:18 -08:00
for(i = 0; i < MAX_LIGHTSTYLES; i++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(sv.lightstyles[i])
fprintf(f, "%s\n", sv.lightstyles[i]);
2019-11-24 20:45:15 -08:00
else
2019-11-25 17:40:18 -08:00
fprintf(f, "m\n");
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
ED_WriteGlobals(f);
for(i = 0; i < sv.num_edicts; i++)
2019-11-24 20:45:15 -08:00
{
ED_Write(f, EdictNum(i));
2019-11-25 17:40:18 -08:00
fflush(f);
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
fclose(f);
Con_Printf("done.\n");
2019-11-24 20:45:15 -08:00
}
/*
===============
Host_Loadgame_f
===============
*/
2019-11-25 17:40:18 -08:00
void Host_Loadgame_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
static char *start;
2019-11-24 22:55:47 -08:00
2019-11-25 17:40:18 -08:00
char name[MAX_OSPATH];
char mapname[MAX_QPATH];
float time, tfloat;
const char *data;
int32_t i;
edict_t *ent;
int32_t entnum;
int32_t version;
float spawn_parms[NUM_SPAWN_PARMS];
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(cmd_source != src_command)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
if(Cmd_Argc() != 2)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("load <savename> : load a game\n");
2019-11-24 20:45:15 -08:00
return;
}
2019-11-24 22:55:47 -08:00
2019-11-25 17:40:18 -08:00
if(strstr(Cmd_Argv(1), ".."))
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("Relative pathnames are not allowed.\n");
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
cls.demonum = -1; // stop demo loop in case this fails
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
q_snprintf(name, sizeof(name), "%s/%s", com_gamedir, Cmd_Argv(1));
COM_AddExtension(name, ".sav", sizeof(name));
2019-11-24 20:45:15 -08:00
// we can't call SCR_BeginLoadingPlaque, because too much stack space has
// been used. The menu calls it before stuffing loadgame command
// SCR_BeginLoadingPlaque ();
2019-11-25 17:40:18 -08:00
Con_Printf("Loading game from %s...\n", name);
2019-11-24 22:55:47 -08:00
2019-11-24 20:45:15 -08:00
// avoid leaking if the previous Host_Loadgame_f failed with a Host_Error
2019-11-25 17:40:18 -08:00
if(start != NULL)
free(start);
2019-11-24 22:55:47 -08:00
2019-11-24 20:45:15 -08:00
start = (char *) COM_LoadMallocFile_TextMode_OSPath(name, NULL);
2019-11-25 17:40:18 -08:00
if(start == NULL)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("ERROR: couldn't open.\n");
2019-11-24 20:45:15 -08:00
return;
}
data = start;
2019-11-25 17:40:18 -08:00
data = COM_ParseIntNewline(data, &version);
if(version != SAVEGAME_VERSION)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
free(start);
2019-11-24 20:45:15 -08:00
start = NULL;
2019-11-25 17:40:18 -08:00
Con_Printf("Savegame is version %" PRIi32 ", not %" PRIi32 "\n", version, SAVEGAME_VERSION);
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
data = COM_ParseStringNewline(data);
for(i = 0; i < NUM_SPAWN_PARMS; i++)
data = COM_ParseFloatNewline(data, &spawn_parms[i]);
2019-11-24 20:45:15 -08:00
// this silliness is so we can load 1.06 save files, which have float skill values
data = COM_ParseFloatNewline(data, &tfloat);
2019-11-25 16:49:58 -08:00
current_skill = (int32_t)(tfloat + 0.1);
2019-11-25 17:40:18 -08:00
Cvar_SetValue("skill", (float)current_skill);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
data = COM_ParseStringNewline(data);
q_strlcpy(mapname, com_token, sizeof(mapname));
data = COM_ParseFloatNewline(data, &time);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
CL_Disconnect_f();
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
SV_SpawnServer(mapname);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(!sv.active)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
free(start);
2019-11-24 20:45:15 -08:00
start = NULL;
2019-11-25 17:40:18 -08:00
Con_Printf("Couldn't load map\n");
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
sv.paused = true; // pause until all clients connect
2019-11-24 20:45:15 -08:00
sv.loadgame = true;
// load the light styles
2019-11-25 17:40:18 -08:00
for(i = 0; i < MAX_LIGHTSTYLES; i++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
data = COM_ParseStringNewline(data);
sv.lightstyles[i] = (const char *)Hunk_Strdup(com_token, "lightstyles");
2019-11-24 20:45:15 -08:00
}
// load the edicts out of the savegame file
2019-11-25 17:40:18 -08:00
entnum = -1; // -1 is the globals
while(*data)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
data = COM_Parse(data);
if(!com_token[0])
break; // end of file
if(strcmp(com_token, "{"))
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Sys_Error("First token isn't a brace");
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
if(entnum == -1)
{
// parse the global vars
data = ED_ParseGlobals(data);
2019-11-24 20:45:15 -08:00
}
else
2019-11-25 17:40:18 -08:00
{
// parse an edict
ent = EdictNum(entnum);
2019-11-25 17:40:18 -08:00
if(entnum < sv.num_edicts)
{
2019-11-24 20:45:15 -08:00
ent->free = false;
2019-12-06 07:53:56 -08:00
memset(ent->fields, 0, progs.entityfields * 4);
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
else
{
memset(ent, 0, pr_edict_size);
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
data = ED_ParseEdict(data, ent);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
// link it into the bsp tree
if(!ent->free)
SV_LinkEdict(ent, false);
2019-11-24 20:45:15 -08:00
}
entnum++;
}
sv.num_edicts = entnum;
sv.time = time;
2019-11-25 17:40:18 -08:00
free(start);
2019-11-24 20:45:15 -08:00
start = NULL;
2019-11-25 17:40:18 -08:00
for(i = 0; i < NUM_SPAWN_PARMS; i++)
2019-11-24 20:45:15 -08:00
svs.clients->spawn_parms[i] = spawn_parms[i];
2019-11-25 17:40:18 -08:00
if(cls.state != ca_dedicated)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
CL_EstablishConnection("local");
Host_Reconnect_f();
2019-11-24 20:45:15 -08:00
}
}
//============================================================================
/*
======================
Host_Name_f
======================
*/
2019-11-25 17:40:18 -08:00
void Host_Name_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
char newName[32];
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(Cmd_Argc() == 1)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
if(Cmd_Argc() == 2)
2019-11-24 20:45:15 -08:00
q_strlcpy(newName, Cmd_Argv(1), sizeof(newName));
else
q_strlcpy(newName, Cmd_Args(), sizeof(newName));
2019-11-25 17:40:18 -08:00
newName[15] = 0; // client_t structure actually says name[32].
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-12-07 09:27:26 -08:00
if(strcmp(cl_name.string, newName) == 0)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
Cvar_Set("_cl_name", newName);
if(cls.state == ca_connected)
Cmd_ForwardToServer();
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
if(host_client->name[0] && strcmp(host_client->name, "unconnected"))
2019-11-24 20:45:15 -08:00
{
2019-12-07 09:27:26 -08:00
if(strcmp(host_client->name, newName) != 0)
2019-11-25 17:40:18 -08:00
Con_Printf("%s renamed to %s\n", host_client->name, newName);
2019-11-24 20:45:15 -08:00
}
2019-12-07 09:27:26 -08:00
strcpy(host_client->name, newName);
ED_RString(host_client->edict, ED_netname) = PR_SetEngineString(host_client->name);
2019-11-24 20:45:15 -08:00
// send notification to all clients
2019-11-25 17:40:18 -08:00
MSG_WriteByte(&sv.reliable_datagram, svc_updatename);
MSG_WriteByte(&sv.reliable_datagram, host_client - svs.clients);
MSG_WriteString(&sv.reliable_datagram, host_client->name);
2019-11-24 20:45:15 -08:00
}
2019-11-25 15:28:38 -08:00
void Host_Say(bool teamonly)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t j;
client_t *client;
client_t *save;
const char *p;
char text[MAXCMDLINE], *p2;
bool quoted;
bool fromServer = false;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(cls.state != ca_dedicated)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Cmd_ForwardToServer();
2019-11-24 20:45:15 -08:00
return;
}
fromServer = true;
teamonly = false;
}
2019-11-25 17:40:18 -08:00
if(Cmd_Argc() < 2)
2019-11-24 20:45:15 -08:00
return;
save = host_client;
p = Cmd_Args();
// remove quotes if present
quoted = false;
2019-11-25 17:40:18 -08:00
if(*p == '\"')
2019-11-24 20:45:15 -08:00
{
p++;
quoted = true;
}
// turn on color set 1
2019-11-25 17:40:18 -08:00
if(!fromServer)
q_snprintf(text, sizeof(text), "\001%s: %s", save->name, p);
2019-11-24 20:45:15 -08:00
else
2019-11-25 17:40:18 -08:00
q_snprintf(text, sizeof(text), "\001<%s> %s", hostname.string, p);
2019-11-24 20:45:15 -08:00
// check length & truncate if necessary
j = strlen(text);
if(j >= (int32_t)strsizeof(text))
2019-11-24 20:45:15 -08:00
{
text[strsizeof(text) - 1] = '\n';
text[strsizeof(text)] = '\0';
2019-11-24 20:45:15 -08:00
}
else
{
p2 = text + j;
2019-11-25 17:40:18 -08:00
while((const char *)p2 > (const char *)text &&
(p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(p2[-1] == '\"' && quoted)
2019-11-24 20:45:15 -08:00
quoted = false;
p2[-1] = '\0';
p2--;
}
p2[0] = '\n';
p2[1] = '\0';
}
2019-11-25 17:40:18 -08:00
for(j = 0, client = svs.clients; j < svs.maxclients; j++, client++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(!client || !client->active || !client->spawned)
2019-11-24 20:45:15 -08:00
continue;
if(teamplay.value && teamonly && ED_Float(client->edict, ED_team) != ED_Float(save->edict, ED_team))
2019-11-24 20:45:15 -08:00
continue;
host_client = client;
SV_ClientPrintf("%s", text);
}
host_client = save;
2019-11-25 17:40:18 -08:00
if(cls.state == ca_dedicated)
2019-11-24 20:45:15 -08:00
Sys_Printf("%s", &text[1]);
}
void Host_Say_f(void)
{
Host_Say(false);
}
void Host_Say_Team_f(void)
{
Host_Say(true);
}
void Host_Tell_f(void)
{
2019-11-25 17:40:18 -08:00
int32_t j;
client_t *client;
client_t *save;
const char *p;
char text[MAXCMDLINE], *p2;
bool quoted;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Cmd_ForwardToServer();
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
if(Cmd_Argc() < 3)
2019-11-24 20:45:15 -08:00
return;
p = Cmd_Args();
// remove quotes if present
quoted = false;
2019-11-25 17:40:18 -08:00
if(*p == '\"')
2019-11-24 20:45:15 -08:00
{
p++;
quoted = true;
}
2019-11-25 17:40:18 -08:00
q_snprintf(text, sizeof(text), "%s: %s", host_client->name, p);
2019-11-24 20:45:15 -08:00
// check length & truncate if necessary
j = strlen(text);
if(j >= (int32_t)strsizeof(text))
2019-11-24 20:45:15 -08:00
{
text[strsizeof(text) - 1] = '\n';
text[strsizeof(text)] = '\0';
2019-11-24 20:45:15 -08:00
}
else
{
p2 = text + j;
2019-11-25 17:40:18 -08:00
while((const char *)p2 > (const char *)text &&
(p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(p2[-1] == '\"' && quoted)
2019-11-24 20:45:15 -08:00
quoted = false;
p2[-1] = '\0';
p2--;
}
p2[0] = '\n';
p2[1] = '\0';
}
save = host_client;
2019-11-25 17:40:18 -08:00
for(j = 0, client = svs.clients; j < svs.maxclients; j++, client++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(!client->active || !client->spawned)
2019-11-24 20:45:15 -08:00
continue;
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(client->name, Cmd_Argv(1)))
2019-11-24 20:45:15 -08:00
continue;
host_client = client;
SV_ClientPrintf("%s", text);
break;
}
host_client = save;
}
/*
==================
Host_Color_f
==================
*/
void Host_Color_f(void)
{
2019-11-25 17:40:18 -08:00
int32_t top, bottom;
int32_t playercolor;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(Cmd_Argc() == 1)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("\"color\" is \"%" PRIi32 " %" PRIi32 "\"\n", ((int32_t)cl_color.value) >> 4, ((int32_t)cl_color.value) & 0x0f);
Con_Printf("color <0-13> [0-13]\n");
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
if(Cmd_Argc() == 2)
2019-11-24 20:45:15 -08:00
top = bottom = atoi(Cmd_Argv(1));
else
{
top = atoi(Cmd_Argv(1));
bottom = atoi(Cmd_Argv(2));
}
top &= 15;
2019-11-25 17:40:18 -08:00
if(top > 13)
2019-11-24 20:45:15 -08:00
top = 13;
bottom &= 15;
2019-11-25 17:40:18 -08:00
if(bottom > 13)
2019-11-24 20:45:15 -08:00
bottom = 13;
2019-11-25 17:40:18 -08:00
playercolor = top * 16 + bottom;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Cvar_SetValue("_cl_color", playercolor);
if(cls.state == ca_connected)
Cmd_ForwardToServer();
2019-11-24 20:45:15 -08:00
return;
}
host_client->colors = playercolor;
ED_Float(host_client->edict, ED_team) = bottom + 1;
2019-11-24 20:45:15 -08:00
// send notification to all clients
2019-11-25 17:40:18 -08:00
MSG_WriteByte(&sv.reliable_datagram, svc_updatecolors);
MSG_WriteByte(&sv.reliable_datagram, host_client - svs.clients);
MSG_WriteByte(&sv.reliable_datagram, host_client->colors);
2019-11-24 20:45:15 -08:00
}
/*
==================
Host_Kill_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Kill_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Cmd_ForwardToServer();
2019-11-24 20:45:15 -08:00
return;
}
if(ED_Float(sv_player, ED_health) <= 0)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("Can't suicide -- allready dead!\n");
2019-11-24 20:45:15 -08:00
return;
}
G_Float(GBL_time) = sv.time;
G_PEdict(GBL_self) = EdictProg(sv_player);
PR_ExecuteProgram(G_Func(GBL_ClientKill));
2019-11-24 20:45:15 -08:00
}
/*
==================
Host_Pause_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Pause_f(void)
2019-11-24 20:45:15 -08:00
{
//ericw -- demo pause support (inspired by MarkV)
2019-11-25 17:40:18 -08:00
if(cls.demoplayback)
2019-11-24 20:45:15 -08:00
{
cls.demopaused = !cls.demopaused;
cl.paused = cls.demopaused;
return;
}
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Cmd_ForwardToServer();
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
if(!pausable.value)
SV_ClientPrintf("Pause not allowed.\n");
2019-11-24 20:45:15 -08:00
else
{
sv.paused ^= 1;
2019-11-25 17:40:18 -08:00
if(sv.paused)
2019-11-24 20:45:15 -08:00
{
SV_BroadcastPrintf("%s paused the game\n", ED_String(sv_player, ED_netname));
2019-11-24 20:45:15 -08:00
}
else
{
SV_BroadcastPrintf("%s unpaused the game\n", ED_String(sv_player, ED_netname));
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
// send notification to all clients
MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
MSG_WriteByte(&sv.reliable_datagram, sv.paused);
2019-11-24 20:45:15 -08:00
}
}
//===========================================================================
/*
==================
Host_PreSpawn_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_PreSpawn_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("prespawn is not valid from the console\n");
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
if(host_client->spawned)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("prespawn not valid -- allready spawned\n");
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
SZ_Write(&host_client->message, sv.signon.data, sv.signon.cursize);
MSG_WriteByte(&host_client->message, svc_signonnum);
MSG_WriteByte(&host_client->message, 2);
2019-11-24 20:45:15 -08:00
host_client->sendsignon = true;
}
/*
==================
Host_Spawn_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Spawn_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t i;
client_t *client;
edict_t *ent;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("spawn is not valid from the console\n");
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
if(host_client->spawned)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("Spawn not valid -- allready spawned\n");
2019-11-24 20:45:15 -08:00
return;
}
// run the entrance script
2019-11-25 17:40:18 -08:00
if(sv.loadgame)
{
// loaded games are fully inited allready
2019-11-24 20:45:15 -08:00
// if this is the last client to be connected, unpause
sv.paused = false;
}
else
{
// set up the edict
ent = host_client->edict;
2019-12-06 07:53:56 -08:00
memset(ent->fields, 0, progs.entityfields * 4);
ED_Float(ent, ED_colormap) = NumForEdict(ent);
ED_Float(ent, ED_team) = (host_client->colors & 15) + 1;
ED_RString(ent, ED_netname) = PR_SetEngineString(host_client->name);
2019-11-24 20:45:15 -08:00
// copy spawn parms out of the client_t
2019-11-25 17:40:18 -08:00
for(i = 0 ; i < NUM_SPAWN_PARMS ; i++)
(&G_Float(GBL_parm1))[i] = host_client->spawn_parms[i];
2019-11-24 20:45:15 -08:00
// call the spawn function
G_Float(GBL_time) = sv.time;
G_PEdict(GBL_self) = EdictProg(sv_player);
PR_ExecuteProgram(G_Func(GBL_ClientConnect));
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if((Sys_DoubleTime() - NET_QSocketGetTime(host_client->netconnection)) <= sv.time)
Sys_Printf("%s entered the game\n", host_client->name);
2019-11-24 20:45:15 -08:00
PR_ExecuteProgram(G_Func(GBL_PutClientInServer));
2019-11-24 20:45:15 -08:00
}
// send all current names, colors, and frag counts
2019-11-25 17:40:18 -08:00
SZ_Clear(&host_client->message);
2019-11-24 20:45:15 -08:00
// send time of update
2019-11-25 17:40:18 -08:00
MSG_WriteByte(&host_client->message, svc_time);
MSG_WriteFloat(&host_client->message, sv.time);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
for(i = 0, client = svs.clients; i < svs.maxclients; i++, client++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
MSG_WriteByte(&host_client->message, svc_updatename);
MSG_WriteByte(&host_client->message, i);
MSG_WriteString(&host_client->message, client->name);
MSG_WriteByte(&host_client->message, svc_updatefrags);
MSG_WriteByte(&host_client->message, i);
MSG_WriteShort(&host_client->message, client->old_frags);
MSG_WriteByte(&host_client->message, svc_updatecolors);
MSG_WriteByte(&host_client->message, i);
MSG_WriteByte(&host_client->message, client->colors);
2019-11-24 20:45:15 -08:00
}
// send all current light styles
2019-11-25 17:40:18 -08:00
for(i = 0; i < MAX_LIGHTSTYLES; i++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
MSG_WriteByte(&host_client->message, svc_lightstyle);
MSG_WriteByte(&host_client->message, (char)i);
MSG_WriteString(&host_client->message, sv.lightstyles[i]);
2019-11-24 20:45:15 -08:00
}
//
// send some stats
//
2019-11-25 17:40:18 -08:00
MSG_WriteByte(&host_client->message, svc_updatestat);
MSG_WriteByte(&host_client->message, STAT_TOTALSECRETS);
MSG_WriteLong(&host_client->message, G_Float(GBL_total_secrets));
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
MSG_WriteByte(&host_client->message, svc_updatestat);
MSG_WriteByte(&host_client->message, STAT_TOTALMONSTERS);
MSG_WriteLong(&host_client->message, G_Float(GBL_total_monsters));
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
MSG_WriteByte(&host_client->message, svc_updatestat);
MSG_WriteByte(&host_client->message, STAT_SECRETS);
MSG_WriteLong(&host_client->message, G_Float(GBL_found_secrets));
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
MSG_WriteByte(&host_client->message, svc_updatestat);
MSG_WriteByte(&host_client->message, STAT_MONSTERS);
MSG_WriteLong(&host_client->message, G_Float(GBL_killed_monsters));
2019-11-24 20:45:15 -08:00
//
// send a fixangle
// Never send a roll angle, because savegames can catch the server
// in a state where it is expecting the client to correct the angle
// and it won't happen if the game was just loaded, so you wind up
// with a permanent head tilt
ent = EdictNum(1 + (host_client - svs.clients));
2019-11-25 17:40:18 -08:00
MSG_WriteByte(&host_client->message, svc_setangle);
for(i = 0; i < 2; i++)
MSG_WriteAngle(&host_client->message, ED_Vector(ent, ED_angles)[i], sv.protocolflags);
2019-11-25 17:40:18 -08:00
MSG_WriteAngle(&host_client->message, 0, sv.protocolflags);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
SV_WriteClientdataToMessage(sv_player, &host_client->message);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
MSG_WriteByte(&host_client->message, svc_signonnum);
MSG_WriteByte(&host_client->message, 3);
2019-11-24 20:45:15 -08:00
host_client->sendsignon = true;
}
/*
==================
Host_Begin_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Begin_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("begin is not valid from the console\n");
2019-11-24 20:45:15 -08:00
return;
}
host_client->spawned = true;
}
//===========================================================================
/*
==================
Host_Kick_f
Kicks a user off of the server
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Kick_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
const char *who;
const char *message = NULL;
client_t *save;
int32_t i;
bool byNumber = false;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(!sv.active)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Cmd_ForwardToServer();
2019-11-24 20:45:15 -08:00
return;
}
}
else if(G_Float(GBL_deathmatch))
2019-11-24 20:45:15 -08:00
return;
save = host_client;
2019-12-07 09:27:26 -08:00
if(Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
2019-11-24 20:45:15 -08:00
{
2019-12-07 09:27:26 -08:00
i = atof(Cmd_Argv(2)) - 1;
2019-11-25 17:40:18 -08:00
if(i < 0 || i >= svs.maxclients)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
if(!svs.clients[i].active)
2019-11-24 20:45:15 -08:00
return;
host_client = &svs.clients[i];
byNumber = true;
}
else
{
2019-11-25 17:40:18 -08:00
for(i = 0, host_client = svs.clients; i < svs.maxclients; i++, host_client++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(!host_client->active)
2019-11-24 20:45:15 -08:00
continue;
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
2019-11-24 20:45:15 -08:00
break;
}
}
2019-11-25 17:40:18 -08:00
if(i < svs.maxclients)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
if(cls.state == ca_dedicated)
2019-11-24 20:45:15 -08:00
who = "Console";
else
who = cl_name.string;
else
who = save->name;
// can't kick yourself!
2019-11-25 17:40:18 -08:00
if(host_client == save)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
if(Cmd_Argc() > 2)
2019-11-24 20:45:15 -08:00
{
message = COM_Parse(Cmd_Args());
2019-11-25 17:40:18 -08:00
if(byNumber)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
message++; // skip the #
while(*message == ' ') // skip white space
2019-11-24 20:45:15 -08:00
message++;
2019-11-25 17:40:18 -08:00
message += strlen(Cmd_Argv(2)); // skip the number
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
while(*message && *message == ' ')
2019-11-24 20:45:15 -08:00
message++;
}
2019-11-25 17:40:18 -08:00
if(message)
SV_ClientPrintf("Kicked by %s: %s\n", who, message);
2019-11-24 20:45:15 -08:00
else
2019-11-25 17:40:18 -08:00
SV_ClientPrintf("Kicked by %s\n", who);
SV_DropClient(false);
2019-11-24 20:45:15 -08:00
}
host_client = save;
}
/*
===============================================================================
DEBUGGING TOOLS
===============================================================================
*/
/*
==================
Host_Give_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Give_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
const char *t;
int32_t v;
eval_t *val;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(cmd_source == src_command)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Cmd_ForwardToServer();
2019-11-24 20:45:15 -08:00
return;
}
if(G_Float(GBL_deathmatch))
2019-11-24 20:45:15 -08:00
return;
t = Cmd_Argv(1);
2019-11-25 17:40:18 -08:00
v = atoi(Cmd_Argv(2));
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
switch(t[0])
2019-11-24 20:45:15 -08:00
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
// MED 01/04/97 added hipnotic give stuff
2019-11-25 17:40:18 -08:00
if(hipnotic)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(t[0] == '6')
{
if(t[1] == 'a')
ED_Float(sv_player, ED_items) = (int32_t)ED_Float(sv_player, ED_items) | HIT_PROXIMITY_GUN;
2019-11-25 17:40:18 -08:00
else
ED_Float(sv_player, ED_items) = (int32_t)ED_Float(sv_player, ED_items) | IT_GRENADE_LAUNCHER;
2019-11-25 17:40:18 -08:00
}
else if(t[0] == '9')
ED_Float(sv_player, ED_items) = (int32_t)ED_Float(sv_player, ED_items) | HIT_LASER_CANNON;
2019-11-25 17:40:18 -08:00
else if(t[0] == '0')
ED_Float(sv_player, ED_items) = (int32_t)ED_Float(sv_player, ED_items) | HIT_MJOLNIR;
2019-11-25 17:40:18 -08:00
else if(t[0] >= '2')
ED_Float(sv_player, ED_items) = (int32_t)ED_Float(sv_player, ED_items) | (IT_SHOTGUN << (t[0] - '2'));
2019-11-24 20:45:15 -08:00
}
else
{
2019-11-25 17:40:18 -08:00
if(t[0] >= '2')
ED_Float(sv_player, ED_items) = (int32_t)ED_Float(sv_player, ED_items) | (IT_SHOTGUN << (t[0] - '2'));
2019-11-24 20:45:15 -08:00
}
break;
case 's':
2019-11-25 17:40:18 -08:00
if(rogue)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
val = GetEdictFieldValue(sv_player, "ammo_shells1");
if(val)
2019-12-07 09:27:26 -08:00
val->flt = v;
2019-11-24 20:45:15 -08:00
}
ED_Float(sv_player, ED_ammo_shells) = v;
2019-11-24 20:45:15 -08:00
break;
case 'n':
2019-11-25 17:40:18 -08:00
if(rogue)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
val = GetEdictFieldValue(sv_player, "ammo_nails1");
if(val)
{
2019-12-07 09:27:26 -08:00
val->flt = v;
if(ED_Float(sv_player, ED_weapon) <= IT_LIGHTNING)
ED_Float(sv_player, ED_ammo_nails) = v;
2019-11-25 17:40:18 -08:00
}
2019-11-24 20:45:15 -08:00
}
else
{
ED_Float(sv_player, ED_ammo_nails) = v;
2019-11-24 20:45:15 -08:00
}
break;
case 'l':
2019-11-25 17:40:18 -08:00
if(rogue)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
val = GetEdictFieldValue(sv_player, "ammo_lava_nails");
if(val)
{
2019-12-07 09:27:26 -08:00
val->flt = v;
if(ED_Float(sv_player, ED_weapon) > IT_LIGHTNING)
ED_Float(sv_player, ED_ammo_nails) = v;
2019-11-25 17:40:18 -08:00
}
2019-11-24 20:45:15 -08:00
}
break;
case 'r':
2019-11-25 17:40:18 -08:00
if(rogue)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
val = GetEdictFieldValue(sv_player, "ammo_rockets1");
if(val)
{
2019-12-07 09:27:26 -08:00
val->flt = v;
if(ED_Float(sv_player, ED_weapon) <= IT_LIGHTNING)
ED_Float(sv_player, ED_ammo_rockets) = v;
2019-11-25 17:40:18 -08:00
}
2019-11-24 20:45:15 -08:00
}
else
{
ED_Float(sv_player, ED_ammo_rockets) = v;
2019-11-24 20:45:15 -08:00
}
break;
case 'm':
2019-11-25 17:40:18 -08:00
if(rogue)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
val = GetEdictFieldValue(sv_player, "ammo_multi_rockets");
if(val)
{
2019-12-07 09:27:26 -08:00
val->flt = v;
if(ED_Float(sv_player, ED_weapon) > IT_LIGHTNING)
ED_Float(sv_player, ED_ammo_rockets) = v;
2019-11-25 17:40:18 -08:00
}
2019-11-24 20:45:15 -08:00
}
break;
case 'h':
ED_Float(sv_player, ED_health) = v;
2019-11-24 20:45:15 -08:00
break;
case 'c':
2019-11-25 17:40:18 -08:00
if(rogue)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
val = GetEdictFieldValue(sv_player, "ammo_cells1");
if(val)
{
2019-12-07 09:27:26 -08:00
val->flt = v;
if(ED_Float(sv_player, ED_weapon) <= IT_LIGHTNING)
ED_Float(sv_player, ED_ammo_cells) = v;
2019-11-25 17:40:18 -08:00
}
2019-11-24 20:45:15 -08:00
}
else
{
ED_Float(sv_player, ED_ammo_cells) = v;
2019-11-24 20:45:15 -08:00
}
break;
case 'p':
2019-11-25 17:40:18 -08:00
if(rogue)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
val = GetEdictFieldValue(sv_player, "ammo_plasma");
if(val)
{
2019-12-07 09:27:26 -08:00
val->flt = v;
if(ED_Float(sv_player, ED_weapon) > IT_LIGHTNING)
ED_Float(sv_player, ED_ammo_cells) = v;
2019-11-25 17:40:18 -08:00
}
2019-11-24 20:45:15 -08:00
}
break;
//johnfitz -- give armour
case 'a':
2019-11-25 17:40:18 -08:00
if(v > 150)
2019-11-24 20:45:15 -08:00
{
ED_Float(sv_player, ED_armortype) = 0.8;
ED_Float(sv_player, ED_armorvalue) = v;
ED_Float(sv_player, ED_items) = ED_Float(sv_player, ED_items) -
((int32_t)(ED_Float(sv_player, ED_items)) & (int32_t)(IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3)) +
2019-11-25 17:40:18 -08:00
IT_ARMOR3;
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
else if(v > 100)
2019-11-24 20:45:15 -08:00
{
ED_Float(sv_player, ED_armortype) = 0.6;
ED_Float(sv_player, ED_armorvalue) = v;
ED_Float(sv_player, ED_items) = ED_Float(sv_player, ED_items) -
((int32_t)(ED_Float(sv_player, ED_items)) & (int32_t)(IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3)) +
2019-11-25 17:40:18 -08:00
IT_ARMOR2;
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
else if(v >= 0)
2019-11-24 20:45:15 -08:00
{
ED_Float(sv_player, ED_armortype) = 0.3;
ED_Float(sv_player, ED_armorvalue) = v;
ED_Float(sv_player, ED_items) = ED_Float(sv_player, ED_items) -
((int32_t)(ED_Float(sv_player, ED_items)) & (int32_t)(IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3)) +
2019-11-25 17:40:18 -08:00
IT_ARMOR1;
2019-11-24 20:45:15 -08:00
}
break;
//johnfitz
}
//johnfitz -- update currentammo to match new ammo (so statusbar updates correctly)
switch((int32_t)(ED_Float(sv_player, ED_weapon)))
2019-11-24 20:45:15 -08:00
{
case IT_SHOTGUN:
case IT_SUPER_SHOTGUN:
ED_Float(sv_player, ED_currentammo) = ED_Float(sv_player, ED_ammo_shells);
2019-11-24 20:45:15 -08:00
break;
case IT_NAILGUN:
case IT_SUPER_NAILGUN:
case RIT_LAVA_SUPER_NAILGUN:
ED_Float(sv_player, ED_currentammo) = ED_Float(sv_player, ED_ammo_nails);
2019-11-24 20:45:15 -08:00
break;
case IT_GRENADE_LAUNCHER:
case IT_ROCKET_LAUNCHER:
case RIT_MULTI_GRENADE:
case RIT_MULTI_ROCKET:
ED_Float(sv_player, ED_currentammo) = ED_Float(sv_player, ED_ammo_rockets);
2019-11-24 20:45:15 -08:00
break;
case IT_LIGHTNING:
case HIT_LASER_CANNON:
case HIT_MJOLNIR:
ED_Float(sv_player, ED_currentammo) = ED_Float(sv_player, ED_ammo_cells);
2019-11-24 20:45:15 -08:00
break;
case RIT_LAVA_NAILGUN: //same as IT_AXE
2019-11-25 17:40:18 -08:00
if(rogue)
ED_Float(sv_player, ED_currentammo) = ED_Float(sv_player, ED_ammo_nails);
2019-11-24 20:45:15 -08:00
break;
case RIT_PLASMA_GUN: //same as HIT_PROXIMITY_GUN
2019-11-25 17:40:18 -08:00
if(rogue)
ED_Float(sv_player, ED_currentammo) = ED_Float(sv_player, ED_ammo_cells);
2019-11-25 17:40:18 -08:00
if(hipnotic)
ED_Float(sv_player, ED_currentammo) = ED_Float(sv_player, ED_ammo_rockets);
2019-11-24 20:45:15 -08:00
break;
}
//johnfitz
}
2019-11-25 17:40:18 -08:00
edict_t *FindViewthing(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t i;
edict_t *e;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
for(i = 0 ; i < sv.num_edicts ; i++)
2019-11-24 20:45:15 -08:00
{
e = EdictNum(i);
if(!strcmp(ED_String(e, ED_classname), "viewthing"))
2019-11-24 20:45:15 -08:00
return e;
}
2019-11-25 17:40:18 -08:00
Con_Printf("No viewthing on map\n");
2019-11-24 20:45:15 -08:00
return NULL;
}
/*
==================
Host_Viewmodel_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Viewmodel_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
edict_t *e;
qmodel_t *m;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
e = FindViewthing();
if(!e)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
m = Mod_ForName(Cmd_Argv(1), false);
if(!m)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("Can't load %s\n", Cmd_Argv(1));
2019-11-24 20:45:15 -08:00
return;
}
ED_Float(e, ED_frame) = 0;
cl.model_precache[(int32_t)ED_Float(e, ED_modelindex)] = m;
2019-11-24 20:45:15 -08:00
}
/*
==================
Host_Viewframe_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Viewframe_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
edict_t *e;
int32_t f;
qmodel_t *m;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
e = FindViewthing();
if(!e)
2019-11-24 20:45:15 -08:00
return;
m = cl.model_precache[(int32_t)ED_Float(e, ED_modelindex)];
2019-11-24 20:45:15 -08:00
f = atoi(Cmd_Argv(1));
2019-11-25 17:40:18 -08:00
if(f >= m->numframes)
2019-11-24 20:45:15 -08:00
f = m->numframes - 1;
ED_Float(e, ED_frame) = f;
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
void PrintFrameName(qmodel_t *m, int32_t frame)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
aliashdr_t *hdr;
maliasframedesc_t *pframedesc;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
hdr = (aliashdr_t *)Mod_Extradata(m);
if(!hdr)
2019-11-24 20:45:15 -08:00
return;
pframedesc = &hdr->frames[frame];
2019-11-25 17:40:18 -08:00
Con_Printf("frame %" PRIi32 ": %s\n", frame, pframedesc->name);
2019-11-24 20:45:15 -08:00
}
/*
==================
Host_Viewnext_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Viewnext_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
edict_t *e;
qmodel_t *m;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
e = FindViewthing();
if(!e)
2019-11-24 20:45:15 -08:00
return;
m = cl.model_precache[(int32_t)ED_Float(e, ED_modelindex)];
2019-11-24 20:45:15 -08:00
ED_Float(e, ED_frame) = ED_Float(e, ED_frame) + 1;
if(ED_Float(e, ED_frame) >= m->numframes)
ED_Float(e, ED_frame) = m->numframes - 1;
2019-11-24 20:45:15 -08:00
PrintFrameName(m, ED_Float(e, ED_frame));
2019-11-24 20:45:15 -08:00
}
/*
==================
Host_Viewprev_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Viewprev_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
edict_t *e;
qmodel_t *m;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
e = FindViewthing();
if(!e)
2019-11-24 20:45:15 -08:00
return;
m = cl.model_precache[(int32_t)ED_Float(e, ED_modelindex)];
2019-11-24 20:45:15 -08:00
ED_Float(e, ED_frame) = ED_Float(e, ED_frame) - 1;
if(ED_Float(e, ED_frame) < 0)
ED_Float(e, ED_frame) = 0;
2019-11-24 20:45:15 -08:00
PrintFrameName(m, ED_Float(e, ED_frame));
2019-11-24 20:45:15 -08:00
}
/*
===============================================================================
DEMO LOOP CONTROL
===============================================================================
*/
/*
==================
Host_Startdemos_f
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Startdemos_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t i, c;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(cls.state == ca_dedicated)
2019-11-24 20:45:15 -08:00
return;
c = Cmd_Argc() - 1;
2019-11-25 17:40:18 -08:00
if(c > MAX_DEMOS)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("Max %" PRIi32 " demos in demoloop\n", MAX_DEMOS);
2019-11-24 20:45:15 -08:00
c = MAX_DEMOS;
}
2019-11-25 17:40:18 -08:00
Con_Printf("%" PRIi32 " demo(s) in loop\n", c);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
for(i = 1; i < c + 1; i++)
q_strlcpy(cls.demos[i - 1], Cmd_Argv(i), sizeof(cls.demos[0]));
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(!sv.active && cls.demonum != -1 && !cls.demoplayback)
2019-11-24 20:45:15 -08:00
{
cls.demonum = 0;
2019-11-25 17:40:18 -08:00
CL_NextDemo();
2019-11-24 20:45:15 -08:00
}
else
{
cls.demonum = -1;
}
}
/*
==================
Host_Demos_f
Return to looping demos
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Demos_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(cls.state == ca_dedicated)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
if(cls.demonum == -1)
2019-11-24 20:45:15 -08:00
cls.demonum = 1;
2019-11-25 17:40:18 -08:00
CL_Disconnect_f();
CL_NextDemo();
2019-11-24 20:45:15 -08:00
}
/*
==================
Host_Stopdemo_f
Return to looping demos
==================
*/
2019-11-25 17:40:18 -08:00
void Host_Stopdemo_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(cls.state == ca_dedicated)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
if(!cls.demoplayback)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
CL_StopPlayback();
CL_Disconnect();
2019-11-24 20:45:15 -08:00
}
//=============================================================================
/*
==================
Host_InitCommands
==================
*/
2019-11-25 17:40:18 -08:00
void Host_InitCommands(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Cmd_AddCommand("maps", Host_Maps_f); //johnfitz
Cmd_AddCommand("mods", Host_Mods_f); //johnfitz
Cmd_AddCommand("games", Host_Mods_f); // as an alias to "mods" -- S.A. / QuakeSpasm
Cmd_AddCommand("mapname", Host_Mapname_f); //johnfitz
Cmd_AddCommand("randmap", Host_Randmap_f); //ericw
Cmd_AddCommand("status", Host_Status_f);
Cmd_AddCommand("quit", Host_Quit_f);
Cmd_AddCommand("god", Host_God_f);
Cmd_AddCommand("notarget", Host_Notarget_f);
Cmd_AddCommand("fly", Host_Fly_f);
Cmd_AddCommand("map", Host_Map_f);
Cmd_AddCommand("restart", Host_Restart_f);
Cmd_AddCommand("changelevel", Host_Changelevel_f);
Cmd_AddCommand("connect", Host_Connect_f);
Cmd_AddCommand("reconnect", Host_Reconnect_f);
Cmd_AddCommand("name", Host_Name_f);
Cmd_AddCommand("noclip", Host_Noclip_f);
Cmd_AddCommand("setpos", Host_SetPos_f); //QuakeSpasm
Cmd_AddCommand("say", Host_Say_f);
Cmd_AddCommand("say_team", Host_Say_Team_f);
Cmd_AddCommand("tell", Host_Tell_f);
Cmd_AddCommand("color", Host_Color_f);
Cmd_AddCommand("kill", Host_Kill_f);
Cmd_AddCommand("pause", Host_Pause_f);
Cmd_AddCommand("spawn", Host_Spawn_f);
Cmd_AddCommand("begin", Host_Begin_f);
Cmd_AddCommand("prespawn", Host_PreSpawn_f);
Cmd_AddCommand("kick", Host_Kick_f);
Cmd_AddCommand("ping", Host_Ping_f);
Cmd_AddCommand("load", Host_Loadgame_f);
Cmd_AddCommand("save", Host_Savegame_f);
Cmd_AddCommand("give", Host_Give_f);
Cmd_AddCommand("startdemos", Host_Startdemos_f);
Cmd_AddCommand("demos", Host_Demos_f);
Cmd_AddCommand("stopdemo", Host_Stopdemo_f);
Cmd_AddCommand("viewmodel", Host_Viewmodel_f);
Cmd_AddCommand("viewframe", Host_Viewframe_f);
Cmd_AddCommand("viewnext", Host_Viewnext_f);
Cmd_AddCommand("viewprev", Host_Viewprev_f);
Cmd_AddCommand("mcache", Mod_Print);
2019-11-24 20:45:15 -08:00
}