Files
Leviathan/Client/Game/game/Interface/SUIMarkPanelWnd.cpp
T
2026-06-01 12:46:52 +02:00

666 lines
17 KiB
C++

#include <network/XSyncStreamConnection.h>
#include "ErrorCode/ErrorCode.h"
#include "d3dx9tex.h"
#include "KRenderDeviceDX.h"
#include "KDeviceManager.h"
#include "KResourceMAnager.h"
#include "KUITextureManager.h"
#include "SStringDB.h"
#include "SLog.h"
#include <toolkit/nsl.h>
#include "Util.h"
#include <toolkit/XStringUtil.h>
#include "SGame.h"
#include "SGameManager.h"
#include "SMessengerMgr.h"
#include "SPlayerInfoMgr.h"
#include "SChatType.h"
#include "SMessage.h"
#include "SGameMessageUI.h"
#include "SGameMessage.h"
#include "KUIControlButton.h"
#include "KUIControlPanel.h"
#include "KUIControlStatic.h"
#include "SUIMarkPanelWnd.h"
#include "CommonUtil.h"
extern HWND g_hWnd;
SUIMarkPanelWnd::SUIMarkPanelWnd( SGameManager * pGameManager, KUIControlPanelManager * pPanelManager ) :
KUIControlPanel( pGameManager, pPanelManager ),
m_pExtensionButton( NULL ), // 확장버튼.
m_pUploadConn( NULL ),
m_pRecvQueue( NULL ),
m_bNewIcon( false )
{
}
SUIMarkPanelWnd::~SUIMarkPanelWnd()
{
Release();
}
// 메모리 해제.
void SUIMarkPanelWnd::Release()
{
// Connection 제거.
CloseUploadConnection();
}
//-----------------------------
// Override
// KUIControlPanel::
// 패널의 크기를 원본크기로 변경한다. 각 패널윈도우의 크기가 다르므로 재정의할것!!.
void SUIMarkPanelWnd::ResizeOriginal()
{
KRect rtWnd = this->GetRect();
const KRect & rtTitlebar = GetChild( "trim_titlebar_open" )->GetRect();
rtWnd.bottom = rtWnd.top + rtTitlebar.GetHeight() - 1;
// 윈도우 크기변경.
KUIWnd::OnSizeChangeNofity( rtWnd );
// Panel 의 함수.
KUIControlPanel::ResizeOriginal();
// 버튼 애니 변경.
PanelExtend();
}
bool SUIMarkPanelWnd::InitControls( KPoint kPos )
{
// ****
// 확장 여부에따라 숨김, 보임 처리가 바뀌는 Wnd 를 배열에 추가한다.
this->AddChangeVisibleWnd( GetChild( "select_list_cyan" ) );
// 확장버튼 컨트롤.
m_pExtensionButton = dynamicCast< KUIControlSimpleButton * >( GetChild( "sub_open" ) );
//const KRect & rtOutLine = GetChild( "select_list_cyan_06" )->GetRect();
const KRect & rtTitlebar = GetChild( "trim_titlebar_open" )->GetRect();
KRect rtOriginal = this->GetRect(); // window의 크기.
rtOriginal.bottom = rtOriginal.top + rtTitlebar.GetHeight();
// 초기설정.( 확대, 축소 크기지정 )
this->Initialize( rtOriginal, this->GetRect() );
kPos.x = rtOriginal.left;
kPos.y = rtOriginal.top;
// 활성화시 텍스트 컬러.
dynamicCast< KUIControlStatic * >( GetChild( "guild_manage_menu" ) )->SetEnableColor( "<#ffffff>" );
return SUIWnd::InitControls( kPos );
}
void SUIMarkPanelWnd::OnNotifyUIWindowOpen( bool bOpen, bool bLimitWnd)
{
if( bOpen )
{
m_bNewIcon = false;
// 공격대정보.
m_pGameManager->PostMsgAtDynamic( new SMSG_GUILD_COMMAND( SMSG_GUILD_COMMAND::GUILD_RAID ) );
}
}
void SUIMarkPanelWnd::ProcMsgAtStatic( SGameMessage* pMsg )
{
switch(pMsg->nType)
{
// ★ 업로드서버 결과.
case IMSG_UPLOADSERVER_RESULT:
{
SIMSG_UPLOADSERVER_RESULT * pData = dynamicCast< SIMSG_UPLOADSERVER_RESULT * >( pMsg );
switch( pData->upload_type )
{
// 로그인 결과.
case SIMSG_UPLOADSERVER_RESULT::UPLOADSERVER_LOGIN_RESULT :
// 로그인 성공.
if( pData->result == RESULT_SUCCESS )
SaveIconEx();
// 로그인 실패.
else
CloseUploadConnection(); // Connection 제거.
break;
// 길드아이콘 업로드 결과.
case SIMSG_UPLOADSERVER_RESULT::UPLOADSERVER_GUILDICON_UPLOAD_RESULT :
#ifdef _DEV
//성공.
if( pData->result == RESULT_SUCCESS )
MessageBox( g_hWnd, "업로드 성공", "OK", MB_OK|MB_ICONINFORMATION );
//실패.
else
MessageBox( g_hWnd, "업로드 실패", "Error", MB_OK|MB_ICONINFORMATION );
#endif
// Connection 제거.
CloseUploadConnection();
break;
}
}
break;
case IMSG_UI_SEND_DATA : // 길드웹 URL.
SIMSG_UI_SEND_DATA *pData = (SIMSG_UI_SEND_DATA *)pMsg;
// 업로드서버 에 로그인 요청.
if( pData->m_strString == "OTP_CONFIRM" )
{
pMsg->bUse = true;
TS_SC_OPEN_GUILD_WINDOW * pOTP = static_cast< TS_SC_OPEN_GUILD_WINDOW * >( pData->m_pData );
UploadServerLogin( pOTP );
SAFE_DELETE( pOTP );
}
// 웹 업로드 URL 및 OTP 설정.
else if( pData->m_strString == "guild_url" )
{
m_strURL = pData->m_strText;
XStringUtil::Replace( m_strURL, "http://", "" );
XStringUtil::Replace( m_strURL, "rion", "192.168.0.18" );
XStringUtil::Replace( m_strURL, "login", "upload" );
std::string::size_type nSPos = m_strURL.find_first_of( "?" );
if( nSPos != std::string::npos )
{
m_OTPServer = m_strURL.substr( nSPos + 1 + strlen( "server=" ), m_strURL.size() );
std::string::size_type nFPos = m_OTPServer.find_first_of( "&" );
if( nFPos != std::string::npos )
m_OTPServer = m_OTPServer.substr( 0, nFPos );
}
nSPos = m_strURL.find( "id=" );
if( nSPos != std::string::npos )
m_OTPID = m_strURL.substr( nSPos + strlen( "id=" ), m_strURL.size() );
// 아이콘 업로드.
//SaveIcon();
pMsg->bUse = true;
}
break;
}
}
void SUIMarkPanelWnd::PumpUpMessage( LPCSTR lpszControlID, DWORD nMessage, DWORD lparam, DWORD wparam )
{
switch( nMessage )
{
case KUI_MESSAGE::KBUTTON_CLICK :
{
// 확대축소 토글.
if( !::_stricmp( lpszControlID, "sub_open" ) || !::_stricmp( lpszControlID, "trim_titlebar_open" ) )
{
// 토글.
this->ToggleExtend();
// 버튼 애니 변경.
PanelExtend();
}
// 길드아이콘 찾아보기.
else if( !::_stricmp( lpszControlID, "button_search_01" ) )
{
FindGuildIconName();
}
// 길드아이콘 업로드.
else if( !::_stricmp( lpszControlID, "button_save_02" ) )
{
// OTP인증 요청.
SGame* pActiveGame = m_pGameManager->GetActiveGame();
if( pActiveGame )
pActiveGame->RqChatting( CHAT_NORMAL, m_PlayerInfoMgr.GetPlayerInfo().GetName(), "/gupdateicon" );
//SaveIcon();
}
}
break;
}
SUIWnd::PumpUpMessage( lpszControlID, nMessage, lparam, wparam );
}
void SUIMarkPanelWnd::Process(DWORD dwTime)
{
if( m_pUploadConn && m_pRecvQueue && m_pUploadConn->IsConnected() && (m_pUploadConn->IsReadable() || (m_pRecvQueue->Size() >= sizeof( TS_MESSAGE ))) )
m_pGameManager->onReadEvent( m_pUploadConn, m_pRecvQueue );
}
//DWORD SUIMarkPanelWnd::OnMouseMessage(DWORD dwMessage, int x, int y)
//{
//
// return SUIWnd::OnMouseMessage(dwMessage, x, y);
//}
// Panel 확대,축소
void SUIMarkPanelWnd::PanelExtend()
{
m_pExtensionButton->SetAniName( this->GetIsExtend() ? "common_button_titanium_sub_open" : "common_button_titanium_sub_close" );
}
// Open 시 필요기능정의.
void SUIMarkPanelWnd::CustomOpen()
{
// Panel 확대,축소
PanelExtend();
}
// 길드아이콘 찾아보기 & 미리보기.
void SUIMarkPanelWnd::FindGuildIconName()
{
char lpstrFile[ MAX_PATH ];
memset( lpstrFile, 0, MAX_PATH );
/// 2011.01.19 안 쓰여서 주석 처리 - prodongi
//DWORD dwRead;
OPENFILENAME OFN;
memset( &OFN, 0, sizeof( OFN ) );
OFN.lStructSize = sizeof( OFN );
OFN.hwndOwner = g_hWnd;
OFN.lpstrFilter=TEXT("Image(*.jpg)\0*.jpg\0All(*.*)\0*.*\0");
OFN.lpstrFile=lpstrFile;
OFN.lpstrDefExt=TEXT("txt");
OFN.nMaxFile=MAX_PATH;
OFN.Flags = OFN_NOCHANGEDIR;
if( GetOpenFileName( &OFN ) )
{
//-------------
// 이미지파일 로드.
HANDLE hFile = CreateFileA( OFN.lpstrFile, GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL);
DWORD dwRead = 0;
if (hFile!=INVALID_HANDLE_VALUE)
{
//
// 파일크기검사.
dwRead = GetFileSize( hFile, NULL );
if( dwRead > ( 1024 * 60 ) )
{
::MessageBox( NULL, S( 1923 ), "Error", MB_OK );
CloseHandle(hFile);
return;
}
CloseHandle(hFile);
}
else
{
::MessageBox( NULL, S( 1923 ), "Error", MB_OK );
return;
}
//
// 이미지 사이즈 검사.
// K3DRenderDeviceDX * pGraphics = (K3DRenderDeviceDX *)KDeviceManagerDX::GetDeviceManager()->GetRenderDevice(); Device 얻기.
HRESULT hr;
D3DXIMAGE_INFO infoImg;
if( ( hr = D3DXGetImageInfoFromFile( OFN.lpstrFile, &infoImg ) ) == D3D_OK )
{
if( D3DXIMAGE_FILEFORMAT::D3DXIFF_JPG == infoImg.ImageFileFormat )
{
if( infoImg.Width > 20 || infoImg.Height > 20 )
{
m_StrIconFullPath = "";
::MessageBox( NULL, S( 1923 ), "Error", MB_OK );
return;
}
}
else
{
m_StrIconFullPath = "";
::MessageBox( NULL, S( 1923 ), "Error", MB_OK );
return;
}
}
else
{
m_StrIconFullPath = "";
//::MessageBox( NULL, DXGetErrorString9( hr ), "Error", MB_OK );
::MessageBox( NULL, "Guild_Icon Load Fail", "Error", MB_OK );
return;
}
//////
std::string path( ".\\Guild_Icon\\" );
std::string fileName( OFN.lpstrFile );
std::string::size_type pos = fileName.rfind( "\\" );
fileName = fileName.substr( pos+1 );
path.append( fileName.c_str() );
//
m_StrIconFullPath = OFN.lpstrFile;
m_strIconFileName = fileName;
KSpriteManager::GetManager()->AddIconSprite( "ui_frame.spr", OFN.lpstrFile, false, true, KColor(255,0,255), true );
std::string strAniName;
if( CStringUtil::GetIconAniName( path.c_str(), strAniName ) )
{
m_bNewIcon = true;
dynamicCast< KUIControlStatic * >( GetChild( "guild_mark_01" ) )->SetAniName( strAniName.c_str() );
}
else
{
dynamicCast< KUIControlStatic * >( GetChild( "guild_mark_01" ) )->SetAniName( "common_mark_icon_none" );
}
}
}
#include <wininet.h>
#include <toolkit/XEnv.h>
void SUIMarkPanelWnd::UploadServerLogin( TS_SC_OPEN_GUILD_WINDOW * pOTP )
{
if( m_pUploadConn == NULL )
{
m_pUploadConn = new XSyncStreamConnection( true, true );
m_pRecvQueue = IQueue::MakeQueue( 1*1024 );
}
if( !m_pUploadConn->IsConnected() )
{
//인증 서버 접속
XAddr addr;
//addr = XAddr( ENV().GetString( "auth_ip", "" ).c_str(), ENV().GetInt( "auth_port", 4500 ) );
std::string strIP = ENV().GetString( "guild_icon_upload.ip" );
int port = atoi( ENV().GetString( "guild_icon_upload.port" ).c_str() );
#ifdef _DEV
::MessageBox( NULL, CStringUtil::StringFormat("%s : %d", strIP.c_str(), port ).c_str(), "", MB_OK );
#endif
addr = XAddr( strIP.c_str(), port );
//addr = XAddr( "192.168.107.19", 4518 );
if( !m_pUploadConn->Connect( addr ) )
{
// Connection 제거.
CloseUploadConnection();
#ifdef _DEV
MessageBox( g_hWnd, "업로드서버 접속 실패", "Rappelz-Error", MB_OK|MB_ICONINFORMATION );
#endif
return;
}
#ifdef _DEV
MessageBox( g_hWnd, "업로드서버 접속 성공", "OK", MB_OK|MB_ICONINFORMATION );
#endif
}
if( m_pUploadConn )
{
TS_CU_LOGIN msgUpload;
msgUpload.client_id = pOTP->client_id;
msgUpload.account_id = pOTP->account_id;
msgUpload.guild_id = this->m_GuildMgr.GetGuildID();
msgUpload.one_time_password = pOTP->one_time_password;
strcpy( msgUpload.raw_server_name, pOTP->raw_server_name );
this->m_pGameManager->ConnPendMessageIconUpload( m_pUploadConn, &msgUpload );
}
}
void SUIMarkPanelWnd::SaveIconEx()
{
if( m_StrIconFullPath.empty() || m_StrIconFullPath == "" )
return;
TS_CU_UPLOAD msg;
//-------------
// 이미지파일 로드.
HANDLE hFile = CreateFileA( m_StrIconFullPath.c_str(), GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL);
DWORD dwRead = 0;
if (hFile!=INVALID_HANDLE_VALUE)
{
dwRead = GetFileSize( hFile, NULL );
msg.file_length = dwRead;
msg.size += dwRead;
msg.set_check_sum();
char * pBuffer = new char[ sizeof( TS_CU_UPLOAD ) + dwRead ];
memcpy( pBuffer, &msg, sizeof( TS_CU_UPLOAD ) );
char * pDes = pBuffer + sizeof( TS_CU_UPLOAD );
ReadFile( hFile, pDes, dwRead, &dwRead, NULL );
this->m_pGameManager->ConnPendMessageIconUpload( m_pUploadConn, (TS_CU_UPLOAD *)( pBuffer ) );
delete [] pBuffer;
CloseHandle(hFile);
}
else
{
CloseUploadConnection(); // Connection 제거.
}
}
void SUIMarkPanelWnd::SaveIcon()
{
if( m_StrIconFullPath == "" || m_OTPServer == "" || m_OTPID == "" )
return;
// 하드코딩.
//std::string strURL = "http://rappelz.nflavor.com/client/guild/iconupload.aspx?server=";
// eop 파일에 적용된 URL 을 서버로부터 받아 ENV() 에 저장한 길드아이콘 업로드 URL.
std::string strURL = ENV().GetString( "guild_icon_upload.url", "client/guild/iconupload.aspx" );
strURL.append( "?server=" );
strURL += m_OTPServer;
strURL.append( "&id=" );
strURL += m_OTPID;
strURL.append( CStringUtil::StringFormat( "&guild=%d", m_GuildMgr.GetGuildID() ).c_str() );
// Header 설정.
static TCHAR hdrs[] = "Content-Type: multipart/form-data; Accept-Encoding: UTF-8, default; boundary=----WebKitFormBoundaryouQ5Yc8wNsmQzyzX";
// formData 형식 설정.
char frmdata[65556] = "------WebKitFormBoundaryouQ5Yc8wNsmQzyzX\r\nContent-Disposition: form-data; name=\"FileUpload1\"; filename=\"icon.jpg\"\r\n";
int length = strlen(frmdata);
//-------------
// 이미지파일 로드.
HANDLE hFile = CreateFileA( m_StrIconFullPath.c_str(), GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL);
DWORD dwRead = 0;
if (hFile!=INVALID_HANDLE_VALUE)
{
dwRead = GetFileSize( hFile, NULL );
// Content-Length.
char pStr[256] = {NULL,};
sprintf( pStr, "Content-Length: %d\r\nContent-Type: image/jpeg\r\n\r\n", dwRead ); // 되는거.
length += strlen( pStr );
strcat( frmdata, pStr );
// ★
if( ReadFile(hFile,frmdata+length,dwRead,&dwRead,NULL) == 0 )
{
CloseHandle(hFile);
return;
}
CloseHandle(hFile);
}
// ★
else
{
CloseHandle(hFile);
return;
}
//-------------
char str[] = "\r\n\r\n------WebKitFormBoundaryouQ5Yc8wNsmQzyzX--\r\n";
sprintf( frmdata+length+dwRead, str );
length += dwRead;
length += strlen( str );
TCHAR * m_html = NULL;
std::string ServerName = strURL.substr( strlen( "HTTP://" ), strURL.size() );
std::string::size_type nFPos = ServerName.find_first_of( "/" );
if( nFPos != std::string::npos )
ServerName = ServerName.substr( 0, nFPos );
strURL = strURL.substr( strlen( "HTTP://" ) + ServerName.size() + 1, strURL.size() );
DWORD_PTR dwContext = 1;
HINTERNET hInternet = InternetOpen( "HTTP", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
// ★
if( hInternet == NULL )
return;
HINTERNET hConnect = InternetConnect( hInternet, ServerName.c_str(), INTERNET_DEFAULT_HTTP_PORT,
NULL, NULL, INTERNET_SERVICE_HTTP, 0, dwContext );
// ★
if( hConnect == NULL )
{
InternetCloseHandle( hInternet );
return;
}
LPCTSTR accept[]={ "*/*", NULL };
/*DWORD dwFlags = INTERNET_FLAG_NO_CACHE_WRITE |
INTERNET_FLAG_KEEP_CONNECTION |
INTERNET_FLAG_IGNORE_CERT_CN_INVALID |
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID|
INTERNET_FLAG_PRAGMA_NOCACHE;;\*/
DWORD dwFlags = INTERNET_FLAG_DONT_CACHE; //INTERNET_FLAG_RELOAD | INTERNET_FLAG_TRANSFER_BINARY;
HINTERNET hRequest = HttpOpenRequest( hConnect, "POST", strURL.c_str(), NULL, NULL, accept, dwFlags, dwContext );
if( hRequest == NULL )
{
InternetCloseHandle( hConnect );
InternetCloseHandle( hInternet );
return;
}
// ★
bool bResult = HttpSendRequest( hRequest, hdrs, strlen(hdrs), frmdata, length );
if( !bResult )
{
InternetCloseHandle( hRequest );
InternetCloseHandle( hConnect );
InternetCloseHandle( hInternet );
return;
}
//----------------------------------------------------------------------------------------------
//// HTML 읽어오기. http Response 확인용. 나중에 안될때를 대비해 디버깅용으로 남겨둔다.
//
//UINT CodePage = CP_UTF8;
// DWORD dwSize = 0;
// BOOL bQuery = InternetQueryDataAvailable( hRequest, &dwSize, 0, 0 );
// if ( bQuery && dwSize > 0 )
// {
// DWORD dwTotal = 0;
// char* pData = (char*)malloc( dwTotal + dwSize + 1 );
// while ( pData && dwSize )
// {
// DWORD dwRead = 0;
// InternetReadFile( hRequest, pData+dwTotal, dwSize, &dwRead );
// dwTotal += dwRead;
// pData[dwTotal] = NULL;
// InternetQueryDataAvailable( hRequest, &dwSize, 0, 0 );
// if ( dwSize > 0 )
// {
// pData = (char*)realloc( pData, dwTotal + dwSize+1 );
// }
// }
// if ( pData )
// {
// int len = MultiByteToWideChar( CodePage, 0, pData, dwTotal, NULL, NULL );
// m_html = (TCHAR *)calloc( len+1, sizeof(TCHAR) );
// if ( m_html )
// {
// //MultiByteToWideChar( CodePage, 0, pData, dwTotal, m_html, len+1 );
// //::OutputDebugString( pData );
// }
// free(pData);
// }
// }
InternetCloseHandle( hRequest );
InternetCloseHandle( hConnect );
InternetCloseHandle( hInternet );
}
// Connection 제거.
void SUIMarkPanelWnd::CloseUploadConnection()
{
if( m_pUploadConn )
{
m_pUploadConn->Close();
delete m_pUploadConn;
m_pUploadConn = NULL;
SAFE_DELETE( m_pRecvQueue );
}
}