Beispiel #1
0
void CGateInfo::MakeNewUser(char *pszPacket)
{
    char				szDecodeMsg[256];
    char				szEncodeMsg[32];
    char				*pszID, *pszName, *pszPassword;
    _TDEFAULTMESSAGE	DefMsg;

    fnDecodeMessageA(&DefMsg, pszPacket);

    if (DefMsg.wIdent == CM_ADDNEWUSER)
    {
        int nPos = fnDecode6BitBufA((pszPacket + DEFBLOCKSIZE), szDecodeMsg, sizeof(szDecodeMsg));
        szDecodeMsg[nPos] = '\0';

        pszID		= &szDecodeMsg[0];

        pszName		= (char *)memchr(szDecodeMsg, '/', memlen(szDecodeMsg) - 1);
        *pszName = '\0';
        pszName++;

        pszPassword	= (char *)memchr(pszName, '/', memlen(pszName) - 1);
        *pszPassword = '******';
        pszPassword++;

        if ((memlen(pszID) - 1) || (memlen(pszName) - 1) || (memlen(pszPassword) - 1))
        {
            char szQuery[1024];
            sprintf( szQuery,
                     "INSERT TBL_ACCOUNT( FLD_LOGINID, FLD_PASSWORD, FLD_USERNAME, FLD_CERTIFICATION ) "
                     "VALUES( '%s', '%s', '%s', 0 )",
                     pszID, pszPassword, pszName );

            CRecordset *pRec = GetDBManager()->CreateRecordset();
            if ( pRec->Execute( szQuery ) && pRec->GetRowCount() )
                fnMakeDefMessageA( &DefMsg, SM_NEWID_SUCCESS, 0, 0, 0, 0 );
            else
                fnMakeDefMessageA( &DefMsg, SM_NEWID_FAIL, 0, 0, 0, 0 );
            GetDBManager()->DestroyRecordset( pRec );
            // -----------------------------------------------------------------------------------
        }
        else
            fnMakeDefMessageA(&DefMsg, SM_NEWID_FAIL, 0, 0, 0, 0);

        fnEncodeMessageA(&DefMsg, szEncodeMsg, sizeof(szEncodeMsg));

        szDecodeMsg[0] = '#';
        memmove(&szDecodeMsg[1], szEncodeMsg, DEFBLOCKSIZE);
        szDecodeMsg[DEFBLOCKSIZE + 1] = '!';
        szDecodeMsg[DEFBLOCKSIZE + 2] = '\0';

        send(sock, szDecodeMsg, DEFBLOCKSIZE + 2, 0);
    }
}
Beispiel #2
0
void CGateInfo::SendToGate(SOCKET cSock, char *pszPacket)
{
    char	szData[256];

    sprintf(szData, "%%%d/#%s!$", (int)cSock, pszPacket);

    int nLen = memlen(pszPacket) - 1;

    szData[0] = '%';

    char *pszNext = ValToAnsiStr((int)cSock, &szData[1]);

    *pszNext++ = '/';
    *pszNext++ = '#';

    memmove(pszNext, pszPacket, nLen);

    pszNext += nLen;

    *pszNext++ = '!';
    *pszNext++ = '$';
    *pszNext++ = '\0';

    //buf.len = pszNext - szData;
    //buf.buf = szData;
    SendToGate(szData,pszNext-szData);
//	WSASend(sock, &buf, 1, &dwSendBytes, 0, NULL, NULL);
}
Beispiel #3
0
void CGateInfo::SendToGate(SOCKET cSock, char *pszPacket)
{
	char	szData[256];
	WSABUF	buf;
	DWORD	dwSendBytes;
	
	int nLen = memlen(pszPacket) - 1;

	szData[0] = '%';
	
	char *pszNext = ValToAnsiStr((int)cSock, &szData[1]);
	
	*pszNext++ = '/';
	*pszNext++ = '#';

	memmove(pszNext, pszPacket, nLen);

	pszNext += nLen;

	*pszNext++ = '!';
	*pszNext++ = '$';
	*pszNext++ = '\0';

	buf.len = pszNext - szData;
	buf.buf = szData;

	WSASend(sock, &buf, 1, &dwSendBytes, 0, NULL, NULL);
}
Beispiel #4
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);
        }
    }
}
Beispiel #5
0
CMonRaceInfo* GetMonRaceInfo(char *pszMonName)
{
	int nCmpLen;
	int nLen = memlen(pszMonName) - 1;

	for (int i = 0; i < g_nNumOfMonRaceInfo; i++)
	{
		nCmpLen = memlen(g_pMonRaceInfo[i].szMonName) - 1;

		if (nCmpLen == nLen)
		{
			if (memcmp(g_pMonRaceInfo[i].szMonName, pszMonName, nLen) == 0)
				return &g_pMonRaceInfo[i];
		}
	}

	return NULL;
}
Beispiel #6
0
/*
 * Arguments: membuf_udata, offset (number)
 * Returns: value
 */
