(svn r248) -Feature: console script files "exec myscript.file"

-Feature: console logging (of debug messages with *developer = 2 and debug_level #) to text-files "script test.txt"
-Feature: server and client are auto-executing "on_server.scr" and "on_client.scr" scripts
This commit is contained in:
darkvater 2004-09-14 16:10:20 +00:00
parent 6d55489368
commit d48ce392b2
5 changed files with 134 additions and 41 deletions

View File

@ -27,6 +27,7 @@ static byte _icursor_counter;
// ** stdlib ** // // ** stdlib ** //
byte _stdlib_developer=1; byte _stdlib_developer=1;
bool _stdlib_con_developer=false; bool _stdlib_con_developer=false;
FILE * _iconsole_output_file;
// ** main console cmd buffer ** // sign_de: especialy for Celestar :D // ** main console cmd buffer ** // sign_de: especialy for Celestar :D
static byte* _iconsole_cmdbuffer[20]; static byte* _iconsole_cmdbuffer[20];
@ -186,6 +187,7 @@ void IConsoleInit()
#if defined(WITH_REV) #if defined(WITH_REV)
extern char _openttd_revision[]; extern char _openttd_revision[];
#endif #endif
_iconsole_output_file = NULL;
_iconsole_color_default = 1; _iconsole_color_default = 1;
_iconsole_color_error = 3; _iconsole_color_error = 3;
_iconsole_color_warning = 13; _iconsole_color_warning = 13;
@ -231,6 +233,7 @@ void IConsoleFree()
{ {
_iconsole_inited=false; _iconsole_inited=false;
IConsoleClear(); IConsoleClear();
if (_iconsole_output_file!=NULL) fclose(_iconsole_output_file);
} }
void IConsoleResize() void IConsoleResize()
@ -344,9 +347,19 @@ void CDECL IConsolePrintF(byte color_code, const char *s, ...)
{ {
va_list va; va_list va;
char buf[1024]; char buf[1024];
int len;
va_start(va, s); va_start(va, s);
vsprintf(buf, s, va); len = vsprintf(buf, s, va);
va_end(va); va_end(va);
if (_iconsole_output_file!=NULL) {
// if there is an console output file ... also print it there
fwrite((void *) &buf, len, 1, _iconsole_output_file);
buf[1023]='\n';
fwrite((void *)&buf[1023], 1, 1,_iconsole_output_file);
}
IConsolePrint(color_code, (byte *) &buf); IConsolePrint(color_code, (byte *) &buf);
} }

View File

@ -10,11 +10,20 @@
# define ENABLE_NETWORK # define ENABLE_NETWORK
#endif #endif
// ** scriptfile handling ** //
static FILE * _script_file;
static bool _script_running;
// ** console command / variable defines ** // // ** console command / variable defines ** //
#define DEF_CONSOLE_CMD(yyyy) static _iconsole_var * yyyy(byte argc, byte* argv[], byte argt[]) #define DEF_CONSOLE_CMD(yyyy) static _iconsole_var * yyyy(byte argc, byte* argv[], byte argt[])
#define DEF_CONSOLE_CMD_HOOK(yyyy) static bool yyyy(_iconsole_cmd * hookcmd) #define DEF_CONSOLE_CMD_HOOK(yyyy) static bool yyyy(_iconsole_cmd * hookcmd)
#define DEF_CONSOLE_VAR_HOOK(yyyy) static bool yyyy(_iconsole_var * hookvar) #define DEF_CONSOLE_VAR_HOOK(yyyy) static bool yyyy(_iconsole_var * hookvar)
// ** supporting functions ** //
static int32 GetArgumentInteger(byte *arg) static int32 GetArgumentInteger(byte *arg)
{ {
int32 result; int32 result;
@ -125,10 +134,68 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
#endif #endif
/* ******************************** */
/* script file console commands */
/* ******************************** */
DEF_CONSOLE_CMD(ConExec)
{
char cmd[1024];
bool doerror;
if (argc<2) return NULL;
doerror = true;
_script_file = fopen(argv[1],"rb");
if (_script_file == NULL) {
if (argc>2) if (atoi(argv[2])==0) doerror=false;
if (doerror) IConsoleError("script file not found");
return NULL;
}
_script_running = true;
while (!feof(_script_file) && _script_running) {
fgets((char *)&cmd, 1024, _script_file);
IConsoleCmdExec((byte *) &cmd);
}
_script_running = false;
fclose(_script_file);
return NULL;
}
DEF_CONSOLE_CMD(ConReturn)
{
_script_running = false;
return NULL;
}
/* **************************** */ /* **************************** */
/* default console commands */ /* default console commands */
/* **************************** */ /* **************************** */
DEF_CONSOLE_CMD(ConScript)
{
extern FILE* _iconsole_output_file;
if (_iconsole_output_file!=NULL) {
if (argc<2) return NULL;
IConsolePrintF(_iconsole_color_default,"file output complete");
fclose(_iconsole_output_file);
} else {
IConsolePrintF(_iconsole_color_default,"file output started to: %s",argv[1]);
_iconsole_output_file = fopen(argv[1],"ab");
if (_iconsole_output_file == NULL) IConsoleError("could not open file");
}
return NULL;
}
DEF_CONSOLE_CMD(ConEcho) DEF_CONSOLE_CMD(ConEcho)
{ {
if (argc<2) return NULL; if (argc<2) return NULL;
@ -335,6 +402,10 @@ DEF_CONSOLE_CMD(ConListDumpVariables)
void IConsoleDebugLibRegister() void IConsoleDebugLibRegister()
{ {
// stdlib
extern bool _stdlib_con_developer;
IConsoleVarRegister("con_developer",(void *) &_stdlib_con_developer,ICONSOLE_VAR_BOOLEAN);
IConsoleVarMemRegister("temp_bool",ICONSOLE_VAR_BOOLEAN); IConsoleVarMemRegister("temp_bool",ICONSOLE_VAR_BOOLEAN);
IConsoleVarMemRegister("temp_int16",ICONSOLE_VAR_INT16); IConsoleVarMemRegister("temp_int16",ICONSOLE_VAR_INT16);
IConsoleVarMemRegister("temp_int32",ICONSOLE_VAR_INT32); IConsoleVarMemRegister("temp_int32",ICONSOLE_VAR_INT32);
@ -356,7 +427,6 @@ void IConsoleStdLibRegister()
{ {
// stdlib // stdlib
extern byte _stdlib_developer; extern byte _stdlib_developer;
extern bool _stdlib_con_developer;
#ifdef _DEBUG #ifdef _DEBUG
IConsoleDebugLibRegister(); IConsoleDebugLibRegister();
@ -373,6 +443,7 @@ void IConsoleStdLibRegister()
IConsoleCmdRegister("dump_vars",ConListDumpVariables); IConsoleCmdRegister("dump_vars",ConListDumpVariables);
IConsoleCmdRegister("echo",ConEcho); IConsoleCmdRegister("echo",ConEcho);
IConsoleCmdRegister("echoc",ConEchoC); IConsoleCmdRegister("echoc",ConEchoC);
IConsoleCmdRegister("exec",ConExec);
IConsoleCmdRegister("exit",ConExit); IConsoleCmdRegister("exit",ConExit);
IConsoleCmdRegister("help",ConHelp); IConsoleCmdRegister("help",ConHelp);
IConsoleCmdRegister("info_cmd",ConInfoCmd); IConsoleCmdRegister("info_cmd",ConInfoCmd);
@ -385,11 +456,12 @@ void IConsoleStdLibRegister()
IConsoleCmdRegister("random",ConRandom); IConsoleCmdRegister("random",ConRandom);
IConsoleCmdRegister("resetengines",ConResetEngines); IConsoleCmdRegister("resetengines",ConResetEngines);
IConsoleCmdHook("resetengines",ICONSOLE_HOOK_ACCESS,ConCmdHookNoNetwork); IConsoleCmdHook("resetengines",ICONSOLE_HOOK_ACCESS,ConCmdHookNoNetwork);
IConsoleCmdRegister("return",ConReturn);
IConsoleCmdRegister("screenshot",ConScreenShot); IConsoleCmdRegister("screenshot",ConScreenShot);
IConsoleCmdRegister("script",ConScript);
IConsoleCmdRegister("scrollto",ConScrollToTile); IConsoleCmdRegister("scrollto",ConScrollToTile);
// variables [please add them alphabeticaly] // variables [please add them alphabeticaly]
IConsoleVarRegister("con_developer",(void *) &_stdlib_con_developer,ICONSOLE_VAR_BOOLEAN);
IConsoleVarRegister("developer",(void *) &_stdlib_developer,ICONSOLE_VAR_BYTE); IConsoleVarRegister("developer",(void *) &_stdlib_developer,ICONSOLE_VAR_BYTE);
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK
IConsoleVarRegister("net_client_timeout",&_network_client_timeout,ICONSOLE_VAR_UINT16); IConsoleVarRegister("net_client_timeout",&_network_client_timeout,ICONSOLE_VAR_UINT16);

View File

@ -1730,6 +1730,7 @@ bool NetworkCoreConnectGame(const byte* b, unsigned short port)
_networking = NetworkConnect(b, port); _networking = NetworkConnect(b, port);
if (_networking) { if (_networking) {
NetworkLobbyShutdown(); NetworkLobbyShutdown();
IConsoleCmdExec("exec scripts/on_client.scr 0");
} else { } else {
if (_networking_override) if (_networking_override)
NetworkLobbyShutdown(); NetworkLobbyShutdown();
@ -1760,6 +1761,8 @@ bool NetworkCoreStartGame()
_networking = true; _networking = true;
NetworkGameFillDefaults(); // clears the network game info NetworkGameFillDefaults(); // clears the network game info
_network_game.players_on++; // the serverplayer is online _network_game.players_on++; // the serverplayer is online
// execute server initialization script
IConsoleCmdExec("exec scripts/on_server.scr 0");
return true; return true;
} }

2
scripts/on_client.scr Normal file
View File

@ -0,0 +1,2 @@
echo "Setting default network client settings..."
*net_ready_ahead = 1

3
scripts/on_server.scr Normal file
View File

@ -0,0 +1,3 @@
echo "Setting default network server settings..."
*net_sync_freq = 4
*net_client_timeout = 300;