2016-08-26 07:26:33 -07:00
|
|
|
/* -*- compile-command: "make MEMDEBUG=TRUE -j5"; -*- */
|
2013-01-05 16:08:19 -08:00
|
|
|
/*
|
2016-08-26 07:26:33 -07:00
|
|
|
* Copyright 2000 - 2016 by Eric House (xwords@eehouse.org). All rights
|
2013-01-05 16:08:19 -08:00
|
|
|
* reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _GAMESDB_H_
|
|
|
|
#define _GAMESDB_H_
|
|
|
|
|
|
|
|
#include <sqlite3.h>
|
2013-01-05 19:40:29 -08:00
|
|
|
#include <glib.h>
|
2013-01-05 16:08:19 -08:00
|
|
|
|
2013-01-05 19:40:29 -08:00
|
|
|
#include "main.h"
|
2013-01-05 16:08:47 -08:00
|
|
|
#include "comtypes.h"
|
|
|
|
|
2013-01-09 06:30:52 -08:00
|
|
|
typedef struct _GameInfo {
|
|
|
|
XP_UCHAR name[128];
|
|
|
|
XP_UCHAR room[128];
|
2014-11-02 17:25:56 -08:00
|
|
|
XP_UCHAR conn[128];
|
2017-10-21 14:59:10 -07:00
|
|
|
XP_UCHAR relayID[32];
|
2016-12-22 08:57:54 -08:00
|
|
|
#ifdef PLATFORM_GTK
|
2016-08-05 08:29:25 -07:00
|
|
|
GdkPixbuf* snap;
|
2016-12-22 08:57:54 -08:00
|
|
|
#endif
|
2013-12-16 08:06:29 -08:00
|
|
|
XP_U32 gameID;
|
2013-01-09 06:30:52 -08:00
|
|
|
XP_S16 nMoves;
|
|
|
|
XP_Bool gameOver;
|
2016-08-26 07:26:33 -07:00
|
|
|
XP_Bool turnLocal;
|
2013-01-09 06:30:52 -08:00
|
|
|
XP_S16 turn;
|
2015-07-06 20:28:16 -07:00
|
|
|
XP_U16 nTotal;
|
2013-01-09 06:30:52 -08:00
|
|
|
XP_S16 nMissing;
|
2013-07-11 20:01:17 -07:00
|
|
|
XP_U16 seed;
|
2016-07-25 08:28:37 -07:00
|
|
|
XP_U32 lastMoveTime;
|
2013-01-09 06:30:52 -08:00
|
|
|
} GameInfo;
|
|
|
|
|
2013-01-07 08:00:47 -08:00
|
|
|
sqlite3* openGamesDB( const char* dbName );
|
2013-01-05 16:08:19 -08:00
|
|
|
void closeGamesDB( sqlite3* dbp );
|
|
|
|
|
2013-01-05 16:08:47 -08:00
|
|
|
void writeToDB( XWStreamCtxt* stream, void* closure );
|
2015-07-06 20:28:16 -07:00
|
|
|
sqlite3_int64 writeNewGameToDB( XWStreamCtxt* stream, sqlite3* pDb );
|
|
|
|
|
2013-01-09 06:30:52 -08:00
|
|
|
void summarize( CommonGlobals* cGlobals );
|
2013-01-05 16:08:47 -08:00
|
|
|
|
2013-01-05 19:40:29 -08:00
|
|
|
/* Return GSList whose data is (ptrs to) rowids */
|
2013-01-24 07:49:49 -08:00
|
|
|
GSList* listGames( sqlite3* dbp );
|
2017-10-22 09:29:15 -07:00
|
|
|
/* Mapping of relayID -> rowid */
|
|
|
|
GHashTable* getRelayIDsToRowsMap( sqlite3* pDb );
|
2017-10-21 16:05:54 -07:00
|
|
|
|
2013-01-24 07:49:49 -08:00
|
|
|
XP_Bool getGameInfo( sqlite3* dbp, sqlite3_int64 rowid, GameInfo* gib );
|
2013-12-16 08:06:29 -08:00
|
|
|
void getRowsForGameID( sqlite3* dbp, XP_U32 gameID, sqlite3_int64* rowids,
|
|
|
|
int* nRowIDs );
|
2013-01-05 21:01:26 -08:00
|
|
|
XP_Bool loadGame( XWStreamCtxt* stream, sqlite3* pDb, sqlite3_int64 rowid );
|
2015-07-06 20:28:16 -07:00
|
|
|
void saveInviteAddrs( XWStreamCtxt* stream, sqlite3* pDb,
|
|
|
|
sqlite3_int64 rowid );
|
|
|
|
XP_Bool loadInviteAddrs( XWStreamCtxt* stream, sqlite3* pDb,
|
|
|
|
sqlite3_int64 rowid );
|
2013-01-16 21:11:35 -08:00
|
|
|
void deleteGame( sqlite3* pDb, sqlite3_int64 rowid );
|
2013-01-05 19:40:29 -08:00
|
|
|
|
2013-01-16 06:46:33 -08:00
|
|
|
#define KEY_RDEVID "RDEVID"
|
2013-09-14 21:06:14 -07:00
|
|
|
#define KEY_LDEVID "LDEVID"
|
2013-12-12 06:08:56 -08:00
|
|
|
#define KEY_SMSPHONE "SMSPHONE"
|
2013-12-19 08:00:04 -08:00
|
|
|
#define KEY_SMSPORT "SMSPORT"
|
2016-08-05 18:31:17 -07:00
|
|
|
#define KEY_WIN_LOC "WIN_LOC"
|
2013-01-16 06:46:33 -08:00
|
|
|
|
2013-01-19 14:37:49 -08:00
|
|
|
void db_store( sqlite3* dbp, const gchar* key, const gchar* value );
|
2013-01-29 07:42:10 -08:00
|
|
|
XP_Bool db_fetch( sqlite3* dbp, const gchar* key, gchar* buf, gint buflen );
|
2013-01-19 14:37:49 -08:00
|
|
|
void db_remove( sqlite3* dbp, const gchar* key );
|
2013-01-16 06:46:33 -08:00
|
|
|
|
2013-01-05 16:08:19 -08:00
|
|
|
#endif
|