Better logging for invalid email addresses (incl. faction no)

This commit is contained in:
Enno Rehling 2004-08-28 23:06:15 +00:00
parent cd021ea812
commit f06e9e8bef
7 changed files with 30 additions and 22 deletions

View File

@ -2056,7 +2056,7 @@ email_cmd(unit * u, struct order * ord)
} else { } else {
faction * f = u->faction; faction * f = u->faction;
if (set_email(&f->email, s)!=0) { if (set_email(&f->email, s)!=0) {
log_error(("Invalid email address: %s\n", s)); log_error(("Invalid email address for faction %s: %s\n", itoa36(f->no), s));
ADDMSG(&f->msgs, msg_message("changemail_invalid", "value", ADDMSG(&f->msgs, msg_message("changemail_invalid", "value",
gc_add(strdup(s)))); gc_add(strdup(s))));
} else { } else {
@ -2446,7 +2446,7 @@ reshow(unit * u, struct order * ord, const char * s, param_t p)
#ifdef HEROES #ifdef HEROES
static int static int
promote_cmd(unit * u, struct order * ord) promotion_cmd(unit * u, struct order * ord)
{ {
int money, people; int money, people;
@ -2471,7 +2471,7 @@ promote_cmd(unit * u, struct order * ord)
use_all(u, i_silver->rtype, people); use_all(u, i_silver->rtype, people);
fset(u, UFL_HERO); fset(u, UFL_HERO);
ADDMSG(&u->faction->msgs, msg_message("hero_promotion", "unit cost", ADDMSG(&u->faction->msgs, msg_message("hero_promotion", "unit cost",
u, money)); u, people));
return 0; return 0;
} }
#endif #endif
@ -3830,7 +3830,7 @@ processorders (void)
#ifdef HEROES #ifdef HEROES
puts(" - Heldenbeförderung"); puts(" - Heldenbeförderung");
parse(K_PROMOTION, promote_cmd, false); parse(K_PROMOTION, promotion_cmd, false);
#endif #endif
puts(" - Neue Nummern"); puts(" - Neue Nummern");

View File

@ -99,7 +99,7 @@ addfaction(const char *email, const char * password,
assert(frace != new_race[RC_ORC]); assert(frace != new_race[RC_ORC]);
if (set_email(&f->email, email)!=0) { if (set_email(&f->email, email)!=0) {
log_error(("Invalid email address: %s\n", email)); log_error(("Invalid email address for faction %s: %s\n", itoa36(f->no), email));
} }
if (password) { if (password) {

View File

@ -1524,7 +1524,7 @@ readfaction(FILE * F)
rds(F, &f->banner); rds(F, &f->banner);
rds(F, &email); rds(F, &email);
if (set_email(&f->email, email)!=0) { if (set_email(&f->email, email)!=0) {
log_error(("Invalid email address: %s\n", email)); log_error(("Invalid email address for faction %s: %s\n", itoa36(f->no), email));
set_email(&f->email, ""); set_email(&f->email, "");
} }
rds(F, &f->passw); rds(F, &f->passw);

View File

@ -630,7 +630,7 @@ gm_addquest(const char * email, const char * name, int radius, unsigned int flag
f->override = strdup(itoa36(rand())); f->override = strdup(itoa36(rand()));
f->override = strdup(itoa36(rand())); f->override = strdup(itoa36(rand()));
if (set_email(&f->email, email)!=0) { if (set_email(&f->email, email)!=0) {
log_error(("Invalid email address: %s\n", email)); log_error(("Invalid email address for faction %s: %s\n", itoa36(f->no), email));
} }
f->name = strdup("Questenpartei"); f->name = strdup("Questenpartei");
f->race = new_race[RC_TEMPLATE]; f->race = new_race[RC_TEMPLATE];
@ -733,7 +733,7 @@ gm_addfaction(const char * email, plane * p, region * r)
f->banner = strdup("Questenpartei"); f->banner = strdup("Questenpartei");
f->passw = strdup(itoa36(rand())); f->passw = strdup(itoa36(rand()));
if (set_email(&f->email, email)!=0) { if (set_email(&f->email, email)!=0) {
log_error(("Invalid email address: %s\n", email)); log_error(("Invalid email address for faction %s: %s\n", itoa36(f->no), email));
} }
f->name = strdup("Questenpartei"); f->name = strdup("Questenpartei");
f->race = new_race[RC_TEMPLATE]; f->race = new_race[RC_TEMPLATE];

View File

@ -258,7 +258,7 @@ readshortpwds()
if (f!=NULL) { if (f!=NULL) {
shortpwd * pwd = (shortpwd*)malloc(sizeof(shortpwd)); shortpwd * pwd = (shortpwd*)malloc(sizeof(shortpwd));
if (set_email(&pwd->email, email)!=0) { if (set_email(&pwd->email, email)!=0) {
log_error(("Invalid email address: %s\n", email)); log_error(("Invalid email address faction %s: %s\n", faction, email));
} }
pwd->pwd = strdup(passwd); pwd->pwd = strdup(passwd);
pwd->used = false; pwd->used = false;

View File

@ -631,6 +631,16 @@ typedef struct lostdata {
int ship; int ship;
} lostdata; } lostdata;
static void
my_lua_error(lua_State * L)
{
const char* error = lua_tostring(L, -1);
log_error((error));
lua_pop(L, 1);
std::terminate();
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@ -669,23 +679,21 @@ main(int argc, char *argv[])
// run the main script // run the main script
if (luafile==NULL) lua_console(luaState); if (luafile==NULL) lua_console(luaState);
else { else {
if (script_path) sprintf(buf, "%s/%s", script_path, luafile);
else strcpy(buf, luafile);
#ifdef LUABIND_NO_EXCEPTIONS
luabind::set_error_callback(my_lua_error);
#else
try { try {
if (script_path) { #endif
sprintf(buf, "%s/%s", script_path, luafile); lua_dofile(luaState, buf);
lua_dofile(luaState, buf); #ifndef LUABIND_NO_EXCEPTIONS
}
else lua_dofile(luaState, luafile);
} }
catch (luabind::error& e) { catch (luabind::error& e) {
lua_State* L = e.state(); lua_State* L = e.state();
const char* error = lua_tostring(L, -1); my_lua_error(L);
log_error((error));
lua_pop(L, 1);
std::terminate();
// L will now point to the destructed
// lua state and be invalid
/* ... */
} }
#endif
} }
#ifdef CLEANUP_CODE #ifdef CLEANUP_CODE
game_done(); game_done();

View File

@ -258,7 +258,7 @@ read_newfactions(const char * filename)
if (nf) continue; if (nf) continue;
nf = calloc(sizeof(newfaction), 1); nf = calloc(sizeof(newfaction), 1);
if (set_email(&nf->email, email)!=0) { if (set_email(&nf->email, email)!=0) {
log_error(("Invalid email address: %s\n", email)); log_error(("Invalid email address for faction %s: %s\n", itoa36(nf->no), email));
} }
nf->password = strdup(password); nf->password = strdup(password);
nf->race = rc_find(race); nf->race = rc_find(race);