From 9023440a8886df3f57ac9d7d144ceacec9a402f4 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sun, 20 Jan 2013 10:03:20 -0800 Subject: [PATCH] reply with alert to any connection attempt when in maint mode --- xwords4/relay/xwrelay.cpp | 19 ++++++++----------- xwords4/relay/xwrelay.h | 5 +++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/xwords4/relay/xwrelay.cpp b/xwords4/relay/xwrelay.cpp index d54678463..c1ff4fd4f 100644 --- a/xwords4/relay/xwrelay.cpp +++ b/xwords4/relay/xwrelay.cpp @@ -1421,6 +1421,10 @@ maint_str_loop( int udpsock, const char* str ) { assert( -1 != udpsock ); int len = 1 + strlen(str); + unsigned char outbuf[len + 2]; + outbuf[0] = XWPDEV_PROTO_VERSION; + outbuf[1] = XWPDEV_ALERT; + memcpy( &outbuf[2], str, len ); fd_set rfds; for ( ; ; ) { @@ -1441,18 +1445,11 @@ maint_str_loop( int udpsock, const char* str ) ssize_t nRead = recvfrom( udpsock, buf, sizeof(buf), 0 /*flags*/, &saddr.addr, &fromlen ); - if ( 2 <= nRead ) { - if ( buf[0] == XWPDEV_PROTO_VERSION && buf[1] == XWPDEV_REG ) { - // reply, reusing buffer - buf[1] = XWPDEV_MSGRSP; - memcpy( &buf[2], str, len ); - send_via_udp( udpsock, &saddr.addr, buf, 2 + len ); - } + if ( 2 <= nRead && buf[0] == XWPDEV_PROTO_VERSION ) { + send_via_udp( udpsock, &saddr.addr, outbuf, sizeof(outbuf) ); } } - - } - + } // for } int @@ -1662,7 +1659,7 @@ main( int argc, char** argv ) if ( !!maint_str ) { maint_str_loop( g_udpsock, maint_str ); - exit( 0 ); + exit( 1 ); // should never exit } /* Needs to be reset after a crash/respawn */ diff --git a/xwords4/relay/xwrelay.h b/xwords4/relay/xwrelay.h index c06682295..a7f27a230 100644 --- a/xwords4/relay/xwrelay.h +++ b/xwords4/relay/xwrelay.h @@ -33,6 +33,11 @@ typedef #endif enum { XWPDEV_NONE /* 0 is an illegal value */ + ,XWPDEV_ALERT /* relay->device: provides a string message to + present to the user (with device allowed not + to present the same string more than once) + format: proto: 1, this enum: 1, + null-terminnated string: varies */ ,XWPDEV_REG /* dev->relay: device registers self and self-selected (e.g. gcm) or assigned devid format: proto: 1; this enum: 1; idType: 1,