LosaDev source snapshot 2019
This commit is contained in:
commit
c198676e97
20588 files changed
+8812878
No files matched your search
@@ -0,0 +1,709 @@
|
||||
#include "StdAfx.h"
|
||||
#include "cFile.h"
|
||||
#include "MD5.h"
|
||||
#include "cDemonLauncher.h"
|
||||
#include "SessionProc.h"
|
||||
#include "GameCommand.h"
|
||||
#include "Utility.h"
|
||||
#include "../include/IIocpContext.h"
|
||||
#include <io.h>
|
||||
#include <shlwapi.h>
|
||||
|
||||
|
||||
|
||||
extern void Tokenize(const std::tstring& str, TOKENS& tokens, const std::tstring& delimiters);
|
||||
extern BOOL GetServices(STRINGS& services, STRINGS& files, STRINGS& scripts);
|
||||
extern BOOL IsService(const TCHAR* serviceName);
|
||||
extern BOOL CreateFolder(const TCHAR* path);
|
||||
extern BOOL CreateConsole(const TCHAR* title, TCHAR* command, TCHAR* arguments);
|
||||
|
||||
|
||||
void CPing::Run(IIocpContext* context)
|
||||
{
|
||||
scPing packet;
|
||||
packet.code = rand();
|
||||
|
||||
SessionProc::SendPacket(
|
||||
context,
|
||||
S_PING,
|
||||
reinterpret_cast<uint8*>(&packet),
|
||||
sizeof(packet));
|
||||
}
|
||||
|
||||
void CServices::Run(IIocpContext* context)
|
||||
{
|
||||
if(!Ready(context))
|
||||
return;
|
||||
|
||||
Begin(context);
|
||||
}
|
||||
|
||||
BOOL CServices::Ready(IIocpContext* context)
|
||||
{
|
||||
m_session = SessionProc::GetSession(context->GetEntity());
|
||||
if(!m_session) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CServices::Begin(IIocpContext* context)
|
||||
{
|
||||
if(GetServices(m_services, m_files, m_scripts))
|
||||
{
|
||||
Debug(_T("Service count :: %lu\n"), m_services.size());
|
||||
|
||||
scServices packet;
|
||||
packet.count = m_services.size();
|
||||
|
||||
cSerialize::Reset();
|
||||
cSerialize::Write(reinterpret_cast<uint8*>(&packet), sizeof(packet));
|
||||
|
||||
Service temp;
|
||||
std::tstring service, file, script;
|
||||
for(uint32 n = 0 ; n < packet.count ; n++)
|
||||
{
|
||||
service = m_services[n];
|
||||
file = m_files[n];
|
||||
script = m_scripts[n];
|
||||
|
||||
ZeroMemory(&temp, sizeof(temp));
|
||||
|
||||
BOOL result = GetRunning(service.c_str(), temp.running, temp.console);
|
||||
if(result)
|
||||
{
|
||||
Debug(_T("Running :: %s\n"), service.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug(_T("Not Running :: %s\n"), service.c_str());
|
||||
}
|
||||
CopyMemory(temp.service, service.c_str(), sizeof(temp.service));
|
||||
cSerialize::Write(reinterpret_cast<uint8*>(&temp), sizeof(temp));
|
||||
}
|
||||
|
||||
SessionProc::SendPacket(
|
||||
context,
|
||||
S_SERVICES,
|
||||
cSerialize::GetBuffer(),
|
||||
cSerialize::GetLength());
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug(_T("Service count :: 0\n"));
|
||||
|
||||
scServices packet;
|
||||
packet.count = 0;
|
||||
|
||||
SessionProc::SendPacket(
|
||||
context,
|
||||
S_SERVICES,
|
||||
reinterpret_cast<uint8*>(&packet),
|
||||
sizeof(packet));
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CServices::GetRunning(const TCHAR* service, BOOL& running, BOOL& console)
|
||||
{
|
||||
running = g_demonLauncher.IsRunningService(service);
|
||||
if(running)
|
||||
{
|
||||
console = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
running = g_demonLauncher.IsRunningConsole(service);
|
||||
if(running)
|
||||
{
|
||||
//PID = g_demonLauncher.GetPID(service);
|
||||
console = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void CTransfer::Run(IIocpContext* context)
|
||||
{
|
||||
if(!Ready(context))
|
||||
return;
|
||||
|
||||
Begin(context);
|
||||
}
|
||||
|
||||
BOOL CTransfer::Ready(IIocpContext* context)
|
||||
{
|
||||
m_session = SessionProc::GetSession(context->GetEntity());
|
||||
if(!m_session) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CTransfer::Begin(IIocpContext* context)
|
||||
{
|
||||
BOOL result = FALSE;
|
||||
switch(m_packet->type)
|
||||
{
|
||||
case TRANSFER_BEGIN :
|
||||
result = TransferBegin();
|
||||
break;
|
||||
|
||||
case TRANSFER_DO :
|
||||
result = TransferDo();
|
||||
break;
|
||||
|
||||
case TRANSFER_END :
|
||||
result = TransferEnd();
|
||||
break;
|
||||
}
|
||||
|
||||
if(result)
|
||||
{
|
||||
scTransfer packet;
|
||||
packet.result = result;
|
||||
packet.type = m_packet->type;
|
||||
packet.index = m_packet->index;
|
||||
|
||||
SessionProc::SendPacket(
|
||||
context,
|
||||
S_TRANSFER,
|
||||
reinterpret_cast<uint8*>(&packet),
|
||||
sizeof(packet));
|
||||
}
|
||||
else
|
||||
{
|
||||
scTransferFail packet;
|
||||
packet.result = result;
|
||||
packet.type = m_packet->type;
|
||||
packet.index = m_packet->index;
|
||||
CopyMemory(packet.file, m_session->GetFile(), sizeof(packet.file));
|
||||
|
||||
SessionProc::SendPacket(
|
||||
context,
|
||||
S_TRANSFER,
|
||||
reinterpret_cast<uint8*>(&packet),
|
||||
sizeof(packet));
|
||||
|
||||
m_session->TransferEnd();
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CTransfer::TransferBegin()
|
||||
{
|
||||
if(m_session->DoingTransfer())
|
||||
return FALSE;
|
||||
|
||||
TCHAR path[512];
|
||||
_stprintf_s(path, _countof(path), _T("%s\\%s"), m_begin->folder, m_begin->file);
|
||||
if(UpdateFile(path, m_begin->length, m_begin->digest))
|
||||
{
|
||||
// 파일이 존재하지 않거나 다른 버젼이므로 복사한다
|
||||
CreateFolder(m_begin->folder);
|
||||
CreateBuffer(path, m_begin->length);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// 파일이 존재하고 같은 버젼의 파일이다
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CTransfer::TransferDo()
|
||||
{
|
||||
if(m_session->TransferDo(m_buffer, m_length))
|
||||
{
|
||||
// 추가 성공
|
||||
if(m_session->GetLength() >= G_MAXFILESIZE)
|
||||
{
|
||||
cFileWriter file;
|
||||
if(!file.Open(m_session->GetFile(), OPEN_ALWAYS))
|
||||
{
|
||||
// 파일생성 실패
|
||||
Debug(_T("CTransfer - 파일생성 실패\n"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
file.Move(FILE_END, 0);
|
||||
if(!file.Write(m_session->GetBuffer(), m_session->GetLength()))
|
||||
{
|
||||
// 파일 쓰기 실패
|
||||
file.Close();
|
||||
Debug(_T("CTransfer - 파일쓰기 실패(%lu Bytes)\n"), m_session->GetLength());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// 종료
|
||||
file.Close();
|
||||
|
||||
// 버퍼정리
|
||||
m_session->TransferWrite();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// 실패
|
||||
Debug(_T("CTransfer - 데이타 전송실패\n"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CTransfer::TransferEnd()
|
||||
{
|
||||
if(!m_session->DoingTransfer())
|
||||
return FALSE;
|
||||
|
||||
if(m_end->length == m_session->GetTransferLength())
|
||||
{
|
||||
// 미리 저장된 파일인지 확인
|
||||
if(m_session->GetTransferLength() == m_session->GetLength())
|
||||
{
|
||||
// 저장된 적이 없으면 기존 파일을 지운다
|
||||
DeleteFile(m_session->GetFile());
|
||||
}
|
||||
|
||||
BOOL result = TRUE;
|
||||
|
||||
cFileWriter file;
|
||||
if(!file.Open(m_session->GetFile(), OPEN_ALWAYS))
|
||||
{
|
||||
// 파일생성 실패
|
||||
result = FALSE;
|
||||
DWORD error = GetLastError();
|
||||
m_session->TransferEnd();
|
||||
Debug(_T("CTransfer - 파일생성 실패\n"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
file.Move(FILE_END, 0);
|
||||
if(!file.Write(m_session->GetBuffer(), m_session->GetLength()))
|
||||
{
|
||||
// 파일 쓰기 실패
|
||||
file.Close();
|
||||
result = FALSE;
|
||||
m_session->TransferEnd();
|
||||
Debug(_T("CTransfer - 파일쓰기 실패(%lu Bytes)\n"), m_session->GetLength());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// 종료
|
||||
file.Close();
|
||||
m_session->TransferEnd();
|
||||
|
||||
Debug(_T("CTransfer - 파일 전송완료 (%0.1lfKB)\n"), m_end->length / 1024.0);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 실패
|
||||
m_session->TransferEnd();
|
||||
Debug(_T("CTransfer - 파일 전송실패\n"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CTransfer::UpdateFile(const TCHAR* fileName, const uint32 fileLength, const BYTE* source)
|
||||
{
|
||||
cFileReader file;
|
||||
BOOL result = file.Open(fileName);
|
||||
if(result)
|
||||
{
|
||||
if(file.GetFileSize() == fileLength)
|
||||
{
|
||||
m_temp.Erase();
|
||||
m_temp.Resize(fileLength);
|
||||
if(!file.Read(m_temp.GetBuffer(), fileLength))
|
||||
{
|
||||
file.Close();
|
||||
return TRUE;
|
||||
}
|
||||
m_temp.SetLength(fileLength);
|
||||
|
||||
CMD5 MD5;
|
||||
MD5.Generate(m_temp.GetBuffer(), fileLength);
|
||||
|
||||
BYTE digest[16];
|
||||
CopyMemory(digest, MD5.GetDigest(), sizeof(digest));
|
||||
for(uint32 n = 0 ; n < 16 ; n++)
|
||||
{
|
||||
if(digest[n] != source[n])
|
||||
{
|
||||
file.Close();
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
file.Close();
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
file.Close();
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CTransfer::CreateBuffer(const TCHAR* fileName, const uint32 length)
|
||||
{
|
||||
m_session->TransferBegin(fileName, length);
|
||||
DeleteFile(m_session->GetFile());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CRemove::Run(IIocpContext* context)
|
||||
{
|
||||
if(!Ready(context))
|
||||
return;
|
||||
|
||||
Begin(context);
|
||||
}
|
||||
|
||||
BOOL CRemove::Ready(IIocpContext* context)
|
||||
{
|
||||
m_session = SessionProc::GetSession(context->GetEntity());
|
||||
if(!m_session) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CRemove::Begin(IIocpContext* context)
|
||||
{
|
||||
BOOL result = RemoveFolder();
|
||||
|
||||
scRemove packet;
|
||||
packet.result = result;
|
||||
|
||||
SessionProc::SendPacket(
|
||||
context,
|
||||
S_REMOVE,
|
||||
reinterpret_cast<uint8*>(&packet),
|
||||
sizeof(packet));
|
||||
}
|
||||
|
||||
BOOL CRemove::RemoveFolder()
|
||||
{
|
||||
SHFILEOPSTRUCT fileop = {0};
|
||||
|
||||
fileop.hwnd = NULL;
|
||||
fileop.wFunc = FO_DELETE; // 삭제 속성 설정
|
||||
fileop.pFrom = m_packet->folder;
|
||||
fileop.pTo = NULL;
|
||||
fileop.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI;
|
||||
fileop.fAnyOperationsAborted = FALSE;
|
||||
fileop.hNameMappings = NULL;
|
||||
fileop.lpszProgressTitle = NULL;
|
||||
|
||||
int result = SHFileOperation(&fileop);
|
||||
return (0 == result) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
void CInstall::Run(IIocpContext* context)
|
||||
{
|
||||
if(!Ready(context))
|
||||
return;
|
||||
|
||||
Begin(context);
|
||||
}
|
||||
|
||||
BOOL CInstall::Ready(IIocpContext* context)
|
||||
{
|
||||
m_session = SessionProc::GetSession(context->GetEntity());
|
||||
if(!m_session) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CInstall::Begin(IIocpContext* context)
|
||||
{
|
||||
BOOL result = FALSE;
|
||||
if(m_packet->install)
|
||||
{
|
||||
result = DoInstall(m_install->service, m_install->file, m_install->script);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = DoUninstall(m_uninstall->service);
|
||||
if(result)
|
||||
{
|
||||
Remove(m_uninstall->clear);
|
||||
}
|
||||
}
|
||||
|
||||
scInstall packet;
|
||||
packet.result = result;
|
||||
|
||||
SessionProc::SendPacket(
|
||||
context,
|
||||
S_INSTALL,
|
||||
reinterpret_cast<uint8*>(&packet),
|
||||
sizeof(packet));
|
||||
}
|
||||
|
||||
BOOL CInstall::DoInstall(const TCHAR* service, const TCHAR* file, const TCHAR* script)
|
||||
{
|
||||
if(CreateRegistry(service, file, script))
|
||||
{
|
||||
TCHAR command[512];
|
||||
_stprintf_s(command, _countof(command), _T("/c \"%s -i %s %s\""), file, service, service);
|
||||
ShellExecute(NULL , NULL, _T("cmd.exe") , command, NULL, SW_HIDE);
|
||||
return IsService(service);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CInstall::DoUninstall(const TCHAR* service)
|
||||
{
|
||||
if(DeleteRegistry(service))
|
||||
{
|
||||
TCHAR command[512];
|
||||
_stprintf_s(command, _countof(command), _T("/c \"sc delete %s\""), service);
|
||||
ShellExecute(NULL , NULL, _T("cmd.exe") , command, NULL, SW_HIDE);
|
||||
return !IsService(service);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void CInstall::Remove(const BOOL b)
|
||||
{
|
||||
if(b)
|
||||
{
|
||||
// 파일을 모두 지운다
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CInstall::CreateRegistry(const TCHAR* service, const TCHAR* file, const TCHAR* script)
|
||||
{
|
||||
TCHAR regKey[512];
|
||||
_stprintf_s(regKey, _countof(regKey), _T("software\\LostSaga\\%s"), service);
|
||||
|
||||
HKEY key;
|
||||
DWORD disp = 0;
|
||||
LONG ret = RegCreateKeyEx(HKEY_CURRENT_USER, regKey,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, &disp);
|
||||
if(ret != ERROR_SUCCESS) return FALSE;
|
||||
|
||||
uint32 length = _tcsclen(service);
|
||||
length = length*sizeof(TCHAR);
|
||||
RegSetValueEx(key, _T("service"), 0, REG_SZ, (LPBYTE)service, length);
|
||||
|
||||
length = _tcsclen(file);
|
||||
length = length*sizeof(TCHAR);
|
||||
RegSetValueEx(key, _T("file"), 0, REG_SZ, (LPBYTE)file, length);
|
||||
|
||||
length = _tcsclen(script);
|
||||
length = length*sizeof(TCHAR);
|
||||
RegSetValueEx(key, _T("script"), 0, REG_SZ, (LPBYTE)script, length);
|
||||
|
||||
RegCloseKey(key);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CInstall::DeleteRegistry(const TCHAR* service)
|
||||
{
|
||||
TCHAR regKey[512];
|
||||
_stprintf_s(regKey, _countof(regKey), _T("software\\LostSaga\\%s"), service);
|
||||
|
||||
DWORD disp = 0;
|
||||
LONG ret = SHDeleteKey(HKEY_CURRENT_USER, regKey);
|
||||
if(ret != ERROR_SUCCESS) return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CPlay::Run(IIocpContext* context)
|
||||
{
|
||||
if(!Ready(context))
|
||||
return;
|
||||
|
||||
Begin(context);
|
||||
}
|
||||
|
||||
BOOL CPlay::Ready(IIocpContext* context)
|
||||
{
|
||||
m_session = SessionProc::GetSession(context->GetEntity());
|
||||
if(!m_session) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CPlay::Begin(IIocpContext* context)
|
||||
{
|
||||
BOOL result = FALSE;
|
||||
if(m_packet->play)
|
||||
{
|
||||
result = g_demonLauncher.Play(m_packet->service, m_packet->isDemon);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = g_demonLauncher.Stop(m_packet->service, m_packet->isDemon);
|
||||
}
|
||||
|
||||
scPlay packet;
|
||||
packet.result = result;
|
||||
|
||||
SessionProc::SendPacket(
|
||||
context,
|
||||
S_PLAY,
|
||||
reinterpret_cast<uint8*>(&packet),
|
||||
sizeof(packet));
|
||||
}
|
||||
|
||||
void CBackup::Run(IIocpContext* context)
|
||||
{
|
||||
if(!Ready(context))
|
||||
return;
|
||||
|
||||
Begin(context);
|
||||
}
|
||||
|
||||
BOOL CBackup::Ready(IIocpContext* context)
|
||||
{
|
||||
m_session = SessionProc::GetSession(context->GetEntity());
|
||||
if(!m_session) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CBackup::Begin(IIocpContext* context)
|
||||
{
|
||||
BOOL result = DoBackup(m_packet->source, m_packet->target);
|
||||
|
||||
scBackup packet;
|
||||
packet.result = result;
|
||||
|
||||
SessionProc::SendPacket(
|
||||
context,
|
||||
S_BACKUP,
|
||||
reinterpret_cast<uint8*>(&packet),
|
||||
sizeof(packet));
|
||||
}
|
||||
|
||||
BOOL CBackup::DoBackup(const TCHAR* source, const TCHAR* target)
|
||||
{
|
||||
SYSTEMTIME systemTime;
|
||||
GetLocalTime(&systemTime);
|
||||
|
||||
TCHAR backup[512];
|
||||
ZeroMemory(backup, _countof(backup));
|
||||
_stprintf_s(backup, _countof(backup),
|
||||
_T("%s\\%04d%02d%02d-%02d%02d"),
|
||||
target,
|
||||
systemTime.wYear,
|
||||
systemTime.wMonth,
|
||||
systemTime.wDay,
|
||||
systemTime.wHour,
|
||||
systemTime.wMinute);
|
||||
|
||||
if(!CreateFolder(backup))
|
||||
return FALSE;
|
||||
|
||||
SHFILEOPSTRUCT fileop = {0};
|
||||
|
||||
fileop.hwnd = NULL;
|
||||
fileop.wFunc = FO_COPY; // 삭제 속성 설정
|
||||
fileop.pFrom = source;
|
||||
fileop.pTo = backup;
|
||||
fileop.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI;
|
||||
fileop.fAnyOperationsAborted = FALSE;
|
||||
fileop.hNameMappings = NULL;
|
||||
fileop.lpszProgressTitle = NULL;
|
||||
|
||||
int result = SHFileOperation(&fileop);
|
||||
return (0 == result) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
void CReboot::Run(IIocpContext* context)
|
||||
{
|
||||
if(!Ready(context))
|
||||
return;
|
||||
|
||||
Begin(context);
|
||||
}
|
||||
|
||||
BOOL CReboot::Ready(IIocpContext* context)
|
||||
{
|
||||
m_session = SessionProc::GetSession(context->GetEntity());
|
||||
if(!m_session) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CReboot::Begin(IIocpContext* context)
|
||||
{
|
||||
BOOL result = DoReboot(m_packet->option);
|
||||
|
||||
scReboot packet;
|
||||
packet.result = result;
|
||||
|
||||
SessionProc::SendPacket(
|
||||
context,
|
||||
S_REBOOT,
|
||||
reinterpret_cast<uint8*>(&packet),
|
||||
sizeof(packet));
|
||||
}
|
||||
|
||||
BOOL CReboot::DoReboot(const uint32 option)
|
||||
{
|
||||
TCHAR command[512];
|
||||
_stprintf_s(command, _countof(command), _T("/c \"shutdown.exe /f /r /t %lu\""), option);
|
||||
ShellExecute(NULL , NULL, _T("cmd.exe") , command, NULL, SW_HIDE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CResource::Run(IIocpContext* context)
|
||||
{
|
||||
if(!Ready(context))
|
||||
return;
|
||||
|
||||
Begin(context);
|
||||
}
|
||||
|
||||
BOOL CResource::Ready(IIocpContext* context)
|
||||
{
|
||||
m_session = SessionProc::GetSession(context->GetEntity());
|
||||
if(!m_session) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CResource::Begin(IIocpContext* context)
|
||||
{
|
||||
UNITS cpus, mems, diskC, diskD, networks;
|
||||
DWORD error;
|
||||
|
||||
m_perfomance.GetCPU(cpus, error);
|
||||
m_perfomance.GetMemory(mems, error);
|
||||
m_perfomance.GetDisk(_T("c:"), diskC, error);
|
||||
m_perfomance.GetDisk(_T("d:"), diskD, error);
|
||||
m_perfomance.GetNetwork(networks, error);
|
||||
|
||||
scResource packet;
|
||||
packet.result = TRUE;
|
||||
packet.cpu = cpus.size();
|
||||
packet.memory = mems.size();
|
||||
packet.disk = diskC.size() + diskD.size();
|
||||
packet.network = networks.size();
|
||||
|
||||
cSerialize::Reset();
|
||||
cSerialize::Write(reinterpret_cast<uint8*>(&packet), sizeof(packet));
|
||||
|
||||
for(unsigned int i = 0 ; i < cpus.size() ; i++)
|
||||
{
|
||||
cSerialize::Write(static_cast<uint32>(cpus[i]));
|
||||
}
|
||||
for(unsigned int i = 0 ; i < mems.size() ; i++)
|
||||
{
|
||||
cSerialize::Write(static_cast<uint32>(mems[i]));
|
||||
}
|
||||
for(unsigned int i = 0 ; i < diskC.size() ; i++)
|
||||
{
|
||||
cSerialize::Write(static_cast<uint32>(diskC[i]));
|
||||
}
|
||||
for(unsigned int i = 0 ; i < diskD.size() ; i++)
|
||||
{
|
||||
cSerialize::Write(static_cast<uint32>(diskD[i]));
|
||||
}
|
||||
for(unsigned int i = 0 ; i < networks.size() ; i++)
|
||||
{
|
||||
cSerialize::Write(static_cast<uint32>(networks[i]));
|
||||
}
|
||||
|
||||
SessionProc::SendPacket(
|
||||
context,
|
||||
S_RESOURCE,
|
||||
cSerialize::GetBuffer(),
|
||||
cSerialize::GetLength());
|
||||
}
|
||||
@@ -0,0 +1,348 @@
|
||||
#pragma once
|
||||
|
||||
#include "cCommand.h"
|
||||
#include "cBuffer.h"
|
||||
#include "cSession.h"
|
||||
#include "cSerialize.h"
|
||||
#include "Utility.h"
|
||||
#include "PerfMon.h"
|
||||
#include "../common/internal.h"
|
||||
#include <vector>
|
||||
|
||||
class CPing : public cCommand
|
||||
{
|
||||
protected:
|
||||
virtual BOOL Verify(IIocpContext* pContext, uint8* buffer, const uint32 length)
|
||||
{
|
||||
if(length != 0)
|
||||
return FALSE;
|
||||
|
||||
m_packet = reinterpret_cast<csPing*>(buffer);
|
||||
return TRUE;
|
||||
}
|
||||
virtual void Self()
|
||||
{
|
||||
Debug(_T("C_PING\n"));
|
||||
}
|
||||
virtual void Run(IIocpContext* context);
|
||||
|
||||
protected:
|
||||
csPing* m_packet;
|
||||
|
||||
};
|
||||
|
||||
class CServices : public cCommand, public cSerialize
|
||||
{
|
||||
protected:
|
||||
virtual BOOL Verify(IIocpContext* pContext, uint8* buffer, const uint32 length)
|
||||
{
|
||||
m_services.clear();
|
||||
m_files.clear();
|
||||
m_scripts.clear();
|
||||
return TRUE;
|
||||
}
|
||||
virtual void Self()
|
||||
{
|
||||
Debug(_T("C_SERVICES\n"));
|
||||
}
|
||||
virtual void Run(IIocpContext* context);
|
||||
|
||||
protected:
|
||||
BOOL Ready(IIocpContext* context);
|
||||
void Begin(IIocpContext* context);
|
||||
|
||||
BOOL GetRunning(const TCHAR* service, BOOL& running, BOOL& console);
|
||||
|
||||
protected:
|
||||
cSession* m_session;
|
||||
|
||||
STRINGS m_services, m_files, m_scripts;
|
||||
};
|
||||
|
||||
|
||||
class CTransfer : public cCommand
|
||||
{
|
||||
protected:
|
||||
virtual BOOL Verify(IIocpContext* pContext, uint8* buffer, const uint32 length)
|
||||
{
|
||||
if(length < sizeof(csTransfer))
|
||||
return FALSE;
|
||||
|
||||
m_packet = reinterpret_cast<csTransfer*>(buffer);
|
||||
m_buffer = NULL;
|
||||
m_length = 0;
|
||||
m_temp.Erase();
|
||||
|
||||
switch(m_packet->type)
|
||||
{
|
||||
case TRANSFER_BEGIN :
|
||||
if(length < sizeof(csTransferBegin))
|
||||
return FALSE;
|
||||
m_begin = reinterpret_cast<csTransferBegin*>(buffer);
|
||||
break;
|
||||
|
||||
case TRANSFER_DO :
|
||||
{
|
||||
if(length < sizeof(csTransferDo))
|
||||
return FALSE;
|
||||
m_do = reinterpret_cast<csTransferDo*>(buffer);
|
||||
m_buffer = (buffer + sizeof(csTransferDo));
|
||||
if(length != (m_do->length + sizeof(csTransferDo)))
|
||||
return FALSE;
|
||||
|
||||
m_length = m_do->length;
|
||||
}
|
||||
break;
|
||||
|
||||
case TRANSFER_END :
|
||||
if(length < sizeof(csTransferEnd))
|
||||
return FALSE;
|
||||
m_end = reinterpret_cast<csTransferEnd*>(buffer);
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
virtual void Self()
|
||||
{
|
||||
Debug(_T("C_TRANSFER\n"));
|
||||
}
|
||||
virtual void Run(IIocpContext* context);
|
||||
|
||||
protected:
|
||||
BOOL Ready(IIocpContext* context);
|
||||
void Begin(IIocpContext* context);
|
||||
|
||||
protected:
|
||||
BOOL TransferBegin();
|
||||
BOOL TransferDo();
|
||||
BOOL TransferEnd();
|
||||
|
||||
BOOL UpdateFile(const TCHAR* fileName, const uint32 fileLength, const BYTE* source);
|
||||
BOOL CreateBuffer(const TCHAR* fileName, const uint32 length);
|
||||
|
||||
protected:
|
||||
cSession* m_session;
|
||||
|
||||
csTransfer* m_packet;
|
||||
csTransferBegin* m_begin;
|
||||
csTransferDo* m_do;
|
||||
csTransferEnd* m_end;
|
||||
uint8* m_buffer;
|
||||
uint32 m_length;
|
||||
cBuffer m_temp;
|
||||
};
|
||||
|
||||
|
||||
class CRemove : public cCommand
|
||||
{
|
||||
protected:
|
||||
virtual BOOL Verify(IIocpContext* pContext, uint8* buffer, const uint32 length)
|
||||
{
|
||||
if(length < sizeof(csRemove))
|
||||
return FALSE;
|
||||
|
||||
m_packet = reinterpret_cast<csRemove*>(buffer);
|
||||
return TRUE;
|
||||
}
|
||||
virtual void Self()
|
||||
{
|
||||
Debug(_T("C_REMOVE\n"));
|
||||
}
|
||||
virtual void Run(IIocpContext* context);
|
||||
|
||||
protected:
|
||||
BOOL Ready(IIocpContext* context);
|
||||
void Begin(IIocpContext* context);
|
||||
|
||||
protected:
|
||||
BOOL RemoveFolder();
|
||||
|
||||
protected:
|
||||
cSession* m_session;
|
||||
|
||||
csRemove* m_packet;
|
||||
};
|
||||
|
||||
class CInstall : public cCommand
|
||||
{
|
||||
protected:
|
||||
virtual BOOL Verify(IIocpContext* pContext, uint8* buffer, const uint32 length)
|
||||
{
|
||||
if(length < sizeof(Install))
|
||||
return FALSE;
|
||||
|
||||
m_packet = reinterpret_cast<Install*>(buffer);
|
||||
if(m_packet->install)
|
||||
{
|
||||
if(length < sizeof(csInstall))
|
||||
return FALSE;
|
||||
|
||||
m_install = reinterpret_cast<csInstall*>(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(length < sizeof(csUninstall))
|
||||
return FALSE;
|
||||
|
||||
m_uninstall = reinterpret_cast<csUninstall*>(buffer);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
virtual void Self()
|
||||
{
|
||||
Debug(_T("C_INSTALL\n"));
|
||||
}
|
||||
virtual void Run(IIocpContext* context);
|
||||
|
||||
protected:
|
||||
BOOL Ready(IIocpContext* context);
|
||||
void Begin(IIocpContext* context);
|
||||
|
||||
protected:
|
||||
BOOL DoInstall(const TCHAR* service, const TCHAR* file, const TCHAR* script);
|
||||
BOOL DoUninstall(const TCHAR* service);
|
||||
void Remove(const BOOL b);
|
||||
|
||||
BOOL CreateRegistry(const TCHAR* service, const TCHAR* file, const TCHAR* script);
|
||||
BOOL DeleteRegistry(const TCHAR* service);
|
||||
|
||||
protected:
|
||||
cSession* m_session;
|
||||
|
||||
Install* m_packet;
|
||||
csInstall* m_install;
|
||||
csUninstall* m_uninstall;
|
||||
};
|
||||
|
||||
|
||||
class CPlay : public cCommand
|
||||
{
|
||||
protected:
|
||||
virtual BOOL Verify(IIocpContext* pContext, uint8* buffer, const uint32 length)
|
||||
{
|
||||
if(length < sizeof(Play))
|
||||
return FALSE;
|
||||
|
||||
m_packet = reinterpret_cast<Play*>(buffer);
|
||||
if(m_packet->play)
|
||||
{
|
||||
if(length < sizeof(csPlay))
|
||||
return FALSE;
|
||||
|
||||
m_play = reinterpret_cast<csPlay*>(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(length < sizeof(csStop))
|
||||
return FALSE;
|
||||
|
||||
m_stop = reinterpret_cast<csStop*>(buffer);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
virtual void Self()
|
||||
{
|
||||
Debug(_T("C_PLAY\n"));
|
||||
}
|
||||
virtual void Run(IIocpContext* context);
|
||||
|
||||
protected:
|
||||
BOOL Ready(IIocpContext* context);
|
||||
void Begin(IIocpContext* context);
|
||||
|
||||
protected:
|
||||
BOOL DoPlay(const TCHAR* service, const BOOL isDemon, DWORD &PID);
|
||||
BOOL DoStop(const TCHAR* service, const BOOL isDemon);
|
||||
|
||||
protected:
|
||||
cSession* m_session;
|
||||
|
||||
Play* m_packet;
|
||||
csPlay* m_play;
|
||||
csStop* m_stop;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class CBackup : public cCommand
|
||||
{
|
||||
protected:
|
||||
virtual BOOL Verify(IIocpContext* pContext, uint8* buffer, const uint32 length)
|
||||
{
|
||||
if(length < sizeof(csBackup))
|
||||
return FALSE;
|
||||
|
||||
m_packet = reinterpret_cast<csBackup*>(buffer);
|
||||
return TRUE;
|
||||
}
|
||||
virtual void Self()
|
||||
{
|
||||
Debug(_T("C_BACKUP\n"));
|
||||
}
|
||||
virtual void Run(IIocpContext* context);
|
||||
|
||||
protected:
|
||||
BOOL Ready(IIocpContext* context);
|
||||
void Begin(IIocpContext* context);
|
||||
|
||||
protected:
|
||||
BOOL DoBackup(const TCHAR* source, const TCHAR* target);
|
||||
|
||||
protected:
|
||||
cSession* m_session;
|
||||
|
||||
csBackup* m_packet;
|
||||
};
|
||||
|
||||
class CReboot : public cCommand
|
||||
{
|
||||
protected:
|
||||
virtual BOOL Verify(IIocpContext* pContext, uint8* buffer, const uint32 length)
|
||||
{
|
||||
if(length < sizeof(csReboot))
|
||||
return FALSE;
|
||||
|
||||
m_packet = reinterpret_cast<csReboot*>(buffer);
|
||||
return TRUE;
|
||||
}
|
||||
virtual void Self()
|
||||
{
|
||||
Debug(_T("C_REBOOT\n"));
|
||||
}
|
||||
virtual void Run(IIocpContext* context);
|
||||
|
||||
protected:
|
||||
BOOL Ready(IIocpContext* context);
|
||||
void Begin(IIocpContext* context);
|
||||
|
||||
protected:
|
||||
BOOL DoReboot(const uint32 option);
|
||||
|
||||
protected:
|
||||
cSession* m_session;
|
||||
|
||||
csReboot* m_packet;
|
||||
};
|
||||
|
||||
class CResource : public cCommand, public cSerialize
|
||||
{
|
||||
protected:
|
||||
virtual BOOL Verify(IIocpContext* pContext, uint8* buffer, const uint32 length)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
virtual void Self()
|
||||
{
|
||||
Debug(_T("C_RESOURCE\n"));
|
||||
}
|
||||
virtual void Run(IIocpContext* context);
|
||||
|
||||
protected:
|
||||
BOOL Ready(IIocpContext* context);
|
||||
void Begin(IIocpContext* context);
|
||||
|
||||
protected:
|
||||
cSession* m_session;
|
||||
|
||||
PerfMon m_perfomance;
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
#include "StdAfx.h"
|
||||
#include "cEnvironment.h"
|
||||
#include "cSessionTable.h"
|
||||
#include "SessionProc.h"
|
||||
#include "InternalCommand.h"
|
||||
#include "../include/IIocpContext.h"
|
||||
#include "../include/INetwork.h"
|
||||
#include "../include/cSingleton.h"
|
||||
#include "../common/Internal.h"
|
||||
|
||||
void IConnect::Run(IIocpContext* context)
|
||||
{
|
||||
Debug(_T("Connected\n"));
|
||||
// 세션추가
|
||||
if(!SessionProc::AddSession(context))
|
||||
{
|
||||
// 접속 중이던 세션이므로 종료가 필요함
|
||||
SessionProc::DeleteSession(context);
|
||||
}
|
||||
}
|
||||
|
||||
void IClose::Run(IIocpContext* context)
|
||||
{
|
||||
Debug(_T("Closed\n"));
|
||||
// 세션삭제
|
||||
SessionProc::DeleteSession(context);
|
||||
}
|
||||
|
||||
void IPing::Run(const uint32 serverId)
|
||||
{
|
||||
// 접속된 모든 클라이언트 소켓들에게 PING을 보낸다
|
||||
//Debug("@Ping\n");
|
||||
|
||||
SessionProc::Broadcast(S_PING, NULL, 0);
|
||||
}
|
||||
|
||||
void IFlush::Run(const uint32 serverId)
|
||||
{
|
||||
//Debug("@Flush\n");
|
||||
|
||||
cSession* session = SessionProc::GetFirstSession();
|
||||
while(session)
|
||||
{
|
||||
cSingleton<INetwork>::GetInstance()->Flush(session->GetContext());
|
||||
session = SessionProc::GetNextSession();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
#include "cCommand.h"
|
||||
|
||||
// 서버에 접속됐을때 자동으로 호출되는 명령
|
||||
class IConnect : public cCommand
|
||||
{
|
||||
protected:
|
||||
virtual void Self()
|
||||
{
|
||||
Debug(_T("I_CONNECT\n"));
|
||||
}
|
||||
virtual void Run(IIocpContext* context);
|
||||
};
|
||||
|
||||
// 서버와 연결이 종료되었을때 자동으로 호출되는 명령
|
||||
class IClose : public cCommand
|
||||
{
|
||||
protected:
|
||||
virtual void Self()
|
||||
{
|
||||
Debug(_T("I_CLOSE\n"));
|
||||
}
|
||||
virtual void Run(IIocpContext* context);
|
||||
};
|
||||
|
||||
// Ping을 처리해야될 타이머 메세지
|
||||
class IPing : public cCommand
|
||||
{
|
||||
public:
|
||||
IPing() : m_sequence(0)
|
||||
{}
|
||||
|
||||
protected:
|
||||
virtual void Self()
|
||||
{
|
||||
Debug(_T("I_PING\n"));
|
||||
}
|
||||
virtual void Run(const uint32 serverId);
|
||||
|
||||
protected:
|
||||
uint32 m_sequence;
|
||||
};
|
||||
|
||||
// send buffer flush
|
||||
class IFlush : public cCommand
|
||||
{
|
||||
public:
|
||||
IFlush()
|
||||
{}
|
||||
|
||||
protected:
|
||||
virtual void Self()
|
||||
{
|
||||
Debug(_T("I_FLUSH\n"));
|
||||
}
|
||||
virtual void Run(const uint32 serverId);
|
||||
};
|
||||
|
||||
// 접속한 서버에서 주는 신호
|
||||
class SPing : public cCommand
|
||||
{
|
||||
protected:
|
||||
virtual void Self()
|
||||
{
|
||||
Debug(_T("S_PING\n"));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{C24427A8-F74F-4662-B8E4-2AB751B66B59}</ProjectGuid>
|
||||
<RootNamespace>LS_controller</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC60.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC60.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\bin\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\Debug\</IntDir>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\bin\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</IntDir>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">C:\Program Files %28x86%29\Microsoft SDKs\Windows\v7.0A\Include;C:\Program Files %28x86%29\boost\boost_1_47;$(IncludePath)</IncludePath>
|
||||
<LibraryPath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">C:\Program Files %28x86%29\Microsoft SDKs\Windows\v7.0A\Lib;C:\Program Files %28x86%29\boost\boost_1_47\lib;$(LibraryPath)</LibraryPath>
|
||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectName)D</TargetName>
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">C:\Program Files %28x86%29\boost\boost_1_47;$(IncludePath)</IncludePath>
|
||||
<LibraryPath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">C:\Program Files %28x86%29\boost\boost_1_47;$(LibraryPath)</LibraryPath>
|
||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectName)</TargetName>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Midl>
|
||||
<TypeLibraryName>$(SolutionDir)$(Configuration)/LS-controller.tlb</TypeLibraryName>
|
||||
<HeaderFileName>
|
||||
</HeaderFileName>
|
||||
</Midl>
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);../../../src/include</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<PrecompiledHeaderOutputFile>$(IntDir)$(TargetName).pch</PrecompiledHeaderOutputFile>
|
||||
<AssemblerListingLocation>
|
||||
</AssemblerListingLocation>
|
||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
||||
<ProgramDataBaseFileName>$(IntDir)ls_controllerD.pdb</ProgramDataBaseFileName>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<Culture>0x0412</Culture>
|
||||
</ResourceCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>perfmonD.lib;pdh.lib;Userenv.lib;Wtsapi32.lib;Shlwapi.lib;../lib/networkD.lib;ws2_32.lib;odbc32.lib;winmm.lib;odbccp32.lib;Mswsock.lib;comsuppw.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>..\Bin\$(ProjectName)D.exe</OutputFile>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<ProgramDatabaseFile>$(TargetDir)$(TargetName).pdb</ProgramDatabaseFile>
|
||||
<GenerateMapFile>false</GenerateMapFile>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
<AdditionalLibraryDirectories>../../../lib</AdditionalLibraryDirectories>
|
||||
<IgnoreSpecificDefaultLibraries>
|
||||
</IgnoreSpecificDefaultLibraries>
|
||||
</Link>
|
||||
<Bscmake>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<OutputFile>$(SolutionDir)$(Configuration)/LS-controller.bsc</OutputFile>
|
||||
</Bscmake>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<BuildLog>
|
||||
<Path>Release\BuildLog.htm</Path>
|
||||
</BuildLog>
|
||||
<Midl>
|
||||
<TypeLibraryName>Release/$(Configuration)/LS-controller.tlb</TypeLibraryName>
|
||||
<HeaderFileName>
|
||||
</HeaderFileName>
|
||||
</Midl>
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);../../../src/include</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<PrecompiledHeaderOutputFile>$(TargetName).pch</PrecompiledHeaderOutputFile>
|
||||
<AssemblerListingLocation>
|
||||
</AssemblerListingLocation>
|
||||
<ObjectFileName>Release\</ObjectFileName>
|
||||
<ProgramDataBaseFileName>Release\LS-controller.pdb</ProgramDataBaseFileName>
|
||||
<XMLDocumentationFileName>Release\</XMLDocumentationFileName>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<Culture>0x0412</Culture>
|
||||
</ResourceCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>perfmon.lib;pdh.lib;Userenv.lib;Wtsapi32.lib;Shlwapi.lib;../lib/Lua_U.lib;../lib/network.lib;ws2_32.lib;odbc32.lib;winmm.lib;odbccp32.lib;Mswsock.lib;comsuppw.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>..\Bin\$(ProjectName).exe</OutputFile>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<ManifestFile>Release\$(TargetFileName).intermediate.manifest</ManifestFile>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<ProgramDatabaseFile>$(TargetDir)$(TargetName).pdb</ProgramDatabaseFile>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
<AdditionalLibraryDirectories>../../../lib</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<Manifest>
|
||||
<OutputManifestFile>$(TargetFileName).embed.manifest</OutputManifestFile>
|
||||
</Manifest>
|
||||
<ManifestResourceCompile>
|
||||
<ResourceOutputFileName>$(TargetFileName).embed.manifest.res</ResourceOutputFileName>
|
||||
</ManifestResourceCompile>
|
||||
<Xdcmake>
|
||||
<OutputFile>Release\$(TargetName).xml</OutputFile>
|
||||
</Xdcmake>
|
||||
<Bscmake>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<OutputFile>$(SolutionDir)\LS_controller\$(Configuration)\LS-controller.bsc</OutputFile>
|
||||
</Bscmake>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="cBuffer.cpp" />
|
||||
<ClCompile Include="cDemonLauncher.cpp" />
|
||||
<ClCompile Include="cFile.cpp" />
|
||||
<ClCompile Include="cServiceLS.cpp" />
|
||||
<ClCompile Include="Utility.cpp" />
|
||||
<ClCompile Include="GameCommand.cpp" />
|
||||
<ClCompile Include="InternalCommand.cpp" />
|
||||
<ClCompile Include="cCommand.cpp" />
|
||||
<ClCompile Include="SessionProc.cpp" />
|
||||
<ClCompile Include="cCommandHandler.cpp">
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cProcessor.cpp">
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cSession.cpp" />
|
||||
<ClCompile Include="cSessionTable.cpp" />
|
||||
<ClCompile Include="cManager.cpp" />
|
||||
<ClCompile Include="main.cpp">
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cMiniDump.cpp" />
|
||||
<ClCompile Include="cScheduler.cpp" />
|
||||
<ClCompile Include="cEnvironment.cpp">
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cService.cpp" />
|
||||
<ClCompile Include="MD5.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="cBuffer.h" />
|
||||
<ClInclude Include="cDemonLauncher.h" />
|
||||
<ClInclude Include="cFile.h" />
|
||||
<ClInclude Include="cServiceLS.h" />
|
||||
<ClInclude Include="Utility.h" />
|
||||
<ClInclude Include="GameCommand.h" />
|
||||
<ClInclude Include="InternalCommand.h" />
|
||||
<ClInclude Include="cCommand.h" />
|
||||
<ClInclude Include="cSerialize.h" />
|
||||
<ClInclude Include="SessionProc.h" />
|
||||
<ClInclude Include="cCommandHandler.h" />
|
||||
<ClInclude Include="cProcessor.h" />
|
||||
<ClInclude Include="cSession.h" />
|
||||
<ClInclude Include="cSessionTable.h" />
|
||||
<ClInclude Include="..\common\Internal.h" />
|
||||
<ClInclude Include="..\common\Protocol.h" />
|
||||
<ClInclude Include="cManager.h" />
|
||||
<ClInclude Include="cMiniDump.h" />
|
||||
<ClInclude Include="cScheduler.h" />
|
||||
<ClInclude Include="cEnvironment.h" />
|
||||
<ClInclude Include="cService.h" />
|
||||
<ClInclude Include="MD5.h" />
|
||||
<ClInclude Include="StdAfx.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,177 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="cProcessor.cpp">
|
||||
<Filter>App\Processor</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cScheduler.cpp">
|
||||
<Filter>App\Scheduler</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cMiniDump.cpp">
|
||||
<Filter>Etc\Minidump</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cService.cpp">
|
||||
<Filter>Etc\Service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cServiceLS.cpp">
|
||||
<Filter>Etc\Service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cCommand.cpp">
|
||||
<Filter>App\Handler</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cCommandHandler.cpp">
|
||||
<Filter>App\Handler</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GameCommand.cpp">
|
||||
<Filter>App\Command</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="InternalCommand.cpp">
|
||||
<Filter>App\Command</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cSession.cpp">
|
||||
<Filter>App\Session</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cSessionTable.cpp">
|
||||
<Filter>App\Session</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cManager.cpp">
|
||||
<Filter>Etc\Manager</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cEnvironment.cpp">
|
||||
<Filter>Etc</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cBuffer.cpp">
|
||||
<Filter>Etc\Utility</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cFile.cpp">
|
||||
<Filter>Etc\Utility</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Etc</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SessionProc.cpp">
|
||||
<Filter>App\Command\Proc</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Utility.cpp">
|
||||
<Filter>Etc\Utility</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MD5.cpp">
|
||||
<Filter>Etc\Utility</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cDemonLauncher.cpp">
|
||||
<Filter>App</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="cProcessor.h">
|
||||
<Filter>App\Processor</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cScheduler.h">
|
||||
<Filter>App\Scheduler</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cMiniDump.h">
|
||||
<Filter>Etc\Minidump</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cServiceLS.h">
|
||||
<Filter>Etc\Service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cService.h">
|
||||
<Filter>Etc\Service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cCommandHandler.h">
|
||||
<Filter>App\Handler</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cCommand.h">
|
||||
<Filter>App\Handler</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GameCommand.h">
|
||||
<Filter>App\Command</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="InternalCommand.h">
|
||||
<Filter>App\Command</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cSessionTable.h">
|
||||
<Filter>App\Session</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cSession.h">
|
||||
<Filter>App\Session</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cManager.h">
|
||||
<Filter>Etc\Manager</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cEnvironment.h">
|
||||
<Filter>Etc</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cSerialize.h">
|
||||
<Filter>Etc\Utility</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cBuffer.h">
|
||||
<Filter>Etc\Utility</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cFile.h">
|
||||
<Filter>Etc\Utility</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\common\Internal.h">
|
||||
<Filter>define</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="SessionProc.h">
|
||||
<Filter>App\Command\Proc</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\common\Protocol.h">
|
||||
<Filter>define</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="StdAfx.h">
|
||||
<Filter>Etc</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Utility.h">
|
||||
<Filter>Etc\Utility</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MD5.h">
|
||||
<Filter>Etc\Utility</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="cDemonLauncher.h">
|
||||
<Filter>App</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="App">
|
||||
<UniqueIdentifier>{a14f78a2-5208-4e30-9757-97cd0d76b073}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="App\Command">
|
||||
<UniqueIdentifier>{27561b4e-9633-4501-a45c-0cb6891051c6}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="App\Scheduler">
|
||||
<UniqueIdentifier>{5fb8afa9-7529-4f38-93a9-2f592f8b56d0}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Etc">
|
||||
<UniqueIdentifier>{1c3ae19c-fde1-4221-904e-2ae5bd198b23}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Etc\Minidump">
|
||||
<UniqueIdentifier>{004c8b2a-6f16-4394-b6a2-4b81b46f9b5d}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Etc\Service">
|
||||
<UniqueIdentifier>{bbb9b669-1f79-4c89-ab62-02a2c16d3f48}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="App\Handler">
|
||||
<UniqueIdentifier>{9af97764-8639-4f8f-8481-9d48566c6111}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="App\Processor">
|
||||
<UniqueIdentifier>{20def935-1e29-43b6-a6a8-474641fafebf}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="App\Session">
|
||||
<UniqueIdentifier>{1f5c2150-0abc-48b1-846c-fd5303d190cd}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Etc\Manager">
|
||||
<UniqueIdentifier>{b3967eb2-cc3a-40aa-a128-99eaf7ecd1bb}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Etc\Utility">
|
||||
<UniqueIdentifier>{6d017d3a-5b14-47ae-9fa6-93bfdb4ab6fc}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="define">
|
||||
<UniqueIdentifier>{522d4564-a3c4-4e70-9912-251110e03ea8}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="App\Command\Proc">
|
||||
<UniqueIdentifier>{d093448e-5c6b-46ce-a5b0-002d776dd24a}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,288 @@
|
||||
// MD5.cpp: implementation of the CMD5 class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "MD5.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
|
||||
#define S11 7
|
||||
#define S12 12
|
||||
#define S13 17
|
||||
#define S14 22
|
||||
#define S21 5
|
||||
#define S22 9
|
||||
#define S23 14
|
||||
#define S24 20
|
||||
#define S31 4
|
||||
#define S32 11
|
||||
#define S33 16
|
||||
#define S34 23
|
||||
#define S41 6
|
||||
#define S42 10
|
||||
#define S43 15
|
||||
#define S44 21
|
||||
|
||||
static BYTE PADDING[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/* F, G, H and I are basic MD5 functions.
|
||||
*/
|
||||
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define I(x, y, z) ((y) ^ ((x) | (~z)))
|
||||
|
||||
/* ROTATE_LEFT rotates x left n bits.
|
||||
*/
|
||||
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
||||
|
||||
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
|
||||
Rotation is separate from addition to prevent recomputation.
|
||||
*/
|
||||
#define FF(a, b, c, d, x, s, ac) { \
|
||||
(a) += F ((b), (c), (d)) + (x) + (UINT)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define GG(a, b, c, d, x, s, ac) { \
|
||||
(a) += G ((b), (c), (d)) + (x) + (UINT)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define HH(a, b, c, d, x, s, ac) { \
|
||||
(a) += H ((b), (c), (d)) + (x) + (UINT)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define II(a, b, c, d, x, s, ac) { \
|
||||
(a) += I ((b), (c), (d)) + (x) + (UINT)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
static void MD5Transform (UINT state[4], BYTE block[64]);
|
||||
static void Encode(BYTE* output, UINT* input, UINT len);
|
||||
static void Decode (UINT* output, BYTE* input, UINT len);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CMD5::CMD5()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CMD5::~CMD5()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
CString CMD5::GetString(CString str)
|
||||
{
|
||||
MD5_CTX context;
|
||||
BYTE digest[16];
|
||||
UINT len = str.GetLength();
|
||||
|
||||
MD5Init (&context);
|
||||
MD5Update (&context, (BYTE*)(LPTSTR)(LPCTSTR)str, len);
|
||||
MD5Final (digest, &context);
|
||||
|
||||
CString temp;
|
||||
CString ret = _T("");
|
||||
for (int i=0; i<16; i++)
|
||||
{
|
||||
temp.Format("%02X", digest[i]);
|
||||
ret += temp;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
*/
|
||||
|
||||
void CMD5::Generate(BYTE* file, UINT length)
|
||||
{
|
||||
ZeroMemory(m_digest, sizeof(m_digest));
|
||||
|
||||
MD5_CTX context;
|
||||
|
||||
MD5Init(&context);
|
||||
MD5Update(&context, file, length);
|
||||
MD5Final(m_digest, &context);
|
||||
}
|
||||
|
||||
void CMD5::MD5Init(MD5_CTX* context)
|
||||
{
|
||||
context->count[0] = context->count[1] = 0;
|
||||
|
||||
context->state[0] = 0x67452301;
|
||||
context->state[1] = 0xefcdab89;
|
||||
context->state[2] = 0x98badcfe;
|
||||
context->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
void CMD5::MD5Update (MD5_CTX* context, BYTE* input, UINT inputLen)
|
||||
{
|
||||
UINT i, index, partLen;
|
||||
|
||||
index = (UINT)((context->count[0] >> 3) & 0x3F);
|
||||
|
||||
if ((context->count[0] += ((UINT)inputLen << 3)) < ((UINT)inputLen << 3))
|
||||
context->count[1]++;
|
||||
|
||||
context->count[1] += ((UINT)inputLen >> 29);
|
||||
partLen = 64 - index;
|
||||
|
||||
if (inputLen >= partLen)
|
||||
{
|
||||
memcpy(&context->buffer[index], input, partLen);
|
||||
MD5Transform (context->state, context->buffer);
|
||||
|
||||
for (i = partLen; i + 63 < inputLen; i += 64)
|
||||
MD5Transform (context->state, &input[i]);
|
||||
|
||||
index = 0;
|
||||
}
|
||||
else
|
||||
i = 0;
|
||||
|
||||
memcpy(&context->buffer[index], &input[i], inputLen-i);
|
||||
}
|
||||
|
||||
void CMD5::MD5Final (BYTE* digest, MD5_CTX* context)
|
||||
{
|
||||
BYTE bits[8];
|
||||
UINT index, padLen;
|
||||
|
||||
Encode (bits, context->count, 8);
|
||||
|
||||
index = (UINT)((context->count[0] >> 3) & 0x3f);
|
||||
padLen = (index < 56) ? (56 - index) : (120 - index);
|
||||
MD5Update (context, PADDING, padLen);
|
||||
|
||||
MD5Update (context, bits, 8);
|
||||
|
||||
Encode (digest, context->state, 16);
|
||||
memset (context, 0, sizeof (*context));
|
||||
}
|
||||
|
||||
|
||||
static void MD5Transform (UINT state[4], BYTE block[64])
|
||||
{
|
||||
UINT a = state[0], b = state[1], c = state[2], d = state[3], x[16];
|
||||
|
||||
Decode (x, block, 64);
|
||||
|
||||
/* Round 1 */
|
||||
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
|
||||
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
|
||||
FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
|
||||
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
|
||||
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
|
||||
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
|
||||
FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
|
||||
FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
|
||||
FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
|
||||
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
|
||||
FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
|
||||
FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
|
||||
FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
|
||||
FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
|
||||
FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
|
||||
FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
|
||||
|
||||
/* Round 2 */
|
||||
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
|
||||
GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
|
||||
GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
|
||||
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
|
||||
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
|
||||
GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
|
||||
GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
|
||||
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
|
||||
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
|
||||
GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
|
||||
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
|
||||
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
|
||||
GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
|
||||
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
|
||||
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
|
||||
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
|
||||
|
||||
/* Round 3 */
|
||||
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
|
||||
HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
|
||||
HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
|
||||
HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
|
||||
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
|
||||
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
|
||||
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
|
||||
HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
|
||||
HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
|
||||
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
|
||||
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
|
||||
HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
|
||||
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
|
||||
HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
|
||||
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
|
||||
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
|
||||
|
||||
/* Round 4 */
|
||||
II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
|
||||
II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
|
||||
II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
|
||||
II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
|
||||
II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
|
||||
II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
|
||||
II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
|
||||
II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
|
||||
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
|
||||
II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
|
||||
II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
|
||||
II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
|
||||
II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
|
||||
II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
|
||||
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
|
||||
II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
|
||||
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
|
||||
/* Zeroize sensitive information. */
|
||||
memset (x, 0, sizeof (x));
|
||||
}
|
||||
|
||||
static void Encode(BYTE* output, UINT* input, UINT len)
|
||||
{
|
||||
UINT i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4) {
|
||||
output[j] = (BYTE)(input[i] & 0xff);
|
||||
output[j+1] = (BYTE)((input[i] >> 8) & 0xff);
|
||||
output[j+2] = (BYTE)((input[i] >> 16) & 0xff);
|
||||
output[j+3] = (BYTE)((input[i] >> 24) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
static void Decode (UINT* output, BYTE* input, UINT len)
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4)
|
||||
output[i] = ((UINT)input[j]) | (((UINT)input[j+1]) << 8) |
|
||||
(((UINT)input[j+2]) << 16) | (((UINT)input[j+3]) << 24);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// MD5.h: interface for the CMD5 class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
class CMD5
|
||||
{
|
||||
public:
|
||||
CMD5();
|
||||
~CMD5();
|
||||
|
||||
public:
|
||||
void Generate(BYTE* file, UINT length);
|
||||
BYTE* GetDigest() { return m_digest; }
|
||||
|
||||
protected:
|
||||
BYTE m_digest[16];
|
||||
|
||||
protected:
|
||||
typedef struct
|
||||
{
|
||||
UINT state[4]; /* state (ABCD) */
|
||||
UINT count[2]; /* number of bits, modulo 2^64 (lsb first) */
|
||||
BYTE buffer[64]; /* input buffer */
|
||||
} MD5_CTX;
|
||||
|
||||
void MD5Init(MD5_CTX* ctx);
|
||||
void MD5Update(MD5_CTX* ctx, BYTE* input, UINT inputlen);
|
||||
void MD5Final(BYTE* digest, MD5_CTX* ctx);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
#include "StdAfx.h"
|
||||
#include "SessionProc.h"
|
||||
#include "SessionProc.h"
|
||||
#include "../include/IIocpContext.h"
|
||||
#include "../include/INetwork.h"
|
||||
#include "../include/cSingleton.h"
|
||||
|
||||
|
||||
void SessionProc::SendPacket(
|
||||
IIocpContext* context,
|
||||
const uint32 command,
|
||||
const uint8* packet,
|
||||
const uint32 length)
|
||||
{
|
||||
if(context)
|
||||
{
|
||||
cSingleton<INetwork>::GetInstance()->Send(
|
||||
context,
|
||||
static_cast<uint16>(command),
|
||||
packet,
|
||||
static_cast<uint16>(length),
|
||||
FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
void SessionProc::Broadcast(
|
||||
const uint32 command,
|
||||
const uint8* packet,
|
||||
const uint32 length)
|
||||
{
|
||||
cSession* session = SessionProc::GetFirstSession();
|
||||
while(session)
|
||||
{
|
||||
SendPacket(
|
||||
session->GetContext(),
|
||||
command,
|
||||
packet,
|
||||
length);
|
||||
session = SessionProc::GetNextSession();
|
||||
}
|
||||
}
|
||||
|
||||
BOOL SessionProc::AddSession(IIocpContext* context)
|
||||
{
|
||||
cSession* session = g_sessionTable.Get(context->GetEntity());
|
||||
if(session) return FALSE;
|
||||
|
||||
// 세션정보 추가
|
||||
return g_sessionTable.Insert(context->GetEntity(), context);
|
||||
}
|
||||
|
||||
|
||||
BOOL SessionProc::DeleteSession(IIocpContext* context)
|
||||
{
|
||||
cSession* session = g_sessionTable.Get(context->GetEntity());
|
||||
if(session)
|
||||
{
|
||||
// 세션 종료시의 처리
|
||||
session->OnDisconnect();
|
||||
|
||||
// 세션 정보 삭제
|
||||
g_sessionTable.Remove(context->GetEntity());
|
||||
}
|
||||
|
||||
// 접속종료
|
||||
context->Disconnect();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
uint32 SessionProc::GetSessionCount()
|
||||
{
|
||||
return g_sessionTable.GetCount();
|
||||
}
|
||||
|
||||
cSession* SessionProc::GetSession(const uint32 entity)
|
||||
{
|
||||
return g_sessionTable.Get(entity);
|
||||
}
|
||||
|
||||
cSession* SessionProc::GetFirstSession()
|
||||
{
|
||||
return g_sessionTable.GetFirst();
|
||||
}
|
||||
|
||||
cSession* SessionProc::GetNextSession()
|
||||
{
|
||||
return g_sessionTable.GetNext();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "cSessionTable.h"
|
||||
|
||||
class IIocpContext;
|
||||
|
||||
class SessionProc
|
||||
{
|
||||
public:
|
||||
static void SendPacket(
|
||||
IIocpContext* context,
|
||||
const uint32 command,
|
||||
const uint8* packet,
|
||||
const uint32 length);
|
||||
|
||||
static void Broadcast(
|
||||
const uint32 command,
|
||||
const uint8* packet,
|
||||
const uint32 length);
|
||||
|
||||
public:
|
||||
static BOOL AddSession(IIocpContext* context);
|
||||
static BOOL DeleteSession(IIocpContext* context);
|
||||
|
||||
public:
|
||||
static uint32 GetSessionCount();
|
||||
|
||||
static cSession* GetSession(const uint32 entity);
|
||||
|
||||
static cSession* GetFirstSession();
|
||||
static cSession* GetNextSession();
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <SDKDDKVer.h>
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
#include <string>
|
||||
#include "../include/common.h"
|
||||
|
||||
extern void Trace( const TCHAR *format, ... );
|
||||
extern void Debug( const TCHAR *format, ... );
|
||||
extern void Information( const TCHAR *format, ... );
|
||||
extern void Debug();
|
||||
|
||||
namespace std { typedef std::basic_string<TCHAR> tstring; }
|
||||
@@ -0,0 +1,320 @@
|
||||
#include "StdAfx.h"
|
||||
#include "cService.h"
|
||||
#include "Utility.h"
|
||||
#include <iostream>
|
||||
#include <wtsapi32.h>
|
||||
#include <userenv.h>
|
||||
#include <tlhelp32.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
BOOL FindUserWindow(const TCHAR* title, DWORD& PID);
|
||||
|
||||
|
||||
// trace
|
||||
void Trace( const TCHAR *format, ... )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
TCHAR buffer[2048];
|
||||
va_list marker;
|
||||
|
||||
va_start( marker, format );
|
||||
_vstprintf_s( buffer, _countof(buffer), format, marker );
|
||||
va_end( marker );
|
||||
|
||||
OutputDebugString( buffer );
|
||||
#endif
|
||||
}
|
||||
|
||||
// console
|
||||
void Debug( const TCHAR *format, ... )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
static TCHAR buffer[2048];
|
||||
|
||||
va_list marker;
|
||||
va_start(marker, format);
|
||||
_vstprintf_s(buffer, _countof(buffer), format, marker);
|
||||
va_end(marker);
|
||||
|
||||
cService::_serviceMainClass->Debug(buffer);
|
||||
//wcout << buffer;
|
||||
#endif
|
||||
}
|
||||
|
||||
// console
|
||||
void Information( const TCHAR *format, ... )
|
||||
{
|
||||
static TCHAR buffer[2048];
|
||||
|
||||
va_list marker;
|
||||
va_start( marker, format );
|
||||
_vstprintf_s( buffer, _countof(buffer), format, marker );
|
||||
va_end( marker );
|
||||
|
||||
cService::_serviceMainClass->Debug(buffer);
|
||||
}
|
||||
|
||||
// last error
|
||||
void Debug()
|
||||
{
|
||||
DWORD dwError = WSAGetLastError();
|
||||
LPTSTR lpMsgBuf = NULL;
|
||||
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
dwError,
|
||||
0, // Default language
|
||||
(LPTSTR)&lpMsgBuf,
|
||||
0,
|
||||
NULL );
|
||||
|
||||
|
||||
#ifdef _UNICODE
|
||||
wcout << _T("WSAGetLastError[") << dwError << _T("] : ") << lpMsgBuf << endl << flush;
|
||||
#else
|
||||
cout << _T("WSAGetLastError[") << dwError << _T("] : ") << lpMsgBuf << endl << flush;
|
||||
#endif
|
||||
|
||||
|
||||
// Free the buffer.
|
||||
LocalFree( lpMsgBuf );
|
||||
}
|
||||
|
||||
void Tokenize(const std::tstring& str, TOKENS& tokens, const std::tstring& delimiters)
|
||||
{
|
||||
tokens.clear();
|
||||
|
||||
// 맨 첫 글자가 구분자인 경우 무시
|
||||
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
|
||||
|
||||
// 구분자가 아닌 첫 글자를 찾는다
|
||||
string::size_type pos = str.find_first_of(delimiters, lastPos);
|
||||
|
||||
while (string::npos != pos || string::npos != lastPos)
|
||||
{
|
||||
// token을 찾았으니 vector에 추가한다
|
||||
tokens.push_back(str.substr(lastPos, pos - lastPos));
|
||||
|
||||
// 구분자를 뛰어넘는다. "not_of"에 주의하라
|
||||
lastPos = str.find_first_not_of(delimiters, pos);
|
||||
|
||||
// 다음 구분자가 아닌 글자를 찾는다
|
||||
pos = str.find_first_of(delimiters, lastPos);
|
||||
}
|
||||
}
|
||||
|
||||
BOOL GetService(std::tstring& service, std::tstring& file, std::tstring& script)
|
||||
{
|
||||
HKEY key;
|
||||
LONG ret = RegOpenKeyEx(HKEY_CURRENT_USER, _T("software\\LostSaga"), 0, KEY_ALL_ACCESS, &key);
|
||||
if(ERROR_SUCCESS != ret) return FALSE;
|
||||
|
||||
DWORD size;
|
||||
FILETIME fileTime;
|
||||
TCHAR group[256], regFile[512], regScript[512];
|
||||
for(DWORD i = 0 ; i < 1000 ; i++)
|
||||
{
|
||||
size = _countof(group);
|
||||
|
||||
ret = RegEnumKeyEx(key, i, group, &size, NULL, NULL, NULL, &fileTime);
|
||||
if(ERROR_SUCCESS != ret) break;
|
||||
|
||||
if(service == group)
|
||||
{
|
||||
HKEY subkey;
|
||||
ret = RegOpenKeyEx(key, group, 0, KEY_ALL_ACCESS, &subkey);
|
||||
if(ERROR_SUCCESS != ret) break;
|
||||
|
||||
size = sizeof(regFile);
|
||||
if(RegQueryValueEx(subkey, _T("file"), NULL, NULL, (LPBYTE)regFile, &size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(subkey);
|
||||
RegCloseKey(key);
|
||||
return FALSE;
|
||||
}
|
||||
size = sizeof(regScript);
|
||||
if(RegQueryValueEx(subkey, _T("script"), NULL, NULL, (LPBYTE)regScript, &size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(subkey);
|
||||
RegCloseKey(key);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
file = regFile;
|
||||
script = regScript;
|
||||
RegCloseKey(subkey);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
RegCloseKey(key);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
BOOL GetServices(STRINGS& services, STRINGS& files, STRINGS& scripts)
|
||||
{
|
||||
services.clear();
|
||||
files.clear();
|
||||
scripts.clear();
|
||||
|
||||
HKEY key;
|
||||
LONG ret = RegOpenKeyEx(HKEY_CURRENT_USER, _T("software\\LostSaga"), 0, KEY_ALL_ACCESS, &key);
|
||||
if(ERROR_SUCCESS != ret)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DWORD size;
|
||||
FILETIME fileTime;
|
||||
TCHAR group[256], service[256], file[512], script[512];
|
||||
for(DWORD i = 0 ; i < 1000 ; i++)
|
||||
{
|
||||
size = _countof(group);
|
||||
|
||||
ret = RegEnumKeyEx(key, i, group, &size, NULL, NULL, NULL, &fileTime);
|
||||
if(ERROR_SUCCESS != ret) break;
|
||||
|
||||
//_stprintf_s(folder, sizeof(folder), "software\\LostSaga\\%s", group);
|
||||
|
||||
HKEY subkey;
|
||||
ret = RegOpenKeyEx(key, group, 0, KEY_ALL_ACCESS, &subkey);
|
||||
if(ERROR_SUCCESS != ret) break;
|
||||
|
||||
size = _countof(service);
|
||||
if(RegQueryValueEx(subkey, _T("service"), NULL, NULL, (LPBYTE)service, &size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(subkey);
|
||||
RegCloseKey(key);
|
||||
return TRUE;
|
||||
}
|
||||
size = _countof(file);
|
||||
if(RegQueryValueEx(subkey, _T("file"), NULL, NULL, (LPBYTE)file, &size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(subkey);
|
||||
RegCloseKey(key);
|
||||
return FALSE;
|
||||
}
|
||||
size = _countof(script);
|
||||
if(RegQueryValueEx(subkey, _T("script"), NULL, NULL, (LPBYTE)script, &size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(subkey);
|
||||
RegCloseKey(key);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
services.push_back(service);
|
||||
files.push_back(file);
|
||||
scripts.push_back(script);
|
||||
RegCloseKey(subkey);
|
||||
}
|
||||
RegCloseKey(key);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
BOOL IsService(const TCHAR* serviceName)
|
||||
{
|
||||
// 서비스 관리자 얻기
|
||||
SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
if(0 == schSCManager) return FALSE;
|
||||
|
||||
// 서비스 핸들 얻기
|
||||
SC_HANDLE schService = OpenService(schSCManager, serviceName, GENERIC_ALL);
|
||||
if(0 == schService) return FALSE;
|
||||
|
||||
// 서비스 상태얻기
|
||||
SERVICE_STATUS_PROCESS status;
|
||||
status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
||||
|
||||
DWORD bytesNeeded;
|
||||
BOOL result = QueryServiceStatusEx(
|
||||
schService,
|
||||
SC_STATUS_PROCESS_INFO,
|
||||
(LPBYTE)(&status),
|
||||
sizeof(status),
|
||||
&bytesNeeded);
|
||||
|
||||
CloseServiceHandle(schService);
|
||||
CloseServiceHandle(schSCManager);
|
||||
return result;
|
||||
}
|
||||
|
||||
BOOL CreateFolder(const TCHAR* path)
|
||||
{
|
||||
std::tstring folder = path;
|
||||
|
||||
TOKENS folders;
|
||||
Tokenize(folder, folders, _T("\\"));
|
||||
|
||||
if(folders.size() > 1 )
|
||||
{
|
||||
std::tstring temp = folders[0];
|
||||
for(uint32 i = 1; i < folders.size(); i++)
|
||||
{
|
||||
temp = temp + _T("\\") + folders[i];
|
||||
::CreateDirectory(temp.c_str(), NULL);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BOOL FindUserWindow(const TCHAR* title, DWORD& PID)
|
||||
{
|
||||
TCHAR text[512] = {0};
|
||||
|
||||
HANDLE hProcessSnap;
|
||||
PROCESSENTRY32 pe32; //프로세스정보를 저장할 구조체
|
||||
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
|
||||
|
||||
// Set the size of the structure before using it.
|
||||
pe32.dwSize = sizeof( PROCESSENTRY32 );
|
||||
|
||||
Process32First( hProcessSnap, &pe32 );
|
||||
printf( "\n Process ID = 0x%08X", pe32.th32ProcessID );
|
||||
printf( "\n Thread count = %d", pe32.cntThreads );
|
||||
printf( "\n Parent process ID = 0x%08X", pe32.th32ParentProcessID );
|
||||
printf( "\n Priority base = %d", pe32.pcPriClassBase );
|
||||
while(Process32Next( hProcessSnap, &pe32 ))
|
||||
{
|
||||
HANDLE hProcess = OpenProcess(PROCESS_VM_READ, FALSE, pe32.th32ProcessID);
|
||||
if(hProcess != NULL)
|
||||
{
|
||||
GetWindowText((HWND)hProcess, text, _countof(text));
|
||||
|
||||
wcout << "title : " << text << endl;;
|
||||
|
||||
if(0 == _tcscmp(title, text))
|
||||
{
|
||||
PID = pe32.th32ProcessID;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
//HWINSTA hWinsta = OpenWindowStation(_T("winsta0"), FALSE, WINSTA_ALL_ACCESS);
|
||||
|
||||
//// 데몬 서버 상태 얻기
|
||||
//HWND hWnd = FindWindow(NULL, title);
|
||||
//if(hWnd)
|
||||
//{
|
||||
// DWORD ret = GetWindowThreadProcessId(hWnd, &PID);
|
||||
|
||||
// CloseWindowStation(hWinsta);
|
||||
// return (ret != 0) ? TRUE : FALSE;
|
||||
//}
|
||||
|
||||
//CloseWindowStation(hWinsta);
|
||||
//return FALSE;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace std { typedef std::basic_string<TCHAR> tstring; }
|
||||
|
||||
typedef std::vector<std::tstring> TOKENS;
|
||||
typedef std::vector<std::tstring> STRINGS;
|
||||
@@ -0,0 +1,184 @@
|
||||
// cBuffer.cpp: implementation of the cBuffer class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "cBuffer.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cBuffer::cBuffer()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
cBuffer::cBuffer( uint32 uBuffLen )
|
||||
{
|
||||
Init();
|
||||
Create( uBuffLen );
|
||||
}
|
||||
|
||||
cBuffer::~cBuffer()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void cBuffer::Init()
|
||||
{
|
||||
m_pDT = NULL;
|
||||
m_unLen = 0;
|
||||
m_unMax = 0;
|
||||
}
|
||||
|
||||
void cBuffer::Destroy()
|
||||
{
|
||||
if( m_pDT )
|
||||
delete []m_pDT;
|
||||
|
||||
m_pDT = NULL;
|
||||
m_unLen = 0;
|
||||
m_unMax = 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Create/Erase
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool cBuffer::Create( uint32 uBuffLen )
|
||||
{
|
||||
if( m_pDT )
|
||||
Destroy();
|
||||
|
||||
m_pDT = new uint8[ uBuffLen ];
|
||||
if( m_pDT )
|
||||
{
|
||||
m_unLen = 0;
|
||||
m_unMax = uBuffLen;
|
||||
|
||||
Erase();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cBuffer::Erase()
|
||||
{
|
||||
if( m_pDT )
|
||||
{
|
||||
ZeroMemory( m_pDT, m_unLen );
|
||||
m_unLen = 0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void cBuffer::Resize( uint32 uBuffLen )
|
||||
{
|
||||
if(m_unMax < uBuffLen)
|
||||
{
|
||||
Create(uBuffLen);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Copy/Append
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool cBuffer::Copy( const TCHAR* pDT )
|
||||
{
|
||||
if( m_pDT )
|
||||
{
|
||||
uint32 unLen = _tcslen( pDT ) + 1;
|
||||
if( unLen <= m_unMax )
|
||||
{
|
||||
Erase();
|
||||
|
||||
m_unLen = unLen;
|
||||
CopyMemory( m_pDT, pDT, m_unLen );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cBuffer::Copy( uint32 unDst, const TCHAR* pDT )
|
||||
{
|
||||
if( m_pDT )
|
||||
{
|
||||
uint32 unLen = _tcslen( pDT ) + 1;
|
||||
if( (unDst+unLen) <= m_unMax )
|
||||
{
|
||||
CopyMemory( m_pDT+unDst, pDT, unLen );
|
||||
m_unLen = unDst + unLen;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cBuffer::Copy( const uint8* pDT, uint32 unLen )
|
||||
{
|
||||
if( m_pDT )
|
||||
{
|
||||
if( unLen <= m_unMax )
|
||||
{
|
||||
Erase();
|
||||
|
||||
m_unLen = unLen;
|
||||
CopyMemory( m_pDT, pDT, m_unLen );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cBuffer::Copy( uint32 unDst, const uint8* pDT, uint32 unLen )
|
||||
{
|
||||
if( m_pDT )
|
||||
{
|
||||
if( (unDst+unLen) <= m_unMax )
|
||||
{
|
||||
CopyMemory( m_pDT + unDst, pDT, unLen );
|
||||
m_unLen = unDst + unLen;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cBuffer::Append( const TCHAR* pDT )
|
||||
{
|
||||
if( m_pDT )
|
||||
{
|
||||
uint32 unLen = _tcslen( pDT ) + 1;
|
||||
if( (unLen+m_unLen) <= m_unMax )
|
||||
{
|
||||
CopyMemory( m_pDT+m_unLen, pDT, unLen );
|
||||
m_unLen += unLen;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool cBuffer::Append( const uint8* pDT, uint32 unLen )
|
||||
{
|
||||
if( m_pDT )
|
||||
{
|
||||
if( (unLen+m_unLen) <= m_unMax )
|
||||
{
|
||||
CopyMemory( m_pDT + m_unLen, pDT, unLen );
|
||||
m_unLen += unLen;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
// cBuffer.h: interface for the cBuffer class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_CBUFFER_H__ECE7A49E_767B_4F38_91CE_A4795B0F4535__INCLUDED_)
|
||||
#define AFX_CBUFFER_H__ECE7A49E_767B_4F38_91CE_A4795B0F4535__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
|
||||
class cBuffer
|
||||
{
|
||||
public:
|
||||
cBuffer();
|
||||
cBuffer( uint32 uBuffLen );
|
||||
virtual ~cBuffer();
|
||||
|
||||
void Init();
|
||||
void Destroy();
|
||||
|
||||
public:
|
||||
bool Create( uint32 uBuffLen );
|
||||
bool Erase();
|
||||
|
||||
void Resize( uint32 uBuffLen );
|
||||
|
||||
public:
|
||||
void SetLength( uint32 unLen ) { m_unLen = unLen; }
|
||||
|
||||
uint32 GetMaxLength() { return m_unMax; }
|
||||
uint32 GetLength() { return m_unLen; }
|
||||
uint8* GetBuffer() const { return m_pDT; }
|
||||
TCHAR* GetString() const { return reinterpret_cast<TCHAR*>(m_pDT); }
|
||||
|
||||
uint8* GetBuffer( uint32 unLen ) const { return (m_pDT+unLen); }
|
||||
|
||||
bool Copy( const TCHAR* pDT );
|
||||
bool Copy( uint32 unDst, const TCHAR* pDT );
|
||||
bool Copy( const uint8* pDT, uint32 unLen );
|
||||
bool Copy( uint32 unDst, const uint8* pDT, uint32 unLen );
|
||||
|
||||
bool Append( const TCHAR* pDT );
|
||||
bool Append( const uint8* pDT, uint32 unLen );
|
||||
|
||||
protected:
|
||||
uint8* m_pDT;
|
||||
uint32 m_unLen;
|
||||
uint32 m_unMax;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // !defined(AFX_CBUFFER_H__ECE7A49E_767B_4F38_91CE_A4795B0F4535__INCLUDED_)
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "StdAfx.h"
|
||||
#include "../include/IIocpContext.h"
|
||||
#include "cCommand.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Operation
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
BOOL cCommand::Run(IIocpContext* context, const uint8* buffer, const uint32 payload)
|
||||
{
|
||||
// 자신의 정보를 출력
|
||||
//Self();
|
||||
|
||||
if(Verify(context, const_cast<uint8*>(buffer), payload))
|
||||
{
|
||||
// 명령처리
|
||||
Run(context);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL cCommand::Run(const uint32 serverId, const uint8* buffer, const uint32 payload)
|
||||
{
|
||||
// 자신의 정보를 출력
|
||||
//Self();
|
||||
|
||||
if(Verify(const_cast<uint8*>(buffer), payload))
|
||||
{
|
||||
// 명령처리
|
||||
Run(serverId);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
class IIocpContext;
|
||||
|
||||
class cCommand
|
||||
{
|
||||
public:
|
||||
cCommand(void) {}
|
||||
~cCommand(void) {}
|
||||
|
||||
public:
|
||||
BOOL Run(IIocpContext* context, const uint8* buffer, const uint32 payload);
|
||||
BOOL Run(const uint32 serverId, const uint8* buffer, const uint32 payload);
|
||||
|
||||
protected:
|
||||
virtual BOOL Verify(IIocpContext* pContext, uint8* buffer, const uint32 length) { return TRUE; }
|
||||
virtual BOOL Verify(uint8* buffer, const uint32 length) { return TRUE; }
|
||||
|
||||
virtual void Self() {}
|
||||
virtual void Run(IIocpContext* context) {}
|
||||
virtual void Run(const uint32 serverId) {}
|
||||
};
|
||||
@@ -0,0 +1,72 @@
|
||||
// cCommandHandler.cpp
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "GameCommand.h"
|
||||
#include "InternalCommand.h"
|
||||
#include "cCommandHandler.h"
|
||||
#include "../common/Protocol.h"
|
||||
#include "../common/Internal.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cCommandHandler::cCommandHandler()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
cCommandHandler::~cCommandHandler()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void cCommandHandler::Init()
|
||||
{
|
||||
m_commandTable.resize(0xFFFF, NULL);
|
||||
LoadCommand();
|
||||
}
|
||||
|
||||
void cCommandHandler::Destroy()
|
||||
{
|
||||
COMMMANDTABLE::iterator it;
|
||||
for(it = m_commandTable.begin() ; it != m_commandTable.end() ; ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
m_commandTable.clear();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// operation
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
void cCommandHandler::LoadCommand()
|
||||
{
|
||||
InsertCommand(I_CONNECT, new IConnect);
|
||||
InsertCommand(I_CLOSE, new IClose);
|
||||
InsertCommand(I_PING, new IPing);
|
||||
InsertCommand(I_FLUSH, new IFlush);
|
||||
|
||||
InsertCommand(C_PING, new CPing);
|
||||
InsertCommand(C_SERVICES, new CServices);
|
||||
InsertCommand(C_TRANSFER, new CTransfer);
|
||||
InsertCommand(C_REMOVE, new CRemove);
|
||||
InsertCommand(C_INSTALL, new CInstall);
|
||||
InsertCommand(C_PLAY, new CPlay);
|
||||
InsertCommand(C_BACKUP, new CBackup);
|
||||
InsertCommand(C_REBOOT, new CReboot);
|
||||
InsertCommand(C_RESOURCE, new CResource);
|
||||
}
|
||||
|
||||
void cCommandHandler::InsertCommand(const uint32 commandId, cCommand* command)
|
||||
{
|
||||
COMMMANDTABLE::pointer ptr = &m_commandTable[commandId];
|
||||
*ptr = command;
|
||||
}
|
||||
|
||||
cCommand* cCommandHandler::Get(const uint32 commandId)
|
||||
{
|
||||
return (commandId < 0xFFFF) ? m_commandTable[commandId] : NULL;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
class cCommand;
|
||||
|
||||
class cCommandHandler
|
||||
{
|
||||
public:
|
||||
cCommandHandler();
|
||||
virtual ~cCommandHandler();
|
||||
|
||||
void Init();
|
||||
void Destroy();
|
||||
|
||||
protected:
|
||||
void LoadCommand();
|
||||
void InsertCommand(const uint32 commandId, cCommand* command);
|
||||
|
||||
public:
|
||||
cCommand* Get(const uint32 commandId);
|
||||
|
||||
protected:
|
||||
typedef std::vector<cCommand*> COMMMANDTABLE;
|
||||
COMMMANDTABLE m_commandTable;
|
||||
};
|
||||
@@ -0,0 +1,256 @@
|
||||
#include "StdAfx.h"
|
||||
#include "cDemonLauncher.h"
|
||||
#include <wtsapi32.h>
|
||||
#include <userenv.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern BOOL GetService(std::tstring& service, std::tstring& file, std::tstring& script);
|
||||
|
||||
|
||||
|
||||
cDemonLauncher g_demonLauncher;
|
||||
|
||||
cDemonLauncher::cDemonLauncher(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
cDemonLauncher::~cDemonLauncher(void)
|
||||
{
|
||||
}
|
||||
|
||||
BOOL cDemonLauncher::Play(const TCHAR* service, const BOOL console)
|
||||
{
|
||||
// 실행중인지 확인
|
||||
if(IsRunningService(service)) return FALSE;
|
||||
if(IsRunningConsole(service)) return FALSE;
|
||||
|
||||
std::tstring key = service;
|
||||
std::tstring m_file;
|
||||
std::tstring m_script;
|
||||
if(GetService(key, m_file, m_script))
|
||||
{
|
||||
if(console == FALSE)
|
||||
{
|
||||
TCHAR command[512];
|
||||
|
||||
_stprintf_s(command, _countof(command), _T("/c \"sc start %s %s %s.txt\""), service, m_script.c_str(), service);
|
||||
ShellExecute(NULL , NULL, _T("cmd.exe") , command, NULL, SW_HIDE);
|
||||
|
||||
Debug(_T("@Play : %s\r\n"), command);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
//TCHAR command[512];
|
||||
//TCHAR path[512]={0};
|
||||
//TCHAR tempPath[512]={0};
|
||||
//TCHAR drive[512]={0};
|
||||
//TCHAR exeFile[512]={0};
|
||||
//TCHAR tempExeFile[512]={0};
|
||||
//TCHAR luaFile[512]={0};
|
||||
//TCHAR tempLuaFile[512]={0};
|
||||
//TCHAR ext1[512]={0};
|
||||
//TCHAR ext2[512]={0};
|
||||
//TCHAR arguments[512]={0};
|
||||
|
||||
//_tsplitpath_s(m_file.c_str(), drive, tempPath, tempExeFile, ext1);
|
||||
////_tsplitpath_s(m_script.c_str(), drive, tempPath, tempLuaFile, ext2);
|
||||
|
||||
//_stprintf_s(path, _countof(path), _T("%s%s"), drive, tempPath);
|
||||
//_stprintf_s(exeFile, _countof(exeFile), _T("%s%s"), tempExeFile, ext1);
|
||||
////_stprintf_s(luaFile, _countof(luaFile), _T("%s%s"), tempLuaFile, ext2);
|
||||
|
||||
////_stprintf_s(command, _countof(command), _T("/c \"start \"%s\" /D%s %s -c %s\""), service, path, exeFile, luaFile);
|
||||
////ShellExecute(NULL , NULL, _T("cmd.exe") , command, path, SW_SHOW);
|
||||
|
||||
|
||||
//_stprintf_s(command, _countof(command), _T("%s\\%s"), path, exeFile);
|
||||
//_stprintf_s(arguments, _countof(arguments), _T(" -c"));
|
||||
////_stprintf_s(arguments, _countof(arguments), _T(" -c %s"), luaFile);
|
||||
|
||||
//CreateConsole(service, command, arguments);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL cDemonLauncher::Stop(const TCHAR* service, const BOOL console)
|
||||
{
|
||||
TCHAR command[512];
|
||||
//uint32 PID = GetPID(service);
|
||||
HANDLE hProcess = GetHandle(service);
|
||||
if( hProcess != 0 )
|
||||
{
|
||||
if(TerminateProcess(hProcess, 0))
|
||||
{
|
||||
RemovePI(service);
|
||||
}
|
||||
//_stprintf_s(command, _countof(command), _T("/c \"taskkill /PID %d\""), PID);
|
||||
//ShellExecute(NULL , NULL, _T("cmd.exe") , command, NULL, SW_HIDE);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
_stprintf_s(command, _countof(command), _T("/c \"sc stop %s\""), service);
|
||||
ShellExecute(NULL , NULL, _T("cmd.exe") , command, NULL, SW_HIDE);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL cDemonLauncher::CreateConsole(const TCHAR* title, TCHAR* command, TCHAR* arguments)
|
||||
{
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
|
||||
ZeroMemory(&si, sizeof(si));
|
||||
ZeroMemory(&pi, sizeof(pi));
|
||||
|
||||
//
|
||||
HANDLE hTokenNew = NULL, hTokenDup = NULL;
|
||||
WTSQueryUserToken(WTSGetActiveConsoleSessionId(), &hTokenNew);
|
||||
DuplicateTokenEx(hTokenNew,MAXIMUM_ALLOWED,NULL,SecurityIdentification,TokenPrimary,&hTokenDup);
|
||||
|
||||
LPVOID pEnv = NULL;
|
||||
if(!CreateEnvironmentBlock(&pEnv, hTokenDup, FALSE))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
//
|
||||
|
||||
ZeroMemory( &si, sizeof( STARTUPINFO ) );
|
||||
si.cb = sizeof( STARTUPINFO );
|
||||
si.lpDesktop = TEXT("winsta0\\default");
|
||||
si.dwFlags = STARTF_USESHOWWINDOW;
|
||||
si.wShowWindow = SW_SHOW ;
|
||||
si.lpTitle = const_cast<TCHAR*>(title); // (LPWSTR)
|
||||
|
||||
if(CreateProcessAsUser(hTokenDup, command, arguments, NULL, NULL, FALSE, CREATE_UNICODE_ENVIRONMENT |NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE, pEnv, NULL, &si, &pi))
|
||||
{
|
||||
SetPI(title, pi);
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
}
|
||||
|
||||
RevertToSelf();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void cDemonLauncher::SetPI(const TCHAR* service, PROCESS_INFORMATION& pi)
|
||||
{
|
||||
if(!IsRunningConsole(service))
|
||||
{
|
||||
m_demons[service] = pi;
|
||||
}
|
||||
}
|
||||
|
||||
void cDemonLauncher::RemovePI(const TCHAR* service)
|
||||
{
|
||||
PROCESS_TABLE::iterator it = m_demons.find(service);
|
||||
if(it != m_demons.end())
|
||||
{
|
||||
m_demons.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
uint32 cDemonLauncher::GetPID(const TCHAR* service)
|
||||
{
|
||||
PROCESS_TABLE::iterator it = m_demons.find(service);
|
||||
if(it != m_demons.end())
|
||||
{
|
||||
PROCESS_INFORMATION pi = it->second;
|
||||
return pi.dwProcessId;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
HANDLE cDemonLauncher::GetHandle(const TCHAR* service)
|
||||
{
|
||||
PROCESS_TABLE::iterator it = m_demons.find(service);
|
||||
if(it != m_demons.end())
|
||||
{
|
||||
PROCESS_INFORMATION pi = it->second;
|
||||
return pi.hProcess;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL cDemonLauncher::IsRunningConsole(const TCHAR* service)
|
||||
{
|
||||
PROCESS_TABLE::const_iterator it = m_demons.find(service);
|
||||
if(it != m_demons.end())
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL cDemonLauncher::IsRunningService(const TCHAR* service)
|
||||
{
|
||||
// 서비스 관리자 얻기
|
||||
SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
if(0 == schSCManager)
|
||||
{
|
||||
Debug(_T("IsRunning :: failed(%s)\n"), service);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// 서비스 핸들 얻기
|
||||
SC_HANDLE schService = OpenService(schSCManager, service, GENERIC_ALL);
|
||||
if(0 == schService)
|
||||
{
|
||||
Debug(_T("IsRunning :: failed(%s)\n"), service);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// 서비스 상태얻기
|
||||
SERVICE_STATUS_PROCESS status;
|
||||
status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
||||
|
||||
DWORD bytesNeeded;
|
||||
BOOL result = QueryServiceStatusEx(
|
||||
schService,
|
||||
SC_STATUS_PROCESS_INFO,
|
||||
(LPBYTE)(&status),
|
||||
sizeof(status),
|
||||
&bytesNeeded);
|
||||
|
||||
CloseServiceHandle(schService);
|
||||
CloseServiceHandle(schSCManager);
|
||||
|
||||
if(result)
|
||||
{
|
||||
switch(status.dwCurrentState)
|
||||
{
|
||||
case SERVICE_CONTINUE_PENDING :
|
||||
return FALSE;
|
||||
|
||||
case SERVICE_PAUSE_PENDING :
|
||||
return FALSE;
|
||||
|
||||
case SERVICE_PAUSED :
|
||||
return FALSE;
|
||||
|
||||
case SERVICE_RUNNING :
|
||||
return TRUE;
|
||||
|
||||
case SERVICE_START_PENDING :
|
||||
return TRUE;
|
||||
|
||||
case SERVICE_STOP_PENDING :
|
||||
return FALSE;
|
||||
|
||||
case SERVICE_STOPPED :
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
|
||||
class cDemonLauncher
|
||||
{
|
||||
public:
|
||||
cDemonLauncher(void);
|
||||
~cDemonLauncher(void);
|
||||
|
||||
public:
|
||||
BOOL Play(const TCHAR* service, const BOOL console);
|
||||
BOOL Stop(const TCHAR* service, const BOOL console);
|
||||
|
||||
BOOL CreateConsole(const TCHAR* title, TCHAR* command, TCHAR* arguments);
|
||||
|
||||
public:
|
||||
void SetPI(const TCHAR* service, PROCESS_INFORMATION& pi);
|
||||
void RemovePI(const TCHAR* service);
|
||||
|
||||
uint32 GetPID(const TCHAR* service);
|
||||
HANDLE GetHandle(const TCHAR* service);
|
||||
|
||||
BOOL IsRunningConsole(const TCHAR* service);
|
||||
BOOL IsRunningService(const TCHAR* service);
|
||||
|
||||
protected:
|
||||
typedef std::map<std::tstring,PROCESS_INFORMATION> PROCESS_TABLE;
|
||||
PROCESS_TABLE m_demons;
|
||||
};
|
||||
|
||||
extern cDemonLauncher g_demonLauncher;
|
||||
@@ -0,0 +1,22 @@
|
||||
// cEnvironment.cpp: implementation of the cEnvironment class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "cEnvironment.h"
|
||||
#include "../include/cSingleton.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
cEnvironment g_environment;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cEnvironment::cEnvironment() :
|
||||
m_maxSession(0),
|
||||
m_flushTime(0)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// cEnvironment.h: interface for the cEnvironment class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_CENVIRONMENT_H__299EC96C_7762_41C7_997D_35C16F4E94A9__INCLUDED_)
|
||||
#define AFX_CENVIRONMENT_H__299EC96C_7762_41C7_997D_35C16F4E94A9__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
|
||||
|
||||
const int PATH_MAXSIZE = 250;
|
||||
|
||||
class cEnvironment
|
||||
{
|
||||
public :
|
||||
cEnvironment();
|
||||
|
||||
public:
|
||||
const uint32 GetMaxSession() { return m_maxSession; }
|
||||
const uint32 GetFlushTime() { return m_flushTime; }
|
||||
|
||||
void SetMaxSession( uint32 sessionCount ) { m_maxSession = sessionCount; }
|
||||
void SetFlushTime( uint32 flushTime ) { m_flushTime = flushTime; }
|
||||
|
||||
private:
|
||||
uint32 m_maxSession;
|
||||
uint32 m_flushTime;
|
||||
};
|
||||
|
||||
extern cEnvironment g_environment;
|
||||
|
||||
#endif // !defined(AFX_CENVIRONMENT_H__299EC96C_7762_41C7_997D_35C16F4E94A9__INCLUDED_)
|
||||
@@ -0,0 +1,274 @@
|
||||
// cFile.cpp: implementation of the cFile class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "cFile.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cFile::cFile() : m_hFile(INVALID_HANDLE_VALUE), m_dwSizeLow(0), m_dwSizeHigh(0)
|
||||
{
|
||||
}
|
||||
|
||||
cFile::cFile(LPCTSTR fileName, DWORD dwMode, DWORD dwShareMode, DWORD dwCreationDisposition) : m_hFile(INVALID_HANDLE_VALUE), m_dwSizeLow(0), m_dwSizeHigh(0)
|
||||
{
|
||||
Open(fileName, dwMode, dwShareMode, dwCreationDisposition);
|
||||
}
|
||||
|
||||
cFile::~cFile()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// operation
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
BOOL cFile::Open(const TCHAR* fileName, DWORD dwMode, DWORD dwShareMode, DWORD dwCreationDisposition)
|
||||
{
|
||||
Close();
|
||||
|
||||
m_hFile = CreateFile( reinterpret_cast<LPCTSTR>(fileName),
|
||||
dwMode,
|
||||
dwShareMode,
|
||||
NULL,
|
||||
dwCreationDisposition,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL);
|
||||
|
||||
if(m_hFile == INVALID_HANDLE_VALUE) return FALSE;
|
||||
|
||||
return (m_hFile == INVALID_HANDLE_VALUE) ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
void cFile::Close()
|
||||
{
|
||||
if(m_hFile != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
CloseHandle(m_hFile);
|
||||
m_hFile = NULL;
|
||||
}
|
||||
|
||||
m_dwSizeLow = 0;
|
||||
m_dwSizeHigh = 0;
|
||||
}
|
||||
|
||||
BOOL cFile::Move(DWORD dwOrigin, LONG lOffset)
|
||||
{
|
||||
if(m_hFile != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD dwResult = SetFilePointer( m_hFile,
|
||||
lOffset,
|
||||
NULL,
|
||||
dwOrigin);
|
||||
return (dwResult == 0xFFFFFFFF) ? FALSE : TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DWORD cFile::GetFileSize()
|
||||
{
|
||||
if(m_dwSizeLow != 0)
|
||||
return m_dwSizeLow;
|
||||
|
||||
DWORD dwError = 0;
|
||||
if(m_hFile != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
m_dwSizeLow = ::GetFileSize(m_hFile, &m_dwSizeHigh);
|
||||
if((INVALID_FILE_SIZE == m_dwSizeLow) &&
|
||||
((dwError = GetLastError()) != NO_ERROR))
|
||||
return 0;
|
||||
}
|
||||
return m_dwSizeLow;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// cFileReader class
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cFileReader::cFileReader(const TCHAR* fileName) : m_nReadType(-1)
|
||||
{
|
||||
if(fileName != NULL)
|
||||
{
|
||||
Open(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
BOOL cFileReader::Open(const TCHAR* fileName)
|
||||
{
|
||||
if(cFile::Open(fileName, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING))
|
||||
{
|
||||
return (GetBOM() > 0) ? TRUE : FALSE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL cFileReader::Read(BYTE* buffer, const DWORD dwLength)
|
||||
{
|
||||
DWORD dwWritten = 0;
|
||||
if(m_hFile == INVALID_HANDLE_VALUE) return FALSE;
|
||||
|
||||
if(ReadFile( m_hFile,
|
||||
buffer,
|
||||
dwLength,
|
||||
&dwWritten,
|
||||
NULL))
|
||||
{
|
||||
if(dwLength == dwWritten) return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL cFileReader::Convert(const BYTE* bufferA, const int lengthA, BYTE* bufferB, const int lengthB)
|
||||
{
|
||||
switch(m_nReadType)
|
||||
{
|
||||
case FILEFORMAT_ANSI :
|
||||
CopyMemory(bufferB, bufferA, (lengthA > lengthB) ? lengthB : lengthA);
|
||||
return TRUE;
|
||||
|
||||
case FILEFORMAT_UNICODE_UTF8 :
|
||||
CopyMemory(bufferB, bufferA, (lengthA > lengthB) ? lengthB : lengthA);
|
||||
return TRUE;
|
||||
|
||||
case FILEFORMAT_UNICODE_LE :
|
||||
WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)bufferA, lengthA, (LPSTR)bufferB, lengthB, NULL, NULL);
|
||||
return TRUE;
|
||||
|
||||
case FILEFORMAT_UNICODE_BE :
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int cFileReader::GetBOM()
|
||||
{
|
||||
if((-1) == m_nReadType)
|
||||
{
|
||||
Move(FILE_BEGIN, 0);
|
||||
|
||||
WORD BOM = 0;
|
||||
if(Read(reinterpret_cast<BYTE*>(&BOM), sizeof(WORD)))
|
||||
{
|
||||
switch(BOM)
|
||||
{
|
||||
case 0xFEFF :
|
||||
m_nReadType = FILEFORMAT_UNICODE_LE;
|
||||
break;
|
||||
|
||||
case 0xFFFE :
|
||||
m_nReadType = 0; //FILEFORMAT_UNICODE_BE; not supported
|
||||
break;
|
||||
|
||||
case 0xBBEF :
|
||||
m_nReadType = FILEFORMAT_UNICODE_UTF8;
|
||||
Move(FILE_BEGIN, 3);
|
||||
break;
|
||||
|
||||
default:
|
||||
m_nReadType = FILEFORMAT_ANSI;
|
||||
Move(FILE_BEGIN, 0);
|
||||
break;
|
||||
}
|
||||
return m_nReadType;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return m_nReadType;
|
||||
}
|
||||
|
||||
DWORD cFileReader::GetFileSize()
|
||||
{
|
||||
if(0 == m_dwSizeLow)
|
||||
{
|
||||
cFile::GetFileSize();
|
||||
|
||||
switch(m_nReadType)
|
||||
{
|
||||
case FILEFORMAT_UNICODE_LE :
|
||||
case FILEFORMAT_UNICODE_BE :
|
||||
m_dwSizeLow -= (2);
|
||||
break;
|
||||
|
||||
case FILEFORMAT_UNICODE_UTF8 :
|
||||
m_dwSizeLow -= (3);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return m_dwSizeLow;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// cFileWriter class
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cFileWriter::cFileWriter(const TCHAR* fileName)
|
||||
{
|
||||
if(fileName != NULL)
|
||||
{
|
||||
Open(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
BOOL cFileWriter::Open(const TCHAR* fileName, DWORD diposition)
|
||||
{
|
||||
if(0 == diposition)
|
||||
{
|
||||
diposition = CREATE_NEW;
|
||||
}
|
||||
|
||||
if(cFile::Open(fileName, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, diposition))
|
||||
{
|
||||
//WriteHeader();
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL cFileWriter::Write(const BYTE* buffer, const DWORD dwLength)
|
||||
{
|
||||
if(dwLength == 0)
|
||||
return TRUE;
|
||||
|
||||
DWORD dwBytes = 0;
|
||||
if(WriteFile( m_hFile,
|
||||
buffer,
|
||||
dwLength,
|
||||
&dwBytes,
|
||||
NULL))
|
||||
{
|
||||
return (dwBytes == dwLength) ? TRUE : FALSE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL cFileWriter::WriteFormat(const TCHAR* format, ...)
|
||||
{
|
||||
TCHAR buffer[4096];
|
||||
|
||||
va_list marker;
|
||||
va_start(marker, format);
|
||||
_vstprintf_s(buffer, _countof(buffer), format, marker);
|
||||
va_end(marker);
|
||||
|
||||
return Write(reinterpret_cast<BYTE*>(buffer), (DWORD)(_tcslen(buffer)*sizeof(TCHAR)));
|
||||
}
|
||||
|
||||
void cFileWriter::WriteHeader()
|
||||
{
|
||||
#ifdef _UNICODE
|
||||
Move(FILE_BEGIN, 0);
|
||||
|
||||
WORD BOM = 0xFEFF;
|
||||
Write(reinterpret_cast<BYTE*>(&BOM), sizeof(BOM));
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
// cFile
|
||||
class cFile
|
||||
{
|
||||
public:
|
||||
cFile();
|
||||
cFile(LPCTSTR fileName, DWORD dwMode, DWORD dwShareMode, DWORD dwCreationDisposition);
|
||||
virtual ~cFile();
|
||||
|
||||
public:
|
||||
BOOL Open(const TCHAR* fileName, DWORD dwMode, DWORD dwShareMode, DWORD dwCreationDisposition);
|
||||
void Close();
|
||||
|
||||
BOOL Move(DWORD dwOrigin, LONG lOffset);
|
||||
virtual DWORD GetFileSize();
|
||||
|
||||
protected:
|
||||
enum SaveFileFormat
|
||||
{
|
||||
FILEFORMAT_ANSI = 1,
|
||||
FILEFORMAT_UNICODE_UTF8,
|
||||
FILEFORMAT_UNICODE_LE,
|
||||
FILEFORMAT_UNICODE_BE,
|
||||
};
|
||||
|
||||
HANDLE m_hFile;
|
||||
DWORD m_dwSizeLow, m_dwSizeHigh;
|
||||
};
|
||||
|
||||
// cFileReader
|
||||
class cFileReader : public cFile
|
||||
{
|
||||
public:
|
||||
cFileReader(const TCHAR* fileName=NULL);
|
||||
|
||||
public:
|
||||
BOOL Open(const TCHAR* fileName);
|
||||
|
||||
BOOL Read(BYTE* buffer, const DWORD dwLength);
|
||||
BOOL Convert(const BYTE* bufferA, const int lengthA, BYTE* bufferB, const int lengthB);
|
||||
|
||||
int GetBOM();
|
||||
|
||||
virtual DWORD GetFileSize();
|
||||
|
||||
private:
|
||||
int m_nReadType;
|
||||
};
|
||||
|
||||
// cFileWriter
|
||||
class cFileWriter : public cFile
|
||||
{
|
||||
public:
|
||||
cFileWriter(const TCHAR* fileName=NULL);
|
||||
|
||||
public:
|
||||
BOOL Open(const TCHAR* fileName, DWORD diposition=0);
|
||||
|
||||
BOOL Write(const BYTE* buffer, const DWORD dwLength);
|
||||
BOOL WriteFormat(const TCHAR* format, ...);
|
||||
|
||||
void WriteHeader();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
#include "stdafx.h"
|
||||
#include "cProcessor.h"
|
||||
#include "cEnvironment.h"
|
||||
#include "cScheduler.h"
|
||||
#include "cManager.h"
|
||||
#include "../include/Constant.h"
|
||||
#include "../include/ISystem.h"
|
||||
#include "../include/cSingleton.h"
|
||||
#include "../common/Internal.h"
|
||||
|
||||
cManager::cManager(void)
|
||||
{
|
||||
}
|
||||
|
||||
cManager::~cManager(void)
|
||||
{
|
||||
}
|
||||
|
||||
BOOL cManager::Init(const uint32 maxSession, const uint32 flush)
|
||||
{
|
||||
g_environment.SetMaxSession(maxSession);
|
||||
g_environment.SetFlushTime(flush);
|
||||
|
||||
cSingleton<ISystem>::GetInstance()->SetProcessor(cSingleton<cProcessor>::GetInstance());
|
||||
cSingleton<ISystem>::GetInstance()->SetEvent(I_CONNECT, I_CLOSE);
|
||||
|
||||
if(!cSingleton<ISystem>::GetInstance()->Startup(maxSession, 1024*51, 1000, 0))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL cManager::Listen(const uint16 port, const uint32 backlog)
|
||||
{
|
||||
if(!cSingleton<ISystem>::GetInstance()->Listen(port, backlog))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL cManager::Start(const uint32 worker, const uint32 commander)
|
||||
{
|
||||
if(!cSingleton<ISystem>::GetInstance()->Start(worker, commander, 0))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL cManager::Timer()
|
||||
{
|
||||
// sets the minimum timer resolution for an application or device driver.
|
||||
timeBeginPeriod(1);
|
||||
|
||||
g_scheduler.AddSchedule(I_PING, NULL, 0, 100000); // ping ÀÔ·Â
|
||||
g_scheduler.AddSchedule(I_FLUSH, NULL, 0, g_environment.GetFlushTime()); // flush out
|
||||
|
||||
cSchedule* schedule = NULL;
|
||||
while(TRUE)
|
||||
{
|
||||
if(g_scheduler.Begin())
|
||||
{
|
||||
while((schedule = g_scheduler.GetSchedule()))
|
||||
{
|
||||
cSingleton<ISystem>::GetInstance()->Call(
|
||||
schedule->GetCommand(),
|
||||
NULL,
|
||||
0);
|
||||
}
|
||||
|
||||
g_scheduler.End();
|
||||
}
|
||||
Sleep(33);
|
||||
}
|
||||
|
||||
// clears a previously set minimum timer resolution.
|
||||
timeEndPeriod(1);
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
class cManager
|
||||
{
|
||||
public:
|
||||
cManager();
|
||||
~cManager();
|
||||
|
||||
public:
|
||||
BOOL Init(const uint32 maxSession, const uint32 flush);
|
||||
BOOL Listen(const uint16 port, const uint32 backlog);
|
||||
BOOL Start(const uint32 worker, const uint32 commander);
|
||||
BOOL Timer();
|
||||
};
|
||||
@@ -0,0 +1,110 @@
|
||||
#include "stdafx.h"
|
||||
#include "cMiniDump.h"
|
||||
#include <TCHAR.h>
|
||||
#include <DBGHELP.h>
|
||||
|
||||
TCHAR cMiniDump::m_filename[MAX_PATH];
|
||||
TCHAR cMiniDump::m_folername[MAX_PATH];
|
||||
|
||||
typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)(
|
||||
HANDLE hProcess,
|
||||
DWORD dwPid,
|
||||
HANDLE hFile,
|
||||
MINIDUMP_TYPE DumpType,
|
||||
CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
|
||||
CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
|
||||
CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
|
||||
|
||||
|
||||
LPTOP_LEVEL_EXCEPTION_FILTER PreviousExceptionFilter = NULL;
|
||||
|
||||
|
||||
LONG WINAPI UnHandledExceptionFilter(struct _EXCEPTION_POINTERS *exceptionInfo)
|
||||
{
|
||||
HMODULE DllHandle = NULL;
|
||||
|
||||
// Windows 2000 이전에는 따로 DBGHELP를 배포해서 설정해 주어야 한다.
|
||||
DllHandle = LoadLibrary(_T("DBGHELP.DLL"));
|
||||
if (DllHandle)
|
||||
{
|
||||
MINIDUMPWRITEDUMP MiniDumpWriteDump = reinterpret_cast<MINIDUMPWRITEDUMP>(GetProcAddress(DllHandle, "MiniDumpWriteDump"));
|
||||
if (MiniDumpWriteDump)
|
||||
{
|
||||
TCHAR DumpPath[MAX_PATH] = {0};
|
||||
|
||||
SYSTEMTIME SystemTime;
|
||||
GetLocalTime(&SystemTime);
|
||||
|
||||
_stprintf_s(
|
||||
DumpPath,
|
||||
MAX_PATH-1,
|
||||
_T("%s\\%s(%04d%02d%02d-%02d%02d%02d).dmp"),
|
||||
cMiniDump::m_folername,
|
||||
cMiniDump::m_filename,
|
||||
SystemTime.wYear,
|
||||
SystemTime.wMonth,
|
||||
SystemTime.wDay,
|
||||
SystemTime.wHour,
|
||||
SystemTime.wMinute,
|
||||
SystemTime.wSecond);
|
||||
|
||||
HANDLE hDumpFile = CreateFile(
|
||||
DumpPath,
|
||||
GENERIC_WRITE,
|
||||
FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL);
|
||||
|
||||
if (hDumpFile != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
_MINIDUMP_EXCEPTION_INFORMATION ExceptionInfo;
|
||||
|
||||
ExceptionInfo.ThreadId = GetCurrentThreadId();
|
||||
ExceptionInfo.ExceptionPointers = exceptionInfo;
|
||||
ExceptionInfo.ClientPointers = NULL;
|
||||
|
||||
BOOL bSuccess = MiniDumpWriteDump(
|
||||
GetCurrentProcess(),
|
||||
GetCurrentProcessId(),
|
||||
hDumpFile,
|
||||
MiniDumpNormal,
|
||||
&ExceptionInfo,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
if (bSuccess)
|
||||
{
|
||||
CloseHandle(hDumpFile);
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
|
||||
CloseHandle(hDumpFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
||||
BOOL cMiniDump::Begin(const TCHAR* filename)
|
||||
{
|
||||
SetErrorMode(SEM_FAILCRITICALERRORS);
|
||||
|
||||
TCHAR temp[512];
|
||||
GetCurrentDirectory(_countof(temp), temp);
|
||||
_sntprintf_s(m_folername, sizeof(m_folername), _T("%s\\dump"), temp);
|
||||
CreateDirectory(m_folername, NULL);
|
||||
|
||||
_tcscpy_s(m_filename, 260, filename);
|
||||
|
||||
PreviousExceptionFilter = SetUnhandledExceptionFilter(UnHandledExceptionFilter);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL cMiniDump::End(VOID)
|
||||
{
|
||||
SetUnhandledExceptionFilter(PreviousExceptionFilter);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
class cMiniDump
|
||||
{
|
||||
public:
|
||||
static BOOL Begin(const TCHAR* filename);
|
||||
static BOOL End(VOID);
|
||||
|
||||
public:
|
||||
static TCHAR m_filename[MAX_PATH];
|
||||
static TCHAR m_folername[MAX_PATH];
|
||||
};
|
||||
@@ -0,0 +1,121 @@
|
||||
// cProcessor.cpp: implementation of the cProcessor class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "cCommand.h"
|
||||
#include "cCommandHandler.h"
|
||||
#include "SessionProc.h"
|
||||
#include "cProcessor.h"
|
||||
#include "../include/cSingleton.h"
|
||||
#include "../include/IIocpContext.h"
|
||||
#include "../include/INetwork.h"
|
||||
#include "../common/Internal.h"
|
||||
|
||||
//#define _USE_TRYEXCEPT 1
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cProcessor::cProcessor()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
cProcessor::~cProcessor()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void cProcessor::Init()
|
||||
{
|
||||
m_commandHandler = new cCommandHandler;
|
||||
}
|
||||
|
||||
void cProcessor::Destroy()
|
||||
{
|
||||
if(m_commandHandler)
|
||||
{
|
||||
delete m_commandHandler;
|
||||
m_commandHandler = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// operation
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
void cProcessor::Timeout()
|
||||
{
|
||||
cSession* session = SessionProc::GetFirstSession();
|
||||
while(session)
|
||||
{
|
||||
Flush(session->GetContext());
|
||||
session = SessionProc::GetNextSession();
|
||||
}
|
||||
}
|
||||
|
||||
void cProcessor::Process(IIocpContext* context, const uint32 commandId, const uint8* data, const uint32 length)
|
||||
{
|
||||
#ifdef _USE_TRYEXCEPT
|
||||
__try
|
||||
{
|
||||
#endif
|
||||
if(context && !context->IsActive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cCommand* pCommand = m_commandHandler->Get(commandId);
|
||||
if(pCommand)
|
||||
{
|
||||
pCommand->Run(context, data, length);
|
||||
//Flush(context);
|
||||
}
|
||||
else
|
||||
{
|
||||
pCommand = m_commandHandler->Get(I_CLOSE);
|
||||
if(pCommand)
|
||||
{
|
||||
pCommand->Run(context, data, length);
|
||||
}
|
||||
}
|
||||
#ifdef _USE_TRYEXCEPT
|
||||
}
|
||||
__except(1)
|
||||
{
|
||||
cout << _T("오류발생 클라이언트 Command :: ") << commandId << endl << flush;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void cProcessor::Process(const uint32 serverId, const uint32 commandId, const uint8* data, const uint32 length)
|
||||
{
|
||||
#ifdef _USE_TRYEXCEPT
|
||||
__try
|
||||
{
|
||||
#endif
|
||||
cCommand* pCommand = m_commandHandler->Get(commandId);
|
||||
if(pCommand)
|
||||
{
|
||||
pCommand->Run(serverId, data, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug(_T("-----> 내부 프로토콜 검색 실패 : ServerID(%lu), Command(%lu)!!"), serverId, commandId);
|
||||
}
|
||||
#ifdef _USE_TRYEXCEPT
|
||||
}
|
||||
__except(1)
|
||||
{
|
||||
cout << _T("오류발생 내부 Command :: ") << commandId << endl << flush;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void cProcessor::Flush(IIocpContext* context)
|
||||
{
|
||||
cSingleton<INetwork>::GetInstance()->Flush(context);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// cProcessor.h: interface for the cProcessor class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_CPROCESSOR_H__99EAE6C9_7E44_4B41_AD66_73D633AE4EA2__INCLUDED_)
|
||||
#define AFX_CPROCESSOR_H__99EAE6C9_7E44_4B41_AD66_73D633AE4EA2__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
|
||||
#include "../include/IProcessor.h"
|
||||
|
||||
|
||||
class cCommandHandler;
|
||||
|
||||
|
||||
class cProcessor : public IProcessor
|
||||
{
|
||||
public:
|
||||
cProcessor();
|
||||
virtual ~cProcessor();
|
||||
|
||||
void Init();
|
||||
void Destroy();
|
||||
|
||||
public:
|
||||
virtual void Timeout();
|
||||
virtual void Process(IIocpContext* context, const uint32 commandId, const uint8* data, const uint32 length);
|
||||
virtual void Process(const uint32 serverId, const uint32 commandId, const uint8* data, const uint32 length);
|
||||
|
||||
private:
|
||||
void Flush(IIocpContext* context);
|
||||
|
||||
private:
|
||||
cCommandHandler* m_commandHandler;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // !defined(AFX_CPROCESSOR_H__99EAE6C9_7E44_4B41_AD66_73D633AE4EA2__INCLUDED_)
|
||||
@@ -0,0 +1,71 @@
|
||||
#include "StdAfx.h"
|
||||
#include "cScheduler.h"
|
||||
|
||||
|
||||
cScheduler g_scheduler;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cScheduler::cScheduler() : m_current(0)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
cScheduler::~cScheduler(void)
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void cScheduler::Init()
|
||||
{
|
||||
}
|
||||
|
||||
void cScheduler::Destroy()
|
||||
{
|
||||
SCHEDULES::iterator it;
|
||||
for(it = m_schedules.begin() ; it != m_schedules.end() ; ++it)
|
||||
{
|
||||
delete (*it);
|
||||
}
|
||||
m_schedules.clear();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Operation
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
BOOL cScheduler::Begin()
|
||||
{
|
||||
m_iterator = m_schedules.begin();
|
||||
m_current = GetTickCount();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void cScheduler::End()
|
||||
{
|
||||
//Debug("cScheduler::End() ÃÑ ¼Ò¿ä½Ã°£ : %lu\n", GetTickCount()-m_current);
|
||||
}
|
||||
|
||||
BOOL cScheduler::AddSchedule(const uint32 command, const uint32 data, const uint32 size, const uint32 tick)
|
||||
{
|
||||
m_schedules.push_back(new cSchedule(command,data,size,tick));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
cSchedule* cScheduler::GetSchedule()
|
||||
{
|
||||
cSchedule* schedule = NULL;
|
||||
while(m_iterator != m_schedules.end())
|
||||
{
|
||||
schedule = (*m_iterator);
|
||||
++m_iterator;
|
||||
|
||||
if(schedule->IsTimeup(m_current))
|
||||
{
|
||||
return schedule;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
class cCommand;
|
||||
|
||||
class cSchedule
|
||||
{
|
||||
public:
|
||||
cSchedule(const uint32 command, const uint32 data, const uint32 size, const uint32 tick)
|
||||
: m_command(command), m_data(data), m_size(size), m_tick(tick), m_last(0)
|
||||
{}
|
||||
|
||||
BOOL IsTimeup(uint32 current)
|
||||
{
|
||||
if(m_tick == 0)
|
||||
return TRUE;
|
||||
|
||||
if((m_last == 0) || ((current - m_last) > m_tick))
|
||||
{
|
||||
m_last = current;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
uint32 GetCommand() { return m_command; }
|
||||
uint32 GetData() { return m_data; }
|
||||
uint32 GetSize() { return m_size; }
|
||||
|
||||
private:
|
||||
uint32 m_command;
|
||||
uint32 m_data;
|
||||
uint32 m_size;
|
||||
|
||||
uint32 m_tick;
|
||||
uint32 m_last;
|
||||
};
|
||||
|
||||
class cScheduler
|
||||
{
|
||||
public:
|
||||
cScheduler(void);
|
||||
~cScheduler(void);
|
||||
|
||||
void Init();
|
||||
void Destroy();
|
||||
|
||||
public:
|
||||
BOOL Begin();
|
||||
void End();
|
||||
|
||||
BOOL AddSchedule(const uint32 command, const uint32 data, const uint32 size, const uint32 tick);
|
||||
|
||||
cSchedule* GetSchedule();
|
||||
|
||||
private:
|
||||
typedef std::list<cSchedule*> SCHEDULES;
|
||||
|
||||
SCHEDULES m_schedules;
|
||||
SCHEDULES::iterator m_iterator;
|
||||
|
||||
uint32 m_current;
|
||||
};
|
||||
|
||||
extern cScheduler g_scheduler;
|
||||
@@ -0,0 +1,158 @@
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include "cBuffer.h"
|
||||
|
||||
|
||||
// ÃÖ´ë¹öÆÛ±æÀÌ
|
||||
const uint32 G_MAXSTORAGELENGTH = 1024 * 16;
|
||||
|
||||
class cSerialize
|
||||
{
|
||||
public:
|
||||
cSerialize(void)
|
||||
{
|
||||
m_storage.Create(G_MAXSTORAGELENGTH);
|
||||
}
|
||||
|
||||
public:
|
||||
void Reset()
|
||||
{
|
||||
m_storage.Erase();
|
||||
}
|
||||
|
||||
uint8* GetBuffer() { return m_storage.GetBuffer(); }
|
||||
uint32 GetLength() { return m_storage.GetLength(); }
|
||||
|
||||
public:
|
||||
void operator<<(const uint8 value) { m_storage.Append(reinterpret_cast<const uint8*>(&value), sizeof(value)); }
|
||||
void operator<<(const uint16 value) { m_storage.Append(reinterpret_cast<const uint8*>(&value), sizeof(value)); }
|
||||
void operator<<(const uint32 value) { m_storage.Append(reinterpret_cast<const uint8*>(&value), sizeof(value)); }
|
||||
void operator<<(const uint64 value) { m_storage.Append(reinterpret_cast<const uint8*>(&value), sizeof(value)); }
|
||||
void operator<<(const float value) { m_storage.Append(reinterpret_cast<const uint8*>(&value), sizeof(value)); }
|
||||
|
||||
public:
|
||||
void Write( const uint8 value ) { m_storage.Append( reinterpret_cast<const uint8*>(&value), sizeof(value) ); }
|
||||
void Write( const uint16 value ){ m_storage.Append( reinterpret_cast<const uint8*>(&value), sizeof(value) ); }
|
||||
void Write( const uint32 value ){ m_storage.Append( reinterpret_cast<const uint8*>(&value), sizeof(value) ); }
|
||||
void Write( const uint64 value ){ m_storage.Append( reinterpret_cast<const uint8*>(&value), sizeof(value) ); }
|
||||
void Write( const float value ) { m_storage.Append( reinterpret_cast<const uint8*>(&value), sizeof(value) ); }
|
||||
void Write( const uint8* value, uint32 length, BOOL saveLength = FALSE )
|
||||
{
|
||||
if( saveLength )
|
||||
Write( static_cast<uint16>(length) );
|
||||
m_storage.Append( value, length );
|
||||
}
|
||||
template<typename TD>
|
||||
void Write( std::vector<TD>& vcList, BOOL saveLength = TRUE )
|
||||
{
|
||||
if( saveLength )
|
||||
Write( static_cast<uint32>(vcList.size()) );
|
||||
|
||||
for( std::vector<TD>::iterator it = vcList.begin() ; it != vcList.end() ; ++it )
|
||||
{
|
||||
Write( *it );
|
||||
}
|
||||
}
|
||||
template<typename TD>
|
||||
void Write( std::list<TD>& vcList, BOOL saveLength = TRUE )
|
||||
{
|
||||
if( saveLength )
|
||||
Write( static_cast<uint32>(vcList.size()) );
|
||||
|
||||
for( std::list<TD>::iterator it = vcList.begin() ; it != vcList.end() ; ++it )
|
||||
{
|
||||
Write( *it );
|
||||
}
|
||||
}
|
||||
template<typename TD>
|
||||
void Read( const uint8* pBuffer, std::vector<TD>& vcList )
|
||||
{
|
||||
uint32 nLength = 0;
|
||||
CopyMemory( &nLength, pBuffer, sizeof(nLength) );
|
||||
|
||||
vcList.clear();
|
||||
vcList.reserve( nLength );
|
||||
|
||||
TD data;
|
||||
pBuffer += sizeof(nLength);
|
||||
for( uint32 i = 0 ; i < nLength ; i++ )
|
||||
{
|
||||
CopyMemory( &data, pBuffer+sizeof(TD)*i, sizeof(TD) );
|
||||
vcList.push_back( data );
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
void SetBuffer( uint8* pBuffer, uint32 maxLength )
|
||||
{
|
||||
m_temporary = pBuffer;
|
||||
m_maxLength = maxLength;
|
||||
m_offset = 0;
|
||||
}
|
||||
BOOL GetStringLength(uint16& length)
|
||||
{
|
||||
CopyMemory( &length, m_temporary+m_offset, sizeof(length) );
|
||||
m_offset += sizeof(uint16);
|
||||
return (m_offset <= m_maxLength) ? TRUE : FALSE;
|
||||
}
|
||||
BOOL GetUInt(uint8& data)
|
||||
{
|
||||
CopyMemory( &data, m_temporary+m_offset, sizeof(data) );
|
||||
m_offset += sizeof(data);
|
||||
return (m_offset <= m_maxLength) ? TRUE : FALSE;
|
||||
}
|
||||
BOOL GetUInt(uint16& data)
|
||||
{
|
||||
CopyMemory( &data, m_temporary+m_offset, sizeof(data) );
|
||||
m_offset += sizeof(data);
|
||||
return (m_offset <= m_maxLength) ? TRUE : FALSE;
|
||||
}
|
||||
BOOL GetUInt(uint32& data)
|
||||
{
|
||||
CopyMemory( &data, m_temporary+m_offset, sizeof(data) );
|
||||
m_offset += sizeof(data);
|
||||
return (m_offset <= m_maxLength) ? TRUE : FALSE;
|
||||
}
|
||||
BOOL GetUInt(uint64& data)
|
||||
{
|
||||
CopyMemory( &data, m_temporary+m_offset, sizeof(data) );
|
||||
m_offset += sizeof(data);
|
||||
return (m_offset <= m_maxLength) ? TRUE : FALSE;
|
||||
}
|
||||
BOOL GetFloat(float& data)
|
||||
{
|
||||
CopyMemory( &data, m_temporary+m_offset, sizeof(data) );
|
||||
m_offset += sizeof(data);
|
||||
return (m_offset <= m_maxLength) ? TRUE : FALSE;
|
||||
}
|
||||
BOOL GetString(const uint32 length, TCHAR* buffer, const uint32 size)
|
||||
{
|
||||
if( length < size )
|
||||
{
|
||||
CopyMemory( buffer, m_temporary+m_offset, length );
|
||||
buffer[length] = NULL;
|
||||
m_offset += length;
|
||||
return (m_offset <= m_maxLength) ? TRUE : FALSE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
/*
|
||||
const BOOL operator>>(uint8& data)
|
||||
{
|
||||
CopyMemory( &data, m_temporary+m_offset, sizeof(data) );
|
||||
m_offset += sizeof(data);
|
||||
return (m_offset <= m_maxLength) ? TRUE : FALSE;
|
||||
}
|
||||
*/
|
||||
const uint8* GetExtra() { return (m_offset <= m_maxLength) ? (m_temporary + m_offset) : NULL; }
|
||||
const uint32 GetExtraLength() { return (m_offset <= m_maxLength) ? (m_maxLength - m_offset) : 0; }
|
||||
|
||||
private:
|
||||
uint8* m_temporary;
|
||||
uint32 m_offset, m_maxLength;
|
||||
|
||||
cBuffer m_storage;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
#include "stdafx.h"
|
||||
#include "cService.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
cService* cService::_serviceMainClass = NULL;
|
||||
|
||||
cService::cService(int argc, TCHAR **argv)
|
||||
{
|
||||
_serviceMainClass = this;
|
||||
|
||||
m_serviceName = _T("");
|
||||
m_displayName = _T("");
|
||||
|
||||
m_arguments.clear();
|
||||
m_arguments.reserve(argc + 1);
|
||||
for(int i = 1 ; i < argc ; i++)
|
||||
{
|
||||
m_arguments.push_back(argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
cService::~cService()
|
||||
{
|
||||
}
|
||||
|
||||
void cService::ServiceMainProc()
|
||||
{
|
||||
if(m_arguments.size() > 0)
|
||||
{
|
||||
if(m_arguments[0] == _T("-i"))
|
||||
{
|
||||
if(m_arguments.size() < 3) return;
|
||||
|
||||
// -i serviceName displayName
|
||||
Debug(_T("service : install\n"));
|
||||
|
||||
m_serviceName = m_arguments[1];
|
||||
m_displayName = m_arguments[2];
|
||||
|
||||
if(Install(m_serviceName.c_str(), m_displayName.c_str()))
|
||||
{
|
||||
Debug(_T("service installed\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug(_T("service install failed\n"));
|
||||
}
|
||||
}
|
||||
else if(m_arguments[0] == _T("-u"))
|
||||
{
|
||||
if(m_arguments.size() < 2) return;
|
||||
|
||||
// -u serviceName
|
||||
Debug(_T("service : uninstall\n"));
|
||||
|
||||
m_serviceName = m_arguments[1];
|
||||
|
||||
if(Uninstall(m_serviceName.c_str()))
|
||||
{
|
||||
Debug(_T("service uninstalled\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug(_T("service uninstall failed\n"));
|
||||
}
|
||||
}
|
||||
else if(m_arguments[0] == _T("-c"))
|
||||
{
|
||||
if(m_arguments.size() < 1) return;
|
||||
|
||||
// -c
|
||||
Debug(_T("service : console\n"));
|
||||
|
||||
ServiceStart();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug(_T("USAGE : \n"));
|
||||
Debug(_T(" -i [service name] [display name]\n"));
|
||||
Debug(_T(" -u [service name]\n"));
|
||||
Debug(_T(" -c [lua file]\n"));
|
||||
Debug(_T(" [lua file] [log file]\n\n"));
|
||||
Debug(_T(" i------------Creates a service\n"));
|
||||
Debug(_T(" u------------Deletes a service\n"));
|
||||
Debug(_T(" c------------Run as console\n"));
|
||||
Debug(_T(" ------------Run as service\n"));
|
||||
Debug(_T("EXAMPLE : \n"));
|
||||
Debug(_T(" -i rod-service \"R.O.D game service\"\n"));
|
||||
Debug(_T(" -c lua-file.lua\n"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_ExecuteProcess();
|
||||
}
|
||||
}
|
||||
|
||||
void WINAPI cService::_ServiceMain(int argc, TCHAR **argv)
|
||||
{
|
||||
if (_serviceMainClass != NULL)
|
||||
{
|
||||
_serviceMainClass->ServiceMain(argc, argv);
|
||||
}
|
||||
}
|
||||
|
||||
void cService::ServiceMain(int argc, TCHAR **argv)
|
||||
{
|
||||
m_hServiceStatusHandle = RegisterServiceCtrlHandler(m_serviceName.c_str(), _ServiceHandler);
|
||||
if(0 == m_hServiceStatusHandle)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_arguments.clear();
|
||||
m_arguments.reserve(argc + 1);
|
||||
m_arguments.push_back(_T(""));
|
||||
for(int i = 1 ; i < argc ; i++)
|
||||
{
|
||||
m_arguments.push_back(argv[i]);
|
||||
}
|
||||
|
||||
// Initialization complete - report running status
|
||||
m_serviceStatus.dwServiceType = SERVICE_WIN32;
|
||||
m_serviceStatus.dwCurrentState = SERVICE_START_PENDING;
|
||||
m_serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
|
||||
m_serviceStatus.dwWin32ExitCode = NO_ERROR;
|
||||
m_serviceStatus.dwServiceSpecificExitCode = 0;
|
||||
m_serviceStatus.dwCheckPoint = 0;
|
||||
m_serviceStatus.dwWaitHint = 0;
|
||||
m_serviceStatus.dwCheckPoint = 0;
|
||||
m_serviceStatus.dwWaitHint = 0;
|
||||
m_serviceStatus.dwCurrentState = SERVICE_RUNNING;
|
||||
|
||||
SetServiceStatus(m_hServiceStatusHandle, &m_serviceStatus);
|
||||
|
||||
if(!ServiceStart())
|
||||
{
|
||||
m_serviceStatus.dwCurrentState = SERVICE_STOPPED;
|
||||
SetServiceStatus(m_hServiceStatusHandle, &m_serviceStatus);
|
||||
}
|
||||
}
|
||||
|
||||
BOOL cService::Install(const TCHAR* serviceName, const TCHAR* displayName)
|
||||
{
|
||||
// 실행 파일 경로
|
||||
TCHAR serviceDemon[MAX_PATH+1];
|
||||
DWORD size = GetModuleFileName(NULL, serviceDemon, MAX_PATH);
|
||||
serviceDemon[size] = 0;
|
||||
|
||||
SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
|
||||
if(0 == schSCManager) return FALSE;
|
||||
|
||||
SC_HANDLE schService = CreateService(
|
||||
schSCManager,
|
||||
serviceName,
|
||||
displayName,
|
||||
SERVICE_ALL_ACCESS,
|
||||
SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
|
||||
SERVICE_AUTO_START,
|
||||
SERVICE_ERROR_NORMAL,
|
||||
serviceDemon,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
if(0 == schService) return FALSE;
|
||||
|
||||
CloseServiceHandle(schService);
|
||||
CloseServiceHandle(schSCManager);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL cService::Uninstall(const TCHAR* serviceName)
|
||||
{
|
||||
// 서비스 관리자 얻기
|
||||
SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
if(0 == schSCManager) return FALSE;
|
||||
|
||||
// 서비스 핸들 얻기
|
||||
SC_HANDLE schService = OpenService(schSCManager, serviceName, DELETE);
|
||||
if(0 == schService) return FALSE;
|
||||
|
||||
// 서비스 삭제
|
||||
if(!DeleteService(schService))
|
||||
{
|
||||
CloseServiceHandle(schService);
|
||||
CloseServiceHandle(schSCManager);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CloseServiceHandle(schService);
|
||||
CloseServiceHandle(schSCManager);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL cService::KillService(const TCHAR* serviceName)
|
||||
{
|
||||
// 서비스 관리자 얻기
|
||||
SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
if(0 == schSCManager) return FALSE;
|
||||
|
||||
// 서비스 핸들 얻기
|
||||
SC_HANDLE schService = OpenService(schSCManager, serviceName, SERVICE_STOP);
|
||||
if(0 == schService) return FALSE;
|
||||
|
||||
// 서비스 중지
|
||||
SERVICE_STATUS status;
|
||||
if(!ControlService(schService, SERVICE_CONTROL_STOP, &status))
|
||||
{
|
||||
CloseServiceHandle(schService);
|
||||
CloseServiceHandle(schSCManager);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CloseServiceHandle(schService);
|
||||
CloseServiceHandle(schSCManager);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL cService::RunService(const TCHAR* serviceName)
|
||||
{
|
||||
// 서비스 관리자 얻기
|
||||
SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
if(0 == schSCManager) return FALSE;
|
||||
|
||||
// 서비스 핸들 얻기
|
||||
SC_HANDLE schService = OpenService(schSCManager, serviceName, SERVICE_START);
|
||||
if(0 == schService) return FALSE;
|
||||
|
||||
// 서비스 시작
|
||||
if(!StartService(schService, 0, 0))
|
||||
{
|
||||
CloseServiceHandle(schService);
|
||||
CloseServiceHandle(schSCManager);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CloseServiceHandle(schService);
|
||||
CloseServiceHandle(schSCManager);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void WINAPI cService::_ServiceHandler(DWORD fdwControl)
|
||||
{
|
||||
if(_serviceMainClass != NULL)
|
||||
{
|
||||
_serviceMainClass->ServiceHandler(fdwControl);
|
||||
}
|
||||
}
|
||||
|
||||
void cService::ServiceHandler(DWORD fdwControl)
|
||||
{
|
||||
switch(fdwControl)
|
||||
{
|
||||
case SERVICE_CONTROL_STOP:
|
||||
case SERVICE_CONTROL_SHUTDOWN:
|
||||
m_serviceStatus.dwWin32ExitCode = 0;
|
||||
m_serviceStatus.dwCurrentState = SERVICE_STOPPED;
|
||||
m_serviceStatus.dwCheckPoint = 0;
|
||||
m_serviceStatus.dwWaitHint = 0;
|
||||
|
||||
ServiceStop();
|
||||
break;
|
||||
|
||||
case SERVICE_CONTROL_PAUSE:
|
||||
m_serviceStatus.dwCurrentState = SERVICE_PAUSED;
|
||||
break;
|
||||
|
||||
default:
|
||||
m_serviceStatus.dwCurrentState = SERVICE_RUNNING;
|
||||
};
|
||||
|
||||
SetServiceStatus(m_hServiceStatusHandle, &m_serviceStatus);
|
||||
}
|
||||
|
||||
BOOL cService::_ExecuteProcess()
|
||||
{
|
||||
SERVICE_TABLE_ENTRY dipatchTable[] =
|
||||
{
|
||||
{const_cast<LPTSTR>(m_serviceName.c_str()), reinterpret_cast<LPSERVICE_MAIN_FUNCTION>(_ServiceMain)},
|
||||
{NULL , NULL}
|
||||
};
|
||||
|
||||
StartServiceCtrlDispatcher(dipatchTable);
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
class cService
|
||||
{
|
||||
public:
|
||||
cService(int argc, TCHAR **argv);
|
||||
virtual ~cService();
|
||||
|
||||
public:
|
||||
void ServiceMainProc(); // 서비스 실행 메인 함수
|
||||
|
||||
static cService* _serviceMainClass;
|
||||
static void WINAPI _ServiceMain(int argc, TCHAR **argv); // 서비스 메인 함수(ServiceMain()함수를 호출)
|
||||
static void WINAPI _ServiceHandler(DWORD fdwControl); // 서비스 제어 메인 함수(ServiceHandler()함수를 호출)
|
||||
|
||||
void ServiceMain(int argc, TCHAR **argv); // 서비스 메인의 구현부
|
||||
void ServiceHandler(DWORD fdwControl); // 서비스 제어의 구현부
|
||||
|
||||
public:
|
||||
virtual BOOL ExecuteProcess() = 0; // 서비스 실행시에 호출되는 함수
|
||||
virtual BOOL ServiceStart() = 0; // 서비스 실행(START)시에 호출됨
|
||||
virtual void ServiceStop() = 0; // 서비스 중지(STOP)시에 호출됨
|
||||
|
||||
virtual void Debug(const TCHAR *message) = 0; // 디버깅용 메세지 출력
|
||||
|
||||
protected:
|
||||
BOOL _ExecuteProcess(); // 서비스의 실행시 호출됨
|
||||
|
||||
// Service Control
|
||||
BOOL Install(const TCHAR* serviceName, const TCHAR* displayName); // 서비스 등록
|
||||
BOOL Uninstall(const TCHAR* serviceName); // 서비스 제거
|
||||
BOOL RunService(const TCHAR* serviceName); // 서비스 실행(START)
|
||||
BOOL KillService(const TCHAR* serviceName); // 서비스 중지(STOP)
|
||||
|
||||
protected:
|
||||
std::vector<std::tstring> m_arguments;
|
||||
std::tstring m_serviceName;
|
||||
std::tstring m_displayName;
|
||||
|
||||
SERVICE_STATUS_HANDLE m_hServiceStatusHandle;
|
||||
SERVICE_STATUS m_serviceStatus;
|
||||
};
|
||||
@@ -0,0 +1,174 @@
|
||||
#include "stdafx.h"
|
||||
#include "cFile.h"
|
||||
#include "cManager.h"
|
||||
#include "cMiniDump.h"
|
||||
#include "cServiceLS.h"
|
||||
#include "../include/cSingleton.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void DisplayHeapInfo(HANDLE heap)
|
||||
{
|
||||
ULONG heapInfo;
|
||||
SIZE_T size;
|
||||
|
||||
if(HeapQueryInformation(
|
||||
heap,
|
||||
HeapCompatibilityInformation,
|
||||
&heapInfo,
|
||||
sizeof(heapInfo),
|
||||
&size) == FALSE)
|
||||
{
|
||||
Debug();
|
||||
}
|
||||
else
|
||||
{
|
||||
//Information(_T("Handle: %X, HeapInfo: %d\n", heap, heapInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void SetHeapInformation()
|
||||
{
|
||||
HANDLE heaps[1025];
|
||||
BOOL results[1025];
|
||||
|
||||
ZeroMemory(heaps, sizeof(heaps));
|
||||
ZeroMemory(results, sizeof(results));
|
||||
|
||||
ULONG HeapFragValue = 2;
|
||||
|
||||
DWORD count = GetProcessHeaps(1024, heaps);
|
||||
for(DWORD i = 0; i < count; i++)
|
||||
{
|
||||
results[i] = HeapSetInformation(
|
||||
heaps[i],
|
||||
HeapCompatibilityInformation,
|
||||
&HeapFragValue,
|
||||
sizeof(HeapFragValue));
|
||||
if(!results[i])
|
||||
{
|
||||
DisplayHeapInfo(heaps[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetCurrentModulePath()
|
||||
{
|
||||
TCHAR temp[MAX_PATH+1];
|
||||
GetModuleFileName(NULL, temp, MAX_PATH);
|
||||
|
||||
TCHAR* token = _tcsrchr(temp, _T('\\'));
|
||||
*(token+1) = _T('\0');
|
||||
SetCurrentDirectory(temp);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cServiceLS::cServiceLS(int argc, TCHAR **argv) : cService(argc, argv)
|
||||
{
|
||||
}
|
||||
|
||||
cServiceLS::~cServiceLS()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
BOOL cServiceLS::ExecuteProcess()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void cServiceLS::ServiceStop()
|
||||
{
|
||||
Debug(_T("service stopped\r\n"));
|
||||
cMiniDump::End();
|
||||
}
|
||||
|
||||
BOOL cServiceLS::ServiceStart()
|
||||
{
|
||||
ConfigureSystem();
|
||||
|
||||
cMiniDump::Begin(_T("lostsaga-controller"));
|
||||
|
||||
m_logFile = _T("lostsaga-controller.txt");
|
||||
|
||||
Debug(_T("----------------------------------------------------\r\n"));
|
||||
Debug(_T("-- start lostsaga-controller\r\n"));
|
||||
Debug(_T("----------------------------------------------------\r\n"));
|
||||
|
||||
if(!cSingleton<cManager>::GetInstance()->Init(10, 80))
|
||||
{
|
||||
TCHAR error[512];
|
||||
wsprintf( error, _T("ls_controller Init failed(%lu)\r\n"), GetLastError());
|
||||
Debug(error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(!cSingleton<cManager>::GetInstance()->Listen(24444, 10))
|
||||
{
|
||||
TCHAR error[512];
|
||||
wsprintf( error, _T("ls_controller Listen failed(%lu)\r\n"), GetLastError());
|
||||
Debug(error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(!cSingleton<cManager>::GetInstance()->Start(2, 1))
|
||||
{
|
||||
TCHAR error[512];
|
||||
wsprintf( error, _T("ls_controller Start failed(%lu)\r\n"), GetLastError());
|
||||
Debug(error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Debug(_T("service start - success\r\n"));
|
||||
cSingleton<cManager>::GetInstance()->Timer();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void cServiceLS::Debug(const TCHAR *message)
|
||||
{
|
||||
if(0 == m_logFile.size())
|
||||
{
|
||||
#ifdef _UNICODE
|
||||
wcout << message;
|
||||
#else
|
||||
cout << message;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
SYSTEMTIME systime;
|
||||
GetLocalTime(&systime);
|
||||
|
||||
TCHAR currentTime[256];
|
||||
_stprintf_s(
|
||||
currentTime,
|
||||
sizeof(currentTime),
|
||||
"[%04d-%02d-%02d %02d:%02d:%02d]",
|
||||
systime.wYear,
|
||||
systime.wMonth,
|
||||
systime.wDay,
|
||||
systime.wHour,
|
||||
systime.wMinute,
|
||||
systime.wSecond);
|
||||
*/
|
||||
cFileWriter file;
|
||||
if(file.Open(GetLogFile(), OPEN_ALWAYS))
|
||||
{
|
||||
uint32 length = (_tcslen(message))*sizeof(TCHAR);
|
||||
file.Move(FILE_BEGIN, file.GetFileSize());
|
||||
file.Write(reinterpret_cast<const BYTE*>(message), length);
|
||||
file.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cServiceLS::ConfigureSystem()
|
||||
{
|
||||
SetHeapInformation();
|
||||
SetCurrentModulePath();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "cService.h"
|
||||
|
||||
|
||||
class cServiceLS : public cService
|
||||
{
|
||||
public:
|
||||
cServiceLS(int argc, TCHAR **argv);
|
||||
virtual ~cServiceLS();
|
||||
|
||||
public:
|
||||
virtual BOOL ExecuteProcess(); // 서비스 실행시에 호출되는 함수(사용자 정의)
|
||||
virtual BOOL ServiceStart(); // 서비스 실행(START)시에 호출됨
|
||||
virtual void ServiceStop(); // 서비스 중지(STOP)시에 호출됨
|
||||
|
||||
virtual void Debug(const TCHAR *message); // 디버깅용 메세지 출력
|
||||
|
||||
protected:
|
||||
void ConfigureSystem();
|
||||
|
||||
const TCHAR* GetLogFile() { return m_logFile.c_str(); } // 서비스 로그가 남을 파일
|
||||
|
||||
protected:
|
||||
std::tstring m_luaFile;
|
||||
std::tstring m_logFile;
|
||||
};
|
||||
@@ -0,0 +1,80 @@
|
||||
#include "stdafx.h"
|
||||
#include "cSession.h"
|
||||
#include "../include/IIocpContext.h"
|
||||
|
||||
|
||||
void tinet_ntoa(uint32 IP, TCHAR* buffer)
|
||||
{
|
||||
SOCKADDR_IN sockAddr;
|
||||
sockAddr.sin_addr.s_addr = IP;
|
||||
|
||||
#ifdef UNICODE
|
||||
char szIP[16];
|
||||
strcpy_s(szIP, sizeof(szIP), inet_ntoa(sockAddr.sin_addr));
|
||||
|
||||
uint32 length = MultiByteToWideChar(CP_ACP, 0, szIP, sizeof(szIP)-1, NULL, NULL);
|
||||
MultiByteToWideChar(CP_ACP, 0, szIP, sizeof(szIP)-1, buffer, length);
|
||||
buffer[length] = NULL;
|
||||
#else
|
||||
strcpy_s(buffer, sizeof(buffer), inet_ntoa(sockAddr.sin_addr));
|
||||
#endif
|
||||
}
|
||||
|
||||
void cSession::OnConnect()
|
||||
{
|
||||
TCHAR szIP[64];
|
||||
tinet_ntoa(GetContext()->GetIP(), szIP);
|
||||
|
||||
TransferEnd();
|
||||
Debug(_T("@¼ÒÄÏ Á¢¼Ó(%s)\n"), szIP);
|
||||
}
|
||||
|
||||
void cSession::OnDisconnect()
|
||||
{
|
||||
TransferEnd();
|
||||
Debug(_T("@¼ÒÄÏ Á¢¼ÓÇØÁ¦\n"));
|
||||
}
|
||||
|
||||
BOOL cSession::TransferBegin(const TCHAR* file, const uint32 length)
|
||||
{
|
||||
if(!m_transfer)
|
||||
{
|
||||
m_transfer = TRUE;
|
||||
if(length > G_MAXFILESIZE)
|
||||
m_buffer.Resize(G_MAXFILESIZE*2);
|
||||
else
|
||||
m_buffer.Resize(length);
|
||||
|
||||
m_transferLength = 0;
|
||||
ZeroMemory(m_file, sizeof(m_file));
|
||||
CopyMemory(m_file, file, sizeof(m_file));
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL cSession::TransferDo(const uint8* buffer, const uint32 length)
|
||||
{
|
||||
if(m_transfer)
|
||||
{
|
||||
m_transferLength += length;
|
||||
return m_buffer.Append(buffer, length);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void cSession::TransferWrite()
|
||||
{
|
||||
if(m_transfer)
|
||||
{
|
||||
m_buffer.Erase();
|
||||
}
|
||||
}
|
||||
|
||||
void cSession::TransferEnd()
|
||||
{
|
||||
m_transfer = FALSE;
|
||||
m_buffer.Erase();
|
||||
ZeroMemory(m_file, sizeof(m_file));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
#include "cBuffer.h"
|
||||
#include "../common/Protocol.h"
|
||||
#include "../include/BoostPooler.h"
|
||||
|
||||
class IIocpContext;
|
||||
|
||||
// 技记鸥涝
|
||||
enum SessionTypes
|
||||
{
|
||||
SESSION_NORMAL = 0,
|
||||
SESSION_LOGIN,
|
||||
SESSION_PLAYER,
|
||||
SESSION_SERVER,
|
||||
SESSION_OPERATOR,
|
||||
};
|
||||
|
||||
// 技记牢磐其捞胶
|
||||
class ISession
|
||||
{
|
||||
public:
|
||||
ISession(void) : m_sessionType(SESSION_NORMAL), m_context(NULL)
|
||||
{}
|
||||
|
||||
public:
|
||||
void SetType(const SessionTypes type) { m_sessionType = type; }
|
||||
void SetContext(IIocpContext* context) { m_context = context; }
|
||||
|
||||
SessionTypes GetType() { return m_sessionType; }
|
||||
IIocpContext* GetContext() { return m_context; }
|
||||
|
||||
public:
|
||||
BOOL IsNormal() { return (SESSION_NORMAL == m_sessionType) ? TRUE : FALSE; }
|
||||
BOOL IsWaiter() { return (SESSION_LOGIN == m_sessionType) ? TRUE : FALSE; }
|
||||
BOOL IsPlayer() { return (SESSION_PLAYER == m_sessionType) ? TRUE : FALSE; }
|
||||
BOOL IsServer() { return (SESSION_SERVER == m_sessionType) ? TRUE : FALSE; }
|
||||
|
||||
public:
|
||||
virtual void OnConnect() {};
|
||||
virtual void OnDisconnect() {};
|
||||
|
||||
protected:
|
||||
SessionTypes m_sessionType;
|
||||
IIocpContext* m_context;
|
||||
};
|
||||
|
||||
// 扁夯技记
|
||||
class cSession : public ISession, public BoostPooler<cSession>
|
||||
{
|
||||
public:
|
||||
cSession(void) {}
|
||||
|
||||
public:
|
||||
virtual void OnConnect();
|
||||
virtual void OnDisconnect();
|
||||
|
||||
public:
|
||||
BOOL TransferBegin(const TCHAR* file, const uint32 length);
|
||||
BOOL TransferDo(const uint8* buffer, const uint32 length);
|
||||
void TransferWrite();
|
||||
void TransferEnd();
|
||||
BOOL DoingTransfer() { return m_transfer; }
|
||||
|
||||
const TCHAR* GetFile() { return m_file; }
|
||||
const uint8* GetBuffer() { return m_buffer.GetBuffer(); }
|
||||
const uint32 GetLength() { return m_buffer.GetLength(); }
|
||||
const uint32 GetTransferLength() { return m_transferLength; }
|
||||
|
||||
public:
|
||||
BOOL m_transfer;
|
||||
TCHAR m_file[512];
|
||||
uint32 m_transferLength;
|
||||
cBuffer m_buffer;
|
||||
};
|
||||
@@ -0,0 +1,90 @@
|
||||
#include "stdafx.h"
|
||||
#include "cSessionTable.h"
|
||||
|
||||
|
||||
cSessionTable g_sessionTable;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cSessionTable::cSessionTable(void)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
cSessionTable::~cSessionTable(void)
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void cSessionTable::Init()
|
||||
{
|
||||
}
|
||||
|
||||
void cSessionTable::Destroy()
|
||||
{
|
||||
m_sessions.clear();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Operation
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
BOOL cSessionTable::Insert(const uint32 entity, IIocpContext* context)
|
||||
{
|
||||
cSession* session = Get(entity);
|
||||
if(!session)
|
||||
{
|
||||
session = new cSession;
|
||||
session->SetContext(context);
|
||||
session->OnConnect();
|
||||
|
||||
m_sessions[entity] = session;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void cSessionTable::Remove(const uint32 entity)
|
||||
{
|
||||
cSession* session = Get(entity);
|
||||
if(!session) return;
|
||||
|
||||
SESSION_TABLE::iterator it = m_sessions.find(entity);
|
||||
if(it != m_sessions.end())
|
||||
{
|
||||
m_sessions.erase(it);
|
||||
}
|
||||
|
||||
switch(session->GetType())
|
||||
{
|
||||
case SESSION_LOGIN :
|
||||
case SESSION_PLAYER :
|
||||
case SESSION_SERVER :
|
||||
default :
|
||||
{
|
||||
delete session;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cSession* cSessionTable::Get(const uint32 entity)
|
||||
{
|
||||
SESSION_TABLE::iterator it = m_sessions.find(entity);
|
||||
return (it != m_sessions.end()) ? it->second : NULL;
|
||||
}
|
||||
|
||||
cSession* cSessionTable::GetFirst()
|
||||
{
|
||||
m_iterator = m_sessions.begin();
|
||||
return (m_iterator != m_sessions.end()) ? m_iterator->second : NULL;
|
||||
}
|
||||
|
||||
cSession* cSessionTable::GetNext()
|
||||
{
|
||||
++m_iterator;
|
||||
return (m_iterator != m_sessions.end()) ? m_iterator->second : NULL;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "cSession.h"
|
||||
|
||||
|
||||
// ¼¼¼ÇÀ» °ü¸®ÇÏ´Â Å×À̺í
|
||||
class cSessionTable
|
||||
{
|
||||
public:
|
||||
cSessionTable(void);
|
||||
~cSessionTable(void);
|
||||
|
||||
void Init();
|
||||
void Destroy();
|
||||
|
||||
public:
|
||||
BOOL Insert(const uint32 entity, IIocpContext* context);
|
||||
void Remove(const uint32 entity);
|
||||
|
||||
uint32 GetCount() { return m_sessions.size(); }
|
||||
|
||||
cSession* Get(const uint32 entity);
|
||||
cSession* GetFirst();
|
||||
cSession* GetNext();
|
||||
|
||||
private:
|
||||
typedef std::map<uint32,cSession*> SESSION_TABLE;
|
||||
|
||||
SESSION_TABLE::iterator m_iterator;
|
||||
SESSION_TABLE m_sessions;
|
||||
};
|
||||
|
||||
extern cSessionTable g_sessionTable;
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "stdafx.h"
|
||||
#include "cServiceLS.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int _tmain(int argc, TCHAR **argv)
|
||||
{
|
||||
// 한글 OS가 설치되지 않은 곳에서 실행되지 않으므로 삭제. 2013-01-14 신영욱
|
||||
//#ifdef _UNICODE
|
||||
// wcin.imbue( locale("korean") );
|
||||
// wcout.imbue(locale("korean"));
|
||||
//#endif
|
||||
|
||||
cServiceLS *service = new cServiceLS(argc, argv);
|
||||
service->ServiceMainProc();
|
||||
delete service;
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user