2013-01-19 15:18:36 -08:00
|
|
|
/* -*- compile-command: "make MEMDEBUG=TRUE -j3"; -*- */
|
2003-11-01 05:35:29 +00:00
|
|
|
/*
|
2013-01-19 15:18:36 -08:00
|
|
|
* Copyright 2001-2013 by Eric House (xwords@eehouse.org). All rights
|
2007-05-26 14:14:01 +00:00
|
|
|
* reserved.
|
2003-11-01 05:35:29 +00:00
|
|
|
*
|
|
|
|
* 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 _MAIN_H_
|
|
|
|
#define _MAIN_H_
|
|
|
|
|
2007-06-02 02:07:45 +00:00
|
|
|
#ifdef XWFEATURE_BLUETOOTH
|
|
|
|
# include <bluetooth/bluetooth.h> /* for bdaddr_t, which should move */
|
|
|
|
#endif
|
2006-08-26 21:15:20 +00:00
|
|
|
|
2013-01-05 16:08:47 -08:00
|
|
|
#include <sqlite3.h>
|
|
|
|
|
2003-11-01 05:35:29 +00:00
|
|
|
#include "comtypes.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "game.h"
|
|
|
|
#include "vtabmgr.h"
|
|
|
|
|
|
|
|
typedef struct ServerInfo {
|
|
|
|
XP_U16 nRemotePlayers;
|
|
|
|
/* CommPipeCtxt* pipe; */
|
|
|
|
} ServerInfo;
|
|
|
|
|
|
|
|
typedef struct ClientInfo {
|
|
|
|
} ClientInfo;
|
|
|
|
|
|
|
|
typedef struct LinuxUtilCtxt {
|
|
|
|
UtilVtable* vtable;
|
|
|
|
} LinuxUtilCtxt;
|
|
|
|
|
2013-01-16 06:46:33 -08:00
|
|
|
typedef void (*SockReceiver)( void* closure, int socket );
|
|
|
|
typedef void (*NewSocketProc)( void* closure, int newSock, int oldSock,
|
|
|
|
SockReceiver proc, void* procClosure );
|
|
|
|
|
2003-11-01 05:35:29 +00:00
|
|
|
typedef struct LaunchParams {
|
|
|
|
/* CommPipeCtxt* pipe; */
|
2013-01-07 06:10:44 -08:00
|
|
|
CurGameInfo pgi;
|
|
|
|
|
2012-09-03 21:33:46 -07:00
|
|
|
GSList* dictDirs;
|
2003-11-01 05:35:29 +00:00
|
|
|
char* fileName;
|
2013-01-07 08:00:47 -08:00
|
|
|
char* dbName;
|
2013-01-29 07:42:10 -08:00
|
|
|
sqlite3* pDb; /* null unless opened */
|
2012-09-11 07:26:17 -07:00
|
|
|
XP_U16 saveFailPct;
|
2012-08-22 07:35:18 -07:00
|
|
|
const XP_UCHAR* playerDictNames[MAX_NUM_PLAYERS];
|
2012-07-29 08:37:08 -07:00
|
|
|
#ifdef USE_SQLITE
|
2012-07-26 20:44:33 -07:00
|
|
|
char* dbFileName;
|
|
|
|
XP_U32 dbFileID;
|
2012-07-29 08:37:08 -07:00
|
|
|
#endif
|
2013-01-16 06:46:33 -08:00
|
|
|
void* relayConStorage; /* opaque outside of relaycon.c */
|
2011-01-23 21:52:26 -08:00
|
|
|
char* pipe;
|
2011-09-30 06:32:21 -07:00
|
|
|
char* nbs;
|
2011-04-10 13:04:05 -07:00
|
|
|
char* bonusFile;
|
2012-10-30 07:01:47 -07:00
|
|
|
#ifdef XWFEATURE_DEVID
|
|
|
|
char* devID;
|
2012-11-03 10:58:01 -07:00
|
|
|
char* rDevID;
|
2013-01-29 07:42:10 -08:00
|
|
|
XP_Bool noAnonDevid;
|
|
|
|
XP_UCHAR devIDStore[16];
|
2012-10-30 07:01:47 -07:00
|
|
|
#endif
|
2003-11-01 05:35:29 +00:00
|
|
|
VTableMgr* vtMgr;
|
|
|
|
XP_U16 nLocalPlayers;
|
2006-05-17 06:10:24 +00:00
|
|
|
XP_U16 nHidden;
|
2011-07-31 22:23:46 -07:00
|
|
|
XP_U16 gameSeed;
|
2011-06-20 18:55:57 -07:00
|
|
|
XP_S16 dropNthRcvd; /* negative means use for random calc */
|
|
|
|
XP_U16 nPacketsRcvd; /* toward dropNthRcvd */
|
2012-05-23 19:58:03 -07:00
|
|
|
XP_U16 undoRatio;
|
2003-11-01 05:35:29 +00:00
|
|
|
XP_Bool askNewGame;
|
2008-10-26 15:33:21 +00:00
|
|
|
XP_S16 quitAfter;
|
2003-11-01 05:35:29 +00:00
|
|
|
XP_Bool sleepOnAnchor;
|
|
|
|
XP_Bool printHistory;
|
|
|
|
XP_Bool undoWhenDone;
|
|
|
|
XP_Bool verticalScore;
|
2008-12-29 03:09:35 +00:00
|
|
|
XP_Bool hideValues;
|
2010-01-26 04:14:18 +00:00
|
|
|
XP_Bool showColors;
|
2010-07-17 06:22:42 -07:00
|
|
|
XP_Bool allowPeek;
|
2010-06-17 18:10:32 -07:00
|
|
|
XP_Bool sortNewTiles;
|
2009-11-08 17:25:19 +00:00
|
|
|
XP_Bool skipCommitConfirm;
|
2009-02-28 18:52:44 +00:00
|
|
|
XP_Bool needsNewGame;
|
2003-11-01 05:35:29 +00:00
|
|
|
// XP_Bool mainParams;
|
|
|
|
XP_Bool skipWarnings;
|
|
|
|
XP_Bool showRobotScores;
|
2005-09-03 15:39:15 +00:00
|
|
|
XP_Bool noHeartbeat;
|
2009-09-26 13:47:51 +00:00
|
|
|
XP_Bool duplicatePackets;
|
2010-03-28 16:08:54 +00:00
|
|
|
XP_Bool skipGameOver;
|
2011-07-18 18:07:15 -07:00
|
|
|
XP_Bool useMmap;
|
2013-06-10 06:15:36 -07:00
|
|
|
XP_Bool closeStdin;
|
2013-08-06 21:10:42 -07:00
|
|
|
XP_Bool useUdp;
|
2013-06-27 07:00:36 -07:00
|
|
|
XP_U16 splitPackets;
|
2013-06-24 18:37:49 -07:00
|
|
|
XP_U16 chatsInterval; /* 0 means disabled */
|
2008-04-08 03:55:53 +00:00
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
XP_Bool allowHintRect;
|
|
|
|
#endif
|
2011-12-06 18:17:55 -08:00
|
|
|
#ifdef XWFEATURE_CROSSHAIRS
|
|
|
|
XP_Bool hideCrosshairs;
|
|
|
|
#endif
|
|
|
|
|
2009-07-09 12:43:51 +00:00
|
|
|
#ifdef XWFEATURE_SLOW_ROBOT
|
|
|
|
XP_U16 robotThinkMin, robotThinkMax;
|
2012-05-02 20:14:42 -07:00
|
|
|
XP_U16 robotTradePct;
|
2009-07-09 12:43:51 +00:00
|
|
|
#endif
|
|
|
|
|
2007-02-02 08:34:37 +00:00
|
|
|
DeviceRole serverRole;
|
2003-11-01 05:35:29 +00:00
|
|
|
|
2006-08-26 21:15:20 +00:00
|
|
|
CommsConnType conType;
|
2007-11-26 02:58:25 +00:00
|
|
|
struct {
|
2006-10-10 01:34:37 +00:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2006-08-26 21:15:20 +00:00
|
|
|
struct {
|
|
|
|
char* relayName;
|
2009-09-14 03:11:11 +00:00
|
|
|
char* invite;
|
2006-08-26 21:15:20 +00:00
|
|
|
short defaultSendPort;
|
2010-09-14 21:13:45 -07:00
|
|
|
XP_Bool seeksPublicRoom;
|
|
|
|
XP_Bool advertiseRoom;
|
2006-08-26 21:15:20 +00:00
|
|
|
} relay;
|
2006-10-10 01:34:37 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XWFEATURE_BLUETOOTH
|
2006-08-26 21:15:20 +00:00
|
|
|
struct {
|
|
|
|
bdaddr_t hostAddr; /* unused if a host */
|
|
|
|
} bt;
|
2007-11-26 02:58:25 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XWFEATURE_IP_DIRECT
|
|
|
|
struct {
|
|
|
|
const char* hostName;
|
|
|
|
int port;
|
|
|
|
} ip;
|
2008-12-29 01:35:29 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XWFEATURE_SMS
|
|
|
|
struct {
|
|
|
|
const char* serverPhone;
|
|
|
|
int port;
|
|
|
|
} sms;
|
2006-10-10 01:34:37 +00:00
|
|
|
#endif
|
2006-08-26 21:15:20 +00:00
|
|
|
} connInfo;
|
|
|
|
|
2003-11-01 05:35:29 +00:00
|
|
|
union {
|
|
|
|
ServerInfo serverInfo;
|
|
|
|
ClientInfo clientInfo;
|
|
|
|
} info;
|
2013-01-07 06:10:44 -08:00
|
|
|
MPSLOT
|
2003-11-01 05:35:29 +00:00
|
|
|
} LaunchParams;
|
|
|
|
|
2006-09-10 19:01:06 +00:00
|
|
|
typedef struct CommonGlobals CommonGlobals;
|
|
|
|
|
2007-11-26 02:58:25 +00:00
|
|
|
typedef void (*SocketChangedFunc)(void* closure, int oldsock, int newsock,
|
|
|
|
void** storage );
|
2006-09-10 19:01:06 +00:00
|
|
|
typedef XP_Bool (*Acceptor)( int sock, void* ctxt );
|
|
|
|
typedef void (*AddAcceptorFunc)(int listener, Acceptor func,
|
2007-11-28 03:59:26 +00:00
|
|
|
CommonGlobals* globals, void** storage );
|
2005-03-19 22:07:53 +00:00
|
|
|
|
2008-12-29 01:35:29 +00:00
|
|
|
#ifdef XWFEATURE_SMS
|
|
|
|
typedef struct LinSMSData LinSMSData;
|
|
|
|
#endif
|
|
|
|
|
2009-07-10 05:04:04 +00:00
|
|
|
typedef struct _TimerInfo {
|
|
|
|
XWTimerProc proc;
|
|
|
|
void* closure;
|
2011-09-19 18:28:19 -07:00
|
|
|
#ifdef USE_GLIBLOOP
|
|
|
|
struct CommonGlobals* globals;
|
|
|
|
#else
|
2009-07-10 05:04:04 +00:00
|
|
|
XP_U32 when; /* used only for ncurses */
|
2011-09-19 18:28:19 -07:00
|
|
|
#endif
|
2009-07-10 05:04:04 +00:00
|
|
|
} TimerInfo;
|
|
|
|
|
2013-01-09 06:30:52 -08:00
|
|
|
typedef void (*OnSaveFunc)( void* closure, sqlite3_int64 rowid,
|
|
|
|
XP_Bool firstTime );
|
2013-01-07 08:00:47 -08:00
|
|
|
|
2006-09-10 19:01:06 +00:00
|
|
|
struct CommonGlobals {
|
2003-11-01 05:35:29 +00:00
|
|
|
LaunchParams* params;
|
2011-01-24 22:20:47 -08:00
|
|
|
CommonPrefs cp;
|
2013-01-07 06:10:44 -08:00
|
|
|
XW_UtilCtxt* util;
|
2003-11-01 05:35:29 +00:00
|
|
|
|
|
|
|
XWGame game;
|
2013-07-09 18:10:41 -07:00
|
|
|
CurGameInfo* gi;
|
2013-01-07 08:00:47 -08:00
|
|
|
CommsAddrRec addr;
|
2013-01-07 06:10:44 -08:00
|
|
|
DictionaryCtxt* dict;
|
|
|
|
PlayerDicts dicts;
|
2003-11-30 19:09:39 +00:00
|
|
|
XP_U16 lastNTilesToUse;
|
2012-09-11 19:07:00 -07:00
|
|
|
XP_U16 lastStreamSize;
|
2012-10-07 12:47:06 -07:00
|
|
|
XP_Bool manualFinal; /* use asked for final scores */
|
2013-01-05 16:08:47 -08:00
|
|
|
sqlite3* pDb;
|
2013-01-05 21:01:26 -08:00
|
|
|
sqlite3_int64 selRow;
|
2006-08-26 21:15:20 +00:00
|
|
|
|
2005-03-19 22:07:53 +00:00
|
|
|
SocketChangedFunc socketChanged;
|
|
|
|
void* socketChangedClosure;
|
2013-01-09 06:30:52 -08:00
|
|
|
OnSaveFunc onSave;
|
|
|
|
void* onSaveClosure;
|
2013-06-27 07:00:36 -07:00
|
|
|
GSList* packetQueue;
|
|
|
|
XP_U32 nextPacketID; /* for debugging */
|
2005-06-23 04:20:00 +00:00
|
|
|
|
2009-09-20 18:45:25 +00:00
|
|
|
CommsRelayState state;
|
|
|
|
|
2006-09-10 19:01:06 +00:00
|
|
|
/* Allow listener sockets to be installed in either gtk or ncurses'
|
|
|
|
* polling mechanism.*/
|
|
|
|
AddAcceptorFunc addAcceptor;
|
|
|
|
Acceptor acceptor;
|
2011-11-17 19:56:36 -08:00
|
|
|
|
2011-11-21 17:57:38 -08:00
|
|
|
/* hash by relayID of lists of messages */
|
|
|
|
GHashTable* noConnMsgs;
|
2006-09-10 19:01:06 +00:00
|
|
|
|
2007-11-26 02:58:25 +00:00
|
|
|
#ifdef XWFEATURE_RELAY
|
|
|
|
int socket; /* relay */
|
|
|
|
void* storage;
|
2006-09-19 03:39:08 +00:00
|
|
|
char* defaultServerName;
|
2007-11-26 02:58:25 +00:00
|
|
|
#endif
|
2006-09-19 03:39:08 +00:00
|
|
|
|
2007-11-26 02:58:25 +00:00
|
|
|
#if defined XWFEATURE_BLUETOOTH
|
2006-09-19 03:39:08 +00:00
|
|
|
struct LinBtStuff* btStuff;
|
2007-11-26 02:58:25 +00:00
|
|
|
#endif
|
|
|
|
#if defined XWFEATURE_IP_DIRECT
|
|
|
|
struct LinUDPStuff* udpStuff;
|
|
|
|
#endif
|
2008-12-29 01:35:29 +00:00
|
|
|
#ifdef XWFEATURE_SMS
|
|
|
|
LinSMSData* smsData;
|
|
|
|
#endif
|
2006-08-26 21:15:20 +00:00
|
|
|
|
2009-07-10 05:04:04 +00:00
|
|
|
TimerInfo timerInfo[NUM_TIMERS_PLUS_ONE];
|
2012-09-10 07:31:45 -07:00
|
|
|
|
|
|
|
XP_U16 curSaveToken;
|
2006-09-10 19:01:06 +00:00
|
|
|
};
|
2003-11-01 05:35:29 +00:00
|
|
|
|
2013-01-16 06:46:33 -08:00
|
|
|
typedef struct _SourceData {
|
|
|
|
GIOChannel* channel;
|
|
|
|
gint watch;
|
|
|
|
SockReceiver proc;
|
|
|
|
void* procClosure;
|
|
|
|
} SourceData;
|
|
|
|
|
2013-01-15 19:04:20 -08:00
|
|
|
typedef struct _GtkAppGlobals {
|
2013-01-16 21:16:07 -08:00
|
|
|
GArray* selRows;
|
2013-01-05 19:40:29 -08:00
|
|
|
LaunchParams* params;
|
2013-01-07 06:10:44 -08:00
|
|
|
GSList* globalsList;
|
2013-01-16 06:46:33 -08:00
|
|
|
GList* sources;
|
2013-01-19 15:18:36 -08:00
|
|
|
GtkWidget* window;
|
2013-01-07 08:00:47 -08:00
|
|
|
GtkWidget* listWidget;
|
2013-01-16 21:16:07 -08:00
|
|
|
GtkWidget* openButton;
|
|
|
|
GtkWidget* deleteButton;
|
2013-01-15 19:04:20 -08:00
|
|
|
} GtkAppGlobals;
|
2013-01-05 19:40:29 -08:00
|
|
|
|
2013-01-16 21:16:07 -08:00
|
|
|
sqlite3_int64 getSelRow( const GtkAppGlobals* apg );
|
|
|
|
|
2003-11-01 05:35:29 +00:00
|
|
|
#endif
|