Skip to content

Commit

Permalink
Updates to configuration and documentation on such
Browse files Browse the repository at this point in the history
Man page and doc/config.md brought up to date. Config options for specifying a
log file and a specifying that logging should also go to stderr are added as
config/command line options.
  • Loading branch information
Chris Harding committed Sep 15, 2014
1 parent 4e9cbde commit 05c35ad
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ install: all
cp -r tileset $(DESTDIR)
mkdir -p $(MANDIR)
cp doc/iiag.6 $(MANDIR)
gzip $(MANDIR)/iiag.6
gzip -f $(MANDIR)/iiag.6

-include $(CLIENT_DEPS) $(SERVER_DEPS)
52 changes: 37 additions & 15 deletions doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,52 @@ Field Types
String | A string value that is terminated with an Space. Note an equal sign also terminates the string. Escape characters (the backslash `\`) can be used to allow a space or equal sign to exist in the string.
Boolean | Either `true` or `false`. If neither, it defaults to `false` and logs an error.
Integer | A decimal numerical value that represents an integer.
Control | A value representing a key to press on the keyboard in order to utilize a control in game. The format is usually `a` for the A-key, `A` for shift+A-key, and so on. Digits are used for literial keycode values. The special values `%left%`, `%right%`, `%up%`, and `%down%` can be used to represent the arrow-keys.
Control | A value representing a key to press on the keyboard in order to utilize a control in game. The format is dependent on the tileset type, which influences the input backend. For ncurses backends, the literal key name is used when possible (e.g. 'a' for the a-key, 'A' for shift-a), and name strings like 'left' for the left arrow key.

Fields
------

Field Name | Type | Description
------------------|---------|-------------
lua-init | string | Specifies the initial lua file to run, like `-i`.
server-ip | string | The IP address of the server to connect to. Unlike `-n`, does nothing unless multiplayer is set.
log-file | string | Specifies the path to the file to log to, like `-l`.
tileset-file | string | The path to the file containing the tileset, like `-t`.
show-all | boolean | Specifies whether everything is shown to the player or not, like `-s`.
forget-walls | boolean | Specifies whether wall-forgetting is enabled or not, like `-f`.
all-alone | boolean | Specifies whether all-alone mode is enabled, like `-l`.
all-alone | boolean | Specifies whether all-alone mode is enabled, like `-a`.
god-mode | boolean | Specifies whether the player may avoid damage during the game, like `-g`.
real-time | boolean | Specifies whether the game should be run in real-time mode, like `-r`.
multiplayer | boolean | Specifies whether the game should try to connect to a remote server, a side effect of `-n` normally.
log-stderr | boolean | Specifies whether logging should be done additionally to stderr or not, like `-e`.
port | integer | The port to connect to on the multiplayer server.
log-level | integer | Specifies the verbosity of the log. Valid values are: 0=ALL (no filtering), 1=DEBUG, 2=INFO, 3=NOTICE, 4=WARNING, 5=ERROR. The setting is inclusive.
throw-anim-delay | integer | The delay between 'frames' of the throwing animation. 0 indicates the lack of animation
ctrl-up | control | How the player moves up.
ctrl-down | control | How the player moves down.
ctrl-left | control | How the player moves left.
ctrl-right | control | How the player moves right.
ctrl-uleft | control | How the player moves up-left.
ctrl-uright | control | How the player moves up-right.
ctrl-dleft | control | How the player moves down-left.
ctrl-dright | control | How the player moves down-right.
ctrl-scrl-center | control | What key centers the player's scrolling on the player.
ctrl-scrl-up | control | How the player scrolls up.
ctrl-scrl-down | control | How the player scrolls down.
ctrl-scrl-left | control | How the player scrolls left.
ctrl-scrl-right | control | How the player scrolls right.
move-up | control | How the player moves up.
move-down | control | How the player moves down.
move-left | control | How the player moves left.
move-right | control | How the player moves right.
move-uleft | control | How the player moves up-left.
move-uright | control | How the player moves up-right.
move-dleft | control | How the player moves down-left.
move-dright | control | How the player moves down-right.
scroll-center | control | What key centers the player's scrolling on the player.
scroll-up | control | How the player scrolls up.
scroll-down | control | How the player scrolls down.
scroll-left | control | How the player scrolls left.
scroll-right | control | How the player scrolls right.
inventory | control | How the player looks at their inventory.
equipment | control | How the player looks at their equipped items.
pickup | control | How the player picks up an item.
drop | control | How the player drops an item.
consume | control | How the player consumes (eats or quaffs) an item.
equip | control | How the player equips (wears or weilds) an item.
throw | control | How the player throws an item.
stance-neutral | control | How the player switchs their stance to neutral.
stance-defend | control | How the player switchs their stance to defensive.
stance-attack | control | How the player switchs their stance to attacking.
idle | control | How to ignore a turn.
disp-ctrl | control | How to display the control configuration menu.
command | control | How to display the command prompt interface.


19 changes: 14 additions & 5 deletions doc/iiag.6
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,20 @@ the mighty land fiish. Or something like that. Like other terminal games,
creatures and other objects are represented as symbols when played in the
terminal, and will eventually support other graphical environments as
well.

.PP
It is not currently possible to win the game.
.SH OPTIONS
.TP
\fB\-a\fR
turn on lonely mode, where there are no monsters. (debugging)
.TP
\fB\-c\fR FILE
play the game using the specified configuration file
.TP
\fB\-e\fR
log errors to stderr as well as the log file
.TP
\fB\-f\fR
turn on wall forgetting
.TP
Expand All @@ -45,8 +54,11 @@ display the useful help text
\fB\-i\fR FILE
run with a specific lua init file
.TP
\fB\-l\fR
turn on lonely mode, where there are no monsters. (debugging)
\fB\-l\fR FILE
specifies the file to log to
.TP
\fB\-L\fR LOG-LEVEL
specifies the log level to use
.TP
\fB\-n\fR ADDRESS
connect to server for multiplayer
Expand All @@ -59,9 +71,6 @@ show everything
.TP
\fB\-t\fR FILE
specify the tileset to use

.PP
It is not currently possible to win the game.
.SH AUTHORS
Chris Harding, Austin Lund, Eric Richter, Alex Macri, Adam "Baha" Kimball, et. al.
.SH SEE ALSO
Expand Down
36 changes: 33 additions & 3 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ config_t config = {
NULL, // cfg_file
"script/init.lua", // lua_init

// log_file
#ifdef SERVER
"server.log",
#else
"iiag.log",
#endif

// tileset_file
// The default tileset changes based on what is supported
// TODO unicode support should probably be detected at runtime
#ifdef WITH_NCURSES
Expand All @@ -34,6 +42,15 @@ config_t config = {
0, // real_time
0, // multiplayer
LOG_INFO, // log_level

// log_stderr
// The server by default also logs to stderr, otherwise not
#ifdef SERVER
1,
#else
0,
#endif

20, // throw_anim_delay
};

Expand All @@ -52,12 +69,15 @@ struct field {
static const struct field cfg_fields[] = {
{ STRING, "lua-init", &config.lua_init },
{ STRING, "server-ip", &config.ip },
{ STRING, "log-file", &config.log_file },
{ STRING, "tileset-file", &config.tileset_file },
{ BOOLEAN, "show-all", &config.show_all },
{ BOOLEAN, "forget-walls", &config.forget_walls },
{ BOOLEAN, "all-alone", &config.all_alone },
{ BOOLEAN, "god-mode", &config.god_mode },
{ BOOLEAN, "real-time", &config.real_time },
{ BOOLEAN, "multiplayer", &config.multiplayer },
{ BOOLEAN, "log-stderr", &config.log_stderr },
{ INTEGER, "log-level", &config.log_level },
{ INTEGER, "throw-anim-delay", &config.throw_anim_delay },
{ INTEGER, "port", &config.port },
Expand Down Expand Up @@ -255,8 +275,12 @@ static void print_help()
{
fprintf(stderr,
"\noptions:\n"
" -a\n"
" Turn on all alone mode, for debugging purposes.\n"
" -c [config file]\n"
" Specify the configuration file to use (- for stdin).\n"
" -e\n"
" Log errors to stderr as well as the log file.\n"
" -f\n"
" Turn on wall forgetting.\n"
" -g\n"
Expand All @@ -265,8 +289,8 @@ static void print_help()
" Display this useful information.\n"
" -i [lua init file]\n"
" The initial lua script to run.\n"
" -l\n"
" Turn on all alone mode, for debugging purposes.\n"
" -l [log file]\n"
" Set the log file to use.\n"
" -L [log level]\n"
" Set the logging level.\n"
" Supported log levels:\n"
Expand Down Expand Up @@ -312,7 +336,7 @@ void init_config(int argc, char ** argv)
case 'f':
config.forget_walls = 1;
break;
case 'l':
case 'a':
config.all_alone = 1;
break;
case 'g':
Expand All @@ -321,6 +345,9 @@ void init_config(int argc, char ** argv)
case 'r':
config.real_time = 1;
break;
case 'e':
config.log_stderr = 1;
break;
#ifndef SERVER
case 'n':
config.multiplayer = 1;
Expand All @@ -330,6 +357,9 @@ void init_config(int argc, char ** argv)

break;
#endif
case 'l':
config.log_file = argv[++i];
break;
case 'L':
config.log_level = (log_level_t) atoi(argv[++i]);
break;
Expand Down
2 changes: 2 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
typedef struct config {
const char * cfg_file;
const char * lua_init;
const char * log_file;
const char * tileset_file;
const char * ip;
int port;
Expand All @@ -21,6 +22,7 @@ typedef struct config {
int real_time;
int multiplayer;
log_level_t log_level;
int log_stderr;
int throw_anim_delay;
} config_t;

Expand Down
25 changes: 9 additions & 16 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
#include "introspection.h"
#include "config.h"

#ifdef SERVER
const char * log_file = "server.log";
#else
const char * log_file = "iiag.log";
#endif

static clock_t sclock;

static char * level_names[] = {
Expand All @@ -27,7 +21,6 @@ static char * level_names[] = {
"ERROR"
};


void wrlog(log_level_t loglevel, const char * fmt, ...)
{
#ifdef WITH_INTROSPECTION
Expand All @@ -45,7 +38,7 @@ void wrlog(log_level_t loglevel, const char * fmt, ...)
if(loglevel < config.log_level) return;

if (logf == NULL) {
logf = fopen(log_file, "a");
logf = fopen(config.log_file, "a");
if (logf == NULL) return; // TODO do something more useful here?

fprintf(logf, "===============================================================================\n");
Expand All @@ -72,16 +65,16 @@ void wrlog(log_level_t loglevel, const char * fmt, ...)
fflush(logf);
va_end(vl);

// Also write to stdout on servers
#ifdef SERVER
va_start(vl, fmt);
// possibly also write to stderr
if (config.log_stderr) {
va_start(vl, fmt);

HEADER(stderr);
vfprintf(stderr, fmt, vl);
fputc('\n', stderr);
HEADER(stderr);
vfprintf(stderr, fmt, vl);
fputc('\n', stderr);

va_end(vl);
#endif
va_end(vl);
}
}

void start_timer(void)
Expand Down

0 comments on commit 05c35ad

Please sign in to comment.