forked from github/server
control log level from command line (with -l, like -v)
make newplayer.lua use the autoseed module, eliminate duplication seeding new players is broken Conflicts: src/gmtool.c src/main.c src/util/log.c src/util/log.h
This commit is contained in:
parent
c31f543718
commit
eebdcf5d93
2
crypto
2
crypto
|
@ -1 +1 @@
|
|||
Subproject commit f0013933852154eccc78536dd813774df5ee7f5d
|
||||
Subproject commit 913358a8d7d961ffc35b238c744ca6ce823ffdd9
|
|
@ -1,32 +1,13 @@
|
|||
dofile("config.lua")
|
||||
p = require("populate")
|
||||
|
||||
local function read_players()
|
||||
-- return {{ email = "noreply@mailinator.com", race = "dwarf", lang = "de" }}
|
||||
local players = {}
|
||||
local input = io.open("newfactions", "r")
|
||||
while input do
|
||||
local str = input:read("*line")
|
||||
if str==nil then break end
|
||||
local email, race, lang = str:match("([^ ]*) ([^ ]*) ([^ ]*)")
|
||||
if string.char(string.byte(email, 1))~='#' then
|
||||
table.insert(players, { race = race, lang = lang, email = email })
|
||||
end
|
||||
end
|
||||
return players
|
||||
local path = 'scripts'
|
||||
if config.install then
|
||||
path = config.install .. '/' .. path
|
||||
end
|
||||
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
|
||||
require 'eressea'
|
||||
require 'eressea.xmlconf' -- read xml data
|
||||
|
||||
local function seed(r, email, race, lang)
|
||||
local f = faction.create(email, race, lang)
|
||||
local u = unit.create(f, r)
|
||||
equip_unit(u, "new_faction")
|
||||
equip_unit(u, "first_unit")
|
||||
equip_unit(u, "first_" .. race, 7) -- disable old callbacks
|
||||
unit.create(f, r, 5):set_skill("mining", 30)
|
||||
unit.create(f, r, 5):set_skill("quarrying", 30)
|
||||
f:set_origin(r)
|
||||
return f
|
||||
end
|
||||
require 'config'
|
||||
auto = require 'eressea.autoseed'
|
||||
|
||||
local function dump_selection(sel)
|
||||
local best = { score = 0, r = nil }
|
||||
|
@ -42,54 +23,9 @@ local function dump_selection(sel)
|
|||
return best
|
||||
end
|
||||
|
||||
players = read_players()
|
||||
local peasants = 20000
|
||||
local trees = 1000
|
||||
local turn = get_turn()
|
||||
local sel
|
||||
if #players > 0 then
|
||||
eressea.read_game(("%d.dat"):format(turn))
|
||||
sel = p.select(regions(), peasants, trees)
|
||||
if #sel > 0 then
|
||||
local best = dump_selection(sel)
|
||||
print("finest region, " .. best.score .. " points: " .. tostring(best.r))
|
||||
end
|
||||
end
|
||||
math.randomseed(os.time())
|
||||
|
||||
local newbs = {}
|
||||
local per_region = 2
|
||||
local num_seeded = 2
|
||||
local start = nil
|
||||
for _, p in ipairs(players) do
|
||||
if num_seeded == per_region then
|
||||
while not start or start.units() do
|
||||
local index = math.random(#sel)
|
||||
start = sel[index]
|
||||
end
|
||||
num_seeded = 0
|
||||
end
|
||||
local dupe = false
|
||||
for f in factions() do
|
||||
if f.email==p.email then
|
||||
print("seed: duplicate email " .. p.email .. " already used by " .. tostring(f))
|
||||
dupe = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not dupe then
|
||||
num_seeded = num_seeded + 1
|
||||
f = seed(start, p.email, p.race or "human", p.lang or "de")
|
||||
print("new faction ".. tostring(f) .. " starts in ".. tostring(start))
|
||||
table.insert(newbs, f)
|
||||
end
|
||||
end
|
||||
|
||||
if #newbs > 0 then
|
||||
init_reports()
|
||||
for _, f in ipairs(newbs) do
|
||||
write_report(f)
|
||||
end
|
||||
eressea.write_game(("%d.dat.new"):format(turn))
|
||||
end
|
||||
|
||||
print("read game")
|
||||
eressea.read_game(get_turn() .. ".dat")
|
||||
print("auto-seed")
|
||||
auto.init()
|
||||
print("editor")
|
||||
gmtool.editor()
|
||||
|
|
|
@ -1239,7 +1239,10 @@ void run_mapper(void)
|
|||
int split = 20;
|
||||
state *st;
|
||||
point tl;
|
||||
|
||||
/* FIXME: dsiable logging
|
||||
int old_flags = log_flags;
|
||||
log_flags &= ~(LOG_CPERROR | LOG_CPWARNING);
|
||||
*/
|
||||
init_curses();
|
||||
curs_set(1);
|
||||
|
||||
|
@ -1331,6 +1334,9 @@ void run_mapper(void)
|
|||
set_readline(NULL);
|
||||
curs_set(1);
|
||||
endwin();
|
||||
/* FIXME: reset logging
|
||||
log_flags = old_flags;
|
||||
*/
|
||||
state_close(st);
|
||||
}
|
||||
|
||||
|
|
51
src/main.c
51
src/main.c
|
@ -128,9 +128,31 @@ static int get_arg(int argc, char **argv, size_t len, int index, const char **re
|
|||
return index;
|
||||
}
|
||||
|
||||
static int verbosity_to_flags(int verbosity) {
|
||||
int flags = 0;
|
||||
switch (verbosity) {
|
||||
case 0:
|
||||
flags = 0;
|
||||
break;
|
||||
case 1:
|
||||
flags = LOG_CPERROR;
|
||||
break;
|
||||
case 2:
|
||||
flags = LOG_CPERROR | LOG_CPWARNING;
|
||||
break;
|
||||
case 3:
|
||||
flags = LOG_CPERROR | LOG_CPWARNING | LOG_CPINFO;
|
||||
break;
|
||||
default:
|
||||
flags = LOG_CPERROR | LOG_CPWARNING | LOG_CPINFO | LOG_CPDEBUG;
|
||||
break;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
static int parse_args(int argc, char **argv, int *exitcode)
|
||||
{
|
||||
int i, log_stderr = 0;
|
||||
int i, log_stderr = 0, log_flags = 0;
|
||||
|
||||
for (i = 1; i != argc; ++i) {
|
||||
char *argi = argv[i];
|
||||
|
@ -168,7 +190,8 @@ static int parse_args(int argc, char **argv, int *exitcode)
|
|||
i = get_arg(argc, argv, 2, i, &luafile, 0);
|
||||
break;
|
||||
case 'l':
|
||||
i = get_arg(argc, argv, 2, i, &logfile, 0);
|
||||
i = get_arg(argc, argv, 2, i, &arg, 0);
|
||||
log_flags = arg ? atoi(arg) : 0xff;
|
||||
break;
|
||||
case 't':
|
||||
i = get_arg(argc, argv, 2, i, &arg, 0);
|
||||
|
@ -192,28 +215,15 @@ static int parse_args(int argc, char **argv, int *exitcode)
|
|||
}
|
||||
}
|
||||
|
||||
switch (verbosity) {
|
||||
case 0:
|
||||
log_stderr = 0;
|
||||
break;
|
||||
case 1:
|
||||
log_stderr = LOG_CPERROR;
|
||||
break;
|
||||
case 2:
|
||||
log_stderr = LOG_CPERROR | LOG_CPWARNING;
|
||||
break;
|
||||
case 3:
|
||||
log_stderr = LOG_CPERROR | LOG_CPWARNING | LOG_CPINFO;
|
||||
break;
|
||||
default:
|
||||
log_stderr = LOG_CPERROR | LOG_CPWARNING | LOG_CPINFO | LOG_CPDEBUG;
|
||||
break;
|
||||
}
|
||||
// open logfile on disk:
|
||||
log_flags = verbosity_to_flags(log_flags);
|
||||
log_open(logfile, log_flags);
|
||||
|
||||
// also log to stderr:
|
||||
log_stderr = verbosity_to_flags(verbosity);
|
||||
if (log_stderr) {
|
||||
log_to_file(log_stderr | LOG_FLUSH | LOG_BRIEF, stderr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -296,7 +306,6 @@ int main(int argc, char **argv)
|
|||
/* parse arguments again, to override ini file */
|
||||
parse_args(argc, argv, &err);
|
||||
|
||||
log_open(logfile, LOG_CPERROR | LOG_CPWARNING | LOG_CPDEBUG | LOG_FLUSH);
|
||||
locale_init();
|
||||
|
||||
#ifdef CRTDBG
|
||||
|
|
|
@ -22,9 +22,6 @@ without prior permission by the authors of Eressea.
|
|||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
|
||||
/* TODO: set from external function */
|
||||
int log_flags = LOG_FLUSH | LOG_CPERROR | LOG_CPWARNING | LOG_CPDEBUG;
|
||||
|
||||
#ifdef STDIO_CP
|
||||
static int stdio_codepage = STDIO_CP;
|
||||
#else
|
||||
|
@ -126,7 +123,7 @@ static const char *log_prefix(int level) {
|
|||
return prefix;
|
||||
}
|
||||
|
||||
static int check_dupe(const char *format, int type)
|
||||
static int check_dupe(const char *format, int level)
|
||||
{
|
||||
static int last_type; /* STATIC_XCALL: used across calls */
|
||||
static char last_message[32]; /* STATIC_XCALL: used across calls */
|
||||
|
@ -136,12 +133,14 @@ static int check_dupe(const char *format, int type)
|
|||
return 1;
|
||||
}
|
||||
if (dupes) {
|
||||
if (level & LOG_CPERROR) {
|
||||
fprintf(stderr, "%s: last message repeated %d times\n", log_prefix(last_type),
|
||||
dupes + 1);
|
||||
}
|
||||
dupes = 0;
|
||||
}
|
||||
strlcpy(last_message, format, sizeof(last_message));
|
||||
last_type = type;
|
||||
last_type = level;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -176,6 +175,7 @@ static void log_stdio(void *data, int level, const char *module, const char *for
|
|||
if (format[len - 1] != '\n') {
|
||||
fputc('\n', out);
|
||||
}
|
||||
fflush(out);
|
||||
}
|
||||
|
||||
log_t *log_to_file(int flags, FILE *out) {
|
||||
|
@ -280,7 +280,7 @@ log_t *log_open(const char *filename, int log_flags)
|
|||
fprintf(logfile, "===\n=== Logfile started at %s===\n", ctime(<ime));
|
||||
return log_create(log_flags, logfile, log_stdio);
|
||||
}
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int log_level(log_t * log, int flags)
|
||||
|
|
|
@ -43,6 +43,8 @@ extern "C" {
|
|||
#define LOG_FLUSH 0x10
|
||||
#define LOG_BRIEF 0x20
|
||||
|
||||
|
||||
extern int log_stderr;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue