Merge branch 'android_branch' into android_translate

This commit is contained in:
Eric House 2020-01-10 14:03:12 -08:00
commit 8291b70842
23 changed files with 269 additions and 89 deletions

View file

@ -1,6 +1,6 @@
def INITIAL_CLIENT_VERS = 9 def INITIAL_CLIENT_VERS = 9
def VERSION_CODE_BASE = 148 def VERSION_CODE_BASE = 149
def VERSION_NAME = '4.4.152' def VERSION_NAME = '4.4.153'
def FABRIC_API_KEY = System.getenv("FABRIC_API_KEY") def FABRIC_API_KEY = System.getenv("FABRIC_API_KEY")
def BUILD_INFO_NAME = "build-info.txt" def BUILD_INFO_NAME = "build-info.txt"

View file

@ -13,9 +13,9 @@
</style> </style>
</head> </head>
<body> <body>
<h2>CrossWords 4.4.152 release</h2> <h2>CrossWords 4.4.153 release</h2>
<p>This release fixes a nasty crash in some non-English versions.</p> <p>This release fixes a crash sending invitations via SMS/Text.</p>
<div id="survey"> <div id="survey">
<p>Please <a href="https://www.surveymonkey.com/s/GX3XLHR">take <p>Please <a href="https://www.surveymonkey.com/s/GX3XLHR">take
@ -23,17 +23,13 @@
CrossWords.</p> CrossWords.</p>
</div> </div>
<h3>New with this (and previous) release</h3> <h3>New with this release</h3>
<ul> <ul>
<li>Fix crash with some localized versions (Weblate problem...)</li> <li>Stop crashing when attempting to send an invitation via SMS (Text message)</li>
<li>Tweak network traffic arrows on game board</li> <li>Fix email invitations</li>
<li>Fix crash dragging tiles</li> <li>Add don't-show-again checkbox to request for permission to check state of phone</li>
<li>Fix invite-via-NFC for Android 10 (and improve for earlier <li>Include new translations in French and Spanish (via Weblate)</li>
Android versions)</li> <li>Change copyright date: Happy 2020!</li>
<li>Add ability to send moves via NFC</li>
<li>More translations (via Weblate) in Catalan, French, German,
Japanese, Norwegian, Polish, and Spanish</li>
<li>Fix a couple of other crashes reported via Google (thanks!)</li>
</ul> </ul>
<p>(The full changelog <p>(The full changelog

View file

@ -755,9 +755,10 @@ public class BoardDelegate extends DelegateBase
// straight to asking for the permission. // straight to asking for the permission.
private void callInviteChoices( final SentInvitesInfo info ) private void callInviteChoices( final SentInvitesInfo info )
{ {
Perms23.tryGetPerms( this, Perm.READ_PHONE_STATE, Perms23.tryGetPermsNA( this, Perm.READ_PHONE_STATE,
R.string.phone_state_rationale, R.string.phone_state_rationale,
Action.ASKED_PHONE_STATE, info ); R.string.key_na_perms_phonestate,
Action.ASKED_PHONE_STATE, info );
} }
private void showInviteChoicesThen( Object[] params ) private void showInviteChoicesThen( Object[] params )
@ -1260,7 +1261,8 @@ public class BoardDelegate extends DelegateBase
break; break;
default: default:
handled = false; handled = super.onDismissed( action, params );
break;
} }
return handled; return handled;
} }

View file

@ -792,9 +792,20 @@ public class DelegateBase implements DlgClickNotify,
public boolean onDismissed( Action action, Object[] params ) public boolean onDismissed( Action action, Object[] params )
{ {
Log.d( TAG, "%s.dlgDismissed(%s)", getClass().getSimpleName(), boolean handled = false;
Log.d( TAG, "%s.onDismissed(%s)", getClass().getSimpleName(),
action.toString() ); action.toString() );
return false;
switch( action ) {
case PERMS_QUERY:
handled = true;
Perms23.onGotPermsAction( this, false, params );
break;
default:
Log.e( TAG, "onDismissed(): not handling action %s", action );
}
return handled;
} }
public void inviteChoiceMade( Action action, DlgClickNotify.InviteMeans means, Object... params ) public void inviteChoiceMade( Action action, DlgClickNotify.InviteMeans means, Object... params )

View file

@ -783,9 +783,10 @@ public class GameConfigDelegate extends DelegateBase
private void showConnAfterCheck() private void showConnAfterCheck()
{ {
if ( null == SMSPhoneInfo.get( m_activity ) ) { if ( null == SMSPhoneInfo.get( m_activity ) ) {
Perms23.tryGetPerms( this, Perms23.Perm.READ_PHONE_STATE, Perms23.tryGetPermsNA( this, Perms23.Perm.READ_PHONE_STATE,
R.string.phone_state_rationale, R.string.phone_state_rationale,
Action.ASKED_PHONE_STATE ); R.string.key_na_perms_phonestate,
Action.ASKED_PHONE_STATE );
} else { } else {
showDialogFragment( DlgID.CHANGE_CONN, m_conTypes ); showDialogFragment( DlgID.CHANGE_CONN, m_conTypes );
} }

View file

@ -217,9 +217,13 @@ public class NetLaunchInfo implements Serializable {
p2pMacAddress = data.getQueryParameter( P2P_MAC_KEY ); p2pMacAddress = data.getQueryParameter( P2P_MAC_KEY );
doAdd = !hasAddrs && null != p2pMacAddress; doAdd = !hasAddrs && null != p2pMacAddress;
break; break;
case COMMS_CONN_NFC:
doAdd = true;
break;
default: default:
doAdd = false; doAdd = false;
Assert.fail(); Log.d( TAG, "unexpected type: %s", typ );
Assert.assertFalse( BuildConfig.DEBUG );
} }
if ( doAdd ) { if ( doAdd ) {
m_addrs.add( typ ); m_addrs.add( typ );
@ -691,7 +695,7 @@ public class NetLaunchInfo implements Serializable {
private void calcValid() private void calcValid()
{ {
boolean valid = hasCommon() && null != m_addrs; boolean valid = hasCommon() && null != m_addrs;
// DbgUtils.logf( "calcValid(%s)", toString() ); // Log.d( TAG, "calcValid(%s); valid (so far): %b", this, valid );
if ( valid ) { if ( valid ) {
for ( Iterator<CommsConnType> iter = m_addrs.iterator(); for ( Iterator<CommsConnType> iter = m_addrs.iterator();
valid && iter.hasNext(); ) { valid && iter.hasNext(); ) {

View file

@ -203,23 +203,26 @@ public class Perms23 {
private static class QueryInfo { private static class QueryInfo {
private Action m_action; private Action m_action;
private Perm[] m_perms; private Perm[] m_perms;
private int mNAKey;
private DelegateBase m_delegate; private DelegateBase m_delegate;
private String m_rationaleMsg; private String m_rationaleMsg;
private Object[] m_params; private Object[] m_params;
private QueryInfo( DelegateBase delegate, Action action, private QueryInfo( DelegateBase delegate, Action action,
Perm[] perms, String msg, Object[] params ) { Perm[] perms, String msg, int naKey,
Object[] params ) {
m_delegate = delegate; m_delegate = delegate;
m_action = action; m_action = action;
m_perms = perms; m_perms = perms;
m_rationaleMsg = msg; m_rationaleMsg = msg;
mNAKey = naKey;
m_params = params; m_params = params;
} }
private QueryInfo( DelegateBase delegate, Object[] params ) private QueryInfo( DelegateBase delegate, Object[] params )
{ {
this( delegate, (Action)params[0], (Perm[])params[1], (String)params[2], this( delegate, (Action)params[0], (Perm[])params[1], (String)params[2],
(Object[])params[3] ); 0, (Object[])params[3] );
} }
private Object[] getParams() private Object[] getParams()
@ -260,6 +263,7 @@ public class Perms23 {
.setPosButton( R.string.button_ask_again ) .setPosButton( R.string.button_ask_again )
.setNegButton( R.string.button_skip ) .setNegButton( R.string.button_skip )
.setParams( QueryInfo.this.getParams() ) .setParams( QueryInfo.this.getParams() )
.setNAKey( mNAKey )
.show(); .show();
} }
} ); } );
@ -319,30 +323,36 @@ public class Perms23 {
* Request permissions, giving rationale once, then call with action and * Request permissions, giving rationale once, then call with action and
* either positive or negative, the former if permission granted. * either positive or negative, the former if permission granted.
*/ */
private static void tryGetPermsImpl( DelegateBase delegate, Perm[] perms,
String rationaleMsg, int naKey,
final Action action, Object... params )
{
// Log.d( TAG, "tryGetPerms(%s)", perm.toString() );
new QueryInfo( delegate, action, perms, rationaleMsg, naKey, params )
.doIt( true );
}
public static void tryGetPerms( DelegateBase delegate, Perm[] perms, int rationaleId, public static void tryGetPerms( DelegateBase delegate, Perm[] perms, int rationaleId,
final Action action, Object... params ) final Action action, Object... params )
{ {
// Log.d( TAG, "tryGetPerms(%s)", perm.toString() ); // Log.d( TAG, "tryGetPerms(%s)", perm.toString() );
Context context = XWApp.getContext(); String msg = LocUtils.getStringOrNull( rationaleId );
String msg = rationaleId == 0 tryGetPermsImpl( delegate, perms, msg, 0, action, params );
? null : LocUtils.getString( context, rationaleId );
tryGetPerms( delegate, perms, msg, action, params );
} }
public static void tryGetPerms( DelegateBase delegate, Perm[] perms, public static void tryGetPerms( DelegateBase delegate, Perm[] perms,
String rationaleMsg, final Action action, String rationaleMsg, final Action action,
Object... params ) Object... params )
{ {
// Log.d( TAG, "tryGetPerms(%s)", perm.toString() ); tryGetPermsImpl( delegate, perms, rationaleMsg, 0, action, params );
new QueryInfo( delegate, action, perms, rationaleMsg, params )
.doIt( true );
} }
public static void tryGetPerms( DelegateBase delegate, Perm perm, public static void tryGetPerms( DelegateBase delegate, Perm perm,
String rationaleMsg, final Action action, String rationaleMsg, final Action action,
Object... params ) Object... params )
{ {
tryGetPerms( delegate, new Perm[]{ perm }, rationaleMsg, action, params ); tryGetPermsImpl( delegate, new Perm[]{ perm }, rationaleMsg, 0,
action, params );
} }
public static void tryGetPerms( DelegateBase delegate, Perm perm, int rationaleId, public static void tryGetPerms( DelegateBase delegate, Perm perm, int rationaleId,
@ -351,6 +361,15 @@ public class Perms23 {
tryGetPerms( delegate, new Perm[]{perm}, rationaleId, action, params ); tryGetPerms( delegate, new Perm[]{perm}, rationaleId, action, params );
} }
public static void tryGetPermsNA( DelegateBase delegate, Perm perm,
int rationaleId, int naKey,
Action action, Object... params )
{
tryGetPermsImpl( delegate, new Perm[] {perm},
LocUtils.getStringOrNull( rationaleId ), naKey,
action, params );
}
public static void onGotPermsAction( DelegateBase delegate, boolean positive, public static void onGotPermsAction( DelegateBase delegate, boolean positive,
Object[] params ) Object[] params )
{ {

View file

@ -265,6 +265,16 @@ public class LocUtils {
return getString( context, true, id ); return getString( context, true, id );
} }
public static String getStringOrNull( int id )
{
String result = null;
if ( 0 != id ) {
Context context = XWApp.getContext();
result = getString( context, true, id );
}
return result;
}
public static String getString( Context context, boolean canUseDB, int id ) public static String getString( Context context, boolean canUseDB, int id )
{ {
String result = null; String result = null;

View file

@ -145,6 +145,7 @@
<string name="key_na_bt_badproto">key_na_bt_badproto</string> <string name="key_na_bt_badproto">key_na_bt_badproto</string>
<string name="key_na_sms_banned">key_na_sms_banned</string> <string name="key_na_sms_banned">key_na_sms_banned</string>
<string name="key_na_longtap_lookup">key_na_longtap_lookup</string> <string name="key_na_longtap_lookup">key_na_longtap_lookup</string>
<string name="key_na_perms_phonestate">key_na_perms_phonestate</string>
<!-- Nor is my email address --> <!-- Nor is my email address -->
<string name="email_author_email">xwords@eehouse.org</string> <string name="email_author_email">xwords@eehouse.org</string>

View file

@ -49,6 +49,7 @@ COMMONSRC = \
$(COMMONDIR)/dictmgr.c \ $(COMMONDIR)/dictmgr.c \
$(COMMONDIR)/dbgutil.c \ $(COMMONDIR)/dbgutil.c \
$(COMMONDIR)/smsproto.c \ $(COMMONDIR)/smsproto.c \
$(COMMONDIR)/device.c \
# PENDING: define this in terms of above!!! # PENDING: define this in terms of above!!!
@ -87,5 +88,6 @@ COMMON5 = \
$(COMMONOBJDIR)/dictmgr.o \ $(COMMONOBJDIR)/dictmgr.o \
$(COMMONOBJDIR)/dbgutil.o \ $(COMMONOBJDIR)/dbgutil.o \
$(COMMONOBJDIR)/smsproto.o \ $(COMMONOBJDIR)/smsproto.o \
$(COMMONOBJDIR)/device.o \
COMMONOBJ = $(COMMON1) $(COMMON2) $(COMMON3) $(COMMON4) $(COMMON5) COMMONOBJ = $(COMMON1) $(COMMON2) $(COMMON3) $(COMMON4) $(COMMON5)

79
xwords4/common/device.c Normal file
View file

@ -0,0 +1,79 @@
/* -*- compile-command: "cd ../linux && make MEMDEBUG=TRUE -j3"; -*- */
/*
* Copyright 2020 by Eric House (xwords@eehouse.org). All rights 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.
*/
#include "device.h"
#include "comtypes.h"
#include "memstream.h"
#include "xwstream.h"
#ifdef XWFEATURE_DEVICE
# define KEY_DEVSTATE PERSIST_KEY("devState")
typedef struct _DevCtxt {
XP_U16 devCount;
} DevCtxt;
static XWStreamCtxt*
mkStream( XW_DUtilCtxt* dutil )
{
XWStreamCtxt* stream = mem_stream_make_raw( MPPARM(dutil->mpool)
dutil_getVTManager(dutil) );
return stream;
}
static DevCtxt*
load( XW_DUtilCtxt* dutil )
{
LOG_FUNC();
DevCtxt* state = (DevCtxt*)dutil->devCtxt;
if ( NULL == state ) {
XWStreamCtxt* stream = mkStream( dutil );
dutil_loadStream( dutil, KEY_DEVSTATE, stream );
state = XP_CALLOC( dutil->mpool, sizeof(*state) );
dutil->devCtxt = state;
if ( 0 < stream_getSize( stream ) ) {
state->devCount = stream_getU16( stream );
++state->devCount; /* for testing until something's there */
XP_LOGF( "%s(): read devCount: %d", __func__, state->devCount );
} else {
XP_LOGF( "%s(): empty stream!!", __func__ );
}
stream_destroy( stream );
}
return state;
}
void
device_store( XW_DUtilCtxt* dutil )
{
LOG_FUNC();
DevCtxt* state = load( dutil );
XWStreamCtxt* stream = mkStream( dutil );
stream_putU16( stream, state->devCount );
dutil_storeStream( dutil, KEY_DEVSTATE, stream );
stream_destroy( stream );
XP_FREEP( dutil->mpool, &dutil->devCtxt );
}
#endif

33
xwords4/common/device.h Normal file
View file

@ -0,0 +1,33 @@
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
/*
* Copyright 2020 by Eric House (xwords@eehouse.org). All rights 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 _DEVICE_H_
#define _DEVICE_H_
#include "dutil.h"
// void device_load( XW_DUtilCtxt dctxt );
# ifdef XWFEATURE_DEVICE
void device_store( XW_DUtilCtxt* dctxt );
# else
# define device_store(dctxt)
# endif
#endif

View file

@ -60,8 +60,8 @@ typedef struct _DUtilVtable {
struct XW_DUtilCtxt { struct XW_DUtilCtxt {
DUtilVtable vtable; DUtilVtable vtable;
void* closure; void* closure;
void* devCtxt; /* owned by device.c */
VTableMgr* vtMgr; VTableMgr* vtMgr;
MPSLOT MPSLOT
}; };

View file

@ -42,9 +42,21 @@ nli_init( NetLaunchInfo* nli, const CurGameInfo* gi, const CommsAddrRec* addr,
nli->nPlayersH = nPlayers; nli->nPlayersH = nPlayers;
nli->forceChannel = forceChannel; nli->forceChannel = forceChannel;
if ( addr_hasType( addr, COMMS_CONN_RELAY ) ) { CommsConnType typ;
types_addType( &nli->_conTypes, COMMS_CONN_RELAY ); for ( XP_U32 st = 0; addr_iter( addr, &typ, &st ); ) {
XP_STRCAT( nli->room, addr->u.ip_relay.invite ); types_addType( &nli->_conTypes, typ );
switch ( typ ) {
case COMMS_CONN_RELAY:
XP_STRCAT( nli->room, addr->u.ip_relay.invite );
break;
case COMMS_CONN_SMS:
XP_STRCAT( nli->phone, addr->u.sms.phone );
// nli->port = addr->u.sms.port; <-- I wish
break;
default:
XP_ASSERT(0);
break;
}
} }
} }
@ -159,9 +171,8 @@ nli_makeFromStream( NetLaunchInfo* nli, XWStreamCtxt* stream )
void void
nli_makeAddrRec( const NetLaunchInfo* nli, CommsAddrRec* addr ) nli_makeAddrRec( const NetLaunchInfo* nli, CommsAddrRec* addr )
{ {
XP_U32 state = 0;
CommsConnType type; CommsConnType type;
while ( types_iter( nli->_conTypes, &type, &state ) ) { for ( XP_U32 state = 0; types_iter( nli->_conTypes, &type, &state ); ) {
addr_addType( addr, type ); addr_addType( addr, type );
switch( type ) { switch( type ) {
case COMMS_CONN_RELAY: case COMMS_CONN_RELAY:
@ -176,6 +187,7 @@ nli_makeAddrRec( const NetLaunchInfo* nli, CommsAddrRec* addr )
break; break;
case COMMS_CONN_SMS: case COMMS_CONN_SMS:
XP_STRCAT( addr->u.sms.phone, nli->phone ); XP_STRCAT( addr->u.sms.phone, nli->phone );
addr->u.sms.port = 1; /* BAD, but 0 is worse */
break; break;
default: default:
XP_ASSERT(0); XP_ASSERT(0);

View file

@ -163,6 +163,8 @@ DEFINES += -DXWFEATURE_DIRECTIP
# Robot can be made to think, to simulate for relay mostly # Robot can be made to think, to simulate for relay mostly
DEFINES += -DXWFEATURE_SLOW_ROBOT DEFINES += -DXWFEATURE_SLOW_ROBOT
DEFINES += -DXWFEATURE_DEVICE
# Support device-to-device connection via UDP, e.g. using wifi on a # Support device-to-device connection via UDP, e.g. using wifi on a
# LAN or where the host/server isn't behind a firewall. # LAN or where the host/server isn't behind a firewall.
# DEFINES += -DXWFEATURE_IP_DIRECT # DEFINES += -DXWFEATURE_IP_DIRECT

View file

@ -65,6 +65,7 @@
#include "gamesdb.h" #include "gamesdb.h"
#include "relaycon.h" #include "relaycon.h"
#include "smsproto.h" #include "smsproto.h"
#include "device.h"
#ifdef CURSES_SMALL_SCREEN #ifdef CURSES_SMALL_SCREEN
# define MENU_WINDOW_HEIGHT 1 # define MENU_WINDOW_HEIGHT 1
@ -2239,8 +2240,11 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
endwin(); endwin();
device_store( params->dutil );
if ( !!params->dbName ) { if ( !!params->dbName ) {
closeGamesDB( params->pDb ); closeGamesDB( params->pDb );
params->pDb = NULL;
} }
relaycon_cleanup( params ); relaycon_cleanup( params );

View file

@ -533,8 +533,9 @@ db_fetch( sqlite3* pDb, const gchar* key, gchar* buf, gint* buflen )
XP_ASSERT( !!pDb ); XP_ASSERT( !!pDb );
FetchResult result = NOT_THERE; FetchResult result = NOT_THERE;
char query[256]; char query[256];
snprintf( query, sizeof(query), int len = snprintf( query, sizeof(query),
"SELECT value from pairs where key = '%s'", key ); "SELECT value from pairs where key = '%s'", key );
XP_ASSERT( len < sizeof(query) );
sqlite3_stmt *ppStmt; sqlite3_stmt *ppStmt;
int sqlResult = sqlite3_prepare_v2( pDb, query, -1, &ppStmt, NULL ); int sqlResult = sqlite3_prepare_v2( pDb, query, -1, &ppStmt, NULL );
XP_Bool found = SQLITE_OK == sqlResult; XP_Bool found = SQLITE_OK == sqlResult;

View file

@ -85,7 +85,7 @@ static void handle_invite_button( GtkWidget* widget, GtkGameGlobals* globals );
static void gtkShowFinalScores( const GtkGameGlobals* globals, static void gtkShowFinalScores( const GtkGameGlobals* globals,
XP_Bool ignoreTimeout ); XP_Bool ignoreTimeout );
static void send_invites( CommonGlobals* cGlobals, XP_U16 nPlayers, static void send_invites( CommonGlobals* cGlobals, XP_U16 nPlayers,
XP_U32 devID, const XP_UCHAR* relayID, XP_U32 relayDevID, const XP_UCHAR* relayID,
const CommsAddrRec* addrs ); const CommsAddrRec* addrs );
@ -1556,18 +1556,19 @@ handle_invite_button( GtkWidget* XP_UNUSED(widget), GtkGameGlobals* globals )
CommsAddrRec inviteAddr = {0}; CommsAddrRec inviteAddr = {0};
gint nPlayers = nMissing; gint nPlayers = nMissing;
XP_U32 devID; XP_U32 relayDevID = 0;
XP_Bool confirmed = gtkInviteDlg( globals, &inviteAddr, &nPlayers, &devID ); XP_Bool confirmed = gtkInviteDlg( globals, &inviteAddr, &nPlayers,
&relayDevID );
XP_LOGF( "%s: inviteDlg => %d", __func__, confirmed ); XP_LOGF( "%s: inviteDlg => %d", __func__, confirmed );
if ( confirmed ) { if ( confirmed ) {
send_invites( cGlobals, nPlayers, devID, NULL, &inviteAddr ); send_invites( cGlobals, nPlayers, relayDevID, NULL, &inviteAddr );
} }
} /* handle_invite_button */ } /* handle_invite_button */
static void static void
send_invites( CommonGlobals* cGlobals, XP_U16 nPlayers, send_invites( CommonGlobals* cGlobals, XP_U16 nPlayers,
XP_U32 devID, const XP_UCHAR* relayID, XP_U32 relayDevID, const XP_UCHAR* relayID,
const CommsAddrRec* addrs ) const CommsAddrRec* addrs )
{ {
CommsAddrRec addr = {0}; CommsAddrRec addr = {0};
@ -1579,10 +1580,12 @@ send_invites( CommonGlobals* cGlobals, XP_U16 nPlayers,
NetLaunchInfo nli = {0}; NetLaunchInfo nli = {0};
nli_init( &nli, cGlobals->gi, &addr, nPlayers, forceChannel ); nli_init( &nli, cGlobals->gi, &addr, nPlayers, forceChannel );
XP_UCHAR buf[32]; if ( addr_hasType( &addr, COMMS_CONN_RELAY ) ) {
snprintf( buf, sizeof(buf), "%X", makeRandomInt() ); XP_UCHAR buf[32];
nli_setInviteID( &nli, buf ); snprintf( buf, sizeof(buf), "%X", makeRandomInt() );
nli_setDevID( &nli, linux_getDevIDRelay( cGlobals->params ) ); nli_setInviteID( &nli, buf ); /* should not be relay only!!! */
}
// nli_setDevID( &nli, linux_getDevIDRelay( cGlobals->params ) );
#ifdef DEBUG #ifdef DEBUG
{ {
@ -1603,9 +1606,9 @@ send_invites( CommonGlobals* cGlobals, XP_U16 nPlayers,
linux_sms_invite( cGlobals->params, &nli, linux_sms_invite( cGlobals->params, &nli,
addrs->u.sms.phone, addrs->u.sms.port ); addrs->u.sms.phone, addrs->u.sms.port );
} }
if ( 0 != devID || !!relayID ) { if ( 0 != relayDevID || !!relayID ) {
XP_ASSERT( 0 != devID || (!!relayID && !!relayID[0]) ); XP_ASSERT( 0 != relayDevID || (!!relayID && !!relayID[0]) );
relaycon_invite( cGlobals->params, devID, relayID, &nli ); relaycon_invite( cGlobals->params, relayDevID, relayID, &nli );
} }
/* while ( gtkaskm( "Invite how many and how?", infos, VSIZE(infos) ) ) { */ /* while ( gtkaskm( "Invite how many and how?", infos, VSIZE(infos) ) ) { */

View file

@ -38,7 +38,7 @@ typedef struct _GtkInviteState {
GtkGameGlobals* globals; GtkGameGlobals* globals;
CommsAddrRec* addr; CommsAddrRec* addr;
gint* nPlayersP; gint* nPlayersP;
XP_U32* devIDp; XP_U32* relayDevIDp;
gint maxPlayers; gint maxPlayers;
GtkWidget* nPlayersCombo; GtkWidget* nPlayersCombo;
@ -96,7 +96,7 @@ handle_ok( GtkWidget* XP_UNUSED(widget), gpointer closure )
case COMMS_CONN_RELAY: case COMMS_CONN_RELAY:
txt = gtk_entry_get_text( GTK_ENTRY(state->devID) ); txt = gtk_entry_get_text( GTK_ENTRY(state->devID) );
snprintf( s_devIDBuf, sizeof(s_devIDBuf), "%s", txt ); snprintf( s_devIDBuf, sizeof(s_devIDBuf), "%s", txt );
*state->devIDp = atoi( txt ); *state->relayDevIDp = atoi( txt );
break; break;
#endif #endif
#ifdef XWFEATURE_BLUETOOTH #ifdef XWFEATURE_BLUETOOTH
@ -275,18 +275,15 @@ onPageChanged( GtkNotebook* XP_UNUSED(notebook), gpointer XP_UNUSED(arg1),
XP_Bool XP_Bool
gtkInviteDlg( GtkGameGlobals* globals, CommsAddrRec* addr, gtkInviteDlg( GtkGameGlobals* globals, CommsAddrRec* addr,
gint* nPlayersP, XP_U32* devIDp ) gint* nPlayersP, XP_U32* relayDevIDp )
{ {
GtkInviteState state; GtkInviteState state = {
XP_MEMSET( &state, 0, sizeof(state) ); .globals = globals,
.addr = addr,
state.globals = globals; .nPlayersP = nPlayersP,
state.addr = addr; .relayDevIDp = relayDevIDp,
state.nPlayersP = nPlayersP; .maxPlayers = *nPlayersP,
state.devIDp = devIDp; };
state.maxPlayers = *nPlayersP;
GtkWidget* dialog; GtkWidget* dialog;
GtkWidget* hbox; GtkWidget* hbox;

View file

@ -24,7 +24,7 @@
/* return true if not cancelled */ /* return true if not cancelled */
XP_Bool gtkInviteDlg( GtkGameGlobals* globals, CommsAddrRec* addr, XP_Bool gtkInviteDlg( GtkGameGlobals* globals, CommsAddrRec* addr,
/*inout*/ gint* nPlayers, /* out */ XP_U32* devID ); /*inout*/ gint* nPlayers, /* out */ XP_U32* relayDevID );
#endif #endif

View file

@ -31,6 +31,7 @@
#include "relaycon.h" #include "relaycon.h"
#include "linuxsms.h" #include "linuxsms.h"
#include "gtkask.h" #include "gtkask.h"
#include "device.h"
static void onNewData( GtkAppGlobals* apg, sqlite3_int64 rowid, static void onNewData( GtkAppGlobals* apg, sqlite3_int64 rowid,
XP_Bool isNew ); XP_Bool isNew );
@ -941,8 +942,9 @@ gtkmain( LaunchParams* params )
} }
gtk_main(); gtk_main();
device_store( params->dutil );
closeGamesDB( params->pDb ); closeGamesDB( params->pDb );
params->pDb = NULL;
relaycon_cleanup( params ); relaycon_cleanup( params );
#ifdef XWFEATURE_SMS #ifdef XWFEATURE_SMS
linux_sms_cleanup( params ); linux_sms_cleanup( params );

View file

@ -205,12 +205,8 @@ linux_dutil_loadStream( XW_DUtilCtxt* duc, const XP_UCHAR* key,
if ( 0 < len ) { if ( 0 < len ) {
XP_U8 buf[len]; XP_U8 buf[len];
linux_dutil_loadPtr( duc, key, buf, &len ); linux_dutil_loadPtr( duc, key, buf, &len );
XP_ASSERT( buf[len-1] == '\0' );
gsize out_len; stream_putBytes( stream, buf, len );
guchar* txt = g_base64_decode( (const gchar*)buf, &out_len ); /* BAD */
stream_putBytes( stream, txt, out_len );
g_free( txt );
} }
XP_LOGF( "%s(key=%s) => len: %d", __func__, key, stream_getSize(stream) ); XP_LOGF( "%s(key=%s) => len: %d", __func__, key, stream_getSize(stream) );
@ -218,7 +214,7 @@ linux_dutil_loadStream( XW_DUtilCtxt* duc, const XP_UCHAR* key,
static void static void
linux_dutil_storePtr( XW_DUtilCtxt* duc, const XP_UCHAR* key, linux_dutil_storePtr( XW_DUtilCtxt* duc, const XP_UCHAR* key,
const void* data, XP_U16 len ) const void* data, const XP_U16 len )
{ {
LaunchParams* params = (LaunchParams*)duc->closure; LaunchParams* params = (LaunchParams*)duc->closure;
sqlite3* pDb = params->pDb; sqlite3* pDb = params->pDb;
@ -238,18 +234,23 @@ linux_dutil_loadPtr( XW_DUtilCtxt* duc, const XP_UCHAR* key,
gint buflen = 0; gint buflen = 0;
FetchResult res = db_fetch( pDb, key, NULL, &buflen ); FetchResult res = db_fetch( pDb, key, NULL, &buflen );
if ( res == BUFFER_TOO_SMALL ) { /* expected: I passed 0 */ if ( res == BUFFER_TOO_SMALL ) { /* expected: I passed 0 */
void* tmp = XP_MALLOC( duc->mpool, buflen ); if ( 0 == *lenp ) {
res = db_fetch( pDb, key, tmp, &buflen ); *lenp = buflen;
XP_ASSERT( res == SUCCESS ); } else {
gchar* tmp = XP_MALLOC( duc->mpool, buflen );
res = db_fetch( pDb, key, tmp, &buflen );
XP_ASSERT( res == SUCCESS );
XP_ASSERT( tmp[buflen-1] == '\0' );
gsize out_len; gsize out_len;
guchar* txt = g_base64_decode( (const gchar*)tmp, &out_len ); guchar* txt = g_base64_decode( (const gchar*)tmp, &out_len );
if ( out_len <= *lenp ) { if ( out_len <= *lenp ) {
XP_MEMCPY( data, txt, out_len ); XP_MEMCPY( data, txt, out_len );
*lenp = out_len; *lenp = out_len;
}
XP_FREEP( duc->mpool, &tmp );
g_free( txt );
} }
XP_FREEP( duc->mpool, &tmp );
g_free( txt );
} else { } else {
*lenp = 0; /* doesn't exist */ *lenp = 0; /* doesn't exist */
} }

View file

@ -313,7 +313,7 @@ relaycon_reg( LaunchParams* params, const XP_UCHAR* rDevID,
} }
void void
relaycon_invite( LaunchParams* params, XP_U32 destDevID, relaycon_invite( LaunchParams* params, XP_U32 destRelayDevID,
const XP_UCHAR* relayID, NetLaunchInfo* invit ) const XP_UCHAR* relayID, NetLaunchInfo* invit )
{ {
XP_U8 tmpbuf[256]; XP_U8 tmpbuf[256];
@ -326,13 +326,13 @@ relaycon_invite( LaunchParams* params, XP_U32 destDevID,
/* write relayID <connname>/<hid>, or if we have an actual devID write a /* write relayID <connname>/<hid>, or if we have an actual devID write a
null byte plus it. */ null byte plus it. */
if ( 0 == destDevID ) { if ( 0 == destRelayDevID ) {
XP_ASSERT( '\0' != relayID[0] ); XP_ASSERT( '\0' != relayID[0] );
indx += writeBytes( &tmpbuf[indx], sizeof(tmpbuf) - indx, indx += writeBytes( &tmpbuf[indx], sizeof(tmpbuf) - indx,
(XP_U8*)relayID, 1 + XP_STRLEN( relayID ) ); (XP_U8*)relayID, 1 + XP_STRLEN( relayID ) );
} else { } else {
tmpbuf[indx++] = '\0'; /* null byte: zero-len str */ tmpbuf[indx++] = '\0'; /* null byte: zero-len str */
indx += writeLong( &tmpbuf[indx], sizeof(tmpbuf) - indx, destDevID ); indx += writeLong( &tmpbuf[indx], sizeof(tmpbuf) - indx, destRelayDevID );
} }
XWStreamCtxt* stream = mem_stream_make_raw( MPPARM(params->mpool) XWStreamCtxt* stream = mem_stream_make_raw( MPPARM(params->mpool)