mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-06 20:45:54 +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 ) ) {
|
||||
break;
|
||||
}
|
||||
if ( !UDPAckTrack::setOnAck( onMsgAcked, packetID, (void*)msg.msgID ) ) {
|
||||
sentIDs.push_back( msg.msgID );
|
||||
if ( !UDPAckTrack::setOnAck( onMsgAcked, packetID,
|
||||
(void*)msg.msgID() ) ) {
|
||||
sentIDs.push_back( msg.msgID() );
|
||||
}
|
||||
}
|
||||
dbmgr->RemoveStoredMessages( sentIDs );
|
||||
|
|
|
@ -988,19 +988,23 @@ DBMgr::decodeMessage( PGresult* result, bool useB64, int rowIndx, int b64indx,
|
|||
}
|
||||
|
||||
void
|
||||
DBMgr::storedMessagesImpl( string test, vector<DBMgr::MsgInfo>& msgs )
|
||||
DBMgr::storedMessagesImpl( string test, vector<DBMgr::MsgInfo>& msgs,
|
||||
bool nullConnnameOK )
|
||||
{
|
||||
string query;
|
||||
string_printf( query, "SELECT id, msg64, msg, msglen, token FROM " MSGS_TABLE
|
||||
" WHERE %s "
|
||||
string_printf( query, "SELECT id, msg64, msg, msglen, token, connname FROM "
|
||||
MSGS_TABLE " WHERE %s "
|
||||
#ifdef HAVE_STIME
|
||||
" AND stime IS NULL "
|
||||
#endif
|
||||
" AND connname IS NULL "
|
||||
" OR connname IN (SELECT connname FROM " GAMES_TABLE
|
||||
" WHERE NOT " GAMES_TABLE ".dead)"
|
||||
" ORDER BY id",
|
||||
test.c_str() );
|
||||
" AND (connname IN (SELECT connname FROM " GAMES_TABLE
|
||||
" WHERE NOT " GAMES_TABLE ".dead)", test.c_str() );
|
||||
|
||||
if ( nullConnnameOK ) {
|
||||
string_printf( query, " OR connname IS NULL ");
|
||||
}
|
||||
string_printf( query, ") ORDER BY id" );
|
||||
|
||||
|
||||
logf( XW_LOGINFO, "%s: query: %s", __func__, 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 ) {
|
||||
int id = atoi( PQgetvalue( result, ii, 0 ) );
|
||||
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];
|
||||
size_t buflen = sizeof(buf);
|
||||
|
@ -1028,7 +1034,7 @@ DBMgr::GetStoredMessages( DevIDRelay relayID, vector<MsgInfo>& msgs )
|
|||
if ( !hasNoMessages( relayID ) ) {
|
||||
string query;
|
||||
string_printf( query, "devid=%d", relayID );
|
||||
storedMessagesImpl( query, msgs );
|
||||
storedMessagesImpl( query, msgs, true );
|
||||
|
||||
if ( 0 == msgs.size() ) {
|
||||
setHasNoMessages( relayID );
|
||||
|
@ -1042,7 +1048,7 @@ DBMgr::GetStoredMessages( const char* const connName, HostID hid,
|
|||
{
|
||||
string query;
|
||||
string_printf( query, "hid = %d AND connname = '%s'", hid, connName );
|
||||
storedMessagesImpl( query, msgs );
|
||||
storedMessagesImpl( query, msgs, false );
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -41,12 +41,18 @@ class DBMgr {
|
|||
|
||||
class MsgInfo {
|
||||
public:
|
||||
MsgInfo( int id, AddrInfo::ClientToken tok ) {
|
||||
msgID = id; token = tok;
|
||||
MsgInfo( int id, AddrInfo::ClientToken tok, bool hc ) {
|
||||
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;
|
||||
int msgID;
|
||||
AddrInfo::ClientToken token;
|
||||
private:
|
||||
bool m_hasConnname;
|
||||
AddrInfo::ClientToken m_token;
|
||||
int m_msgID;
|
||||
};
|
||||
|
||||
static DBMgr* Get();
|
||||
|
@ -141,7 +147,8 @@ class DBMgr {
|
|||
void RemoveStoredMessages( string& msgIDs );
|
||||
void decodeMessage( PGresult* result, bool useB64, int rowIndx, int b64indx,
|
||||
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 );
|
||||
bool UpdateDevice( DevIDRelay relayID );
|
||||
|
||||
|
|
|
@ -82,6 +82,8 @@
|
|||
#include "udpack.h"
|
||||
#include "udpager.h"
|
||||
|
||||
static void log_hex( const uint8_t* memp, size_t len, const char* tag );
|
||||
|
||||
typedef struct _UDPHeader {
|
||||
uint32_t packetID;
|
||||
XWPDevProto proto;
|
||||
|
@ -347,19 +349,22 @@ static bool
|
|||
getHeader( const unsigned char** bufpp, const unsigned char* end,
|
||||
UDPHeader* header )
|
||||
{
|
||||
const uint8_t* start = *bufpp;
|
||||
bool success = false;
|
||||
uint8_t byt;
|
||||
if ( getNetByte( bufpp, end, &byt ) ) {
|
||||
header->proto = (XWPDevProto)byt;
|
||||
if ( XWPDEV_PROTO_VERSION_1 == header->proto
|
||||
&& vli2un( bufpp, end, &header->packetID )
|
||||
&& getNetByte( bufpp, end, &byt ) ) {
|
||||
&& getNetByte( bufpp, end, &byt )
|
||||
&& byt < XWPDEV_N_ELEMS ) {
|
||||
header->cmd = (XWRelayReg)byt;
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
if ( !success ) {
|
||||
logf( XW_LOGERROR, "%s: bad packet header", __func__ );
|
||||
log_hex( start, 7, "packet header" );
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
@ -1176,7 +1181,7 @@ pushMsgs( vector<unsigned char>& out, DBMgr* dbmgr, const char* connName,
|
|||
uint8_t* ptr = msg.msg.data();
|
||||
pushShort( out, 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
|
||||
|
||||
#define NUM_PER_LINE 8
|
||||
void
|
||||
log_hex( const unsigned char* memp, int len, const char* tag )
|
||||
static void
|
||||
log_hex( const uint8_t* memp, size_t len, const char* tag )
|
||||
{
|
||||
const char* hex = "0123456789ABCDEF";
|
||||
int i, j;
|
||||
int offset = 0;
|
||||
size_t offset = 0;
|
||||
|
||||
while ( offset < len ) {
|
||||
char buf[128];
|
||||
|
@ -1526,7 +1531,10 @@ retrieveMessages( DevID& devID, const AddrInfo* addr )
|
|||
const DBMgr::MsgInfo& msg = *iter;
|
||||
uint32_t packetID;
|
||||
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;
|
||||
const struct sockaddr* 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,
|
||||
dest_addr );
|
||||
}
|
||||
} else {
|
||||
success = send_msg_via_udp( addr, msg.token, msg.msg.data(),
|
||||
msg.msg.size(), &packetID );
|
||||
}
|
||||
|
||||
if ( !success ) {
|
||||
|
@ -1545,7 +1550,7 @@ retrieveMessages( DevID& devID, const AddrInfo* addr )
|
|||
__func__, devID.asRelayID() );
|
||||
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,
|
||||
length-initiated string to present to user. */
|
||||
|
||||
|
||||
,XWPDEV_N_ELEMS /* MUST BE LAST */
|
||||
|
||||
}
|
||||
#ifndef CANT_DO_TYPEDEF
|
||||
XWRelayReg
|
||||
|
|
Loading…
Add table
Reference in a new issue