mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-12 08:47:50 +01:00
Add sms support, largely untested.
This commit is contained in:
parent
41ae10f8b6
commit
09c879dccc
1 changed files with 49 additions and 24 deletions
|
@ -1,6 +1,6 @@
|
||||||
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE"; -*- */
|
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE"; -*- */
|
||||||
/*
|
/*
|
||||||
* Copyright 2000-2008 by Eric House (xwords@eehouse.org). All rights
|
* Copyright 2000-2009 by Eric House (xwords@eehouse.org). All rights
|
||||||
* reserved.
|
* reserved.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
|
@ -56,6 +56,8 @@
|
||||||
#include "memstream.h"
|
#include "memstream.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "dbgutil.h"
|
#include "dbgutil.h"
|
||||||
|
#include "linuxsms.h"
|
||||||
|
#include "linuxudp.h"
|
||||||
|
|
||||||
#ifdef CURSES_SMALL_SCREEN
|
#ifdef CURSES_SMALL_SCREEN
|
||||||
# define MENU_WINDOW_HEIGHT 1
|
# define MENU_WINDOW_HEIGHT 1
|
||||||
|
@ -840,13 +842,13 @@ cursesListenOnSocket( CursesAppGlobals* globals, int newSock )
|
||||||
{
|
{
|
||||||
XP_ASSERT( globals->fdCount+1 < FD_MAX );
|
XP_ASSERT( globals->fdCount+1 < FD_MAX );
|
||||||
|
|
||||||
XP_WARNF( "setting fd[%d] to %d", globals->fdCount, newSock );
|
XP_WARNF( "%s: setting fd[%d] to %d", __func__, globals->fdCount, newSock );
|
||||||
globals->fdArray[globals->fdCount].fd = newSock;
|
globals->fdArray[globals->fdCount].fd = newSock;
|
||||||
globals->fdArray[globals->fdCount].events = POLLIN;
|
globals->fdArray[globals->fdCount].events = POLLIN;
|
||||||
|
|
||||||
++globals->fdCount;
|
++globals->fdCount;
|
||||||
XP_LOGF( "listenOnSocket: there are now %d sources to poll",
|
XP_LOGF( "%s: there are now %d sources to poll",
|
||||||
globals->fdCount );
|
__func__, globals->fdCount );
|
||||||
} /* cursesListenOnSocket */
|
} /* cursesListenOnSocket */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -971,48 +973,54 @@ blocking_gotEvent( CursesAppGlobals* globals, int* ch )
|
||||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
unsigned char buf[256];
|
unsigned char buf[256];
|
||||||
int nBytes;
|
int nBytes;
|
||||||
|
CommsAddrRec addrRec;
|
||||||
|
CommsAddrRec* addrp = NULL;
|
||||||
|
|
||||||
/* It's a normal data socket */
|
/* It's a normal data socket */
|
||||||
if ( 0 ) {
|
switch ( globals->cGlobals.params->conType ) {
|
||||||
#ifdef XWFEATURE_RELAY
|
#ifdef XWFEATURE_RELAY
|
||||||
} else if ( globals->cGlobals.params->conType
|
case COMMS_CONN_RELAY:
|
||||||
== COMMS_CONN_RELAY ) {
|
|
||||||
nBytes = linux_relay_receive( &globals->cGlobals, buf,
|
nBytes = linux_relay_receive( &globals->cGlobals, buf,
|
||||||
sizeof(buf) );
|
sizeof(buf) );
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#ifdef XWFEATURE_SMS
|
||||||
|
case COMMS_CONN_SMS:
|
||||||
|
addrp = &addrRec;
|
||||||
|
nBytes = linux_sms_receive( &globals->cGlobals,
|
||||||
|
globals->fdArray[fdIndex].fd,
|
||||||
|
buf, sizeof(buf), addrp );
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef XWFEATURE_BLUETOOTH
|
#ifdef XWFEATURE_BLUETOOTH
|
||||||
} else if ( globals->cGlobals.params->conType
|
case COMMS_CONN_BT:
|
||||||
== COMMS_CONN_BT ) {
|
|
||||||
nBytes = linux_bt_receive( globals->fdArray[fdIndex].fd,
|
nBytes = linux_bt_receive( globals->fdArray[fdIndex].fd,
|
||||||
buf, sizeof(buf) );
|
buf, sizeof(buf) );
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
default:
|
||||||
XP_ASSERT( 0 );
|
XP_ASSERT( 0 ); /* fired */
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( nBytes != -1 ) {
|
if ( nBytes != -1 ) {
|
||||||
XWStreamCtxt* inboundS;
|
XWStreamCtxt* inboundS;
|
||||||
struct sockaddr_in addr_sock = {0};
|
/* struct sockaddr_in addr_sock = {0}; */
|
||||||
redraw = XP_FALSE;
|
redraw = XP_FALSE;
|
||||||
|
|
||||||
XP_STATUSF( "linuxReceive=>%d", nBytes );
|
XP_STATUSF( "linuxReceive=>%d", nBytes );
|
||||||
inboundS = stream_from_msgbuf( &globals->cGlobals,
|
inboundS = stream_from_msgbuf( &globals->cGlobals,
|
||||||
buf, nBytes );
|
buf, nBytes );
|
||||||
if ( !!inboundS ) {
|
if ( !!inboundS ) {
|
||||||
CommsAddrRec addrRec;
|
/* addrRec.u.ip_relay.ipAddr = */
|
||||||
|
/* ntohl(addr_sock.sin_addr.s_addr); */
|
||||||
XP_MEMSET( &addrRec, 0, sizeof(addrRec) );
|
/* XP_LOGF( "captured incoming ip address: 0x%lx", */
|
||||||
addrRec.conType = COMMS_CONN_RELAY;
|
/* addrRec.u.ip_relay.ipAddr ); */
|
||||||
|
|
||||||
addrRec.u.ip_relay.ipAddr =
|
|
||||||
ntohl(addr_sock.sin_addr.s_addr);
|
|
||||||
XP_LOGF( "captured incoming ip address: 0x%lx",
|
|
||||||
addrRec.u.ip_relay.ipAddr );
|
|
||||||
|
|
||||||
if ( comms_checkIncomingStream(
|
if ( comms_checkIncomingStream(
|
||||||
globals->cGlobals.game.comms,
|
globals->cGlobals.game.comms,
|
||||||
inboundS, &addrRec ) ) {
|
inboundS, addrp ) ) {
|
||||||
XP_LOGF( "comms read port: %d",
|
/* XP_LOGF( "comms read port: %d", */
|
||||||
addrRec.u.ip_relay.port );
|
/* addrRec.u.ip_relay.port ); */
|
||||||
redraw = server_receiveMessage(
|
redraw = server_receiveMessage(
|
||||||
globals->cGlobals.game.server, inboundS );
|
globals->cGlobals.game.server, inboundS );
|
||||||
}
|
}
|
||||||
|
@ -1414,6 +1422,13 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
|
||||||
XP_STRNCPY( addr.u.ip_relay.cookie, params->connInfo.relay.cookie,
|
XP_STRNCPY( addr.u.ip_relay.cookie, params->connInfo.relay.cookie,
|
||||||
sizeof(addr.u.ip_relay.cookie) - 1 );
|
sizeof(addr.u.ip_relay.cookie) - 1 );
|
||||||
# endif
|
# endif
|
||||||
|
# ifdef XWFEATURE_SMS
|
||||||
|
} else if ( params->conType == COMMS_CONN_SMS ) {
|
||||||
|
addr.conType = COMMS_CONN_SMS;
|
||||||
|
XP_STRNCPY( addr.u.sms.phone, params->connInfo.sms.serverPhone,
|
||||||
|
sizeof(addr.u.sms.phone) - 1 );
|
||||||
|
addr.u.sms.port = params->connInfo.sms.port;
|
||||||
|
# endif
|
||||||
# ifdef XWFEATURE_BLUETOOTH
|
# ifdef XWFEATURE_BLUETOOTH
|
||||||
} else if ( params->conType == COMMS_CONN_BT ) {
|
} else if ( params->conType == COMMS_CONN_BT ) {
|
||||||
addr.conType = COMMS_CONN_BT;
|
addr.conType = COMMS_CONN_BT;
|
||||||
|
@ -1473,6 +1488,16 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef XWFEATURE_BLUETOOTH
|
||||||
|
linux_bt_close( &g_globals.cGlobals );
|
||||||
|
#endif
|
||||||
|
#ifdef XWFEATURE_SMS
|
||||||
|
linux_sms_close( &g_globals.cGlobals );
|
||||||
|
#endif
|
||||||
|
#ifdef XWFEATURE_IP_DIRECT
|
||||||
|
linux_udp_close( &g_globals.cGlobals );
|
||||||
|
#endif
|
||||||
|
|
||||||
endwin();
|
endwin();
|
||||||
} /* cursesmain */
|
} /* cursesmain */
|
||||||
#endif /* PLATFORM_NCURSES */
|
#endif /* PLATFORM_NCURSES */
|
||||||
|
|
Loading…
Add table
Reference in a new issue