snapshot: saved games open now

This commit is contained in:
Eric House 2023-02-22 10:27:39 -08:00
parent 78d84a941e
commit 4bc24b41f6
5 changed files with 114 additions and 11 deletions

View file

@ -1,6 +1,7 @@
/* -*- compile-command: "cd ../wasm && make MEMDEBUG=TRUE install -j3"; -*- */
/*
* Copyright 2021 by Eric House (xwords@eehouse.org). All rights reserved.
* Copyright 2021 - 2023 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
@ -1590,6 +1591,13 @@ main_onGameMessage( Globals* globals, XP_U32 gameID,
}
}
void
main_onCtrlReceived( Globals* globals, const XP_U8* buf, XP_U16 len )
{
XP_LOGFF("(len=%d)", len );
XP_ASSERT(0);
}
void
main_onGameGone( Globals* globals, XP_U32 gameID )
{

View file

@ -107,6 +107,7 @@ void main_gameFromInvite( Globals* globals, const NetLaunchInfo* invite );
void main_onGameMessage( Globals* globals, XP_U32 gameID,
const CommsAddrRec* from, const XP_U8* buf,
XP_U16 len );
void main_onCtrlReceived( Globals* globals, const XP_U8* buf, XP_U16 len );
void main_onGameGone( Globals* globals, XP_U32 gameID );
void main_sendOnClose( XWStreamCtxt* stream, XWEnv env, void* closure );
void main_playerScoreHeld( GameState* gs, XP_U16 player );

View file

@ -220,6 +220,55 @@ ensurePath(const char* keys[], char buf[], bool mkDirs)
}
}
static void
wasm_dutil_storeStream( XW_DUtilCtxt* duc, XWEnv xwe, const XP_UCHAR* keys[],
XWStreamCtxt* stream )
{
LOG_FUNC();
char path[128];
ensurePath(keys, path, true);
// XP_LOGFF( "opening %s", path );
int fd = open(path, O_RDWR | O_CREAT, 0666);
if ( -1 == fd ) {
XP_LOGFF( "error from open(%s): %s", path, strerror(errno));
}
XP_ASSERT( fd != -1 ); /* firing */
const XP_U8* data = stream_getPtr( stream );
const XP_U16 len = stream_getSize( stream );
ssize_t nWritten = write( fd, data, len );
XP_LOGFF( "wrote %d bytes to path %s", nWritten, path );
XP_ASSERT( nWritten == len );
++((WasmDUtilCtxt*)duc)->dirtyCount;
}
static void
wasm_dutil_loadStream( XW_DUtilCtxt* duc, XWEnv xwe, const XP_UCHAR* keys[],
XWStreamCtxt* inOut )
{
LOG_FUNC();
char path[128];
ensurePath(keys, path, false);
XP_LOGFF( "(path: %s [retry: %s])", path, path );
struct stat statbuf;
int err = stat(path, &statbuf);
if ( 0 == err ) {
XP_U8 buf[statbuf.st_size];
int fd = open(path, O_RDONLY);
ssize_t nRead = read(fd, buf, statbuf.st_size);
close( fd );
stream_putBytes( inOut, buf, statbuf.st_size );
} else {
XP_LOGFF( "no file at %s", path );
}
XP_LOGFF( "from %s", path );
XP_LOGFF( "read %zu bytes", statbuf.st_size );
XP_LOGFF( "read %zu bytes from path %s", statbuf.st_size, path );
}
static void
wasm_dutil_storePtr( XW_DUtilCtxt* duc, XWEnv xwe,
const char* keys[],
@ -313,6 +362,7 @@ callWithKeys( XW_DUtilCtxt* duc, char path[], int depth,
return goOn;
}
# ifdef XWFEATURE_DEVICE
static void
wasm_dutil_forEach( XW_DUtilCtxt* duc, XWEnv xwe,
const char* keysIn[],
@ -357,6 +407,7 @@ wasm_dutil_remove( XW_DUtilCtxt* duc, const XP_UCHAR* keys[] )
deleteAll(path);
++((WasmDUtilCtxt*)duc)->dirtyCount;
}
#endif
#ifdef XWFEATURE_DEVID
static const XP_UCHAR*
@ -382,6 +433,15 @@ wasm_dutil_md5sum( XW_DUtilCtxt* duc, XWEnv xwe, const XP_U8* ptr,
return NULL;
}
static void
wasm_dutil_getUsername( XW_DUtilCtxt* duc, XWEnv xwe, XP_U16 num,
XP_Bool isLocal, XP_Bool isRobot,
XP_UCHAR* buf, XP_U16* len )
{
LOG_FUNC();
XP_ASSERT(0);
}
static void
wasm_dutil_notifyPause( XW_DUtilCtxt* XP_UNUSED(duc), XWEnv XP_UNUSED(xwe),
XP_U32 XP_UNUSED_DBG(gameID),
@ -393,6 +453,13 @@ wasm_dutil_notifyPause( XW_DUtilCtxt* XP_UNUSED(duc), XWEnv XP_UNUSED(xwe),
LOG_FUNC();
}
static XP_Bool
wasm_dutil_haveGame( XW_DUtilCtxt* duc, XWEnv xwe, XP_U32 gameID,XP_U8 channel )
{
XP_ASSERT(0);
return XP_TRUE;
}
static void
wasm_dutil_onDupTimerChanged( XW_DUtilCtxt* XP_UNUSED(duc), XWEnv XP_UNUSED(xwe),
XP_U32 XP_UNUSED_DBG(gameID),
@ -419,6 +486,13 @@ wasm_dutil_onMessageReceived( XW_DUtilCtxt* duc, XWEnv xwe, XP_U32 gameID,
main_onGameMessage( globals, gameID, from, buf, len );
}
static void
wasm_dutil_onCtrlReceived( XW_DUtilCtxt* duc, XWEnv xwe, const XP_U8* buf, XP_U16 len )
{
Globals* globals = (Globals*)duc->closure;
main_onCtrlReceived( globals, buf, len );
}
static void
wasm_dutil_onGameGoneReceived( XW_DUtilCtxt* duc, XWEnv XP_UNUSED(xwe),
XP_U32 gameID, const CommsAddrRec* from )
@ -477,10 +551,14 @@ wasm_dutil_make( MPFORMAL VTableMgr* vtMgr, void* closure )
SET_PROC(getUserString);
SET_PROC(getUserQuantityString);
SET_PROC(storeStream);
SET_PROC(loadStream);
SET_PROC(storePtr);
SET_PROC(loadPtr);
#ifdef XWFEATURE_DEVICE
SET_PROC(forEach);
SET_PROC(remove);
#endif
#ifdef XWFEATURE_SMS
SET_PROC(phoneNumbersSame);
@ -494,11 +572,13 @@ wasm_dutil_make( MPFORMAL VTableMgr* vtMgr, void* closure )
#ifdef COMMS_CHECKSUM
SET_PROC(md5sum);
#endif
SET_PROC(getUsername);
SET_PROC(notifyPause);
SET_PROC(haveGame);
SET_PROC(onDupTimerChanged);
SET_PROC(onInviteReceived);
SET_PROC(onMessageReceived);
SET_PROC(onCtrlReceived);
SET_PROC(onGameGoneReceived);
SET_PROC(ackMQTTMsg);

View file

@ -425,6 +425,14 @@ wasm_util_remSelected( XW_UtilCtxt* uc, XWEnv xwe )
main_showRemaining( gs );
}
static void
wasm_util_getMQTTIDsFor( XW_UtilCtxt* uc, XWEnv xwe, XP_U16 nRelayIDs,
const XP_UCHAR* relayIDs[] )
{
LOG_FUNC();
}
static void
wasm_util_timerSelected( XW_UtilCtxt* uc, XWEnv xwe, XP_Bool inDuplicateMode,
XP_Bool canPause )
@ -595,9 +603,8 @@ wasm_util_make( MPFORMAL CurGameInfo* gi, XW_DUtilCtxt* dctxt, GameState* closur
wuctxt->dctxt = dctxt;
wuctxt->closure = closure;
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_userError, wasm );
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_makeStreamFromAddr, wasm );
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_userError, wasm );
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_notifyMove, wasm );
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_notifyTrade, wasm );
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_notifyPickTileBlank, wasm );
@ -626,6 +633,7 @@ wasm_util_make( MPFORMAL CurGameInfo* gi, XW_DUtilCtxt* dctxt, GameState* closur
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_makeEmptyDict, wasm );
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_notifyIllegalWords, wasm );
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_remSelected, wasm );
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_getMQTTIDsFor, wasm );
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_timerSelected, wasm );
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_formatPauseHistory, wasm );
SET_VTABLE_ENTRY( wuctxt->super.vtable, util_bonusSquareHeld, wasm );

