void CDBProcess::ReConnectODBC(CDatabase *m_db, const char *strdb, const char *strname, const char *strpwd) { char strlog[256]; memset( strlog, 0x00, 256); CTime t = CTime::GetCurrentTime(); sprintf_s(strlog, 256, "[%d-%d %d:%d] Trying to reconnect to ODBC...\r\n", t.GetMonth(), t.GetDay(), t.GetHour(), t.GetMinute()); LogFileWrite( strlog ); // DATABASE 연결... CString strConnect; strConnect.Format (_T("DSN=%s;UID=%s;PWD=%s"), strdb, strname, strpwd); int iCount = 0; do{ iCount++; if( iCount >= 4 ) break; m_db->SetLoginTimeout(10); try { m_db->OpenEx((LPCTSTR )strConnect, CDatabase::noOdbcDialog); } catch( CDBException* e ) { e->Delete(); } }while(!m_db->IsOpen()); }
int OutputJSONBuffer(json_t *js, LogFileCtx *file_ctx, MemBuffer **buffer) { if (file_ctx->sensor_name) { json_object_set_new(js, "host", json_string(file_ctx->sensor_name)); } if (file_ctx->is_pcap_offline) { json_object_set_new(js, "pcap_filename", json_string(PcapFileGetFilename())); } if (file_ctx->prefix) { MemBufferWriteRaw((*buffer), file_ctx->prefix, file_ctx->prefix_len); } OutputJSONMemBufferWrapper wrapper = { .buffer = buffer, .expand_by = OUTPUT_BUFFER_SIZE }; int r = json_dump_callback(js, OutputJSONMemBufferCallback, &wrapper, file_ctx->json_flags); if (r != 0) return TM_ECODE_OK; LogFileWrite(file_ctx, *buffer); return 0; }
int CSharedMemQueue::PutData(char *pBuf, int size) { char logstr[256]; memset( logstr, 0x00, 256); BYTE BlockMode; int index = 0, count = 0; if( (DWORD)size > m_wOffset ) { sprintf( logstr, "DataSize Over.. - %d bytes\r\n", size ); LogFileWrite( logstr ); return SMQ_PKTSIZEOVER; } do { if( m_pHeader->RearMode == W ) { aa(); count++; continue; } m_pHeader->RearMode = W; m_pHeader->WritePid = ::GetCurrentThreadId(); // writing side (game server) is multi thread aa(); // no operation function if( m_pHeader->WritePid != ::GetCurrentThreadId() ) { count++; continue; } LONG pQueue = m_lReference + (m_pHeader->Rear * m_wOffset); BlockMode = GetByte( (char*)pQueue, index ); if( BlockMode == WR && m_pHeader->nCount >= MAX_COUNT-1 ) { m_pHeader->RearMode = WR; return SMQ_FULL; } index = 0; SetByte( (char*)pQueue, WR, index ); // Block Mode Set to WR -> Data Exist SetShort( (char*)pQueue, size, index ); SetString( (char*)pQueue, pBuf, size, index ); m_pHeader->nCount++; m_pHeader->Rear = (m_pHeader->Rear + 1) % MAX_COUNT; m_pHeader->RearMode = WR; break; } while( count < 50 ); if( count >= 50 ) { m_pHeader->RearMode = WR; return SMQ_WRITING; } return 1; }
void CAISocket::CloseProcess() { CString logstr; CTime time = CTime::GetCurrentTime(); logstr.Format("*** CloseProcess - socketID=%d... *** %d-%d-%d, %d:%d]\r\n", m_Sid, time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute() ); LogFileWrite( logstr ); Initialize(); CIOCPSocket2::CloseProcess(); }
CProgramLog::~CProgramLog() { DeleteCriticalSection(&m_kCritical); char buf[128]; char tmpTime[32]; char tmpDate[32]; _strtime(tmpTime); _strdate(tmpDate); sprintf(buf, "EndTime: 【%s %s】\r\n", tmpDate, tmpTime); LogFileWrite(buf, strlen(buf)); }
void CGameSocket::CloseProcess() { CString logstr; CTime time = CTime::GetCurrentTime(); logstr.Format("*** CloseProcess - socketID=%d ... sSid = %d *** %d-%d-%d, %d:%d]\r\n", m_Sid, m_sSocketID, time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute() ); LogFileWrite( logstr ); TRACE("*** CloseProcess - socketID=%d ... sSid = %d *** \n", m_Sid, m_sSocketID); m_pMain->DeleteAllUserList(m_sSocketID); Initialize(); CIOCPSocket2::CloseProcess(); }
CProgramLog::CProgramLog() { m_dwLastClearTime = 0; m_bShowPrint = true; InitializeCriticalSection(&m_kCritical); char buf[128]; char tmpTime[32]; char tmpDate[32]; _strtime(tmpTime); _strdate(tmpDate); sprintf(buf, "BeginTime: 【%s %s】\r\n", tmpDate, tmpTime); LogFileWrite(buf, strlen(buf)); }
int CSharedMemQueue::GetData( char* pBuf ) { int index = 0, size = 0, temp_front = 0; BYTE BlockMode; if( m_pHeader->FrontMode == R ) return SMQ_READING; m_pHeader->FrontMode = R; m_pHeader->ReadPid = _getpid(); // reading side ( agent ) is multi process ( one process -> act each single thread ) aa(); // no operation function if( m_pHeader->ReadPid != _getpid() ) { m_pHeader->FrontMode = WR; return SMQ_READING; } LONG pQueue = m_lReference + (m_pHeader->Front * m_wOffset); index = 0; BlockMode = GetByte( (char *)pQueue, index ); if( BlockMode == E ) { m_pHeader->FrontMode = WR; if( m_pHeader->Front < m_pHeader->Rear || (m_pHeader->Front > m_pHeader->Rear && m_pHeader->Front > MAX_COUNT-100) ) { temp_front = (m_pHeader->Front + 1) % MAX_COUNT; m_pHeader->Front = temp_front; m_pHeader->nCount--; char logstr[256]; memset( logstr, 0x00, 256 ); sprintf( logstr, "SMQ EMPTY Block Find - F:%d, R:%d\n", m_pHeader->Front, m_pHeader->Rear); LogFileWrite( logstr ); TRACE(logstr); } return SMQ_EMPTY; } size = GetShort( (char*)pQueue, index ); GetString( pBuf, (char*)pQueue, size, index ); m_pHeader->nCount--; temp_front = (m_pHeader->Front + 1) % MAX_COUNT; m_pHeader->Front = temp_front; memset( (void*)pQueue, 0x00, m_wOffset ); m_pHeader->FrontMode = WR; return size; }
void DisplayErrorMsg(SQLHANDLE hstmt) { SQLCHAR SqlState[6], Msg[1024]; SQLINTEGER NativeError; SQLSMALLINT i, MsgLen; SQLRETURN rc2; char logstr[512]; memset( logstr, NULL, 512 ); i = 1; while ((rc2 = SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, i, SqlState, &NativeError, Msg, sizeof(Msg), &MsgLen)) != SQL_NO_DATA) { sprintf( logstr, "*** %s, %d, %s, %d ***\r\n", SqlState,NativeError,Msg,MsgLen ); LogFileWrite( logstr ); // TRACE("*** %s, %d, %s, %d ***\n", SqlState,NativeError,Msg,MsgLen); i++; } }
BOOL CSharedMemQueue::InitailizeMMF(DWORD dwOffsetsize, int maxcount, LPCTSTR lpname, BOOL bCreate ) { char logstr[256]; memset( logstr, 0x00, 256); if( maxcount < 1 ) return FALSE; DWORD dwfullsize = dwOffsetsize * maxcount + sizeof(_SMQ_HEADER); m_nMaxCount = maxcount; m_wOffset = dwOffsetsize; if( bCreate ) m_hMMFile = CreateFileMapping( (HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE, 0, dwfullsize, lpname ); else m_hMMFile = OpenFileMapping( FILE_MAP_ALL_ACCESS, TRUE, lpname ); if( m_hMMFile == NULL ) { strcpy( logstr , "Shared Memory Open Fail!!\r\n" ); LogFileWrite( logstr ); return FALSE; } m_lpMMFile = (char *)MapViewOfFile(m_hMMFile, FILE_MAP_WRITE, 0, 0, 0); if( !m_lpMMFile ) return FALSE; TRACE("%s Address : %x\n", lpname, m_lpMMFile); m_bMMFCreate = bCreate; m_pHeader = (_SMQ_HEADER *)m_lpMMFile; m_lReference = (LONG)(m_lpMMFile + sizeof(_SMQ_HEADER)); // 초기 위치 셋팅 if( bCreate ) { memset( m_lpMMFile, 0x00, dwfullsize ); m_pHeader->Rear = m_pHeader->Front = 0; m_pHeader->nCount = 0; m_pHeader->RearMode = m_pHeader->FrontMode = E; m_pHeader->CreatePid = _getpid(); } return TRUE; }
void CProgramLog::Log(int nlevel, const char *szText, ...) { #ifndef NO_PROGRAM_LOG if (m_bMultithreading) EnterCriticalSection(&m_kCritical); ++m_dwLogCount; int iPos = 0; iPos += sprintf(m_szBuffer + iPos, "【%05d】", m_dwLogCount); char tmpTime[32]; _strtime(tmpTime); iPos += sprintf(m_szBuffer + iPos, "【%s】 ", tmpTime); va_list args; va_start(args, szText); iPos += _vsnprintf(m_szBuffer + iPos, 6 * 1024 - 50, szText, args); m_szBuffer[iPos] = '\r'; m_szBuffer[iPos + 1] = '\n'; m_szBuffer[iPos + 2] = '\0'; //m_szBuffer[iPos] = '\n'; //m_szBuffer[iPos + 1] = '\0'; if (m_bShowPrint) printf(m_szBuffer); #ifdef WIN32 OutputDebugStringA(m_szBuffer); #endif if (nlevel < 1) { LogFileWrite(m_szBuffer, iPos + 2); } va_end(args); if (m_bMultithreading) LeaveCriticalSection(&m_kCritical); #endif }
BOOL CIOCPSocket2::Accept( SOCKET listensocket, struct sockaddr* addr, int* len ) { m_Socket = accept( listensocket, addr, len); if( m_Socket == INVALID_SOCKET) { int err = WSAGetLastError(); TRACE("Socket Accepting Fail - %d\n", err); char logstr[1024]; memset( logstr, NULL, 1024 ); sprintf( logstr, "Socket Accepting Fail - %d\r\n", err); LogFileWrite( logstr ); return FALSE; } struct linger lingerOpt; lingerOpt.l_onoff = 1; lingerOpt.l_linger = 0; setsockopt(m_Socket, SOL_SOCKET, SO_LINGER, (const char *)&lingerOpt, sizeof(lingerOpt)); return TRUE; }
// happens on character selection void CUser::SetLogInInfoToDB(BYTE bInit) { int index = 0, send_index = 0, retvalue = 0, addrlen = 20; char send_buff[256], strClientIP[20]; memset( send_buff, NULL, 256); memset( strClientIP, 0x00, 20 ); _ZONE_SERVERINFO *pInfo = NULL; struct sockaddr_in addr; pInfo = m_pMain->m_ServerArray.GetData( m_pMain->m_nServerNo ); if( !pInfo ) { CString logstr; logstr.Format("%d Server Info Invalid User Closed...\r\n", m_pMain->m_nServerNo ); LogFileWrite( logstr ); Close(); } getpeername(m_Socket, (struct sockaddr*)&addr, &addrlen ); strcpy( strClientIP, inet_ntoa(addr.sin_addr) ); SetByte(send_buff, WIZ_LOGIN_INFO, send_index); SetShort(send_buff, m_Sid, send_index); SetKOString(send_buff, m_strAccountID, send_index); SetKOString(send_buff, m_pUserData->m_id, send_index); SetKOString(send_buff, pInfo->strServerIP, send_index); SetShort(send_buff, _LISTEN_PORT, send_index); SetKOString(send_buff, strClientIP, send_index); SetByte(send_buff, bInit, send_index); retvalue = m_pMain->m_LoggerSendQueue.PutData( send_buff, send_index ); if( retvalue >= SMQ_FULL ) { char logstr[256]; memset( logstr, 0x00, 256 ); sprintf( logstr, "UserInfo Send Fail : %d", retvalue); m_pMain->m_StatusList.AddString(logstr); } }
int OutputJSONBuffer(json_t *js, LogFileCtx *file_ctx, MemBuffer *buffer) { if (file_ctx->sensor_name) { json_object_set_new(js, "host", json_string(file_ctx->sensor_name)); } if (file_ctx->prefix) MemBufferWriteRaw(buffer, file_ctx->prefix, file_ctx->prefix_len); int r = json_dump_callback(js, MemBufferCallback, buffer, JSON_PRESERVE_ORDER|JSON_COMPACT|JSON_ENSURE_ASCII| #ifdef JSON_ESCAPE_SLASH JSON_ESCAPE_SLASH #else 0 #endif ); if (r != 0) return TM_ECODE_OK; LogFileWrite(file_ctx, buffer); return 0; }
DWORD WINAPI AcceptThread(LPVOID lp) { CIOCPort* pIocport = (CIOCPort*) lp; WSANETWORKEVENTS network_event; DWORD wait_return; int sid; CIOCPSocket2* pSocket = NULL; char logstr[1024]; memset( logstr, NULL, 1024 ); struct sockaddr_in addr; int len; while(1) { wait_return = WaitForSingleObject( pIocport->m_hListenEvent, INFINITE); if(wait_return == WAIT_FAILED) { TRACE("Wait failed Error %d\n", GetLastError()); char logstr[1024]; memset( logstr, NULL, 1024 ); sprintf( logstr, "Wait failed Error %d\r\n", GetLastError()); LogFileWrite( logstr ); return 1; } WSAEnumNetworkEvents( pIocport->m_ListenSocket, pIocport->m_hListenEvent, &network_event); if(network_event.lNetworkEvents &FD_ACCEPT) { if(network_event.iErrorCode[FD_ACCEPT_BIT] == 0 ) { sid = pIocport->GetNewSid(); if(sid < 0) { TRACE("Accepting User Socket Fail - New Uid is -1\n"); char logstr[1024]; memset( logstr, NULL, 1024 ); sprintf( logstr, "Accepting User Socket Fail - New Uid is -1\r\n"); LogFileWrite( logstr ); goto loop_pass_accept; } pSocket = pIocport->GetIOCPSocket( sid ); if( !pSocket ) { TRACE("Socket Array has Broken...\n"); char logstr[1024]; memset( logstr, NULL, 1024 ); sprintf( logstr, "Socket Array has Broken...\r\n"); LogFileWrite( logstr ); // pIocport->PutOldSid( sid ); // Invalid sid must forbidden to use goto loop_pass_accept; } len = sizeof(addr); if( !pSocket->Accept( pIocport->m_ListenSocket, (struct sockaddr *)&addr, &len ) ) { TRACE("Accept Fail %d\n", sid); char logstr[1024]; memset( logstr, NULL, 1024 ); sprintf( logstr, "Accept Fail %d\r\n", sid); LogFileWrite( logstr ); pIocport->RidIOCPSocket( sid, pSocket ); pIocport->PutOldSid( sid ); goto loop_pass_accept; } pSocket->InitSocket( pIocport ); if( !pIocport->Associate( pSocket, pIocport->m_hServerIOCPort ) ) { TRACE("Socket Associate Fail\n"); char logstr[1024]; memset( logstr, NULL, 1024 ); sprintf( logstr, "Socket Associate Fail\r\n"); LogFileWrite( logstr ); pSocket->CloseProcess(); pIocport->RidIOCPSocket( sid, pSocket ); pIocport->PutOldSid( sid ); goto loop_pass_accept; } // Crytion //pSocket->SendCryptionKey(); // 암호화 // ~ pSocket->Receive(); TRACE("Success Accepting...%d\n", sid); } loop_pass_accept: continue; } } return 1; }
void CGameSocket::RecvUserInfo(char* pBuf) { // TRACE("RecvUserInfo()\n"); int index = 0; short uid=-1, sHp, sMp, sLength = 0; BYTE bNation, bLevel, bZone, bAuthority=1; short sDamage, sAC; float fHitAgi, fAvoidAgi; char strName[MAX_ID_SIZE+1]; memset(strName, 0x00, MAX_ID_SIZE+1); // short sItemAC; BYTE bTypeLeft; BYTE bTypeRight; short sAmountLeft; short sAmountRight; // uid = GetShort( pBuf, index ); sLength = GetShort( pBuf, index ); if( sLength > MAX_ID_SIZE || sLength <= 0 ) { char countstr[256]; memset( countstr, NULL, 256 ); CTime cur = CTime::GetCurrentTime(); sprintf( countstr, "RecvUserInfo() Fail : %d월 %d일 %d시 %d분 - uid=%d, name=%s\r\n", cur.GetMonth(), cur.GetDay(), cur.GetHour(), cur.GetMinute(), uid, strName); LogFileWrite( countstr ); TRACE("### RecvUserInfo() Fail ---> uid = %d, name=%s ### \n", uid, strName); return; } GetString(strName, pBuf, sLength, index); bZone = GetByte( pBuf, index ); bNation = GetByte( pBuf, index ); bLevel = GetByte( pBuf, index ); sHp = GetShort( pBuf, index ); sMp = GetShort( pBuf, index ); sDamage = GetShort( pBuf, index ); sAC = GetShort( pBuf, index ); fHitAgi = Getfloat( pBuf, index ); fAvoidAgi = Getfloat( pBuf, index ); // sItemAC = GetShort(pBuf, index); bTypeLeft = GetByte(pBuf, index); bTypeRight = GetByte(pBuf, index); sAmountLeft = GetShort(pBuf, index); sAmountRight = GetShort(pBuf, index); bAuthority = GetByte(pBuf, index); // //CUser* pUser = m_pMain->GetActiveUserPtr(uid); //if( pUser == NULL ) return; CUser* pUser = new CUser; pUser->Initialize(); pUser->m_iUserId = uid; strcpy(pUser->m_strUserID, strName); pUser->m_curZone = bZone; pUser->m_pMap = m_pMain->GetZoneByID(bZone); pUser->m_bNation = bNation; pUser->m_sLevel = bLevel; pUser->m_sHP = sHp; pUser->m_sMP = sMp; //pUser->m_sSP = sSp; pUser->m_sHitDamage = sDamage; pUser->m_fHitrate = fHitAgi; pUser->m_fAvoidrate = fAvoidAgi; pUser->m_sAC = sAC; pUser->m_bLive = USER_LIVE; // pUser->m_sItemAC = sItemAC; pUser->m_bMagicTypeLeftHand = bTypeLeft; pUser->m_bMagicTypeRightHand = bTypeRight; pUser->m_sMagicAmountLeftHand = sAmountLeft; pUser->m_sMagicAmountRightHand = sAmountRight; pUser->m_byIsOP = bAuthority; // TRACE("**** RecvUserInfo()---> uid = %d, name=%s, leng=%d ******\n", uid, strName, sLength); if(uid >= USER_BAND && uid < MAX_USER) { m_pMain->m_pUser[uid] = pUser; } _USERLOG* pUserLog = NULL; pUserLog = new _USERLOG; pUserLog->t = CTime::GetCurrentTime(); pUserLog->byFlag = USER_LOGIN; pUserLog->byLevel = pUser->m_sLevel; strcpy( pUserLog->strUserID, pUser->m_strUserID ); pUser->m_UserLogList.push_back( pUserLog ); }