_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
db.cpp File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "stratagus.h"
#include "sqlite3.h"
#include "games.h"

db.cpp - Database routines.

#define SQLCreatePlayersTable
 
#define SQLCreateGamesTable
 
#define SQLCreateGameDataTable
 
#define SQLCreateRankingsTable
 
#define SQLCreateMapsTable
 
#define SQLCreateTables
 
static const char * dbfile = "metaserver.db"
 
static sqlite3 * DB
 
static int DBMaxIDCallback (void *password, int argc, char **argv, char **colname)
 
int DBInit (void)
 
void DBQuit (void)
 
static int DBFindUserCallback (void *password, int argc, char **argv, char **colname)
 
int DBFindUser (char *username, char *password)
 
int DBAddUser (char *username, char *password)
 
int DBUpdateLoginDate (char *username)
 

Macro Definition Documentation

#define SQLCreateGameDataTable
Value:
"CREATE TABLE game_data (" \
"id INTEGER," \
"username TEXT," \
"result INTEGER," \
"score INTEGER," \
"units INTEGER," \
"buildings INTEGER," \
"res1 INTEGER, res2 INTEGER, res3 INTEGER, res4 INTEGER, res5 INTEGER, res6 INTEGER," \
"res1_used INTEGER, res2_used INTEGER, res3_used INTEGER, res4_used INTEGER, res5_used INTEGER, res6_used INTEGER," \
"kills INTEGER," \
"razings INTEGER," \
"gamecycle INTEGER," \
"PRIMARY KEY (id, username));"
#define SQLCreateGamesTable
Value:
"CREATE TABLE games (" \
"date INTEGER," \
"id INTEGER PRIMARY KEY," \
"gamename TEXT," \
"map_id INTEGER" \
");"
#define SQLCreateMapsTable
Value:
"CREATE TABLE maps (" \
"map_id INTEGER PRIMARY KEY," \
"map_name TEXT," \
"map_filename TEXT," \
"map_uuid TEXT," \
"map_size_x INTEGER," \
"map_size_y INTEGER" \
");"
#define SQLCreatePlayersTable
Value:
"CREATE TABLE players (" \
"username TEXT PRIMARY KEY," \
"password TEXT," \
"register_date INTEGER," \
"last_login_date INTEGER" \
");"
#define SQLCreateRankingsTable
Value:
"CREATE TABLE rankings (" \
"username TEXT," \
"gamename TEXT," \
"ranking INTEGER," \
"PRIMARY KEY (username, gamename)" \
");"
#define SQLCreateTables
Value:
#define SQLCreatePlayersTable
Definition: db.cpp:52
#define SQLCreateRankingsTable
Definition: db.cpp:83
#define SQLCreateMapsTable
Definition: db.cpp:91
#define SQLCreateGamesTable
Definition: db.cpp:60

Function Documentation

int DBAddUser ( char *  username,
char *  password 
)

Add a user

Parameters
usernameUser name
passwordPassword
Returns
0 for success, non-zero otherwise
int DBFindUser ( char *  username,
char *  password 
)

Find a user and return the password

Parameters
usernameUser name to find
passwordIf the user is found the password will be returned here
Returns
1 if user is found, 0 otherwise
static int DBFindUserCallback ( void *  password,
int  argc,
char **  argv,
char **  colname 
)
static

Find user callback

int DBInit ( void  )

Initialize the database

Returns
0 for success, non-zero for failure
static int DBMaxIDCallback ( void *  password,
int  argc,
char **  argv,
char **  colname 
)
static

Max id callback

void DBQuit ( void  )

Close the database

int DBUpdateLoginDate ( char *  username)

Log in a user

Parameters
usernameUser name
Returns
0 for success, non-zero otherwise

Variable Documentation

sqlite3* DB
static
const char* dbfile = "metaserver.db"
static
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.