2005-07-24 14:12:37 +00:00
/* $Id$ */
2008-05-06 15:11:33 +00:00
/** @file console_cmds.cpp Implementation of the console hooks. */
2007-02-23 11:50:43 +00:00
2004-09-12 21:49:38 +00:00
# include "stdafx.h"
2005-06-02 19:30:21 +00:00
# include "openttd.h"
2008-05-24 10:15:06 +00:00
# include "console_internal.h"
2005-02-05 15:58:59 +00:00
# include "debug.h"
2008-03-31 00:17:39 +00:00
# include "engine_func.h"
2007-04-12 13:07:15 +00:00
# include "landscape.h"
2005-07-22 06:31:31 +00:00
# include "saveload.h"
2004-09-12 21:49:38 +00:00
# include "variables.h"
2008-05-30 18:20:26 +00:00
# include "network/network.h"
# include "network/network_func.h"
2007-12-21 21:50:46 +00:00
# include "command_func.h"
2008-01-07 00:19:09 +00:00
# include "settings_func.h"
2006-08-05 00:59:45 +00:00
# include "fios.h"
2008-08-31 10:50:05 +00:00
# include "fileio_func.h"
2006-07-28 21:51:00 +00:00
# include "screenshot.h"
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
# include "genworld.h"
2007-12-21 19:49:27 +00:00
# include "strings_func.h"
2008-01-09 09:57:48 +00:00
# include "viewport_func.h"
2007-12-25 11:26:07 +00:00
# include "window_func.h"
# include "functions.h"
2007-12-26 11:45:43 +00:00
# include "map_func.h"
2007-12-26 13:50:40 +00:00
# include "date_func.h"
2007-12-27 13:35:39 +00:00
# include "vehicle_func.h"
2008-01-07 14:23:25 +00:00
# include "string_func.h"
2008-09-30 20:51:04 +00:00
# include "company_func.h"
# include "company_base.h"
2008-01-13 14:37:30 +00:00
# include "settings_type.h"
2008-06-03 18:35:58 +00:00
# include "gamelog.h"
2004-09-12 21:49:38 +00:00
2008-01-13 01:21:35 +00:00
# ifdef ENABLE_NETWORK
# include "table/strings.h"
# endif /* ENABLE_NETWORK */
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[])
2007-03-07 11:47:46 +00:00
# define DEF_CONSOLE_HOOK(function) static bool function()
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
2007-03-07 11:47:46 +00:00
static inline bool NetworkAvailable ( )
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 )
{
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_WARNING , " - %s " , str ) ;
2005-05-02 15:52:19 +00:00
}
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
}
2006-04-23 22:06:52 +00:00
DEF_CONSOLE_CMD ( ConStopAllVehicles )
{
if ( argc = = 0 ) {
IConsoleHelp ( " Stops all vehicles in the game. For debugging only! Use at your own risk... Usage: 'stopall' " ) ;
return true ;
}
2007-12-27 13:35:39 +00:00
StopAllVehicles ( ) ;
2006-04-23 22:06:52 +00:00
return true ;
}
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 ] ) ) {
2006-09-09 22:15:19 +00:00
if ( result > = MapSize ( ) ) {
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_ERROR , " Tile does not exist " ) ;
2006-09-09 22:15:19 +00:00
return true ;
}
2005-05-02 15:52:19 +00:00
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
}
2007-03-07 11:47:46 +00:00
extern void BuildFileList ( ) ;
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 ) {
2007-06-17 15:48:57 +00:00
char * filename = str_fmt ( " %s.sav " , argv [ 1 ] ) ;
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " Saving map... " ) ;
2005-05-02 15:52:19 +00:00
2007-06-17 15:48:57 +00:00
if ( SaveOrLoad ( filename , SL_SAVE , SAVE_DIR ) ! = SL_OK ) {
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_ERROR , " Saving map failed " ) ;
2006-06-27 21:25:53 +00:00
} else {
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_DEFAULT , " Map sucessfully saved to %s " , filename ) ;
2006-06-27 21:25:53 +00:00
}
2007-06-17 15:48:57 +00:00
free ( filename ) ;
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
}
2007-01-03 18:06:50 +00:00
/* Explicitly save the configuration */
DEF_CONSOLE_CMD ( ConSaveConfig )
{
if ( argc = = 0 ) {
IConsoleHelp ( " Saves the current config, typically to 'openttd.cfg'. " ) ;
return true ;
}
SaveToConfig ( ) ;
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " Saved config. " ) ;
2007-01-03 18:06:50 +00:00
return true ;
}
2005-03-27 12:48:25 +00:00
static const FiosItem * GetFiosItem ( const char * file )
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
2008-06-02 14:19:27 +00:00
for ( const FiosItem * item = _fios_items . Begin ( ) ; item ! = _fios_items . End ( ) ; item + + ) {
if ( strcmp ( file , item - > name ) = = 0 ) return item ;
if ( strcmp ( file , item - > title ) = = 0 ) return item ;
2005-03-27 12:48:25 +00:00
}
2005-01-04 15:06:08 +00:00
2008-06-02 14:19:27 +00:00
/* If no name matches, try to parse it as number */
char * endptr ;
int i = strtol ( file , & endptr , 10 ) ;
if ( file = = endptr | | * endptr ! = ' \0 ' ) i = - 1 ;
2005-01-04 15:06:08 +00:00
2008-06-02 14:19:27 +00:00
return IsInsideMM ( i , 0 , _fios_items . Length ( ) ) ? _fios_items . Get ( 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
if ( argc = = 0 ) {
2005-10-19 19:44:01 +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 ;
2008-06-02 14:19:27 +00:00
const char * file = argv [ 1 ] ;
const FiosItem * item = GetFiosItem ( file ) ;
2005-03-27 12:48:25 +00:00
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 ;
2008-05-24 10:35:15 +00:00
default : IConsolePrintF ( CC_ERROR , " %s: Not a savegame. " , file ) ;
2005-03-27 12:48:25 +00:00
}
2006-06-27 21:25:53 +00:00
} else {
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_ERROR , " %s: No such file or directory. " , file ) ;
2006-06-27 21:25:53 +00:00
}
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 )
{
if ( argc = = 0 ) {
IConsoleHelp ( " Remove a savegame by name or index. Usage: 'rm <file | number>' " ) ;
return true ;
}
if ( argc ! = 2 ) return false ;
2008-06-02 14:19:27 +00:00
const char * file = argv [ 1 ] ;
const FiosItem * item = GetFiosItem ( file ) ;
2005-09-11 14:57:56 +00:00
if ( item ! = NULL ) {
if ( ! FiosDelete ( item - > name ) )
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_ERROR , " %s: Failed to delete file " , file ) ;
2006-06-27 21:25:53 +00:00
} else {
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_ERROR , " %s: No such file or directory. " , file ) ;
2006-06-27 21:25:53 +00:00
}
2005-09-11 14:57:56 +00:00
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 )
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2005-10-19 19:44: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 ( ) ;
2008-06-02 14:19:27 +00:00
for ( uint i = 0 ; i < _fios_items . Length ( ) ; i + + ) {
IConsolePrintF ( CC_DEFAULT , " %d) %s " , i , _fios_items [ i ] . 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
if ( argc = = 0 ) {
2005-10-19 19:44:01 +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 ;
2008-06-02 14:19:27 +00:00
const char * file = argv [ 1 ] ;
const FiosItem * item = GetFiosItem ( file ) ;
2005-03-27 12:48:25 +00:00
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 ;
2008-05-24 10:35:15 +00:00
default : IConsolePrintF ( CC_ERROR , " %s: Not a directory. " , file ) ;
2005-01-04 15:06:08 +00:00
}
2006-06-27 21:25:53 +00:00
} else {
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_ERROR , " %s: No such file or directory. " , file ) ;
2006-06-27 21:25:53 +00:00
}
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
2006-08-05 00:59:45 +00:00
FiosGetSavegameList ( SLD_LOAD_GAME ) ;
2005-01-04 15:06:08 +00:00
FiosFreeSavegameList ( ) ;
2005-03-28 13:30:51 +00:00
FiosGetDescText ( & path , NULL ) ;
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , 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 ;
2006-01-29 18:04:52 +00:00
const char * banip = NULL ;
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 ) {
2008-09-30 20:39:50 +00:00
IConsoleHelp ( " Ban a client from a network game. Usage: 'ban <ip | client-id>' " ) ;
2005-05-02 15:52:19 +00:00
IConsoleHelp ( " For client-id's, see the command 'clients' " ) ;
2006-01-29 18:04:52 +00:00
IConsoleHelp ( " If the client is no longer online, you can still ban his/her IP " ) ;
2005-05-02 15:52:19 +00:00
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
2006-01-29 18:04:52 +00:00
if ( strchr ( argv [ 1 ] , ' . ' ) = = NULL ) { // banning with ID
2006-01-19 15:58:57 +00:00
index = atoi ( argv [ 1 ] ) ;
2006-01-19 16:12:24 +00:00
ci = NetworkFindClientInfoFromIndex ( index ) ;
2006-01-29 18:04:52 +00:00
} else { // banning IP
2006-01-19 16:12:24 +00:00
ci = NetworkFindClientInfoFromIP ( argv [ 1 ] ) ;
2006-01-29 18:04:52 +00:00
if ( ci = = NULL ) {
banip = argv [ 1 ] ;
index = ( uint32 ) - 1 ;
} else {
index = ci - > client_index ;
}
2006-01-19 15:58:57 +00:00
}
2005-01-02 12:03:43 +00:00
2005-05-02 15:52:19 +00:00
if ( index = = NETWORK_SERVER_INDEX ) {
2006-01-25 18:11:06 +00:00
IConsoleError ( " Silly boy, you can not ban yourself! " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2006-01-19 15:58:57 +00:00
2006-01-29 18:04:52 +00:00
if ( index = = 0 | | ( ci = = NULL & & index ! = ( uint32 ) - 1 ) ) {
2006-01-19 16:12:24 +00:00
IConsoleError ( " Invalid client " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-01-02 12:03:43 +00:00
}
2005-05-02 15:52:19 +00:00
if ( ci ! = NULL ) {
2008-06-30 14:48:44 +00:00
IConsolePrint ( CC_DEFAULT , " Client banned " ) ;
2008-09-30 20:39:50 +00:00
banip = GetClientIP ( ci ) ;
2008-05-30 18:20:26 +00:00
NetworkServerSendError ( index , NETWORK_ERROR_KICKED ) ;
2006-06-27 21:25:53 +00:00
} else {
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " Client not online, banned IP " ) ;
2006-06-27 21:25:53 +00:00
}
2006-01-29 18:04:52 +00:00
/* Add user to ban-list */
for ( index = 0 ; index < lengthof ( _network_ban_list ) ; index + + ) {
if ( _network_ban_list [ index ] = = NULL ) {
_network_ban_list [ index ] = strdup ( banip ) ;
break ;
}
}
2005-01-02 12:03:43 +00:00
2005-05-02 15:52:19 +00:00
return true ;
}
DEF_CONSOLE_CMD ( ConUnBan )
{
2005-10-19 19:38:35 +00:00
uint i , index ;
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2008-09-30 20:39:50 +00:00
IConsoleHelp ( " Unban a client from a network game. Usage: 'unban <ip | client-id>' " ) ;
2005-10-19 19:38:35 +00:00
IConsoleHelp ( " For a list of banned IP's, see the command 'banlist' " ) ;
2005-05-02 15:52:19 +00:00
return true ;
2005-01-02 12:03:43 +00:00
}
2005-05-02 15:52:19 +00:00
if ( argc ! = 2 ) return false ;
2005-10-19 20:00:05 +00:00
index = ( strchr ( argv [ 1 ] , ' . ' ) = = NULL ) ? atoi ( argv [ 1 ] ) : 0 ;
2005-10-19 19:38:35 +00:00
index - - ;
2005-05-02 15:52:19 +00:00
for ( i = 0 ; i < lengthof ( _network_ban_list ) ; i + + ) {
2006-01-29 18:04:52 +00:00
if ( _network_ban_list [ i ] = = NULL ) continue ;
2005-05-02 15:52:19 +00:00
2006-06-14 12:30:31 +00:00
if ( strcmp ( _network_ban_list [ i ] , argv [ 1 ] ) = = 0 | | index = = i ) {
2006-01-29 18:04:52 +00:00
free ( _network_ban_list [ i ] ) ;
_network_ban_list [ i ] = NULL ;
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " IP unbanned. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
}
2005-01-02 12:03:43 +00:00
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " 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 ;
}
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " Banlist: " ) ;
2005-01-02 12:03:43 +00:00
for ( i = 0 ; i < lengthof ( _network_ban_list ) ; i + + ) {
2006-01-29 18:04:52 +00:00
if ( _network_ban_list [ i ] ! = NULL )
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_DEFAULT , " %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 ;
}
2007-03-06 20:59:52 +00:00
if ( _pause_game = = 0 ) {
2005-01-24 21:33:44 +00:00
DoCommandP ( 0 , 1 , 0 , NULL , CMD_PAUSE ) ;
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " Game paused. " ) ;
2006-06-27 21:25:53 +00:00
} else {
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " Game is already paused. " ) ;
2006-06-27 21:25:53 +00:00
}
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 ;
}
2007-03-06 20:59:52 +00:00
if ( _pause_game ! = 0 ) {
2005-01-24 21:33:44 +00:00
DoCommandP ( 0 , 0 , 0 , NULL , CMD_PAUSE ) ;
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " Game unpaused. " ) ;
2006-06-27 21:25:53 +00:00
} else {
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " Game is already unpaused. " ) ;
2006-06-27 21:25:53 +00:00
}
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
2008-05-17 11:46:35 +00:00
if ( _network_server ) {
IConsoleCmdExec ( argv [ 2 ] ) ;
} else {
2008-05-30 18:20:26 +00:00
NetworkClientSendRcon ( argv [ 1 ] , argv [ 2 ] ) ;
2008-05-17 11:46:35 +00:00
}
2005-05-02 15:52:19 +00:00
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
if ( argc = = 0 ) {
2006-01-25 18:11:06 +00:00
IConsoleHelp ( " List the status of all clients connected to the server. Usage 'status' " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2008-05-30 18:20:26 +00:00
NetworkServerShowStatusToConsole ( ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-12-04 17:54:56 +00:00
}
2006-01-25 18:11:06 +00:00
DEF_CONSOLE_CMD ( ConServerInfo )
{
if ( argc = = 0 ) {
2008-09-30 20:39:50 +00:00
IConsoleHelp ( " List current and maximum client/company limits. Usage 'server_info' " ) ;
2006-01-25 18:11:06 +00:00
IConsoleHelp ( " You can change these values by setting the variables 'max_clients', 'max_companies' and 'max_spectators' " ) ;
return true ;
}
2008-06-03 08:04:35 +00:00
IConsolePrintF ( CC_DEFAULT , " Current/maximum clients: %2d/%2d " , _network_game_info . clients_on , _settings_client . network . max_clients ) ;
2008-09-30 20:39:50 +00:00
IConsolePrintF ( CC_DEFAULT , " Current/maximum companies: %2d/%2d " , ActiveCompanyCount ( ) , _settings_client . network . max_companies ) ;
2008-06-03 08:04:35 +00:00
IConsolePrintF ( CC_DEFAULT , " Current/maximum spectators: %2d/%2d " , NetworkSpectatorCount ( ) , _settings_client . network . max_spectators ) ;
2006-01-25 18:11:06 +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 ) {
2008-09-30 20:39:50 +00:00
IConsoleHelp ( " Kick a client from a network game. Usage: 'kick <ip | client-id>' " ) ;
2005-05-02 15:52:19 +00:00
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
2006-01-19 15:58:57 +00:00
if ( strchr ( argv [ 1 ] , ' . ' ) = = NULL ) {
index = atoi ( argv [ 1 ] ) ;
2006-01-19 16:12:24 +00:00
ci = NetworkFindClientInfoFromIndex ( index ) ;
2006-01-19 15:58:57 +00:00
} else {
2006-01-19 16:12:24 +00:00
ci = NetworkFindClientInfoFromIP ( argv [ 1 ] ) ;
2006-01-19 15:58:57 +00:00
index = ( ci = = NULL ) ? 0 : ci - > client_index ;
}
2005-05-02 15:52:19 +00:00
if ( index = = NETWORK_SERVER_INDEX ) {
2006-01-25 18:11:06 +00:00
IConsoleError ( " 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
}
2006-01-19 15:58:57 +00:00
2005-05-02 15:52:19 +00:00
if ( index = = 0 ) {
2006-01-19 16:12:24 +00:00
IConsoleError ( " Invalid client " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
if ( ci ! = NULL ) {
2008-05-30 18:20:26 +00:00
NetworkServerSendError ( index , NETWORK_ERROR_KICKED ) ;
2006-06-27 21:25:53 +00:00
} else {
2006-01-19 16:12:24 +00:00
IConsoleError ( " Client not found " ) ;
2006-06-27 21:25:53 +00:00
}
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 )
{
2008-09-30 20:39:50 +00:00
CompanyID 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>' " ) ;
2008-09-30 20:39:50 +00:00
IConsoleHelp ( " For company-id's, see the list of companies from the dropdown menu. Company 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
2008-09-30 20:39:50 +00:00
index = ( CompanyID ) ( atoi ( argv [ 1 ] ) - 1 ) ;
2004-12-16 11:36:57 +00:00
2005-05-02 15:52:19 +00:00
/* Check valid range */
2008-09-30 20:39:50 +00:00
if ( ! IsValidCompanyID ( index ) ) {
IConsolePrintF ( CC_ERROR , " Company does not exist. Company-id must be between 1 and %d. " , MAX_COMPANIES ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2004-12-16 11:36:57 +00:00
2008-09-30 20:39:50 +00:00
const Company * c = GetCompany ( index ) ;
2005-05-02 15:52:19 +00:00
2008-09-30 20:39:50 +00:00
if ( c - > 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 ;
}
2008-09-30 20:39:50 +00:00
if ( NetworkCompanyHasClients ( index ) ) {
2008-05-30 18:20:26 +00:00
IConsoleError ( " Cannot remove company: a client is connected to that company. " ) ;
return false ;
2005-05-02 15:52:19 +00:00
}
2008-05-30 18:20:26 +00:00
const NetworkClientInfo * ci = NetworkFindClientInfoFromIndex ( NETWORK_SERVER_INDEX ) ;
2006-10-17 22:16:46 +00:00
if ( ci - > client_playas = = 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 */
2008-09-30 20:39:50 +00:00
DoCommandP ( 0 , 2 , index , NULL , CMD_COMPANY_CTRL ) ;
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , " 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 ) {
2005-10-19 19:38:35 +00:00
IConsoleHelp ( " Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients' " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2006-10-18 13:17:46 +00:00
FOR_ALL_ACTIVE_CLIENT_INFOS ( ci ) {
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_INFO , " Client #%1d name: '%s' company: %1d IP: %s " ,
2006-10-18 13:17:46 +00:00
ci - > client_index , ci - > client_name ,
2008-09-30 20:39:50 +00:00
ci - > client_playas + ( IsValidCompanyID ( ci - > client_playas ) ? 1 : 0 ) ,
GetClientIP ( ci ) ) ;
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 ;
2008-09-30 20:39:50 +00:00
const char * company = 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>' " ) ;
2008-09-30 20:39:50 +00:00
IConsoleHelp ( " IP can contain port and company: 'IP[[#Company]:Port]', eg: 'server.ottd.org#2:443' " ) ;
IConsoleHelp ( " Company #255 is spectator all others are a certain company with Company 1 being #1 " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2004-09-12 21:49:38 +00:00
2005-05-02 15:52:19 +00:00
if ( argc < 2 ) return false ;
2006-10-18 13:17:46 +00:00
if ( _networking ) NetworkDisconnect ( ) ; // we are in network-mode, first close it!
2004-12-04 17:54:56 +00:00
2004-09-12 23:35:01 +00:00
ip = argv [ 1 ] ;
2006-10-15 23:48:34 +00:00
/* Default settings: default port and new company */
2004-12-04 17:54:56 +00:00
rport = NETWORK_DEFAULT_PORT ;
2008-09-30 20:39:50 +00:00
_network_playas = COMPANY_NEW_COMPANY ;
2004-09-12 21:49:38 +00:00
2008-09-30 20:39:50 +00:00
ParseConnectionString ( & company , & port , ip ) ;
2004-09-12 23:35:01 +00:00
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_DEFAULT , " Connecting to %s... " , ip ) ;
2008-09-30 20:39:50 +00:00
if ( company ! = NULL ) {
_network_playas = ( CompanyID ) atoi ( company ) ;
IConsolePrintF ( CC_DEFAULT , " company-no: %d " , _network_playas ) ;
2006-10-15 23:48:34 +00:00
2008-09-30 20:39:50 +00:00
/* From a user pov 0 is a new company, internally it's different and all
* companies are offset by one to ease up on users ( eg companies 1 - 8 not 0 - 7 ) */
if ( _network_playas ! = COMPANY_SPECTATOR ) {
2006-10-17 22:16:46 +00:00
_network_playas - - ;
2008-09-30 20:39:50 +00:00
if ( ! IsValidCompanyID ( _network_playas ) ) return false ;
2006-10-15 23:48:34 +00:00
}
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 ) ;
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_DEFAULT , " 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
2008-02-07 10:01:18 +00:00
_script_file = FioFOpenFile ( argv [ 1 ] , " r " , BASE_DIR ) ;
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 ;
2008-02-07 10:01:18 +00:00
FioFCloseFile ( _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 */
/* **************************** */
2007-03-07 11:47:46 +00:00
extern bool CloseConsoleLogIfActive ( ) ;
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 ;
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_DEFAULT , " 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 ;
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_DEFAULT , 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 ;
2008-05-24 10:35:15 +00:00
IConsolePrint ( ( ConsoleColour ) atoi ( argv [ 1 ] ) , argv [ 2 ] ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
DEF_CONSOLE_CMD ( ConNewGame )
{
if ( argc = = 0 ) {
IConsoleHelp ( " Start a new game. Usage: 'newgame [seed]' " ) ;
IConsoleHelp ( " The server can force a new game using 'newgame'; any client joined will rejoin after the server is done generating the new game. " ) ;
return true ;
}
StartNewGameWithoutGUI ( ( argc = = 2 ) ? ( uint ) atoi ( argv [ 1 ] ) : GENERATE_NEW_SEED ) ;
return true ;
}
2004-12-04 17:54:56 +00:00
extern void SwitchMode ( int new_mode ) ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
DEF_CONSOLE_CMD ( ConRestart )
{
if ( argc = = 0 ) {
IConsoleHelp ( " Restart game. Usage: 'restart' " ) ;
IConsoleHelp ( " Restarts a game. It tries to reproduce the exact same map as the game started with. " ) ;
return true ;
}
/* Don't copy the _newgame pointers to the real pointers, so call SwitchMode directly */
2008-05-29 15:13:28 +00:00
_settings_game . game_creation . map_x = MapLogX ( ) ;
_settings_game . game_creation . map_y = FindFirstBit ( MapSizeY ( ) ) ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
SwitchMode ( SM_NEWGAME ) ;
return true ;
}
DEF_CONSOLE_CMD ( ConGetSeed )
2004-12-04 17:54:56 +00:00
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
IConsoleHelp ( " Returns the seed used to create this game. Usage: 'getseed' " ) ;
IConsoleHelp ( " The seed can be used to reproduce the exact same map as the game started with. " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
2008-05-29 15:13:28 +00:00
IConsolePrintF ( CC_DEFAULT , " Generation Seed: %u " , _settings_game . game_creation . generation_seed ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-09-12 21:49:38 +00:00
}
2007-06-13 14:52:41 +00:00
DEF_CONSOLE_CMD ( ConGetDate )
{
if ( argc = = 0 ) {
IConsoleHelp ( " Returns the current date (day-month-year) of the game. Usage: 'getdate' " ) ;
return true ;
}
YearMonthDay ymd ;
ConvertDateToYMD ( _date , & ymd ) ;
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_DEFAULT , " Date: %d-%d-%d " , ymd . day , ymd . month + 1 , ymd . year ) ;
2007-06-13 14:52:41 +00:00
return true ;
}
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-10-19 19:44:01 +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 ;
}
2005-10-19 19:41:38 +00:00
if ( argc > 3 ) return false ;
2006-07-28 21:51:00 +00:00
SetScreenshotType ( SC_VIEWPORT ) ;
2005-10-19 19:41:38 +00:00
if ( argc > 1 ) {
if ( strcmp ( argv [ 1 ] , " big " ) = = 0 | | ( argc = = 3 & & strcmp ( argv [ 2 ] , " big " ) = = 0 ) )
2006-07-28 21:51:00 +00:00
SetScreenshotType ( SC_WORLD ) ;
2005-05-02 15:52:19 +00:00
2005-10-19 19:41:38 +00:00
if ( strcmp ( argv [ 1 ] , " no_con " ) = = 0 | | ( argc = = 3 & & strcmp ( argv [ 2 ] , " no_con " ) = = 0 ) )
2004-09-12 21:49:38 +00:00
IConsoleClose ( ) ;
2004-09-19 15:24:45 +00:00
}
2005-10-19 19:41:38 +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 ;
}
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_DEFAULT , " variable name: %s " , var - > name ) ;
IConsolePrintF ( CC_DEFAULT , " variable type: %s " , _icon_vartypes [ var - > type ] ) ;
IConsolePrintF ( CC_DEFAULT , " 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
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_DEFAULT , " command name: %s " , cmd - > name ) ;
IConsolePrintF ( CC_DEFAULT , " 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 ) {
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_DEFAULT , " Current debug-level: '%s' " , GetDebugString ( ) ) ;
2006-06-27 21:25:53 +00:00
} else {
SetDebugString ( argv [ 1 ] ) ;
}
2005-05-20 17:59:24 +00:00
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 ;
}
2008-05-29 15:13:28 +00:00
if ( _game_mode = = GM_NORMAL & & _settings_client . gui . autosave_on_exit ) DoExitSave ( ) ;
2007-07-23 15:28:02 +00:00
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 ;
}
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_ERROR , " ERROR: alias is of special type, please see its execution-line: '%s' " , alias - > cmdline ) ;
2005-07-08 22:25:24 +00:00
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
2008-05-24 10:35:15 +00:00
IConsolePrint ( CC_WARNING , " ---- OpenTTD Console Help ---- " ) ;
IConsolePrint ( CC_DEFAULT , " - variables: [command to list all variables: list_vars] " ) ;
IConsolePrint ( CC_DEFAULT , " set value with '<var> = <value>', use '++/--' to in-or decrement " ) ;
IConsolePrint ( CC_DEFAULT , " or omit '=' and just '<var> <value>'. get value with typing '<var>' " ) ;
IConsolePrint ( CC_DEFAULT , " - commands: [command to list all commands: list_cmds] " ) ;
IConsolePrint ( CC_DEFAULT , " call commands with '<command> <arg2> <arg3>...' " ) ;
IConsolePrint ( CC_DEFAULT , " - to assign strings, or use them as arguments, enclose it within quotes " ) ;
IConsolePrint ( CC_DEFAULT , " like this: '<command> \" string argument with spaces \" ' " ) ;
IConsolePrint ( CC_DEFAULT , " - use 'help <command> | <variable>' to get specific information " ) ;
IConsolePrint ( CC_DEFAULT , " - scroll console output with shift + (up | down) | (pageup | pagedown)) " ) ;
IConsolePrint ( CC_DEFAULT , " - scroll console input history with the up | down arrows " ) ;
IConsolePrint ( CC_DEFAULT , " " ) ;
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 ) {
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_DEFAULT , " %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 )
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_DEFAULT , " %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 )
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_DEFAULT , " %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 ) {
2008-05-30 18:20:26 +00:00
NetworkClientSendChat ( NETWORK_ACTION_CHAT , DESTTYPE_BROADCAST , 0 /* param does not matter */ , argv [ 1 ] ) ;
2006-06-27 21:25:53 +00:00
} else {
2008-05-30 18:20:26 +00:00
NetworkServerSendChat ( NETWORK_ACTION_CHAT , DESTTYPE_BROADCAST , 0 , argv [ 1 ] , NETWORK_SERVER_INDEX ) ;
2006-06-27 21:25:53 +00:00
}
2005-05-02 15:52:19 +00:00
return true ;
2004-12-04 17:54:56 +00:00
}
2008-09-30 20:39:50 +00:00
DEF_CONSOLE_CMD ( ConCompanies )
2006-05-11 14:08:03 +00:00
{
2008-09-30 20:39:50 +00:00
Company * c ;
2006-05-11 14:08:03 +00:00
if ( argc = = 0 ) {
2008-09-30 20:39:50 +00:00
IConsoleHelp ( " List the in-game details of all clients connected to the server. Usage 'companies' " ) ;
2006-05-11 14:08:03 +00:00
return true ;
}
NetworkPopulateCompanyInfo ( ) ;
2008-09-30 20:39:50 +00:00
FOR_ALL_COMPANIES ( c ) {
2006-05-14 23:01:11 +00:00
char buffer [ 512 ] ;
2008-09-30 20:39:50 +00:00
const NetworkCompanyInfo * npi = & _network_company_info [ c - > index ] ;
2007-05-02 19:00:59 +00:00
2008-09-30 20:39:50 +00:00
GetString ( buffer , STR_00D1_DARK_BLUE + _company_colours [ c - > index ] , lastof ( buffer ) ) ;
2008-05-24 10:35:15 +00:00
IConsolePrintF ( CC_INFO , " #:%d(%s) Company Name: '%s' Year Founded: %d Money: % " OTTD_PRINTF64 " d Loan: % " OTTD_PRINTF64 " d Value: % " OTTD_PRINTF64 " d (T:%d, R:%d, P:%d, S:%d) %sprotected " ,
2008-09-30 20:39:50 +00:00
c - > index + 1 , buffer , npi - > company_name , c - > inaugurated_year , ( int64 ) c - > money , ( int64 ) c - > current_loan , ( int64 ) CalculateCompanyValue ( c ) ,
2007-05-02 19:00:59 +00:00
/* trains */ npi - > num_vehicle [ 0 ] ,
/* lorry + bus */ npi - > num_vehicle [ 1 ] + npi - > num_vehicle [ 2 ] ,
/* planes */ npi - > num_vehicle [ 3 ] ,
/* ships */ npi - > num_vehicle [ 4 ] ,
/* protected */ StrEmpty ( npi - > password ) ? " un " : " " ) ;
2006-05-11 14:08:03 +00:00
}
return true ;
}
2008-09-30 20:39:50 +00:00
DEF_CONSOLE_CMD ( ConSayCompany )
2004-12-04 17:54:56 +00:00
{
2005-05-02 15:52:19 +00:00
if ( argc = = 0 ) {
2008-09-30 20:39:50 +00:00
IConsoleHelp ( " Chat to a certain company in a multiplayer game. Usage: 'say_company <company-no> \" <msg> \" ' " ) ;
IConsoleHelp ( " CompanyNo is the company that plays as company <companyno>, 1 through max_companies " ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
if ( argc ! = 3 ) return false ;
2004-12-04 17:54:56 +00:00
2008-09-30 20:39:50 +00:00
CompanyID company_id = ( CompanyID ) ( atoi ( argv [ 1 ] ) - 1 ) ;
if ( ! IsValidCompanyID ( company_id ) ) {
IConsolePrintF ( CC_DEFAULT , " Unknown company. Company range is between 1 and %d. " , MAX_COMPANIES ) ;
2005-05-02 15:52:19 +00:00
return true ;
}
if ( ! _network_server ) {
2008-09-30 20:39:50 +00:00
NetworkClientSendChat ( NETWORK_ACTION_CHAT_COMPANY , DESTTYPE_TEAM , company_id , argv [ 2 ] ) ;
2006-06-27 21:25:53 +00:00
} else {
2008-09-30 20:39:50 +00:00
NetworkServerSendChat ( NETWORK_ACTION_CHAT_COMPANY , DESTTYPE_TEAM , company_id , argv [ 2 ] , NETWORK_SERVER_INDEX ) ;
2006-06-27 21:25:53 +00:00
}
2005-05-02 15:52:19 +00:00
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 ) {
2008-09-30 20:39:50 +00:00
IConsoleHelp ( " Chat to a certain client 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 ) {
2008-05-30 18:20:26 +00:00
NetworkClientSendChat ( NETWORK_ACTION_CHAT_CLIENT , DESTTYPE_CLIENT , atoi ( argv [ 1 ] ) , argv [ 2 ] ) ;
2006-06-27 21:25:53 +00:00
} else {
2008-05-30 18:20:26 +00:00
NetworkServerSendChat ( NETWORK_ACTION_CHAT_CLIENT , DESTTYPE_CLIENT , atoi ( argv [ 1 ] ) , argv [ 2 ] , NETWORK_SERVER_INDEX ) ;
2006-06-27 21:25:53 +00:00
}
2005-05-02 15:52:19 +00:00
return true ;
2004-12-04 17:54:56 +00:00
}
2007-12-02 15:12:19 +00:00
extern void HashCurrentCompanyPassword ( ) ;
2008-09-30 20:39:50 +00:00
/* Also use from within company_gui to change the password graphically */
2005-05-02 15:52:19 +00:00
bool NetworkChangeCompanyPassword ( byte argc , char * argv [ ] )
{
if ( argc = = 0 ) {
2008-09-30 20:39:50 +00:00
if ( ! IsValidCompanyID ( _local_company ) ) return true ; // dedicated server
IConsolePrintF ( CC_WARNING , " Current value for 'company_pw': %s " , _network_company_info [ _local_company ] . password ) ;
2005-05-02 15:52:19 +00:00
return true ;
2004-12-04 17:54:56 +00:00
}
2008-09-30 20:39:50 +00:00
if ( ! IsValidCompanyID ( _local_company ) ) {
2005-05-02 15:52:19 +00:00
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
2006-06-14 13:22:30 +00:00
if ( strcmp ( argv [ 0 ] , " * " ) = = 0 ) argv [ 0 ] [ 0 ] = ' \0 ' ;
2004-12-13 15:07:33 +00:00
2008-09-30 20:39:50 +00:00
ttd_strlcpy ( _network_company_info [ _local_company ] . password , argv [ 0 ] , sizeof ( _network_company_info [ _local_company ] . password ) ) ;
2004-12-13 15:07:33 +00:00
2007-12-02 15:12:19 +00:00
if ( ! _network_server ) {
2008-05-30 18:20:26 +00:00
NetworkClientSetPassword ( ) ;
2007-12-02 15:12:19 +00:00
} else {
HashCurrentCompanyPassword ( ) ;
}
2005-05-02 15:52:19 +00:00
2008-09-30 20:39:50 +00:00
IConsolePrintF ( CC_WARNING , " 'company_pw' changed to: %s " , _network_company_info [ _local_company ] . password ) ;
2005-05-28 16:59:51 +00:00
2005-05-02 15:52:19 +00:00
return true ;
}
2004-12-04 17:54:56 +00:00
2006-09-17 11:33:19 +00:00
# endif /* ENABLE_NETWORK */
2004-12-16 13:59:23 +00:00
2005-05-02 15:52:19 +00:00
DEF_CONSOLE_CMD ( ConPatch )
{
if ( argc = = 0 ) {
2008-09-30 20:39:50 +00:00
IConsoleHelp ( " Change patch variables for all clients. Usage: 'patch <name> [<value>]' " ) ;
2005-05-02 15:52:19 +00:00
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 ] ) ;
2006-06-27 21:25:53 +00:00
} else {
2008-05-30 09:23:05 +00:00
IConsoleSetPatchSetting ( argv [ 1 ] , argv [ 2 ] ) ;
2006-06-27 21:25:53 +00:00
}
2004-12-23 17:37:26 +00:00
2005-05-02 15:52:19 +00:00
return true ;
}
2004-12-13 15:07:33 +00:00
2007-04-05 12:59:57 +00:00
DEF_CONSOLE_CMD ( ConListPatches )
{
if ( argc = = 0 ) {
2008-08-11 17:15:31 +00:00
IConsoleHelp ( " List patch options. Usage: 'list_patches [<pre-filter>]' " ) ;
2007-04-05 12:59:57 +00:00
return true ;
}
2008-08-11 17:15:31 +00:00
if ( argc > 2 ) return false ;
2007-04-05 12:59:57 +00:00
2008-08-11 17:15:31 +00:00
IConsoleListPatches ( ( argc = = 2 ) ? argv [ 1 ] : NULL ) ;
2007-04-05 12:59:57 +00:00
return true ;
}
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
}
2008-06-03 18:35:58 +00:00
DEF_CONSOLE_CMD ( ConGamelogPrint )
{
GamelogPrintConsole ( ) ;
return true ;
}
2004-12-04 17:54:56 +00:00
2004-09-12 21:49:38 +00:00
# ifdef _DEBUG
/* ****************************************** */
/* debug commands and variables */
/* ****************************************** */
2007-03-07 11:47:46 +00:00
static void IConsoleDebugLibRegister ( )
2004-09-12 21:49:38 +00:00
{
2007-02-23 11:50:43 +00:00
/* debugging variables and functions */
extern bool _stdlib_con_developer ; // XXX extern in .cpp
2004-09-19 15:24:45 +00:00
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 ) ;
2006-04-22 08:45:58 +00:00
IConsoleCmdRegister ( " stopall " , ConStopAllVehicles ) ;
2005-05-02 15:52:19 +00:00
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 */
/* ****************************************** */
2007-03-07 11:47:46 +00:00
void IConsoleStdLibRegister ( )
2004-09-12 21:49:38 +00:00
{
2007-02-23 11:50:43 +00:00
/* stdlib */
extern byte _stdlib_developer ; // XXX extern in .cpp
2004-09-12 21:49:38 +00:00
2007-02-23 11:50:43 +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 ) ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
IConsoleCmdRegister ( " restart " , ConRestart ) ;
IConsoleCmdRegister ( " getseed " , ConGetSeed ) ;
2007-06-13 14:52:41 +00:00
IConsoleCmdRegister ( " getdate " , ConGetDate ) ;
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 ) ;
2007-01-03 18:06:50 +00:00
IConsoleCmdRegister ( " saveconfig " , ConSaveConfig ) ;
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 ) ;
2006-09-14 23:26:58 +00:00
IConsoleCmdRegister ( " patch " , ConPatch ) ;
2007-04-05 12:59:57 +00:00
IConsoleCmdRegister ( " list_patches " , ConListPatches ) ;
2008-06-03 18:35:58 +00:00
IConsoleCmdRegister ( " gamelog " , ConGamelogPrint ) ;
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
2006-01-25 18:40:12 +00:00
/* Network hooks; only active in network */
IConsoleCmdHookAdd ( " resetengines " , ICONSOLE_HOOK_ACCESS , ConHookNoNetwork ) ;
2005-05-02 15:52:19 +00:00
/*** Networking commands ***/
IConsoleCmdRegister ( " say " , ConSay ) ;
IConsoleCmdHookAdd ( " say " , ICONSOLE_HOOK_ACCESS , ConHookNeedNetwork ) ;
2008-09-30 20:39:50 +00:00
IConsoleCmdRegister ( " companies " , ConCompanies ) ;
IConsoleCmdHookAdd ( " companies " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleAliasRegister ( " players " , " companies " ) ;
IConsoleCmdRegister ( " say_company " , ConSayCompany ) ;
IConsoleCmdHookAdd ( " say_company " , ICONSOLE_HOOK_ACCESS , ConHookNeedNetwork ) ;
IConsoleAliasRegister ( " say_player " , " say_company %+ " ) ;
2005-05-02 15:52:19 +00:00
IConsoleCmdRegister ( " say_client " , ConSayClient ) ;
IConsoleCmdHookAdd ( " say_client " , ICONSOLE_HOOK_ACCESS , ConHookNeedNetwork ) ;
2006-01-25 18:40:12 +00:00
2005-05-02 15:52:19 +00:00
IConsoleCmdRegister ( " connect " , ConNetworkConnect ) ;
IConsoleCmdHookAdd ( " connect " , ICONSOLE_HOOK_ACCESS , ConHookClientOnly ) ;
2006-01-25 18:40:12 +00:00
IConsoleAliasRegister ( " join " , " connect %A " ) ;
2005-05-02 15:52:19 +00:00
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 ) ;
2006-01-25 18:40:12 +00:00
IConsoleCmdRegister ( " server_info " , ConServerInfo ) ;
IConsoleCmdHookAdd ( " server_info " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleAliasRegister ( " info " , " server_info " ) ;
2005-05-02 15:52:19 +00:00
IConsoleCmdRegister ( " rcon " , ConRcon ) ;
IConsoleCmdHookAdd ( " rcon " , ICONSOLE_HOOK_ACCESS , ConHookNeedNetwork ) ;
2006-01-25 18:40:12 +00:00
IConsoleCmdRegister ( " reset_company " , ConResetCompany ) ;
IConsoleCmdHookAdd ( " reset_company " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleAliasRegister ( " clean_company " , " reset_company %A " ) ;
IConsoleCmdRegister ( " kick " , ConKick ) ;
IConsoleCmdHookAdd ( " kick " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
2005-05-02 15:52:19 +00:00
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 ) ;
2006-01-25 18:40:12 +00:00
2005-05-02 15:52:19 +00:00
IConsoleCmdRegister ( " pause " , ConPauseGame ) ;
IConsoleCmdHookAdd ( " pause " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
IConsoleCmdRegister ( " unpause " , ConUnPauseGame ) ;
IConsoleCmdHookAdd ( " unpause " , ICONSOLE_HOOK_ACCESS , ConHookServerOnly ) ;
/*** Networking variables ***/
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 %+ " ) ;
2008-05-30 09:23:05 +00:00
IConsoleAliasRegister ( " net_frame_freq " , " patch frame_freq %+ " ) ;
IConsoleAliasRegister ( " net_sync_freq " , " patch sync_freq %+ " ) ;
IConsoleAliasRegister ( " server_pw " , " patch server_password %+ " ) ;
IConsoleAliasRegister ( " server_password " , " patch server_password %+ " ) ;
IConsoleAliasRegister ( " rcon_pw " , " patch rcon_password %+ " ) ;
IConsoleAliasRegister ( " rcon_password " , " patch rcon_password %+ " ) ;
2008-09-30 20:39:50 +00:00
IConsoleAliasRegister ( " name " , " patch client_name %+ " ) ;
2008-05-30 09:23:05 +00:00
IConsoleAliasRegister ( " server_name " , " patch server_name %+ " ) ;
IConsoleAliasRegister ( " server_port " , " patch server_port %+ " ) ;
IConsoleAliasRegister ( " server_ip " , " patch server_bind_ip %+ " ) ;
IConsoleAliasRegister ( " server_bind_ip " , " patch server_bind_ip %+ " ) ;
IConsoleAliasRegister ( " server_ip_bind " , " patch server_bind_ip %+ " ) ;
IConsoleAliasRegister ( " server_bind " , " patch server_bind_ip %+ " ) ;
IConsoleAliasRegister ( " server_advertise " , " patch server_advertise %+ " ) ;
IConsoleAliasRegister ( " max_clients " , " patch max_clients %+ " ) ;
IConsoleAliasRegister ( " max_companies " , " patch max_companies %+ " ) ;
IConsoleAliasRegister ( " max_spectators " , " patch max_spectators %+ " ) ;
IConsoleAliasRegister ( " max_join_time " , " patch max_join_time %+ " ) ;
IConsoleAliasRegister ( " pause_on_join " , " patch pause_on_join %+ " ) ;
IConsoleAliasRegister ( " autoclean_companies " , " patch autoclean_companies %+ " ) ;
IConsoleAliasRegister ( " autoclean_protected " , " patch autoclean_protected %+ " ) ;
IConsoleAliasRegister ( " autoclean_unprotected " , " patch autoclean_unprotected %+ " ) ;
IConsoleAliasRegister ( " restart_game_year " , " patch restart_game_year %+ " ) ;
2008-09-30 20:39:50 +00:00
IConsoleAliasRegister ( " min_players " , " patch min_clients %+ " ) ;
2008-05-30 09:23:05 +00:00
IConsoleAliasRegister ( " reload_cfg " , " patch reload_cfg %+ " ) ;
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
}