forked from github/server
kill the RESTART order
make more parts of process_order their own function started writing process_order in Lua, to see how far I've gotten fix a bug in the logging library
This commit is contained in:
parent
abca123b76
commit
a662f88868
|
@ -23,7 +23,7 @@ function test_process()
|
|||
assert_equal("function", _G.type(eressea.process.set_prefix))
|
||||
assert_equal("function", _G.type(eressea.process.set_stealth))
|
||||
assert_equal("function", _G.type(eressea.process.set_status))
|
||||
assert_equal("function", _G.type(eressea.process.set_description))
|
||||
assert_equal("function", _G.type(eressea.process.set_name))
|
||||
assert_equal("function", _G.type(eressea.process.set_group))
|
||||
assert_equal("function", _G.type(eressea.process.set_origin))
|
||||
assert_equal("function", _G.type(eressea.process.quit))
|
||||
|
|
|
@ -2,6 +2,8 @@ require "lunit"
|
|||
|
||||
local _G = _G
|
||||
local eressea = eressea
|
||||
local default_ship = config.ships[1]
|
||||
local default_building = config.buildings[1]
|
||||
|
||||
module("tests.orders", lunit.testcase)
|
||||
|
||||
|
@ -145,7 +147,7 @@ end
|
|||
|
||||
function test_process_leave()
|
||||
r2 = _G.region.create(1, 0, 'plain')
|
||||
b = _G.building.create(r, "castle")
|
||||
b = _G.building.create(r, default_building)
|
||||
u.building = b
|
||||
assert_equal(b, u.building)
|
||||
u:add_order('VERLASSEN')
|
||||
|
@ -153,3 +155,31 @@ function test_process_leave()
|
|||
assert_not_equal(b, u.building)
|
||||
end
|
||||
|
||||
function test_process_name_unit()
|
||||
u:add_order("BENENNE EINHEIT 'Weasel'")
|
||||
u:add_order("BESCHREIBE EINHEIT 'Juanita'")
|
||||
eressea.process.set_name()
|
||||
assert_equal('Weasel', u.name)
|
||||
assert_equal('Juanita', u.info)
|
||||
end
|
||||
|
||||
function test_process_name_faction()
|
||||
u:add_order("BENENNE PARTEI 'Herpderp'")
|
||||
eressea.process.set_name()
|
||||
assert_equal('Herpderp', f.name)
|
||||
end
|
||||
|
||||
function test_process_name_building()
|
||||
u:add_order("BENENNE GEBAEUDE 'Herpderp'")
|
||||
u.building = _G.building.create(r, default_building)
|
||||
eressea.process.set_name()
|
||||
assert_equal('Herpderp', u.building.name)
|
||||
end
|
||||
|
||||
function test_process_name_ship()
|
||||
u:add_order("BENENNE SCHIFF 'Herpderp'")
|
||||
u.ship = _G.ship.create(r, default_ship)
|
||||
eressea.process.set_name()
|
||||
assert_equal('Herpderp', u.ship.name)
|
||||
end
|
||||
|
||||
|
|
|
@ -135,7 +135,8 @@ void process_status(void) {
|
|||
process_cmd(K_STATUS, status_cmd, 0);
|
||||
}
|
||||
|
||||
void process_display(void) {
|
||||
void process_name(void) {
|
||||
process_cmd(K_NAME, name_cmd, 0);
|
||||
process_cmd(K_DISPLAY, display_cmd, 0);
|
||||
}
|
||||
|
||||
|
@ -158,7 +159,14 @@ void process_study(void) {
|
|||
}
|
||||
|
||||
void process_movement(void) {
|
||||
region * r;
|
||||
|
||||
movement();
|
||||
for (r=regions; r; r=r->next) {
|
||||
if (r->ships) {
|
||||
sinkships(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void process_use(void) {
|
||||
|
@ -168,3 +176,20 @@ void process_use(void) {
|
|||
void process_leave(void) {
|
||||
process_cmd(K_LEAVE, leave_cmd, 0);
|
||||
}
|
||||
|
||||
void process_maintenance(void) {
|
||||
region * r;
|
||||
for (r=regions; r; r=r->next) {
|
||||
unit * u;
|
||||
for (u=r->units; u; u=u->next) {
|
||||
order * ord;
|
||||
for (ord=u->orders; ord; ord=ord->next) {
|
||||
keyword_t kwd = get_keyword(ord);
|
||||
if (kwd==K_PAY) {
|
||||
pay_cmd(u, ord);
|
||||
}
|
||||
}
|
||||
}
|
||||
maintain_buildings(r, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ void process_ally(void);
|
|||
void process_prefix(void);
|
||||
void process_setstealth(void);
|
||||
void process_status(void);
|
||||
void process_display(void);
|
||||
void process_name(void);
|
||||
void process_group(void);
|
||||
void process_origin(void);
|
||||
void process_quit(void);
|
||||
|
@ -24,6 +24,7 @@ void process_use(void);
|
|||
void process_battle(void);
|
||||
void process_siege(void);
|
||||
void process_leave(void);
|
||||
void process_maintenance(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ module eressea {
|
|||
void process_prefix @ set_prefix(void); /* PREFIX */
|
||||
void process_setstealth @ set_stealth(void); /* STEALTH */
|
||||
void process_status @ set_status(void); /* STATUS */
|
||||
void process_display @ set_description(void); /* DESCRIBE */
|
||||
void process_name @ set_name(void); /* NAME/DISPLAY */
|
||||
void process_group @ set_group(void); /* GROUP */
|
||||
void process_origin @ set_origin(void); /* ORIGIN */
|
||||
void process_quit @ quit(void); /* QUIT */
|
||||
|
@ -21,5 +21,6 @@ module eressea {
|
|||
void process_battle @ battle(void); /* ATTACK */
|
||||
void process_siege @ siege(void); /* SIEGE */
|
||||
void process_leave @ leave(void); /* LEAVE */
|
||||
void process_maintenance @ maintenance(void); /* PAY */
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,9 +119,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#define DMRISEHAFEN 0.2F /* weekly chance that demand goes up with harbor */
|
||||
|
||||
/* - exported global symbols ----------------------------------- */
|
||||
boolean nobattle = false;
|
||||
boolean nomonsters = false;
|
||||
/* ------------------------------------------------------------- */
|
||||
|
||||
static int RemoveNMRNewbie(void)
|
||||
{
|
||||
|
@ -135,40 +132,6 @@ static int RemoveNMRNewbie(void)
|
|||
return value;
|
||||
}
|
||||
|
||||
static void restart_race(unit * u, const race * rc)
|
||||
{
|
||||
faction *oldf = u->faction;
|
||||
faction *f = addfaction(oldf->email, oldf->passw, rc, oldf->locale,
|
||||
oldf->subscription);
|
||||
unit *nu = addplayer(u->region, f);
|
||||
order **ordp = &u->orders;
|
||||
f->subscription = u->faction->subscription;
|
||||
f->age = u->faction->age;
|
||||
fset(f, FFL_RESTART);
|
||||
if (f->subscription) {
|
||||
sql_print(
|
||||
("UPDATE subscriptions set faction='%s', race='%s' where id=%u;\n",
|
||||
itoa36(f->no), dbrace(rc), f->subscription));
|
||||
}
|
||||
f->magiegebiet = u->faction->magiegebiet;
|
||||
f->options = u->faction->options;
|
||||
free_orders(&nu->orders);
|
||||
nu->orders = u->orders;
|
||||
u->orders = NULL;
|
||||
while (*ordp) {
|
||||
order *ord = *ordp;
|
||||
if (get_keyword(ord) != K_RESTART) {
|
||||
*ordp = ord->next;
|
||||
ord->next = NULL;
|
||||
if (u->thisorder == ord)
|
||||
set_order(&u->thisorder, NULL);
|
||||
} else {
|
||||
ordp = &ord->next;
|
||||
}
|
||||
}
|
||||
destroyfaction(u->faction);
|
||||
}
|
||||
|
||||
static void checkorders(void)
|
||||
{
|
||||
faction *f;
|
||||
|
@ -1169,50 +1132,6 @@ int leave_cmd(unit * u, struct order *ord)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int restart_cmd(unit * u, struct order *ord)
|
||||
{
|
||||
init_tokens(ord);
|
||||
skip_token(); /* skip keyword */
|
||||
|
||||
if (!fval(u->region->terrain, LAND_REGION)) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", ""));
|
||||
} else {
|
||||
const char *s_race = getstrtoken(), *s_pass;
|
||||
const race *frace = findrace(s_race, u->faction->locale);
|
||||
|
||||
if (!frace) {
|
||||
frace = u->faction->race;
|
||||
s_pass = s_race;
|
||||
} else {
|
||||
s_pass = getstrtoken();
|
||||
}
|
||||
|
||||
if (u->faction->age > 3 && fval(u->faction, FFL_RESTART)) {
|
||||
cmistake(u, ord, 314, MSG_EVENT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( /* frace != u->faction->race && */ u->faction->age < 81) {
|
||||
cmistake(u, ord, 241, MSG_EVENT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!playerrace(frace)) {
|
||||
cmistake(u, ord, 243, MSG_EVENT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!checkpasswd(u->faction, (const char *)s_pass, false)) {
|
||||
cmistake(u, ord, 86, MSG_EVENT);
|
||||
log_warning("RESTART with wrong password, faction %s, pass %s\n", factionid(u->faction), s_pass);
|
||||
return 0;
|
||||
}
|
||||
restart_race(u, frace);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static boolean EnhancedQuit(void)
|
||||
{
|
||||
static int value = -1;
|
||||
|
@ -1539,40 +1458,16 @@ static void nmr_death(faction * f)
|
|||
}
|
||||
}
|
||||
|
||||
static void parse_restart(void)
|
||||
static void remove_idle_players(void)
|
||||
{
|
||||
region *r;
|
||||
faction *f;
|
||||
|
||||
/* Sterben erst nachdem man allen anderen gegeben hat - bzw. man kann
|
||||
* alles machen, was nicht ein dreißigtägiger Befehl ist. */
|
||||
|
||||
for (r = regions; r; r = r->next) {
|
||||
unit *u, *un;
|
||||
for (u = r->units; u;) {
|
||||
order *ord;
|
||||
|
||||
un = u->next;
|
||||
for (ord = u->orders; ord != NULL; ord = ord->next) {
|
||||
if (get_keyword(ord) == K_RESTART) {
|
||||
if (u->number > 0) {
|
||||
if (restart_cmd(u, ord) != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
u = un;
|
||||
}
|
||||
}
|
||||
|
||||
if (verbosity >= 1)
|
||||
puts
|
||||
(" - beseitige Spieler, die sich zu lange nicht mehr gemeldet haben...");
|
||||
log_info(" - beseitige Spieler, die sich zu lange nicht mehr gemeldet haben...");
|
||||
|
||||
for (f = factions; f; f = f->next) {
|
||||
if (fval(f, FFL_NOIDLEOUT))
|
||||
if (fval(f, FFL_NOIDLEOUT)) {
|
||||
f->lastorders = turn;
|
||||
}
|
||||
if (NMRTimeout() > 0 && turn - f->lastorders >= NMRTimeout()) {
|
||||
nmr_death(f);
|
||||
destroyfaction(f);
|
||||
|
@ -1606,10 +1501,7 @@ static void parse_restart(void)
|
|||
continue;
|
||||
}
|
||||
}
|
||||
if (verbosity >= 1) {
|
||||
puts(" - beseitige Spieler, die sich nach der Anmeldung nicht "
|
||||
"gemeldet haben...");
|
||||
}
|
||||
log_info(" - beseitige Spieler, die sich nach der Anmeldung nicht gemeldet haben...");
|
||||
|
||||
age = calloc(MAX(4, turn + 1), sizeof(int));
|
||||
for (f = factions; f; f = f->next)
|
||||
|
@ -3073,7 +2965,7 @@ static int guard_on_cmd(unit * u, struct order *ord)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void sinkships(region * r)
|
||||
void sinkships(struct region * r)
|
||||
{
|
||||
ship **shp = &r->ships;
|
||||
|
||||
|
@ -4154,7 +4046,7 @@ int use_cmd(unit * u, struct order *ord)
|
|||
return err;
|
||||
}
|
||||
|
||||
static int pay_cmd(unit * u, struct order *ord)
|
||||
int pay_cmd(unit * u, struct order *ord)
|
||||
{
|
||||
if (!u->building) {
|
||||
cmistake(u, ord, 6, MSG_EVENT);
|
||||
|
@ -4627,9 +4519,7 @@ void init_processor(void)
|
|||
p += 10; /* in case it has any effects on alliance victories */
|
||||
add_proc_order(p, K_LEAVE, &leave_cmd, 0, "Verlassen");
|
||||
|
||||
if (!nobattle) {
|
||||
add_proc_region(p, &do_battle, "Attackieren");
|
||||
}
|
||||
add_proc_region(p, &do_battle, "Attackieren");
|
||||
|
||||
if (!global.disabled[K_BESIEGE]) {
|
||||
p += 10;
|
||||
|
@ -4653,10 +4543,8 @@ void init_processor(void)
|
|||
"Gebaeudeunterhalt (1. Versuch)");
|
||||
|
||||
p += 10; /* QUIT fuer sich alleine */
|
||||
add_proc_global(p, &quit, "Sterben");
|
||||
if (!global.disabled[K_RESTART]) {
|
||||
add_proc_global(p, &parse_restart, "Neustart");
|
||||
}
|
||||
add_proc_global(p, quit, "Sterben");
|
||||
add_proc_global(p, remove_idle_players, "remove idle players");
|
||||
|
||||
if (!global.disabled[K_CAST]) {
|
||||
p += 10;
|
||||
|
|
|
@ -53,6 +53,7 @@ extern "C" {
|
|||
extern void new_units(void);
|
||||
extern void quit(void);
|
||||
extern void update_long_order(struct unit *u);
|
||||
extern void sinkships(struct region * r);
|
||||
extern int password_cmd(struct unit *u, struct order *ord);
|
||||
extern int banner_cmd(struct unit *u, struct order *ord);
|
||||
extern int email_cmd(struct unit *u, struct order *ord);
|
||||
|
@ -69,6 +70,7 @@ extern "C" {
|
|||
extern int use_cmd(struct unit *u, struct order *ord);
|
||||
extern int siege_cmd(struct unit *u, struct order *ord);
|
||||
extern int leave_cmd(struct unit *u, struct order *ord);
|
||||
extern int pay_cmd(struct unit *u, struct order *ord);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -449,7 +449,6 @@ const char *keywords[MAXKEYWORDS] = {
|
|||
"URSPRUNG",
|
||||
"EMAIL",
|
||||
"PIRATERIE",
|
||||
"NEUSTART",
|
||||
"GRUPPE",
|
||||
"OPFERE",
|
||||
"BETEN",
|
||||
|
|
|
@ -128,7 +128,6 @@ typedef enum {
|
|||
K_URSPRUNG,
|
||||
K_EMAIL,
|
||||
K_PIRACY,
|
||||
K_RESTART,
|
||||
K_GROUP,
|
||||
K_SACRIFICE,
|
||||
K_PRAY,
|
||||
|
|
|
@ -253,7 +253,7 @@ void log_error(const char *format, ...)
|
|||
}
|
||||
}
|
||||
|
||||
void _log_info(const char *format, ...)
|
||||
void log_info(const char *format, ...)
|
||||
{
|
||||
const char * prefix = "INFO";
|
||||
const int mask = LOG_CPINFO;
|
||||
|
|
Loading…
Reference in New Issue