- Neues Script für Jadee/Wente-Gates, nur Braut/Bräutigam durchlassen

- SQL-Stream verbessert, File wird nur erzeugt wenn auch geschrieben wird.
This commit is contained in:
Enno Rehling 2004-07-10 17:16:15 +00:00
parent 565b78bcd4
commit f1328bff7c
10 changed files with 76 additions and 53 deletions

View File

@ -121,8 +121,10 @@ restart_race(unit *u, const race * rc)
order ** ordp = &u->orders; order ** ordp = &u->orders;
f->subscription = u->faction->subscription; f->subscription = u->faction->subscription;
fset(f, FFL_RESTART); fset(f, FFL_RESTART);
if (f->subscription) fprintf(sqlstream, "UPDATE subscriptions set faction='%s', race='%s' where id=%u;\n", if (f->subscription) {
itoa36(f->no), dbrace(rc), 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->magiegebiet = u->faction->magiegebiet;
f->options = u->faction->options; f->options = u->faction->options;
free_orders(&nu->orders); free_orders(&nu->orders);
@ -1208,15 +1210,15 @@ parse_quit(void)
char info[256]; char info[256];
sprintf(info, "%d Einheiten, %d Personen, %d Silber", sprintf(info, "%d Einheiten, %d Personen, %d Silber",
f->no_units, f->number, f->money); f->no_units, f->number, f->money);
if (f->subscription) fprintf(sqlstream, if (f->subscription) {
"UPDATE subscriptions SET lastturn=%d, password='%s', info='%s' " sql_print(("UPDATE subscriptions SET lastturn=%d, password='%s', info='%s' WHERE id=%u;\n",
"WHERE id=%u;\n", f->lastorders, f->override, info, f->subscription));
f->lastorders, f->override, info, f->subscription); }
} else { } else {
if (f->subscription) fprintf(sqlstream, if (f->subscription) {
"UPDATE subscriptions SET status='ACTIVE', lastturn=%d, password='%s' " sql_print(("UPDATE subscriptions SET status='ACTIVE', lastturn=%d, password='%s' WHERE id=%u;\n",
"WHERE id=%u;\n", f->lastorders, f->override, f->subscription));
f->lastorders, f->override, f->subscription); }
} }
if (NMRTimeout()>0 && turn - f->lastorders >= (NMRTimeout() - 1)) { if (NMRTimeout()>0 && turn - f->lastorders >= (NMRTimeout() - 1)) {
@ -2797,9 +2799,10 @@ renumber_factions(void)
for (rp=renum;rp;rp=rp->next) { for (rp=renum;rp;rp=rp->next) {
f = rp->faction; f = rp->faction;
a_remove(&f->attribs, rp->attrib); a_remove(&f->attribs, rp->attrib);
if (f->subscription) fprintf(sqlstream, "UPDATE subscriptions set faction='%s' where " if (f->subscription) {
"id=%u;\n", itoa36(rp->want), sql_print(("UPDATE subscriptions set faction='%s' where id=%u;\n",
f->subscription); itoa36(rp->want), f->subscription));
}
f->no = rp->want; f->no = rp->want;
register_faction_id(rp->want); register_faction_id(rp->want);
fset(f, FF_NEWID); fset(f, FF_NEWID);

View File

@ -2354,7 +2354,7 @@ kernel_done(void)
translation_done(); translation_done();
skill_done(); skill_done();
gc_done(); gc_done();
if (sqlstream!=NULL) sql_done(); sql_done();
} }
const char * localenames[] = { const char * localenames[] = {
@ -2494,14 +2494,12 @@ remove_empty_factions(boolean writedropouts)
} }
} }
} }
if (f->subscription) fprintf(sqlstream, "UPDATE subscriptions set status='DEAD' where " if (f->subscription) {
"id=%u\n;", f->subscription); sql_print(("UPDATE subscriptions set status='DEAD' where id=%u\n;",
f->subscription));
}
*fp = f->next; *fp = f->next;
/* stripfaction(f);
* free(f);
* Wir können die nicht löschen, weil sie evtl. noch in attributen
* referenziert sind ! */
} }
else fp = &(*fp)->next; else fp = &(*fp)->next;
} }

View File

@ -49,30 +49,24 @@ info_name(const tnode * tnext, const char * str, void * data, struct order * ord
unused(str); unused(str);
unused(data); unused(data);
unused(ord); unused(ord);
if (sqlstream!=NULL) {
}
} }
static void static void
info_address(const tnode * tnext, const char * str, void * data, struct order * ord) info_address(const tnode * tnext, const char * str, void * data, struct order * ord)
{ {
if (sqlstream!=NULL) {
}
} }
static void static void
info_phone(const tnode * tnext, const char * str, void * data, struct order * ord) info_phone(const tnode * tnext, const char * str, void * data, struct order * ord)
{ {
if (sqlstream!=NULL) {
}
} }
static void static void
info_vacation(const tnode * tnext, const char * str, void * data, struct order * ord) info_vacation(const tnode * tnext, const char * str, void * data, struct order * ord)
{ {
if (sqlstream!=NULL) {
#ifdef SQLOUTPUT #ifdef SQLOUTPUT
if (sqlstream!=NULL) {
unit * u = (unit*)data; unit * u = (unit*)data;
faction * f = u->faction; faction * f = u->faction;
const char * email = sqlquote(igetstrtoken(str)); const char * email = sqlquote(igetstrtoken(str));
@ -86,8 +80,8 @@ info_vacation(const tnode * tnext, const char * str, void * data, struct order *
start.tm_year, start.tm_mon, start.tm_mday, itoa36(f->no)); start.tm_year, start.tm_mon, start.tm_mday, itoa36(f->no));
fprintf(sqlstream, "UPDATE factions SET vacation_end = '%04d-%02d-%02d' WHERE id = '%s';\n", fprintf(sqlstream, "UPDATE factions SET vacation_end = '%04d-%02d-%02d' WHERE id = '%s';\n",
end.tm_year, end.tm_mon, end.tm_mday, itoa36(f->no)); end.tm_year, end.tm_mon, end.tm_mday, itoa36(f->no));
#endif
} }
#endif
} }
static tnode g_keys; static tnode g_keys;
@ -112,7 +106,6 @@ infocommands(void)
} }
if (*rp==r) rp = &r->next; if (*rp==r) rp = &r->next;
} }
fflush(sqlstream);
} }
void void

