2017-11-09 19:55:28 +01:00
|
|
|
#include <platform.h>
|
2018-09-28 20:50:24 +02:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "db/driver.h"
|
|
|
|
|
2017-11-09 19:55:28 +01:00
|
|
|
#include "orderdb.h"
|
|
|
|
|
|
|
|
#include <util/log.h>
|
|
|
|
|
|
|
|
#include <critbit.h>
|
|
|
|
|
2017-12-12 09:19:35 +01:00
|
|
|
#include <assert.h>
|
2017-11-09 19:55:28 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2018-09-28 20:50:24 +02:00
|
|
|
void orderdb_open(void)
|
|
|
|
{
|
|
|
|
const char *dbname;
|
|
|
|
|
|
|
|
dbname = config_get("game.dbswap");
|
|
|
|
db_driver_open(DB_SWAP, dbname);
|
|
|
|
}
|
|
|
|
|
|
|
|
void orderdb_close(void)
|
|
|
|
{
|
|
|
|
db_driver_close(DB_SWAP);
|
|
|
|
}
|
|
|
|
|
2017-11-09 19:55:28 +01:00
|
|
|
void odata_create(order_data **pdata, size_t len, const char *str)
|
|
|
|
{
|
|
|
|
order_data *data;
|
|
|
|
char *result;
|
|
|
|
|
2017-12-12 09:19:35 +01:00
|
|
|
assert(pdata);
|
2017-11-09 19:55:28 +01:00
|
|
|
data = malloc(sizeof(order_data) + len + 1);
|
|
|
|
data->_refcount = 1;
|
|
|
|
result = (char *)(data + 1);
|
|
|
|
data->_str = (len > 0) ? result : NULL;
|
2017-12-12 09:19:35 +01:00
|
|
|
if (str) {
|
|
|
|
strcpy(result, str);
|
|
|
|
}
|
|
|
|
*pdata = data;
|
2017-11-09 19:55:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void odata_release(order_data * od)
|
|
|
|
{
|
|
|
|
if (od) {
|
|
|
|
if (--od->_refcount == 0) {
|
|
|
|
free(od);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-10 07:56:56 +01:00
|
|
|
void odata_addref(order_data *od)
|
|
|
|
{
|
|
|
|
++od->_refcount;
|
|
|
|
}
|
|
|
|
|
2017-11-09 19:55:28 +01:00
|
|
|
order_data *odata_load(int id)
|
|
|
|
{
|
2018-09-28 20:50:24 +02:00
|
|
|
if (id > 0) {
|
|
|
|
return db_driver_order_load(id);
|
|
|
|
}
|
|
|
|
return NULL;
|
2017-11-09 19:55:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int odata_save(order_data *od)
|
|
|
|
{
|
2018-09-28 20:50:24 +02:00
|
|
|
if (od->_str) {
|
|
|
|
return db_driver_order_save(od->_str);
|
|
|
|
}
|
|
|
|
return 0;
|
2017-11-09 19:55:28 +01:00
|
|
|
}
|