Restructure repository to include all source folders
Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
#include "stdafx.h"
|
||||
#include "ConsoleCMDFactory.h"
|
||||
#include <BaseLibrary/Utility/Math/Math.h>
|
||||
|
||||
CConsoleCMDFactory::StringCMD::StringCMD(const TCHAR* szCommand, CConsoleCommand* lpCMD)
|
||||
: m_szCommand(szCommand), m_lpCMD(lpCMD),
|
||||
m_dwHashValue(Math::HashFunc::sdbmHash(reinterpret_cast<const unsigned char*>(szCommand)))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
CConsoleCMDFactory::CConsoleCMDFactory()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
CConsoleCMDFactory::~CConsoleCMDFactory()
|
||||
{
|
||||
for(CMDVector::iterator itr = m_CMDVector.begin();
|
||||
itr != m_CMDVector.end(); ++itr)
|
||||
{
|
||||
delete itr->m_lpCMD;
|
||||
}
|
||||
|
||||
m_CMDVector.clear();
|
||||
}
|
||||
|
||||
|
||||
bool CConsoleCMDFactory::AddCommand(const TCHAR* szCommand, CConsoleCommand* lpConsoleCommand)
|
||||
{
|
||||
if(0 == szCommand, 0 == lpConsoleCommand)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_CMDVector.push_back(StringCMD(szCommand, lpConsoleCommand));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Desc : <20>ִ<EFBFBD> <20><><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD> Ŀ<>ǵ<EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||||
CConsoleCommand* CConsoleCMDFactory::Create(const TCHAR* szCommand, size_t nCommandLength)
|
||||
{
|
||||
// ù<><C3B9>° WhiteSpace<63><65> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ÿ<EFBFBD><C5B8><EFBFBD> <20><><EFBFBD>Ѵ<EFBFBD>.
|
||||
size_t nIndex = 0;
|
||||
for (; nIndex < nCommandLength; ++nIndex)
|
||||
{
|
||||
if (TEXT('\0') == szCommand[nIndex] || TEXT(' ') == szCommand[nIndex] ||
|
||||
TEXT('\t') == szCommand[nIndex] || TEXT('\n') == szCommand[nIndex])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const int MAX_BUFFER = 256;
|
||||
char szCommandOnly[MAX_BUFFER];
|
||||
|
||||
if(nIndex < MAX_BUFFER)
|
||||
{
|
||||
memcpy(szCommandOnly, szCommand, nIndex);
|
||||
szCommandOnly[nIndex] = 0;
|
||||
|
||||
for (CMDVector::iterator itr = m_CMDVector.begin();
|
||||
itr != m_CMDVector.end(); ++itr)
|
||||
{
|
||||
StringCMD& stringCMD = *itr;
|
||||
|
||||
if (0 == _tcscmp(stringCMD.m_szCommand, szCommandOnly))
|
||||
{
|
||||
return stringCMD.m_lpCMD->Clone(szCommand, nCommandLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
#ifndef _CONSOLE_COMMAND_FACTORY_H_
|
||||
#define _CONSOLE_COMMAND_FACTORY_H_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <Pattern/Command.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
class CConsoleCommand : public CCommand
|
||||
{
|
||||
protected:
|
||||
|
||||
virtual CConsoleCommand* Clone(const TCHAR* szCommand, size_t nCommandLength) = 0;
|
||||
friend class CConsoleCMDFactory;
|
||||
};
|
||||
|
||||
// Singleton Ŀ<>ǵ<EFBFBD> <20>ν<EFBFBD><CEBD>Ͻ<EFBFBD>. ( <20>ΰ<EFBFBD> Ŀ<>ǵ尡 <20><><EFBFBD><EFBFBD> <20><><EFBFBD>쿡 <20><><EFBFBD><EFBFBD>. )
|
||||
template<typename Derived>
|
||||
class CConsoleCMDSingleton : public CConsoleCommand
|
||||
{
|
||||
public:
|
||||
inline virtual CConsoleCommand* Clone(const TCHAR* szCommand, size_t nCommandLength);
|
||||
virtual bool Destroy() { return true; }
|
||||
};
|
||||
|
||||
template<typename Derived>
|
||||
inline CConsoleCommand* CConsoleCMDSingleton<Derived>::Clone(const TCHAR* szCommand, size_t nCommandLength)
|
||||
{
|
||||
static Derived Instance;
|
||||
return &Instance;
|
||||
}
|
||||
|
||||
// <20>ܼ<EFBFBD> Ŀ<>ǵ<EFBFBD> <20><><EFBFBD>丮.
|
||||
class CConsoleCMDFactory
|
||||
{
|
||||
public:
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_CMD_BUFFER = 512 // <20>ִ<EFBFBD> Ŀ<>ǵ<EFBFBD> <20><><EFBFBD><EFBFBD> ũ<><C5A9>.
|
||||
};
|
||||
|
||||
CConsoleCMDFactory();
|
||||
virtual ~CConsoleCMDFactory();
|
||||
|
||||
// Desc : Ŀ<>ǵ带 <20>߰<EFBFBD><DFB0>Ѵ<EFBFBD>. szCommand<6E><64> <20>ݵ<EFBFBD><DDB5><EFBFBD> <20><><EFBFBD>ڿ<EFBFBD> <20><><EFBFBD>ͷ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>̿<EFBFBD><CCBF>߸<EFBFBD> <20>Ѵ<EFBFBD>.
|
||||
bool AddCommand(const TCHAR* szCommand, CConsoleCommand* lpConsoleCommand);
|
||||
|
||||
// Desc : Ŀ<>ǵ尡 <20><><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD> <20>ʿ<EFBFBD><CABF>ϸ<EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>.
|
||||
CConsoleCommand* Create(const TCHAR* szCommand, size_t nCommandLength);
|
||||
|
||||
protected:
|
||||
|
||||
struct StringCMD
|
||||
{
|
||||
unsigned long m_dwHashValue;
|
||||
const TCHAR* m_szCommand;
|
||||
CConsoleCommand* m_lpCMD;
|
||||
|
||||
StringCMD(const TCHAR* szCommand, CConsoleCommand* lpCMD);
|
||||
};
|
||||
|
||||
typedef std::vector<StringCMD> CMDVector;
|
||||
CMDVector m_CMDVector;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,323 @@
|
||||
#include "stdafx.h"
|
||||
#include "ConsoleWindow.h"
|
||||
|
||||
#include <windowsx.h>
|
||||
#include <Pattern/Command.h>
|
||||
#include "ConsoleCMDFactory.h"
|
||||
|
||||
const TCHAR* WINCONSOLE_CLASSNAME = TEXT("RowConsoleWindow");
|
||||
const TCHAR* WINCONSOLE_FONTNAME = TEXT("Arial");
|
||||
|
||||
const int WINCONSOLE_FONTSIZE = 10; // font height<68><74>. ^^;;
|
||||
const unsigned int WINCONSOLE_WIDTH = 480;
|
||||
const unsigned int WINCONSOLE_HEIGHT = 640;
|
||||
|
||||
const unsigned int WINCONSOLE_INFO_HEIGHT = 450;
|
||||
const unsigned int WINCONSOLE_INPUT_HEIGHT = 24;
|
||||
const unsigned int WINCONSOLE_OUTPUT_HEIGHT = WINCONSOLE_HEIGHT - WINCONSOLE_INFO_HEIGHT - WINCONSOLE_INPUT_HEIGHT-30;
|
||||
const unsigned int WINCONSOLE_X = (GetSystemMetrics(SM_CXSCREEN) - WINCONSOLE_WIDTH - 20);
|
||||
const unsigned int WINCONSOLE_Y = (20);
|
||||
|
||||
const unsigned int MAX_OUTPUT_COUNT = 50;
|
||||
|
||||
const UINT CConsoleWindow::ms_PrintOutputMsg = RegisterWindowMessage(TEXT("ConsoleWindowCustomPrintOutput"));
|
||||
const UINT CConsoleWindow::ms_PrintInfoMsg = RegisterWindowMessage(TEXT("ConsoleWindowCustomPrintInfo"));
|
||||
const TCHAR* CConsoleWindow::ms_this = TEXT("RowConsoleWindow");
|
||||
|
||||
|
||||
CConsoleWindow::CConsoleWindow(HINSTANCE hInstance, HWND hParentWnd,
|
||||
CConsoleCMDFactory& CMDFactory, CCommandProcess& CMDProcess)
|
||||
: m_hParentWnd(hParentWnd), m_hWnd(0),
|
||||
m_hWndInfo(0), m_hWndInput(0), m_hWndOutput(0),
|
||||
m_hFont(0), m_fOldProc(0), m_hInstance(hInstance),
|
||||
m_CMDFactory(CMDFactory), m_CMDProcess(CMDProcess),
|
||||
m_MsgPool(MAX_MESSAGE_SIZE)
|
||||
{
|
||||
memset(m_szWindowName, 0, sizeof(char) * MAX_WINDOW_NAME);
|
||||
}
|
||||
|
||||
|
||||
CConsoleWindow::~CConsoleWindow()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
|
||||
bool CConsoleWindow::Initialize(const char* szWindowName)
|
||||
{
|
||||
ConsoleWindowLock::Syncronize sync(m_ConsoleWindowLock);
|
||||
|
||||
if(0 != m_hWnd)
|
||||
{
|
||||
// <20>̹<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ǿ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʴ´<CAB4>.
|
||||
return true;
|
||||
}
|
||||
|
||||
strncpy(m_szWindowName, szWindowName, MAX_WINDOW_NAME - 1);
|
||||
m_szWindowName[MAX_WINDOW_NAME - 1] = 0;
|
||||
|
||||
WNDCLASS wc;
|
||||
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
|
||||
wc.hCursor = LoadCursor(0, IDC_ARROW);
|
||||
wc.hIcon = LoadIcon(0, IDI_APPLICATION);
|
||||
wc.hInstance = m_hInstance;
|
||||
wc.lpfnWndProc = CConsoleWindow::ConsoleWindowProc;
|
||||
wc.lpszClassName = WINCONSOLE_CLASSNAME;
|
||||
wc.lpszMenuName = 0;
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
|
||||
if (!RegisterClass(&wc))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, WINCONSOLE_CLASSNAME, m_szWindowName, WS_VISIBLE,
|
||||
WINCONSOLE_X, WINCONSOLE_Y, WINCONSOLE_WIDTH, WINCONSOLE_HEIGHT, m_hParentWnd, 0, m_hInstance, 0);
|
||||
|
||||
if(0 == m_hWnd)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(FALSE == SetProp(m_hWnd, ms_this, reinterpret_cast<HANDLE>(this)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_hWndInfo = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "information ====================================",
|
||||
WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_READONLY | ES_MULTILINE,
|
||||
0, 0, WINCONSOLE_WIDTH - 10, WINCONSOLE_INFO_HEIGHT, m_hWnd, 0, m_hInstance, 0);
|
||||
|
||||
if(0 == m_hWndInfo)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_hWndOutput = CreateWindowEx(WS_EX_CLIENTEDGE, "LISTBOX", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | LBS_NOSEL,
|
||||
0, WINCONSOLE_INFO_HEIGHT, WINCONSOLE_WIDTH - 10, WINCONSOLE_OUTPUT_HEIGHT,
|
||||
m_hWnd, 0, m_hInstance, 0);
|
||||
|
||||
if(0 == m_hWndOutput)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_hWndInput = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE, 0,
|
||||
WINCONSOLE_INFO_HEIGHT + WINCONSOLE_OUTPUT_HEIGHT-10, WINCONSOLE_WIDTH - 10,
|
||||
WINCONSOLE_INPUT_HEIGHT, m_hWnd, 0, m_hInstance, 0);
|
||||
|
||||
if(0 == m_hWndInput)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_fOldProc = (LONG_PTR)SetWindowLongPtr(m_hWndInput, GWLP_WNDPROC,
|
||||
(LONG)((LONG_PTR)CConsoleWindow::InputWindowProc));
|
||||
|
||||
if(FALSE == SetProp(m_hWndInput, ms_this, reinterpret_cast<HANDLE>(this)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//subclass the edit control
|
||||
if ((m_hFont = CreateFont(-(WINCONSOLE_FONTSIZE), 0, // Height, Font-width
|
||||
0, 0, // Angle
|
||||
FW_NORMAL, // Weight
|
||||
FALSE, // Italic
|
||||
FALSE, // Underline
|
||||
FALSE, // ...
|
||||
DEFAULT_CHARSET,
|
||||
OUT_DEFAULT_PRECIS,
|
||||
CLIP_DEFAULT_PRECIS,
|
||||
DEFAULT_QUALITY, // DEFAULT_PITCH | FF_DONTCARE,
|
||||
FIXED_PITCH | FF_DONTCARE,
|
||||
WINCONSOLE_FONTNAME)) == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// <20><EFBFBD><F1B5BFB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><EFBFBD><DEBD><EFBFBD> ť<><C5A5> <20><><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD> <20><><EFBFBD>ؼ<EFBFBD> SendMessage <20><> PostMessage <20><> <20>ٲ<EFBFBD>. 2002.09.07
|
||||
PostMessage(m_hWndInfo, WM_SETFONT, (WPARAM)m_hFont, (LPARAM)MAKELPARAM(FALSE, 0));
|
||||
PostMessage(m_hWndOutput, WM_SETFONT, (WPARAM)m_hFont, (LPARAM)MAKELPARAM(FALSE, 0));
|
||||
PostMessage(m_hWndInput, WM_SETFONT, (WPARAM)m_hFont, (LPARAM)MAKELPARAM(FALSE, 0));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#define SAFE_DESTROY_WND(hWnd) if(0 != (hWnd)) { DestroyWindow((hWnd)); (hWnd) = 0; }
|
||||
|
||||
bool CConsoleWindow::Destroy()
|
||||
{
|
||||
ConsoleWindowLock::Syncronize sync(m_ConsoleWindowLock);
|
||||
|
||||
if (m_hFont)
|
||||
{
|
||||
DeleteObject((HGDIOBJ)m_hFont);
|
||||
m_hFont = 0;
|
||||
}
|
||||
|
||||
SAFE_DESTROY_WND(m_hWndInfo);
|
||||
SAFE_DESTROY_WND(m_hWndInput);
|
||||
SAFE_DESTROY_WND(m_hWndOutput);
|
||||
SAFE_DESTROY_WND(m_hWnd);
|
||||
|
||||
UnregisterClass(WINCONSOLE_CLASSNAME, m_hInstance);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CConsoleWindow::PrintOutput(const TCHAR* lpFormat, ...)
|
||||
{
|
||||
ConsoleWindowLock::Syncronize sync(m_ConsoleWindowLock);
|
||||
|
||||
if(0 != m_hWnd)
|
||||
{
|
||||
TCHAR* szText = reinterpret_cast<TCHAR*>(m_MsgPool.malloc());
|
||||
if(0 != szText)
|
||||
{
|
||||
va_list arguments;
|
||||
va_start(arguments, lpFormat);
|
||||
int nLength = _vsntprintf(szText, MAX_MESSAGE_SIZE - 1, lpFormat, arguments);
|
||||
va_end(arguments);
|
||||
|
||||
if(0 < nLength)
|
||||
{
|
||||
szText[nLength] = 0;
|
||||
PostMessage(m_hWnd, ms_PrintOutputMsg, (WPARAM)szText, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CConsoleWindow::PrintInfo(const TCHAR* lpFormat, ...)
|
||||
{
|
||||
ConsoleWindowLock::Syncronize sync(m_ConsoleWindowLock);
|
||||
|
||||
if(0 != m_hWnd)
|
||||
{
|
||||
TCHAR* szText = reinterpret_cast<TCHAR*>(m_MsgPool.malloc());
|
||||
if(0 != szText)
|
||||
{
|
||||
va_list arguments;
|
||||
va_start(arguments, lpFormat);
|
||||
int nLength = _vsntprintf(szText, MAX_MESSAGE_SIZE - 1, lpFormat, arguments);
|
||||
va_end(arguments);
|
||||
|
||||
if(0 < nLength)
|
||||
{
|
||||
szText[nLength] = 0;
|
||||
PostMessage(m_hWnd, ms_PrintInfoMsg, (WPARAM)szText, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LRESULT CALLBACK CConsoleWindow::ConsoleWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
CConsoleWindow* lpConsoleWindow =
|
||||
reinterpret_cast<CConsoleWindow*>(GetProp(hWnd, ms_this));
|
||||
|
||||
if(0 == lpConsoleWindow )
|
||||
{
|
||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
if(msg == ms_PrintOutputMsg && 0 != wParam)
|
||||
{
|
||||
TCHAR* szText = reinterpret_cast<TCHAR*>(wParam);
|
||||
|
||||
HWND hWndOutput = lpConsoleWindow->m_hWndOutput;
|
||||
|
||||
int nEndIndex = ListBox_GetCount(hWndOutput);
|
||||
if(nEndIndex > MAX_OUTPUT_COUNT)
|
||||
{
|
||||
ListBox_DeleteString(hWndOutput, 0);
|
||||
}
|
||||
|
||||
ListBox_AddString(hWndOutput, szText);
|
||||
ListBox_SetTopIndex(hWndOutput, nEndIndex - 1);
|
||||
|
||||
ConsoleWindowLock::Syncronize sync(lpConsoleWindow->m_ConsoleWindowLock);
|
||||
lpConsoleWindow->m_MsgPool.free(szText);
|
||||
}
|
||||
else if (msg == ms_PrintInfoMsg && 0 != wParam)
|
||||
{
|
||||
TCHAR* szText = reinterpret_cast<TCHAR*>(wParam);
|
||||
|
||||
HWND hWndInfo = lpConsoleWindow->m_hWndInfo;
|
||||
|
||||
SetWindowText(hWndInfo, szText);
|
||||
UpdateWindow(hWndInfo);
|
||||
|
||||
ConsoleWindowLock::Syncronize sync(lpConsoleWindow->m_ConsoleWindowLock);
|
||||
lpConsoleWindow->m_MsgPool.free(szText);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
case WM_CLOSE:
|
||||
SetWindowLongPtr(lpConsoleWindow->m_hWndInput, GWLP_WNDPROC, (LONG)lpConsoleWindow->m_fOldProc);
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
||||
case WM_CTLCOLORLISTBOX :
|
||||
SetBkColor((HDC) wParam, GetSysColor(COLOR_BTNFACE));
|
||||
return (LRESULT) GetSysColorBrush(COLOR_BTNFACE);
|
||||
|
||||
default:
|
||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
LRESULT CALLBACK CConsoleWindow::InputWindowProc(HWND hWnd, WORD msg, WORD wParam, LONG lParam)
|
||||
{
|
||||
CConsoleWindow* lpConsoleWindow =
|
||||
reinterpret_cast<CConsoleWindow*>(GetProp(hWnd, ms_this));
|
||||
|
||||
if(0 == lpConsoleWindow || 0 == lpConsoleWindow->m_fOldProc)
|
||||
{
|
||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||
}
|
||||
else if (WM_CHAR == msg)
|
||||
{
|
||||
if (VK_RETURN == wParam)
|
||||
{
|
||||
lpConsoleWindow->CreateCommand();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return (LONG)CallWindowProc((WNDPROC)lpConsoleWindow->m_fOldProc, hWnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
|
||||
void CConsoleWindow::CreateCommand()
|
||||
{
|
||||
TCHAR szCommand[CConsoleCMDFactory::MAX_CMD_BUFFER];
|
||||
|
||||
int nLength = GetWindowText(m_hWndInput, szCommand, CConsoleCMDFactory::MAX_CMD_BUFFER);
|
||||
if(0 < nLength)
|
||||
{
|
||||
CConsoleCommand* lpCommand = m_CMDFactory.Create(szCommand, nLength);
|
||||
if(0 != lpCommand)
|
||||
{
|
||||
PrintOutput(szCommand);
|
||||
m_CMDProcess.Add(lpCommand);
|
||||
}
|
||||
else
|
||||
{
|
||||
PrintOutput(TEXT("Can't recognize command. Please reinput."));
|
||||
}
|
||||
}
|
||||
|
||||
SetWindowText(m_hWndInput, "");
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
#ifndef _CONSOLE_WINDOW_H_
|
||||
#define _CONSOLE_WINDOW_H_
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <Thread/Lock.h>
|
||||
#include <boost/pool/pool.hpp>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
class CCommandProcess;
|
||||
class CConsoleCMDFactory;
|
||||
|
||||
class CConsoleWindow
|
||||
{
|
||||
public:
|
||||
|
||||
enum Const
|
||||
{
|
||||
MAX_MESSAGE_SIZE = 8192,
|
||||
MAX_WINDOW_NAME = 128
|
||||
};
|
||||
|
||||
CConsoleWindow(HINSTANCE hInstance, HWND hParentWnd,
|
||||
CConsoleCMDFactory& CMDFactory, CCommandProcess& CMDProcess);
|
||||
virtual ~CConsoleWindow();
|
||||
|
||||
bool Initialize(const char* szWindowName);
|
||||
bool Destroy();
|
||||
|
||||
CCommandProcess& GetCMDProcess() { return m_CMDProcess; }
|
||||
CConsoleCMDFactory& GetConsoleCMDFactory() { return m_CMDFactory; }
|
||||
|
||||
void PrintOutput(const TCHAR* lpFormat, ...);
|
||||
void PrintInfo(const TCHAR* lpFormat, ...);
|
||||
|
||||
private:
|
||||
|
||||
void CreateCommand();
|
||||
|
||||
// static members
|
||||
static LRESULT CALLBACK ConsoleWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
static LRESULT CALLBACK InputWindowProc(HWND hWnd, WORD msg, WORD wParam, LONG lParam);
|
||||
|
||||
static const UINT ms_PrintOutputMsg;
|
||||
static const UINT ms_PrintInfoMsg;
|
||||
static const TCHAR* ms_this;
|
||||
|
||||
typedef CCSLock ConsoleWindowLock;
|
||||
|
||||
ConsoleWindowLock m_ConsoleWindowLock;
|
||||
CACHE_PAD(Padding, sizeof(ConsoleWindowLock));
|
||||
|
||||
HWND m_hParentWnd;
|
||||
HWND m_hWnd;
|
||||
HWND m_hWndInfo;
|
||||
HWND m_hWndInput;
|
||||
HWND m_hWndOutput;
|
||||
|
||||
HFONT m_hFont;
|
||||
HINSTANCE m_hInstance;
|
||||
LONG_PTR m_fOldProc;
|
||||
|
||||
char m_szWindowName[MAX_WINDOW_NAME];
|
||||
|
||||
CCommandProcess& m_CMDProcess;
|
||||
CConsoleCMDFactory& m_CMDFactory;
|
||||
|
||||
boost::pool<> m_MsgPool;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,48 @@
|
||||
#include "stdafx.h"
|
||||
#include "MsgProc.h"
|
||||
|
||||
CMsgProcessMgr::CMsgProcessMgr()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CMsgProcessMgr::~CMsgProcessMgr()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
bool CMsgProcessMgr::Register(UINT uMsg, CMsgProc* lpMsgProcessProc)
|
||||
{
|
||||
return m_MessageProcessMap.insert(
|
||||
MessageProcessMap::value_type(uMsg, lpMsgProcessProc)).second;
|
||||
}
|
||||
|
||||
|
||||
bool CMsgProcessMgr::Remove(UINT uMsg)
|
||||
{
|
||||
return (0 != m_MessageProcessMap.erase(uMsg));
|
||||
}
|
||||
|
||||
|
||||
CMsgProc* CMsgProcessMgr::FindMsgProc(UINT uMsg)
|
||||
{
|
||||
MessageProcessMap::iterator find = m_MessageProcessMap.find(uMsg);
|
||||
MessageProcessMap::iterator end = m_MessageProcessMap.end();
|
||||
|
||||
return (find != end) ? find->second : 0;
|
||||
}
|
||||
|
||||
|
||||
void CMsgProcessMgr::Clear()
|
||||
{
|
||||
MessageProcessMap::iterator pos = m_MessageProcessMap.begin();
|
||||
MessageProcessMap::iterator end = m_MessageProcessMap.end();
|
||||
|
||||
for(; pos != end; ++pos)
|
||||
{
|
||||
delete pos->second;
|
||||
}
|
||||
|
||||
m_MessageProcessMap.clear();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef _GM_NETWORK_MSG_PROC_
|
||||
#define _GM_NETWORK_MSG_PROC_
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <map>
|
||||
|
||||
class CMsgProc
|
||||
{
|
||||
public:
|
||||
virtual ~CMsgProc() = 0;
|
||||
virtual LRESULT operator () (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) = 0;
|
||||
};
|
||||
|
||||
inline CMsgProc::~CMsgProc() { }
|
||||
|
||||
class CMsgProcessMgr
|
||||
{
|
||||
public:
|
||||
|
||||
CMsgProcessMgr();
|
||||
~CMsgProcessMgr();
|
||||
|
||||
bool Register(UINT uMsg, CMsgProc* lpMsgProcessProc);
|
||||
bool Remove(UINT uMsg);
|
||||
|
||||
CMsgProc* FindMsgProc(UINT uMsg);
|
||||
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
|
||||
typedef std::map<UINT, CMsgProc*> MessageProcessMap;
|
||||
|
||||
MessageProcessMap m_MessageProcessMap;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,213 @@
|
||||
#include "stdafx.h"
|
||||
#include "TimerProc.h"
|
||||
|
||||
const TCHAR* CTimerProcMgr::ms_this = TEXT("CTimerProcMgr");
|
||||
|
||||
const CTimerProcMgr::TIMER_ID CTimerProcMgr::INVALID_TIMER_ID = 0xFFFFFFFF;
|
||||
const CTimerProcMgr::PROC_ID CTimerProcMgr::INVALID_PROC_ID = 0xFFFFFFFF;
|
||||
|
||||
|
||||
CTimerProcMgr::CTimerProcMgr()
|
||||
: m_nProcIDCounter(1),
|
||||
m_nTimerIDCounter(1)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
CTimerProcMgr::~CTimerProcMgr()
|
||||
{
|
||||
ClearAll();
|
||||
}
|
||||
|
||||
|
||||
CTimerProcMgr::TIMER_ID CTimerProcMgr::CreateTimer(HWND hOwnerWnd, unsigned long dwInterval)
|
||||
{
|
||||
TIMER_ID nTimerID = GetTimerID(hOwnerWnd, dwInterval);
|
||||
|
||||
if(INVALID_TIMER_ID == nTimerID)
|
||||
{
|
||||
std::pair<TimerMap::iterator, bool> result_pair;
|
||||
result_pair.second = false;
|
||||
|
||||
do
|
||||
{
|
||||
nTimerID = m_nTimerIDCounter++;
|
||||
|
||||
result_pair = m_TimerMap.insert(
|
||||
TimerMap::value_type(nTimerID, InternalTimerData(hOwnerWnd, dwInterval)));
|
||||
|
||||
if(result_pair.second)
|
||||
{
|
||||
if(0 == SetTimer(hOwnerWnd, nTimerID, dwInterval, CTimerProcMgr::TimerProc))
|
||||
{
|
||||
nTimerID = INVALID_TIMER_ID;
|
||||
m_TimerMap.erase(result_pair.first);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetProp(hOwnerWnd, ms_this, this);
|
||||
}
|
||||
}
|
||||
|
||||
} while(!result_pair.second);
|
||||
}
|
||||
|
||||
return nTimerID;
|
||||
}
|
||||
|
||||
bool CTimerProcMgr::RemoveTimer(TIMER_ID nTimerID)
|
||||
{
|
||||
TimerMap::iterator find = m_TimerMap.find(nTimerID);
|
||||
TimerMap::iterator end = m_TimerMap.end();
|
||||
|
||||
if(find != end)
|
||||
{
|
||||
InternalTimerData& timerData = find->second;
|
||||
KillTimer(timerData.m_hOwnerWnd, find->first);
|
||||
|
||||
TimerProcessList::iterator process_pos = timerData.m_timerProcessList.begin();
|
||||
TimerProcessList::iterator process_end = timerData.m_timerProcessList.end();
|
||||
|
||||
for(;process_pos != process_end; ++process_pos)
|
||||
{
|
||||
delete process_pos->m_lpTimerProc;
|
||||
}
|
||||
|
||||
timerData.m_timerProcessList.clear();
|
||||
|
||||
m_TimerMap.erase(find);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
CTimerProcMgr::TIMER_ID CTimerProcMgr::GetTimerID(HWND hOwnerWnd, unsigned long dwInterval)
|
||||
{
|
||||
TimerMap::iterator pos = m_TimerMap.begin();
|
||||
TimerMap::iterator end = m_TimerMap.end();
|
||||
|
||||
for(; pos != end; ++pos)
|
||||
{
|
||||
InternalTimerData& timerData = pos->second;
|
||||
|
||||
if(timerData.m_hOwnerWnd == hOwnerWnd &&
|
||||
timerData.m_dwInterval == dwInterval)
|
||||
{
|
||||
return pos->first;
|
||||
}
|
||||
}
|
||||
|
||||
return INVALID_TIMER_ID;
|
||||
}
|
||||
|
||||
|
||||
CTimerProcMgr::PROC_ID CTimerProcMgr::AddProc(TIMER_ID nTimerID, CTimerProc* lpTimerProc)
|
||||
{
|
||||
TimerMap::iterator find = m_TimerMap.find(nTimerID);
|
||||
TimerMap::iterator end = m_TimerMap.end();
|
||||
|
||||
if(find != end)
|
||||
{
|
||||
InternalTimerData& timerData = find->second;
|
||||
|
||||
PROC_ID nProcID = m_nProcIDCounter++;
|
||||
timerData.m_timerProcessList.push_back(InternalProcessData(nProcID, lpTimerProc));
|
||||
|
||||
return nProcID;
|
||||
}
|
||||
|
||||
return INVALID_PROC_ID;
|
||||
}
|
||||
|
||||
|
||||
bool CTimerProcMgr::RemoveProc(PROC_ID nProcID)
|
||||
{
|
||||
TimerMap::iterator pos = m_TimerMap.begin();
|
||||
TimerMap::iterator end = m_TimerMap.end();
|
||||
|
||||
TimerProcessList::iterator process_pos;
|
||||
TimerProcessList::iterator process_end;
|
||||
|
||||
for(; pos != end; ++pos)
|
||||
{
|
||||
InternalTimerData& timerData = pos->second;
|
||||
|
||||
process_pos = timerData.m_timerProcessList.begin();
|
||||
process_end = timerData.m_timerProcessList.end();
|
||||
|
||||
for(; process_pos != process_end; ++process_pos)
|
||||
{
|
||||
InternalProcessData& processData = *process_pos;
|
||||
|
||||
if(processData.m_nProcessID == nProcID)
|
||||
{
|
||||
delete processData.m_lpTimerProc;
|
||||
timerData.m_timerProcessList.erase(process_pos);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void CTimerProcMgr::ClearAll()
|
||||
{
|
||||
TimerMap::iterator pos = m_TimerMap.begin();
|
||||
TimerMap::iterator end = m_TimerMap.end();
|
||||
|
||||
for(;pos != end; ++pos)
|
||||
{
|
||||
InternalTimerData& timerData = pos->second;
|
||||
KillTimer(timerData.m_hOwnerWnd, pos->first);
|
||||
|
||||
TimerProcessList::iterator process_pos = timerData.m_timerProcessList.begin();
|
||||
TimerProcessList::iterator process_end = timerData.m_timerProcessList.end();
|
||||
|
||||
for(;process_pos != process_end; ++process_pos)
|
||||
{
|
||||
delete process_pos->m_lpTimerProc;
|
||||
}
|
||||
|
||||
timerData.m_timerProcessList.clear();
|
||||
}
|
||||
|
||||
m_TimerMap.clear();
|
||||
}
|
||||
|
||||
|
||||
VOID CALLBACK CTimerProcMgr::TimerProc(HWND hWnd, UINT uMsg,
|
||||
UINT_PTR nTimerID, DWORD dwTime)
|
||||
{
|
||||
CTimerProcMgr* lpTimerProcMgr =
|
||||
reinterpret_cast<CTimerProcMgr*>(GetProp(hWnd, ms_this));
|
||||
|
||||
if(0 != lpTimerProcMgr && uMsg == WM_TIMER)
|
||||
{
|
||||
TimerMap::iterator find = lpTimerProcMgr->m_TimerMap.find(nTimerID);
|
||||
TimerMap::iterator end = lpTimerProcMgr->m_TimerMap.end();
|
||||
|
||||
if(find != end)
|
||||
{
|
||||
InternalTimerData& timerData = find->second;
|
||||
|
||||
TimerProcessList::iterator process_pos = timerData.m_timerProcessList.begin();
|
||||
TimerProcessList::iterator process_end = timerData.m_timerProcessList.end();
|
||||
|
||||
for(; process_pos != process_end; ++process_pos)
|
||||
{
|
||||
InternalProcessData& processData = *process_pos;
|
||||
|
||||
if(0 != processData.m_lpTimerProc)
|
||||
{
|
||||
(*processData.m_lpTimerProc)(hWnd, uMsg, nTimerID, dwTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
#ifndef _GM_NETWORK_TIMER_PROC_
|
||||
#define _GM_NETWORK_TIMER_PROC_
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
class CTimerProc
|
||||
{
|
||||
public:
|
||||
virtual ~CTimerProc() { }
|
||||
virtual VOID operator () (HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) = 0;
|
||||
};
|
||||
|
||||
|
||||
class CTimerProcMgr
|
||||
{
|
||||
public:
|
||||
|
||||
CTimerProcMgr();
|
||||
~CTimerProcMgr();
|
||||
|
||||
typedef unsigned int TIMER_ID;
|
||||
typedef unsigned int PROC_ID;
|
||||
|
||||
static const TIMER_ID INVALID_TIMER_ID;
|
||||
static const PROC_ID INVALID_PROC_ID;
|
||||
|
||||
TIMER_ID CreateTimer(HWND hOwnerWnd, unsigned long dwInterval);
|
||||
bool RemoveTimer(TIMER_ID nTimerID);
|
||||
|
||||
TIMER_ID GetTimerID(HWND hOwnerWnd, unsigned long dwInterval);
|
||||
|
||||
PROC_ID AddProc(TIMER_ID nTimerID, CTimerProc* lpTimerProc);
|
||||
bool RemoveProc(PROC_ID nProcID);
|
||||
|
||||
void ClearAll();
|
||||
|
||||
private:
|
||||
|
||||
static VOID CALLBACK TimerProc(HWND hWnd, UINT uMsg, UINT_PTR nTimerID, DWORD dwTime);
|
||||
|
||||
struct InternalProcessData
|
||||
{
|
||||
PROC_ID m_nProcessID;
|
||||
CTimerProc* m_lpTimerProc;
|
||||
|
||||
InternalProcessData(PROC_ID nProcessID, CTimerProc* lpTimerProc)
|
||||
: m_nProcessID(nProcessID), m_lpTimerProc(lpTimerProc)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::list<InternalProcessData> TimerProcessList;
|
||||
|
||||
struct InternalTimerData
|
||||
{
|
||||
HWND m_hOwnerWnd;
|
||||
unsigned long m_dwInterval;
|
||||
TimerProcessList m_timerProcessList;
|
||||
|
||||
InternalTimerData(HWND hOwnerWnd, unsigned long dwInterval)
|
||||
: m_hOwnerWnd(hOwnerWnd), m_dwInterval(dwInterval)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// Key : TimerID
|
||||
typedef std::map<TIMER_ID, InternalTimerData> TimerMap;
|
||||
|
||||
static const TCHAR* ms_this;
|
||||
|
||||
TimerMap m_TimerMap;
|
||||
PROC_ID m_nProcIDCounter;
|
||||
TIMER_ID m_nTimerIDCounter;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,637 @@
|
||||
#include "stdafx.h"
|
||||
#include "ServerWindowFramework.h"
|
||||
|
||||
#include <Thread/Lock.h>
|
||||
#include <Thread/ThreadMgr.h>
|
||||
#include <Pattern/Command.h>
|
||||
|
||||
#include <Log/ServerLog.h>
|
||||
#include <Network/IOCP/IOCPNet.h>
|
||||
#include <Utility/Time/Pulse/Pulse.h>
|
||||
#include <Stream/Buffer/Buffer.h>
|
||||
#include <Stream/Buffer/BufferFactory.h>
|
||||
|
||||
#include "./SysTray/SysTray.h"
|
||||
#include "./ConsoleWindow/ConsoleWindow.h"
|
||||
#include "./ConsoleWIndow/ConsoleCMDFactory.h"
|
||||
|
||||
#include "./MsgProc/MsgProc.h"
|
||||
#include "./MsgProc/TimerProc.h"
|
||||
|
||||
#include <Network/Dispatch/ServerRequest.h>
|
||||
|
||||
#include <Utility/Setup/ServerSetup.h>
|
||||
#include <Network/Packet/ManagePacketCmd.h>
|
||||
|
||||
#include <mmsystem.h>
|
||||
|
||||
namespace ServerWindowFrameworkConst
|
||||
{
|
||||
enum Const
|
||||
{
|
||||
INITIALIZE_SUCCESS = (1 << 0),
|
||||
DESTROY_CALLED = (1 << 1),
|
||||
DEFAULT_PROCESS_TICK = 100 // 0.1<EFBFBD>ʸ<EFBFBD><EFBFBD><EFBFBD> <20>ѹ<EFBFBD><D1B9><EFBFBD> ó<><C3B3>
|
||||
};
|
||||
};
|
||||
|
||||
const char* CServerWindowFramework::ms_this = TEXT("CServerWindowFramework");
|
||||
const UINT CServerWindowFramework::ms_SendDataMsg = RegisterWindowMessage("Send WM_COPYDATAMessage");
|
||||
|
||||
/*
|
||||
// Ʈ<><C6AE><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20>ش<EFBFBD>.
|
||||
class CCheckSysTray : public CTimerProc
|
||||
{
|
||||
public:
|
||||
|
||||
CCheckSysTray(CSysTray& sysTray) : m_sysTray(sysTray) { }
|
||||
virtual ~CCheckSysTray() { }
|
||||
virtual VOID operator () (HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { m_sysTray.Update(); }
|
||||
|
||||
private:
|
||||
|
||||
CSysTray& m_sysTray;
|
||||
};
|
||||
*/
|
||||
|
||||
class CSendDataToManageClient : public CMsgProc
|
||||
{
|
||||
public:
|
||||
|
||||
virtual LRESULT operator () (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
CBuffer* lpBuffer = reinterpret_cast<CBuffer*>(lParam);
|
||||
|
||||
if(0 != lpBuffer)
|
||||
{
|
||||
const char* szManageClientWindowName = CServerSetup::GetManageClientWindowName();
|
||||
|
||||
HWND hManageWnd = FindWindow(szManageClientWindowName, szManageClientWindowName);
|
||||
if(0 != hManageWnd)
|
||||
{
|
||||
COPYDATASTRUCT copyStruct;
|
||||
|
||||
copyStruct.dwData = 0;
|
||||
copyStruct.cbData = lpBuffer->length();
|
||||
copyStruct.lpData = lpBuffer->rd_ptr();
|
||||
|
||||
SendMessage(hManageWnd, WM_COPYDATA, 0, (LPARAM)©Struct);
|
||||
}
|
||||
|
||||
SAFE_RELEASE_BUFFER(lpBuffer);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
class CRecvCommandFromManageClient : public CMsgProc
|
||||
{
|
||||
public:
|
||||
|
||||
CRecvCommandFromManageClient(
|
||||
CServerWindowFramework& serverWindowFramework,
|
||||
CConsoleCMDFactory& commandFactory,
|
||||
CCommandProcess& commandProcess)
|
||||
: m_ServerWindowFramework(serverWindowFramework),
|
||||
m_CommandFactory(commandFactory),
|
||||
m_CommandProcess(commandProcess)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual LRESULT operator () (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if(0 != lParam)
|
||||
{
|
||||
COPYDATASTRUCT& copyDataStruct = *reinterpret_cast<PCOPYDATASTRUCT>(lParam);
|
||||
|
||||
ServerManage::ManageCommand* lpManageCmd =
|
||||
reinterpret_cast<ServerManage::ManageCommand*>(copyDataStruct.lpData);
|
||||
|
||||
if(ServerManage::CMD::ExecuteCommand == lpManageCmd->GetCmd())
|
||||
{
|
||||
char szCmdBuffer[CConsoleCMDFactory::MAX_CMD_BUFFER];
|
||||
|
||||
CCommand* lpCommand = 0;
|
||||
int nLength = _snprintf(szCmdBuffer, CConsoleCMDFactory::MAX_CMD_BUFFER - 1,
|
||||
"%s", reinterpret_cast<char*>(lpManageCmd + 1));
|
||||
|
||||
szCmdBuffer[CConsoleCMDFactory::MAX_CMD_BUFFER - 1] = 0;
|
||||
|
||||
if(0 < nLength)
|
||||
{
|
||||
lpCommand = m_CommandFactory.Create(szCmdBuffer, nLength);
|
||||
}
|
||||
|
||||
if(0 != lpCommand)
|
||||
{
|
||||
m_CommandProcess.Add(lpCommand);
|
||||
m_ServerWindowFramework.PrintOutput(szCmdBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
ERRLOG1(g_Log, "Command create failed from ManageTool. CMD:%s", szCmdBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
CServerWindowFramework& m_ServerWindowFramework;
|
||||
CConsoleCMDFactory& m_CommandFactory;
|
||||
CCommandProcess& m_CommandProcess;
|
||||
};
|
||||
|
||||
|
||||
CServerWindowFramework::CServerWindowFramework()
|
||||
: m_hWnd(0),
|
||||
m_hInstance(0),
|
||||
m_nMenuID(0),
|
||||
m_dwInternalFlags(0),
|
||||
m_dwServerStatus(0),
|
||||
m_lpSysTray(0),
|
||||
m_lpConsoleWindow(0),
|
||||
m_lpCommandProcess(new (std::nothrow) CCommandProcess),
|
||||
m_lpCommandFactory(new (std::nothrow) CConsoleCMDFactory),
|
||||
m_lpIOCPNet(new (std::nothrow) CIOCPNet),
|
||||
m_lpMsgProcessMgr(new (std::nothrow) CMsgProcessMgr),
|
||||
m_lpTimerProcessMgr(new (std::nothrow) CTimerProcMgr),
|
||||
m_lpBufferFactory(new (std::nothrow) CPoolBufferFactory)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
CServerWindowFramework::~CServerWindowFramework()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
|
||||
bool CServerWindowFramework::Initialize(HINSTANCE hInstance, const char* szWndApplicationName,
|
||||
const TCHAR* szCmdLine, int nICON_ID, int nMenu_ID)
|
||||
{
|
||||
const char* szErrorLogText = 0;
|
||||
|
||||
#define INIT_ERR_TEXT(DetailError) TEXT("this:0x%p/ServerWindowFramework initialize failed - "##DetailError)
|
||||
|
||||
TIMECAPS tc;
|
||||
memset(&tc, 0, sizeof(TIMECAPS));
|
||||
|
||||
if(0 == m_lpCommandProcess || 0 == m_lpCommandFactory || 0 == m_lpIOCPNet ||
|
||||
0 == m_lpMsgProcessMgr || 0 == m_lpTimerProcessMgr || 0 == m_lpBufferFactory)
|
||||
{
|
||||
// <20><>ü <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
szErrorLogText = INIT_ERR_TEXT("Create defaultobject failed");
|
||||
}
|
||||
else if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR)
|
||||
{
|
||||
// Ÿ<≯<EFBFBD> <20>ð<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
szErrorLogText = INIT_ERR_TEXT("Get timer resolution failed");
|
||||
}
|
||||
else if (TIMERR_NOERROR != timeBeginPeriod(min(max(tc.wPeriodMin, unsigned int(1)), tc.wPeriodMax)))
|
||||
{
|
||||
// Ÿ<≯<EFBFBD> <20>ð<EFBFBD> <20>ּҰ<D6BC><D2B0><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
szErrorLogText = INIT_ERR_TEXT("Set timer resolution failed");
|
||||
}
|
||||
else if(!InitializeFramework(hInstance, szWndApplicationName, nICON_ID, nMenu_ID))
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>ũ <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
szErrorLogText = INIT_ERR_TEXT("InitialzeFramework failed");
|
||||
}
|
||||
else if(!ApplicationSpecificInit(szCmdLine))
|
||||
{
|
||||
// <20><EFBFBD><DEBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
szErrorLogText = INIT_ERR_TEXT("ApplicationSpecificInit failed");
|
||||
}
|
||||
|
||||
if(0 != szErrorLogText)
|
||||
{
|
||||
ERRLOG1(g_Log, szErrorLogText, this);
|
||||
return false;
|
||||
}
|
||||
|
||||
#undef INIT_ERR_TEXT
|
||||
|
||||
// <20>ʱ<EFBFBD>ȭ <20><><EFBFBD><EFBFBD>
|
||||
SendManageClientPing();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CServerWindowFramework::isValid()
|
||||
{
|
||||
return (m_dwInternalFlags & ServerWindowFrameworkConst::INITIALIZE_SUCCESS) &&
|
||||
!(m_dwInternalFlags & ServerWindowFrameworkConst::DESTROY_CALLED);
|
||||
}
|
||||
|
||||
|
||||
bool CServerWindowFramework::InitializeFramework(HINSTANCE hInstance,
|
||||
const char* szWndApplicationName,
|
||||
int nICON_ID, int nMenu_ID)
|
||||
{
|
||||
if(!(m_dwInternalFlags & ServerWindowFrameworkConst::INITIALIZE_SUCCESS))
|
||||
{
|
||||
_sntprintf(m_szAppName, MAX_PATH - 1, _T("%s"), szWndApplicationName);
|
||||
m_szAppName[MAX_PATH - 1] = 0;
|
||||
|
||||
m_hInstance = hInstance;
|
||||
m_nMenuID = nMenu_ID;
|
||||
|
||||
WNDCLASS wndClass;
|
||||
|
||||
wndClass.hInstance = hInstance;
|
||||
wndClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(nICON_ID));
|
||||
wndClass.lpszClassName = m_szAppName;
|
||||
|
||||
wndClass.style = 0;
|
||||
wndClass.lpfnWndProc = (WNDPROC)CServerWindowFramework::ServerWindowFrameworkProc;
|
||||
wndClass.cbClsExtra = 0;
|
||||
wndClass.cbWndExtra = 0;
|
||||
wndClass.hCursor = 0;
|
||||
wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
||||
wndClass.lpszMenuName = 0;
|
||||
|
||||
if (!RegisterClass(&wndClass))
|
||||
{
|
||||
ERRLOG1(g_Log, "RegisterClass failed. ErrorCode:%d.", GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
m_hWnd = CreateWindow(wndClass.lpszClassName, m_szAppName, WS_OVERLAPPEDWINDOW | WS_MINIMIZE,
|
||||
0, 0, 0, 0, 0, 0, wndClass.hInstance, 0);
|
||||
|
||||
if (0 == m_hWnd)
|
||||
{
|
||||
ERRLOG1(g_Log, "CreateWindow failed. ErrorCode:%d", GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!SetProp(m_hWnd, ms_this, this))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_lpSysTray = new CSysTray(m_hWnd, wndClass.hInstance);
|
||||
m_lpConsoleWindow = new CConsoleWindow(wndClass.hInstance, m_hWnd,
|
||||
*m_lpCommandFactory, *m_lpCommandProcess);
|
||||
|
||||
if(0 == m_lpSysTray || 0 == m_lpConsoleWindow)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!m_lpSysTray->AddIcon(szWndApplicationName,
|
||||
LoadIcon(wndClass.hInstance, MAKEINTRESOURCE(nICON_ID)), nICON_ID))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!m_lpMsgProcessMgr->Register(ms_SendDataMsg, new CSendDataToManageClient))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if(!m_lpMsgProcessMgr->Register(WM_COPYDATA,
|
||||
new CRecvCommandFromManageClient(*this, *m_lpCommandFactory, *m_lpCommandProcess)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!m_lpIOCPNet->Initialize())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_dwInternalFlags |= ServerWindowFrameworkConst::INITIALIZE_SUCCESS;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CServerWindowFramework::Destroy()
|
||||
{
|
||||
if(!(m_dwInternalFlags & ServerWindowFrameworkConst::DESTROY_CALLED))
|
||||
{
|
||||
m_dwInternalFlags |= ServerWindowFrameworkConst::DESTROY_CALLED;
|
||||
|
||||
delete m_lpIOCPNet;
|
||||
m_lpIOCPNet = 0;
|
||||
|
||||
delete m_lpMsgProcessMgr;
|
||||
m_lpMsgProcessMgr = 0;
|
||||
|
||||
delete m_lpTimerProcessMgr;
|
||||
m_lpTimerProcessMgr = 0;
|
||||
|
||||
delete m_lpSysTray;
|
||||
m_lpSysTray = 0;
|
||||
|
||||
if(0 != m_hWnd)
|
||||
{
|
||||
DestroyWindow(m_hWnd);
|
||||
m_hWnd = 0;
|
||||
}
|
||||
|
||||
delete m_lpConsoleWindow;
|
||||
m_lpConsoleWindow = 0;
|
||||
|
||||
delete m_lpCommandProcess;
|
||||
m_lpCommandProcess = 0;
|
||||
|
||||
delete m_lpCommandFactory;
|
||||
m_lpCommandFactory = 0;
|
||||
|
||||
delete m_lpBufferFactory;
|
||||
m_lpBufferFactory = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CServerWindowFramework::ProcessMessage()
|
||||
{
|
||||
MSG message;
|
||||
|
||||
while(GetMessage(&message, 0, 0, 0))
|
||||
{
|
||||
if(!IsDialogMessage(m_hWnd, &message))
|
||||
{
|
||||
TranslateMessage(&message);
|
||||
DispatchMessage(&message);
|
||||
}
|
||||
}
|
||||
|
||||
SERLOG1(g_Log, "this:0x%p/finish server", this);
|
||||
SERLOG1(g_SessionLog, "this:0x%p/finish server", this);
|
||||
|
||||
CServerRequest::GetInstance().RequestOff();
|
||||
CServerRequest::GetInstance().RemoveAllRequest();
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD>带 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
ProcessThreadList::iterator pos = m_ProcessThreadList.begin();
|
||||
ProcessThreadList::iterator end = m_ProcessThreadList.end();
|
||||
|
||||
for(;pos != end; ++pos)
|
||||
{
|
||||
// TODO : 2<>ʰ<EFBFBD> <20><><EFBFBD><EFBFBD>.. <20><><EFBFBD>⼭ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>.
|
||||
|
||||
CThread* lpProcessThread = *pos;
|
||||
CThreadMgr::Stop(lpProcessThread, 2000);
|
||||
};
|
||||
|
||||
SERLOG1(g_Log, "this:0x%p/finish process threads", this);
|
||||
|
||||
pos = m_ProcessThreadList.begin();
|
||||
end = m_ProcessThreadList.end();
|
||||
for(;pos != end; ++pos)
|
||||
{
|
||||
delete *pos;
|
||||
}
|
||||
|
||||
m_ProcessThreadList.clear();
|
||||
|
||||
Destroy();
|
||||
}
|
||||
|
||||
LRESULT CALLBACK CServerWindowFramework::ServerWindowFrameworkProc(HWND hWnd, UINT uMsg,
|
||||
WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
CServerWindowFramework* lpServerWindowFramework = GetThisPtr(hWnd);
|
||||
|
||||
// Preprocess Messages
|
||||
if(WM_DESTROY == uMsg)
|
||||
{
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
else if(0 != lpServerWindowFramework)
|
||||
{
|
||||
CMsgProc* lpMsgProc = 0;
|
||||
|
||||
if(0 != lpServerWindowFramework->m_lpMsgProcessMgr)
|
||||
{
|
||||
lpMsgProc = lpServerWindowFramework->m_lpMsgProcessMgr->FindMsgProc(uMsg);
|
||||
}
|
||||
|
||||
if(0 != lpMsgProc)
|
||||
{
|
||||
return (*lpMsgProc)(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
else if(uMsg == CSysTray::GetSysTrayNotifyMsg())
|
||||
{
|
||||
switch(lParam)
|
||||
{
|
||||
case WM_RBUTTONUP:
|
||||
{
|
||||
CSysTray* lpSysTray = lpServerWindowFramework->m_lpSysTray;
|
||||
if(0 != lpSysTray)
|
||||
{
|
||||
HMENU hMenu = LoadMenu(lpServerWindowFramework->m_hInstance,
|
||||
MAKEINTRESOURCE(lpServerWindowFramework->m_nMenuID));
|
||||
|
||||
if(0 != hMenu)
|
||||
{
|
||||
HMENU hSubMenu = GetSubMenu(hMenu, 0);
|
||||
|
||||
if(0 != hSubMenu)
|
||||
{
|
||||
lpSysTray->ShowPopupMenu(hWnd, hSubMenu);
|
||||
DestroyMenu(hSubMenu);
|
||||
}
|
||||
|
||||
DestroyMenu(hMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
|
||||
void CServerWindowFramework::PrintOutput(const char* lpFormat, ... )
|
||||
{
|
||||
if(0 != m_lpConsoleWindow)
|
||||
{
|
||||
char szText[CConsoleWindow::MAX_MESSAGE_SIZE];
|
||||
|
||||
va_list arguments;
|
||||
va_start(arguments, lpFormat);
|
||||
|
||||
int nLength = _vsntprintf(szText,
|
||||
CConsoleWindow::MAX_MESSAGE_SIZE - 1, lpFormat, arguments);
|
||||
|
||||
va_end(arguments);
|
||||
|
||||
if(0 < nLength)
|
||||
{
|
||||
szText[nLength] = 0;
|
||||
m_lpConsoleWindow->PrintOutput(szText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CServerWindowFramework::PrintInfo(const char* lpFormat, ... )
|
||||
{
|
||||
if(0 != m_lpConsoleWindow)
|
||||
{
|
||||
char szText[CConsoleWindow::MAX_MESSAGE_SIZE];
|
||||
|
||||
va_list arguments;
|
||||
va_start(arguments, lpFormat);
|
||||
|
||||
int nLength = _vsntprintf(szText,
|
||||
CConsoleWindow::MAX_MESSAGE_SIZE - 1, lpFormat, arguments);
|
||||
|
||||
va_end(arguments);
|
||||
|
||||
if(0 < nLength)
|
||||
{
|
||||
szText[nLength] = 0;
|
||||
m_lpConsoleWindow->PrintInfo(szText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool CServerWindowFramework::AddProcessThread(CThread* lpProcessThread)
|
||||
{
|
||||
const char* szErrorString = 0;
|
||||
|
||||
if(0 == lpProcessThread)
|
||||
{
|
||||
szErrorString = TEXT("this:0x%p/Process thread pointer is 0");
|
||||
}
|
||||
else if(INVALID_HANDLE_VALUE == CThreadMgr::Run(lpProcessThread))
|
||||
{
|
||||
szErrorString = TEXT("this:0x%p/Process thread start failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ProcessThreadList.push_back(lpProcessThread);
|
||||
return true;
|
||||
}
|
||||
|
||||
ERRLOG1(g_Log, szErrorString, lpProcessThread);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool CServerWindowFramework::SendManageClientPacket(const void* lpData, unsigned short usLength)
|
||||
{
|
||||
if(0 != m_lpBufferFactory)
|
||||
{
|
||||
CBuffer* lpBuffer = CREATE_BUFFER(*m_lpBufferFactory, usLength);
|
||||
|
||||
if(0 != lpBuffer)
|
||||
{
|
||||
memcpy(lpBuffer->wr_ptr(), lpData, usLength);
|
||||
lpBuffer->wr_ptr(usLength);
|
||||
|
||||
if(0 != PostMessage(m_hWnd, ms_SendDataMsg, 0,
|
||||
reinterpret_cast<LPARAM>(lpBuffer)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
SAFE_RELEASE_BUFFER(lpBuffer);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void CServerWindowFramework::SendManageClientPing()
|
||||
{
|
||||
ServerManage::PktManagePing managePing;
|
||||
|
||||
GetModuleFileName(0, managePing.m_szAppFullPathName, MAX_PATH - 1);
|
||||
managePing.m_szAppFullPathName[MAX_PATH - 1] = 0;
|
||||
|
||||
_snprintf(managePing.m_szWindowName, MAX_PATH - 1, "%s", m_szAppName);
|
||||
managePing.m_szWindowName[MAX_PATH - 1] = 0;
|
||||
|
||||
_snprintf(managePing.m_szCommandLine, MAX_PATH * 2 - 1, "%s", GetCommandLine());
|
||||
managePing.m_szCommandLine[MAX_PATH * 2 - 1] = 0;
|
||||
|
||||
managePing.m_dwStatusFlag = m_dwServerStatus;
|
||||
managePing.InitPtHead(sizeof(ServerManage::PktManagePing), ServerManage::CMD::IPC_ManagePing, 0, 0);
|
||||
|
||||
SendManageClientPacket(&managePing, managePing.GetLen());
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// ó<><C3B3> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//
|
||||
|
||||
CProcessThread::CProcessThread(CServerWindowFramework& ServerWindowFramework)
|
||||
: m_bExit(FALSE), m_nProcessTick(ServerWindowFrameworkConst::DEFAULT_PROCESS_TICK),
|
||||
m_ServerWindowFramework(ServerWindowFramework)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CProcessThread::CProcessThread(CServerWindowFramework& ServerWindowFramework, long nProcessTick)
|
||||
: m_bExit(FALSE), m_nProcessTick(nProcessTick),
|
||||
m_ServerWindowFramework(ServerWindowFramework)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
CProcessThread::~CProcessThread()
|
||||
{
|
||||
CThreadMgr::Stop(this, INFINITE);
|
||||
}
|
||||
|
||||
unsigned int CProcessThread::Run()
|
||||
{
|
||||
if(!m_ServerWindowFramework.isValid())
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD> <20>α<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
return -1;
|
||||
}
|
||||
|
||||
CCommandProcess& CommandProcess = *m_ServerWindowFramework.GetCommandProcess();
|
||||
CIOCPNet& IOCPNetwork = *m_ServerWindowFramework.GetIOCPNet();
|
||||
CServerRequest& ServerRequest = CServerRequest::GetInstance();
|
||||
|
||||
CPulse& Pulse = CPulse::GetInstance();
|
||||
Pulse.SetTicksPerPulse(m_nProcessTick);
|
||||
|
||||
while(!IsEndLoop())
|
||||
{
|
||||
unsigned long dwCurrentPulse = Pulse.CheckSleep();
|
||||
|
||||
CommandProcess.ProcessAll(); // Ŀ<>ǵ<EFBFBD> ť ó<><C3B3>
|
||||
IOCPNetwork.Process(); // IOCP Networkó<6B><C3B3>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> ó<><C3B3>.
|
||||
InternalRun(Pulse);
|
||||
|
||||
if(Pulse.ProcessBySecond(1))
|
||||
{
|
||||
// ServerRequest ó<><C3B3>. 1<>ʸ<EFBFBD><CAB8><EFBFBD> timeout request<73><74> ó<><C3B3><EFBFBD>Ѵ<EFBFBD>.
|
||||
ServerRequest.RemoveTimeoutRequest();
|
||||
}
|
||||
|
||||
if(Pulse.ProcessBySecond(5))
|
||||
{
|
||||
// ManageClient<6E><74> 5<>ʸ<EFBFBD><CAB8><EFBFBD> Ping<6E><67><EFBFBD><EFBFBD> <20><>, Application Name<6D><65> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
|
||||
m_ServerWindowFramework.SendManageClientPing();
|
||||
}
|
||||
}
|
||||
|
||||
// Ŭ<><C5AC><EFBFBD><EFBFBD> <20>ڵ带 <20>ִ´<D6B4>.
|
||||
Cleanup(Pulse);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
#ifndef _CSERVER_WINDOW_FRAMEWORK_
|
||||
#define _CSERVER_WINDOW_FRAMEWORK_
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <climits>
|
||||
#include <Thread/Lock.h>
|
||||
#include <Thread/Thread.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
class CSysTray;
|
||||
class CConsoleWindow;
|
||||
|
||||
class CCommand;
|
||||
class CCommandProcess;
|
||||
|
||||
class CConsoleCMDFactory;
|
||||
class CIOCPNet;
|
||||
|
||||
class CMsgProcessMgr;
|
||||
class CTimerProcMgr;
|
||||
|
||||
class CPulse;
|
||||
class CBufferFactory;
|
||||
class CServerWindowFramework;
|
||||
|
||||
|
||||
// <20><><EFBFBD>μ<EFBFBD><CEBC><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
class CProcessThread : public CThread
|
||||
{
|
||||
public:
|
||||
|
||||
CProcessThread(CServerWindowFramework& ServerWindowFramework);
|
||||
CProcessThread(CServerWindowFramework& ServerWindowFramework, long nProcessTick);
|
||||
virtual ~CProcessThread();
|
||||
|
||||
protected:
|
||||
|
||||
virtual void InternalRun(CPulse& Pulse) = 0;
|
||||
virtual void Cleanup(CPulse& Pulse) = 0;
|
||||
|
||||
private:
|
||||
|
||||
virtual unsigned int Run(); // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>Ǵ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ִ´<D6B4>.
|
||||
virtual BOOL End() { InterlockedExchange(&m_bExit, TRUE); return TRUE; }
|
||||
BOOL IsEndLoop() { return InterlockedCompareExchange(&m_bExit, TRUE, TRUE); }
|
||||
|
||||
volatile LONG m_bExit;
|
||||
long m_nProcessTick;
|
||||
CServerWindowFramework& m_ServerWindowFramework;
|
||||
};
|
||||
|
||||
class CServerWindowFramework
|
||||
{
|
||||
public:
|
||||
|
||||
bool Initialize(HINSTANCE hInstance, const TCHAR* szWndApplicationName,
|
||||
const char* szCmdLine, int nICON_ID, int nMenu_ID);
|
||||
|
||||
HWND GetWnd() { return m_hWnd; }
|
||||
void ProcessMessage();
|
||||
|
||||
bool isValid();
|
||||
|
||||
void PrintOutput(const char* lpFormat, ...);
|
||||
void PrintInfo(const char* lpFormat, ...);
|
||||
|
||||
bool SendManageClientPacket(const void* lpData, unsigned short usLength);
|
||||
void SendManageClientPing();
|
||||
|
||||
void SetStatusFlag(unsigned long dwServerStatus) { m_dwServerStatus = dwServerStatus; }
|
||||
unsigned long GetStatusFlag() { return m_dwServerStatus; }
|
||||
|
||||
CMsgProcessMgr* GetMsgProcessMgr() { return m_lpMsgProcessMgr; }
|
||||
CTimerProcMgr* GetTimerProcMgr() { return m_lpTimerProcessMgr; }
|
||||
CIOCPNet* GetIOCPNet() { return m_lpIOCPNet; }
|
||||
CConsoleWindow* GetConsoleWindow() { return m_lpConsoleWindow; }
|
||||
CCommandProcess* GetCommandProcess() { return m_lpCommandProcess; }
|
||||
CConsoleCMDFactory* GetCommandFactory() { return m_lpCommandFactory; } // <20><><EFBFBD>ο<EFBFBD><CEBF><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
|
||||
private:
|
||||
|
||||
bool InitWindow(WNDCLASS& wndClass, const char* szWndApplicationName);
|
||||
void Destroy();
|
||||
|
||||
protected:
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ƽ<DEBE> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD> <20><>.
|
||||
CServerWindowFramework();
|
||||
virtual ~CServerWindowFramework();
|
||||
|
||||
// <20>ݵ<EFBFBD><DDB5><EFBFBD> <20>ʱ<EFBFBD>ȭ<EFBFBD><C8AD> <20><> <20>־<EFBFBD><D6BE><EFBFBD> <20><>.
|
||||
bool InitializeFramework(HINSTANCE hInstance, const TCHAR* szWndApplicationName, int nICON_ID, int nMenu_ID);
|
||||
|
||||
// <20><EFBFBD><DEBD><EFBFBD> <20><><EFBFBD>μ<EFBFBD><CEBC><EFBFBD> <20>߰<EFBFBD>, Ŀ<>ǵ<EFBFBD> <20>߰<EFBFBD>, Listener<65>߰<EFBFBD> <20><><EFBFBD><EFBFBD> ó<><C3B3><EFBFBD><EFBFBD> <20>Ѵ<EFBFBD>.
|
||||
virtual bool ApplicationSpecificInit(const TCHAR* szCmdLine) = 0;
|
||||
|
||||
// ó<><C3B3> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>߰<EFBFBD>.
|
||||
bool AddProcessThread(CThread* lpProcessThread);
|
||||
|
||||
static CServerWindowFramework* GetThisPtr(HWND hWnd) { return reinterpret_cast<CServerWindowFramework*>(GetProp(hWnd, ms_this)); }
|
||||
static LRESULT CALLBACK ServerWindowFrameworkProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
static VOID CALLBACK FrameworkTimerProc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
|
||||
|
||||
private:
|
||||
|
||||
typedef std::list<CThread*> ProcessThreadList;
|
||||
|
||||
HINSTANCE m_hInstance;
|
||||
HWND m_hWnd;
|
||||
int m_nMenuID;
|
||||
unsigned long m_dwInternalFlags;
|
||||
unsigned long m_dwServerStatus;
|
||||
|
||||
CSysTray* m_lpSysTray; // <20><><EFBFBD>ο<EFBFBD><CEBF><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
CConsoleWindow* m_lpConsoleWindow; // <20><><EFBFBD>ο<EFBFBD><CEBF><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
CCommandProcess* m_lpCommandProcess; // <20><><EFBFBD>ο<EFBFBD><CEBF><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
CConsoleCMDFactory* m_lpCommandFactory; // <20><><EFBFBD>ο<EFBFBD><CEBF><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
|
||||
CIOCPNet* m_lpIOCPNet; // <20><><EFBFBD>ο<EFBFBD><CEBF><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
|
||||
CMsgProcessMgr* m_lpMsgProcessMgr; // <20><EFBFBD><DEBD><EFBFBD> <20><><EFBFBD>μ<EFBFBD><CEBC><EFBFBD> <20>Ŵ<EFBFBD><C5B4><EFBFBD>
|
||||
CTimerProcMgr* m_lpTimerProcessMgr; // Ÿ<≯<EFBFBD> <20><><EFBFBD>μ<EFBFBD><CEBC><EFBFBD> <20>Ŵ<EFBFBD><C5B4><EFBFBD>
|
||||
|
||||
CBufferFactory* m_lpBufferFactory; // <20><><EFBFBD><EFBFBD> Factory
|
||||
|
||||
ProcessThreadList m_ProcessThreadList;
|
||||
|
||||
char m_szAppName[MAX_PATH];
|
||||
|
||||
static const char* ms_this;
|
||||
static const UINT ms_SendDataMsg;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,104 @@
|
||||
#include "stdafx.h"
|
||||
#include "SysTray.h"
|
||||
|
||||
#include <shellapi.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
// constructor and destructor
|
||||
CSysTray::CSysTray(HWND hWnd, HINSTANCE hInstance)
|
||||
: m_hWnd(hWnd), m_hInstance(hInstance), m_uIconCount(0)
|
||||
{
|
||||
memset(&m_IconData, 0, sizeof(NOTIFYICONDATA));
|
||||
}
|
||||
|
||||
CSysTray::~CSysTray()
|
||||
{
|
||||
RemoveIcon();
|
||||
}
|
||||
|
||||
|
||||
// add item
|
||||
BOOL CSysTray::AddIcon(const char *lpToolTip, HICON hIcon, UINT uID)
|
||||
{
|
||||
BOOL res;
|
||||
|
||||
if(0 != m_IconData.cbSize)
|
||||
{
|
||||
RemoveIcon();
|
||||
}
|
||||
|
||||
m_IconData.cbSize = sizeof(NOTIFYICONDATA);
|
||||
m_IconData.hWnd = m_hWnd;
|
||||
m_IconData.uID = uID;
|
||||
m_IconData.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
|
||||
m_IconData.hIcon = hIcon;
|
||||
m_IconData.uCallbackMessage = GetSysTrayNotifyMsg();
|
||||
|
||||
if (lpToolTip)
|
||||
{
|
||||
_snprintf(m_IconData.szTip, 64, "%s", lpToolTip);
|
||||
}
|
||||
else
|
||||
{
|
||||
_snprintf(m_IconData.szTip, 64, "Temp Application");
|
||||
}
|
||||
|
||||
res = Shell_NotifyIcon(NIM_ADD, &m_IconData);
|
||||
|
||||
if(res)
|
||||
{
|
||||
m_uIconCount++;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
// remove item
|
||||
BOOL CSysTray::RemoveIcon(void)
|
||||
{
|
||||
BOOL res = Shell_NotifyIcon(NIM_DELETE, &m_IconData);
|
||||
|
||||
//decrement the counter
|
||||
if (res)
|
||||
{
|
||||
if(m_IconData.hIcon)
|
||||
{
|
||||
DestroyIcon(m_IconData.hIcon);
|
||||
}
|
||||
|
||||
--m_uIconCount;
|
||||
|
||||
memset(&m_IconData, 0, sizeof(NOTIFYICONDATA));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
BOOL CSysTray::Update()
|
||||
{
|
||||
if(0 != m_IconData.cbSize)
|
||||
{
|
||||
return Shell_NotifyIcon(NIM_MODIFY, &m_IconData);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// show popup menu
|
||||
void CSysTray::ShowPopupMenu(HWND hWnd, HMENU hMenu)
|
||||
{
|
||||
POINT mouse;
|
||||
GetCursorPos(&mouse);
|
||||
|
||||
SetForegroundWindow(hWnd);
|
||||
TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, mouse.x, mouse.y, 0, hWnd, NULL);
|
||||
SetForegroundWindow(hWnd);
|
||||
}
|
||||
|
||||
const UINT CSysTray::GetSysTrayNotifyMsg()
|
||||
{
|
||||
static const UINT s_MsgID = RegisterWindowMessage(TEXT("CSysTrayNotifyMessage"));
|
||||
return s_MsgID;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef _MY_SYSTRAY_H_
|
||||
#define _MY_SYSTRAY_H_
|
||||
|
||||
// 2002<30><32> 9<><39> 3<><33>
|
||||
// <20><><EFBFBD><EFBFBD>ȣ
|
||||
#pragma once
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
|
||||
|
||||
class CSysTray
|
||||
{
|
||||
private:
|
||||
|
||||
NOTIFYICONDATA m_IconData;
|
||||
|
||||
HWND m_hWnd;
|
||||
HINSTANCE m_hInstance;
|
||||
UINT m_uIconCount;
|
||||
|
||||
public:
|
||||
|
||||
// constructor and destructor
|
||||
CSysTray(HWND hWnd, HINSTANCE hInstance);
|
||||
~CSysTray();
|
||||
|
||||
BOOL AddIcon(const char *lpToolTip, HICON hIcon, UINT uID);
|
||||
BOOL RemoveIcon();
|
||||
BOOL Update();
|
||||
|
||||
void ShowPopupMenu(HWND hWnd, HMENU hMenu);
|
||||
|
||||
static const UINT GetSysTrayNotifyMsg();
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user