¤”ˆ †Œ¤ë¥¼ ™œ©•œ ¥¬–¼ 게‍„ „œë²„ ”„ë ˆ‍„›Œ¬ 개발

  • View

  • Download

Embed Size (px)

Text of ¤”ˆ †Œ¤ë¥¼ ™œ©•œ...

  • 1. Casual Game Server Framework CGSF 2012-10-18 MEMOKGC

2. Casual Game Server Framework(CGSF) 1. CGSF 2. MMO / MO / ?? Casual Game Server Framework 3. Casual Game Server Framework(CGSF) 3. License Free Casual Game Server Framework 4. Casual Game Server Framework(CGSF) 4. : - - - .. Casual Game Server Framework 5. CGSF - Table of Contents1. CGSF Internal Structure2. Network Layer3. Logic Queue4. Logic Layer5. Database Layer6. P2P Layer7. Sample FPS Server / Client8. Conclusion5 Casual Game Server Framework 6. ACE Proactor WorkWorkWork1NThreadThreadThread Logic Queue (IOCP)Logic1.Single Thread Thread2. Database ProxyDatabase Impl Local Database Impl Remote(DB Thread) DataBase ServerHalf Sync Half Async PatternDataBase 6 7. Network LayerNetwork Layer Logic Layer Database Layer P2P Layer7 8. Network Layer ACE Framework TCP ACEPacket Logic PacketDataProactorAnalyzerQueue Kernel ACE Thread Worker Thread = (Core * 2) ?? 8Casual Game Server Framework 9. Network Layer ACE Application Acceptor & Service Handler9 Casual Game Server Framework 10. Network Layer ACE Application Acceptor & Service Handler Expansion10Casual Game Server Framework 11. Network Layer ACE Application Worker Thread Creation ACE_Thread_Manager::instance()->spawn_n(ThreadCount, ProactorWorkThread, ); 1. ThreadCount : 2. ProcatorWorkThread : Thread Entry 11 Casual Game Server Framework 12. Network LayerACE Application Worker Thread Event Detection void ProactorWorkThread(void* Args) {ACE_Proactor::instance()->proactor_run_event_loop(); } ::GetQueuedCompletionStatus(m_hIOCP, , &pCompletionKey, , );12 Casual Game Server Framework 13. Network LayerACE Application proactor_run_event_loop()NetworkEngine.dll!SFProactorService::handle_read_stream()ACEd.dll!ACE_WIN32_Asynch_Read_Stream_Result::complete()ACEd.dll!ACE_WIN32_Proactor::application_specific_code()ACEd.dll!ACE_WIN32_Proactor::handle_events(unsigned long milli_seconds=4294967295)ACEd.dll!ACE_WIN32_Proactor::handle_events()ACEd.dll!ACE_Proactor::handle_events()ACEd.dll!ACE_Proactor::proactor_run_event_loop(int (ACE_Proactor *)* eh=0x00000000)NetworkEngine.dll!ProactorWorkThread(void * Args=0x00000000)ACEd.dll!ACE_Thread_Adapter::invoke_i()ACEd.dll!ACE_Thread_Adapter::invoke()ACEd.dll!ace_thread_adapter(void * args=0x0118b558) SFProactorService 13 Casual Game Server Framework 14. Network LayerPacket Analyzer ?14 Casual Game Server Framework 15. Network LayerACE Application User Session(Socket) & Received Data Process15 Casual Game Server Framework 16. Network Layer Packet Analyzer Packet Analyzer- - HeaderData 16 Casual Game Server Framework 17. Network Layer Packet Analyzer Packet Header Packet Length Encryption Compress Checksum(CRC) Directive 17Casual Game Server Framework 18. Network Layer Packet Analyzer TCP HeaderHeaderHeaderDataHeaderData 18Casual Game Server Framework 19. Network LayerPacket Analyzer Raw Packet CRC Packet Raw PacketCRC Packet19 Casual Game Server Framework 20. Network Layer lzf . Zlib ??20Casual Game Server Framework 21. Network Layer 1. 2. 21 Casual Game Server Framework 22. Network Layer Example Lzf, Zlib 1. class SFCompressLzf 2. BOOL Compress(BYTE* pDest, int& DestLen, BYTE* pSrc, int SrcLen); 3. BOOL Uncompress(BYTE* pDest, int& DestLen, BYTE* pSrc, intSrcLen); 1. class SFCompressZLib 2. BOOL Compress(BYTE* pDest, int& DestLen, BYTE* pSrc, int SrcLen); 3. BOOL Uncompress(BYTE* pDest, int& DestLen, BYTE* pSrc, int SrcLen);22 Casual Game Server Framework 23. Network Layer Example Packet Analyzer1. template 2. class SFPacketAnalyzer3. {4. .5. static T& GetCompressor(){return m_Compress;}6. static T m_Compress;7. .8. };23 Casual Game Server Framework 24. Network Layer Example - SFProactorServiceSFPacketAnalyzer::GetCompressor().Compress(); http://www.zlib.net http://oldhome.schmorp.de/marc/liblzf.html24Casual Game Server Framework 25. Logic Queue Logic Queue25Casual Game Server Framework 26. Network LayerLogic Queue Logic Queue 1. Queue- 2. IOCP 26Casual Game Server Framework 27. Network Layer Logic Queue Logic Queue template class SFIOCPQueue : public SFTSSyncQueue { BOOL Push(T* pMsg) { ::PostQueuedCompletionStatus(m_hIOCP, 0, (ULONG_PTR)pMsg, NULL); return TRUE; } T* Pop() { SFASSERT( FALSE != ::GetQueuedCompletionStatus(m_hIOCP, &NumberOfBytesTransferred, &pCompletionKey, &pOverlapped, INFINITE)); return (T*)(pCompletionKey); }27Casual Game Server Framework 28. Network Layer Logic Queue Logic Queue 1. Worker ThreadLogicGatewaySingleton::instance()->PushPacket(pPacket); 2. Logic ThreadpCommand = LogicGatewaySingleton::instance()->PopPacket();LogicEntrySingleton::instance()->ProcessPacket(pCommand); 28 Casual Game Server Framework 29. Logic LayerNetwork Layer Logic LayerDatabase Layer P2P Layer29 30. Logic LayerCGSF Logic Layer 1. 2. - - - - ,- - 30Casual Game Server Framework 31. Logic Layer Logic Thread Single Thread 1. - Lock(); SharedVar++; Unlock(); 2. 3. 4. (Node.js)31 Casual Game Server Framework 32. Logic Layer Logic Thread 1. Blocking Codeex) Sleep() 2. , 32 Casual Game Server Framework 33. Logic Layer Logic Thread Logic Thread Entry33 Casual Game Server Framework 34. Logic Layer CGSF Game Lobby34 Casual Game Server Framework 35. Logic Layer CGSF GameRoom35 Casual Game Server Framework 36. Logic LayerCGSF GameLoading 36 Casual Game Server Framework 37. Logic Layer CGSF GamePlay37 Casual Game Server Framework 38. Logic Layer CGSF GameResult38 Casual Game Server Framework 39. Logic Layer StateDesign Pattern !! 39 Casual Game Server Framework 40. Logic LayerGameRoom Game Room State Design 40 Casual Game Server Framework 41. Logic Layer GameRoom Player State Design41 Casual Game Server Framework 42. Logic Layer GameRoom Packet Flow( )42 Casual Game Server Framework 43. Logic LayerGameRoom SFRoomPlay : 43Casual Game Server Framework 44. Logic LayerGameRoom GameMode ExampleFPSServer SFFreeForAll 44 Casual Game Server Framework 45. Logic Layer 45 Casual Game Server Framework 46. Logic LayerGoogle protocol buffer Google Protocol Buffer1. http://code.google.com/p/protobuf/2. (http://javawork.egloos.com/2726467) MessagePackhttp://msgpack.org/46Casual Game Server Framework 47. Logic Layer Google protocol buffer Example message Chat{required string ChatMessage = 1;}Chat PktChat;PktChat.chatmessage(); 47Casual Game Server Framework 48. Database LayerNetwork Layer Logic LayerDatabase Layer P2P Layer48 49. Database LayerDatabase 1. MS-SQL2. MySQL MS-SQL MySQL mysql 49Casual Game Server Framework 50. Database Layer MySQL MySQL : http://www.mysql.com/50 Casual Game Server Framework 51. Database Layer Implementation 1. - 2. , DB 51Casual Game Server Framework 52. Database Layer Implementation 1. DB Game Database Database ServerServer2. IOCP 3. 52Casual Game Server Framework 53. Database Layer Implementation Half-Sync/Half-Async http://javawork.egloos.com/181869653Casual Game Server Framework 54. Database Layer Implementation Logic Thread Manager ThreadDBWorker Thread 54 Casual Game Server Framework 55. Database LayerImplementation Logic Thread Send1. SFMessage* pMessage = LogicEntrySingleton::instance()->GetDBMessage();2. .3. LogicEntrySingleton::instance()->GetDataBaseProxy()->SendDBRequest(pMessage); 55Casual Game Server Framework 56. Database Layer Implementation Command Pattern , 56Casual Game Server Framework 57. Database Layer Implementation DB Query Command SFDBWorker(Thread)1. while(TRUE)2. {3.ACE_Method_Request* pReq = this->m_Queue.dequeue();4. .5.int Result = pReq->call();6. .7. } DB !!57Casual Game Server Framework 58. Database Layer Implementation Request call method1.extern ACE_TSS Database;2.3.int SFDBRequest::call(void)4.{5...6.Database->Call(m_pMessage);7...8.return 0;9.}58Casual Game Server Framework 59. Database Layer TLS Thread Local Storage(TLS) 59 Casual Game Server Framework 60. Database Layer Implementaion ~ 60Casual Game Server Framework 61. P2P LayerNetwork Layer Logic LayerDatabase Layer P2P Layer61 62. P2P Layer P2P P2P Layer1. P2P 62 Casual Game Server Framework 63. P2P Layer P2P P2P Module1. OCF P2P - OCF - http://www.ocf.kr/2. Raknet3. Enet - League of Legends ?? - http://enet.bespin.org 63Casual Game Server Framework 64. P2P Layer P2P - 1Peer11 Peer1 Relay Relay ServerServerPeer2 Peer22 SuperPeer Super PeerPeer33 Peer364 Casual Game Server Framework 65. P2P LayerP2P - 1Peer1Peer1 RelayRelayServerServerPeer2Peer2Peer4 Peer3 Peer4Peer365Casual Game Server Framework 66. P2P Layer P2P - 2Relay Peer1RelayServer Peer1 ServerPeer4 Peer2 Peer2 Peer4Peer3Peer366 Casual Game Server Framework 67. P2P LayerP2P P2P Manager Interface 67 Casual Game Server Framework 68. P2P LayerP2P P2P Method(IUDPNetworkCallback)1. HandleUDPNetworkMessage2. ReportMyIP 68 Casual Game Server Framework 69. P2P Layer P2P Lock Free Library : liblfds(http://www.liblfds.org)BOOL P2PManager::PushPacket(BYTE* pData, int Length)queue_guaranteed_enqueue(m_pQueue, pP2PData);BOOL P2PManager::Update()while (queue_dequeue(m_pQueue, (void**)&pP2PData)){m_pUDPCallback->HandleUDPNetworkMessage(); 69Casual Game Server Framework 70. P2P Layer P2P Mechanism Report My IPRelay Svr Game Svr123Client 11. Request My Public IP2. Receive My Public IP3. Report My IP 70 Casual Game Server Framework 71. P2P LayerP2P Mechanism Sharing IP & Connect Game Room .123 Client 1 Client 2 Client 341. Enter Room2. Receive Room