📄 creadargument.cpp
字号:
bool CClientBill::Receive_sub( t_connection *c)
{
struct timeval tv;
fd_set rfds;
global_time_new = timeGetTime();
FD_ZERO( &rfds );
FD_SET( c->socket, &rfds );
tv.tv_sec = 2;
tv.tv_usec = 0;
if ( select( c->socket, &rfds, NULL, NULL, &tv) < 0 )
{
return false;
}
if ( FD_ISSET( c->socket, &rfds ) )
{
int addlen;
DWORD dwBytesRead;
while ( 1 )
{
if ( ioctlsocket( c->socket, FIONREAD, &dwBytesRead ) < 0 )
{
return false;
}
if ( dwBytesRead == 0 )
{
break;
}
//Buffer_len
//Buffer_pnt
addlen = recv( c->socket, &Buffer[Buffer_pnt], Buffer_len, 0 );
if ( addlen < 0 )
{
return false;
}
else if ( addlen > 0 )
{
Buffer_len -= addlen;
Buffer_pnt += addlen;
if ( Buffer_len == 0 )
{
answer = (void*)Buffer[0];
return true;
}
else if( Buffer_len < 0 )
{
return false;
}
}
}
}
return false;
}
/*
int CClientBill::Netsgo_connect_gatewayd(char *host_nm,int port_no)
{
int serv_sock;
int rtncd,ok;
// if ((serv_sock = connect(host_nm,port_no)) < 0) //socket connect (socket(), connect())
return (-1);
return serv_sock;
}
*/
//int(2byte) //user id length,
//string(length) //user id
int CClientBill::Thrunet_SendMessage()
{
char test[100];
wsprintf(test,"%s %d",UserID,UserIDlength);
int size = 2 + UserIDlength;
char *dis = new char [size];
int pnt;
memset(dis,0, size );
memcpy(dis,&UserIDlength,2);
memcpy(dis+2,UserID,UserIDlength);
DWORD cur_time;
DWORD check_time = timeGetTime();
int addlen;
pnt = 0;
while( 1 )
{
addlen = send( connections.socket, dis + pnt , size, 0 );
// addlen = send( connections[curr_connect].socket, dis + pnt , size, 0 );
if( addlen < 0 )
{
PostQuitMessage(0);
return 0;
// Error..
}
else
{
size -= addlen;
pnt += addlen;
if( size == 0 )
{
// 己傍.
break;
}
else if( size < 0 )
{
PostQuitMessage(0);
return 0;
// Error.,
}
}
cur_time = timeGetTime();
if( cur_time - check_time > 5000 )
{
PostQuitMessage(0);
return 0;
// Error .. 5檬悼救 Packet阑 焊郴瘤 给沁促.
}
else
{
// 酒流篮 矫埃捞 巢疽栏聪 弧府 焊郴..
}
}
bool ret;
short int answer;
ret = WaitingTheAnswerForTHTUNET( &connections, &answer );
// ret = WaitingTheAnswerForTHTUNET( &connections[curr_connect], &answer );
if( ret == false )
{
//thrunet俊 楷搬等巴捞 酒聪芭唱.
//急捞 谗绢脸芭唱,
//蜡丰荤侩阑 给窍绰 蜡历捞芭唱,
}
else // 搬苞啊 逞绢吭促 !!!!
{
switch( answer )
{
case 0 : return 1;
break;
case -1: return 0;
break;
}
}
return 0;
}
void CheckGameSocketAndSendHeartBeat(void* ThreadParam) //30檬俊 茄锅究 霸烙 家南捞 摧洒搁 辆樊力 家南档 摧绰促.
{
if((int)ThreadParam <0)
return;
if(g_pBill==NULL)
return;
HANDLE hHeartBeat = CreateEvent(NULL, FALSE, FALSE, STRING_TERMINATEEVENT);
if (!hHeartBeat) hHeartBeat = OpenEvent(NULL, TRUE, STRING_TERMINATEEVENT);
while(1)
{
//20檬埃 扁促赴促.
if (WaitForSingleObject(hHeartBeat, 20000) != WAIT_TIMEOUT)
{
CloseHandle(hHeartBeat);
break;
}
if( connections.socket == 0 )
{
g_pBill->CloseSocket();
return;
}
switch( g_pBill->ReturnLineNum() )
{
case 0:
case 1:
case 2:
case 3:
case 4:
g_pBill->HeartBeatToGameSocket();
break;
case 5: //kornet world
g_pBill->HeartBeatToGameSocket();
break;
case 6: //mezzy system
case 7: //WeverNet
case 8: //WiseTop
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
g_pBill->HeartBeatToGameSocket();
break;
default:
char dis[100];
sprintf(dis,"Check HeartBeat %d Corp",g_pBill->ReturnLineNum());
MessageBox(NULL,dis,"HeartBeat Error",NULL);
}
}
}
int CClientBill::CloseSocket() //辆樊力侩栏肺 凯妨乐绰 家南阑 馆券
{
if(sockfd)
closesocket(sockfd);
return 1;
}
int CClientBill::MakePaySocket(int How)
{
if(ReturnLineNum()<0)
return 0;
struct sockaddr_in addr;
int i;
memset(&sockfd,0,sizeof(sockfd));
for( i = 0 ; i < 10 ; i ++)
{
sockfd = socket( AF_INET, SOCK_STREAM, 0 ); // 牢磐齿鸥涝, 胶飘覆家 南
if ( sockfd == INVALID_SOCKET )
{
int err = WSAGetLastError();
switch( err )
{
case WSANOTINITIALISED : Sleep( 30 );
break;
}
}
else break;
}
if( i == 10 ) return -1;
addr.sin_family = AF_INET;
addr.sin_port = htons( ReturnPayPORTNumber() );
addr.sin_addr.s_addr = inet_addr( ReturnPayIPaddress() );
u_long argp = 1;
ioctlsocket ( sockfd , FIONBIO, &argp);
int ret = connect( sockfd , ( LPSOCKADDR )&addr, sizeof( addr ) );
// if(ret<0)
// PostQuitMessage(0);
for( i = 0 ; i < 4 ; i ++)
{
fd_set wfds;
FD_ZERO(&wfds);
FD_SET( sockfd , &wfds);
struct timeval t;
t.tv_sec = 2;
t.tv_usec = 0;
select (0, NULL, &wfds, NULL, &t);
if ( !FD_ISSET( sockfd , &wfds) ) // send镜荐 乐绰 惑炔捞 酒聪搁...
{
if( i == 9 ) // 佬芭唱 镜荐 绝绰 惑炔阑 9锅鳖瘤绰 扁促妨霖促.
{
int err = WSAGetLastError();
return -2;
}
}
else break;
}
return( 1 );
}
void CClientBill::HeartBeatToOtherSocket() //辆樊力 诀眉侩栏肺 凯赴 家南俊促 老沥矫埃付促 皋矫瘤甫 焊辰促.
{
SendToPaySocket("alive",5);
}
void CClientBill::HeartBeatToGameSocket() //角力 霸烙侩栏肺 凯赴 家南俊促 老沥矫埃付促 皋矫瘤甫 焊郴促.
{ //霸烙辑滚俊 立加窍瘤 臼绊 肺弊牢父 茄 惑怕啊 拌加 蜡瘤瞪 版快 酒公繁 皋矫瘤啊 朝扼啊瘤 臼扁 锭巩俊 辆樊力 霸捞飘傀捞俊辑
//立加捞 谗变巴栏肺 埃林茄促.
SendAliveCheckRoutine();
}
////////////////////////
// 翠捞 朝扼坷搁 bool *answer俊 蔼捞 翠捞 甸绢啊绊 true甫 府畔茄促.
// 翠捞 绝栏搁 answer俊 蔼阑 持瘤 臼绊 false甫 府畔茄促.
bool WaitingTheAnswerForTHTUNET_sub( t_connection *c, short int *answer )
{
struct timeval tv;
fd_set rfds;
global_time_new = timeGetTime();
FD_ZERO( &rfds );
FD_SET( c->socket, &rfds );
tv.tv_sec = 2;
tv.tv_usec = 0;
if ( select( c->socket, &rfds, NULL, NULL, &tv) < 0 )
{
return false;
}
if ( FD_ISSET( c->socket, &rfds ) )
{
int addlen;
DWORD dwBytesRead;
while ( 1 )
{
if ( ioctlsocket( c->socket, FIONREAD, &dwBytesRead ) < 0 )
{
return false;
}
if ( dwBytesRead == 0 )
{
break;
}
addlen = recv( c->socket, &thrunetanswerbuf[ thrunetanswerbuf_pnt], thrunetanswerbuf_len, 0 );
if ( addlen < 0 )
{
return false;
}
else if ( addlen > 0 )
{
thrunetanswerbuf_len -= addlen;
thrunetanswerbuf_pnt += addlen;
if ( thrunetanswerbuf_len == 0 )
{
*answer = *(short int *)thrunetanswerbuf;
return true;
}
else if( thrunetanswerbuf_len < 0 )
{
return false;
}
}
}
}
return false;
}
bool WaitingTheAnswerForTHTUNET( t_connection *c, short int *answer )
{
bool ret;
if ( !c->socket )
{
return false;
}
thrunetanswerbuf_len = 4;
thrunetanswerbuf_pnt = 0;
DWORD s_time = timeGetTime();
DWORD c_time;
while( 1 )
{
Sleep(10);
ret = WaitingTheAnswerForTHTUNET_sub( c, answer );
if( ret == true )
{
return ret;
}
c_time = global_time_new;
if( c_time - s_time > 5000 )
{
return false;
}
}
}
//unitel
void Uniwin_CallbackDetectFileChangeThread(void *pThreadParam)
{
STRUCTCHECKUNIPARAM *pParam = (STRUCTCHECKUNIPARAM *)pThreadParam;
STRUCTCHECKUNIPARAM structParam;
structParam.hWndReceiveWindow = pParam->hWndReceiveWindow;
structParam.nSendToMessage = pParam->nSendToMessage;
delete pParam; // parameter should be destroyed..
HANDLE hTerminateEvent = CreateEvent(NULL, FALSE, FALSE, STRING_TERMINATEEVENT);
if (!hTerminateEvent) hTerminateEvent = OpenEvent(NULL, TRUE, STRING_TERMINATEEVENT);
BOOL bUniwinRunningStatus = IsWindow(FindWindow("UNIMAIN_CLASS", NULL));
// Send Message at Trigger of (Running <-> Terminated state)
BOOL bUniwinWndFound = FALSE;
while(1)
{
// 捞镑俊 GetUniwinInfo狼 老何 风凭阑 持绢 蜡聪扩狼 惑怕甫 林扁利(1000 ms)栏肺 眉农窍咯
// 惑怕啊 函且 版快 皋矫瘤甫 林档废 荐沥啊瓷窃.
// 泅犁绰 蜡聪扩捞 辆丰 瞪 版快 捞甫 Notify窍扁 困秦 累己凳.
bUniwinWndFound = IsWindow(FindWindow("UNIMAIN_CLASS", NULL));
if (bUniwinRunningStatus && !bUniwinWndFound)
{
bUniwinRunningStatus = FALSE;
::PostMessage(structParam.hWndReceiveWindow, structParam.nSendToMessage, 0, (LPARAM)TRUE);
}
else if (!bUniwinRunningStatus && bUniwinWndFound)
{
bUniwinRunningStatus = TRUE;
}
// check at every 1 second
if (WaitForSingleObject(hTerminateEvent, 1000) != WAIT_TIMEOUT)
{
CloseHandle(hTerminateEvent);
return;
}
}
}
// EXAPLAIN 5 : Start Uniwin running check thread..
BOOL CUnicheck::Uniwin_StartCheckUniwin(HWND hReceiveWindow, UINT nReceiveMessage)
{
// this param will destroy at thread function..
STRUCTCHECKUNIPARAM *pStructParam = new STRUCTCHECKUNIPARAM;
pStructParam->hWndReceiveWindow = hReceiveWindow;
pStructParam->nSendToMessage = nReceiveMessage;
unsigned long hThreadHandle = _beginthread(Uniwin_CallbackDetectFileChangeThread, NULL, (void*)pStructParam);
if (hThreadHandle == -1)
return FALSE;
return TRUE;
}
// EXAPLAIN 6 : Terminate uniwin check thread
void CUnicheck::Uniwin_TerminateCheckUniwin()
{
HANDLE hTerminateEvent = OpenEvent(NULL, TRUE, STRING_TERMINATEEVENT);
if (hTerminateEvent)
return;
SetEvent(hTerminateEvent);
Sleep(100);
}
// EXAPLAIN 7 : Get Current uniwin infomation
void CUnicheck::Uniwin_GetUniwinInfo()
{
// UpdateData(TRUE);
// 1. Find Uniwin Directory...
char *pUniwinDirectory = new char[MAX_PATH + 1];
GetPrivateProfileString("UNITEL", "UNIWIN", "", pUniwinDirectory, MAX_PATH, "win.ini");
// returns pUniwinDirectory >> "C:\UNIWIN98\"
// if return "" then uniwin doesnot installed..
// Check UniwinDirectory Fail...
if (!lstrlen(pUniwinDirectory))
{
delete pUniwinDirectory;
return;
}
// 2. Make Global.ull Full Path
char *pGlobalUll = new char[MAX_PATH + 1];
strcpy(pGlobalUll, pUniwinDirectory);
strcat(pGlobalUll, "GLOBAL.ULL");
// returns pGlobalUll >> "C:\UNIWIN98\GLOBAL.ULL"
// 3. Prepare for obtain user info from "global.ull"
HWND hUniwinWindow = NULL;
BOOL bRunningStatus = 0;
// buffer for user id
char *pUserID = new char[MAX_USERID];
memset(pUserID , 0 , MAX_USERID);
*pUserID = '\0';
// buffer for user name
char *pUserName = new char[MAX_USERNAME];
memset(pUserName,0,MAX_USERNAME);
*pUserName = '\0';
Uniwin_RunningStatus=0;
// memset(szpUniwinDirectory,0,100);
memset(Uniwin_szpUserID,0,100);
memset(Uniwin_szpUserName,0,100);
// buffer for login status
int nLoginStatus = 0;
// load global.ull
HINSTANCE hGlobalUll = ::LoadLibrary(pGlobalUll);
if (hGlobalUll)
{
// 4. Check Uniwin is running (you can use FindWindow at _CallbackDetectFileChangeThread Function.
FnGetHWNDUnimain fnGetHWNDUnimain = (FnGetHWNDUnimain)GetProcAddress(hGlobalUll, "GetHWNDUnimain");
if (fnGetHWNDUnimain)
hUniwinWindow = fnGetHWNDUnimain();
bRunningStatus = ::IsWindow(hUniwinWindow);
if (bRunningStatus)
{
// Send Unimain to close my window When Logoff
// when logoff of uniwin then my window receives WM_CLOSE message (LPARAM is 1).
::SendMessage(hUniwinWindow, UM_CLOSENOTIFY, (WPARAM)Uniwin_m_hWnd, (LPARAM)TRUE);
// 5. Get User ID
FnUNIGetUserID fnUNIGetUserID = (FnUNIGetUserID)GetProcAddress(hGlobalUll, "UNIGetUserID");
if (fnUNIGetUserID)
strcpy(pUserID, fnUNIGetUserID());
// 6. Get User Name
FnUNIGetUserName fnUNIGetUserName = (FnUNIGetUserName)GetProcAddress(hGlobalUll, "UNIGetUserName");
if (fnUNIGetUserName)
strcpy(pUserName, fnUNIGetUserName());
// 7. Get Login Status
FnUNIGetLoginStatus fnUNIGetLoginStatus = (FnUNIGetLoginStatus)GetProcAddress(hGlobalUll, "UNIGetLoginStatus");
if (fnUNIGetLoginStatus)
nLoginStatus = fnUNIGetLoginStatus();
Uniwin_RunningStatus = bRunningStatus;
// memcpy(szpUniwinDirectory, pUniwinDirectory,100);
memcpy(Uniwin_szpUserID , pUserID,strlen(pUserID));
memcpy(Uniwin_szpUserName , pUserName,strlen(pUserName));
// MessageBox(NULL,pUniwinDirectory,"Directory",NULL);
// MessageBox(NULL,pUserID,"ID",NULL);
// MessageBox(NULL,pUserName,"Name",NULL);
// MessageBox(NULL,pUserID,"ID",NULL);
}
::FreeLibrary(hGlobalUll);
}
delete pUniwinDirectory;
delete pGlobalUll;
delete pUserID;
delete pUserName;
// UpdateData(FALSE);
}
void CUnicheck::Uniwin_Init(HWND hwnd)
{
// _asm int 3;
Uniwin_m_hWnd=hwnd;
g_unitel->Uniwin_StartCheckUniwin(hwnd,UM_TERMINATENOTIFY);
// g_unitel->Uniwin_StartCheckUniwin(NULL,UM_TERMINATENOTIFY);
g_unitel->Uniwin_GetUniwinInfo();
char FromUnitel[100],FromArgument[100];
memset(FromUnitel,0,100);
memset(FromArgument,0,100);
strcpy(FromArgument,g_pBill->Unitel_ID());
if(strlen(g_unitel->Uniwin_szpUserID)<1)
PostQuitMessage(0);
strcpy(FromUnitel,g_unitel->Uniwin_szpUserID);
if(strcmp(FromArgument,FromUnitel)) //父距 牢磊肺 逞绢柯 酒捞叼客 蜡聪炮肺何磐 罐篮 酒捞叼啊 促福搁
PostQuitMessage(0);
}
CUnicheck::CUnicheck()
{
// Uniwin_Init(hwnd);
}
CUnicheck::~CUnicheck()
{
Uniwin_TerminateCheckUniwin();
}
char* CUnicheck::ReturnUniteIP(char *Name)
{
LPHOSTENT lpHostEnt = gethostbyname((LPCTSTR)Name);
memset(UnitelIP,0,40);
if (lpHostEnt)
{
IN_ADDR inAddr;
memcpy((void*)&inAddr.S_un.S_addr, lpHostEnt->h_addr,lpHostEnt->h_length);
wsprintf(UnitelIP,"%d.%d.%d.%d",
inAddr.S_un.S_un_b.s_b1,
inAddr.S_un.S_un_b.s_b2,
inAddr.S_un.S_un_b.s_b3,
inAddr.S_un.S_un_b.s_b4);
return UnitelIP;
// m_strResult.Format("DWORD:%X,ToSTR: %d.%d.%d.%d",
// inAddr.S_un.S_addr,
// inAddr.S_un.S_un_b.s_b1,
// inAddr.S_un.S_un_b.s_b2,
// inAddr.S_un.S_un_b.s_b3,
// inAddr.S_un.S_un_b.s_b4);
}
return NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -