Ejemplo n.º 1
0
void CGateInfo::ReceiveOpenUser(char *pszPacket)
{
    char	*pszPos;
    int		nSocket;
    int		nLen = memlen(pszPacket);

    if (pszPos = (char *)memchr(pszPacket, '/', nLen))
    {
        nSocket = AnsiStrToVal(pszPacket);

        pszPos++;

        CUserInfo* pUserInfo = new CUserInfo;

        if (pUserInfo)
        {
            MultiByteToWideChar(CP_ACP, 0, pszPacket, -1, pUserInfo->szSockHandle, sizeof(pUserInfo->szSockHandle)/sizeof(TCHAR));
            MultiByteToWideChar(CP_ACP, 0, pszPos, -1, pUserInfo->szAddress, sizeof(pUserInfo->szAddress)/sizeof(TCHAR));

            pUserInfo->sock					= nSocket;
            pUserInfo->nCertification		= 0;
            pUserInfo->nClientVersion		= 0;
            pUserInfo->fSelServerOk			= FALSE;

            ZeroMemory(pUserInfo->szUserID, sizeof(pUserInfo->szUserID));

            xUserInfoList.AddNewNode(pUserInfo);

            InsertLogMsgParam(IDS_OPEN_USER, pUserInfo->szAddress);
        }
    }
}
Ejemplo n.º 2
0
void CGateInfo::ReceiveCloseUser(char *pszPacket)
{
	int nSocket = AnsiStrToVal(pszPacket);
/*
	map<SOCKET, CUserInfo, less<SOCKET> >::iterator it = pGateInfo->UserInfoMap.find((SOCKET)nSocket);

	if (it != pGateInfo->UserInfoMap.end())
	{
		InsertLogMsgParam(IDS_CLOSE_USER, it->second.szAddress);

		pGateInfo->UserInfoMap.erase(it);
	} */
}
Ejemplo n.º 3
0
void CGateInfo::ReceiveSendUser(char *pszPacket)
{
    char	*pszPos;
    int		nSocket;
    int		nLen = memlen(pszPacket);

    if ((pszPos = (char *)memchr(pszPacket, '/', nLen)))
    {
        nSocket = AnsiStrToVal(pszPacket);

        pszPos++;

        _LPTSENDBUFF lpSendUserData = new _TSENDBUFF;

        lpSendUserData->sock		= (SOCKET)nSocket;

        memmove(lpSendUserData->szData, pszPos, memlen(pszPos));

        g_SendToGateQ.PushQ((BYTE *)lpSendUserData);
    }
}
Ejemplo n.º 4
0
void CGateInfo::ReceiveServerMsg(char *pszPacket)
{
    char		*pszPos;
    int			nCertification;
    int			nLen = memlen(pszPacket);

    if (pszPos = (char *)memchr(pszPacket, '/', nLen))
    {
        *pszPos++ = '\0';
        nCertification = AnsiStrToVal(pszPos);

        char szQuery[256];
        sprintf( szQuery,
                 "UPDATE TBL_ACCOUNT SET FLD_CERTIFICATION=%d WHERE FLD_LOGINID='%s'",
                 nCertification, pszPacket );

        CRecordset *pRec = GetDBManager()->CreateRecordset();
        pRec->Execute( szQuery );
        GetDBManager()->DestroyRecordset( pRec );
    }
}
Ejemplo n.º 5
0
DWORD WINAPI ServerWorkerThread(LPVOID CompletionPortID)
{
	DWORD				dwBytesTransferred;

	CServerInfo*		pServerInfo;

	LPOVERLAPPED		lpOverlapped;

	DWORD				dwFlags;
	DWORD				dwRecvBytes;

	char				szBuff[DATA_BUFSIZE];
	int					nBuffLen;
	char				*pszFirst, *pszEnd, *pszDivide;

	LONG				lValid;
	WORD				w1, w2;
	char				szCC[32];
	int					nPos;

	while (TRUE)
	{
		GetQueuedCompletionStatus((HANDLE)CompletionPortID, &dwBytesTransferred, (LPDWORD)&pServerInfo, (LPOVERLAPPED *)&lpOverlapped, INFINITE);
		
		if (g_fTerminated) return 0L;

		if (dwBytesTransferred == 0)
		{
			closesocket(pServerInfo->m_sock);
			if (pServerInfo) GlobalFree(pServerInfo);

			UpdateStatusBarSession(FALSE);
			
			continue;
		}

		if (pServerInfo->nOvFlag == OVERLAPPED_RECV)
		{
			if (pServerInfo->nRemainBuffLen)
			{
				memmove(szBuff, pServerInfo->RemainBuff, pServerInfo->nRemainBuffLen); // Copy previous remain data in szBuff
				memmove(&szBuff[pServerInfo->nRemainBuffLen], pServerInfo->Buffer, dwBytesTransferred + 1); // Append new received data in szBuff

				nBuffLen = pServerInfo->nRemainBuffLen + dwBytesTransferred;

				pszEnd = &szBuff[0];
			}
			else
			{
				pszEnd		= &pServerInfo->Buffer[0];
				nBuffLen	= dwBytesTransferred;
			}

			while (nBuffLen)
			{
				if ((pszFirst = (char *)memchr(pszEnd, '#', nBuffLen)) && (pszEnd = (char *)memchr(pszFirst, '!', nBuffLen)))
				{
					*pszEnd++ = '\0';

					if (pszDivide = (char *)memchr(pszFirst, '/', pszEnd - pszFirst))
					{
						*pszDivide++ = '\0';

						_LPTSENDBUFF lpSendUserData = new _TSENDBUFF;

						if (lpSendUserData)
						{
							lpSendUserData->nCertification = AnsiStrToVal(pszFirst + 1);

							w1 = lpSendUserData->nCertification	^ 0xAA;
							w2 = memlen(pszDivide) - 1;
							lValid = MAKELONG(w1, w2);
							
							nPos = fnEncode6BitBufA((unsigned char *)&lValid, szCC, sizeof(LONG), sizeof(szCC));
							szCC[nPos] = '\0';

							if (memcmp((pszEnd - nPos - 1), szCC, nPos) == 0)
							{
								fnDecodeMessageA(&lpSendUserData->DefMsg, pszDivide);

								*(pszEnd - nPos - 1) = '\0';

								if (lpSendUserData->DefMsg.wIdent >= 100 && lpSendUserData->DefMsg.wIdent <= 200)
								{
									lpSendUserData->pServerInfo = pServerInfo;

									switch (lpSendUserData->DefMsg.wIdent)
									{
										case DB_MAKEITEMRCD2:
										{
											lpSendUserData->lpbtAddData = new BYTE[sizeof(_TMAKEITEMRCD)];
											fnDecode6BitBufA((pszDivide + DEFBLOCKSIZE), (char *)lpSendUserData->lpbtAddData, sizeof(_TMAKEITEMRCD));

											lpSendUserData->lpbtAddData2 = NULL;

											break;
										}
										default:
										{
											nPos = fnDecode6BitBufA((pszDivide + DEFBLOCKSIZE), (char *)&lpSendUserData->HumanLoad, sizeof(lpSendUserData->HumanLoad));
				
											switch (lpSendUserData->DefMsg.wIdent)
											{
												case DB_MAKEITEMRCD:
												{
													lpSendUserData->lpbtAddData = new BYTE[sizeof(_TMAKEITEMRCD)];
													fnDecode6BitBufA((pszDivide + DEFBLOCKSIZE + 75), (char *)lpSendUserData->lpbtAddData, sizeof(_TMAKEITEMRCD));

													lpSendUserData->lpbtAddData2 = NULL;
													break;
												}
												case DB_SAVEHUMANRCD:
												{
													lpSendUserData->lpbtAddData = new BYTE[sizeof(_THUMANRCD)];
													fnDecode6BitBufA((pszDivide + DEFBLOCKSIZE + 75), (char *)lpSendUserData->lpbtAddData, sizeof(_THUMANRCD));

													int nRemainLen = (int)(pszEnd - pszFirst) - (DEFBLOCKSIZE + 75 + HUMANRCDBLOCKSIZE);

													lpSendUserData->lpbtAddData2 = new BYTE[nRemainLen + 1];

													memcpy(lpSendUserData->lpbtAddData2, (pszDivide + DEFBLOCKSIZE + 75 + HUMANRCDBLOCKSIZE), nRemainLen);
													lpSendUserData->lpbtAddData2[nRemainLen] = '\0';

													break;
												}
												default:
													lpSendUserData->lpbtAddData		= NULL;
													lpSendUserData->lpbtAddData2	= NULL;
											}

											break;
										}
									}
									
									g_DBMsgQ.PushQ((BYTE *)lpSendUserData);
								}
								else
									g_ServerMsgQ.PushQ((BYTE *)lpSendUserData);
							}
							else
								delete lpSendUserData;
						}
					}
					
					nBuffLen -= (pszEnd - pszFirst);
				}
				else
					break;
			} // while

			if (pszFirst && nBuffLen)
			{
				memmove(pServerInfo->RemainBuff, pszFirst, nBuffLen);
				pServerInfo->nRemainBuffLen = nBuffLen;
#ifdef _DEBUG
				_RPT2(_CRT_WARN, "Remain Packet : %d, %s\n", nBuffLen, pszFirst);
#endif
			}
			else
				pServerInfo->nRemainBuffLen = 0;

			// Set next overlapped Process
			dwFlags = 0;

			ZeroMemory(&(pServerInfo->Overlapped), sizeof(OVERLAPPED));

			pServerInfo->DataBuf.len	= DATA_BUFSIZE;
			pServerInfo->DataBuf.buf	= pServerInfo->Buffer;
			pServerInfo->nOvFlag		= OVERLAPPED_RECV;

			if (WSARecv(pServerInfo->m_sock, &(pServerInfo->DataBuf), 1, &dwRecvBytes, &dwFlags, &(pServerInfo->Overlapped), NULL) == SOCKET_ERROR)
			{
				if (WSAGetLastError() != ERROR_IO_PENDING)
				{
					InsertLogMsg(_T("WSARecv() failed"));
					
//					CloseSession(pServerInfo);
					continue;
				}
			}
		} // if (OVERLAPPED_RECV)
	}

	return 0;
}
Ejemplo n.º 6
0
void CGateInfo::ReceiveCloseUser(char *pszPacket)
{
    int nSocket = AnsiStrToVal(pszPacket);
}
Ejemplo n.º 7
0
void ProcReceiveBuffer(char *pszPacket, int nRecv)
{
	int					nBuffLen = nRecv;
	char				szBuff[DATA_BUFSIZE];
	char				*pszFirst, *pszEnd = &szBuff[0], *pszDevide;
	_TDEFAULTMESSAGE	DefMsg;
	_TDEFAULTMESSAGE	SendDefMsg;
	int					nCertification;
	WORD				w1, w2;
	LONG				lValid;
	int					nPos;
	char				szCC[32];
	char				szEncodeMsg[256];

	CReadyUserInfo		*pReadUserInfo;
	CUserInfo			*pUserInfo;

	_TCLIENTITEMRCD		tClientItemRcd;

	if (g_nRemainBuffLen)
		memmove(szBuff, g_szRemainBuff, g_nRemainBuffLen);

	memmove(&szBuff[g_nRemainBuffLen], pszPacket, nBuffLen + 1);

	nBuffLen += g_nRemainBuffLen;

	while (nBuffLen)
	{
		if ((pszFirst = (char *)memchr(pszEnd, '#', nBuffLen)) && (pszEnd = (char *)memchr(pszFirst, '!', nBuffLen)))
		{
			*pszEnd++ = '\0';

			if (pszDevide = (char *)memchr(pszFirst, '/', pszEnd - pszFirst))
			{
				*pszDevide++ = '\0';

				nCertification = AnsiStrToVal(pszFirst + 1);

				w1 = nCertification	^ 0xAA;
				w2 = memlen(pszDevide) - 1;
				lValid = MAKELONG(w1, w2);
				
				nPos = fnEncode6BitBufA((unsigned char *)&lValid, szCC, sizeof(LONG), sizeof(szCC));
				szCC[nPos] = '\0';

				if (memcmp((pszEnd - nPos - 1), szCC, nPos) == 0)
				{
					fnDecodeMessageA(&DefMsg, pszDevide);

					*(pszEnd - nPos - 1) = '\0';

					switch (DefMsg.wIdent)
					{
						case DBR_LOADHUMANRCD2:
						{
							CReadyUserInfo2*	pReadyUserInfo2 = new CReadyUserInfo2;

							pReadyUserInfo2->m_dwReadyStartTime = GetTickCount();
							pReadyUserInfo2->m_nNumOfGenItem	= HIBYTE(DefMsg.wParam);
							pReadyUserInfo2->m_nNumOfMagic		= DefMsg.wSeries;
							pReadyUserInfo2->m_nNumOfItem		= LOBYTE(DefMsg.wParam);

							fnDecode6BitBufA((pszDevide + DEFBLOCKSIZE), (char *)&pReadyUserInfo2->m_THumanRcd, sizeof(_THUMANRCD));
							
							memmove(pReadyUserInfo2->pszData, pszDevide + DEFBLOCKSIZE + HUMANRCDBLOCKSIZE, memlen(pszDevide + DEFBLOCKSIZE + HUMANRCDBLOCKSIZE));

							g_xReadyUserInfoList2.AddNewNode(pReadyUserInfo2);

							break;
						}
						case DBR_LOADHUMANRCD:
						{
							pReadUserInfo = (CReadyUserInfo *)DefMsg.nRecog;

							nPos = fnDecode6BitBufA((pszDevide + DEFBLOCKSIZE), (char *)&pReadUserInfo->m_pUserInfo->m_THumanRcd, sizeof(_THUMANRCD));

							char *pszData;

							pszData = (pszDevide + DEFBLOCKSIZE + HUMANRCDBLOCKSIZE);

							if (HIBYTE(DefMsg.wParam))		// Decode General Item
							{
								pReadUserInfo->m_pUserInfo->m_nNumOfGenItems = HIBYTE(DefMsg.wParam);

								_TGENITEMRCD	GenItemRcd;
								char			szVal[5];						

								for (int i = 0; i < HIBYTE(DefMsg.wParam); i++)
								{
									_LPTGENERALITEMRCD lptGenItemRcd = new _TGENERALITEMRCD;

									if (lptGenItemRcd)
									{
										fnDecode6BitBufA(pszData, (char *)&GenItemRcd, sizeof(_TGENITEMRCD));
										
										memcpy(lptGenItemRcd->szMakeIndex, GenItemRcd.szItem, 12);

										ZeroMemory(szVal, sizeof(szVal));

										memcpy(szVal, &lptGenItemRcd->szMakeIndex[1], 3);
										lptGenItemRcd->nStdIndex	= AnsiStrToVal(szVal);
										memcpy(szVal, &lptGenItemRcd->szMakeIndex[4], 4);
										lptGenItemRcd->nDura		= AnsiStrToVal(szVal);
										memcpy(szVal, &lptGenItemRcd->szMakeIndex[8], 4);
										lptGenItemRcd->nDuraMax		= AnsiStrToVal(szVal);

										pReadUserInfo->m_pUserInfo->m_lpTGenItemRcd.AddNewNode(lptGenItemRcd);
								
										pszData += GENITEMRCDBLOCKSIZE;
									}
								}
							}								  

							if (DefMsg.wSeries)		// Decode Magic
							{
								pReadUserInfo->m_pUserInfo->m_nNumOfMagics = DefMsg.wSeries;

								for (int i = 0; i < DefMsg.wSeries; i++)
								{
									_LPTHUMANMAGICRCD lpHumanMagicRcd = new _THUMANMAGICRCD;

									if (lpHumanMagicRcd)
									{
										fnDecode6BitBufA(pszData, (char *)lpHumanMagicRcd, sizeof(_THUMANMAGICRCD));
										pReadUserInfo->m_pUserInfo->m_lpTMagicRcd.AddNewNode(lpHumanMagicRcd);
										pszData += MAGICRCDBLOCKSIZE;

//#ifdef _DEBUG
//										_RPT3(_CRT_WARN, "%d - %d - %d\n", lpHumanMagicRcd->btLevel, lpHumanMagicRcd->btUseKey, lpHumanMagicRcd->nCurrTrain);
//#endif
									}
								}
							}								  

							if (LOBYTE(DefMsg.wParam))		// Decode Item
							{
								pReadUserInfo->m_pUserInfo->m_nNumOfItems = LOBYTE(DefMsg.wParam);
		//						pReadUserInfo->m_pUserInfo->m_lpTItemRcd = (_LPTUSERITEMRCD)GlobalAlloc(GPTR, sizeof(_TUSERITEMRCD) * DefMsg.wParam);

								for (int i = 0; i < LOBYTE(DefMsg.wParam); i++)
								{
									_LPTUSERITEMRCD lpTItemRcd = new _TUSERITEMRCD;

									if (lpTItemRcd)
									{
										fnDecode6BitBufA(pszData, (char *)lpTItemRcd, sizeof(_TUSERITEMRCD));
										pReadUserInfo->m_pUserInfo->m_lpTItemRcd.AddNewNode(lpTItemRcd);
										pszData += ITEMRCDBLOCKSIZE;
									}
								}
							}

							if (DefMsg.wTag)		// Decode Horse
							{
								if (!pReadUserInfo->m_pUserInfo->m_lpTHorseRcd)
									pReadUserInfo->m_pUserInfo->m_lpTHorseRcd = new _THORSERCD;

								fnDecode6BitBufA(pszData, (char *)pReadUserInfo->m_pUserInfo->m_lpTHorseRcd, sizeof(_THORSERCD));
							}

							if (pReadUserInfo->m_pUserInfo->m_pxPlayerObject)
							{
								pReadUserInfo->m_pUserInfo->m_pxPlayerObject->MakeFeature();
								pReadUserInfo->m_pUserInfo->m_pxPlayerObject->Initialize();
								pReadUserInfo->m_pUserInfo->m_pxPlayerObject->m_fIsAlive	= TRUE;

								pReadUserInfo->m_pUserInfo->m_btCurrentMode	= USERMODE_PLAYGAME;
							}

							break;
						}
						case DBR_MAKEITEMRCD:
						{
							pUserInfo = (CUserInfo *)DefMsg.nRecog;

							_LPTUSERITEMRCD lpTItemRcd = new _TUSERITEMRCD;

							if (lpTItemRcd)
							{
								nPos = fnDecode6BitBufA((pszDevide + DEFBLOCKSIZE), (char *)lpTItemRcd, sizeof(_TUSERITEMRCD));
								
								pUserInfo->m_lpTItemRcd.AddNewNode(lpTItemRcd);

								fnMakeDefMessage(&SendDefMsg, SM_ADDITEM, (int)pUserInfo->m_pxPlayerObject, 0, 0, 1);

								if (lpTItemRcd->szMakeIndex[0] != 'G')
								{
									g_pStdItemSpecial[lpTItemRcd->nStdIndex].GetStandardItem(&tClientItemRcd);
									g_pStdItemSpecial[lpTItemRcd->nStdIndex].GetUpgradeStdItem(&tClientItemRcd, lpTItemRcd);
								}

								memcpy(tClientItemRcd.szMakeIndex, lpTItemRcd->szMakeIndex, 12);
								
								tClientItemRcd.nDura		= lpTItemRcd->nDura;
								tClientItemRcd.nDuraMax		= lpTItemRcd->nDuraMax;

								nPos = 	fnEncode6BitBufA((unsigned char *)&tClientItemRcd, szEncodeMsg, sizeof(_TCLIENTITEMRCD), sizeof(szEncodeMsg));
								szEncodeMsg[nPos] = '\0';

								pUserInfo->m_pxPlayerObject->SendSocket(&SendDefMsg, szEncodeMsg);
							}

							break;
						}
						case DBR_MAKEITEMRCD2:
						{
							CPlayerObject* pPlayerObject = (CPlayerObject *)DefMsg.nRecog;
							
							pUserInfo = pPlayerObject->m_pUserInfo;
							
							_LPTUSERITEMRCD lpTItemRcd = new _TUSERITEMRCD;

							if (lpTItemRcd)
							{
								nPos = fnDecode6BitBufA((pszDevide + DEFBLOCKSIZE), (char *)lpTItemRcd, sizeof(_TUSERITEMRCD));
								
								pUserInfo->m_lpTItemRcd.AddNewNode(lpTItemRcd);

								fnMakeDefMessage(&SendDefMsg, SM_ADDITEM, (int)pUserInfo->m_pxPlayerObject, 0, 0, 1);

								if (lpTItemRcd->szMakeIndex[0] != 'G')
								{
									g_pStdItemSpecial[lpTItemRcd->nStdIndex].GetStandardItem(&tClientItemRcd);
									g_pStdItemSpecial[lpTItemRcd->nStdIndex].GetUpgradeStdItem(&tClientItemRcd, lpTItemRcd);
								}

								memcpy(tClientItemRcd.szMakeIndex, lpTItemRcd->szMakeIndex, 12);
								
								tClientItemRcd.nDura		= lpTItemRcd->nDura;
								tClientItemRcd.nDuraMax		= lpTItemRcd->nDuraMax;

								nPos = 	fnEncode6BitBufA((unsigned char *)&tClientItemRcd, szEncodeMsg, sizeof(_TCLIENTITEMRCD), sizeof(szEncodeMsg));
								szEncodeMsg[nPos] = '\0';

								pUserInfo->m_pxPlayerObject->SendSocket(&SendDefMsg, szEncodeMsg);
							}

							break;
						}
					}
				}
			}

			nBuffLen -= (pszEnd - pszFirst);
		}
		else
			break;
	} // while

	if (pszFirst && (nBuffLen > 0))
	{
		memmove(g_szRemainBuff, pszFirst, nBuffLen);
		g_nRemainBuffLen = nBuffLen;
#ifdef _DEBUG
	_RPT2(_CRT_WARN, "ProcReceiveBuffer:%d, %s\n", g_nRemainBuffLen, pszFirst);
#endif
	}
	else
		g_nRemainBuffLen = 0;
}