Skip to content

Commit

Permalink
use log file instead of stdout
Browse files Browse the repository at this point in the history
git-svn-id: https://sauerbraten.svn.sourceforge.net/svnroot/sauerbraten@3425 ac1f7847-fce6-4368-a212-70e9bdee79d4
  • Loading branch information
eihrul committed Feb 12, 2011
1 parent bcd0448 commit 1be46b5
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 44 deletions.
16 changes: 8 additions & 8 deletions docs/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ <h1>Cube 2: Sauerbraten - Configuration</h1>
<a href="#_minus_ks"><tt>-kS</tt></a>
</li>
<li>
<a href="#_minus_gn"><tt>-gN</tt></a>
</li>
<li>
<a href="#_minus_ls"><tt>-lS</tt></a>
</li>
<li>
Expand Down Expand Up @@ -107,9 +110,6 @@ <h1>Cube 2: Sauerbraten - Configuration</h1>
<li>
<a href="#_minus_on"><tt>-oN</tt></a>
</li>
<li>
<a href="#_minus_gn"><tt>-gN</tt></a>
</li>
</ul>
</li>
<li>
Expand Down Expand Up @@ -714,6 +714,11 @@ <h2 id="command_line_options">Command Line Options</h2>
directory.
</p>

<pre id="_minus_gn">-gS</pre>
<p>
Sets the log file to S. All console output is written to the log file.
</p>

<pre id="_minus_ls">-lS</pre>
<p>
Loads map S on startup (default: base/metl4).
Expand Down Expand Up @@ -773,11 +778,6 @@ <h2 id="command_line_options">Command Line Options</h2>
Sets the openness of the server to N. N=1 disables mastermodes 2 (locked) and 3 (private), while N=0 (default) enables all mastermodes.
</p>

<pre id="_minus_gn">-gN</pre>
<p>
Sets the maximum amount of bots a master can add to the server. Set to 0 to disable bots. The default is 8.
</p>

<h2 id="console_commands">Console Commands</h2>

<pre id="bind">bind K A</pre>
Expand Down
1 change: 1 addition & 0 deletions docs/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ <h1>Cube 2: Sauerbraten - Change History</h1>
<ul>
<li>config files and maps are now saved to the My Games directory on Windows</li>
<li>server now loads entities directly from maps if available</li>
<li>added "-g" command-line option which sets which file console output is logged to</li>
<li>added simplified IK for pitch animation</li>
<li>added support for applying transforms to bone tags on skeletal models</li>
<li>use premultiplied-alpha for grass textures to avoid darkening around grass outlines</li>
Expand Down
2 changes: 1 addition & 1 deletion rpg.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bin\rpg.exe -q"$HOME\My Games\Sauerbraten" -r %*
bin\rpg.exe -q"$HOME\My Games\Sauerbraten" -grpg-log.txt -r %*

2 changes: 1 addition & 1 deletion sauerbraten.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
start bin\sauerbraten.exe "-q$HOME\My Games\Sauerbraten" -r %*
start bin\sauerbraten.exe "-q$HOME\My Games\Sauerbraten" -glog.txt -r %*
2 changes: 1 addition & 1 deletion server.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bin\sauerbraten.exe "-q$HOME\My Games\Sauerbraten" -d %*
bin\sauerbraten.exe "-q$HOME\My Games\Sauerbraten" -gserver-log.txt -d %*
2 changes: 1 addition & 1 deletion src/engine/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void conoutfv(int type, const char *fmt, va_list args)
vformatstring(buf, fmt, args, sizeof(buf));
conline(type, buf);
filtertext(buf, buf);
puts(buf);
logoutf("%s", buf);
}

void conoutf(const char *fmt, ...)
Expand Down
36 changes: 18 additions & 18 deletions src/engine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void cleanup()
extern void clear_console(); clear_console();
extern void clear_mdls(); clear_mdls();
extern void clear_sound(); clear_sound();
closelogfile();
SDL_Quit();
}

Expand Down Expand Up @@ -967,13 +968,11 @@ int main(int argc, char **argv)
#endif
#endif

setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
setlogfile(NULL);

int dedicated = 0;
char *load = NULL, *initscript = NULL;

#define log(s) puts("init: " s)

initing = INIT_RESET;
for(int i = 1; i<argc; i++)
{
Expand All @@ -982,15 +981,16 @@ int main(int argc, char **argv)
case 'q':
{
const char *dir = sethomedir(&argv[i][2]);
if(dir) printf("Using home directory: %s\n", dir);
if(dir) logoutf("Using home directory: %s", dir);
break;
}
case 'k':
{
const char *dir = addpackagedir(&argv[i][2]);
if(dir) printf("Adding package directory: %s\n", dir);
if(dir) logoutf("Adding package directory: %s", dir);
break;
}
case 'g': logoutf("Setting log file", &argv[i][2]); setlogfile(&argv[i][2]); break;
case 'r': execfile(argv[i][2] ? &argv[i][2] : "init.cfg", false); restoredinits = true; break;
case 'd': dedicated = atoi(&argv[i][2]); if(dedicated<=0) dedicated = 2; break;
case 'w': scr_w = clamp(atoi(&argv[i][2]), SCR_MINW, SCR_MAXW); if(!findarg(argc, argv, "-h")) scr_h = -1; break;
Expand Down Expand Up @@ -1027,7 +1027,7 @@ int main(int argc, char **argv)

if(dedicated <= 1)
{
log("sdl");
logoutf("init: sdl");

int par = 0;
#ifdef _DEBUG
Expand All @@ -1040,18 +1040,18 @@ int main(int argc, char **argv)
if(SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO|SDL_INIT_AUDIO|par)<0) fatal("Unable to initialize SDL: %s", SDL_GetError());
}

