INDEX LAYER::Save( PODBC odbc ) { if( !this ) return INVALID_INDEX; if( iLayer && iLayer != INVALID_INDEX ) { lprintf( WIDE("Recovering prior layer") ); return iLayer; } { INDEX iStart = route_start_layer.layer->Save( odbc ); INDEX iEnd = route_end_layer.layer->Save( odbc ); INDEX iPeice; if( pLayerData ) iPeice = pLayerData->peice->Save( odbc, iLayer, pLayerData->psvInstance ); else iPeice = INVALID_INDEX; SQLInsert( odbc, WIDE("board_layer") ,WIDE("x") , 2, x ,WIDE("y"), 2, y ,WIDE("min_x"), 2, min_x ,WIDE("min_y"), 2, min_y ,WIDE("width"), 2, w ,WIDE("height"), 2, h ,WIDE("linked_from_id"), 2, iStart ,WIDE("linked_from_x"), 2, route_start_layer.x ,WIDE("linked_from_y"), 2, route_start_layer.y ,WIDE("linked_to_id"), 2, iEnd ,WIDE("linked_to_x"), 2, route_end_layer.x ,WIDE("linked_to_y"), 2, route_end_layer.y ,WIDE("route"), 2, flags.bRoute ,WIDE("peice_info_id"), 2, iPeice ,WIDE("peice_type"), 1, pLayerData->peice->name() , NULL, 0, NULL ); iLayer = FetchLastInsertID( odbc, NULL, NULL ); lprintf( WIDE("Saved %lu"), iLayer ); } if( flags.bRoute /*&& pds_path*/ ) { INDEX idx; PLAYER_PATH_NODE path_node; for( idx = 0; path_node = (PLAYER_PATH_NODE)PeekDataEx( &pds_path, idx ); idx++ ) { SQLCommandf( odbc , WIDE("insert into board_layer_path(board_layer_id,x,y,fore,back)values(%lu,%ld,%ld,%d,%d)") , iLayer , path_node->x, path_node->y , path_node->flags.ForeDir, path_node->flags.BackDir ); } } return iLayer; }
static void InitView() { CTEXTSTR *results; PODBC odbc = SQLGetODBCEx( cashball_local.DSN, cashball_local.user, cashball_local.password ); SQLCommandf( odbc, "use %s", cashball_local.database ); if( SQLRecordQueryf( odbc, NULL, &results, NULL, "select count(*) from INFORMATION_SCHEMA.VIEWS where table_name = 'v_SessionCashball'" ) ) { if( results && results[0][0] == '0' ) { SQLEndQuery( odbc ); if( !SQLCommandf( odbc, "CREATE VIEW v_SessionCashball as " "SELECT top 1 itemprog.pri_sunball Cashball" " FROM Itemprog inner join" " (SELECT top 1 dbo.session.ses_id, dbo.session.hallid, dbo.session.ses_date, ISNULL(RTRIM(dbo.program.prg_desc) + ' - ' + RTRIM(dbo.sesslot.slt_desc)" " + CASE WHEN [Session].Ses_Test = 1 THEN ' (Test)' ELSE '' END, '') AS SessionName" " FROM dbo.session\n" " INNER JOIN dbo.program ON dbo.session.prg_id = dbo.program.prg_id \n" " INNER JOIN dbo.sesslot ON dbo.session.slt_id = dbo.sesslot.slt_id \n" " WHERE ses_status=2" " ORDER BY dbo.session.ses_id desc )\n" " AS SessionTemp ON itemprog.ses_id=sessionTemp.ses_id" ) ) { CTEXTSTR error; FetchSQLError( odbc, &error ); lprintf( "Error : %s", error ); } } SQLEndQuery( odbc ); } else { CTEXTSTR error; FetchSQLError( odbc, &error ); lprintf( "Error : %s", error ); } SQLDropODBC( odbc ); }
//---------------------------------------------------------------------------------------- // Timer for checking the timestamp static uintptr_t CPROC countDown( PTHREAD thread ) { TEXTCHAR buf[45]; uint8_t found = 0; uint32_t startTime; PODBC odbc; // Loop forever while( 1 ) { // Get Current time startTime = timeGetTime(); // Sleep to next timeout if( l.flags.bLogSleeps ) { long x = ( l.iIdleTime*(60)*(1000) ) - ( startTime - l.last_event_time ); lprintf( WIDE("Sleep for... %d:%02d.%03d"), x / 60000, (x / 1000 ) %60, x % 1000 ); } if( ( l.iIdleTime*(60)*(1000) ) > ( startTime - l.last_event_time ) ) WakeableSleep( ( l.iIdleTime*(60)*(1000) ) - ( startTime - l.last_event_time ) ); startTime = timeGetTime(); // sleep some more if we got a new event if( ( l.iIdleTime*(60)*(1000) ) > ( startTime - l.last_event_time ) ) continue; // Make connection to database odbc = SQLGetODBC( l.option_dsn ); if( l.flags.bLogSleeps ) lprintf( WIDE("woke up and user is %p (%d)"), HaveCurrentUser( odbc ), ( startTime - l.last_event_time ) ); // If there is current user, else there is no active logins or processes to kill if( HaveCurrentUser( odbc ) ) { uint32_t target_tick = startTime + ( l.iScreenSaverWaitTime * 1000 ); int32_t remaining = ( target_tick - startTime ); // Get time // Check last event, if timeout not hit go back to sleep until timeout will be hit if( remaining < 0 ) { if( l.flags.bLogSleeps ) lprintf( WIDE("Not enough time, go back and wait...") ); // Close Connection to database SQLDropODBC( odbc ); // not enough time has really passed... sleep more continue; } // Let hook know to update activity flag l.flags.countingDown = 1; // Start countdown do { // Update time to check against remaining = ( target_tick - startTime ); // Update Banner Message snprintf( buf, sizeof( buf ), WIDE(" The system will logout in %d.%03d seconds...") , remaining / 1000, remaining % 1000 ); BannerTopNoWait( buf ); // Don't eat to much cpu time IdleFor( 200 ); startTime = timeGetTime(); } while( l.flags.countingDown && ( target_tick > startTime ) ); // If countdown made it to 0 if( ( target_tick < startTime ) ) { uint32_t x; uint32_t y; // Logout users SQLCommandf( odbc , WIDE("update login_history set logout_whenstamp=now() where logout_whenstamp=11111111111111 and system_id=%d"), g.system_id ); // Get current process list if ( !EnumProcesses( l.pidList2, sizeof( l.pidList2 ), &l.pidListLength2 ) ) lprintf( WIDE(" Getting Process List 2 Failed!") ); // Kill Processes for( x = 0; x < l.pidListLength2; x++ ) { // Check if process existed originally for( y = 0; y < l.pidListLength1; y++ ) { if( l.pidList2[x] == l.pidList1[y] ) { found = 1; break; } } // If did not exist originally kill the process if( !found ) { TEXTCHAR cmd[25]; snprintf( cmd, sizeof( cmd ), WIDE("pskill %d"), l.pidList2[x] ); System( cmd, LogOutput, 0 ); } found = 0; } // Give extra time to see Banner IdleFor( 500 ); // Reset Data l.flags.countingDown = 0; } // Remove Banner RemoveBanner2Ex( NULL DBG_SRC ); } else { // fake an event, there was no user, so didn't do anything, just sleep more l.last_event_time = startTime; } // Close Connection to database SQLDropODBC( odbc ); } return 0; }