View file

@ -23,6 +23,8 @@
#include <stdarg.h>
#include "wasmutls.h"
#include "xptypes.h"
#include "comtypes.h"
EM_JS(void, console_log, (const char* msg), {
let jsmsg = UTF8ToString(msg);
@ -44,17 +46,21 @@ wasm_debugf( const char* format, ... )
void
wasm_debugff( const char* func, const char* file, const char* fmt, ...)
{
char buf[1024];
snprintf( buf, sizeof(buf), "%s:%s(): %s", file, func, fmt );
buf[sizeof(buf)-1] = '\0'; /* to be safe */
char buf1[512];
int required = snprintf( buf1, sizeof(buf1), "%s:%s()", file, func );
XP_ASSERT( required < sizeof(buf1) );
char buf2[1024];
va_list ap;
va_start( ap, fmt );
char buf2[1024];
vsnprintf( buf2, sizeof(buf2), buf, ap );
required = vsnprintf( buf2, sizeof(buf2), fmt, ap );
XP_ASSERT( required < sizeof(buf2) );
va_end( ap );
buf2[sizeof(buf2)-1] = '\0'; /* to be safe */
console_log( buf2 );
char buf3[VSIZE(buf1) + VSIZE(buf2)];
required = snprintf( buf3, sizeof(buf3), "%s: %s", buf1, buf2 );
XP_ASSERT( required < sizeof(buf3) );
console_log( buf3 );
}
#ifndef MEM_DEBUG