log("net");
logoutf("init: net");
if(enet_initialize()<0) fatal("Unable to initialise network module");
atexit(enet_deinitialize);
enet_time_set(0);

log("game");
logoutf("init: game");
game::parseoptions(gameargs);
initserver(dedicated>0, dedicated>1); // never returns if dedicated
ASSERT(dedicated <= 1);
game::initclient();

log("video: mode");
logoutf("init: video: mode");
const SDL_VideoInfo *video = SDL_GetVideoInfo();
if(video)
{
Expand All @@ -1061,18 +1061,18 @@ int main(int argc, char **argv)
int usedcolorbits = 0, useddepthbits = 0, usedfsaa = 0;
setupscreen(usedcolorbits, useddepthbits, usedfsaa);

log("video: misc");
logoutf("init: video: misc");
SDL_WM_SetCaption("Cube 2: Sauerbraten", NULL);
keyrepeat(false);
SDL_ShowCursor(0);

log("gl");
logoutf("init: gl");
gl_checkextensions();
gl_init(scr_w, scr_h, usedcolorbits, useddepthbits, usedfsaa);
notexture = textureload("packages/textures/notexture.png");
if(!notexture) fatal("could not find core textures");

log("console");
logoutf("init: console");
identflags &= ~IDF_PERSIST;
if(!execfile("data/stdlib.cfg", false)) fatal("cannot find data files (you are running from the wrong folder, try .bat file in the main folder)"); // this is the first file we load.
if(!execfile("data/font.cfg", false)) fatal("cannot find font definitions");
Expand All @@ -1081,19 +1081,19 @@ int main(int argc, char **argv)
inbetweenframes = true;
renderbackground("initializing...");

log("gl: effects");
logoutf("init: gl: effects");
loadshaders();
particleinit();
initdecals();

log("world");
logoutf("init: world");
camera1 = player = game::iterdynents(0);
emptymap(0, true, NULL, false);

log("sound");
logoutf("init: sound");
initsound();

log("cfg");
logoutf("init: cfg");
execfile("data/keymap.cfg");
execfile("data/stdedit.cfg");
execfile("data/menus.cfg");
Expand Down Expand Up @@ -1129,14 +1129,14 @@ int main(int argc, char **argv)

if(load)
{
log("localconnect");
logoutf("init: localconnect");
//localconnect();
game::changemap(load);
}

if(initscript) execute(initscript);

log("mainloop");
logoutf("init: mainloop");

initmumble();
resetfpshistory();
Expand Down
69 changes: 56 additions & 13 deletions src/engine/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,55 @@

#include "engine.h"

static FILE *logfile = NULL;

void closelogfile()
{
if(logfile)
{
fclose(logfile);
logfile = NULL;
}
}

void setlogfile(const char *fname)
{
closelogfile();
if(fname && fname[0])
{
fname = findfile(fname, "w");
if(fname) logfile = fopen(fname, "w");
}
setvbuf(logfile ? logfile : stdout, NULL, _IOLBF, BUFSIZ);
}

void logoutfv(const char *fmt, va_list args)
{
vfprintf(logfile ? logfile : stdout, fmt, args);
fputc('\n', logfile ? logfile : stdout);
}

void logoutf(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
logoutfv(fmt, args);
va_end(args);
}

#ifdef STANDALONE
void fatal(const char *s, ...)
void fatal(const char *fmt, ...)
{
void cleanupserver();
cleanupserver();
defvformatstring(msg,s,s);
printf("servererror: %s\n", msg);
va_list args;
va_start(args, fmt);
logoutfv(fmt, args);
fprintf(stderr, "server error: ");
vfprintf(stderr, fmt, args);
fputc('\n', stderr);
va_end(args);
closelogfile();
exit(EXIT_FAILURE);
}

Expand All @@ -18,7 +60,7 @@ void conoutfv(int type, const char *fmt, va_list args)
string sf, sp;
vformatstring(sf, fmt, args);
filtertext(sp, sf);
puts(sp);
logoutf("%s", sp);
}