static int
mem_index (lua_State *L)
{
    if (lua_type(L, 2) == LUA_TNUMBER) {
	struct membuf *mb = checkudata(L, 1, MEM_TYPENAME);
	const int off = lua_tointeger(L, 2);
	const int type = memtype(mb);
	char *ptr = mb->data + memlen(type, off);

	switch (type) {
	case MEM_TCHAR:
	    lua_pushnumber(L, *((char *) ptr));
	    break;
	case MEM_TUCHAR:
	    lua_pushnumber(L, *((unsigned char *) ptr));
	    break;
	case MEM_TSHORT:
	    lua_pushnumber(L, *((short *) ptr));
	    break;
	case MEM_TUSHORT:
	    lua_pushnumber(L, *((unsigned short *) ptr));
	    break;
	case MEM_TINT:
	    lua_pushinteger(L, *((int *) ptr));
	    break;
	case MEM_TUINT:
	    lua_pushinteger(L, *((unsigned int *) ptr));
	    break;
	case MEM_TLONG:
	    lua_pushnumber(L, *((long *) ptr));
	    break;
	case MEM_TULONG:
	    lua_pushnumber(L, *((unsigned long *) ptr));
	    break;
	case MEM_TFLOAT:
	    lua_pushnumber(L, *((float *) ptr));
	    break;
	case MEM_TDOUBLE:
	    lua_pushnumber(L, *((double *) ptr));
	    break;
	case MEM_TNUMBER:
	    lua_pushnumber(L, *((lua_Number *) ptr));
	    break;
	case MEM_TBITSTRING:
	    lua_pushboolean(L, *(ptr - 1) & (1 << (off & 7)));
	    break;
	}
    } else {
	lua_getmetatable(L, 1);
	lua_replace(L, 1);
	lua_rawget(L, 1);
    }
    return 1;
}
Beispiel #7
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);
    }
}
Beispiel #8
0
void SendExToServer(char *pszPacket)
{
	DWORD	dwSendBytes;
	WSABUF	buf;

	buf.len = memlen(pszPacket) - 1;
	buf.buf = pszPacket;

	if ( WSASend(g_csock, &buf, 1, &dwSendBytes, 0, NULL, NULL) == SOCKET_ERROR )
	{
		int nErr = WSAGetLastError();
	}
}
Beispiel #9
0
void CStdItemSpecial::GetStandardItem(_LPTCLIENTITEMRCD lpClientItemRcd)
{
    memcpy(lpClientItemRcd->tStdItem.szName, szName, memlen(szName));

    lpClientItemRcd->tStdItem.btStdMode			= (BYTE)wStdMode;
    lpClientItemRcd->tStdItem.btShape			= (BYTE)wShape;
    lpClientItemRcd->tStdItem.btWeight			= (BYTE)wWeight;
    lpClientItemRcd->tStdItem.btAniCount		= (BYTE)wAniCount;
    lpClientItemRcd->tStdItem.btSource			= (BYTE)wSource;
//	lpClientItemRcd->tStdItem.btNeedIdentify	= (BYTE)g_pStdItemWeapon[nIdx].wNeedIdentify;
    lpClientItemRcd->tStdItem.wLooks			= (WORD)dwLooks;
    lpClientItemRcd->tStdItem.wDuraMax			= (WORD)wDuraMax;
    lpClientItemRcd->tStdItem.btNeed			= (BYTE)wNeed;
    lpClientItemRcd->tStdItem.btNeedLevel		= (BYTE)wNeedLevel;
    lpClientItemRcd->tStdItem.nPrice			= (UINT)dwPrice;
}
Beispiel #10
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 );
    }
}
Beispiel #11
0
void CWHAbusive::ChangeAbusiveText(char *pszText)
{
	int		nChange;
	char	*pszSrc, *pszFilter;

	for (int i = 0; i < m_nCount; i++)
	{
		pszSrc		= pszText;
		pszFilter	= &m_szAbusiveList[i][0];
		nChange		= 0;
		
		while (*pszSrc)
		{
			if (*pszSrc == *pszFilter)
			{
				nChange++;

				while (*pszFilter != 0)
				{
					if (*++pszSrc != *++pszFilter) break;

					nChange++;
				}

				if (*pszFilter == 0 && nChange >= (int)(memlen(&m_szAbusiveList[i][0]) - 1))
				{
					for (int nCnt = nChange; nCnt > 0; nCnt--)
						*(pszSrc - nCnt) = '*';
				}

				pszFilter	= &m_szAbusiveList[i][0];
				nChange		= 0;
			}

			pszSrc++;
		}
	}
}
UINT WINAPI ThreadFuncForMsg(LPVOID lpParameter)
{
	_TDEFAULTMESSAGE	DefaultMsg;
	char				*pszBegin, *pszEnd;
	int					nCount;
	PLISTNODE			pListNode;
	CGateInfo*			pGateInfo;

	while (TRUE)
	{
		if (g_xGateList.GetCount())
		{
			pListNode = g_xGateList.GetHead();

			while (pListNode)
			{
				pGateInfo = g_xGateList.GetData(pListNode);

				if (pGateInfo)
				{
					nCount = pGateInfo->g_SendToGateQ.GetCount();

					if (nCount)
					{
						for (int nLoop = 0; nLoop < nCount; nLoop++)
						{
							_LPTSENDBUFF pSendBuff = (_LPTSENDBUFF)pGateInfo->g_SendToGateQ.PopQ();

							if (pSendBuff)
							{
								int nLen = memlen(pSendBuff->szData);

								if ((pszBegin = (char *)memchr(pSendBuff->szData, '#', nLen)) &&(pszEnd = (char *)memchr(pSendBuff->szData, '!', nLen)))
								{
									*pszEnd = '\0';

									fnDecodeMessageA(&DefaultMsg, (pszBegin + 2));	// 2 = "#?" ? = Check Code 

									switch (DefaultMsg.wIdent)
									{
										case CM_PROTOCOL:
											break;
										case CM_IDPASSWORD:
											pGateInfo->ProcLogin(pSendBuff->sock, pszBegin + DEFBLOCKSIZE + 2);
											break;
										case CM_SELECTSERVER:
											pGateInfo->ProcSelectServer(pSendBuff->sock, DefaultMsg.wParam);
											break;
										case CM_ADDNEWUSER:
											pGateInfo->ProcAddUser(pSendBuff->sock, pszBegin + DEFBLOCKSIZE + 2);
											break;
										case CM_UPDATEUSER:
											break;
										case CM_CHANGEPASSWORD:
											break;
									}
								}

								delete pSendBuff;
								pSendBuff = NULL;
							}
						}
					}
				}

				pListNode = g_xGateList.GetNext(pListNode);
			}
		}

		SleepEx(1, TRUE);	
	}

	return 0;
}
Beispiel #13
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;
}
Beispiel #14
0
void CGateInfo::ProcSelectServer(SOCKET s, WORD wServerIndex)
{
    _TDEFAULTMESSAGE	DefMsg;
    char				szEncodePacket[128];
    char				szEncodeAllPacket[256];
    char				szEncodeMsg[24];
    char				*pServerIP;
    GAMESERVERINFO		*pServerInfo;

    PLISTNODE pListNode = xUserInfoList.GetHead();

    while (pListNode)
    {
        CUserInfo *pUserInfo = xUserInfoList.GetData(pListNode);

        if (pUserInfo->sock == s)
        {
            if (!pUserInfo->fSelServerOk)
            {
                fnMakeDefMessageA(&DefMsg, SM_SELECTSERVER_OK, 0, pUserInfo->nCertification, 0, 0);
                int nPos = fnEncodeMessageA(&DefMsg, szEncodeMsg, sizeof(szEncodePacket));
                szEncodeMsg[nPos] = '\0';

                for ( PLISTNODE pNode = g_xGameServerList.GetHead(); pNode; pNode = g_xGameServerList.GetNext( pNode ) )
                {
                    pServerInfo = g_xGameServerList.GetData( pNode );

                    if ( pServerInfo->index == wServerIndex )
                    {
                        pServerIP = pServerInfo->ip;
                        pServerInfo->connCnt++;
                        break;
                    }
                }

                if ( !pServerIP )
                    break;

                pUserInfo->nServerID = wServerIndex;

                int nPos2 = fnEncode6BitBufA((unsigned char *)pServerIP, szEncodePacket, memlen(pServerIP), sizeof(szEncodePacket));
                szEncodePacket[nPos2] = '\0';

                memmove(szEncodeAllPacket, szEncodeMsg, nPos);
                memmove(&szEncodeAllPacket[nPos], szEncodePacket, nPos2);
                szEncodeAllPacket[nPos + nPos2] = '\0';

                SendToGate(s, szEncodeAllPacket);

                pUserInfo->fSelServerOk = TRUE;

                pListNode = xUserInfoList.RemoveNode(pListNode);
            }
        }
        else
            pListNode = xUserInfoList.GetNext(pListNode);
    }
}
Beispiel #15
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;
}
Beispiel #16
0
void CGateInfo::ProcLogin(SOCKET s, char *pszData)
{
    char				szIDPassword[32];
    char				*pszID, *pszPassword;
    char				szEncodePacket[64];
    _TDEFAULTMESSAGE	DefMsg;
    int					nPos;
    char				szQuery[256];

    if (memlen(pszData) - 1 <= 0) return;

    PLISTNODE pListNode = xUserInfoList.GetHead();

    while (pListNode)
    {
        CUserInfo *pUserInfo = xUserInfoList.GetData(pListNode);

        if (pUserInfo->sock == s)
        {
            int nDecodeLen = fnDecode6BitBufA(pszData, szIDPassword, sizeof(szIDPassword));
            szIDPassword[nDecodeLen] = '\0';

            pszID		= &szIDPassword[0];

            if (pszPassword	= (char *)memchr(szIDPassword, '/', sizeof(szIDPassword)))
            {
                *pszPassword = '******';
                pszPassword++;

                sprintf( szQuery, "SELECT * FROM TBL_ACCOUNT WHERE FLD_LOGINID='%s'", pszID );

                CRecordset *pRec = GetDBManager()->CreateRecordset();

                if ( !pRec->Execute( szQuery ) || !pRec->Fetch() )
                    fnMakeDefMessageA( &DefMsg, SM_ID_NOTFOUND, 0, 0, 0, 0 );
                else if ( CompareDBString( pszPassword, pRec->Get( "FLD_PASSWORD" ) ) != 0 )
                    fnMakeDefMessageA( &DefMsg, SM_PASSWD_FAIL, 0, 0, 0, 0 );
                else
                {
                    int nCertCode = atoi( pRec->Get( "FLD_CERTIFICATION" ) );
                    /*
                    			if ( nCertCode > 0 && nCertCode < 30 )
                    				fnMakeDefMessageA(&DefMsg, SM_CERTIFICATION_FAIL, (nCertCode + 1), 0, 0, 0);
                    			else if ( nCertCode >= 30 )
                    				fnMakeDefMessageA(&DefMsg, SM_CERTIFICATION_FAIL, 1, 0, 0, 0);
                    			else*/
                    {
                        char szEncodeServerList[512];
                        char szEncodeAllPacket[1024];

                        fnMakeDefMessageA(&DefMsg, SM_PASSOK_SELECTSERVER, 0, 1, 0, 0);
                        nPos = fnEncodeMessageA(&DefMsg, szEncodePacket, sizeof(szEncodePacket));
                        szEncodePacket[nPos] = '\0';

                        int nPos2 = fnEncode6BitBufA((unsigned char *)g_szServerList, szEncodeServerList, memlen(g_szServerList), sizeof(szEncodeServerList));
                        szEncodeServerList[nPos2] = '\0';

                        memmove(szEncodeAllPacket, szEncodePacket, nPos);
                        memmove(&szEncodeAllPacket[nPos], szEncodeServerList, memlen(szEncodeServerList));

                        SendToGate(s, szEncodeAllPacket);

                        GetDBManager()->DestroyRecordset( pRec );

                        pUserInfo->nCertification = GetCertification();

                        //				pRec = GetDBManager()->CreateRecordset();
                        //				sprintf( szQuery,
                        //					"UPDATE TBL_ACCOUNT SET FLD_CERTIFICATION=%d WHERE FLD_LOGINID='%s'",
                        //					GetCertification(), pszID );
                        //				pRec->Execute( szQuery );

                        //				GetDBManager()->DestroyRecordset( pRec );

                        return;
                    }
                }

                GetDBManager()->DestroyRecordset( pRec );

                nPos = fnEncodeMessageA(&DefMsg, szEncodePacket, sizeof(szEncodePacket));
                szEncodePacket[nPos] = '\0';

                SendToGate(s, szEncodePacket);
            }
        }

        pListNode = xUserInfoList.GetNext(pListNode);
    }
}
Beispiel #17
0
/*
 * Arguments: membuf_udata, offset (number), value
 */
