Crossfire Server, Trunk
|
#include <cflogger.h>
#include <cflogger_proto.h>
#include <sqlite3.h>
#include <stdlib.h>
#include <string.h>
#include <svnversion.h>
Go to the source code of this file.
Macros | |
#define | CFLOGGER_CURRENT_FORMAT 3 |
#define | DO_OR_ROLLBACK(sqlstring) |
#define | UPDATE_OR_ROLLBACK(tbl, newschema, select_columns) |
Functions | |
static void | add_death (object *victim, object *killer) |
static void | add_map_event (mapstruct *map, int event_code, object *pl) |
static void | add_player_event (object *pl, int event_code) |
int | cflogger_globalEventListener (int *type,...) |
int | cflogger_runPluginCommand (object *op, char *params) |
static void | check_tables (void) |
static int | check_tables_callback (void *param, int argc, char **argv, char **azColName) |
int | closePlugin (void) |
static int | do_sql (const char *sql) |
int | eventListener (int *type,...) |
static int | get_living_id (object *living) |
static int | get_map_id (mapstruct *map) |
static int | get_region_id (region *reg) |
void * | getPluginProperty (int *type,...) |
int | initPlugin (const char *iversion, f_plug_api gethooksptr) |
int | postInitPlugin (void) |
static int | store_time (void) |
static int | update_table_format (const char *table, const char *newschema, const char *select_columns) |
Variables | |
static sqlite3 * | database |
static int | last_stored_day = -1 |
CF_PLUGIN char | SvnRevPlugin [] = SVN_REV |
This plugin will log events to an sqlite3 database named cflogger.db in the var directory.
Log includes:
Definition in file cflogger.cpp.
#define CFLOGGER_CURRENT_FORMAT 3 |
Current database format
Definition at line 58 of file cflogger.cpp.
#define DO_OR_ROLLBACK | ( | sqlstring | ) |
Helper macros for rolling back and returning if query failed. Used in check_tables().
Yes they are quite messy. The alternatives seemed worse.
Definition at line 181 of file cflogger.cpp.
#define UPDATE_OR_ROLLBACK | ( | tbl, | |
newschema, | |||
select_columns | |||
) |
Definition at line 190 of file cflogger.cpp.
Logs a death.
If either of the parameters is NULL, or if neither is a PLAYER, nothing is logged.
victim | who died. |
killer | who killed. |
Definition at line 517 of file cflogger.cpp.
References cf_object_get_object_property(), CFAPI_OBJECT_PROP_OWNER, do_sql(), get_living_id(), get_map_id(), sword_of_souls::killer, PLAYER, object::type, and sword_of_souls::victim.
Referenced by cflogger_globalEventListener().
Logs an event for a map.
map | map for which to log an event. |
event_code | arbitrary event code. |
pl | object causing the event. Can be NULL. |
Definition at line 493 of file cflogger.cpp.
References do_sql(), get_living_id(), get_map_id(), disinfect::map, altar_valkyrie::pl, and PLAYER.
Referenced by cflogger_globalEventListener().
|
static |
Logs an event for a living object.
pl | object for which to log an event. |
event_code | arbitrary event code. |
Definition at line 467 of file cflogger.cpp.
References do_sql(), get_living_id(), get_map_id(), and altar_valkyrie::pl.
Referenced by cflogger_globalEventListener().
int cflogger_globalEventListener | ( | int * | type, |
... | |||
) |
Handles a global event.
type | ignored. |
Definition at line 626 of file cflogger.cpp.
References add_death(), add_map_event(), add_player_event(), make_face_from_files::args, EVENT_BORN, EVENT_CLOCK, EVENT_GKILL, EVENT_KICK, EVENT_LOGIN, EVENT_LOGOUT, EVENT_MAPENTER, EVENT_MAPLEAVE, EVENT_MAPLOAD, EVENT_MAPRESET, EVENT_MAPUNLOAD, EVENT_MUZZLE, EVENT_PLAYER_DEATH, EVENT_REMOVE, sword_of_souls::killer, disinfect::map, give::op, altar_valkyrie::pl, store_time(), and is_valid_types_gen::type.
Referenced by postInitPlugin().
int cflogger_runPluginCommand | ( | object * | op, |
char * | params | ||
) |
Runs a plugin command. Doesn't do anything.
op | ignored. |
params | ignored. |
Definition at line 602 of file cflogger.cpp.
|
static |
Checks the database format, and applies changes if old version.
Definition at line 202 of file cflogger.cpp.
References cf_log(), CFLOGGER_CURRENT_FORMAT, check_tables_callback(), database, DO_OR_ROLLBACK, do_sql(), llevDebug, llevError, PLUGIN_NAME, and UPDATE_OR_ROLLBACK.
Referenced by postInitPlugin().
|
static |
Simple callback to get an integer from a query.
param | user-supplied data. |
argc | number of items. |
argv | values. |
azColName | column names. |
Definition at line 81 of file cflogger.cpp.
Referenced by check_tables().
int closePlugin | ( | void | ) |
Close the plugin.
Closes the sqlite database.
Definition at line 748 of file cflogger.cpp.
References cf_log(), database, llevInfo, and PLUGIN_VERSION.
|
static |
Helper function to run a SQL query.
Will LOG() an error if the query fails.
sql | query to run. |
Definition at line 103 of file cflogger.cpp.
References cf_log(), database, llevError, navar-midane_pickup::msg, and PLUGIN_NAME.
Referenced by add_death(), add_map_event(), add_player_event(), check_tables(), get_living_id(), get_map_id(), get_region_id(), store_time(), and update_table_format().
int eventListener | ( | int * | type, |
... | |||
) |
Handles an object-related event. Doesn't do anything.
type | ignored. |
Definition at line 614 of file cflogger.cpp.
|
static |
Returns a unique identifier for specified object.
Will insert an item in the table if required.
If the object is a player, only name is taken into account to generate an id.
Else, the object's level is taken into account, to distinguish monsters with the same name and different levels (special monsters, and such).
living | object to get identifier for. |
Definition at line 326 of file cflogger.cpp.
References database, do_sql(), diamondslots::id, is_valid_types_gen::line, and PLAYER.
Referenced by add_death(), add_map_event(), and add_player_event().
|
static |
Gets the unique identifier for a map.
Will generate one if required.
Maps starting with '/random/' will all share the same identifier for the same region.
map | map for which an id is wanted. Must not be NULL. |
Definition at line 396 of file cflogger.cpp.
References database, do_sql(), get_region_id(), diamondslots::id, is_valid_types_gen::line, disinfect::map, and python_init::path.
Referenced by add_death(), add_map_event(), and add_player_event().
|
static |
Gets the unique identifier for a region.
Will generate one if required.
reg | region for which an id is wanted |
Definition at line 360 of file cflogger.cpp.
References database, do_sql(), diamondslots::id, is_valid_types_gen::line, and region::name.
Referenced by get_map_id().
void* getPluginProperty | ( | int * | type, |
... | |||
) |
Gets a plugin property.
type | ignored. |
Definition at line 566 of file cflogger.cpp.
References make_face_from_files::args, buf, PLUGIN_NAME, PLUGIN_VERSION, and is_valid_types_gen::type.
int initPlugin | ( | const char * | iversion, |
f_plug_api | gethooksptr | ||
) |
Main plugin entry point.
iversion | server version. |
gethooksptr | function to get hooks from. |
Definition at line 550 of file cflogger.cpp.
References cf_init_plugin(), cf_log(), llevInfo, and PLUGIN_VERSION.
int postInitPlugin | ( | void | ) |
Plugin was initialized, now to finish.
Registers events, initializes the database.
Definition at line 697 of file cflogger.cpp.
References cf_get_directory(), cf_log(), cf_system_register_global_event(), cflogger_globalEventListener(), check_tables(), database, EVENT_BORN, EVENT_CLOCK, EVENT_GKILL, EVENT_KICK, EVENT_LOGIN, EVENT_LOGOUT, EVENT_MAPENTER, EVENT_MAPLEAVE, EVENT_MAPLOAD, EVENT_MAPRESET, EVENT_MAPUNLOAD, EVENT_MUZZLE, EVENT_PLAYER_DEATH, EVENT_REMOVE, llevDebug, llevError, llevInfo, python_init::path, PLUGIN_NAME, PLUGIN_VERSION, and store_time().
|
static |
Stores a line to match current ingame and real time.
Definition at line 429 of file cflogger.cpp.
References cf_get_time(), database, send::date, timeofday_t::day, do_sql(), timeofday_t::hour, last_stored_day, is_valid_types_gen::line, timeofday_t::minute, timeofday_t::month, and timeofday_t::year.
Referenced by cflogger_globalEventListener(), and postInitPlugin().
|
static |
Updates a table to a new schema, used for when ALTER TABLE doesn't work. (Such as when changing column constraints.)
table | Name of table. |
newschema | This is the new table format. Will be inserted into the parantheses of "create table table_name()". |
select_columns | This is inserted into "INSERT INTO table_name SELECT _ FROM ..." to allow changing order of columns, or skipping some. Normally it should be "*". |
No error checking is done. Also it is expected that appending an _old on the table name won't collide with anything.
Note that columns are expected to have same (or compatible) type, and be in the same order. Further both tables should have the same number of columns.
Definition at line 144 of file cflogger.cpp.
References do_sql().
|
static |
Pointer to the logging database.
Definition at line 61 of file cflogger.cpp.
Referenced by check_tables(), closePlugin(), do_sql(), get_living_id(), get_map_id(), get_region_id(), postInitPlugin(), and store_time().
|
static |
To keep track of stored ingame/real time matching.
Definition at line 64 of file cflogger.cpp.
Referenced by store_time().
Definition at line 55 of file cflogger.cpp.