LRESULT CALLBACK HookProcLF(int nCode, WPARAM wParam, LPARAM lParam) { LPCWPSTRUCT pcwp = (LPCWPSTRUCT)lParam; if (pcwp->message == WM_KILLFOCUS || pcwp->message == WM_SETFOCUS) { char timeStr[128] = ""; FormatTimeString(timeStr); char className[LEN] = ""; char classNameWP[LEN] = "null"; GetClassName(pcwp->hwnd, className, LEN); if (pcwp->wParam != 0) { GetClassName((HWND)pcwp->wParam, classNameWP, LEN); } FILE* fp = fopen("R:\\hook.log", "at+"); if (fp != nullptr) { if (pcwp->message == WM_KILLFOCUS) { fprintf(fp, "%s %s -> %s\n", timeStr, className, classNameWP); } else if (pcwp->message == WM_SETFOCUS) { fprintf(fp, "%s %s <- %s\n", timeStr, className, classNameWP); } fclose(fp); } } return CallNextHookEx(g_hookLF, nCode, wParam, lParam); }
static void PrintLogHeader() { Text sTime = FormatTimeString(); Print("+====================================================================+\n"); Print("| STARSHATTER %-25s%29s |\n", versionInfo, sTime.data()); Memory::SetLevel(Memory::MAXIMAL); Memory::OpenLog(); MachineInfo::DescribeMachine(); }
BOOL CPlaySettingsPage::LoadSettings() { CString strValue; CRegistry pRegistry; strValue = FormatTimeString( pRegistry.GetInt( "Profit", "PlayRetry", 180 ) ); m_wndRetry.SetCurSel( m_wndRetry.FindStringExact( -1, (LPCTSTR)strValue ) ); if ( m_wndRetry.GetCurSel() == CB_ERR ) { int nItem = m_wndRetry.AddString( strValue ); m_wndRetry.SetCurSel( nItem ); } return TRUE; }
void PlayerDlg::ShowPlayer() { Player* p = Player::GetCurrentPlayer(); if (p) { if (txt_name) txt_name->SetText(p->Name()); if (txt_password) txt_password->SetText(p->Password()); if (txt_squadron) txt_squadron->SetText(p->Squadron()); if (txt_signature) txt_signature->SetText(p->Signature()); char flight_time[64], missions[16], kills[16], losses[16], points[16]; FormatTime(flight_time, p->FlightTime()); sprintf_s(missions, "%d", p->Missions()); sprintf_s(kills, "%d", p->Kills()); sprintf_s(losses, "%d", p->Losses()); sprintf_s(points, "%d", p->Points()); if (lbl_createdate) lbl_createdate->SetText(FormatTimeString(p->CreateDate())); if (lbl_rank) lbl_rank->SetText(Player::RankName(p->Rank())); if (lbl_flighttime) lbl_flighttime->SetText(flight_time); if (lbl_missions) lbl_missions->SetText(missions); if (lbl_kills) lbl_kills->SetText(kills); if (lbl_losses) lbl_losses->SetText(losses); if (lbl_points) lbl_points->SetText(points); if (img_rank) { img_rank->SetPicture(*Player::RankInsignia(p->Rank(), 0)); img_rank->Show(); } for (int i = 0; i < 15; i++) { if (img_medals[i]) { int medal = p->Medal(i); if (medal) { medals[i] = medal; img_medals[i]->SetPicture(*Player::MedalInsignia(medal, 0)); img_medals[i]->Show(); } else { medals[i] = -1; img_medals[i]->Hide(); } } } for (int i = 0; i < 10; i++) { if (txt_chat[i]) txt_chat[i]->SetText(p->ChatMacro(i)); } } else { if (txt_name) txt_name->SetText(""); if (txt_password) txt_password->SetText(""); if (txt_squadron) txt_squadron->SetText(""); if (txt_signature) txt_signature->SetText(""); if (lbl_createdate) lbl_createdate->SetText(""); if (lbl_rank) lbl_rank->SetText(""); if (lbl_flighttime) lbl_flighttime->SetText(""); if (lbl_missions) lbl_missions->SetText(""); if (lbl_kills) lbl_kills->SetText(""); if (lbl_losses) lbl_losses->SetText(""); if (lbl_points) lbl_points->SetText(""); if (img_rank) img_rank->Hide(); for (int i = 0; i < 15; i++) { medals[i] = -1; if (img_medals[i]) img_medals[i]->Hide(); } for (int i = 0; i < 10; i++) { if (txt_chat[i]) txt_chat[i]->SetText(""); } } }
int ProcessTurnAroundMessage(MsgHdr *HdrBuff_P) { int Done = 0; int Rtnval; switch(HdrBuff_P->engEvent) { // // For An Open, Bump the Number Of Clients // case ENGMSG_OPEN : if(Verbose) { FormatTimeString(TimeString,time(0)); printf("\nEngine Calls : %s DPT_OpenEngine", TimeString); fflush(stdout); } ++NumOpenClients; break; // // For a close, Decrement The Number Of Clients, And If This Was The // Last Client And The No Kill Is Not Set, Set Up To Exit // case ENGMSG_CLOSE : if(Verbose) { FormatTimeString(TimeString,time(0)); printf("\nEngine Calls : %s DPT_CloseEngine", TimeString); fflush(stdout); } if(NumOpenClients > 0) { --NumOpenClients; } if(NumOpenClients <= 0) { if(!NoKill) { Done = 1; } } break; // // For An Echo, All That Is Needed Is The Return Message // case ENGMSG_ECHO : if(Verbose) { FormatTimeString(TimeString,time(0)); printf( "\nEngine Calls : %s Engine Echo Message", TimeString); fflush(stdout); } break; } //switch(HdrBuff_P->engEvent) // // Make sure this guy is still out there before putting the message back on the queue // if(kill(HdrBuff_P->callerID,0) == 0) { // // Set Up And Return The Message // HdrBuff_P->MsgID = HdrBuff_P->callerID; HdrBuff_P->callerID = P_ID; Rtnval = msgsnd(MsqID,(struct msgbuf *)HdrBuff_P,MsgDataSize,0); // // If We Had An Error Sending, Print A Message And Exit // if(Rtnval == -1) { if(Verbose) { FormatTimeString(TimeString,time(0)); printf( "\n%s Error Sending A Message In The Engine : %d\n", TimeString,errno); fflush(stdout); } RmLock(NULL); exit(ExitMsgSendFail); } } //if(kill(HdrBuff_P->callerID,0) == 0) else { if(Verbose) { printf("\n : Returning message for PID %ld : no process found, discarding", HdrBuff_P->callerID); } } return(Done); } //int ProcessTurnAroundMessage(MsgHdr *HdrBuff_P)
int main(int argc, char *argv[]) { int Rtnval; int Done; struct sigaction sig; DPT_RTN_T i; // // Set up our argument pointers for others to use // Argc = argc; Argv = argv; # if (defined(_DPT_SOLARIS) || defined(_DPT_ROOTONLY)) // Only root or sys are allowed to run dptutil. if ( ( getuid () != 0 ) && ( geteuid () != 0 ) && ( getuid () != 3 ) && ( geteuid () != 3 ) && ( getgid () != 0 ) && ( getegid () != 0 ) && ( getgid () != 3 ) && ( getegid () != 3 ) ) { printf ("You must be root to run this utility\n"); return (0); } # endif /* Parse The Command Line Parameters, And If An Error Exit */ if(ParseCommandLine(argc,argv)) { exit(ExitBadParameter); } #ifdef _SINIX_ADDON DEBUG_SETOUTPUT(est); if (DebugToFile) { DEBUG_BEGIN(5, "DPT Engine"); DEBUG_SETLEVEL(DebugToFile); } else DEBUG_OFF; SNI_set_compile_date(&engineSig); if (Signature) { printf("%s: V.%d.%c%c %.2d.%.2d.%d\n", engineSig.dsDescription, engineSig.dsVersion, engineSig.dsRevision, engineSig.dsSubRevision, engineSig.dsDay, engineSig.dsMonth, 1980 + engineSig.dsYear); exit(ExitGoodStatus); } #else DEBUG_SETOUTPUT(cerr); DEBUG_OFF; #endif /* Check To See If There Is Already An Engine Out There */ if (MkLock(NULL) == 1) { #ifndef _SINIX_ADDON if(Verbose) #endif printf( "\nThere Appears To Be Another Copy Of dpteng Already Running!\n"); exit(ExitDuplicateEngine); } /* If The Engine Cannot Be Opened, Print A Message And Exit */ i = DPT_StartEngine(); if(i != MSG_RTN_COMPLETED) { if(Verbose) { printf("\nStarting the Engine: "); if (i == ERR_OSD_OPEN_ENGINE) printf("Open HBA(s) "); else if (i == ERR_SEMAPHORE_ALLOC) printf("Alloc Semaphore "); else if (i == ERR_CONN_LIST_ALLOC) printf("Alloc Connection List "); else printf(" With Unknown Error %lx", (unsigned long)i); printf("Failed\n"); } RmLock(NULL); exit(ExitEngOpenFail); } /* Initialize The Signaling */ memset((void *)&sig,0,sizeof(sig)); #if defined ( _DPT_SCO ) || defined ( _DPT_AIX ) || defined( _DPT_BSDI ) || defined(_DPT_FREE_BSD ) || defined(_DPT_LINUX) sig.sa_handler = (void (*)(int))AlarmHandler; #elif defined ( _DPT_SOLARIS ) sig.sa_handler = (void (*)(int))AlarmHandler; /* M0001 - Added UnixWare Support */ #elif defined ( _DPT_UNIXWARE ) sig.sa_handler = (void (*)(int))AlarmHandler; /* M0001 - Added UnixWare DGUX */ #elif defined ( _DPT_DGUX ) sig.sa_handler = (void (*)_PROTO_ARGS((int)))AlarmHandler; #elif defined ( SNI_MIPS ) sig.sa_handler = (void (*)())AlarmHandler; #else #error Define this for your OS #endif #ifdef NEW_LOGGER #if defined(_DPT_SCO) || defined(_DPT_BSDI) || defined(_DPT_FREE_BSD) || defined(_DPT_LINUX) || defined (_DPT_SOLARIS) // ignore sighup, sigterm will come later after a few seconds signal(SIGHUP, (void (*) (int)) DptSignalIgnore); signal(SIGTERM, (void (*) (int)) DptSignalIgnore); signal(SIGCHLD, (void (*) (int)) DptSignalIgnore); #else #error Define me. These are shutdown signals to ignore so the SOC logger // can write its final heartbeat on a shutdown #endif #endif //#ifdef NEW_LOGGER /* If The Signaling Could Not Be Set Up, Print An Error And Exit */ if(sigaction(SIGALRM,&sig,0) == -1) { if(Verbose) printf("\nSignaling Could Not Be Set Up\n"); RmLock(NULL); exit(ExitSignalFail); } /* if no debug mode selected, start engine as daemon (like inetd) */ /* i.e. fork son proc and create new session id. - michiz */ if (!Verbose && !EataHex && !EataInfo && !DebugEngMsg) { int i; if ((i = fork()) != 0) { ChLock(NULL, i); exit(0); } setsid(); } #ifdef _SINIX_ADDON /* New option -stop to kill a hanged up engine */ if (ExitEngine) { int i; struct msqid_ds CtlBuf; MsqID = msgget(DPT_EngineKey, MSG_ALLRD | MSG_ALLWR); if(MsqID != -1) { msgctl(MsqID, IPC_STAT, &CtlBuf); // Stop engine only, if no dptmgr still running if ( CtlBuf.msg_lspid && CtlBuf.msg_lrpid && (getpgid(CtlBuf.msg_lspid) != -1) && (getpgid(CtlBuf.msg_lrpid) != -1)) printf("You must stop dptmgr first\n"); else { i = MessageDPTEngine(DPT_EngineKey, MsqID, ENGMSG_CLOSE, 2,1); if (i) msgctl(MsqID, IPC_RMID, &CtlBuf); if(Verbose) printf("dpteng successfully stopped\n"); } } RmLock(NULL); exit(ExitGoodStatus); } #endif /* Check To See If There Is Already An Engine Out There */ MsqID = CheckForEngine(DPT_EngineKey,1,2); if(MsqID != -1) { #ifndef _SINIX_ADDON if(Verbose) #endif printf( "\nThere Appears To Be Another Copy Of dpteng Already Running!\n"); RmLock(NULL); exit(ExitDuplicateEngine); } /* Get The Process ID To Use As The Unique Caller ID */ P_ID = getpid(); /* Try To Create The Unique Message Que Of This ID */ MsqID = msgget(DPT_EngineKey,IPC_CREAT | IPC_EXCL | MSG_ALLRD | MSG_ALLWR); /* If We Could Not Allocate The Message Que, Print A Message And Exit */ if(MsqID == -1) { if(Verbose) printf("\nThe Message Queue Could Not Be Allocated\n"); RmLock(NULL); exit(ExitMsqAllocFail); } /* Set Up The Function To Call When The Program Terminates Normally */ atexit(ProgramUnload); /* Loop Forever Waiting For A Header Message To Come In. Once A Header */ /* Message Is Received, We Will Attach To The Shared Memory Segment */ /* That Is Passed In The Header. This Memory Is The In And Out Buffers */ Done = 0; if(Verbose) printf("\ndpteng Is Ready.\n"); while(1) { // // At the top of the loop, we will pull off and process all turnaround messages on the queue since // they don't have to be sent down to the engine // while((Rtnval = (msgrcv(MsqID,(struct msgbuf *)&HdrBuff, MsgDataSize, DPT_TurnAroundKey,IPC_NOWAIT) != -1))) { Done = ProcessTurnAroundMessage(&HdrBuff); } // // If Done is set, there are no more clients, so let's // check for any messages in the queue before we exit. It // is possible that someone is trying to load and we don't // want to pull the rug out from under him // if(Done) { Rtnval = msgrcv(MsqID,(struct msgbuf *)&HdrBuff, MsgDataSize, -DPT_EngineKey,IPC_NOWAIT); // // If the call failed, were OUT-O-HERE // if(Rtnval == -1) { if(Verbose) { printf("\n : No Clients, Engine Unloads"); } break; } // // There was a message on the queue so continue processing // Done = 0; } // // Done is not set, so wait for a message to come in // else { while((Rtnval = (msgrcv(MsqID,(struct msgbuf *)&HdrBuff, MsgDataSize, -DPT_EngineKey,0) == -1))) { /* If The Message Failed, And The Reason Was Not An Interrupt, Exit */ if(errno != EINTR) break; } } /* If The Message Received OK Go Process It */ if(Rtnval == 0) { // // Check to make sure this guy is still out there before processing the message // if not, throw away the message // if(kill(HdrBuff.callerID,0) != 0) { if(Verbose) { printf("\n : Message received for PID %ld : no process found, discarding", HdrBuff.callerID); } continue; } /* If This Is A Turnarround Message, Process it */ if((HdrBuff.engineTag == HdrBuff.callerID)&& (HdrBuff.engineTag == HdrBuff.targetTag)) { Done = ProcessTurnAroundMessage(&HdrBuff); continue; } /* Attach To The Shared Memory */ toEng_P = (uCHAR *)shmat((int)HdrBuff.BufferID,0,0); /* Make Sure That We Could Attach */ if((long)toEng_P != -1) { fromEng_P = toEng_P + HdrBuff.FromEngBuffOffset; /* M0000 : New Verbose Statements */ if(Verbose) { FormatTimeString(TimeString,time(0)); printf("\nEngine Calls : %s DPT_CallEngine",TimeString); printf( "\n EngTag = %lx, Event = %lx, Target = %lx", (unsigned long)HdrBuff.engineTag, (unsigned long)HdrBuff.engEvent, (unsigned long)HdrBuff.targetTag); printf( "\n Offset = %lx fromEng_P = %lx toEng_P = %lx", HdrBuff.FromEngBuffOffset, (unsigned long)fromEng_P, (unsigned long)toEng_P); /*#else "\n EngTag = %x, Event = %x, Target = %x", HdrBuff.engineTag,HdrBuff.engEvent,HdrBuff.targetTag); #endif */ fflush(stdout); } /* All Went Well With The Receive, So Call The Engine */ HdrBuff.result = DPT_Engine( HdrBuff.engineTag, HdrBuff.engEvent, HdrBuff.targetTag, fromEng_P,toEng_P, HdrBuff.timeOut); // // Detach from the memory segment // shmdt((char *)toEng_P); // // Check to make sure this guy is still out there before returning the message // if not, throw away the message // if(kill(HdrBuff.callerID,0) != 0) { if(Verbose) { printf("\n : Returning message for PID %ld : no process found, discarding", HdrBuff.callerID); } continue; } /* Set Up The Proper Message Type In The Buffer Headers */ HdrBuff.MsgID = HdrBuff.callerID; HdrBuff.callerID = DPT_EngineKey; Rtnval = msgsnd(MsqID,(struct msgbuf *)&HdrBuff,MsgDataSize,0); /* If We Had An Error Sending, Print A Message And Exit */ if(Rtnval == -1) { if(Verbose) { FormatTimeString(TimeString,time(0)); printf( "\n%s Error Sending A Message In The Engine : %d\n", TimeString,errno); fflush(stdout); } RmLock(NULL); exit(ExitMsgSendFail); } } /* else printf("\nError Trying To Attach To The Memory"); */ } /* If We Had An Error Receiving, Print A Message And Exit */ else { if(Verbose) { FormatTimeString(TimeString,time(0)); printf( "\n%s Error Receiving A Message In The Engine : %d\n", TimeString,errno); fflush(stdout); } RmLock(NULL); exit(ExitMsgReceiveFail); } } } //main(int argc, char *argv[])