50 static void do_sql(
const char *sql, sqlite3 *base) {
57 err = sqlite3_exec(base, sql, NULL, NULL, &msg);
58 if (err != SQLITE_OK) {
67 int nrow, ncolumn, id;
70 sql = sqlite3_mprintf(
"select liv_id from living where liv_name='%q' and liv_is_player = 1", living->
name);
72 sql = sqlite3_mprintf(
"select liv_id from living where liv_name='%q' and liv_is_player = 0 and liv_level = %d", living->
name, living->
level);
76 id = atoi(line[ncolumn]);
79 sql = sqlite3_mprintf(
"insert into living(liv_name, liv_is_player, liv_level) values('%q', %d, %d)", living->
name, living->
type ==
PLAYER ? 1 : 0, living->
level);
84 sqlite3_free_table(line);
91 int nrow, ncolumn, id;
96 sql = sqlite3_mprintf(
"select reg_id from region where reg_name='%q'", reg->
name);
100 id = atoi(line[ncolumn]);
103 sql = sqlite3_mprintf(
"insert into region(reg_name) values( '%q' )", reg->
name);
108 sqlite3_free_table(line);
119 int nrow, ncolumn,
id = 0;
124 sql = sqlite3_mprintf(
"select time_id from time where time_time='%q'", date);
127 id = atoi(line[ncolumn]);
130 sql = sqlite3_mprintf(
"insert into time(time_time) values( '%q' )", date);
135 sqlite3_free_table(line);
150 const char *propname;
154 va_start(args, type);
155 propname = va_arg(args,
const char *);
157 if (!strcmp(propname,
"Identification")) {
158 buf = va_arg(args,
char *);
159 size = va_arg(args,
int);
165 if (!strcmp(propname,
"FullName")) {
166 buf = va_arg(args,
char *);
167 size = va_arg(args,
int);
186 va_start(args, type);
187 event_code = va_arg(args,
int);
189 switch (event_code) {
203 snprintf(path, 500,
"%s/cflogger.db", dir);
212 snprintf(path, 500,
"%s/cfnewspaper.db", dir);
252 static void news_cat(
char *buffer,
int size,
const char *format, ...) {
255 size -= strlen(buffer)-1;
256 buffer += strlen(buffer);
258 va_start(args, format);
259 vsprintf(buffer, format, args);
263 static void do_kills(
char *buffer,
int size, time_t start, time_t end,
const char *reg,
kill_format *format) {
270 const char *raw =
"select sum(1) as deaths from kill_event inner join living on liv_id = ke_victim_id where liv_is_player = %d and ke_time >= %d and ke_time < %d %s";
272 sql = sqlite3_mprintf(raw, 1, start, end, reg);
273 err = sqlite3_get_table(
logger_database, sql, &results, &nrow, &ncolumn, &msg);
274 if (err != SQLITE_OK) {
278 if (nrow > 0 && results[ncolumn] != NULL)
279 deaths = atoi(results[ncolumn]);
280 sqlite3_free_table(results);
284 else if (deaths == 1)
290 sql = sqlite3_mprintf(raw, 0, start, end);
291 err = sqlite3_get_table(
logger_database, sql, &results, &nrow, &ncolumn, &msg);
292 if (err != SQLITE_OK) {
296 if (nrow > 0 && results[ncolumn] != NULL)
297 deaths = atoi(results[ncolumn]);
298 sqlite3_free_table(results);
302 else if (deaths == 1)
317 f.
no_monster_death =
"No monster was killed, players were lazy around here.";
322 snprintf(where, 50,
"and map_reg_id = %d", region_id);
324 do_kills(buffer, size, start, end, where, &f);
327 static void do_region(
region *reg,
char *buffer,
int size, time_t start, time_t end) {
328 news_cat(buffer, size,
"--- local %s news ---\n", reg->
name);
337 f.
one_player_death =
"Only one player died in the whole world, May Fido(tm) Have Mercy.";
338 f.
many_player_death =
"Monsters all around the world were busy, %d players died.";
339 f.
no_monster_death =
"No monster was killed at all, players must be tired!";
340 f.
one_monster_death =
"One poor monster was killed in the whole, too bad for it.";
342 do_kills(buffer, size, start, end,
"", &f);
345 static void do_world(
char *buffer,
int size, time_t start, time_t end) {
346 news_cat(buffer, size,
"--- worldnews section ---\n");
368 sql = sqlite3_mprintf(
"select * from time where time_ingame < '%q' order by time_ingame desc", date);
369 err = sqlite3_get_table(
logger_database, sql, &results, &nrow, &ncolumn, &msg);
370 if (err != SQLITE_OK) {
374 if (nrow > 1 && results[ncolumn+1] != NULL) {
375 end = atol(results[ncolumn+1]);
376 if (nrow > 1 && results[ncolumn+2] != NULL)
377 start = atol(results[ncolumn+2]);
383 do_region(reg, contents, 5000, start, end);
386 do_world(contents, 5000, start, end);
405 va_start(args, type);
406 who = va_arg(args,
object *);
408 activator = va_arg(args,
object *);
409 third = va_arg(args,
object *);
410 buf = va_arg(args,
char *);
411 fix = va_arg(args,
int);
413 event = va_arg(args,
object *);
414 event_code =
event->subtype;
static paper_properties * get_newspaper(const char *name)
#define CFAPI_OBJECT_PROP_NAME
void cf_get_time(timeofday_t *tod)
static void do_region(region *reg, char *buffer, int size, time_t start, time_t end)
static sqlite3 * logger_database
static int get_time_id(timeofday_t *tod, int create)
struct kill_format kill_format
region * cf_map_get_region_property(mapstruct *map, int propcode)
CF_PLUGIN void * getPluginProperty(int *type,...)
static paper_properties default_properties
static void get_newspaper_content(object *paper, paper_properties *properties, region *reg)
#define CFAPI_OBJECT_PROP_NAME_PLURAL
f_plug_api unregisterGlobalEvent
void *(* f_plug_api)(int *type,...)
#define CFAPI_OBJECT_PROP_MESSAGE
f_plug_api registerGlobalEvent
void cf_log(LogLevel logLevel, const char *format,...)
static void do_world_kills(char *buffer, int size, time_t start, time_t end)
static sqlite3 * newspaper_database
CF_PLUGIN int postInitPlugin(void)
int cf_init_plugin(f_plug_api getHooks)
CF_PLUGIN int closePlugin(void)
object * cf_object_insert_object(object *op, object *container)
static void read_parameters(void)
static void news_cat(char *buffer, int size, const char *format,...)
CF_PLUGIN void * eventListener(int *type,...)
int snprintf(char *dest, int max, const char *format,...)
static void do_region_kills(region *reg, char *buffer, int size, time_t start, time_t end)
static void do_kills(char *buffer, int size, time_t start, time_t end, const char *reg, kill_format *format)
static void format_time(timeofday_t *tod, char *buffer, int size)
#define CFAPI_MAP_PROP_REGION
const char * cf_get_directory(int id)
static int get_living_id(object *living)
static int get_region_id(region *reg)
void cf_object_set_string_property(object *op, int propcode, const char *value)
CF_PLUGIN int initPlugin(const char *iversion, f_plug_api gethooksptr)
CF_PLUGIN void * cfnewspaper_globalEventListener(int *type,...)
static void do_world(char *buffer, int size, time_t start, time_t end)
object * cf_create_object_by_name(const char *name)
static void do_sql(const char *sql, sqlite3 *base)
CF_PLUGIN int cfnewspaper_runPluginCommand(object *op, char *params)
struct paper_properties paper_properties