2001-04-26 19:41:06 +02:00
|
|
|
/* vi: set ts=2:
|
|
|
|
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
|
|
| | Enno Rehling <enno@eressea-pbem.de>
|
|
|
|
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
|
|
|
| (c) 1998 - 2001 | Henning Peters <faroul@beyond.kn-bremen.de>
|
|
|
|
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
|
|
|
|
+-------------------+ Stefan Reich <reich@halbling.de>
|
|
|
|
|
|
|
|
This program may not be used, modified or distributed
|
|
|
|
without prior permission by the authors of Eressea.
|
|
|
|
|
|
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include <eressea.h>
|
|
|
|
|
|
|
|
#include "infocmd.h"
|
|
|
|
|
|
|
|
#include "command.h"
|
|
|
|
|
|
|
|
/* kernel includes */
|
|
|
|
#include <faction.h>
|
|
|
|
#include <region.h>
|
|
|
|
#include <unit.h>
|
2001-12-10 01:13:39 +01:00
|
|
|
#include <save.h>
|
|
|
|
|
|
|
|
/* util includes */
|
|
|
|
#include <base36.h>
|
|
|
|
#include <sql.h>
|
2001-04-26 19:41:06 +02:00
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
#include <string.h>
|
2001-12-10 01:13:39 +01:00
|
|
|
#include <time.h>
|
2001-04-26 19:41:06 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
static void
|
|
|
|
info_email(const char * str, void * data, const char * cmd)
|
2001-12-10 01:13:39 +01:00
|
|
|
{
|
|
|
|
unused(str);
|
|
|
|
unused(data);
|
|
|
|
unused(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
info_name(const char * str, void * data, const char * cmd)
|
2001-04-26 19:41:06 +02:00
|
|
|
{
|
|
|
|
unit * u = (unit*)data;
|
2001-12-10 01:13:39 +01:00
|
|
|
faction * f = u->faction;
|
|
|
|
const char * name = sqlquote(igetstrtoken(str));
|
2001-04-26 19:41:06 +02:00
|
|
|
|
2001-12-10 01:13:39 +01:00
|
|
|
if (sqlstream!=NULL) {
|
|
|
|
fprintf(sqlstream, "UPDATE users SET firstname = '%s' WHERE id = %u;\n",
|
|
|
|
name, f->unique_id);
|
2001-04-26 19:41:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-12-10 01:13:39 +01:00
|
|
|
info_address(const char * str, void * data, const char * cmd)
|
|
|
|
{
|
|
|
|
unit * u = (unit*)data;
|
|
|
|
faction * f = u->faction;
|
|
|
|
const char * address = sqlquote(igetstrtoken(str));
|
|
|
|
|
|
|
|
if (sqlstream!=NULL) {
|
|
|
|
fprintf(sqlstream, "UPDATE users SET address = '%s' WHERE id = %u;\n",
|
|
|
|
address, f->unique_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
info_phone(const char * str, void * data, const char * cmd)
|
2001-04-26 19:41:06 +02:00
|
|
|
{
|
|
|
|
unit * u = (unit*)data;
|
2001-12-10 01:13:39 +01:00
|
|
|
faction * f = u->faction;
|
|
|
|
const char * phone = sqlquote(igetstrtoken(str));
|
2001-04-26 19:41:06 +02:00
|
|
|
|
2001-12-10 01:13:39 +01:00
|
|
|
if (sqlstream!=NULL) {
|
|
|
|
fprintf(sqlstream, "UPDATE users SET phone = '%s' WHERE id = %u;\n",
|
|
|
|
phone, f->unique_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
info_vacation(const char * str, void * data, const char * cmd)
|
|
|
|
{
|
|
|
|
unit * u = (unit*)data;
|
|
|
|
faction * f = u->faction;
|
|
|
|
const char * email = sqlquote(igetstrtoken(str));
|
|
|
|
int duration = atoi(getstrtoken());
|
|
|
|
time_t start_time = time(NULL);
|
|
|
|
time_t end_time = start_time + 60*60*24*duration;
|
|
|
|
struct tm start = *localtime(&start_time);
|
|
|
|
struct tm end = *localtime(&end_time);
|
|
|
|
|
|
|
|
if (sqlstream!=NULL) {
|
|
|
|
fprintf(sqlstream, "UPDATE factions SET vacation = '%s' WHERE id = '%s';\n", email, itoa36(f->no));
|
|
|
|
fprintf(sqlstream, "UPDATE factions SET vacation_start = '%04d-%02d-%02d' WHERE id = '%s';\n",
|
|
|
|
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",
|
|
|
|
end.tm_year, end.tm_mon, end.tm_mday, itoa36(f->no));
|
2001-04-26 19:41:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static tnode g_keys;
|
|
|
|
|
|
|
|
void
|
|
|
|
infocommands(void)
|
|
|
|
{
|
|
|
|
region ** rp = ®ions;
|
|
|
|
while (*rp) {
|
|
|
|
region * r = *rp;
|
|
|
|
unit **up = &r->units;
|
|
|
|
while (*up) {
|
|
|
|
unit * u = *up;
|
|
|
|
strlist * order;
|
|
|
|
for (order = u->orders; order; order = order->next)
|
|
|
|
if (igetkeyword(order->s, u->faction->locale) == K_INFO) {
|
|
|
|
do_command(&g_keys, u, order->s);
|
|
|
|
}
|
|
|
|
if (u==*up) up = &u->next;
|
|
|
|
}
|
|
|
|
if (*rp==r) rp = &r->next;
|
|
|
|
}
|
2001-12-10 01:13:39 +01:00
|
|
|
fflush(sqlstream);
|
2001-04-26 19:41:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
info_command(const char * str, void * data, const char * cmd)
|
|
|
|
{
|
|
|
|
do_command(&g_keys, data, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-12-10 01:13:39 +01:00
|
|
|
init_info(void)
|
2001-04-26 19:41:06 +02:00
|
|
|
{
|
2002-02-23 12:30:41 +01:00
|
|
|
add_command(&g_keys, "info", &info_command);
|
2001-12-10 01:13:39 +01:00
|
|
|
|
2002-02-23 12:30:41 +01:00
|
|
|
add_command(&g_keys, "email", &info_email);
|
|
|
|
add_command(&g_keys, "name", &info_name);
|
|
|
|
add_command(&g_keys, "adresse", &info_address);
|
|
|
|
add_command(&g_keys, "telefon", &info_phone);
|
|
|
|
add_command(&g_keys, "urlaub", &info_vacation);
|
2001-04-26 19:41:06 +02:00
|
|
|
}
|