#include "stdafx.h"
#include "GMTool.h"
#include "resource.h"
#include "Cheat_Common.h"
#include "Protocol_Cheat.h"

void cGMTool::InitDlgStop()
{
	HWND hWnd = mSubDlg[GMTOOL_SUBDLG_STOP];

	/// 위치 셋팅
	RECT rc0;
	::GetWindowRect( mMainDlg, &rc0 );
	int x = rc0.right;
	int y = rc0.top + GetSystemMetrics(SM_CYCAPTION);
	::SetWindowPos( hWnd, 0, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );

	mSubDlgPos[GMTOOL_SUBDLG_STOP].x = 0;
	mSubDlgPos[GMTOOL_SUBDLG_STOP].y = GetSystemMetrics(SM_CYCAPTION);

	/// 초기화
	SetDlgItemText( hWnd, IDC_EDIT_STOP_ID, _T("") );
	SendDlgItemMessage( hWnd, IDC_EDIT_STOP_TIME, EM_SETLIMITTEXT, (WPARAM)5, 0 );
	SendDlgItemMessage( hWnd, IDC_EDIT_STOP_ID, EM_SETLIMITTEXT, (WPARAM)MAX_NAME_SIZE, 0 );
	SetDlgItemInt ( hWnd, IDC_EDIT_STOP_TIME, 1, false );
	
}

void cGMTool::OnCommandStop( int id, int msg )
{
	switch( id )
	{
	case IDC_BUTTON_STOP_CANCEL:
		::ShowWindow( mSubDlg[GMTOOL_SUBDLG_STOP], SW_HIDE );
		::SetActiveWindow( mParentWnd );
		break;
	case IDC_BUTTON_STOP_OK:
		{
			/// 내용 받기
			TCHAR str[MAX_NAME_BUFFER_SIZE] = {0,};
			int retcode = GetDlgItemTextW( mSubDlg[GMTOOL_SUBDLG_STOP], IDC_EDIT_STOP_ID, str, MAX_NAME_BUFFER_SIZE );
			if( retcode == false )
				return;

			cStringT temp = str;
			temp.Replace( _T("\r\n"), _T(" ") );
			temp.Replace( _T("\t"), _T(" ") );

			BOOL ret = FALSE;
			int time = GetDlgItemInt( mSubDlg[GMTOOL_SUBDLG_STOP], IDC_EDIT_STOP_TIME, &ret, false );
			if( ret == FALSE )
				return;

			unsigned long totaltime = time * 60 * 1000;

			/// 메시지 전송
			if( NETWORK->IsConnected() )
			{
				MSG_REQ_CHEAT_STOP msg;
				::memset( &msg, 0, sizeof(msg) );
				msg.Category = NM_CHEAT;
				msg.Protocol = NM_CHEAT_STOP_REQ;
				::Sstrncpy( msg.mCharName, MAX_NAME_BUFFER_SIZE, temp.Cstr(), MAX_NAME_SIZE );
				msg.mDuration = time;

				NETWORK->SendNetworkMsg( (char*)&msg, sizeof(msg) );
			}
			SetDlgItemText( mSubDlg[GMTOOL_SUBDLG_STOP], IDC_EDIT_STOP_ID, _T("") );
			//SetDlgItemText( mSubDlg[GMTOOL_SUBDLG_STOP], IDC_EDIT_STOP_TIME, _T("") );
		}
		break;
	case IDC_EDIT_STOP_ID:
		{
		}
		break;
	}
}