게임서버/namespace univ_dev(21)
-
Login Server
안녕하세요 대학생개발자입니다. 오랜만에 제 원래 전공으로 돌아왔습니다. 오늘은 오랜만에 서버에 대한 포스팅으로 돌아왔는데요. 이전까지는 데이터베이스에 대한 설치와 간단한 쿼리를 익히는게 시간을 쓰느라 포스팅에 지연이 있었습니다. 그럼 시작하도록 하겠습니다. 우선 이전까지는 채팅서버를 만들었었습니다. 일반적으로 우리가 아는 채팅서버라는건 로그인이라는 과정을 통해서 인증을 받은 유저들에 한해서 접근이 가능하도록 설계가 되어있을겁니다. 생각해보면 너무나도 당연한 얘기입니다. 로그인도 하지않은 유저가 채팅서버에 들어와서 채팅 메시지를 보낸다는건 상식적으로 봤을때 정상적으로 보이지 않는 것 같습니다. 반대의 경우도 마찬가지입니다. 로그인도 안한 유저가 로그인이 되어있는 유저의 채팅을 받아 본다는것도 말이안되는건 ..
2022.05.19 -
Chatting Server(Multi Thread)
안녕하세요 대학생개발자입니다. 이번글의 목적은 저번글에 이어서 채팅서버에 대한 다 하지 못한 얘기를 해볼까합니다. 이전 글에서 다뤘던 내용이지만 채팅 서버의 구조는 다음과 같았습니다. 메시지를 처리하는 1개의 스레드와 그 외에 IO를 처리하는 워커 스레드들... 그리고 그 워커 스레드들에게서 하나의 큐를 통해 Job을 전달받는 메시지 처리 스레드가 존재했었습니다. 이 구조에서는 메시지 처리 스레드는 메시지가 없으면 큐가 계속 비었는지 있는지 확인하는 방식의 폴링을 채택했었습니다. 물론 이벤트를 이용해서 폴링을 하지 않고 잠들게 할 수 있었지만, 그렇게 하지 않고 그냥 폴링을 통해 하나의 cpu를 계속 사용하도록 만들었었습니다. 이부분에서는 장점도 있고 당연히 단점도 있을겁니다. 우선 장점으로는 구현이 매..
2022.05.04 -
NetServer(Chatting Server)
안녕하세요 대학생개발자입니다. 여전히 저는 할일이 많이 남았습니다. 사실 요샌 거의 이론보단 실제 개발에 치중해 있다보니 블로그 글을 쓸 일이 크게 없는것 같습니다. 예전에 LanServer, LanClient 서버와 서버간의 연결에서의 서버, 클라이언트 역할을 하게될 두개의 클래스에 대한 소개를 했었습니다. 이제 시작할 부분은 실제 유저인 클라이언트와 연결을 담당할 외부로 노출될 서버를 개발하게 되었습니다. 뭐... 이름이 바뀌었다고 해서 기능이 크게 달라지진 않았습니다. 대부분의 기능은 LanServer와 동일할겁니다. 뭐... 컨텐츠 쪽의 로직이 많이 달라지겠지만 그건 지금 네트워크 라이브러리에게 중요한것은 아닙니다. 우리가 중요하게 여겨야 할 부분은 네트워크를 타고 흐르는 패킷에 대한 보안입니다...
2022.05.03 -
LockFreeStack Trouble Shooting
안녕하세요 대학생 개발자입니다. 락프리에 대한 언급이 있었던지 1주일쯤 지났습니다. 아마 보신분들이 실제로 개발을 해보셨을지는 모르겠습니다만 락프리 알고리즘을 구글링했을때 나오는 의사코드를 보고 코딩을 하셨던분들은 간단히 테스트 해봤을때에는 전혀 문제가 발생하지 않았을겁니다. 하지만 여러 스레드에서 초당 몇백만건의 push, pop을 하게되면 여러 문제가 발생할 수 있는데요. 그럼 시작하도록 하겠습니다. 그래서 무슨문제가 발생하는데? 아마 이 부분이 제일 궁금할 것 같습니다. 저도 이 문제를 찾기위해서 거의 2주일 가까운 시간을 소모하면서 메모리 로그를 봤던 것 같습니다. 사실 이 트러블슈팅의 과정을 올리는게 맞는지 모르겠습니다만... 뭐 이건 제 포트폴리오가 될것이니 이런것도 올려도 상관없을 것 같다는..
2022.03.28 -
DumpClass
안녕하세요 대학생 개발자입니다. 이번 글에서는 예외에 대한 핸들링에 대한 부분과 덤프클래스에 대해서 정리를 해보려고합니다. 우리가 0을 분모로 나눗셈을 하려고 하거나 혹은 new에서 메모리가 할당이 되지 않은 이런 경우를 포함 다수 경우에 예외가 발생하게 됩니다. 그리고 이 예외는 c runtime library가 처리를 하거나 혹은 os가 처리할 수 도있겠죠. 우리는 이 예외에대한 모든 핸들링 처리를 우리 코드로 돌리는 작업을 할겁니다. 그리고 예외가 발생했을때 덤프를 남겨 우리가 확인할 수 있게 할겁니다. 그리고 최근 글을 보신분들은 아시겠지만 덤프에대한 구현을 하려는게 아니라 왜 덤프를 써야하는지 왜 에러를 직접 핸들링 해야되는지에 대한 베이직한 이론내용이 들어가지 구현에 대한 부분은 언급하고있지 ..
2022.03.28 -
LockFree
안녕하세요 대학생 개발자입니다. 정말 오랜만에 글을 남기게 되었습니다. 한동안 락프리 개발에 시간을 많이 들였습니다.. 사실 락프리라는 알고리즘이 나온지 얼마 안된 기술은 아닙니다. 문서상에 언급되는것만 해도 거의 10년이상된 오래된 기술입니다. 그런데 제가 이런걸 공부하는데 왜 이렇게 오래걸리게 되었냐하면 락프리는 순수하게 멀티스레딩으로 잘 작동되는지 확인이 필요합니다. 사실 만드는 시간보다 검증하고 에러 수정하는 작업에 더 많은 기간을 소모했던것 같습니다. 그리고 락프리 스택과 큐를 사용하기 위해서는 또 다른 문제가 생기는데 이부분에 대해서는 제가 나중에 글을 통해서 언급하도록 하겠습니다. 그럼 시작하겠습니다. 왜 락프리냐? 아마 일반적으로 락프리를 사용하는 경우라면 다음과 같은 경우일겁니다. 너무 ..
2022.03.22 -
Network Library - LanServer,LanClient
안녕하세요 대학생 개발자입니다. 마지막 글을 올리고 나서 아주 오랜 시간이 흘렀습니다. 사실 이 테스트를 올릴까 말까 고민을 했었는데 말입니다... 이 내용은 새로운 지식이라기보다는 제가 만든 서버에 대한 구현만 있기 때문에 따로 올릴까 말까 고민했었는데 말입니다... 그래도 일단은 쓰기로 했습니다... 이번 글은 그냥 저 혼자 끄적이는 느낌이 강하고 따로 새로운 지식이 들어가는 부분도 아니기 때문에 크게 고민 없이 술술 읽으셔도 될 것 같습니다. 그리고 가장 중요한 점... 크게 유익 한글은 아닐 겁니다. 직전 글에서는 IOCP에 대한 주의사항과 문제가 될 수 있는 점을 정리했었습니다. 그리고 한동안 그를 바탕으로 주의하며 에코 더미 테스트를 했었습니다. 추가로 서버와 서버 간 통신을 하기 위한 서버 ..
2022.03.03 -
MMO_TCPFighter
안녕하세요 대학생 개발자입니다 이번글에서는 저번에 AsyncSelect 모델로 만들었었던 클라이언트의 서버를 만들어 볼 예정입니다. MMO식으로 바꿔서 약 7천명의 더미 봇들을 넣고 테스트를 해볼겁니다. 소켓 모델에 대해서 소개를 해야겠습니다. MMO라고 하면 일반적으로 IOCP를 떠올리시겠지만... 이번프로젝트는 여전히 싱글스레드 + select모델입니다. (왜냐... 아직 멀티스레드에 대한 언급을 안했기 때문에) iocp의 구현이 안됩니다. 그리고 select모델을 이용해도 7000명수용...뭐 큰 문제 없었습니다. 간단한 클라이언트 수정부분에 대해서만 설명드리고 본격적으로 서버에 대한 내용으로 넘어가겠습니다. 우선 클라이언트 기존의 경우에는 MO방식이었죠... 그래서 맵 크기도 640 480 이었습..
2022.01.17 -
Chatting Server
안녕하세요 대학생 개발자입니다. 요새 날씨가 많이 춥습니다... 어디 나갈때마다 손발이 얼어붙을거같은데요 역시 이런날에는 집에 짱박혀서 코딩이나 하면서 블로그 쓰는게 제일 좋은거 같아요 그럼 시작하도록 하겠습니다. 이번 글에서 제가 다뤄볼 내용은 채팅서버입니다. 채팅서버는 서버 중에서 가장 난이도가 쉬운 서버중 하나인데요... 이유가 채팅의 경우에는 온 데이터를 따로 가공하지 않고 그대로 돌려보내는 에코서버와 비슷한 방향으로 구현이 되기 때문입니다. 물론 채팅도 중간에 내용을 변경해야되는 경우가 있다면 변경해야되겠지만(욕설 필터링 과같은) 이번 서버에서는 그런게 없기 때문에 그냥 온 패킷 그대로 돌려주는 경우가 많았습니다. 그리고 가장 중요한것은 채팅서버는 온 경우 바로 그자리에서 반응을 취하는 구조이기..
2021.12.30 -
Red-Black tree delete
안녕하세요 대학생개발자입니다. 저번 글에 이어서... 레드블랙트리에 대해서 얘기를 해보려고 합니다. 생각보다 포스팅간의 텀이 길어졌는데요... 제가 실수로 다만들어놓고 삭제를 해버리는바람에 ^^... 다시만들었답니다^^^^ 그래도 다행인게 한번 만들어 보니까 그다음에 만들때는 금방 만들더라구요... 그와 동시에 이해도도 조금 상승한 것 같습니다... 바로 시작하도록 하겠습니다. 우선 삭제과정까지는 이진탐색트리와 동일합니다. 삭제노드의 자식이 하나이하일 케이스에서는 자기 노드를 바로 삭제하고 아래노드로 연결시켜주면 끝납니다. 삭제노드의 자식이 둘일경우에는 - 오른쪽 자식중 가장 작은 노드를 삭제하면서 그 값을 타겟에 넣거나 - 왼쪽 자식중 가장 큰 노드를 삭제하면서 그 값을 타겟에 넣는 방법이 있습니다. ..
2021.12.23 -
Red-Black Tree (basic + insert)
안녕하세요 대학생개발자입니다. 휴... 요새 한창 매우 바쁘다가 한꺼번에 과제가 해결되버렸습니다... 예전에 제가 안된다고 했던 과제있죠?? 그게 레드블랙 트린데 말입니다... 사실 레드블랙트리를 아직도 100%이해했다고 자신하지 못하겠습니다ㅠㅠ... 물론 하나하나의 케이스를 놓고보면 어떻게 노드가 움직여야 되는지 어떤색으로 칠해져야되는지 알겠지만 그게 코드로 나오는데까지 시간이 상당히 오래 걸리더라구요... 아마... 이번 레드블랙 트리는 2번에 걸쳐서 나눠서 하게될 것 같습니다. 당연하게도 삽입과 삭제의 과정이 너무 케이스가 많기때문에 긴 글이 될 것같습니다. 실제로 다른글들도 읽어봤지만 한큐에 다 정리하기에는 양이 너무 많아보였고... 제가 실제로 메모장에 정리하면서 봤을때도 상당한 양이였기 때문에..
2021.12.22 -
Jump Point Search PathFinding Algorithm
안녕하세요 대학생 개발자입니다. 이번 글에서는 저번글에서 약속했던것과 같이 Jump Point Search(이하 JPS)를 다뤄볼 예정입니다. 저번 시간에는 A* 알고리즘을 통해서 휴리스틱 추정값을 통해서 탐색해나갈 방향성에 대해서 제시를 했었는데요. 우리가 일반적으로 알고리즘에서 느리다고 하는 부분은 기본적으로 정렬, 삽입, 삭제, 탐색 등이 있습니다. 하지만 A*의 경우에는 priority queue를 써야하기 때문에 정렬은 빠질수가 없습니다. 혹은 pq가 아니라 리스트를 써서 매번 가장 F값이 작은걸 골라 낸다고 하더라도 그만큼의 시간 소요는 없어서는 안되는 것이라는 거죠. 그렇다면 우리가 줄일수 있는것은 중간에 거쳐가는 노드의 생성을 줄이는 겁니다. 물론 노드의 생성을 줄인다는게 메모리 풀링을 통..
2021.12.21 -
A* Path Finding Algorithm
안녕하세요 대학생 개발자입니다. 정말 오랜만에 블로그에 글을 남기는 것 같은데요... 이번 글에서는 길 찾기 알고리즘에 대해서 얘기를 해보려고 합니다. 길찾기 알고리즘은 길을 찾는 알고리즘이죠 말그대로 대신 시작점과 끝점이 주어졌을 때 가장 최단거리를 찾아주는 알고리즘이 되겠습니다. 게임을 플레이할때 분명히 벽넘어를 클릭했는데 벽을 피해서(우회해서) 목적지에 도착하는(+최단거리로) 그런 경우를 많이 보셨을 겁니다. 이런경우에는 길찾기 알고리즘에 의한 행동으로 보시면 될 것 같습니다. 그러면 바로 알고리즘에 대한 얘기를 해보겠습니다 먼저 이번글에서 소개할 녀석은 바로 A*입니다. 대부분 게임에서 에이스타를 많이 사용합니다( 물론 지금은 많이 느리기때문에 에이스타보다 더 좋은 길찾기 알고리즘으로 넘어갔습니다..
2021.12.19 -
ObjectFreeList
안녕하세요 대학생개발자입니다. 오늘은 메모리풀과 오브젝트풀, 프리리스트에 대한 얘기를 해보려고합니다. 우선 메모리풀과 프리리스트에 대한 기본적인 이론이 필요할텐데요. pool을 사전에 돌려보면 그냥 수영장이죠... 즉 물을 담아놓는 곳입니다. 여기의 메모리풀또한 메모리의 수영장과 동일합니다. 메모리를 담아놓는 공간이 되는것입니다. 그리고 필요한 메모리를 꺼내서 쓰고 다시 갖다놓을 수 있는거죠 마치 여름엔 물을 가득채워서 물놀이를 하고 겨울에는 텅텅비워놓는것 처럼요. 그럼 간략하게 메모리 풀이 뭔지 감정도는 잡았습니다. 이제 메모리풀이란게 왜 필요한지 설명을 드리려고하는데... 사실 너무 당연한거여서... 이걸 적어야하나 싶습니다. 제일 일차적인 목적은 당연히 할당과 반환에 쓰이는 오버헤드를 줄이기 위함입..
2021.11.28 -
Serializing Buffer
안녕하세요 대학생 개발자입니다. 이번 글에서는 직렬화 버퍼에 대해서 얘기를 해보려고합니다. 지금까지 제가 TCP 프로토콜을 이용한 간단한 스트리트 파이터 같은 게임을 만들어봤는데요... 사실 이정도면 나름 완성이 되어있는 상태라고 봐도 무방합니다. 왜냐하면 사실 플레이어가 서버에게 보낼 수 있는 프로토콜은 전부 5바이트로 확정되어있기 때문이고 (이때문에 사실 링버퍼의 의미도 크게 없긴함) 5바이트로 되어있기 때문에 그냥 버퍼를 5바이트 잡고(char [5]같은걸로요) 그걸 패킷이라고 전달해줘도 되기 때문입니다. 하지만 큰 게임들은 가변 길이 버퍼를 많이 사용하게 되는데요... 가변길이 버퍼를 사용하게 되면 좋은점은 당연하게도 너무 큰 버퍼를 잡지 않아도 된다는 장점이 분명 있습니다. 우선 당장은 직렬화 ..
2021.11.23 -
WSAAsyncSelect로 게임클라이언트 제작
안녕하세요 대학생개발자입니다. 최근 어마어마한 과제와 어마어마한 일들로 인해서 포스팅을 하지 못했습니다. 드디어 과제가 끝나서 이 과제에 대한 포스팅을 해보려고 하는데요... 이번 글에서는 AsyncSelect 모델을 이용한 게임 클라이언트를 만들었고 그에대한 정리를 해볼겁니다. 이전에 말씀 드렸듯 AsyncSelect 모델은 최근 개발에서는 잘 사용하지 않는 모델입니다. WinMain에 상당히 종속적이고 싱글스레드에서 사용하기 좋기 때문입니다. 뭐 이런 내용은 지금당장 크게 중요한 부분은 아니니 실제 개발부분으로 들어가겠습니다. 시작하겠습니다 먼저 게임에 대한 프로토콜인데요. 일단 프로토콜은 예전의 별 찍기를 만들었던 것과 거의 비슷하게 될 것 같습니다... 우선 프로토콜은 두 종류로 나눠서 사용하고있..
2021.11.19 -
WSAAsyncSelect 그림그리기 클라이언트
안녕하세요 대학생개발자입니다. 이번에는 WSAAsyncSelect를 이용한 공유 그림판 클라이언트를 하나 만들어 봤어요. 사실 이벤트 드리븐이란게 진행도를 따로 그리기가 힘들어서 그냥 구조를 말로 설명드릴게요. 우선 내가 만든 소켓이랑 윈도우에 UM_NETWORK라는 메세지와 플래그로 FD_CONNECT, FD_CLOSE, FD_WRITE, FD_READ 정도를 async select하게 만들었습니다. 위쪽 소켓 초기화 부분은 비동기 소켓 하나 만들고 그냥 아이피 하나 읽어와서 연결하는 부분이라 따로 적진 않겠습니다. 네 뭐 이정도만 올려도 되겠죠? 우선 링거로 Time wait을 없애버렸고 WSAAsyncSelect로 메시지를 등록했습니다. 다음으로 이작업이 끝나게 되면 메시지를 기다렸다가 메시지가 뜨..
2021.11.13 -
WSAAsyncSelect
안녕하세요 대학생개발자입니다. 이번글에서는 AsyncSelect모델을 가지고 같이 그림을 그릴수 있는 보드를 만들어봤는데요... 우선 AsyncSelect가 뭔지 부터 간단히정리하고 가겠습니다. AsyncSelect 말그대로 select를 비동기적으로 수행한다는겁니다. select를 비동기적으로 한다는건 무슨의미일까요... 음... 일단 select를 다시한번 말씀드린다면... 게임에서의 select서버는 프레임에 맞춰서 루프를 계속 돌면서 폴링을 하는 방법이라고 정리를 했었습니다. 그럼 비동기 select니까 얘도 폴링을 하는 식으로 만들겠구나 라고 생각할 수 있는데요. 음... 사실 이부분에서 select와 async select모델은 전혀 다릅니다. async select의 경우에는 폴링기법으로 로..
2021.11.13 -
링 버퍼
안녕하세요 대학생 개발자입니다. 오늘은 링버퍼에 대해서 다뤄볼 예정입니다. 우선 시작하기 전에 게임서버에 링버퍼가 왜 필요한지에 대해서 간단히 설명해야될 것 같습니다. 게임서버는 당연히 빠른 속도와 안정성이 생명입니다. 안정성의 경우에는 모든 케이스에 에러체크를 하고 꼼꼼히 코드를 짜도 터지는 문제긴 하지만... 속도의 경우에는 다른데요... 어쩔수 없이 사용해야 되는 큰 코스트를 가진 함수들 가령... 입출력에 관련된 함수들, 혹은 매우 큰 로직, 했던 코드의 반복 이런 다양한 경우가 있을건데요 이번에 생각해볼것은 어쩔수 없이 사용해야 되는 큰 코스트를 가진 함수들에 대해서생각을 해볼겁니다. 우리가 socket io를 하게되면 어쩔수 없이 호출하는 함수중 가장 많은 비중이 차지하는 함수가 아마 send..
2021.11.12 -
select를 이용한 별움직이기 서버
안녕하세요 대학생 개발자입니다. 음... 마지막으로 올렸던 글에서는 별 움직이기 클라이언트에 대한 정리를 했었는데요 오늘은 서버에 대해서 정리를 해보려고 합니다...(오늘 테스트 하는데 혹시 서버가 죽을까... 무서웠습니다) 프로토콜은 이전과 동일합니다. 대신에 다른점은 그냥 이번에는 메세지 안에 헤더가 포함되어있다는 점 뿐??... 뭐 코드에서 아주조금만 달라지면 똑같은 결과로 나오니까... 뭐 특이점은 없습니다. 먼저 얘도 TCP 소켓하나 만들어서 리슨소켓으로 쓸거구요. +논블로킹 소켓으로 만들어줄겁니다. +서버의 경우에는 linger를 이용해서 time_wait을 없엘겁니다. 그외에는 특이사항이 없기 때문에 따로 코드를 올리진 않을거구요. 먼저 서버의 로직의 경우에는 클라이언트와는 좀 다를겁니다. ..
2021.11.08 -
select를 이용한 별움직이기 클라이언트
안녕하세요 대학생 개발자입니다. 이번 글에서는 과제였던... select를 이용해서 별움직이기 클라이언트를 만들어서 서버에 연결을 해보려고합니다.(물론 잘되야겠죠 ㅋㅋㅋ) 먼저 당연히 서버와 통신을 하려면 L7에서의 프로토콜이 필요합니다. 그럼 프로토콜을 잠시 보겠습니다. 네 메세지는 이렇게 생겼습니다. 일단 우선 Header가 있는데... 이건 제가 구현을 할때 Header로 buffer를 가르키고 Msg...를 가지고 buffer+4부분을 가르키게 구현했기 때문에 모든 메세지에 헤더가 붙지 않았습니다... 아 그리고 헤더에 보시면 not_used라는 항목이있는데요... 이게 원래 프로토콜에 따라서 사이즈가 다른경우가 대부분이겠지만 지금의 경우에는 제가 링버퍼를 구현을 못한 상태입니다. 그래서 아직 프..
2021.11.08