mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-11 08:48:06 +01:00
fix treating game-targeted messages as if they were device-targeted.
Should probably have separate tables for the two types....
This commit is contained in:
parent
b80051cc73
commit
0e6b211a76
5 changed files with 50 additions and 28 deletions
|
@ -902,8 +902,9 @@ CookieRef::send_stored_messages( HostID dest, const AddrInfo* addr )
|
||||||
msg.msg.size(), true, &packetID ) ) {
|
msg.msg.size(), true, &packetID ) ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( !UDPAckTrack::setOnAck( onMsgAcked, packetID, (void*)msg.msgID ) ) {
|
if ( !UDPAckTrack::setOnAck( onMsgAcked, packetID,
|
||||||
sentIDs.push_back( msg.msgID );
|
(void*)msg.msgID() ) ) {
|
||||||
|
sentIDs.push_back( msg.msgID() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbmgr->RemoveStoredMessages( sentIDs );
|
dbmgr->RemoveStoredMessages( sentIDs );
|
||||||
|
|
|
@ -988,19 +988,23 @@ DBMgr::decodeMessage( PGresult* result, bool useB64, int rowIndx, int b64indx,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DBMgr::storedMessagesImpl( string test, vector<DBMgr::MsgInfo>& msgs )
|
DBMgr::storedMessagesImpl( string test, vector<DBMgr::MsgInfo>& msgs,
|
||||||
|
bool nullConnnameOK )
|
||||||
{
|
{
|
||||||
string query;
|
string query;
|
||||||
string_printf( query, "SELECT id, msg64, msg, msglen, token FROM " MSGS_TABLE
|
string_printf( query, "SELECT id, msg64, msg, msglen, token, connname FROM "
|
||||||
" WHERE %s "
|
MSGS_TABLE " WHERE %s "
|
||||||
#ifdef HAVE_STIME
|
#ifdef HAVE_STIME
|
||||||
" AND stime IS NULL "
|
" AND stime IS NULL "
|
||||||
#endif
|
#endif
|
||||||
" AND connname IS NULL "
|
" AND (connname IN (SELECT connname FROM " GAMES_TABLE
|
||||||
" OR connname IN (SELECT connname FROM " GAMES_TABLE
|
" WHERE NOT " GAMES_TABLE ".dead)", test.c_str() );
|
||||||
" WHERE NOT " GAMES_TABLE ".dead)"
|
|
||||||
" ORDER BY id",
|
if ( nullConnnameOK ) {
|
||||||
test.c_str() );
|
string_printf( query, " OR connname IS NULL ");
|
||||||
|
}
|
||||||
|
string_printf( query, ") ORDER BY id" );
|
||||||
|
|
||||||
|
|
||||||
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
|
logf( XW_LOGINFO, "%s: query: %s", __func__, query.c_str() );
|
||||||
PGresult* result = PQexec( getThreadConn(), query.c_str() );
|
PGresult* result = PQexec( getThreadConn(), query.c_str() );
|
||||||
|
@ -1009,7 +1013,9 @@ DBMgr::storedMessagesImpl( string test, vector<DBMgr::MsgInfo>& msgs )
|
||||||
for ( int ii = 0; ii < nTuples; ++ii ) {
|
for ( int ii = 0; ii < nTuples; ++ii ) {
|
||||||
int id = atoi( PQgetvalue( result, ii, 0 ) );
|
int id = atoi( PQgetvalue( result, ii, 0 ) );
|
||||||
AddrInfo::ClientToken token = atoi( PQgetvalue( result, ii, 4 ) );
|
AddrInfo::ClientToken token = atoi( PQgetvalue( result, ii, 4 ) );
|
||||||
MsgInfo msg( id, token );
|
const char* connname = PQgetvalue( result, ii, 5 );
|
||||||
|
bool hasConnname = connname != NULL && '\0' != connname[0];
|
||||||
|
MsgInfo msg( id, token, hasConnname );
|
||||||
|
|
||||||
uint8_t buf[1024];
|
uint8_t buf[1024];
|
||||||
size_t buflen = sizeof(buf);
|
size_t buflen = sizeof(buf);
|
||||||
|
@ -1028,7 +1034,7 @@ DBMgr::GetStoredMessages( DevIDRelay relayID, vector<MsgInfo>& msgs )
|
||||||
if ( !hasNoMessages( relayID ) ) {
|
if ( !hasNoMessages( relayID ) ) {
|
||||||
string query;
|
string query;
|
||||||
string_printf( query, "devid=%d", relayID );
|
string_printf( query, "devid=%d", relayID );
|
||||||
storedMessagesImpl( query, msgs );
|
storedMessagesImpl( query, msgs, true );
|
||||||
|
|
||||||
if ( 0 == msgs.size() ) {
|
if ( 0 == msgs.size() ) {
|
||||||
setHasNoMessages( relayID );
|
setHasNoMessages( relayID );
|
||||||
|
@ -1042,7 +1048,7 @@ DBMgr::GetStoredMessages( const char* const connName, HostID hid,
|
||||||
{
|
{
|
||||||
string query;
|
string query;
|
||||||
string_printf( query, "hid = %d AND connname = '%s'", hid, connName );
|
string_printf( query, "hid = %d AND connname = '%s'", hid, connName );
|
||||||
storedMessagesImpl( query, msgs );
|
storedMessagesImpl( query, msgs, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -41,12 +41,18 @@ class DBMgr {
|
||||||
|
|
||||||
class MsgInfo {
|
class MsgInfo {
|
||||||
public:
|
public:
|
||||||
MsgInfo( int id, AddrInfo::ClientToken tok ) {
|
MsgInfo( int id, AddrInfo::ClientToken tok, bool hc ) {
|
||||||
msgID = id; token = tok;
|
m_msgID = id; m_token = tok; m_hasConnname = hc;
|
||||||
}
|
}
|
||||||
|
bool hasConnname() const { return m_hasConnname; }
|
||||||
|
AddrInfo::ClientToken token() const { return m_token; }
|
||||||
|
int msgID() const { return m_msgID; }
|
||||||
|
|
||||||
vector<uint8_t> msg;
|
vector<uint8_t> msg;
|
||||||
int msgID;
|
private:
|
||||||
AddrInfo::ClientToken token;
|
bool m_hasConnname;
|
||||||
|
AddrInfo::ClientToken m_token;
|
||||||
|
int m_msgID;
|
||||||
};
|
};
|
||||||
|
|
||||||
static DBMgr* Get();
|
static DBMgr* Get();
|
||||||
|
@ -141,7 +147,8 @@ class DBMgr {
|
||||||
void RemoveStoredMessages( string& msgIDs );
|
void RemoveStoredMessages( string& msgIDs );
|
||||||
void decodeMessage( PGresult* result, bool useB64, int rowIndx, int b64indx,
|
void decodeMessage( PGresult* result, bool useB64, int rowIndx, int b64indx,
|
||||||
int byteaIndex, unsigned char* buf, size_t* buflen );
|
int byteaIndex, unsigned char* buf, size_t* buflen );
|
||||||
void storedMessagesImpl( string query, vector<DBMgr::MsgInfo>& msgs );
|
void storedMessagesImpl( string query, vector<DBMgr::MsgInfo>& msgs,
|
||||||
|
bool nullConnnameOK );
|
||||||
int CountStoredMessages( const char* const connName, int hid );
|
int CountStoredMessages( const char* const connName, int hid );
|
||||||
bool UpdateDevice( DevIDRelay relayID );
|
bool UpdateDevice( DevIDRelay relayID );
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,8 @@
|
||||||
#include "udpack.h"
|
#include "udpack.h"
|
||||||
#include "udpager.h"
|
#include "udpager.h"
|
||||||
|
|
||||||
|
static void log_hex( const uint8_t* memp, size_t len, const char* tag );
|
||||||
|
|
||||||
typedef struct _UDPHeader {
|
typedef struct _UDPHeader {
|
||||||
uint32_t packetID;
|
uint32_t packetID;
|
||||||
XWPDevProto proto;
|
XWPDevProto proto;
|
||||||
|
@ -347,19 +349,22 @@ static bool
|
||||||
getHeader( const unsigned char** bufpp, const unsigned char* end,
|
getHeader( const unsigned char** bufpp, const unsigned char* end,
|
||||||
UDPHeader* header )
|
UDPHeader* header )
|
||||||
{
|
{
|
||||||
|
const uint8_t* start = *bufpp;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
uint8_t byt;
|
uint8_t byt;
|
||||||
if ( getNetByte( bufpp, end, &byt ) ) {
|
if ( getNetByte( bufpp, end, &byt ) ) {
|
||||||
header->proto = (XWPDevProto)byt;
|
header->proto = (XWPDevProto)byt;
|
||||||
if ( XWPDEV_PROTO_VERSION_1 == header->proto
|
if ( XWPDEV_PROTO_VERSION_1 == header->proto
|
||||||
&& vli2un( bufpp, end, &header->packetID )
|
&& vli2un( bufpp, end, &header->packetID )
|
||||||
&& getNetByte( bufpp, end, &byt ) ) {
|
&& getNetByte( bufpp, end, &byt )
|
||||||
|
&& byt < XWPDEV_N_ELEMS ) {
|
||||||
header->cmd = (XWRelayReg)byt;
|
header->cmd = (XWRelayReg)byt;
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( !success ) {
|
if ( !success ) {
|
||||||
logf( XW_LOGERROR, "%s: bad packet header", __func__ );
|
logf( XW_LOGERROR, "%s: bad packet header", __func__ );
|
||||||
|
log_hex( start, 7, "packet header" );
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@ -1176,7 +1181,7 @@ pushMsgs( vector<unsigned char>& out, DBMgr* dbmgr, const char* connName,
|
||||||
uint8_t* ptr = msg.msg.data();
|
uint8_t* ptr = msg.msg.data();
|
||||||
pushShort( out, len );
|
pushShort( out, len );
|
||||||
out.insert( out.end(), ptr, ptr + len );
|
out.insert( out.end(), ptr, ptr + len );
|
||||||
msgIDs.push_back( msg.msgID );
|
msgIDs.push_back( msg.msgID() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1236,12 +1241,12 @@ handleMsgsMsg( const AddrInfo* addr, bool sendFull,
|
||||||
} // handleMsgsMsg
|
} // handleMsgsMsg
|
||||||
|
|
||||||
#define NUM_PER_LINE 8
|
#define NUM_PER_LINE 8
|
||||||
void
|
static void
|
||||||
log_hex( const unsigned char* memp, int len, const char* tag )
|
log_hex( const uint8_t* memp, size_t len, const char* tag )
|
||||||
{
|
{
|
||||||
const char* hex = "0123456789ABCDEF";
|
const char* hex = "0123456789ABCDEF";
|
||||||
int i, j;
|
int i, j;
|
||||||
int offset = 0;
|
size_t offset = 0;
|
||||||
|
|
||||||
while ( offset < len ) {
|
while ( offset < len ) {
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
@ -1526,7 +1531,10 @@ retrieveMessages( DevID& devID, const AddrInfo* addr )
|
||||||
const DBMgr::MsgInfo& msg = *iter;
|
const DBMgr::MsgInfo& msg = *iter;
|
||||||
uint32_t packetID;
|
uint32_t packetID;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
if ( AddrInfo::NULL_TOKEN == msg.token ) {
|
if ( msg.hasConnname() ) {
|
||||||
|
success = send_msg_via_udp( addr, msg.token(), msg.msg.data(),
|
||||||
|
msg.msg.size(), &packetID );
|
||||||
|
} else {
|
||||||
int socket;
|
int socket;
|
||||||
const struct sockaddr* dest_addr;
|
const struct sockaddr* dest_addr;
|
||||||
if ( get_addr_info_if( addr, &socket, &dest_addr ) ) {
|
if ( get_addr_info_if( addr, &socket, &dest_addr ) ) {
|
||||||
|
@ -1535,9 +1543,6 @@ retrieveMessages( DevID& devID, const AddrInfo* addr )
|
||||||
success = 0 < send_packet_via_udp_impl( newPacket, socket,
|
success = 0 < send_packet_via_udp_impl( newPacket, socket,
|
||||||
dest_addr );
|
dest_addr );
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
success = send_msg_via_udp( addr, msg.token, msg.msg.data(),
|
|
||||||
msg.msg.size(), &packetID );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !success ) {
|
if ( !success ) {
|
||||||
|
@ -1545,7 +1550,7 @@ retrieveMessages( DevID& devID, const AddrInfo* addr )
|
||||||
__func__, devID.asRelayID() );
|
__func__, devID.asRelayID() );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
UDPAckTrack::setOnAck( onMsgAcked, packetID, (void*)msg.msgID );
|
UDPAckTrack::setOnAck( onMsgAcked, packetID, (void*)msg.msgID() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,9 @@ enum { XWPDEV_NONE /* 0 is an illegal value */
|
||||||
,XWPDEV_ALERT /* relay->dev: format: header,
|
,XWPDEV_ALERT /* relay->dev: format: header,
|
||||||
length-initiated string to present to user. */
|
length-initiated string to present to user. */
|
||||||
|
|
||||||
|
|
||||||
|
,XWPDEV_N_ELEMS /* MUST BE LAST */
|
||||||
|
|
||||||
}
|
}
|
||||||
#ifndef CANT_DO_TYPEDEF
|
#ifndef CANT_DO_TYPEDEF
|
||||||
XWRelayReg
|
XWRelayReg
|
||||||
|
|
Loading…
Add table
Reference in a new issue