static int
mem_newindex (lua_State *L)
{
    struct membuf *mb = checkudata(L, 1, MEM_TYPENAME);
    const int off = lua_tointeger(L, 2);
    const int type = memtype(mb);
    char *ptr = mb->data + memlen(type, off);

    switch (lua_type(L, 3)) {
    case LUA_TNUMBER: {
	    lua_Number num = lua_tonumber(L, 3);

	    switch (type) {
	    case MEM_TCHAR:
		*((char *) ptr) = (char) num;
		break;
	    case MEM_TUCHAR:
		*((unsigned char *) ptr) = (unsigned char) num;
		break;
	    case MEM_TSHORT:
		*((short *) ptr) = (short) num;
		break;
	    case MEM_TUSHORT:
		*((unsigned short *) ptr) = (unsigned short) num;
		break;
	    case MEM_TINT:
		*((int *) ptr) = (int) num;
		break;
	    case MEM_TUINT:
		*((unsigned int *) ptr) = (unsigned int) num;
		break;
	    case MEM_TLONG:
		*((long *) ptr) = (long) num;
		break;
	    case MEM_TULONG:
		*((unsigned long *) ptr) = (unsigned long) num;
		break;
	    case MEM_TFLOAT:
		*((float *) ptr) = (float) num;
		break;
	    case MEM_TDOUBLE:
		*((double *) ptr) = (double) num;
		break;
	    case MEM_TNUMBER:
		*((lua_Number *) ptr) = num;
		break;
	    case MEM_TBITSTRING:
		luaL_argerror(L, 3, "boolean expected");
		break;
	    }
	}
	break;
    case LUA_TBOOLEAN:
	if (type != MEM_TBITSTRING)
	    luaL_argerror(L, 1, "bitstring expected");
	else {
	    const int bit = 1 << (off & 7);

	    --ptr;  /* correct address */
	    if (lua_toboolean(L, 3)) *ptr |= bit;  /* set */
	    else *ptr &= ~bit;  /* clear */
	}
	break;
    case LUA_TSTRING:
	{
	    size_t len;
	    const char *s = lua_tolstring(L, 3, &len);

	    memcpy(ptr, s, len);
	}
	break;
    default:
	luaL_argerror(L, 3, "membuf value expected");
    }
    return 0;
}
Beispiel #18
0
void CGateInfo::GetSelectCharacter(SOCKET s, char *pszPacket)
{
	char				szDecodeMsg[128];
	char				szServerIP[32];
	char				szEncodeMsg[32];
	char				szEncodeData[64];
	char				szEncodePacket[256];
	_TDEFAULTMESSAGE	DefaultMsg;
	
	// ORZ: Load Balancing, 접속수가 가장 적은 게이트 서버 IP 선택
	GAMESERVERINFO *pBestServer = NULL;
	GAMESERVERINFO *pTemp;

//	EnterCriticalSection( &g_xGameServerList.m_cs );
	for ( PLISTNODE pNode = g_xGameServerList.GetHead();pNode; pNode = g_xGameServerList.GetNext( pNode ) )
	{
		pTemp = g_xGameServerList.GetData( pNode );
		
		if ( !pBestServer || pTemp->connCnt < pBestServer->connCnt )
		{
			pBestServer = pTemp;
			continue;
		}
	}

	pBestServer->connCnt++;
//	LeaveCriticalSection( &g_xGameServerList.m_cs );

	strcpy( szServerIP, pBestServer->ip );
	// ORZ: from here

	int nPos = fnDecode6BitBufA(pszPacket, szDecodeMsg, sizeof(szDecodeMsg));
	szDecodeMsg[nPos] = '\0';

	char *pszDevide = (char *)memchr(szDecodeMsg, '/', nPos);
	
	if (pszDevide)
	{
		*pszDevide++ = '\0';

		// 서버 선택이 가능하도록 수정
		_TLOADHUMAN		tLoadHuman;
		CServerInfo*	pServerInfo;

		memcpy(tLoadHuman.szUserID, szDecodeMsg, memlen(szDecodeMsg));
		memcpy(tLoadHuman.szCharName, pszDevide, memlen(pszDevide));
		ZeroMemory(tLoadHuman.szUserAddr, sizeof(tLoadHuman.szUserAddr));
		tLoadHuman.nCertification = 0;

		PLISTNODE pListNode = g_xServerList.GetHead();

		if (pListNode)
			pServerInfo = g_xServerList.GetData(pListNode);

		GetLoadHumanRcd(pServerInfo, &tLoadHuman, 0);

		fnMakeDefMessageA(&DefaultMsg, SM_STARTPLAY, 0, 0, 0, 0);
		nPos = fnEncodeMessageA(&DefaultMsg, szEncodeMsg, sizeof(szEncodeMsg));
		int nPos2 = fnEncode6BitBufA((unsigned char *)szServerIP, szEncodeData, memlen(szServerIP) -1, sizeof(szEncodeData));
		
		memmove(szEncodePacket, szEncodeMsg, nPos);
		memmove(&szEncodePacket[nPos], szEncodeData, nPos2);
		szEncodePacket[nPos + nPos2] = '\0';
		
		// ORZ: 전체 리스트에 추가한다.
		// 같은 아이디가 이미 존재하거나 메모리 부족등의 이유로 실패할 수 있다.
//		if ( GetGlobalUserList()->Insert( tLoadHuman.szCharName, szServerIP ) )
			SendToGate(s, szEncodePacket);
//		else
//		{
//			fnMakeDefMessageA(&DefaultMsg, SM_STARTFAIL, 0, 0, 0, 0);
//			nPos = fnEncodeMessageA(&DefaultMsg, szEncodeMsg, sizeof(szEncodeMsg));
//			szEncodeMsg[nPos] = '\0';
			
//			SendToGate(pGateInfo->sock, s, szEncodeMsg);
//		}
	}
}