int main( int argc, char **argv ) { POINTER mem_lock; uintptr_t size = 0; TEXTCHAR *myname = StrDup( pathrchr( DupCharToText( argv[0] ) ) ); TEXTCHAR *endname; TEXTCHAR lockname[256]; if( myname ) myname++; else myname = DupCharToText( argv[0] ); // go to the .exe extension endname = (TEXTCHAR*)StrRChr( myname, '.' ); if( endname ) { // remove .exe extension endname[0] = 0; // go to the .stop extension endname = (TEXTCHAR*)StrRChr( myname, '.' ); } if( endname ) { // remove .stop extension endname[0] = 0; } else { // this would be an invalid name. return 0; } snprintf( lockname, sizeof( lockname ), WIDE( "%s.instance.lock" ), myname ); lprintf( WIDE( "Checking lock %s" ), lockname ); mem_lock = OpenSpace( lockname , NULL //, WIDE("memory.delete") , &size ); if( mem_lock ) { #ifdef WIN32 PRENDER_INTERFACE pri = GetDisplayInterface(); PVIDEO video = (PVIDEO)mem_lock; if( video->hWndOutput ) { ForceDisplayFocus( video ); RestoreDisplay( video ); } else { // region found, but no content... } #endif } else lprintf( WIDE("lock region not found.") ); return 0; }
int main( int argc, char **argv ) { struct url_data *data = SACK_URLParse( DupCharToText( argv[1] ) ); CTEXTSTR url = SACK_BuildURL( data ); printf( WIDE("recode: %s\n"), url ); printf( WIDE("protocol =%s\n"),data->protocol ); printf( WIDE("user =%s\n"),data->user ); printf( WIDE("password =%s\n"),data->password ); printf( WIDE("host =%s\n"),data->host ); printf( WIDE("default port =%d\n"),data->default_port ); printf( WIDE("port =%d\n"),data->port ); printf( WIDE("resource_path =%s\n"),data->resource_path ); printf( WIDE("resource_file =%s\n"),data->resource_file ); printf( WIDE("resource_extension =%s\n"),data->resource_extension ); printf( WIDE("resource_anchor =%s\n"),data->resource_anchor ); if( !data->cgi_parameters ) printf( WIDE("No CGI Parameters.\n") ); else { INDEX idx; struct url_cgi_data *cgi_data; LIST_FORALL( data->cgi_parameters, idx, struct url_cgi_data *, cgi_data ) { printf( WIDE("CGI PARAM %d: %s=%s\n"), idx, cgi_data->name, cgi_data->value ); } } return 0; }
int main( int argc, char **argv ) { FILE *input = stdin; PVARTEXT pvt_cmd; TEXTCHAR readbuf[4096]; TEXTCHAR *buf; int offset = 0; int no_headers = 0; PODBC default_odbc = NULL; CTEXTSTR select_into; PLIST output = NULL; PLIST outputs = NULL; int arg_ofs = 0; SQLSetFeedbackHandler( ShowSQLStates ); //SetAllocateDebug( TRUE ); //SetAllocateLogging( TRUE ); if( argc < 2 ) Usage( 1 ); else { while( argv[1+arg_ofs] && ( argv[1+arg_ofs][0] == '-' ) ) { TEXTSTR tmp; switch( argv[1+arg_ofs][1] ) { case 'n': no_headers = 1; break; case 'f': arg_ofs++; input = sack_fopen( 0, tmp = DupCharToText( argv[1+arg_ofs] ), WIDE("rt") ); if( input ) SQLSetFeedbackHandler( LogSQLStates ); break; } if( tmp ) { Deallocate( TEXTSTR, tmp ); tmp = NULL; } arg_ofs++; } if( argv[1+arg_ofs] ) default_odbc = ConnectToDatabase( DupCharToText( argv[1 + arg_ofs] ) ); } SetHeapUnit( 4096 * 1024 ); // 4 megs expansion if needed... pvt_cmd = VarTextCreateExx( 10000, 50000 ); while( (buf = readbuf), fgets( readbuf + offset , sizeof( readbuf ) - offset , input ) ) { CTEXTSTR *result = NULL; size_t len; while( buf[0] == WIDE(' ') || buf[0] == WIDE('\t') ) buf++; len = strlen( buf ); if( buf[0] == WIDE('#') ) continue; if( ( len > 0 ) && buf[len-1] == WIDE('\n') ) { len--; buf[len] = 0; } if( strcmp( buf, WIDE("\\q") ) == 0 ) break; if( !buf[0] && VarTextLength( pvt_cmd ) == 0 ) continue; if( ( len > 0 ) && buf[len-1] == WIDE('\\') ) { buf[len-1] = 0; len--; vtprintf( pvt_cmd, WIDE("%s"), buf ); offset = 0; //offset = (len - 1); // read over the slash continue; } else { if( len > 0 ) vtprintf( pvt_cmd, WIDE("%s"), buf ); offset = 0; } buf = GetText( VarTextPeek( pvt_cmd ) ); if( buf[0] == WIDE('?') ) { int fields; int replace = 0; int ofs = 1; CTEXTSTR *columns; TEXTSTR *_columns; PVARTEXT pvt = NULL; if( buf[1] == WIDE('!') ) { replace = 1; ofs = 2; } if( output ) { if( !select_into || !select_into[0] ) { printf( WIDE("Table name was invalid to insert into on the destination side...\'%s\'"), select_into ); VarTextEmpty( pvt_cmd ); continue; } pvt = VarTextCreateExx( 10000, 50000 ); } if( SQLRecordQuery( default_odbc, buf + ofs, &fields, &result, &columns ) ) { int count = 0; int first = 1; _columns = NewArray( TEXTSTR, fields ); if( !no_headers ) { { int n; for( n = 0; n < fields; n++ ) { _columns[n] = StrDup( columns[n] ); if( !pvt ) fprintf( stdout, WIDE("%s%s"), n?WIDE(","):WIDE(""), columns[n] ); } } if( !pvt ) fprintf( stdout, WIDE("\n") ); } for( ; result; FetchSQLRecord( default_odbc, &result ) ) { if( pvt && first ) { vtprintf( pvt, WIDE("%s into `%s` ("), replace?WIDE("replace"):WIDE("insert ignore"), select_into ); { int first = 1; int n; for( n = 0; n < fields; n++ ) { vtprintf( pvt, WIDE("%s`%s`"), first?WIDE(""):WIDE(","), _columns[n] ); first = 0; } } vtprintf( pvt, WIDE(") values ") ); } if( pvt ) { vtprintf( pvt, WIDE("%s("), first?WIDE(""):WIDE(",") ); { int first = 1; // private first, sorry :) parse that, Visual studio can. int n; for( n = 0; n < fields; n++ ) { TEXTSTR tmp; vtprintf( pvt, WIDE("%s%s") , first?WIDE(""):WIDE(",") , result[n]?(tmp=EscapeStringOpt( result[n], TRUE)):((tmp=NULL),WIDE("NULL")) ); Release( tmp ); first = 0; } } vtprintf( pvt, WIDE(")") ); } else { int n; int first = 1; for( n = 0; n < fields; n++ ) { fprintf( stdout, WIDE("%s%s"), first?WIDE(""):WIDE(","),result[n]?result[n]:WIDE("NULL") ); first = 0; } fprintf( stdout, WIDE("\n") ); } first = 0; count++; if( ( VarTextLength( pvt ) ) > 100000 ) { PTEXT cmd; first = 1; // reset first to rebuild the beginning of the insert. printf( WIDE("Flushing at 100k characters...%d records\n"), count ); if( pvt ) { cmd = VarTextGet( pvt ); if( cmd ) { INDEX idx; PODBC odbc; LIST_FORALL( output, idx, PODBC, odbc ) { if( !SQLCommand( odbc, GetText( cmd ) ) ) printf( WIDE("Failed command to:%s\n"), (CTEXTSTR)GetLink( &outputs, idx ) ); } LineRelease( cmd ); } } } } if( !no_headers ) { int n; for( n = 0; n < fields; n++ ) { Release( _columns[n] ); } } Release( _columns ); }
void CPROC ReadComplete( PCLIENT pc, POINTER buffer, size_t size ) { static uint64_t LastMessage; // this is safe - only ONE connection EVER uint64_t test; int ToRead = 8; if( !buffer ) { Log( WIDE("Initial Read issued allocated buffer...read events a go.") ); buffer = Allocate( 1024 ); } else { ((TEXTCHAR*)buffer)[size] = 0; if( !LastMessage ) { Log1( WIDE("Message is: %8.8s"), buffer ); if( *(uint64_t*)buffer == *(uint64_t*)"USERLIST" ) { Log1( WIDE("Message is: USERLIST!!"), buffer ); ToRead = 2; LastMessage = *(uint64_t*)buffer; Log1( WIDE("Last Message is: %8.8s"), &LastMessage ); } else if( *(uint64_t*)buffer == *(uint64_t*)"USERDEAD" ) { BasicMessageBox( WIDE("Relay Responce"), WIDE("User has been terminated!") ); RemoveClient( pc ); } else if( *(uint64_t*)buffer == *(uint64_t*)"ALL DONE" ) { RemoveClient( pc ); } else if( *(uint64_t*)buffer == *(uint64_t*)"MESSAGE!" || *(uint64_t*)buffer == *(uint64_t*)"WINNERS:" ) { ToRead = 1; LastMessage = *(uint64_t*)buffer; } else if( *(uint64_t*)buffer == *(uint64_t*)"MASTERIS" ) { LastMessage = *(uint64_t*)buffer; } else { printf( WIDE("Unknown responce from relay: %8.8s"), buffer ); } } else { Log1( WIDE("Continuing message: %8.8s"), &LastMessage ); if( LastMessage == *(uint64_t*)"MESSAGE!" || LastMessage == *(uint64_t*)"WINNERS:" ) { Log( WIDE("(1)") ); ToRead = *(uint8_t*)buffer; LastMessage++; } else if( (test = ((*(uint64_t*)"WINNERS:")+1)), (LastMessage == test) ) { PCONTROL pcList = GetControl( frame, LST_WINNERS ); TEXTCHAR *winnerlist = (TEXTCHAR*)buffer; TEXTCHAR *endline, lastchar; ResetList( pcList ); winnerlist[size] = 0; Log2( WIDE("Got %d bytes of data:%s"), size, winnerlist ); endline = winnerlist; do { while( endline[0] && ( endline[0] != ',' && endline[0] != ':' ) ) { if( endline[0] == 3 ) endline[0] = ' '; // space fill this... endline++; } lastchar = endline[0]; //if( endline[0] ) { endline[0] = 0; AddListItem( pcList, winnerlist ); if( lastchar ) { winnerlist = endline+1; while( winnerlist[0] && winnerlist[0] == ' ' ) winnerlist++; endline = winnerlist; } } } while( endline[0] ); LastMessage = 0; } else if( (test = ((*(uint64_t*)"MESSAGE!")+1)), (LastMessage == test) ) { Log( WIDE("(2)") ); BasicMessageBox( WIDE("Relay Message"), DupCharToText( (char*)buffer ) ); LastMessage = 0; } else if( LastMessage == *(uint64_t*)"MASTERIS" ) { if( *(uint64_t*)buffer == *(uint64_t*)"ABSENT.." ) { SetControlText( GetControl( frame, CHK_MASTER ), WIDE("Game Master is absent") ); } else if( *(uint64_t*)buffer == *(uint64_t*)"PRESENT!" ) { SetControlText( GetControl( frame, CHK_MASTER ), WIDE("Game Master is PRESENT") ); } else { BasicMessageBox( WIDE("Master Status"), WIDE("Unknown Responce...") ); } LastMessage = 0; RemoveClient( pc ); } else if( LastMessage == (*(uint64_t*)"USERLIST") ) { Log( WIDE("(3)") ); ToRead = *(uint16_t*)buffer; Log1( WIDE("User list with size of %d"), ToRead ); LastMessage++; } else if( (test = ((*(uint64_t*)"USERLIST")+1) ), (LastMessage == test) ) { PCONTROL pcList = GetControl( frame, LST_USERS ); TEXTCHAR *userlist = (TEXTCHAR*)buffer; TEXTCHAR *endline; //Log1( WIDE("Got %d bytes of data..."), size ); ResetList( pcList ); userlist[size] = 0; endline = userlist; do { while( endline[0] && endline[0] != '\n' ) { if( endline[0] == 3 ) endline[0] = ' '; // space fill this... endline++; } if( endline[0] ) { TEXTCHAR *endname; TEXTCHAR *realname; PLISTITEM hli; endline[0] = 0; hli = AddListItem( pcList, userlist ); endname = userlist; while( endname[0] != ' ' ) endname++; endname[0] = 0; realname = NewArray( TEXTCHAR, ( endname - userlist ) + 1 ); StrCpyEx( realname, userlist, max( ( endname - userlist ), size ) ); SetItemData( hli, (uintptr_t)realname ); endline++; userlist = endline; } } while( endline[0] ); LastMessage = 0; RemoveClient( pc ); } else { Log1( WIDE("Unknonw Continuation state for %8.8s"), &LastMessage ); } } } ReadTCPMsg( pc, buffer, ToRead ); }
int main( int argc, char **argv ) { POINTER mem_lock; uintptr_t size = 0; TEXTCHAR *myname = StrDup( pathrchr( DupCharToText( argv[0] ) ) ); TEXTCHAR *endname; TEXTCHAR lockname[256]; if( myname ) myname++; else myname = DupCharToText( argv[0] ); // go to the .exe extension endname = (TEXTCHAR*)StrRChr( myname, '.' ); if( endname ) { // remove .exe extension endname[0] = 0; // go to the .stop extension endname = (TEXTCHAR*)StrRChr( myname, '.' ); } if( endname ) { // remove .stop extension endname[0] = 0; } else { // this would be an invalid name. return 0; } snprintf( lockname, sizeof( lockname ), WIDE( "%s.instance.lock" ), myname ); lprintf( WIDE( "Checking lock %s" ), lockname ); mem_lock = OpenSpace( lockname , NULL //, WIDE("memory.delete") , &size ); if( mem_lock ) { #ifdef WIN32 PRENDER_INTERFACE pri = GetDisplayInterface(); PVIDEO video = (PVIDEO)mem_lock; if( video->hWndOutput ) { ForceDisplayFocus( video ); keybd_event( VK_MENU, 56, 0, 0 ); keybd_event( VK_F4, 62, 0, 0 ); keybd_event( VK_F4, 62, KEYEVENTF_KEYUP, 0 ); keybd_event( VK_MENU, 56, KEYEVENTF_KEYUP, 0 ); #if 0 { int tick = timeGetTime(); while( ( tick + 15000 > timeGetTime() ) && IsWindow( video->hWndOutput ) ) WakeableSleep( 100 ); if( IsWindow( video->hWndOutput ) ) #define WM_EXIT_PLEASE 0xd1e if( !SendMessage( video->hWndOutput, WM_QUERYENDSESSION, 0, 0 ) ) printf( "Failed to post queyendsession." ); } #endif } else { // region found, but no content... } #endif } else lprintf( WIDE("lock region not found.") ); return 0; }