void conoutf(const char *fmt, ...)
Expand Down Expand Up @@ -406,7 +448,7 @@ ENetSocket connectmaster()
if(masteraddress.host == ENET_HOST_ANY)
{
#ifdef STANDALONE
printf("looking up %s...\n", mastername);
logoutf("looking up %s...", mastername);
#endif
masteraddress.port = masterport;
if(!resolverwait(mastername, &masteraddress)) return ENET_SOCKET_NULL;
Expand All @@ -420,7 +462,7 @@ ENetSocket connectmaster()
if(sock == ENET_SOCKET_NULL || connectwithtimeout(sock, mastername, masteraddress) < 0)
{
#ifdef STANDALONE
printf(sock==ENET_SOCKET_NULL ? "could not open socket\n" : "could not connect\n");
logoutf(sock==ENET_SOCKET_NULL ? "could not open socket" : "could not connect");
#endif
return ENET_SOCKET_NULL;
}
Expand Down Expand Up @@ -616,7 +658,7 @@ void serverslice(bool dedicated, uint timeout) // main server update, called f
if(totalmillis-laststatus>60*1000) // display bandwidth stats, useful for server ops
{
laststatus = totalmillis;
if(nonlocalclients || serverhost->totalSentData || serverhost->totalReceivedData) printf("status: %d remote clients, %.1f send, %.1f rec (K/sec)\n", nonlocalclients, serverhost->totalSentData/60.0f/1024, serverhost->totalReceivedData/60.0f/1024);
if(nonlocalclients || serverhost->totalSentData || serverhost->totalReceivedData) logoutf("status: %d remote clients, %.1f send, %.1f rec (K/sec)", nonlocalclients, serverhost->totalSentData/60.0f/1024, serverhost->totalReceivedData/60.0f/1024);
serverhost->totalSentData = serverhost->totalReceivedData = 0;
}

Expand All @@ -639,7 +681,7 @@ void serverslice(bool dedicated, uint timeout) // main server update, called f
c.peer->data = &c;
char hn[1024];
copystring(c.hostname, (enet_address_get_host_ip(&c.peer->address, hn, sizeof(hn))==0) ? hn : "unknown");
printf("client connected (%s)\n", c.hostname);
logoutf("client connected (%s)", c.hostname);
int reason = server::clientconnect(c.num, c.peer->address.host);
if(!reason) nonlocalclients++;
else disconnect_client(c.num, reason);
Expand All @@ -656,7 +698,7 @@ void serverslice(bool dedicated, uint timeout) // main server update, called f
{
client *c = (client *)event.peer->data;
if(!c) break;
printf("disconnected client (%s)\n", c->hostname);
logoutf("disconnected client (%s)", c->hostname);
server::clientdisconnect(c->num);
nonlocalclients--;
c->type = ST_EMPTY;
Expand Down Expand Up @@ -711,7 +753,7 @@ void rundedicatedserver()
#ifdef WIN32
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
#endif
printf("dedicated server started, waiting for clients...\nCtrl-C to exit\n\n");
logoutf("dedicated server started, waiting for clients...");
for(;;) serverslice(true, 5);
}

Expand Down Expand Up @@ -817,8 +859,9 @@ bool serveroption(char *opt)
case 'j': setvar("serverport", atoi(opt+2)); return true;
case 'm': setsvar("mastername", opt+2); setvar("updatemaster", mastername[0] ? 1 : 0); return true;
#ifdef STANDALONE
case 'q': printf("Using home directory: %s\n", opt+2); sethomedir(opt+2); return true;
case 'k': printf("Adding package directory: %s\n", opt+2); addpackagedir(opt+2); return true;
case 'q': logoutf("Using home directory: %s", opt); sethomedir(opt+2); return true;
case 'k': logoutf("Adding package directory: %s", opt); addpackagedir(opt+2); return true;
case 'g': logoutf("Setting log file: %s", opt); setlogfile(opt+2); return true;
#endif
default: return false;
}
Expand All @@ -829,7 +872,7 @@ vector<const char *> gameargs;
#ifdef STANDALONE
int main(int argc, char* argv[])
{
setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
setlogfile(NULL);
if(enet_initialize()<0) fatal("Unable to initialise network module");
atexit(enet_deinitialize);
enet_time_set(0);
Expand Down
1 change: 0 additions & 1 deletion src/fpsgame/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ namespace server
case 'y': setsvar("serverpass", &arg[2]); return true;
case 'p': setsvar("adminpass", &arg[2]); return true;
case 'o': setvar("publicserver", atoi(&arg[2])); return true;
case 'g': setvar("serverbotlimit", atoi(&arg[2])); return true;
}
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions src/shared/iengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ extern void conoutf(const char *s, ...);
extern void conoutf(int type, const char *s, ...);
extern void conoutfv(int type, const char *fmt, va_list args);

extern void setlogfile(const char *fname);
extern void closelogfile();
extern void logoutfv(const char *fmt, va_list args);
extern void logoutf(const char *fmt, ...);

// menus
extern vec menuinfrontofplayer();
extern void newgui(char *name, char *contents, char *header = NULL);
Expand Down

0 comments on commit 1be46b5

Please sign in to comment.