diff --git a/xwords4/linux/cursesmain.c b/xwords4/linux/cursesmain.c index 370b053ea..2e72e3b44 100644 --- a/xwords4/linux/cursesmain.c +++ b/xwords4/linux/cursesmain.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include /* gethostbyname */ #include @@ -1513,6 +1515,15 @@ curses_util_makeStreamFromAddr(XW_UtilCtxt* uc, XP_PlayerAddr channelNo ) } /* curses_util_makeStreamFromAddr */ #endif +#ifdef XWFEATURE_CHAT +static void +curses_util_showChat( XW_UtilCtxt* XP_UNUSED(uc), const XP_UCHAR* const msg ) +{ + XP_LOGF( "%s: got \"%s\"", __func__, msg ); +} +#endif + + static void setupCursesUtilCallbacks( CursesAppGlobals* globals, XW_UtilCtxt* util ) { @@ -1526,6 +1537,10 @@ setupCursesUtilCallbacks( CursesAppGlobals* globals, XW_UtilCtxt* util ) #ifndef XWFEATURE_STANDALONE_ONLY util->vtable->m_util_makeStreamFromAddr = curses_util_makeStreamFromAddr; #endif +#ifdef XWFEATURE_CHAT + util->vtable->m_util_showChat = curses_util_showChat; +#endif + util->vtable->m_util_userQuery = curses_util_userQuery; util->vtable->m_util_confirmTrade = curses_util_confirmTrade; util->vtable->m_util_userPickTileBlank = curses_util_userPickTileBlank; @@ -1699,6 +1714,32 @@ handle_stdin( GIOChannel* XP_UNUSED_DBG(source), GIOCondition condition, } #endif +static gboolean +chatsTimerFired( gpointer data ) +{ + CursesAppGlobals* globals = (CursesAppGlobals*)data; + + GameStateInfo gsi; + game_getState( &globals->cGlobals.game, &gsi ); + + if ( gsi.gameIsConnected ) { + XP_UCHAR msg[128]; + struct tm* timp; + struct timeval tv; + struct timezone tz; + + gettimeofday( &tv, &tz ); + timp = localtime( &tv.tv_sec ); + + snprintf( msg, sizeof(msg), "Saying hi via chat at %.2d:%.2d:%.2d:", + timp->tm_hour, timp->tm_min, timp->tm_sec ); + server_sendChat( globals->cGlobals.game.server, msg ); + XP_LOGF( "%s: sent \"%s\"", __func__, msg ); + } + + return TRUE; +} + void cursesmain( XP_Bool isServer, LaunchParams* params ) { @@ -1788,6 +1829,11 @@ cursesmain( XP_Bool isServer, LaunchParams* params ) } else if ( !!params->nbs && !!params->fileName ) { do_nbs_then_close( &g_globals.cGlobals, &procs ); } else { + if ( 0 != params->chatsInterval ) { + (void)g_timeout_add_seconds( params->chatsInterval, chatsTimerFired, + &g_globals ); + } + XP_Bool opened = XP_FALSE; initCurses( &g_globals ); getmaxyx( g_globals.boardWin, height, width ); diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index b2af84b6d..035781b09 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -550,6 +550,7 @@ typedef enum { ,CMD_VERTICALSCORE ,CMD_NOPEEK ,CMD_SPLITPACKETS + ,CMD_CHAT #ifdef XWFEATURE_CROSSHAIRS ,CMD_NOCROSSHAIRS #endif @@ -652,6 +653,7 @@ static CmdInfoRec CmdInfoRecs[] = { ,{ CMD_NOPEEK, false, "no-peek", "disallow scoreboard tap changing player" } ,{ CMD_SPLITPACKETS, false, "split-packets", "send tcp packets in " "sections to test relay reassembly" } + ,{ CMD_CHAT, true, "send-chat", "send a chat every seconds" } #ifdef XWFEATURE_CROSSHAIRS ,{ CMD_NOCROSSHAIRS, false, "hide-crosshairs", "don't show crosshairs on board" } @@ -1913,6 +1915,9 @@ main( int argc, char** argv ) case CMD_SPLITPACKETS: mainParams.splitPackets = XP_TRUE; break; + case CMD_CHAT: + mainParams.chatsInterval = atoi(optarg); + break; #ifdef XWFEATURE_CROSSHAIRS case CMD_NOCROSSHAIRS: mainParams.hideCrosshairs = XP_TRUE; diff --git a/xwords4/linux/main.h b/xwords4/linux/main.h index b68cd2685..bda26c923 100644 --- a/xwords4/linux/main.h +++ b/xwords4/linux/main.h @@ -91,6 +91,7 @@ typedef struct LaunchParams { XP_Bool useMmap; XP_Bool closeStdin; XP_Bool splitPackets; + XP_U16 chatsInterval; /* 0 means disabled */ #ifdef XWFEATURE_SEARCHLIMIT XP_Bool allowHintRect; #endif