2005-07-24 14:12:37 +00:00
/* $Id$ */
2004-09-12 21:49:38 +00:00
# include "stdafx.h"
2005-06-02 19:30:21 +00:00
# include "openttd.h"
2004-09-12 21:49:38 +00:00
# include "console.h"
2005-02-05 15:58:59 +00:00
# include "debug.h"
2004-09-12 21:49:38 +00:00
# include "engine.h"
# include "functions.h"
2005-07-22 06:31:31 +00:00
# include "saveload.h"
2005-02-06 13:41:02 +00:00
# include "string.h"
2004-09-12 21:49:38 +00:00
# include "variables.h"
2004-12-04 17:54:56 +00:00
# include "network_data.h"
# include "network_client.h"
# include "network_server.h"
2004-12-22 19:16:10 +00:00
# include "network_udp.h"
2004-12-04 17:54:56 +00:00
# include "command.h"
2004-12-13 15:07:33 +00:00
# include "settings.h"
2005-01-04 15:06:08 +00:00
# include "hal.h" /* for file list */
2005-06-16 00:54:19 +00:00
# include "vehicle.h"
2004-09-12 21:49:38 +00:00
2004-09-14 16:10:20 +00:00
// ** scriptfile handling ** //
2005-05-02 15:52:19 +00:00
static FILE * _script_file ;
2004-09-14 16:10:20 +00:00
static bool _script_running ;
2004-09-12 21:49:38 +00:00
// ** console command / variable defines ** //
2005-05-02 15:52:19 +00:00
# define DEF_CONSOLE_CMD(function) static bool function(byte argc, char *argv[])
# define DEF_CONSOLE_HOOK(function) static bool function(void)
2004-09-12 21:49:38 +00:00
2004-09-14 16:10:20 +00:00
2004-09-12 21:49:38 +00:00
/* **************************** */
/* variable and command hooks */
/* **************************** */
2004-12-04 17:54:56 +00:00
# ifdef ENABLE_NETWORK
2005-05-02 15:52:19 +00:00
static inline bool NetworkAvailable ( void )
2004-09-12 21:49:38 +00:00
{
2005-05-02 15:52:19 +00:00
if ( ! _network_available ) {
IConsoleError ( " You cannot use this command because there is no network available. " ) ;
2004-09-12 21:49:38 +00:00
return false ;
2004-09-19 15:24:45 +00:00
}
2004-09-12 21:49:38 +00:00
return true ;
}
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_HOOK ( ConHookServerOnly )
2004-09-12 21:49:38 +00:00
{
2005-05-02 15:52:19 +00:00
if ( ! NetworkAvailable ( ) ) return false ;
2004-12-04 17:54:56 +00:00
if ( ! _network_server ) {
2005-05-11 15:30:28 +00:00
IConsoleError ( " This command/variable is only available to a network server. " ) ;
2004-09-12 21:49:38 +00:00
return false ;
2004-09-19 15:24:45 +00:00
}
2004-09-12 21:49:38 +00:00
return true ;
}
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_HOOK ( ConHookClientOnly )
2004-09-12 21:49:38 +00:00
{
2005-05-02 15:52:19 +00:00
if ( ! NetworkAvailable ( ) ) return false ;
if ( _network_server ) {
2005-05-11 15:30:28 +00:00
IConsoleError ( " This command/variable is not available to a network server. " ) ;
2004-12-04 17:54:56 +00:00
return false ;
}
return true ;
}
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_HOOK ( ConHookNeedNetwork )
2004-12-04 17:54:56 +00:00
{
2005-05-02 15:52:19 +00:00
if ( ! NetworkAvailable ( ) ) return false ;
if ( ! _networking ) {
2005-05-11 15:30:28 +00:00
IConsoleError ( " Not connected. This command/variable is only available in multiplayer. " ) ;
2004-09-12 21:49:38 +00:00
return false ;
2004-09-19 15:24:45 +00:00
}
2004-09-12 21:49:38 +00:00
return true ;
}
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_HOOK ( ConHookNoNetwork )
2004-12-04 17:54:56 +00:00
{
2005-05-02 15:52:19 +00:00
if ( _networking ) {
2005-05-11 15:30:28 +00:00
IConsoleError ( " This command/variable is forbidden in multiplayer. " ) ;
2004-12-04 17:54:56 +00:00
return false ;
}
return true ;
}
# endif /* ENABLE_NETWORK */
2005-05-02 15:52:19 +00:00
static void IConsoleHelp ( const char * str )
{
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_warn , " - %s " , str ) ;
2005-05-02 15:52:19 +00:00
}
2004-09-12 21:49:38 +00:00
2005-06-16 00:54:19 +00:00
DEF_CONSOLE_CMD ( ConStopAllVehicles )
{
Vehicle * v ;
if ( argc = = 0 ) {
2005-06-16 20:54:37 +00:00
IConsoleHelp ( " Stops all vehicles in the game. For debugging only! Use at your own risk... Usage: 'stopall' " ) ;
2005-06-16 00:54:19 +00:00
return true ;
}
FOR_ALL_VEHICLES ( v ) {
if ( IsValidVehicle ( v ) ) {
/* Code ripped from CmdStartStopTrain. Can't call it, because of
* ownership problems , so we ' ll duplicate some code , for now */
if ( v - > type = = VEH_Train )
v - > u . rail . days_since_order_progr = 0 ;
v - > vehstatus | = VS_STOPPED ;
InvalidateWindowWidget ( WC_VEHICLE_VIEW , v - > index , STATUS_BAR ) ;
InvalidateWindow ( WC_VEHICLE_DEPOT , v - > tile ) ;
}
}
return true ;
}
2004-09-12 21:49:38 +00:00
DEF_CONSOLE_CMD ( ConResetEngines )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Reset status data of all engines. This might solve some issues with 'lost' engines. Usage: 'resetengines' " ) ;
return true ;
}
2004-09-12 21:49:38 +00:00
StartupEngines ( ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
2004-09-19 15:24:45 +00:00
# ifdef _DEBUG
2004-09-12 21:49:38 +00:00
DEF_CONSOLE_CMD ( ConResetTile )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Reset a tile to bare land. Usage: 'resettile <tile>' " ) ;
IConsoleHelp ( " Tile can be either decimal (34161) or hexadecimal (0x4a5B) " ) ;
return true ;
}
2004-09-12 21:49:38 +00:00
if ( argc = = 2 ) {
2005-05-02 15:52:19 +00:00
uint32 result ;
if ( GetArgumentInteger ( & result , argv [ 1 ] ) ) {
DoClearSquare ( ( TileIndex ) result ) ;
return true ;
}
2004-09-12 21:49:38 +00:00
}
2005-05-02 15:52:19 +00:00
return false ;
2004-09-12 21:49:38 +00:00
}
2005-05-02 16:00:49 +00:00
# endif /* _DEBUG */
2004-09-12 21:49:38 +00:00
DEF_CONSOLE_CMD ( ConScrollToTile )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Center the screen on a given tile. Usage: 'scrollto <tile>' " ) ;
IConsoleHelp ( " Tile can be either decimal (34161) or hexadecimal (0x4a5B) " ) ;
return true ;
}
2004-09-12 21:49:38 +00:00
if ( argc = = 2 ) {
2005-05-02 15:52:19 +00:00
uint32 result ;
if ( GetArgumentInteger ( & result , argv [ 1 ] ) ) {
ScrollMainWindowToTile ( ( TileIndex ) result ) ;
return true ;
}
2004-09-12 21:49:38 +00:00
}
2005-05-02 15:52:19 +00:00
return false ;
2004-09-12 21:49:38 +00:00
}
2005-01-04 15:06:08 +00:00
extern bool SafeSaveOrLoad ( const char * filename , int mode , int newgm ) ;
2005-01-22 20:23:18 +00:00
extern void BuildFileList ( void ) ;
2005-01-04 15:06:08 +00:00
extern void SetFiosType ( const byte fiostype ) ;
2005-03-25 18:26:49 +00:00
/* Save the map to a file */
DEF_CONSOLE_CMD ( ConSave )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Save the current game. Usage: 'save <filename>' " ) ;
return true ;
}
2005-03-25 18:26:49 +00:00
if ( argc = = 2 ) {
2005-05-02 15:52:19 +00:00
char buf [ 200 ] ;
snprintf ( buf , lengthof ( buf ) , " %s%s%s.sav " , _path . save_dir , PATHSEP , argv [ 1 ] ) ;
2005-05-14 19:34:59 +00:00
IConsolePrint ( _icolour_def , " Saving map... " ) ;
2005-05-02 15:52:19 +00:00
if ( SaveOrLoad ( buf , SL_SAVE ) ! = SL_OK ) {
2005-05-14 19:34:59 +00:00
IConsolePrint ( _icolour_err , " SaveMap failed " ) ;
2005-05-02 15:52:19 +00:00
} else
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_def , " Map sucessfully saved to %s " , buf ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-03-25 18:26:49 +00:00
}
2005-05-02 15:52:19 +00:00
return false ;
2005-03-25 18:26:49 +00:00
}
2005-03-27 12:48:25 +00:00
static const FiosItem * GetFiosItem ( const char * file )
2005-01-04 15:06:08 +00:00
{
2005-03-27 12:48:25 +00:00
int i ;
2005-01-04 15:06:08 +00:00
2005-05-13 17:05:03 +00:00
_saveload_mode = SLD_LOAD_GAME ;
2005-03-27 12:48:25 +00:00
BuildFileList ( ) ;
2005-01-04 15:06:08 +00:00
2005-03-27 12:48:25 +00:00
for ( i = 0 ; i < _fios_num ; i + + ) {
if ( strcmp ( file , _fios_list [ i ] . name ) = = 0 ) break ;
2005-07-17 15:58:47 +00:00
if ( strcmp ( file , _fios_list [ i ] . title ) = = 0 ) break ;
2005-03-27 12:48:25 +00:00
}
2005-01-04 15:06:08 +00:00
2005-03-27 12:48:25 +00:00
if ( i = = _fios_num ) { /* If no name matches, try to parse it as number */
char * endptr ;
2005-01-08 00:48:10 +00:00
2005-03-27 12:48:25 +00:00
i = strtol ( file , & endptr , 10 ) ;
if ( file = = endptr | | * endptr ! = ' \0 ' ) i = - 1 ;
}
2005-01-04 15:06:08 +00:00
2005-03-27 12:48:25 +00:00
return IS_INT_INSIDE ( i , 0 , _fios_num ) ? & _fios_list [ i ] : NULL ;
2005-01-04 15:06:08 +00:00
}
2005-03-27 12:48:25 +00:00
2005-01-04 15:06:08 +00:00
DEF_CONSOLE_CMD ( ConLoad )
{
2005-05-02 15:52:19 +00:00
const FiosItem * item ;
const char * file ;
2005-03-27 12:48:25 +00:00
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2005-05-02 17:05:59 +00:00
IConsoleHelp ( " Load a game by name or index. Usage: 'load <file \\ number>' " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-01-04 15:06:08 +00:00
}
2005-05-02 15:52:19 +00:00
if ( argc ! = 2 ) return false ;
2005-03-27 12:48:25 +00:00
file = argv [ 1 ] ;
item = GetFiosItem ( file ) ;
if ( item ! = NULL ) {
switch ( item - > type ) {
2005-07-17 15:58:47 +00:00
case FIOS_TYPE_FILE : case FIOS_TYPE_OLDFILE : {
2005-03-27 12:48:25 +00:00
_switch_mode = SM_LOAD ;
SetFiosType ( item - > type ) ;
2005-07-17 15:58:47 +00:00
ttd_strlcpy ( _file_to_saveload . name , FiosBrowseTo ( item ) , sizeof ( _file_to_saveload . name ) ) ;
ttd_strlcpy ( _file_to_saveload . title , item - > title , sizeof ( _file_to_saveload . title ) ) ;
} break ;
2005-05-14 19:34:59 +00:00
default : IConsolePrintF ( _icolour_err , " %s: Not a savegame. " , file ) ;
2005-03-27 12:48:25 +00:00
}
2005-05-02 15:52:19 +00:00
} else
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_err , " %s: No such file or directory. " , file ) ;
2005-01-04 15:06:08 +00:00
FiosFreeSavegameList ( ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-01-04 15:06:08 +00:00
}
2005-09-11 14:57:56 +00:00
DEF_CONSOLE_CMD ( ConRemove )
{
const FiosItem * item ;
const char * file ;
if ( argc = = 0 ) {
IConsoleHelp ( " Remove a savegame by name or index. Usage: 'rm <file | number>' " ) ;
return true ;
}
if ( argc ! = 2 ) return false ;
file = argv [ 1 ] ;
item = GetFiosItem ( file ) ;
if ( item ! = NULL ) {
if ( ! FiosDelete ( item - > name ) )
IConsolePrintF ( _icolour_err , " %s: Failed to delete file " , file ) ;
} else
IConsolePrintF ( _icolour_err , " %s: No such file or directory. " , file ) ;
FiosFreeSavegameList ( ) ;
return true ;
}
2005-03-27 12:48:25 +00:00
/* List all the files in the current dir via console */
DEF_CONSOLE_CMD ( ConListFiles )
{
int i ;
2005-01-08 00:48:10 +00:00
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2005-05-02 21:56:01 +00:00
IConsoleHelp ( " List all loadable savegames and directories in the current dir via console. Usage: 'ls \\ dir' " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2005-01-08 00:48:10 +00:00
BuildFileList ( ) ;
2005-03-27 12:48:25 +00:00
for ( i = 0 ; i < _fios_num ; i + + ) {
2005-05-02 15:52:19 +00:00
const FiosItem * item = & _fios_list [ i ] ;
2005-07-17 15:58:47 +00:00
IConsolePrintF ( _icolour_def , " %d) %s " , i , item - > title ) ;
2005-01-08 00:48:10 +00:00
}
FiosFreeSavegameList ( ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-01-08 00:48:10 +00:00
}
2005-01-04 15:06:08 +00:00
/* Change the dir via console */
2005-03-27 12:48:25 +00:00
DEF_CONSOLE_CMD ( ConChangeDirectory )
2005-01-04 15:06:08 +00:00
{
2005-05-02 15:52:19 +00:00
const FiosItem * item ;
const char * file ;
2005-01-04 15:06:08 +00:00
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2005-05-02 17:05:59 +00:00
IConsoleHelp ( " Change the dir via console. Usage: 'cd <directory \\ number>' " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-01-04 15:06:08 +00:00
}
2005-05-02 15:52:19 +00:00
if ( argc ! = 2 ) return false ;
2005-03-27 12:48:25 +00:00
file = argv [ 1 ] ;
item = GetFiosItem ( file ) ;
if ( item ! = NULL ) {
switch ( item - > type ) {
2005-05-02 15:52:19 +00:00
case FIOS_TYPE_DIR : case FIOS_TYPE_DRIVE : case FIOS_TYPE_PARENT :
2005-03-27 12:48:25 +00:00
FiosBrowseTo ( item ) ;
break ;
2005-05-14 19:34:59 +00:00
default : IConsolePrintF ( _icolour_err , " %s: Not a directory. " , file ) ;
2005-01-04 15:06:08 +00:00
}
2005-05-02 15:52:19 +00:00
} else
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_err , " %s: No such file or directory. " , file ) ;
2005-01-04 15:06:08 +00:00
2005-03-27 12:48:25 +00:00
FiosFreeSavegameList ( ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-03-27 12:48:25 +00:00
}
DEF_CONSOLE_CMD ( ConPrintWorkingDirectory )
{
2005-05-02 15:52:19 +00:00
const char * path ;
if ( argc = = 0 ) {
IConsoleHelp ( " Print out the current working directory. Usage: 'pwd' " ) ;
return true ;
}
2005-03-27 12:48:25 +00:00
2005-05-02 15:52:19 +00:00
// XXX - Workaround for broken file handling
2005-03-27 12:48:25 +00:00
FiosGetSavegameList ( & _fios_num , SLD_LOAD_GAME ) ;
2005-01-04 15:06:08 +00:00
FiosFreeSavegameList ( ) ;
2005-03-28 13:30:51 +00:00
FiosGetDescText ( & path , NULL ) ;
2005-05-14 19:34:59 +00:00
IConsolePrint ( _icolour_def , path ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-01-04 15:06:08 +00:00
}
2005-05-16 13:46:26 +00:00
DEF_CONSOLE_CMD ( ConClearBuffer )
{
if ( argc = = 0 ) {
IConsoleHelp ( " Clear the console buffer. Usage: 'clear' " ) ;
return true ;
}
IConsoleClearBuffer ( ) ;
InvalidateWindow ( WC_CONSOLE , 0 ) ;
return true ;
}
2004-12-04 17:54:56 +00:00
2004-09-12 21:49:38 +00:00
// ********************************* //
// * Network Core Console Commands * //
// ********************************* //
# ifdef ENABLE_NETWORK
2005-01-02 12:03:43 +00:00
DEF_CONSOLE_CMD ( ConBan )
{
NetworkClientInfo * ci ;
2005-05-02 15:52:19 +00:00
uint32 index ;
2005-01-02 12:03:43 +00:00
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Ban a player from a network game. Usage: 'ban <client-id>' " ) ;
IConsoleHelp ( " For client-id's, see the command 'clients' " ) ;
return true ;
}
2005-01-02 12:03:43 +00:00
2005-05-02 15:52:19 +00:00
if ( argc ! = 2 ) return false ;
2005-01-02 12:03:43 +00:00
2005-05-02 15:52:19 +00:00
index = atoi ( argv [ 1 ] ) ;
2005-01-02 12:03:43 +00:00
2005-05-02 15:52:19 +00:00
if ( index = = NETWORK_SERVER_INDEX ) {
2005-05-14 19:34:59 +00:00
IConsolePrint ( _icolour_def , " Silly boy, you can not ban yourself! " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
if ( index = = 0 ) {
IConsoleError ( " Invalid Client-ID " ) ;
return true ;
2005-01-02 12:03:43 +00:00
}
2005-05-02 15:52:19 +00:00
ci = NetworkFindClientInfoFromIndex ( index ) ;
2005-01-02 12:03:43 +00:00
2005-05-02 15:52:19 +00:00
if ( ci ! = NULL ) {
2005-01-02 12:03:43 +00:00
uint i ;
2005-05-02 15:52:19 +00:00
/* Add user to ban-list */
2005-01-02 12:03:43 +00:00
for ( i = 0 ; i < lengthof ( _network_ban_list ) ; i + + ) {
2005-05-02 15:52:19 +00:00
if ( _network_ban_list [ i ] = = NULL | | _network_ban_list [ i ] [ 0 ] = = ' \0 ' ) {
_network_ban_list [ i ] = strdup ( inet_ntoa ( * ( struct in_addr * ) & ci - > client_ip ) ) ;
break ;
2005-01-02 12:03:43 +00:00
}
}
2005-05-02 15:52:19 +00:00
SEND_COMMAND ( PACKET_SERVER_ERROR ) ( NetworkFindClientStateFromIndex ( index ) , NETWORK_ERROR_KICKED ) ;
} else
IConsoleError ( " Client-ID not found " ) ;
2005-01-02 12:03:43 +00:00
2005-05-02 15:52:19 +00:00
return true ;
}
DEF_CONSOLE_CMD ( ConUnBan )
{
uint i ;
if ( argc = = 0 ) {
IConsoleHelp ( " Unban a player from a network game. Usage: 'unban <ip>' " ) ;
return true ;
2005-01-02 12:03:43 +00:00
}
2005-05-02 15:52:19 +00:00
if ( argc ! = 2 ) return false ;
for ( i = 0 ; i < lengthof ( _network_ban_list ) ; i + + ) {
if ( _network_ban_list [ i ] = = NULL | | _network_ban_list [ i ] [ 0 ] = = ' \0 ' )
continue ;
if ( strncmp ( _network_ban_list [ i ] , argv [ 1 ] , strlen ( _network_ban_list [ i ] ) ) = = 0 ) {
_network_ban_list [ i ] [ 0 ] = ' \0 ' ;
2005-05-14 19:34:59 +00:00
IConsolePrint ( _icolour_def , " IP unbanned. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
}
2005-01-02 12:03:43 +00:00
2005-05-14 19:34:59 +00:00
IConsolePrint ( _icolour_def , " IP not in ban-list. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-01-02 12:03:43 +00:00
}
DEF_CONSOLE_CMD ( ConBanList )
{
uint i ;
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " List the IP's of banned clients: Usage 'banlist' " ) ;
return true ;
}
2005-05-14 19:34:59 +00:00
IConsolePrint ( _icolour_def , " Banlist: " ) ;
2005-01-02 12:03:43 +00:00
for ( i = 0 ; i < lengthof ( _network_ban_list ) ; i + + ) {
if ( _network_ban_list [ i ] = = NULL | | _network_ban_list [ i ] [ 0 ] = = ' \0 ' )
continue ;
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_def , " %d) %s " , i + 1 , _network_ban_list [ i ] ) ;
2005-01-02 12:03:43 +00:00
}
2005-05-02 15:52:19 +00:00
return true ;
2005-01-02 12:03:43 +00:00
}
2005-01-24 21:33:44 +00:00
DEF_CONSOLE_CMD ( ConPauseGame )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Pause a network game. Usage: 'pause' " ) ;
return true ;
}
2005-01-24 21:33:44 +00:00
if ( _pause = = 0 ) {
DoCommandP ( 0 , 1 , 0 , NULL , CMD_PAUSE ) ;
2005-05-14 19:34:59 +00:00
IConsolePrint ( _icolour_def , " Game paused. " ) ;
2005-01-24 21:33:44 +00:00
} else
2005-05-14 19:34:59 +00:00
IConsolePrint ( _icolour_def , " Game is already paused. " ) ;
2005-01-24 21:33:44 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2005-01-24 21:33:44 +00:00
}
DEF_CONSOLE_CMD ( ConUnPauseGame )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Unpause a network game. Usage: 'unpause' " ) ;
return true ;
}
2005-01-24 21:33:44 +00:00
if ( _pause ! = 0 ) {
DoCommandP ( 0 , 0 , 0 , NULL , CMD_PAUSE ) ;
2005-05-14 19:34:59 +00:00
IConsolePrint ( _icolour_def , " Game unpaused. " ) ;
2005-01-24 21:33:44 +00:00
} else
2005-05-14 19:34:59 +00:00
IConsolePrint ( _icolour_def , " Game is already unpaused. " ) ;
2005-01-24 21:33:44 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2005-01-24 21:33:44 +00:00
}
2005-01-15 20:09:16 +00:00
DEF_CONSOLE_CMD ( ConRcon )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Remote control the server from another client. Usage: 'rcon <password> <command>' " ) ;
IConsoleHelp ( " Remember to enclose the command in quotes, otherwise only the first parameter is sent " ) ;
return true ;
2005-01-15 20:09:16 +00:00
}
2005-05-02 15:52:19 +00:00
if ( argc < 3 ) return false ;
2005-01-15 20:09:16 +00:00
2005-05-02 15:52:19 +00:00
SEND_COMMAND ( PACKET_CLIENT_RCON ) ( argv [ 1 ] , argv [ 2 ] ) ;
return true ;
2005-01-15 20:09:16 +00:00
}
2004-12-04 17:54:56 +00:00
DEF_CONSOLE_CMD ( ConStatus )
{
2005-05-02 15:52:19 +00:00
static const char * stat_str [ ] = { " inactive " , " authorized " , " waiting " , " loading map " , " map done " , " ready " , " active " } ;
2004-12-04 17:54:56 +00:00
const char * status ;
2004-12-19 10:17:26 +00:00
const NetworkClientState * cs ;
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " List the status of all clients connected to the server: Usage 'status' " ) ;
return true ;
}
2004-12-04 17:54:56 +00:00
FOR_ALL_CLIENTS ( cs ) {
2005-05-02 15:52:19 +00:00
int lag = NetworkCalculateLag ( cs ) ;
const NetworkClientInfo * ci = DEREF_CLIENT_INFO ( cs ) ;
2004-12-04 17:54:56 +00:00
2005-05-02 15:52:19 +00:00
status = ( cs - > status < = STATUS_ACTIVE ) ? stat_str [ cs - > status ] : " unknown " ;
2004-12-12 16:04:32 +00:00
IConsolePrintF ( 8 , " Client #%d/%s status: %s frame-lag: %d play-as: %d unique-id: %s " ,
cs - > index , ci - > client_name , status , lag , ci - > client_playas , ci - > unique_id ) ;
2004-12-04 17:54:56 +00:00
}
2005-05-02 15:52:19 +00:00
return true ;
2004-12-04 17:54:56 +00:00
}
DEF_CONSOLE_CMD ( ConKick )
{
NetworkClientInfo * ci ;
2005-05-02 15:52:19 +00:00
uint32 index ;
2004-12-04 17:54:56 +00:00
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Kick a player from a network game. Usage: 'kick <client-id>' " ) ;
IConsoleHelp ( " For client-id's, see the command 'clients' " ) ;
return true ;
}
2004-12-04 17:54:56 +00:00
2005-05-02 15:52:19 +00:00
if ( argc ! = 2 ) return false ;
2004-12-04 17:54:56 +00:00
2005-05-02 15:52:19 +00:00
index = atoi ( argv [ 1 ] ) ;
if ( index = = NETWORK_SERVER_INDEX ) {
2005-05-14 19:34:59 +00:00
IConsolePrint ( _icolour_def , " Silly boy, you can not kick yourself! " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-12-04 17:54:56 +00:00
}
2005-05-02 15:52:19 +00:00
if ( index = = 0 ) {
2005-05-04 10:17:00 +00:00
IConsoleError ( " Invalid client-id " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
ci = NetworkFindClientInfoFromIndex ( index ) ;
2004-12-04 17:54:56 +00:00
2005-05-02 15:52:19 +00:00
if ( ci ! = NULL ) {
SEND_COMMAND ( PACKET_SERVER_ERROR ) ( NetworkFindClientStateFromIndex ( index ) , NETWORK_ERROR_KICKED ) ;
} else
2005-05-04 10:17:00 +00:00
IConsoleError ( " Client-id not found " ) ;
2004-12-04 17:54:56 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2004-12-04 17:54:56 +00:00
}
2004-12-16 11:36:57 +00:00
DEF_CONSOLE_CMD ( ConResetCompany )
{
Player * p ;
2004-12-19 10:17:26 +00:00
NetworkClientState * cs ;
2004-12-16 11:36:57 +00:00
NetworkClientInfo * ci ;
2005-05-02 15:52:19 +00:00
byte index ;
2004-12-16 11:36:57 +00:00
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2005-05-04 10:17:00 +00:00
IConsoleHelp ( " Remove an idle company from the game. Usage: 'reset_company <company-id>' " ) ;
IConsoleHelp ( " For company-id's, see the list of companies from the dropdown menu. Player 1 is 1, etc. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2004-12-16 11:36:57 +00:00
2005-05-02 15:52:19 +00:00
if ( argc ! = 2 ) return false ;
2004-12-16 11:36:57 +00:00
2005-05-02 15:52:19 +00:00
index = atoi ( argv [ 1 ] ) ;
2004-12-16 11:36:57 +00:00
2005-05-02 15:52:19 +00:00
/* Check valid range */
if ( index < 1 | | index > MAX_PLAYERS ) {
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_err , " Company does not exist. Company-id must be between 1 and %d. " , MAX_PLAYERS ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2004-12-16 11:36:57 +00:00
2005-05-02 15:52:19 +00:00
/* Check if company does exist */
index - - ;
2005-06-21 16:28:17 +00:00
p = GetPlayer ( index ) ;
2005-05-02 15:52:19 +00:00
if ( ! p - > is_active ) {
2005-05-04 10:17:00 +00:00
IConsoleError ( " Company does not exist. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
if ( p - > is_ai ) {
2005-05-04 10:17:00 +00:00
IConsoleError ( " Company is owned by an AI. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
/* Check if the company has active players */
FOR_ALL_CLIENTS ( cs ) {
ci = DEREF_CLIENT_INFO ( cs ) ;
2005-05-04 10:17:00 +00:00
if ( ci - > client_playas - 1 = = index ) {
IConsoleError ( " Cannot remove company: a client is connected to that company. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-12-16 11:36:57 +00:00
}
2005-05-02 15:52:19 +00:00
}
ci = NetworkFindClientInfoFromIndex ( NETWORK_SERVER_INDEX ) ;
if ( ci - > client_playas - 1 = = index ) {
2005-05-04 10:17:00 +00:00
IConsoleError ( " Cannot remove company: the server is connected to that company. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-12-16 11:36:57 +00:00
}
2005-05-02 15:52:19 +00:00
/* It is safe to remove this company */
DoCommandP ( 0 , 2 , index , NULL , CMD_PLAYER_CTRL ) ;
2005-05-14 19:34:59 +00:00
IConsolePrint ( _icolour_def , " Company deleted. " ) ;
2004-12-16 11:36:57 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2004-12-16 11:36:57 +00:00
}
2004-12-04 17:54:56 +00:00
DEF_CONSOLE_CMD ( ConNetworkClients )
{
NetworkClientInfo * ci ;
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Get a list of connected clients including their ID, name, and company-id. Usage: 'clients' " ) ;
return true ;
}
2004-12-04 17:54:56 +00:00
for ( ci = _network_client_info ; ci ! = & _network_client_info [ MAX_CLIENT_INFO ] ; ci + + ) {
if ( ci - > client_index ! = NETWORK_EMPTY_INDEX ) {
2005-05-04 10:17:00 +00:00
IConsolePrintF ( 8 , " Client #%d name: %s play-as company: %d " , ci - > client_index , ci - > client_name , ci - > client_playas ) ;
2004-12-04 17:54:56 +00:00
}
}
2005-05-02 15:52:19 +00:00
return true ;
2004-12-04 17:54:56 +00:00
}
2004-09-12 21:49:38 +00:00
DEF_CONSOLE_CMD ( ConNetworkConnect )
{
2005-05-02 15:52:19 +00:00
char * ip ;
2005-02-06 22:25:27 +00:00
const char * port = NULL ;
const char * player = NULL ;
2004-09-12 21:49:38 +00:00
uint16 rport ;
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Connect to a remote OTTD server and join the game. Usage: 'connect <ip>' " ) ;
IConsoleHelp ( " IP can contain port and player: 'IP#Player:Port', eg: 'server.ottd.org#2:443' " ) ;
return true ;
}
2004-09-12 21:49:38 +00:00
2005-05-02 15:52:19 +00:00
if ( argc < 2 ) return false ;
if ( _networking ) // We are in network-mode, first close it!
2004-12-04 17:54:56 +00:00
NetworkDisconnect ( ) ;
2004-09-12 23:35:01 +00:00
ip = argv [ 1 ] ;
2004-12-04 17:54:56 +00:00
rport = NETWORK_DEFAULT_PORT ;
2004-09-12 21:49:38 +00:00
2004-09-12 23:35:01 +00:00
ParseConnectionString ( & player , & port , ip ) ;
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_def , " Connecting to %s... " , ip ) ;
2004-12-04 17:54:56 +00:00
if ( player ! = NULL ) {
2004-09-12 21:49:38 +00:00
_network_playas = atoi ( player ) ;
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_def , " player-no: %s " , player ) ;
2004-09-12 21:49:38 +00:00
}
2004-12-04 17:54:56 +00:00
if ( port ! = NULL ) {
2004-09-12 21:49:38 +00:00
rport = atoi ( port ) ;
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_def , " port: %s " , port ) ;
2004-09-12 21:49:38 +00:00
}
2004-12-04 17:54:56 +00:00
NetworkClientConnectGame ( ip , rport ) ;
2004-09-12 21:49:38 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
2004-12-04 17:54:56 +00:00
# endif /* ENABLE_NETWORK */
2004-09-12 21:49:38 +00:00
2004-09-14 16:10:20 +00:00
/* ******************************** */
/* script file console commands */
/* ******************************** */
DEF_CONSOLE_CMD ( ConExec )
{
2005-05-02 15:52:19 +00:00
char cmdline [ ICON_CMDLN_SIZE ] ;
2005-05-02 17:05:59 +00:00
char * cmdptr ;
2004-09-14 16:10:20 +00:00
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Execute a local script file. Usage: 'exec <script> <?>' " ) ;
return true ;
}
if ( argc < 2 ) return false ;
2004-09-14 16:10:20 +00:00
2004-12-04 17:54:56 +00:00
_script_file = fopen ( argv [ 1 ] , " r " ) ;
2004-09-14 16:10:20 +00:00
if ( _script_file = = NULL ) {
2005-05-02 15:52:19 +00:00
if ( argc = = 2 | | atoi ( argv [ 2 ] ) ! = 0 ) IConsoleError ( " script file not found " ) ;
return true ;
2005-02-18 08:49:04 +00:00
}
2004-09-14 16:10:20 +00:00
_script_running = true ;
2005-05-02 17:05:59 +00:00
while ( _script_running & & fgets ( cmdline , sizeof ( cmdline ) , _script_file ) ! = NULL ) {
/* Remove newline characters from the executing script */
2005-05-15 18:43:36 +00:00
for ( cmdptr = cmdline ; * cmdptr ! = ' \0 ' ; cmdptr + + ) {
2005-05-02 17:05:59 +00:00
if ( * cmdptr = = ' \n ' | | * cmdptr = = ' \r ' ) {
* cmdptr = ' \0 ' ;
break ;
}
}
2005-05-02 15:52:19 +00:00
IConsoleCmdExec ( cmdline ) ;
2005-05-02 17:05:59 +00:00
}
2005-02-18 08:36:11 +00:00
2005-05-02 15:52:19 +00:00
if ( ferror ( _script_file ) )
2005-02-18 08:36:11 +00:00
IConsoleError ( " Encountered errror while trying to read from script file " ) ;
2004-09-14 16:10:20 +00:00
_script_running = false ;
fclose ( _script_file ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-14 16:10:20 +00:00
}
DEF_CONSOLE_CMD ( ConReturn )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Stop executing a running script. Usage: 'return' " ) ;
return true ;
}
2004-09-14 16:10:20 +00:00
_script_running = false ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-14 16:10:20 +00:00
}
2004-09-12 21:49:38 +00:00
/* **************************** */
/* default console commands */
/* **************************** */
2005-01-16 18:19:33 +00:00
extern bool CloseConsoleLogIfActive ( void ) ;
2005-01-15 16:38:10 +00:00
DEF_CONSOLE_CMD ( ConScript )
{
extern FILE * _iconsole_output_file ;
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Start or stop logging console output to a file. Usage: 'script <filename>' " ) ;
IConsoleHelp ( " If filename is omitted, a running log is stopped if it is active " ) ;
return true ;
}
2005-01-15 16:38:10 +00:00
if ( ! CloseConsoleLogIfActive ( ) ) {
2005-05-02 15:52:19 +00:00
if ( argc < 2 ) return false ;
2005-07-08 22:25:24 +00:00
IConsolePrintF ( _icolour_def , " file output started to: %s " , argv [ 1 ] ) ;
2004-09-19 15:24:45 +00:00
_iconsole_output_file = fopen ( argv [ 1 ] , " ab " ) ;
2004-09-14 16:10:20 +00:00
if ( _iconsole_output_file = = NULL ) IConsoleError ( " could not open file " ) ;
}
2005-01-15 16:38:10 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2004-09-14 16:10:20 +00:00
}
2004-09-12 21:49:38 +00:00
DEF_CONSOLE_CMD ( ConEcho )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Print back the first argument to the console. Usage: 'echo <arg>' " ) ;
return true ;
}
if ( argc < 2 ) return false ;
2005-05-14 19:34:59 +00:00
IConsolePrint ( _icolour_def , argv [ 1 ] ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
DEF_CONSOLE_CMD ( ConEchoC )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Print back the first argument to the console in a given colour. Usage: 'echoc <colour> <arg2>' " ) ;
return true ;
}
if ( argc < 3 ) return false ;
2004-09-12 21:49:38 +00:00
IConsolePrint ( atoi ( argv [ 1 ] ) , argv [ 2 ] ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
2004-12-04 17:54:56 +00:00
extern void SwitchMode ( int new_mode ) ;
DEF_CONSOLE_CMD ( ConNewGame )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Start a new game. Usage: 'newgame' " ) ;
2005-05-12 00:18:30 +00:00
IConsoleHelp ( " The server can force a new game using 'newgame', any client using it will part and start a single-player game " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2005-05-12 00:18:30 +00:00
GenRandomNewGame ( Random ( ) , InteractiveRandom ( ) ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
2004-12-13 18:51:08 +00:00
DEF_CONSOLE_CMD ( ConAlias )
{
2005-05-02 15:52:19 +00:00
IConsoleAlias * alias ;
2004-12-13 22:13:02 +00:00
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Add a new alias, or redefine the behaviour of an existing alias . Usage: 'alias <name> <command>' " ) ;
return true ;
}
if ( argc < 3 ) return false ;
2004-12-13 22:13:02 +00:00
alias = IConsoleAliasGet ( argv [ 1 ] ) ;
if ( alias = = NULL ) {
2005-05-02 15:52:19 +00:00
IConsoleAliasRegister ( argv [ 1 ] , argv [ 2 ] ) ;
2004-12-13 22:13:02 +00:00
} else {
free ( alias - > cmdline ) ;
alias - > cmdline = strdup ( argv [ 2 ] ) ;
}
2005-05-02 15:52:19 +00:00
return true ;
2004-12-13 18:51:08 +00:00
}
2004-09-12 21:49:38 +00:00
DEF_CONSOLE_CMD ( ConScreenShot )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2005-05-02 17:05:59 +00:00
IConsoleHelp ( " Create a screenshot of the game. Usage: 'screenshot [big \\ no_con]' " ) ;
2005-05-02 15:52:19 +00:00
IConsoleHelp ( " 'big' makes a screenshot of the whole map, 'no_con' hides the console to create the screenshot " ) ;
return true ;
}
2004-09-19 15:24:45 +00:00
if ( argc < 2 ) {
_make_screenshot = 1 ;
2004-09-12 21:49:38 +00:00
} else {
2004-09-19 15:24:45 +00:00
if ( strcmp ( argv [ 1 ] , " big " ) = = 0 )
2005-05-02 15:52:19 +00:00
_make_screenshot = 2 ;
2004-09-19 15:24:45 +00:00
if ( strcmp ( argv [ 1 ] , " no_con " ) = = 0 ) {
2004-09-12 21:49:38 +00:00
IConsoleClose ( ) ;
2004-09-19 15:24:45 +00:00
_make_screenshot = 1 ;
2004-09-12 21:49:38 +00:00
}
2004-09-19 15:24:45 +00:00
}
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
2004-09-13 06:56:30 +00:00
DEF_CONSOLE_CMD ( ConInfoVar )
2004-09-12 21:49:38 +00:00
{
2005-05-02 15:52:19 +00:00
static const char * _icon_vartypes [ ] = { " boolean " , " byte " , " uint16 " , " uint32 " , " int16 " , " int32 " , " string " } ;
const IConsoleVar * var ;
if ( argc = = 0 ) {
IConsoleHelp ( " Print out debugging information about a variable. Usage: 'info_var <var>' " ) ;
return true ;
}
if ( argc < 2 ) return false ;
var = IConsoleVarGet ( argv [ 1 ] ) ;
if ( var = = NULL ) {
IConsoleError ( " the given variable was not found " ) ;
return true ;
}
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_def , " variable name: %s " , var - > name ) ;
IConsolePrintF ( _icolour_def , " variable type: %s " , _icon_vartypes [ var - > type ] ) ;
IConsolePrintF ( _icolour_def , " variable addr: 0x%X " , var - > addr ) ;
2005-05-02 15:52:19 +00:00
if ( var - > hook . access ) IConsoleWarning ( " variable is access hooked " ) ;
if ( var - > hook . pre ) IConsoleWarning ( " variable is pre hooked " ) ;
if ( var - > hook . post ) IConsoleWarning ( " variable is post hooked " ) ;
return true ;
2004-09-14 16:10:20 +00:00
}
DEF_CONSOLE_CMD ( ConInfoCmd )
{
2005-05-02 15:52:19 +00:00
const IConsoleCmd * cmd ;
if ( argc = = 0 ) {
IConsoleHelp ( " Print out debugging information about a command. Usage: 'info_cmd <cmd>' " ) ;
return true ;
}
if ( argc < 2 ) return false ;
cmd = IConsoleCmdGet ( argv [ 1 ] ) ;
if ( cmd = = NULL ) {
IConsoleError ( " the given command was not found " ) ;
return true ;
2004-09-19 15:24:45 +00:00
}
2005-05-02 15:52:19 +00:00
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_def , " command name: %s " , cmd - > name ) ;
IConsolePrintF ( _icolour_def , " command proc: 0x%X " , cmd - > proc ) ;
2005-05-02 15:52:19 +00:00
if ( cmd - > hook . access ) IConsoleWarning ( " command is access hooked " ) ;
if ( cmd - > hook . pre ) IConsoleWarning ( " command is pre hooked " ) ;
if ( cmd - > hook . post ) IConsoleWarning ( " command is post hooked " ) ;
return true ;
2004-09-12 21:49:38 +00:00
}
DEF_CONSOLE_CMD ( ConDebugLevel )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2005-05-20 17:59:24 +00:00
IConsoleHelp ( " Get/set the default debugging level for the game. Usage: 'debug_level [<level>]' " ) ;
2005-05-02 15:52:19 +00:00
IConsoleHelp ( " Level can be any combination of names, levels. Eg 'net=5 ms=4'. Remember to enclose it in \" 's " ) ;
return true ;
}
2005-05-20 17:59:24 +00:00
if ( argc > 2 ) return false ;
if ( argc = = 1 ) {
IConsolePrintF ( _icolour_def , " Current debug-level: '%s' " , GetDebugString ( ) ) ;
} else SetDebugString ( argv [ 1 ] ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
DEF_CONSOLE_CMD ( ConExit )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Exit the game. Usage: 'exit' " ) ;
return true ;
}
2004-09-12 21:49:38 +00:00
_exit_game = true ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
2005-05-15 10:40:53 +00:00
DEF_CONSOLE_CMD ( ConPart )
{
if ( argc = = 0 ) {
IConsoleHelp ( " Leave the currently joined/running game (only ingame). Usage: 'part' " ) ;
return true ;
}
if ( _game_mode ! = GM_NORMAL ) return false ;
_switch_mode = SM_MENU ;
return true ;
}
2004-09-12 21:49:38 +00:00
DEF_CONSOLE_CMD ( ConHelp )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 2 ) {
2005-05-02 17:05:59 +00:00
const IConsoleCmd * cmd ;
const IConsoleVar * var ;
const IConsoleAlias * alias ;
2005-05-02 15:52:19 +00:00
cmd = IConsoleCmdGet ( argv [ 1 ] ) ;
2005-07-08 22:25:24 +00:00
if ( cmd ! = NULL ) {
cmd - > proc ( 0 , NULL ) ;
return true ;
}
alias = IConsoleAliasGet ( argv [ 1 ] ) ;
if ( alias ! = NULL ) {
cmd = IConsoleCmdGet ( alias - > cmdline ) ;
if ( cmd ! = NULL ) {
cmd - > proc ( 0 , NULL ) ;
return true ;
}
IConsolePrintF ( _icolour_err , " ERROR: alias is of special type, please see its execution-line: '%s' " , alias - > cmdline ) ;
return true ;
}
var = IConsoleVarGet ( argv [ 1 ] ) ;
if ( var ! = NULL & & var - > help ! = NULL ) {
IConsoleHelp ( var - > help ) ;
return true ;
}
IConsoleError ( " command or variable not found " ) ;
return true ;
}
2005-05-02 15:52:19 +00:00
2005-05-04 10:17:00 +00:00
IConsolePrint ( 13 , " ---- OpenTTD Console Help ---- " ) ;
IConsolePrint ( 1 , " - variables: [command to list all variables: list_vars] " ) ;
2005-05-02 15:52:19 +00:00
IConsolePrint ( 1 , " set value with '<var> = <value>', use '++/--' to in-or decrement " ) ;
IConsolePrint ( 1 , " or omit '=' and just '<var> <value>'. get value with typing '<var>' " ) ;
2005-05-04 10:17:00 +00:00
IConsolePrint ( 1 , " - commands: [command to list all commands: list_cmds] " ) ;
2005-05-02 15:52:19 +00:00
IConsolePrint ( 1 , " call commands with '<command> <arg2> <arg3>...' " ) ;
2005-05-04 10:17:00 +00:00
IConsolePrint ( 1 , " - to assign strings, or use them as arguments, enclose it within quotes " ) ;
2005-05-02 15:52:19 +00:00
IConsolePrint ( 1 , " like this: '<command> \" string argument with spaces \" ' " ) ;
2005-05-04 10:17:00 +00:00
IConsolePrint ( 1 , " - use 'help <command> \\ <variable>' to get specific information " ) ;
IConsolePrint ( 1 , " - scroll console output with shift + (up \\ down) \\ (pageup \\ pagedown)) " ) ;
IConsolePrint ( 1 , " - scroll console input history with the up \\ down arrows " ) ;
2004-09-19 15:24:45 +00:00
IConsolePrint ( 1 , " " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
DEF_CONSOLE_CMD ( ConListCommands )
{
2005-05-02 15:52:19 +00:00
const IConsoleCmd * cmd ;
2004-09-19 15:24:45 +00:00
size_t l = 0 ;
2004-09-12 21:49:38 +00:00
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " List all registered commands. Usage: 'list_cmds [<pre-filter>]' " ) ;
return true ;
}
2004-09-19 15:24:45 +00:00
if ( argv [ 1 ] ! = NULL ) l = strlen ( argv [ 1 ] ) ;
2004-09-12 21:49:38 +00:00
2005-05-02 15:52:19 +00:00
for ( cmd = _iconsole_cmds ; cmd ! = NULL ; cmd = cmd - > next ) {
if ( argv [ 1 ] = = NULL | | strncmp ( cmd - > name , argv [ 1 ] , l ) = = 0 ) {
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_def , " %s " , cmd - > name ) ;
2005-05-02 15:52:19 +00:00
}
}
2004-09-12 21:49:38 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
DEF_CONSOLE_CMD ( ConListVariables )
{
2005-05-02 15:52:19 +00:00
const IConsoleVar * var ;
2004-09-19 15:24:45 +00:00
size_t l = 0 ;
2004-09-12 21:49:38 +00:00
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " List all registered variables. Usage: 'list_vars [<pre-filter>]' " ) ;
return true ;
}
2004-09-19 15:24:45 +00:00
if ( argv [ 1 ] ! = NULL ) l = strlen ( argv [ 1 ] ) ;
2004-09-12 21:49:38 +00:00
2005-05-02 15:52:19 +00:00
for ( var = _iconsole_vars ; var ! = NULL ; var = var - > next ) {
if ( argv [ 1 ] = = NULL | | strncmp ( var - > name , argv [ 1 ] , l ) = = 0 )
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_def , " %s " , var - > name ) ;
2005-05-02 15:52:19 +00:00
}
2004-09-12 21:49:38 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
2004-12-13 18:51:08 +00:00
DEF_CONSOLE_CMD ( ConListAliases )
{
2005-05-02 15:52:19 +00:00
const IConsoleAlias * alias ;
2004-12-13 18:51:08 +00:00
size_t l = 0 ;
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " List all registered aliases. Usage: 'list_aliases [<pre-filter>]' " ) ;
return true ;
}
2004-09-12 21:49:38 +00:00
2004-09-19 15:24:45 +00:00
if ( argv [ 1 ] ! = NULL ) l = strlen ( argv [ 1 ] ) ;
2004-09-12 21:49:38 +00:00
2005-05-02 15:52:19 +00:00
for ( alias = _iconsole_aliases ; alias ! = NULL ; alias = alias - > next ) {
if ( argv [ 1 ] = = NULL | | strncmp ( alias - > name , argv [ 1 ] , l ) = = 0 )
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_def , " %s => %s " , alias - > name , alias - > cmdline ) ;
2005-05-02 15:52:19 +00:00
}
2004-09-12 21:49:38 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
2004-12-04 17:54:56 +00:00
# ifdef ENABLE_NETWORK
DEF_CONSOLE_CMD ( ConSay )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Chat to your fellow players in a multiplayer game. Usage: 'say \" <msg> \" ' " ) ;
return true ;
}
if ( argc ! = 2 ) return false ;
if ( ! _network_server ) {
SEND_COMMAND ( PACKET_CLIENT_CHAT ) ( NETWORK_ACTION_CHAT , DESTTYPE_BROADCAST , 0 /* param does not matter */ , argv [ 1 ] ) ;
2004-12-04 17:54:56 +00:00
} else
2005-05-02 15:52:19 +00:00
NetworkServer_HandleChat ( NETWORK_ACTION_CHAT , DESTTYPE_BROADCAST , 0 , argv [ 1 ] , NETWORK_SERVER_INDEX ) ;
return true ;
2004-12-04 17:54:56 +00:00
}
DEF_CONSOLE_CMD ( ConSayPlayer )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Chat to a certain player in a multiplayer game. Usage: 'say_player <player-no> \" <msg> \" ' " ) ;
IConsoleHelp ( " PlayerNo is the player that plays as company <playerno>, 1 through max_players " ) ;
return true ;
}
if ( argc ! = 3 ) return false ;
2004-12-04 17:54:56 +00:00
2005-05-02 15:52:19 +00:00
if ( atoi ( argv [ 1 ] ) < 1 | | atoi ( argv [ 1 ] ) > MAX_PLAYERS ) {
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_def , " Unknown player. Player range is between 1 and %d. " , MAX_PLAYERS ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
if ( ! _network_server ) {
SEND_COMMAND ( PACKET_CLIENT_CHAT ) ( NETWORK_ACTION_CHAT_PLAYER , DESTTYPE_PLAYER , atoi ( argv [ 1 ] ) , argv [ 2 ] ) ;
2004-12-04 17:54:56 +00:00
} else
2005-05-02 15:52:19 +00:00
NetworkServer_HandleChat ( NETWORK_ACTION_CHAT_PLAYER , DESTTYPE_PLAYER , atoi ( argv [ 1 ] ) , argv [ 2 ] , NETWORK_SERVER_INDEX ) ;
return true ;
2004-12-04 17:54:56 +00:00
}
DEF_CONSOLE_CMD ( ConSayClient )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
IConsoleHelp ( " Chat to a certain player in a multiplayer game. Usage: 'say_client <client-no> \" <msg> \" ' " ) ;
2005-07-08 22:25:24 +00:00
IConsoleHelp ( " For client-id's, see the command 'clients' " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
if ( argc ! = 3 ) return false ;
if ( ! _network_server ) {
SEND_COMMAND ( PACKET_CLIENT_CHAT ) ( NETWORK_ACTION_CHAT_CLIENT , DESTTYPE_CLIENT , atoi ( argv [ 1 ] ) , argv [ 2 ] ) ;
2004-12-04 17:54:56 +00:00
} else
2005-05-02 15:52:19 +00:00
NetworkServer_HandleChat ( NETWORK_ACTION_CHAT_CLIENT , DESTTYPE_CLIENT , atoi ( argv [ 1 ] ) , argv [ 2 ] , NETWORK_SERVER_INDEX ) ;
return true ;
2004-12-04 17:54:56 +00:00
}
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_HOOK ( ConHookServerPW )
{
if ( strncmp ( _network_server_password , " * " , NETWORK_PASSWORD_LENGTH ) = = 0 ) {
_network_server_password [ 0 ] = ' \0 ' ;
_network_game_info . use_password = 0 ;
} else
_network_game_info . use_password = 1 ;
2004-12-13 15:07:33 +00:00
2005-05-02 15:52:19 +00:00
return true ;
}
2004-12-13 15:07:33 +00:00
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_HOOK ( ConHookRconPW )
{
if ( strncmp ( _network_rcon_password , " * " , NETWORK_PASSWORD_LENGTH ) = = 0 )
_network_rcon_password [ 0 ] = ' \0 ' ;
2004-12-13 17:04:41 +00:00
2005-05-02 15:52:19 +00:00
ttd_strlcpy ( _network_game_info . rcon_password , _network_rcon_password , sizeof ( _network_game_info . rcon_password ) ) ;
2004-12-04 17:54:56 +00:00
2005-05-02 15:52:19 +00:00
return true ;
}
2004-12-04 17:54:56 +00:00
2005-05-02 15:52:19 +00:00
/* Also use from within player_gui to change the password graphically */
bool NetworkChangeCompanyPassword ( byte argc , char * argv [ ] )
{
if ( argc = = 0 ) {
2005-05-11 15:30:28 +00:00
if ( _local_player > = MAX_PLAYERS ) return true ; // dedicated server
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_warn , " Current value for 'company_pw': %s " , _network_player_info [ _local_player ] . password ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-12-04 17:54:56 +00:00
}
2005-05-02 15:52:19 +00:00
if ( _local_player > = MAX_PLAYERS ) {
IConsoleError ( " You have to own a company to make use of this command. " ) ;
return false ;
2005-01-15 20:09:16 +00:00
}
2005-05-02 15:52:19 +00:00
if ( argc ! = 1 ) return false ;
2004-12-13 15:07:33 +00:00
2005-05-02 15:52:19 +00:00
if ( strncmp ( argv [ 0 ] , " * " , sizeof ( _network_player_info [ _local_player ] . password ) ) = = 0 )
argv [ 0 ] [ 0 ] = ' \0 ' ;
2004-12-13 15:07:33 +00:00
2005-05-02 15:52:19 +00:00
ttd_strlcpy ( _network_player_info [ _local_player ] . password , argv [ 0 ] , sizeof ( _network_player_info [ _local_player ] . password ) ) ;
2004-12-13 15:07:33 +00:00
2005-05-02 15:52:19 +00:00
if ( ! _network_server )
SEND_COMMAND ( PACKET_CLIENT_SET_PASSWORD ) ( _network_player_info [ _local_player ] . password ) ;
2005-05-28 16:59:51 +00:00
IConsolePrintF ( _icolour_warn , " 'company_pw' changed to: %s " , _network_player_info [ _local_player ] . password ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2004-12-04 17:54:56 +00:00
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_HOOK ( ConProcPlayerName )
{
NetworkClientInfo * ci = NetworkFindClientInfoFromIndex ( _network_own_client_index ) ;
if ( ci = = NULL ) return false ;
// Don't change the name if it is the same as the old name
if ( strcmp ( ci - > client_name , _network_player_name ) ! = 0 ) {
2004-12-13 17:04:41 +00:00
if ( ! _network_server ) {
2005-05-02 15:52:19 +00:00
SEND_COMMAND ( PACKET_CLIENT_SET_NAME ) ( _network_player_name ) ;
2004-12-04 17:54:56 +00:00
} else {
2005-05-02 15:52:19 +00:00
if ( NetworkFindName ( _network_player_name ) ) {
2005-08-28 12:24:57 +00:00
NetworkTextMessage ( NETWORK_ACTION_NAME_CHANGE , 1 , false , ci - > client_name , " %s " , _network_player_name ) ;
2005-05-02 15:52:19 +00:00
ttd_strlcpy ( ci - > client_name , _network_player_name , sizeof ( ci - > client_name ) ) ;
NetworkUpdateClientInfo ( NETWORK_SERVER_INDEX ) ;
}
2004-12-04 17:54:56 +00:00
}
}
2005-05-02 15:52:19 +00:00
return true ;
}
2004-12-13 17:04:41 +00:00
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_HOOK ( ConHookServerName )
{
ttd_strlcpy ( _network_game_info . server_name , _network_server_name , sizeof ( _network_game_info . server_name ) ) ;
return true ;
}
2004-12-13 17:47:21 +00:00
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_HOOK ( ConHookServerAdvertise )
{
2005-05-17 16:07:48 +00:00
if ( ! _network_advertise ) // remove us from advertising
2005-05-02 15:52:19 +00:00
NetworkUDPRemoveAdvertise ( ) ;
2005-03-29 19:10:13 +00:00
2005-05-02 15:52:19 +00:00
return true ;
}
2005-03-29 19:10:13 +00:00
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_CMD ( ConProcServerIP )
{
if ( argc = = 0 ) {
2005-05-14 19:34:59 +00:00
IConsolePrintF ( _icolour_warn , " Current value for 'server_ip': %s " , inet_ntoa ( * ( struct in_addr * ) & _network_server_bind_ip ) ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-12-15 22:06:47 +00:00
}
2005-05-02 15:52:19 +00:00
if ( argc ! = 1 ) return false ;
2005-03-29 19:10:13 +00:00
2005-05-28 18:47:05 +00:00
_network_server_bind_ip = ( strcmp ( argv [ 0 ] , " all " ) = = 0 ) ? inet_addr ( " 0.0.0.0 " ) : inet_addr ( argv [ 0 ] ) ;
2005-05-02 15:52:19 +00:00
snprintf ( _network_server_bind_ip_host , sizeof ( _network_server_bind_ip_host ) , " %s " , inet_ntoa ( * ( struct in_addr * ) & _network_server_bind_ip ) ) ;
2005-05-28 16:59:51 +00:00
IConsolePrintF ( _icolour_warn , " 'server_ip' changed to: %s " , inet_ntoa ( * ( struct in_addr * ) & _network_server_bind_ip ) ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2004-12-16 13:59:23 +00:00
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_CMD ( ConPatch )
{
if ( argc = = 0 ) {
IConsoleHelp ( " Change patch variables for all players. Usage: 'patch <name> [<value>]' " ) ;
IConsoleHelp ( " Omitting <value> will print out the current value of the patch-setting. " ) ;
return true ;
2004-12-16 13:59:23 +00:00
}
2005-05-02 15:52:19 +00:00
if ( argc = = 1 | | argc > 3 ) return false ;
2004-12-16 13:59:23 +00:00
2005-05-02 15:52:19 +00:00
if ( argc = = 2 ) {
IConsoleGetPatchSetting ( argv [ 1 ] ) ;
} else
IConsoleSetPatchSetting ( argv [ 1 ] , argv [ 2 ] ) ;
2004-12-23 17:37:26 +00:00
2005-05-02 15:52:19 +00:00
return true ;
}
2004-12-13 17:47:21 +00:00
# endif /* ENABLE_NETWORK */
2004-12-13 15:07:33 +00:00
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_CMD ( ConListDumpVariables )
{
const IConsoleVar * var ;
size_t l = 0 ;
if ( argc = = 0 ) {
IConsoleHelp ( " List all variables with their value. Usage: 'dump_vars [<pre-filter>]' " ) ;
return true ;
2004-12-13 16:16:28 +00:00
}
2005-05-02 15:52:19 +00:00
if ( argv [ 1 ] ! = NULL ) l = strlen ( argv [ 1 ] ) ;
2004-12-13 16:16:28 +00:00
2005-05-02 15:52:19 +00:00
for ( var = _iconsole_vars ; var ! = NULL ; var = var - > next ) {
if ( argv [ 1 ] = = NULL | | strncmp ( var - > name , argv [ 1 ] , l ) = = 0 )
IConsoleVarPrintGetValue ( var ) ;
}
2004-12-13 15:07:33 +00:00
2005-05-02 15:52:19 +00:00
return true ;
2004-12-04 17:54:56 +00:00
}
2004-09-12 21:49:38 +00:00
# ifdef _DEBUG
/* ****************************************** */
/* debug commands and variables */
/* ****************************************** */
2005-01-22 22:47:58 +00:00
static void IConsoleDebugLibRegister ( void )
2004-09-12 21:49:38 +00:00
{
2004-12-05 12:25:25 +00:00
// debugging variables and functions
2004-09-19 15:24:45 +00:00
extern bool _stdlib_con_developer ; /* XXX extern in .c */
2005-05-02 15:52:19 +00:00
IConsoleVarRegister ( " con_developer " , & _stdlib_con_developer , ICONSOLE_VAR_BOOLEAN , " Enable/disable console debugging information (internal) " ) ;
IConsoleCmdRegister ( " resettile " , ConResetTile ) ;
IConsoleAliasRegister ( " dbg_echo " , " echo %A; echo %B " ) ;
IConsoleAliasRegister ( " dbg_echo2 " , " echo %! " ) ;
2004-09-12 21:49:38 +00:00
}
# endif
/* ****************************************** */
/* console command and variable registration */
/* ****************************************** */
2004-12-04 17:54:56 +00:00
void IConsoleStdLibRegister ( void )
2004-09-12 21:49:38 +00:00
{
// stdlib
2004-09-19 15:24:45 +00:00
extern byte _stdlib_developer ; /* XXX extern in .c */
2004-09-12 21:49:38 +00:00
2004-12-05 12:25:25 +00:00
// default variables and functions
2004-09-19 15:24:45 +00:00
IConsoleCmdRegister ( " debug_level " , ConDebugLevel ) ;
IConsoleCmdRegister ( " dump_vars " , ConListDumpVariables ) ;
IConsoleCmdRegister ( " echo " , ConEcho ) ;
IConsoleCmdRegister ( " echoc " , ConEchoC ) ;
IConsoleCmdRegister ( " exec " , ConExec ) ;
IConsoleCmdRegister ( " exit " , ConExit ) ;
2005-05-15 10:40:53 +00:00
IConsoleCmdRegister ( " part " , ConPart ) ;
2004-09-19 15:24:45 +00:00
IConsoleCmdRegister ( " help " , ConHelp ) ;
IConsoleCmdRegister ( " info_cmd " , ConInfoCmd ) ;
IConsoleCmdRegister ( " info_var " , ConInfoVar ) ;
IConsoleCmdRegister ( " list_cmds " , ConListCommands ) ;
IConsoleCmdRegister ( " list_vars " , ConListVariables ) ;
2005-05-02 15:52:19 +00:00
IConsoleCmdRegister ( " list_aliases " , ConListAliases ) ;
IConsoleCmdRegister ( " newgame " , ConNewGame ) ;
2004-09-19 15:24:45 +00:00
IConsoleCmdRegister ( " quit " , ConExit ) ;
IConsoleCmdRegister ( " resetengines " , ConResetEngines ) ;
2005-05-02 15:52:19 +00:00
IConsoleCmdRegister ( " return " , ConReturn ) ;
IConsoleCmdRegister ( " screenshot " , ConScreenShot ) ;
IConsoleCmdRegister ( " script " , ConScript ) ;
IConsoleCmdRegister ( " scrollto " , ConScrollToTile ) ;
2005-07-08 22:25:24 +00:00
IConsoleCmdRegister ( " alias " , ConAlias ) ;
IConsoleCmdRegister ( " load " , ConLoad ) ;
2005-09-11 14:57:56 +00:00
IConsoleCmdRegister ( " rm " , ConRemove ) ;
2005-07-08 22:25:24 +00:00
IConsoleCmdRegister ( " save " , ConSave ) ;
2005-05-02 15:52:19 +00:00
IConsoleCmdRegister ( " ls " , ConListFiles ) ;
IConsoleCmdRegister ( " cd " , ConChangeDirectory ) ;
IConsoleCmdRegister ( " pwd " , ConPrintWorkingDirectory ) ;
2005-05-16 13:46:26 +00:00
IConsoleCmdRegister ( " clear " , ConClearBuffer ) ;
2005-06-16 00:54:19 +00:00
IConsoleCmdRegister ( " stopall " , ConStopAllVehicles ) ;
2005-05-02 15:52:19 +00:00
IConsoleAliasRegister ( " dir " , " ls " ) ;
2005-09-11 18:36:22 +00:00
IConsoleAliasRegister ( " del " , " rm %+ " ) ;
2005-05-02 15:52:19 +00:00
IConsoleAliasRegister ( " newmap " , " newgame " ) ;
IConsoleAliasRegister ( " new_map " , " newgame " ) ;
2005-01-08 00:48:10 +00:00
IConsoleAliasRegister ( " new_game " , " newgame " ) ;
2004-12-05 12:25:25 +00:00
2005-05-02 15:52:19 +00:00
IConsoleVarRegister ( " developer " , & _stdlib_developer , ICONSOLE_VAR_BYTE , " Redirect debugging output from the console/command line to the ingame console (value 2). Default value: 1 " ) ;
2005-01-08 00:48:10 +00:00
2005-05-02 15:52:19 +00:00
/* networking variables and functions */
2004-12-04 17:54:56 +00:00
# ifdef ENABLE_NETWORK
2005-05-02 15:52:19 +00:00
/*** Networking commands ***/
IConsoleCmdRegister ( " say " , ConSay ) ;
IConsoleCmdHookAdd ( " say " , ICONSOLE_HOOK_ACCESS , ConHookNeedNetwork ) ;
IConsoleCmdRegister ( " say_player " , ConSayPlayer ) ;
IConsoleCmdHookAdd ( " say_player " , ICONSOLE_HOOK_ACCESS , ConHookNeedNetwork ) ;
IConsoleCmdRegister ( " say_client " , ConSayClient ) ;
IConsoleCmdHookAdd ( " say_client " , ICONSOLE_HOOK_ACCESS , ConHookNeedNetwork ) ;
IConsoleCmdRegister ( " kick " , ConKick ) ;
IConsoleCmdHookAdd ( " kick " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleCmdRegister ( " reset_company " , ConResetCompany ) ;
IConsoleCmdHookAdd ( " reset_company " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleAliasRegister ( " clean_company " , " reset_company %A " ) ;
IConsoleCmdRegister ( " connect " , ConNetworkConnect ) ;
2005-05-15 10:40:53 +00:00
IConsoleAliasRegister ( " join " , " connect %A " ) ;
2005-05-02 15:52:19 +00:00
IConsoleCmdHookAdd ( " connect " , ICONSOLE_HOOK_ACCESS , ConHookClientOnly ) ;
IConsoleCmdRegister ( " clients " , ConNetworkClients ) ;
2005-05-04 10:17:00 +00:00
IConsoleCmdHookAdd ( " clients " , ICONSOLE_HOOK_ACCESS , ConHookNeedNetwork ) ;
2005-05-02 15:52:19 +00:00
IConsoleCmdRegister ( " status " , ConStatus ) ;
IConsoleCmdHookAdd ( " status " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleCmdHookAdd ( " resetengines " , ICONSOLE_HOOK_ACCESS , ConHookNoNetwork ) ;
2005-06-16 00:54:19 +00:00
IConsoleCmdHookAdd ( " stopall " , ICONSOLE_HOOK_ACCESS , ConHookNoNetwork ) ;
2005-05-02 15:52:19 +00:00
IConsoleCmdRegister ( " rcon " , ConRcon ) ;
IConsoleCmdHookAdd ( " rcon " , ICONSOLE_HOOK_ACCESS , ConHookNeedNetwork ) ;
IConsoleCmdRegister ( " ban " , ConBan ) ;
IConsoleCmdHookAdd ( " ban " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleCmdRegister ( " unban " , ConUnBan ) ;
IConsoleCmdHookAdd ( " unban " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleCmdRegister ( " banlist " , ConBanList ) ;
IConsoleCmdHookAdd ( " banlist " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleCmdRegister ( " pause " , ConPauseGame ) ;
IConsoleCmdHookAdd ( " pause " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleCmdRegister ( " unpause " , ConUnPauseGame ) ;
IConsoleCmdHookAdd ( " unpause " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleCmdRegister ( " patch " , ConPatch ) ;
IConsoleCmdHookAdd ( " patch " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
/*** Networking variables ***/
IConsoleVarRegister ( " net_frame_freq " , & _network_frame_freq , ICONSOLE_VAR_BYTE , " The amount of frames before a command will be (visibly) executed. Default value: 1 " ) ;
IConsoleVarHookAdd ( " net_frame_freq " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleVarRegister ( " net_sync_freq " , & _network_sync_freq , ICONSOLE_VAR_UINT16 , " The amount of frames to check if the game is still in sync. Default value: 100 " ) ;
IConsoleVarHookAdd ( " net_sync_freq " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleVarStringRegister ( " server_pw " , & _network_server_password , sizeof ( _network_server_password ) , " Set the server password to protect your server. Use '*' to clear the password " ) ;
IConsoleVarHookAdd ( " server_pw " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleVarHookAdd ( " server_pw " , ICONSOLE_HOOK_POST_ACTION , ConHookServerPW ) ;
IConsoleAliasRegister ( " server_password " , " server_pw %+ " ) ;
IConsoleVarStringRegister ( " rcon_pw " , & _network_rcon_password , sizeof ( _network_rcon_password ) , " Set the rcon-password to change server behaviour. Use '*' to disable rcon " ) ;
IConsoleVarHookAdd ( " rcon_pw " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleVarHookAdd ( " rcon_pw " , ICONSOLE_HOOK_POST_ACTION , ConHookRconPW ) ;
IConsoleAliasRegister ( " rcon_password " , " rcon_pw %+ " ) ;
IConsoleVarStringRegister ( " company_pw " , NULL , 0 , " Set a password for your company, so no one without the correct password can join. Use '*' to clear the password " ) ;
IConsoleVarHookAdd ( " company_pw " , ICONSOLE_HOOK_ACCESS , ConHookNeedNetwork ) ;
IConsoleVarProcAdd ( " company_pw " , NetworkChangeCompanyPassword ) ;
IConsoleAliasRegister ( " company_password " , " company_pw %+ " ) ;
IConsoleVarStringRegister ( " name " , & _network_player_name , sizeof ( _network_player_name ) , " Set your name for multiplayer " ) ;
IConsoleVarHookAdd ( " name " , ICONSOLE_HOOK_ACCESS , ConHookNeedNetwork ) ;
IConsoleVarHookAdd ( " name " , ICONSOLE_HOOK_POST_ACTION , ConProcPlayerName ) ;
IConsoleVarStringRegister ( " server_name " , & _network_server_name , sizeof ( _network_server_name ) , " Set the name of the server for multiplayer " ) ;
IConsoleVarHookAdd ( " server_name " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleVarHookAdd ( " server_name " , ICONSOLE_HOOK_POST_ACTION , ConHookServerName ) ;
IConsoleVarRegister ( " server_port " , & _network_server_port , ICONSOLE_VAR_UINT32 , " Set the server port. Changes take effect the next time you start a server " ) ;
2005-05-28 19:05:24 +00:00
IConsoleVarRegister ( " server_ip " , & _network_server_bind_ip , ICONSOLE_VAR_UINT32 , " Set the IP the server binds to. Changes take effect the next time you start a server. Use 'all' to bind to any IP. " ) ;
2005-05-02 15:52:19 +00:00
IConsoleVarProcAdd ( " server_ip " , ConProcServerIP ) ;
IConsoleAliasRegister ( " server_bind_ip " , " server_ip %+ " ) ;
IConsoleAliasRegister ( " server_ip_bind " , " server_ip %+ " ) ;
IConsoleAliasRegister ( " server_bind " , " server_ip %+ " ) ;
IConsoleVarRegister ( " max_join_time " , & _network_max_join_time , ICONSOLE_VAR_UINT16 , " Set the maximum amount of time (ticks) a client is allowed to join. Default value: 500 " ) ;
IConsoleVarRegister ( " server_advertise " , & _network_advertise , ICONSOLE_VAR_BOOLEAN , " Set if the server will advertise to the master server and show up there " ) ;
IConsoleVarHookAdd ( " server_advertise " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleVarHookAdd ( " server_advertise " , ICONSOLE_HOOK_POST_ACTION , ConHookServerAdvertise ) ;
IConsoleVarRegister ( " pause_on_join " , & _network_pause_on_join , ICONSOLE_VAR_BOOLEAN , " Set if the server should pause gameplay while a client is joining. This might help slow users " ) ;
IConsoleVarHookAdd ( " pause_on_join " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleVarRegister ( " autoclean_companies " , & _network_autoclean_companies , ICONSOLE_VAR_BOOLEAN , " Automatically shut down inactive companies to free them up for other players. Customize with 'autoclean_(un)protected' " ) ;
IConsoleVarHookAdd ( " autoclean_companies " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleVarRegister ( " autoclean_protected " , & _network_autoclean_protected , ICONSOLE_VAR_BYTE , " Automatically remove the password from an inactive company after the given amount of months " ) ;
IConsoleVarHookAdd ( " autoclean_protected " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
2005-06-30 12:42:27 +00:00
IConsoleVarRegister ( " autoclean_unprotected " , & _network_autoclean_unprotected , ICONSOLE_VAR_BYTE , " Automatically shut down inactive companies after the given amount of months " ) ;
2005-05-02 15:52:19 +00:00
IConsoleVarHookAdd ( " autoclean_unprotected " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleVarRegister ( " restart_game_date " , & _network_restart_game_date , ICONSOLE_VAR_BYTE , " Auto-restart the server when Jan 1st of the set year is reached. Use '0' to disable this " ) ;
IConsoleVarHookAdd ( " restart_game_date " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
2004-12-04 17:54:56 +00:00
# endif /* ENABLE_NETWORK */
2004-09-12 21:49:38 +00:00
2004-12-05 12:25:25 +00:00
// debugging stuff
# ifdef _DEBUG
IConsoleDebugLibRegister ( ) ;
# endif
2004-09-12 21:49:38 +00:00
}