Skip to content

Commit 6a87b8e

Browse files
committed
Daily Log & 디버깅용 코드 삭제 및 로그에서 정상적으로 출력되지 않는 한글 수정
1 parent af16a75 commit 6a87b8e

File tree

9 files changed

+34
-40
lines changed

9 files changed

+34
-40
lines changed

iocpServer/iocpServer/Iocp.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ bool IOCP_Server::initServer()
66

77
int nRet = WSAStartup(MAKEWORD(2, 2), &wsaData);
88
if (0 != nRet) {
9-
spdlog::error("WSAStartup() 함수 실패 : {}", WSAGetLastError());
9+
spdlog::error("WSAStartup() Function failure : {}", WSAGetLastError());
1010
return false;
1111
}
1212

1313
//연결지향형 TCP , Overlapped I/O 소켓을 생성
1414
listenSocket = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, NULL, WSA_FLAG_OVERLAPPED);
1515

1616
if (INVALID_SOCKET == listenSocket) {
17-
spdlog::error("socket() 함수 실패 : {}", WSAGetLastError());
17+
spdlog::error("socket() Function failure : {}", WSAGetLastError());
1818
return false;
1919
}
2020

@@ -36,15 +36,15 @@ bool IOCP_Server::BindandListen(const u_short port)
3636
//int nRet = ::bind(listenSocket, (SOCKADDR*)&stServerAddr, sizeof(SOCKADDR_IN));
3737
int nRet = ::bind(listenSocket, reinterpret_cast<sockaddr *>(&stServerAddr), sizeof(SOCKADDR_IN));
3838
if (0 != nRet) {
39-
spdlog::error("bind() 함수 실패 : {}", WSAGetLastError());
39+
spdlog::error("bind() Function failure : {}", WSAGetLastError());
4040
return false;
4141
}
4242

4343
// 접속 요청을 받아들이기 위해 cIOCompletionPort소켓을 등록하고
4444
// 접속 대기큐를 5개로 설정 한다.
4545
nRet = ::listen(listenSocket, 5);
4646
if (0 != nRet) {
47-
spdlog::error("listen() 함수 실패 : {}", WSAGetLastError());
47+
spdlog::error("listen() Function failure : {}", WSAGetLastError());
4848
return false;
4949
}
5050

@@ -62,7 +62,7 @@ bool IOCP_Server::StartServer()
6262
// CompletionPort객체 생성 요청을 한다.
6363
g_hiocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, NULL, MAX_WORKERTHREAD);
6464
if (NULL == g_hiocp) {
65-
spdlog::error("CreateIoCompletionPort() 함수 실패 : {}", GetLastError());
65+
spdlog::error("CreateIoCompletionPort() Function failure : {}", GetLastError());
6666
return false;
6767
}
6868

@@ -168,14 +168,12 @@ void IOCP_Server::WokerThread()
168168
// client가 접속을 끊었을때..
169169
if (FALSE == bSuccess || (0 == dwIoSize && TRUE == bSuccess))
170170
{
171-
spdlog::info("Socket 접속 끊김 / [unique_id:{}]", (int)pPlayerSession->get_unique_id());
172-
spdlog::info("Total Packet Count : {}", packet_cnt);
171+
spdlog::info("Socket Disconnected / [unique_id:{}]", (int)pPlayerSession->get_unique_id());
173172
ClosePlayer(pPlayerSession->get_unique_id());
174173
CloseSocket(pPlayerSession);
175174
continue;
176175
}
177176