View File

@ -77,7 +77,7 @@ unitmessage_write(const trigger * t, FILE * F)
unitmessage_data * td = (unitmessage_data*)t->data.v; unitmessage_data * td = (unitmessage_data*)t->data.v;
fprintf(F, "%s ", itoa36(td->target->no)); fprintf(F, "%s ", itoa36(td->target->no));
fwritestr(F, td->string); fwritestr(F, td->string);
fprintf(F, "%d %d ", td->type, td->level); fprintf(F, " %d %d ", td->type, td->level);
} }
static int static int

View File

@ -24,26 +24,42 @@
#include "log.h" #include "log.h"
FILE * sqlstream; #include <stdarg.h>
#include <stdio.h>
static FILE * sqlstream = NULL;
static char * sqlfilename = NULL;
void void
sql_init(const char * filename) sql_init(const char * filename)
{ {
static boolean init = false; if (sqlfilename!=NULL) free(sqlfilename);
if (!init) { sqlfilename = strdup(filename);
sqlstream = fopen(filename, "wt+"); }
if (sqlstream==NULL) {
log_error(("could not open file: %s\n", filename)); void
} _sql_print(const char * format, ...)
init = true; {
} if (!sqlstream && sqlfilename) {
sqlstream=fopen(sqlfilename, "wt+");
free(sqlfilename);
sqlfilename=NULL;
}
if (sqlstream!=NULL) {
va_list marker;
va_start(marker, format);
vfprintf(sqlstream, format, marker);
va_end(marker);
}
} }
void void
sql_done(void) sql_done(void)
{ {
if (sqlstream) fclose(sqlstream); if (sqlstream) fclose(sqlstream);
/* TODO */ if (sqlfilename) free(sqlfilename);
sqlstream=NULL;
sqlfilename=NULL;
} }
const char * const char *

View File

@ -25,10 +25,12 @@
extern "C" { extern "C" {
#endif #endif
extern FILE * sqlstream; extern void sql_init(const char * filename);
extern void sql_init(const char * filename); extern void sql_done(void);
extern void sql_done(void); extern const char * sqlquote(const char * str);
extern const char * sqlquote(const char * str); extern void _sql_print(const char * format, ...);
#define sql_print(x) _sql_print x
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -71,6 +71,7 @@ lc_write(const struct attrib * a, FILE* F)
write_building_reference(b, F); write_building_reference(b, F);
fwritestr(F, fname); fwritestr(F, fname);
fputc(' ', F);
} }
static int static int

View File

@ -8,6 +8,7 @@
#include <attributes/key.h> #include <attributes/key.h>
// kernel includes // kernel includes
#include <kernel/building.h>
#include <kernel/faction.h> #include <kernel/faction.h>
#include <kernel/item.h> #include <kernel/item.h>
#include <kernel/magic.h> #include <kernel/magic.h>
@ -232,7 +233,7 @@ unit_getregion(const unit& u)
static void static void
unit_setbuilding(unit& u, building& b) unit_setbuilding(unit& u, building& b)
{ {
leave(u.region, u); leave(u.region, &u);
u.building = &b; u.building = &b;
} }

View File

@ -549,11 +549,11 @@ void
confirm_newbies(void) confirm_newbies(void)
{ {
faction * f = factions; faction * f = factions;
if (sqlstream==NULL) return;
while (f) { while (f) {
if (!fval(f, FFL_DBENTRY)) { if (!fval(f, FFL_DBENTRY)) {
if (f->subscription) { if (f->subscription) {
fprintf(sqlstream, "UPDATE subscriptions SET status='ACTIVE', faction='%s', race='%s' WHERE id=%u;\n", itoa36(f->no), dbrace(f->race), f->subscription); sql_print(("UPDATE subscriptions SET status='ACTIVE', faction='%s', race='%s' WHERE id=%u;\n",
itoa36(f->no), dbrace(f->race), f->subscription));
fset(f, FFL_DBENTRY); fset(f, FFL_DBENTRY);
} }
} }

View File

@ -6,20 +6,29 @@ hellgate = nil
peacegate = nil peacegate = nil
function gate_exchange(b1, b2) function gate_exchange(b1, b2)
local units = {} local units1 = {}
local units2 = {}
local u local u
for u in b1.units do for u in b1.units do
units[u.no] = u if u:get_flag("wdgt") then
units1[u.no] = u
end
end end
for u in b2.units do for u in b2.units do
u.region = b1.region if u:get_flag("wdgt") then
u.building = b1 units2[u.no] = u
end
end end
for id in units do for id in units1 do
u = units[id] u = units1[id]
u.region = b2.region u.region = b2.region
u.building = b2 u.building = b2
end end
for id in units2 do
u = units2[id]
u.region = b1.region
u.building = b1
end
end end
function hellgate_action(b) function hellgate_action(b)