CTelnetServer::~CTelnetServer(void) { DebugTry(Shutdown()); DebugTry(DeleteCriticalSection(&ProcessingCS)); DebugTry(DeleteCriticalSection(&ListCS)); DebugTry(DeleteCriticalSection(&BufferCS)); DebugTry(DeleteCriticalSection(&CommandCS)); // DONT WSACleanup(?) }
PLUGIN_API VOID SetGameState(DWORD GameState) { DebugSpew("MQ2ChatWnd::SetGameState()"); if (GameState==GAMESTATE_CHARSELECT) { if (bNoCharSelect) { // destroy chatwnd at charselect if NoCharSelect=on DestroyChatWnd(); } else { AddMQ2KeyBind("MQ2CSCHAT",DoMQ2ChatBind); KeyCombo Combo; ParseKeyCombo("/",Combo); SetMQ2KeyBind("MQ2CSCHAT",FALSE,Combo); } } else { if (GameState!=GAMESTATE_CHARCREATE) RemoveMQ2KeyBind("MQ2CSCHAT"); if (GameState==GAMESTATE_INGAME && !MQChatWnd) { // we entered the game, set up shop DebugTry(CreateChatWindow()); } } }
// This is called every time WriteChatColor is called by MQ2Main or any plugin, // IGNORING FILTERS, IF YOU NEED THEM MAKE SURE TO IMPLEMENT THEM. IF YOU DONT // CALL CEverQuest::dsp_chat MAKE SURE TO IMPLEMENT EVENTS HERE PLUGIN_API DWORD OnWriteChatColor(PCHAR Line, DWORD Color, DWORD Filter) { //DebugSpewAlways("MQ2ChatWnd::OnWriteChatColor(%s)",Line); if (!MQChatWnd) { if (gGameState==GAMESTATE_INGAME) { SetGameState(gGameState); } if (!MQChatWnd) { return 0; } } MQChatWnd->dShow=1; PFILTER pFilter=gpFilters; while (pFilter) { if (!pFilter->pEnabled || (*pFilter->pEnabled)) { if (!_strnicmp(Line,pFilter->FilterText,pFilter->Length)) { return 0; } } pFilter = pFilter->pNext; } Color=pChatManager->GetRGBAFromIndex(Color); CHAR szProcessed[MAX_STRING]; pPlugins; MQToSTML(Line,szProcessed,MAX_STRING,Color); pPlugins; strcat_s(szProcessed,"<br>"); CXStr NewText(szProcessed); DebugTry(ConvertItemTags(NewText,FALSE)); ChatBuffer *pNewBuffer = new ChatBuffer; GetCXStr(NewText.Ptr,pNewBuffer->Text,MAX_STRING); pNewBuffer->pPrev=pPendingChatTail; pNewBuffer->pNext=0; if (pPendingChatTail) { pPendingChatTail->pNext=pNewBuffer; } else { pPendingChat=pNewBuffer; } pPendingChatTail=pNewBuffer; PendingChatLines++; return 0; }
void PulseService(bool Broadcast, unsigned int MSG, void *lpData) { if (MSG == PULSE_PULSE) { if (GetGameState() == GAMESTATE_CHARSELECT && !MQChatWnd) { CreateChatWindow(); } if (MQChatWnd && PendingChatLines) { bool doscroll = (((CXWnd*)MQChatWnd->OutputBox)->VScrollPos == (MQChatWnd->OutputBox->VScrollMax)); DWORD ThisPulse = PendingChatLines; if (ThisPulse > LINES_PER_FRAME) { ThisPulse = LINES_PER_FRAME; } PendingChatLines -= ThisPulse; MQChatWnd->OutBoxLines += ThisPulse; if (MQChatWnd->OutBoxLines > MAX_CHAT_SIZE) { DWORD Diff = (MQChatWnd->OutBoxLines - MAX_CHAT_SIZE) + LINES_PER_FRAME; MQChatWnd->OutBoxLines -= Diff; Benchmark(bmStripFirstStmlLines, MQChatWnd->OutputBox->StripFirstSTMLLines(Diff)); } for (DWORD N = 0 ; N < ThisPulse ; N++) { DebugTry(MQChatWnd->OutputBox->AppendSTML( pPendingChat->Text)); ChatBuffer *pNext = pPendingChat->pNext; delete pPendingChat; pPendingChat = pNext; } if (!pPendingChat) { pPendingChatTail = 0; } if (doscroll || MQChatWnd->AutoScroll) { DebugTry(((CXWnd*)MQChatWnd->OutputBox)->SetVScrollPos(MQChatWnd->OutputBox->VScrollMax)); } } } }
void ConsoleService(bool Broadcast, unsigned int MSG, void *lpData) { if (MSG != CONSOLE_OUTPUT_WITHCODES) { return; } // same as OnWriteChatColor if (!MQChatWnd) { EQGamestateService(false, GAMESTATESERVICE_CHANGED, (void*)gGameState); if (!MQChatWnd) { return; } } MQChatWnd->dShow = 1; PCHAR pConsOutput = (PCHAR)lpData; PFILTER pFilter = gpFilters; while (pFilter) { if (!pFilter->pEnabled || (*pFilter->pEnabled)) { if (!strnicmp(pConsOutput, pFilter->FilterText, pFilter->Length)) { return; } } pFilter = pFilter->pNext; } DWORD Color = pChatManager->GetRGBAFromIndex(USERCOLOR_DEFAULT); CHAR szProcessed[MAX_STRING]; MQToSTML(pConsOutput, szProcessed, MAX_STRING, Color); strcat(szProcessed,"<br>"); CXStr NewText(szProcessed); DebugTry(ConvertItemTags(NewText, 0)); CLock L(&ChatS,1); ChatBuffer *pNewBuffer = new ChatBuffer; GetCXStr(NewText.Ptr, pNewBuffer->Text, MAX_STRING); pNewBuffer->pPrev = pPendingChatTail; pNewBuffer->pNext = 0; if (pPendingChatTail) { pPendingChatTail->pNext = pNewBuffer; } else { pPendingChat = pNewBuffer; } pPendingChatTail = pNewBuffer; PendingChatLines++; }
void CTelnetServer::Shutdown() { // close listener DebugTry(ShutdownListener()); bKillThread=true; while(bThreading) Sleep(20); // the critical section wasnt holding for some reason.. //EnterCriticalSection(&ProcessingCS); // wait until thread shuts down.. EnterCriticalSection(&CommandCS); // close all connections while(Connections) { // remove connection... _TELNET *Next=Connections->pNext; while(Connections->Received) { PCHATBUF rNext=Connections->Received->pNext; free(Connections->Received); Connections->Received=rNext; } delete Connections->connection; delete Connections; Connections=Next; } // delete all extra shit while(Sends) { PCHATBUF pNext=Sends->pNext; free(Sends); Sends=pNext; } while(Commands) { PCHATBUF pNext=Commands->pNext; free(Commands); Commands=pNext; } LeaveCriticalSection(&CommandCS); //DebugTry(LeaveCriticalSection(&ProcessingCS)); }
void EQGamestateService(bool Broadcast, unsigned int MSG, void *lpData) { if (MSG == GAMESTATESERVICE_CHANGED) { DWORD GameState = (DWORD)lpData; if (GameState == GAMESTATE_CHARSELECT) { AddMQ2KeyBind("MQ2CSCHAT", DoMQ2ChatBind); KeyCombo Combo; ParseKeyCombo("/", Combo); SetMQ2KeyBind("MQ2CSCHAT", 0, Combo); } else { RemoveMQ2KeyBind("MQ2CSCHAT"); if (GameState == GAMESTATE_INGAME && !MQChatWnd) { // we entered the game, set up shop DebugTry(CreateChatWindow()); } } } }
void SetChatFont(int size) // brainiac 12-12-2007 { struct FONTDATA { DWORD NumFonts; PCHAR* Fonts; }; FONTDATA* Fonts; // font array structure DWORD* SelFont; // selected font // get fonts structure -- this offset can be found by looking at // SetChatfont which is called from the /chatfontsize function Fonts = (FONTDATA*)&(((char*)pWndMgr)[EQ_CHAT_FONT_OFFSET]); // check font array bounds and pointers if (size<0 || size>=(int)Fonts->NumFonts) { return; } if (!Fonts->Fonts || !MQChatWnd) { return; } //DebugSpew("Setting Size: %i", size); SelFont = (DWORD*)Fonts->Fonts[size]; // Save the text, change the font, then restore the text CXStr str(((CStmlWnd*)MQChatWnd->OutputBox)->GetSTMLText()); ((CXWnd*)MQChatWnd->OutputBox)->SetFont(SelFont); ((CStmlWnd*)MQChatWnd->OutputBox)->SetSTMLText(str,1,0); ((CStmlWnd*)MQChatWnd->OutputBox)->ForceParseNow(); // scroll to bottom of chat window DebugTry(((CXWnd*)MQChatWnd->OutputBox)->SetVScrollPos(MQChatWnd->OutputBox->VScrollMax)); MQChatWnd->FontSize=size; };
void Heartbeat() { if (gbUnload) return; static ULONGLONG LastGetTick = 0; static bool bFirstHeartBeat = true; static ULONGLONG TickDiff = 0; static fMQPulse pEQPlayNicePulse = NULL; static DWORD BeatCount = 0; ULONGLONG Tick = MQGetTickCount64(); BeatCount++; if (bFirstHeartBeat) { LastGetTick = Tick; bFirstHeartBeat = false; } // This accounts for rollover TickDiff += (Tick - LastGetTick); LastGetTick = Tick; #ifndef ISXEQ while (TickDiff >= 100) { TickDiff -= 100; if (gDelay>0) gDelay--; DropTimers(); } #endif if (!gStringTableFixed && pStringTable) // Please dont remove the second condition { FixStringTable(); gStringTableFixed = TRUE; } DebugTry(int GameState = GetGameState()); if (GameState != -1) { if ((DWORD)GameState != gGameState) { DebugSpew("GetGameState()=%d vs %d", GameState, gGameState); gGameState = GameState; DebugTry(Benchmark(bmPluginsSetGameState, PluginsSetGameState(GameState))); } } else return; DebugTry(UpdateMQ2SpawnSort()); #ifndef ISXEQ_LEGACY #ifndef ISXEQ DebugTry(DrawHUD()); //if (gGameState==GAMESTATE_INGAME && !bMouseLook && ScreenMode==3) //{ // DebugTry(pWndMgr->DrawCursor()); //} #endif #endif bRunNextCommand = TRUE; DebugTry(Pulse()); #ifndef ISXEQ_LEGACY #ifndef ISXEQ DebugTry(Benchmark(bmPluginsPulse, DebugTry(PulsePlugins()))); #endif if (pEQPlayNicePulse) { pEQPlayNicePulse(); } else { HMODULE hmEQPlayNice; if (((BeatCount % 63) == 0) && (hmEQPlayNice = GetModuleHandle("EQPlayNice.dll"))) { if (pEQPlayNicePulse = (fMQPulse)GetProcAddress(hmEQPlayNice, "Compat_ProcessFrame")) pEQPlayNicePulse(); } } #endif DebugTry(ProcessPendingGroundItems()); static bool ShownNews = false; if (gGameState == GAMESTATE_CHARSELECT && !ShownNews) { ShownNews = true; if (gCreateMQ2NewsWindow) CreateMQ2NewsWindow(); } #ifndef ISXEQ DWORD CurTurbo = 0; if (gDelayedCommands) {// delayed commands lockit lk(ghLockDelayCommand); DoCommand((PSPAWNINFO)pLocalPlayer, gDelayedCommands->szText); PCHATBUF pNext = gDelayedCommands->pNext; LocalFree(gDelayedCommands); gDelayedCommands = pNext; } while (bRunNextCommand) { if (!DoNextCommand()) break; if (!gTurbo) break;//bRunNextCommand = FALSE; if (++CurTurbo>gMaxTurbo) break;//bRunNextCommand = FALSE; } DoTimedCommands(); #endif }
PLUGIN_API VOID OnPulse() { if (gGameState==GAMESTATE_CHARSELECT && !MQChatWnd && !bNoCharSelect) { CreateChatWindow(); } //if (CXWnd *krwnd = FindMQ2Window("TaskOverlayWnd")) { // Sleep(0); //} if (MQChatWnd) { switch (gGameState) { case GAMESTATE_CHARSELECT: { if (MQChatWnd->ZLayer != 1) MQChatWnd->ZLayer = 1; break; } case GAMESTATE_INGAME: { if (MQChatWnd->ZLayer != 0) MQChatWnd->ZLayer = 0; break; } } if(PendingChatLines) { // set 'old' to current ulOldVScrollPos=MQChatWnd->OutputBox->VScrollPos; // scroll down if autoscroll enabled, or current position is the bottom of chatwnd bool bScrollDown=bAutoScroll?true:(MQChatWnd->OutputBox->VScrollPos==MQChatWnd->OutputBox->VScrollMax?true:false); DWORD ThisPulse=PendingChatLines; if (ThisPulse>LINES_PER_FRAME) { ThisPulse=LINES_PER_FRAME; } PendingChatLines-=ThisPulse; MQChatWnd->OutBoxLines+=ThisPulse; if (MQChatWnd->OutBoxLines>MAX_CHAT_SIZE) { DWORD Diff=(MQChatWnd->OutBoxLines-MAX_CHAT_SIZE)+LINES_PER_FRAME; MQChatWnd->OutBoxLines-=Diff; Benchmark(bmStripFirstStmlLines,MQChatWnd->OutputBox->StripFirstSTMLLines(Diff)); } for (DWORD N=0 ; N<ThisPulse ; N++) { if(pPendingChat) { DebugTry(MQChatWnd->OutputBox->AppendSTML(pPendingChat->Text)); ChatBuffer *pNext=pPendingChat->pNext; delete pPendingChat; pPendingChat=pNext; } //DebugSpew("NEW: max %u - pos: %u",MQChatWnd->OutputBox->VScrollMax,MQChatWnd->OutputBox->VScrollPos); } if (!pPendingChat) { pPendingChatTail=0; } if(bScrollDown) { // set current vscroll position to bottom DebugTry(((CXWnd*)MQChatWnd->OutputBox)->SetVScrollPos(MQChatWnd->OutputBox->VScrollMax)); } else { // autoscroll is disabled and current vscroll position was not at the bottom, retain position // note: if the window is full (VScrollMax value between 9793 and 9835), this will not adjust with // the flushing of buffer that keeps window a certain max size DebugTry(((CXWnd*)MQChatWnd->OutputBox)->SetVScrollPos(ulOldVScrollPos)); } } if(InHoverState()) { ((CXWnd*)MQChatWnd)->DoAllDrawing(); } } }
PLUGIN_API VOID OnReloadUI() { DebugSpewAlways("MQ2ChatWnd::OnReloadUI()"); // redraw window when you load/reload UI DebugTry(CreateChatWindow()); }