178-
179177
stOverlappedEx* pOverlappedEx = (stOverlappedEx*)lpOverlapped;
180178
// Overlapped I/O Recv작업 결과 뒤 처리
181179
switch (pOverlappedEx->m_eOperation) {
@@ -193,7 +191,8 @@ void IOCP_Server::WokerThread()
193191
default:
194192
{
195193
// 예외 상황
196-
spdlog::critical("[Exception WokerThread({})] No value defined..!", (int)pOverlappedEx->m_eOperation);
194+
spdlog::critical("[Exception WokerThread({})] No value defined..! / [unique_id:{}]",
195+
(int)pOverlappedEx->m_eOperation, pPlayerSession->get_unique_id());
197196
}
198197
break;
199198

@@ -261,7 +260,7 @@ bool IOCP_Server::SendPacket(class PLAYER_Session * pPlayerSession, char * pMsg,
261260
// socket_error이면 client socket이 끊어진걸로 처리한다.
262261
if (nRet == SOCKET_ERROR && (WSAGetLastError() != ERROR_IO_PENDING))
263262
{
264-
spdlog::error("WSASend() 함수 실패 : {}", WSAGetLastError());
263+
spdlog::error("WSASend() Function failure : {} / [unique_id:{}]", WSAGetLastError(), pPlayerSession->get_unique_id());
265264
ClosePlayer(pPlayerSession->get_unique_id());
266265
CloseSocket(pPlayerSession);
267266
return false;
@@ -274,7 +273,7 @@ void IOCP_Server::OnRecv(struct stOverlappedEx* pOver, int ioSize)
274273
// 플레이어 세션 에서 플레이어 데이터 가져오기
275274
auto pTempPlayerSession = player_session.find(pOver->m_unique_id); // getPlayerSession(pOver->m_unique_id);
276275
if (pTempPlayerSession == player_session.end()) {
277-
spdlog::error("No Exit Session [unique_id:{}]", pOver->m_unique_id);
276+
spdlog::error("No Exit Session / [unique_id:{}]", pOver->m_unique_id);
278277
return;
279278
}
280279
auto pPlayerSession = pTempPlayerSession->second;
@@ -285,7 +284,7 @@ void IOCP_Server::OnRecv(struct stOverlappedEx* pOver, int ioSize)
285284
// 쓰기를 위한 위치를 옮겨준다.
286285
if (!pPlayerSession->get_buffer().moveWritePos(ioSize))
287286
{
288-
spdlog::error("ReadBuffer Over Flow [unique_id:{}]", pPlayerSession->get_unique_id());
287+
spdlog::error("ReadBuffer Over Flow / [unique_id:{}]", pPlayerSession->get_unique_id());
289288
}
290289

291290
PACKET_HEADER header;
@@ -309,7 +308,7 @@ void IOCP_Server::OnRecv(struct stOverlappedEx* pOver, int ioSize)
309308
// Packet_Header 를 가져온다.
310309
auto PacketSize = pPlayerSession->get_buffer().getHeaderSize((char*)&header, sizeof(header));
311310
if (PacketSize == -1) {
312-
spdlog::error("getHeaderSize [unique_id:{}]", pPlayerSession->get_unique_id());
311+
spdlog::error("getHeaderSize / [unique_id:{}]", pPlayerSession->get_unique_id());
313312
}
314313

315314
if (pPlayerSession->get_buffer().getReadAbleSize() < header.packet_len || header.packet_len <= PACKET_HEADER_BYTE) {
@@ -318,7 +317,7 @@ void IOCP_Server::OnRecv(struct stOverlappedEx* pOver, int ioSize)
318317
header.packet_len, PACKET_HEADER_BYTE, pPlayerSession->get_buffer().getReadAbleSize(), header.packet_len, pPlayerSession->get_unique_id());
319318
// Packet 사이즈가 Header 크기보다 작을 경우 Error count를 올린다.
320319
if (header.packet_len <= PACKET_HEADER_BYTE) {
321-
pPlayerSession->set_error_cnt();
320+
pPlayerSession->update_error_cnt();
322321
}
323322
break;
324323
}
@@ -401,7 +400,7 @@ void IOCP_Server::AccepterThread()
401400
// I/O Completion Port객체와 소켓을 연결시킨다.
402401
bool bRet = BindIOCompletionPort(pPlayerSession);
403402
if (false == bRet) {
404-
spdlog::error("BindIOCompletionPort() 함수 실패 : {}", GetLastError());
403+
spdlog::error("BindIOCompletionPort() Function failure : {}", GetLastError());
405404
CloseSocket(pPlayerSession);
406405
continue;
407406
}
@@ -423,12 +422,12 @@ void IOCP_Server::AccepterThread()
423422

424423
char clientIP[32] = { 0, };
425424
inet_ntop(AF_INET, &(client_addr.sin_addr), clientIP, 32 - 1);
426-
spdlog::info("[접속] Client IP : {} / SOCKET : {} / [unique_id:{}]", clientIP, (int)pPlayerSession->get_sock(), pPlayerSession->get_unique_id());
425+
spdlog::info("[Connect] Client IP : {} / SOCKET : {} / [unique_id:{}]", clientIP, (int)pPlayerSession->get_sock(), pPlayerSession->get_unique_id());
427426

428427
// Recv Overlapped I/O작업을 요청해 놓는다.
429428
bRet = BindRecv(pPlayerSession, 0);
430429
if (false == bRet) {
431-
spdlog::error("BindRecv() 함수 실패 [unique_id:{}]", pPlayerSession->get_unique_id());
430+
spdlog::error("BindRecv() Function failure / [unique_id:{}]", pPlayerSession->get_unique_id());
432431
ClosePlayer(pPlayerSession->get_unique_id());
433432
CloseSocket(pPlayerSession);
434433
continue;
@@ -443,7 +442,7 @@ bool IOCP_Server::BindIOCompletionPort(class PLAYER_Session * pPlayerSession)
443442
auto hIOCP = CreateIoCompletionPort((HANDLE)pPlayerSession->get_sock(), g_hiocp, (ULONG_PTR)(pPlayerSession), 0);
444443

445444
if (NULL == hIOCP || g_hiocp != hIOCP) {
446-
spdlog::error("CreateIoCompletionPort() 함수 실패 : {} / [unique_id:{}]", GetLastError(), pPlayerSession->get_unique_id());
445+
spdlog::error("CreateIoCompletionPort() Function failure : {} / [unique_id:{}]", GetLastError(), pPlayerSession->get_unique_id());
447446
return false;
448447
}
449448

@@ -460,7 +459,7 @@ bool IOCP_Server::BindRecv(class PLAYER_Session * pPlayerSession, int remainSize
460459
pPlayerSession->get_buffer().checkWrite(remainSize);
461460
}
462461

463-
//Overlapped I/O을 위해 각 정보를 셋팅해 준다.
462+
// Overlapped I/O을 위해 각 정보를 셋팅해 준다.
464463
wBuf.len = MAX_SOCKBUF;
465464
wBuf.buf = pPlayerSession->get_buffer().getWriteBuffer();
466465
pPlayerSession->get_Recv_over().m_eOperation = IOOperation::RECV;
@@ -475,9 +474,9 @@ bool IOCP_Server::BindRecv(class PLAYER_Session * pPlayerSession, int remainSize
475474
(LPWSAOVERLAPPED) & (pPlayerSession->get_Recv_over()),
476475
NULL);
477476

478-
//socket_error이면 client socket이 끊어진걸로 처리한다.
477+
// socket_error이면 client socket이 끊어진걸로 처리한다.
479478
if (nRet == SOCKET_ERROR && (WSAGetLastError() != ERROR_IO_PENDING)) {
480-
spdlog::error("WSARecv() 함수 실패 : {} / [unique_id:{}]", WSAGetLastError(), pPlayerSession->get_unique_id());
479+
spdlog::error("WSARecv() Function failure : {} / [unique_id:{}]", WSAGetLastError(), pPlayerSession->get_unique_id());
481480
ClosePlayer(pPlayerSession->get_unique_id());
482481
CloseSocket(pPlayerSession);
483482
return false;

iocpServer/iocpServer/Library/Api.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void Logic_API::API_Thread()
7272
{
7373
AuthRoute* auth = new AuthRoute();
7474
auth->ApiProcessing(packet);
75-
//delete[] auth;
75+
delete auth;
7676
}
7777
break;
7878

@@ -95,7 +95,7 @@ void Logic_API::API_Thread()
9595
break;
9696

9797
default:
98-
spdlog::error("ProcessPacket ProtocolType ({} / {})이 없습니다 / [unique_id:{}]", packet.packet_type, protocolBase, packet.unique_id);
98+
spdlog::error("ProcessPacket ProtocolType ({} / {})is not found..! / [unique_id:{}]", packet.packet_type, protocolBase, packet.unique_id);
9999
break;
100100

101101
}

iocpServer/iocpServer/Library/L_Auth.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ AuthRoute::AuthRoute()
66

77
AuthRoute::~AuthRoute()
88
{
9-
std::cout << "~AuthRoute()" << std::endl;
109
}
1110

1211
void AuthRoute::ApiProcessing(Packet_Frame packet)
@@ -15,34 +14,30 @@ void AuthRoute::ApiProcessing(Packet_Frame packet)
1514
case CLIENT_AUTH_TEST:
1615
{
1716
//std::cout << "CLIENT_AUTH_TEST" << std::endl;
18-
packet_cnt++;
1917
}
2018
break;
2119

2220
case CLIENT_AUTH_TEST2:
2321
{
2422
//std::cout << "CLIENT_AUTH_TEST2" << std::endl;
25-
packet_cnt++;
2623
}
2724
break;
2825

2926
case CLIENT_AUTH_TEST3:
3027
{
3128
//std::cout << "CLIENT_AUTH_TEST3" << std::endl;
32-
packet_cnt++;
3329
}
3430
break;
3531

3632
case CLIENT_AUTH_TEST4:
3733
{
3834
//std::cout << "CLIENT_AUTH_TEST4" << std::endl;
39-
packet_cnt++;
4035
}
4136
break;
4237

4338
default:
4439
{
45-
std::cout << "[Error] ApiProcessing ProtocolType( AuthRoute / " << packet.packet_type << " )ÀÌ ¾ø½À´Ï´Ù..!" << std::endl;
40+
spdlog::error("L_Auth->ApiProcessing ProtocolType ({})is not found..! / [unique_id:{}]", packet.packet_type, packet.unique_id);
4641
}
4742
break;
4843
}

iocpServer/iocpServer/Main.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
class IOCP_Server iocp_server;
44
class SERVER_Timer timer;
55
class Logic_API api;
6-
int packet_cnt;
76
std::queue<Packet_Frame> recvPacketQueue;
87
std::unordered_map<unsigned __int64, class PLAYER *> player;
98
std::unordered_map<unsigned __int64, class PLAYER_Session *> player_session;
109

1110
int main() {
1211
// daily Logger Start
13-
//auto daily_logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 0, 0); // 00:00 new log
14-
//spdlog::set_default_logger(daily_logger);
15-
16-
packet_cnt = 0;
12+
auto daily_logger = spdlog::daily_logger_mt("daily_logger", "logs/iocpServer.txt", 0, 0); // 00:00 new log
13+
daily_logger->flush_on(spdlog::level::debug);
14+
spdlog::set_default_logger(daily_logger);
15+
16+
// Server Packet Info
1717
spdlog::info("Client Start Packet No : {}", CLIENT_BASE);
1818
spdlog::info("Max Client Packet No : {}", MAX_CLIENT_PROTOCOL_NO);
1919
spdlog::info("Server Start Packet No : {}", SERVER_BASE);
2020
spdlog::info("Max Server Packet No : {}\n", MAX_SERVER_PROTOCOL_NO);
2121

22+
// Server Start
2223
iocp_server.initServer(); // Socket 생성
2324
iocp_server.BindandListen(SERVERPORT); // Listen 처리
2425
iocp_server.initClient(); // Player Init

iocpServer/iocpServer/Main.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
#pragma comment(lib, "ws2_32.lib")
55

66
#define _WINSOCK_DEPRECATED_NO_WARNINGS // 윈속 오류 방지
7-
#define MAX_CONNECT 40 // 최대 접속 인원
8-
#define MAX_WORKERTHREAD 9 // 쓰레드 풀에 넣을 쓰레드 수
9-
#define DEBUG_MODE TRUE // printf 출력 여부
107

118
// Header 선언
129
#include <WinSock2.h>
@@ -45,5 +42,4 @@ extern class Logic_API api;
4542
extern std::queue<Packet_Frame> recvPacketQueue;
4643
extern std::unordered_map<unsigned __int64, class PLAYER *> player; // 플레이어 데이터
4744
extern std::unordered_map<unsigned __int64, class PLAYER_Session *> player_session; // 플레이어 세션
48-
extern int packet_cnt;
4945
#endif

iocpServer/iocpServer/Protocol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
#define UNIQUE_START_NO 1000 // 고유번호 시작
88
#define MAX_SOCKBUF 4096 // 최대 패킷 사이즈
99
#define MAX_PLAYER 10 // 최대 접속 인원
10+
#define MAX_WORKERTHREAD 9 // 쓰레드 풀에 넣을 쓰레드 수
1011
#define PACKET_HEADER_BYTE 4 // Packet Header 크기
1112
#define LIMIT_ERROR_CNT 5 // 최대 오류 개수
1213

14+
1315
// 프로토콜 타입
1416
const enum ProtocolType {
1517
None = 0,

iocpServer/iocpServer/Session.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void PLAYER_Session::set_init_session()
1313
unique_id = 0;
1414
}
1515

16-
void PLAYER_Session::set_error_cnt()
16+
void PLAYER_Session::update_error_cnt()
1717
{
1818
// Call Error += 1
1919
error_cnt += 1;

iocpServer/iocpServer/Session.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class PLAYER_Session {
4747
// set
4848
void set_unique_id(const unsigned __int64 id);
4949
void set_init_session();
50-
void set_error_cnt();
50+
void update_error_cnt();
5151

5252
private:
5353
SOCKET m_socketSession; // Cliet와 연결되는 소켓

iocpServer/iocpServer/iocpServer.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<SDLCheck>false</SDLCheck>
9090
<ConformanceMode>true</ConformanceMode>
9191
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
92+
<MultiProcessorCompilation>true</MultiProcessorCompilation>
9293
</ClCompile>
9394
<Link>
9495
<SubSystem>Console</SubSystem>

0 commit comments

Comments
 (0)