bool UnitSyncProcessor::BuildSubResponse( const QByteArray& subRequest, const QByteArray& data ) { RequestProcessor* subProcessor = _processors.value( subRequest ); if( !subProcessor || !subProcessor->ProcessRequest( data ) ) { SetResponse( "Not found", Response_Html ); return false; } SetResponse( subProcessor->Response(), subProcessor->Type() ); return true; }
bool UnitSyncGamesProcessor::ProcessAIListRequest( const QByteArray& game, const QList<QByteArray>& subRequest ) { if( subRequest.size() == 2 ) { SetResponse( BuildAIListList( game ), Response_Html ); return true; } else if( subRequest.size() == 3 ) { SetResponse( BuildAiInfo( game, subRequest[ 2 ] ), Response_Html ); return true; } SetResponse( "Wrong game AI list request", Response_Html ); return true; }
bool UnitSyncGamesProcessor::ProcessOptionsRequest( const QByteArray& game, const QList<QByteArray>& subRequest ) { if( subRequest.size() == 2 ) { SetResponse( BuildGamesOptionsList( game ), Response_Html ); return true; } if( subRequest.size() == 3 ) { QList< SpringOption > options = UnitSync()->GetGameOptions( game ); SetResponse( ProcessorsTools::BuildOption( subRequest[ 2 ], options ), Response_PlainText ); return true; } SetResponse( "Wrong game options request", Response_Html ); return true; }
bool UnitSyncGamesProcessor::ProcessSideRequest( const QByteArray& game, const QList<QByteArray>& subRequest ) { if( subRequest.size() == 2 ) { SetResponse( BuildSideList( game ), Response_Html ); return true; } else if( subRequest.size() == 3 ) { SetResponse( BuildSideMenu( game, subRequest[ 2 ] ), Response_Html ); return true; } else if( subRequest.size() == 4 && subRequest[ 3 ] == SideIconRequest ) { SetResponse( BuildSideIcon( game, subRequest[ 2 ] ), Response_Image ); return true; } SetResponse( "Wrong game side request", Response_Html ); return true; }
bool UnitSyncGamesListProcessor::BuildResponse() { QList<QString> games = UnitSync()->GetGamesList(); QByteArray text; for( int i = 0; i < games.size(); ++i ) { QByteArray game = games[ i ].toUtf8(); text.append( game ).append( "\n" ); } SetResponse( text, Response_PlainText ); return true; }
bool UnitSyncGamesProcessor::ProcessValidMapsRequest( const QByteArray& game ) { QByteArray result; QList< QString > items = UnitSync()->GetGameValidMaps( game ); for( int i = 0; i < items.size(); ++i ) { result.append( items[ i ] ).append( "<br>" ); } SetResponse( result, Response_Html ); return true; }
bool UnitSyncGamesProcessor::BuildResponse() { QList<QString> games = UnitSync()->GetGamesList(); QByteArray html; for( int i = 0; i < games.size(); ++i ) { QByteArray game = games[ i ].toUtf8(); html.append( "<a href=\"/Games/" ).append( game ).append( "\">" ).append( game ).append( "</a><br>" ); } SetResponse( html, Response_Html ); return true; }
bool UnitSyncGamesProcessor::BuildSubResponse( const QByteArray& subRequest, const QByteArray& data ) { if( data.isEmpty() ) { SetResponse( BuildGameMenu( subRequest ), Response_Html ); return true; } QList< QByteArray > cmdList = data.split( L'/' ); if( cmdList.size() < 2 ) { SetResponse( "Wrong data", Response_Html ); return true; } const QByteArray cmd = cmdList[ 1 ]; if( cmd == GameChecksumRequest ) { SetResponse( QByteArray::number( UnitSync()->GetGameHash( subRequest ) ), Response_Html ); return true; } else if( cmd == GameSidesRequest ) { return ProcessSideRequest( subRequest, cmdList ); } else if( cmd == AIListRequest ) { return ProcessAIListRequest( subRequest, cmdList ); } else if( cmd == ValidMapsRequest ) { return ProcessValidMapsRequest( subRequest ); } else if( cmd == GameOptionsRequest ) { return ProcessOptionsRequest( subRequest, cmdList ); } if( cmd == GamesOptionsListRequest ) { SetResponse( ProcessorsTools::BuildOptionsList( UnitSync()->GetGameOptions( subRequest ) ), Response_PlainText ); return true; } SetResponse( "Wrong game request", Response_Html ); return true; }
/** * Test assorted tlcl functions */ static void TlclTest(void) { uint8_t buf[32], buf2[32]; ResetMocks(); TEST_EQ(TlclLibInit(), VBERROR_SUCCESS, "Init"); ResetMocks(); mock_retval = VBERROR_SIMULATED; TEST_EQ(TlclLibInit(), mock_retval, "Init bad"); ResetMocks(); TEST_EQ(TlclLibClose(), VBERROR_SUCCESS, "Close"); ResetMocks(); mock_retval = VBERROR_SIMULATED; TEST_EQ(TlclLibClose(), mock_retval, "Close bad"); ResetMocks(); ToTpmUint32(buf + 2, 123); TEST_EQ(TlclPacketSize(buf), 123, "TlclPacketSize"); ResetMocks(); ToTpmUint32(buf + 2, 10); TEST_EQ(TlclSendReceive(buf, buf2, sizeof(buf2)), 0, "SendReceive"); TEST_PTR_EQ(calls[0].req, buf, "SendReceive req ptr"); TEST_EQ(calls[0].req_size, 10, "SendReceive size"); ResetMocks(); calls[0].retval = VBERROR_SIMULATED; ToTpmUint32(buf + 2, 10); TEST_EQ(TlclSendReceive(buf, buf2, sizeof(buf2)), VBERROR_SIMULATED, "SendReceive fail"); ResetMocks(); SetResponse(0, 123, 10); ToTpmUint32(buf + 2, 10); TEST_EQ(TlclSendReceive(buf, buf2, sizeof(buf2)), 123, "SendReceive error response"); // TODO: continue self test (if needed or doing) // TODO: then retry doing self test }
bool UnitSyncProcessor::BuildResponse() { SetResponse( _html, Response_Html ); return true; }