 |
Crossfire Server, Trunk
1.75.0
|
Go to the documentation of this file.
58 #define CFLOGGER_CURRENT_FORMAT 3
82 int *format = (
int *)param;
84 *format = atoi(argv[0]);
110 err = sqlite3_exec(
database, sql, NULL, NULL, &msg);
111 if (err != SQLITE_OK) {
145 const char *select_columns) {
149 sql = sqlite3_mprintf(
"ALTER TABLE %s RENAME TO %s_old;", table, table);
152 if (err != SQLITE_OK)
155 sql = sqlite3_mprintf(
"CREATE TABLE %s(%s);", table, newschema);
158 if (err != SQLITE_OK)
161 sql = sqlite3_mprintf(
"INSERT INTO %s SELECT %s FROM %s_old;",
162 table, select_columns, table);
165 if (err != SQLITE_OK)
168 sql = sqlite3_mprintf(
"DROP TABLE %s_old;", table, table);
181 #define DO_OR_ROLLBACK(sqlstring) \
182 if (do_sql(sqlstring) != SQLITE_OK) { \
183 do_sql("rollback transaction;"); \
184 cf_log(llevError, " [%s] Logger database format update failed! Couldn't upgrade from format %d to fromat %d!. Won't log.\n", PLUGIN_NAME, format, CFLOGGER_CURRENT_FORMAT);\
185 sqlite3_close(database); \
190 #define UPDATE_OR_ROLLBACK(tbl, newschema, select_columns) \
191 if (update_table_format((tbl), (newschema), (select_columns)) != SQLITE_OK) { \
192 do_sql("rollback transaction;"); \
193 cf_log(llevError, " [%s] Logger database format update failed! Couldn't upgrade from format %d to fromat %d!. Won't log.\n", PLUGIN_NAME, format, CFLOGGER_CURRENT_FORMAT);\
194 sqlite3_close(database); \
222 if (
do_sql(
"BEGIN EXCLUSIVE TRANSACTION;") != SQLITE_OK) {
228 DO_OR_ROLLBACK(
"create table living(liv_id integer primary key autoincrement, liv_name text, liv_is_player integer, liv_level integer);");
229 DO_OR_ROLLBACK(
"create table region(reg_id integer primary key autoincrement, reg_name text);");
230 DO_OR_ROLLBACK(
"create table map(map_id integer primary key autoincrement, map_path text, map_reg_id integer);");
231 DO_OR_ROLLBACK(
"create table time(time_real integer, time_ingame text);");
233 DO_OR_ROLLBACK(
"create table living_event(le_liv_id integer, le_time integer, le_code integer, le_map_id integer);");
234 DO_OR_ROLLBACK(
"create table map_event(me_map_id integer, me_time integer, me_code integer, me_living_id integer);");
235 DO_OR_ROLLBACK(
"create table kill_event(ke_time integer, ke_victim_id integer, ke_victim_level integer, ke_map_id integer , ke_killer_id integer, ke_killer_level integer);");
237 DO_OR_ROLLBACK(
"create table parameters(param_name text, param_value text);");
238 DO_OR_ROLLBACK(
"insert into parameters values( 'version', '1' );");
239 do_sql(
"COMMIT TRANSACTION;");
249 if (
do_sql(
"BEGIN EXCLUSIVE TRANSACTION;") != SQLITE_OK) {
258 UPDATE_OR_ROLLBACK(
"living",
"liv_id INTEGER PRIMARY KEY AUTOINCREMENT, liv_name TEXT NOT NULL, liv_is_player INTEGER NOT NULL, liv_level INTEGER NOT NULL",
"*");
259 UPDATE_OR_ROLLBACK(
"region",
"reg_id INTEGER PRIMARY KEY AUTOINCREMENT, reg_name TEXT UNIQUE NOT NULL",
"*");
260 UPDATE_OR_ROLLBACK(
"map",
"map_id INTEGER PRIMARY KEY AUTOINCREMENT, map_path TEXT NOT NULL, map_reg_id INTEGER NOT NULL, CONSTRAINT map_path_reg_id UNIQUE(map_path, map_reg_id)",
"*");
263 UPDATE_OR_ROLLBACK(
"time",
"time_real INTEGER PRIMARY KEY, time_ingame TEXT UNIQUE NOT NULL");
265 UPDATE_OR_ROLLBACK(
"living_event",
"le_liv_id INTEGER NOT NULL, le_time INTEGER NOT NULL, le_code INTEGER NOT NULL, le_map_id INTEGER NOT NULL",
"*");
266 UPDATE_OR_ROLLBACK(
"map_event",
"me_map_id INTEGER NOT NULL, me_time INTEGER NOT NULL, me_code INTEGER NOT NULL, me_living_id INTEGER NOT NULL",
"*");
267 UPDATE_OR_ROLLBACK(
"kill_event",
"ke_time INTEGER NOT NULL, ke_victim_id INTEGER NOT NULL, ke_victim_level INTEGER NOT NULL, ke_map_id INTEGER NOT NULL, ke_killer_id INTEGER NOT NULL, ke_killer_level INTEGER NOT NULL",
"*");
278 DO_OR_ROLLBACK(
"CREATE TABLE parameters(param_name TEXT NOT NULL PRIMARY KEY, param_value TEXT);");
279 DO_OR_ROLLBACK(
"INSERT INTO parameters (param_name, param_value) VALUES( 'version', '2' );");
282 DO_OR_ROLLBACK(
"CREATE INDEX living_name_player_level ON living(liv_name,liv_is_player,liv_level);");
285 DO_OR_ROLLBACK(
"CREATE INDEX kill_event_time ON kill_event(ke_time);");
289 do_sql(
"COMMIT TRANSACTION;");
294 if (
do_sql(
"BEGIN EXCLUSIVE TRANSACTION;") != SQLITE_OK) {
300 UPDATE_OR_ROLLBACK(
"time",
"time_ingame TEXT NOT NULL PRIMARY KEY, time_real INTEGER NOT NULL",
"time_ingame, time_real");
301 DO_OR_ROLLBACK(
"UPDATE parameters SET param_value = '3' WHERE param_name = 'version';");
302 do_sql(
"COMMIT TRANSACTION;");
329 int nrow, ncolumn, id;
332 sql = sqlite3_mprintf(
"select liv_id from living where liv_name='%q' and liv_is_player = 1",
living->name);
334 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);
335 sqlite3_get_table(
database, sql, &
line, &nrow, &ncolumn, NULL);
338 id = atoi(
line[ncolumn]);
341 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);
343 id = sqlite3_last_insert_rowid(
database);
346 sqlite3_free_table(
line);
363 int nrow, ncolumn, id;
368 sql = sqlite3_mprintf(
"select reg_id from region where reg_name='%q'", reg->
name);
369 sqlite3_get_table(
database, sql, &
line, &nrow, &ncolumn, NULL);
372 id = atoi(
line[ncolumn]);
375 sql = sqlite3_mprintf(
"insert into region(reg_name) values( '%q' )", reg->
name);
377 id = sqlite3_last_insert_rowid(
database);
380 sqlite3_free_table(
line);
399 int nrow, ncolumn, id, reg_id;
402 if (strncmp(
path,
"/random/", 7) == 0)
406 sql = sqlite3_mprintf(
"select map_id from map where map_path='%q' and map_reg_id = %d",
path, reg_id);
407 sqlite3_get_table(
database, sql, &
line, &nrow, &ncolumn, NULL);
410 id = atoi(
line[ncolumn]);
413 sql = sqlite3_mprintf(
"insert into map(map_path, map_reg_id) values( '%q', %d)",
path, reg_id);
415 id = sqlite3_last_insert_rowid(
database);
418 sqlite3_free_table(
line);
446 sql = sqlite3_mprintf(
"select * from time where time_ingame='%q'", date);
447 sqlite3_get_table(
database, sql, &
line, &nrow, &ncolumn, NULL);
449 sqlite3_free_table(
line);
453 sql = sqlite3_mprintf(
"insert into time (time_ingame, time_real) values( '%s', %d )", date, now);
478 sql = sqlite3_mprintf(
"insert into living_event values( %d, %d, %d, %d)",
id,
time(NULL), event_code, map_id);
502 sql = sqlite3_mprintf(
"insert into map_event values( %d, %d, %d, %d)", mapid,
time(NULL), event_code, playerid);
518 int vid, kid, map_id;
521 if (!victim || !killer)
535 sql = sqlite3_mprintf(
"insert into kill_event values( %d, %d, %d, %d, %d, %d)",
time(NULL), vid, victim->
level, map_id, kid, killer->
level);
568 const char *propname;
572 va_start(args,
type);
573 propname = va_arg(args,
const char *);
575 if (!strcmp(propname,
"Identification")) {
576 buf = va_arg(args,
char *);
577 size = va_arg(args,
int);
581 }
else if (!strcmp(propname,
"FullName")) {
582 buf = va_arg(args,
char *);
583 size = va_arg(args,
int);
634 va_start(args,
type);
635 event_code = va_arg(args,
int);
637 switch (event_code) {
642 op = va_arg(args,
object *);
647 op = va_arg(args,
object *);
648 va_arg(args,
object *);
654 pl = va_arg(args,
player *);
660 op = va_arg(args,
object *);
674 op = va_arg(args,
object *);
675 killer = va_arg(args,
object *);
704 snprintf(
path,
sizeof(
path),
"%s/cflogger.db", dir);
void cf_log(LogLevel logLevel, const char *format,...)
Wrapper for LOG().
struct region * region
What jurisdiction in the game world this map is ruled by points to the struct containing all the prop...
static int do_sql(const char *sql)
Helper function to run a SQL query.
const char * cf_get_directory(int id)
Gets a directory Crossfire uses.
@ llevError
Error, serious thing.
static int check_tables_callback(void *param, int argc, char **argv, char **azColName)
Simple callback to get an integer from a query.
int postInitPlugin(void)
Plugin was initialized, now to finish.
static int update_table_format(const char *table, const char *newschema, const char *select_columns)
Updates a table to a new schema, used for when ALTER TABLE doesn't work.
object * cf_object_get_object_property(object *op, int propcode)
#define UPDATE_OR_ROLLBACK(tbl, newschema, select_columns)
static void add_map_event(mapstruct *map, int event_code, object *pl)
Logs an event for a map.
static int get_map_id(mapstruct *map)
Gets the unique identifier for a map.
object * ob
The object representing the player.
struct mapstruct * map
Pointer to the map in which this object is present.
static int get_region_id(region *reg)
Gets the unique identifier for a region.
Represents the ingame time.
non standard information is not specified or uptime this means how long since the executable has been started A particular host may have been running a server for quite a long time
#define EVENT_MAPLOAD
A map is loaded (pristine state)
#define EVENT_LOGOUT
Player logout.
int closePlugin(void)
Close the plugin.
void * getPluginProperty(int *type,...)
Gets a plugin property.
char * name
Shortend name of the region as maps refer to it.
char path[HUGE_BUF]
Filename of the map.
int16_t level
Level of creature or object.
#define EVENT_LOGIN
Player login.
#define EVENT_CLOCK
Global time event.
int cflogger_runPluginCommand(object *op, char *params)
Runs a plugin command.
void(* f_plug_api)(int *type,...)
General API function.
#define EVENT_MAPENTER
A player entered a map.
int cf_init_plugin(f_plug_api getHooks)
#define EVENT_MAPRESET
A map is resetting.
#define EVENT_BORN
A new character has been created.
uint8_t type
PLAYER, BULLET, etc.
#define EVENT_MAPUNLOAD
A map is freed (includes swapping out)
int cflogger_globalEventListener(int *type,...)
Handles a global event.
#define CFLOGGER_CURRENT_FORMAT
Current database format.
static void add_player_event(object *pl, int event_code)
Logs an event for a living object.
static int store_time(void)
Stores a line to match current ingame and real time.
#define CFAPI_OBJECT_PROP_OWNER
Various statistics of objects.
int eventListener(int *type,...)
Handles an object-related event.
static int last_stored_day
To keep track of stored ingame/real time matching.
pluglist shows those as well as a short text describing each the list will simply appear empty The keyword for the Python plugin is Python plugout< keyword > Unloads a given identified by its _keyword_ So if you want to unload the Python you need to do plugout Python plugin< libname > Loads a given whose _filename_ is libname So in the case of you d have to do a plugin cfpython so Note that all filenames are relative to the default plugin path(SHARE/plugins). Console messages. ----------------- When Crossfire starts
#define EVENT_PLAYER_DEATH
Global Death event
CF_PLUGIN char SvnRevPlugin[]
void cf_system_register_global_event(int event, const char *name, f_plug_event hook)
#define EVENT_MUZZLE
A player was Muzzled (no_shout set).
static void add_death(object *victim, object *killer)
Logs a death.
static sqlite3 * database
Pointer to the logging database.
#define EVENT_MAPLEAVE
A player left a map.
#define EVENT_REMOVE
A Player character has been removed.
static int get_living_id(object *living)
Returns a unique identifier for specified object.
#define DO_OR_ROLLBACK(sqlstring)
Helper macros for rolling back and returning if query failed.
static void check_tables(void)
Checks the database format, and applies changes if old version.
int initPlugin(const char *iversion, f_plug_api gethooksptr)
Main plugin entry point.
#define EVENT_GKILL
Triggered when anything got killed by anyone.
#define EVENT_KICK
A player was Kicked by a DM
void cf_get_time(timeofday_t *tod)
@ llevDebug
Only for debugging purposes.