├── .gitattributes ├── .gitignore ├── Cocos2dxGameClient ├── Classes │ ├── AppDelegate.cpp │ ├── AppDelegate.h │ ├── CircularBuffer.cpp │ ├── CircularBuffer.h │ ├── HelloWorldScene.cpp │ ├── HelloWorldScene.h │ ├── TcpClient.cpp │ └── TcpClient.h ├── Resources │ ├── CloseNormal.png │ ├── CloseSelected.png │ ├── HelloWorld.png │ ├── Player.png │ ├── Projectile.png │ ├── Target.png │ └── fonts │ │ └── Marker Felt.ttf ├── cocos2d │ └── unzip_this_here.zip └── proj.win32 │ ├── CocosGameClient.sln │ ├── CocosGameClient.vcxproj │ ├── CocosGameClient.vcxproj.filters │ ├── CocosGameClient.vcxproj.user │ ├── UserDefault.xml │ ├── build-cfg.json │ ├── game.rc │ ├── main.cpp │ ├── main.h │ ├── res │ └── game.ico │ └── resource.h ├── Dockerfile ├── DummyClient ├── DummyClient.sln └── DummyClient │ ├── ClientManager.cpp │ ├── ClientManager.h │ ├── ClientSession.cpp │ ├── ClientSession.h │ ├── DummyClient.cpp │ ├── DummyClient.h │ ├── DummyClient.vcxproj │ ├── DummyClient.vcxproj.filters │ ├── ReadMe.txt │ ├── packages.config │ ├── stdafx.cpp │ ├── stdafx.h │ └── targetver.h ├── EasyServer ├── Database │ ├── SQLiteSpy.db3 │ ├── SQLiteSpy.exe │ └── user_example.db3 ├── EasyServer.sln └── EasyServer │ ├── CircularBuffer.cpp │ ├── CircularBuffer.h │ ├── ClientManager.cpp │ ├── ClientManager.h │ ├── ClientSession.cpp │ ├── ClientSession.h │ ├── Config.h │ ├── DatabaseJobContext.cpp │ ├── DatabaseJobContext.h │ ├── DatabaseJobManager.cpp │ ├── DatabaseJobManager.h │ ├── DbHelper.cpp │ ├── DbHelper.h │ ├── EasyServer.cpp │ ├── EasyServer.h │ ├── EasyServer.vcxproj │ ├── EasyServer.vcxproj.filters │ ├── Exception.cpp │ ├── Exception.h │ ├── ObjectPool.h │ ├── PacketHandling.cpp │ ├── ProducerConsumerQueue.h │ ├── ReadMe.txt │ ├── RefCountable.h │ ├── SQLStatement.h │ ├── Scheduler.cpp │ ├── Scheduler.h │ ├── ThreadLocal.cpp │ ├── ThreadLocal.h │ ├── sqlite3.c │ ├── sqlite3.h │ ├── sqlite3ext.h │ ├── stdafx.cpp │ ├── stdafx.h │ └── targetver.h ├── LICENSE ├── PacketType.h └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | sqlite*.* linguist-language=C++ 2 | 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | *.dylib 9 | 10 | # Compiled Static libraries 11 | *.lai 12 | *.la 13 | *.a 14 | -------------------------------------------------------------------------------- /Cocos2dxGameClient/Classes/AppDelegate.cpp: -------------------------------------------------------------------------------- 1 | #include "AppDelegate.h" 2 | #include "HelloWorldScene.h" 3 | 4 | USING_NS_CC; 5 | 6 | AppDelegate::AppDelegate() { 7 | 8 | } 9 | 10 | AppDelegate::~AppDelegate() 11 | { 12 | } 13 | 14 | bool AppDelegate::applicationDidFinishLaunching() { 15 | // initialize director 16 | auto director = Director::getInstance(); 17 | auto glview = director->getOpenGLView(); 18 | if(!glview) { 19 | glview = GLView::create("My Game"); 20 | director->setOpenGLView(glview); 21 | } 22 | 23 | // turn on display FPS 24 | director->setDisplayStats(true); 25 | 26 | // set FPS. the default value is 1.0/60 if you don't call this 27 | director->setAnimationInterval(1.0 / 60); 28 | 29 | // create a scene. it's an autorelease object 30 | auto scene = HelloWorld::createScene(); 31 | 32 | // run 33 | director->runWithScene(scene); 34 | 35 | return true; 36 | } 37 | 38 | // This function will be called when the app is inactive. When comes a phone call,it's be invoked too 39 | void AppDelegate::applicationDidEnterBackground() { 40 | Director::getInstance()->stopAnimation(); 41 | 42 | // if you use SimpleAudioEngine, it must be pause 43 | // SimpleAudioEngine::getInstance()->pauseBackgroundMusic(); 44 | } 45 | 46 | // this function will be called when the app is active again 47 | void AppDelegate::applicationWillEnterForeground() { 48 | Director::getInstance()->startAnimation(); 49 | 50 | // if you use SimpleAudioEngine, it must resume here 51 | // SimpleAudioEngine::getInstance()->resumeBackgroundMusic(); 52 | } 53 | -------------------------------------------------------------------------------- /Cocos2dxGameClient/Classes/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #ifndef _APP_DELEGATE_H_ 2 | #define _APP_DELEGATE_H_ 3 | 4 | #include "cocos2d.h" 5 | 6 | /** 7 | @brief The cocos2d Application. 8 | 9 | The reason for implement as private inheritance is to hide some interface call by Director. 10 | */ 11 | class AppDelegate : private cocos2d::Application 12 | { 13 | public: 14 | AppDelegate(); 15 | virtual ~AppDelegate(); 16 | 17 | /** 18 | @brief Implement Director and Scene init code here. 19 | @return true Initialize success, app continue. 20 | @return false Initialize failed, app terminate. 21 | */ 22 | virtual bool applicationDidFinishLaunching(); 23 | 24 | /** 25 | @brief The function be called when the application enter background 26 | @param the pointer of the application 27 | */ 28 | virtual void applicationDidEnterBackground(); 29 | 30 | /** 31 | @brief The function be called when the application enter foreground 32 | @param the pointer of the application 33 | */ 34 | virtual void applicationWillEnterForeground(); 35 | }; 36 | 37 | #endif // _APP_DELEGATE_H_ 38 | 39 | -------------------------------------------------------------------------------- /Cocos2dxGameClient/Classes/CircularBuffer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/Cocos2dxGameClient/Classes/CircularBuffer.cpp -------------------------------------------------------------------------------- /Cocos2dxGameClient/Classes/CircularBuffer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/Cocos2dxGameClient/Classes/CircularBuffer.h -------------------------------------------------------------------------------- /Cocos2dxGameClient/Classes/HelloWorldScene.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/Cocos2dxGameClient/Classes/HelloWorldScene.cpp -------------------------------------------------------------------------------- /Cocos2dxGameClient/Classes/HelloWorldScene.h: -------------------------------------------------------------------------------- 1 | #ifndef __HELLOWORLD_SCENE_H__ 2 | #define __HELLOWORLD_SCENE_H__ 3 | 4 | #include "cocos2d.h" 5 | 6 | class HelloWorld : public cocos2d::LayerColor 7 | { 8 | public: 9 | // there's no 'id' in cpp, so we recommend returning the class instance pointer 10 | static cocos2d::Scene* createScene(); 11 | 12 | // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone 13 | virtual bool init(); 14 | 15 | // a selector callback 16 | void menuCloseCallback(cocos2d::Ref* pSender); 17 | 18 | // implement the "static create()" method manually 19 | CREATE_FUNC(HelloWorld); 20 | 21 | 22 | void spriteMoveFinished(cocos2d::CCNode * sender); 23 | void gameLogic(float dt); 24 | 25 | void onKeyPressed(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event) {} 26 | void onKeyReleased(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event); 27 | 28 | void helloWorld() { CCLOG("HELLO~~~"); } 29 | void updatePeer(int id, float x, float y); 30 | void updateMe(float x, float y); 31 | void chatDraw(const std::string& from, const std::string& chat); 32 | 33 | 34 | private: 35 | cocos2d::CCSprite* mPlayerSprite = nullptr; 36 | std::map mPeerMap; 37 | }; 38 | 39 | #endif // __HELLOWORLD_SCENE_H__ 40 | -------------------------------------------------------------------------------- /Cocos2dxGameClient/Classes/TcpClient.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/Cocos2dxGameClient/Classes/TcpClient.cpp -------------------------------------------------------------------------------- /Cocos2dxGameClient/Classes/TcpClient.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "CircularBuffer.h" 4 | 5 | #ifndef _WIN32 6 | #include 7 | #include 8 | #else 9 | #include 10 | #endif 11 | 12 | #define BUF_SIZE 32768 13 | 14 | class TcpClient 15 | { 16 | public: 17 | static TcpClient* getInstance(); 18 | static void destroyInstance(); 19 | 20 | bool connect(const char* serverAddr, int port); 21 | 22 | 23 | /// request test 24 | void loginRequest(); 25 | void chatRequest(const char* chat); 26 | void moveRequest(float x, float y); 27 | 28 | 29 | private: 30 | TcpClient(); 31 | virtual ~TcpClient(); 32 | 33 | bool initialize(); 34 | bool send(const char* data, int length); 35 | 36 | void networkThread(); 37 | void processPacket(); 38 | 39 | private: 40 | 41 | SOCKET m_sock; 42 | CircularBuffer m_recvBuffer; 43 | 44 | int m_loginId; 45 | 46 | }; 47 | 48 | -------------------------------------------------------------------------------- /Cocos2dxGameClient/Resources/CloseNormal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/Cocos2dxGameClient/Resources/CloseNormal.png -------------------------------------------------------------------------------- /Cocos2dxGameClient/Resources/CloseSelected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/Cocos2dxGameClient/Resources/CloseSelected.png -------------------------------------------------------------------------------- /Cocos2dxGameClient/Resources/HelloWorld.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/Cocos2dxGameClient/Resources/HelloWorld.png -------------------------------------------------------------------------------- /Cocos2dxGameClient/Resources/Player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/Cocos2dxGameClient/Resources/Player.png -------------------------------------------------------------------------------- /Cocos2dxGameClient/Resources/Projectile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/Cocos2dxGameClient/Resources/Projectile.png -------------------------------------------------------------------------------- /Cocos2dxGameClient/Resources/Target.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/Cocos2dxGameClient/Resources/Target.png -------------------------------------------------------------------------------- /Cocos2dxGameClient/Resources/fonts/Marker Felt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/Cocos2dxGameClient/Resources/fonts/Marker Felt.ttf -------------------------------------------------------------------------------- /Cocos2dxGameClient/cocos2d/unzip_this_here.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/Cocos2dxGameClient/cocos2d/unzip_this_here.zip -------------------------------------------------------------------------------- /Cocos2dxGameClient/proj.win32/CocosGameClient.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CocosGameClient", "CocosGameClient.vcxproj", "{76A39BB2-9B84-4C65-98A5-654D86B86F2A}" 5 | ProjectSection(ProjectDependencies) = postProject 6 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} = {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} 7 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25} = {207BC7A9-CCF1-4F2F-A04D-45F72242AE25} 8 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} = {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} 9 | EndProjectSection 10 | EndProject 11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d", "..\cocos2d\cocos\2d\cocos2d.vcxproj", "{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}" 12 | EndProject 13 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libchipmunk", "..\cocos2d\external\chipmunk\proj.win32\chipmunk.vcxproj", "{207BC7A9-CCF1-4F2F-A04D-45F72242AE25}" 14 | EndProject 15 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libAudio", "..\cocos2d\cocos\audio\proj.win32\CocosDenshion.vcxproj", "{F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}" 16 | EndProject 17 | Global 18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 19 | Debug|Win32 = Debug|Win32 20 | Release|Win32 = Release|Win32 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Debug|Win32.ActiveCfg = Debug|Win32 24 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Debug|Win32.Build.0 = Debug|Win32 25 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Release|Win32.ActiveCfg = Release|Win32 26 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Release|Win32.Build.0 = Release|Win32 27 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Debug|Win32.ActiveCfg = Debug|Win32 28 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Debug|Win32.Build.0 = Debug|Win32 29 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Release|Win32.ActiveCfg = Release|Win32 30 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Release|Win32.Build.0 = Release|Win32 31 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Debug|Win32.ActiveCfg = Debug|Win32 32 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Debug|Win32.Build.0 = Debug|Win32 33 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Release|Win32.ActiveCfg = Release|Win32 34 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Release|Win32.Build.0 = Release|Win32 35 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Debug|Win32.ActiveCfg = Debug|Win32 36 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Debug|Win32.Build.0 = Debug|Win32 37 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Release|Win32.ActiveCfg = Release|Win32 38 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Release|Win32.Build.0 = Release|Win32 39 | EndGlobalSection 40 | GlobalSection(SolutionProperties) = preSolution 41 | HideSolutionNode = FALSE 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /Cocos2dxGameClient/proj.win32/CocosGameClient.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A} 15 | test_win32 16 | Win32Proj 17 | 18 | 19 | 20 | Application 21 | Unicode 22 | true 23 | v100 24 | v110 25 | v110_xp 26 | v120 27 | 28 | 29 | Application 30 | Unicode 31 | v100 32 | v110 33 | v110_xp 34 | v120 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | <_ProjectFileVersion>10.0.40219.1 52 | $(SolutionDir)$(Configuration).win32\ 53 | $(Configuration).win32\ 54 | true 55 | $(SolutionDir)$(Configuration).win32\ 56 | $(Configuration).win32\ 57 | false 58 | AllRules.ruleset 59 | 60 | 61 | AllRules.ruleset 62 | 63 | 64 | 65 | 66 | $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\lib;$(LibraryPath) 67 | 68 | 69 | $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\lib;$(LibraryPath) 70 | 71 | 72 | 73 | Disabled 74 | $(EngineRoot)cocos\audio\include;$(EngineRoot)external;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)extensions;..\Classes;..;%(AdditionalIncludeDirectories) 75 | WIN32;_DEBUG;_WINDOWS;_USE_MATH_DEFINES;GL_GLEXT_PROTOTYPES;CC_ENABLE_CHIPMUNK_INTEGRATION=1;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 76 | false 77 | EnableFastChecks 78 | MultiThreadedDebugDLL 79 | 80 | 81 | Level3 82 | EditAndContinue 83 | 4267;4251;4244;%(DisableSpecificWarnings) 84 | true 85 | 86 | 87 | %(AdditionalDependencies) 88 | $(OutDir)$(ProjectName).exe 89 | $(OutDir);%(AdditionalLibraryDirectories) 90 | true 91 | Windows 92 | MachineX86 93 | 94 | 95 | 96 | 97 | 98 | 99 | if not exist "$(OutDir)" mkdir "$(OutDir)" 100 | xcopy /Y /Q "$(EngineRoot)external\websockets\prebuilt\win32\*.*" "$(OutDir)" 101 | 102 | 103 | if not exist "$(OutDir)" mkdir "$(OutDir)" 104 | if not exist "$(OutDir)UserDefault.xml" copy "$(ProjectDir)UserDefault.xml" "$(OutDir)" 105 | 106 | Copy UserDefault.xml 107 | 108 | 109 | 110 | 111 | MaxSpeed 112 | true 113 | $(EngineRoot)cocos\audio\include;$(EngineRoot)external;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)extensions;..\Classes;..;%(AdditionalIncludeDirectories) 114 | WIN32;NDEBUG;_WINDOWS;_USE_MATH_DEFINES;GL_GLEXT_PROTOTYPES;CC_ENABLE_CHIPMUNK_INTEGRATION=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 115 | MultiThreadedDLL 116 | true 117 | 118 | 119 | Level3 120 | ProgramDatabase 121 | 4267;4251;4244;%(DisableSpecificWarnings) 122 | true 123 | 124 | 125 | libcurl_imp.lib;websockets.lib;%(AdditionalDependencies) 126 | $(OutDir)$(ProjectName).exe 127 | $(OutDir);%(AdditionalLibraryDirectories) 128 | true 129 | Windows 130 | true 131 | true 132 | MachineX86 133 | 134 | 135 | 136 | 137 | 138 | 139 | if not exist "$(OutDir)" mkdir "$(OutDir)" 140 | xcopy /Y /Q "$(EngineRoot)external\websockets\prebuilt\win32\*.*" "$(OutDir)" 141 | 142 | 143 | if not exist "$(OutDir)" mkdir "$(OutDir)" 144 | if not exist "$(OutDir)UserDefault.xml" copy "$(ProjectDir)UserDefault.xml" "$(OutDir)" 145 | 146 | Copy UserDefault.xml 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | {98a51ba8-fc3a-415b-ac8f-8c7bd464e93e} 167 | false 168 | 169 | 170 | {f8edd7fa-9a51-4e80-baeb-860825d2eac6} 171 | 172 | 173 | {207bc7a9-ccf1-4f2f-a04d-45f72242ae25} 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /Cocos2dxGameClient/proj.win32/CocosGameClient.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {84a8ebd7-7cf0-47f6-b75e-d441df67da40} 6 | 7 | 8 | {bb6c862e-70e9-49d9-81b7-3829a6f50471} 9 | 10 | 11 | {715254bc-d70b-4ec5-bf29-467dd3ace079} 12 | 13 | 14 | {a51839c6-905c-4295-8f40-5d0e1d05974e} 15 | 16 | 17 | 18 | 19 | win32 20 | 21 | 22 | Classes 23 | 24 | 25 | Classes 26 | 27 | 28 | Networking 29 | 30 | 31 | Networking 32 | 33 | 34 | 35 | 36 | win32 37 | 38 | 39 | Classes 40 | 41 | 42 | Classes 43 | 44 | 45 | Networking 46 | 47 | 48 | Networking 49 | 50 | 51 | Networking 52 | 53 | 54 | 55 | 56 | resource 57 | 58 | 59 | -------------------------------------------------------------------------------- /Cocos2dxGameClient/proj.win32/CocosGameClient.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(ProjectDir)..\Resources 5 | WindowsLocalDebugger 6 | NativeOnly 7 | 8 | 9 | $(ProjectDir)..\Resources 10 | WindowsLocalDebugger 11 | 12 | -------------------------------------------------------------------------------- /Cocos2dxGameClient/proj.win32/UserDefault.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 127.0.0.1 4 | 9001 5 | 6 | -------------------------------------------------------------------------------- /Cocos2dxGameClient/proj.win32/build-cfg.json: -------------------------------------------------------------------------------- 1 | { 2 | "copy_resources": [ 3 | { 4 | "from": "../Resources", 5 | "to": "" 6 | } 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /Cocos2dxGameClient/proj.win32/game.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #define APSTUDIO_HIDDEN_SYMBOLS 11 | #include "windows.h" 12 | #undef APSTUDIO_HIDDEN_SYMBOLS 13 | ///////////////////////////////////////////////////////////////////////////// 14 | #undef APSTUDIO_READONLY_SYMBOLS 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // English (U.S.) resources 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | #ifdef _WIN32 21 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 22 | #pragma code_page(1252) 23 | #endif //_WIN32 24 | 25 | #ifdef APSTUDIO_INVOKED 26 | ///////////////////////////////////////////////////////////////////////////// 27 | // 28 | // TEXTINCLUDE 29 | // 30 | 31 | 1 TEXTINCLUDE 32 | BEGIN 33 | "resource.h\0" 34 | END 35 | 36 | #endif // APSTUDIO_INVOKED 37 | 38 | ///////////////////////////////////////////////////////////////////////////// 39 | // 40 | // Icon 41 | // 42 | 43 | // Icon with lowest ID value placed first to ensure application icon 44 | // remains consistent on all systems. 45 | GLFW_ICON ICON "res\\game.ico" 46 | 47 | ///////////////////////////////////////////////////////////////////////////// 48 | // 49 | // Version 50 | // 51 | 52 | VS_VERSION_INFO VERSIONINFO 53 | FILEVERSION 1,0,0,1 54 | PRODUCTVERSION 1,0,0,1 55 | FILEFLAGSMASK 0x3fL 56 | #ifdef _DEBUG 57 | FILEFLAGS 0x1L 58 | #else 59 | FILEFLAGS 0x0L 60 | #endif 61 | FILEOS 0x4L 62 | FILETYPE 0x2L 63 | FILESUBTYPE 0x0L 64 | BEGIN 65 | BLOCK "StringFileInfo" 66 | BEGIN 67 | BLOCK "040904B0" 68 | BEGIN 69 | VALUE "CompanyName", "\0" 70 | VALUE "FileDescription", "game Module\0" 71 | VALUE "FileVersion", "1, 0, 0, 1\0" 72 | VALUE "InternalName", "game\0" 73 | VALUE "LegalCopyright", "Copyright \0" 74 | VALUE "OriginalFilename", "game.exe\0" 75 | VALUE "ProductName", "game Module\0" 76 | VALUE "ProductVersion", "1, 0, 0, 1\0" 77 | END 78 | END 79 | BLOCK "VarFileInfo" 80 | BEGIN 81 | VALUE "Translation", 0x0409, 0x04B0 82 | END 83 | END 84 | 85 | ///////////////////////////////////////////////////////////////////////////// 86 | #endif // !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 87 | -------------------------------------------------------------------------------- /Cocos2dxGameClient/proj.win32/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "AppDelegate.h" 3 | #include "cocos2d.h" 4 | 5 | USING_NS_CC; 6 | 7 | int APIENTRY _tWinMain(HINSTANCE hInstance, 8 | HINSTANCE hPrevInstance, 9 | LPTSTR lpCmdLine, 10 | int nCmdShow) 11 | { 12 | UNREFERENCED_PARAMETER(hPrevInstance); 13 | UNREFERENCED_PARAMETER(lpCmdLine); 14 | 15 | // create the application instance 16 | AppDelegate app; 17 | return Application::getInstance()->run(); 18 | } 19 | -------------------------------------------------------------------------------- /Cocos2dxGameClient/proj.win32/main.h: -------------------------------------------------------------------------------- 1 | #ifndef __MAIN_H__ 2 | #define __MAIN_H__ 3 | 4 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 5 | 6 | // Windows Header Files: 7 | #include 8 | #include 9 | 10 | // C RunTime Header Files 11 | #include "CCStdC.h" 12 | 13 | #endif // __MAIN_H__ 14 | -------------------------------------------------------------------------------- /Cocos2dxGameClient/proj.win32/res/game.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/Cocos2dxGameClient/proj.win32/res/game.ico -------------------------------------------------------------------------------- /Cocos2dxGameClient/proj.win32/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by game.RC 4 | // 5 | 6 | #define IDS_PROJNAME 100 7 | #define IDR_TESTJS 100 8 | 9 | #define ID_FILE_NEW_WINDOW 32771 10 | 11 | // Next default values for new objects 12 | // 13 | #ifdef APSTUDIO_INVOKED 14 | #ifndef APSTUDIO_READONLY_SYMBOLS 15 | #define _APS_NEXT_RESOURCE_VALUE 201 16 | #define _APS_NEXT_CONTROL_VALUE 1000 17 | #define _APS_NEXT_SYMED_VALUE 101 18 | #define _APS_NEXT_COMMAND_VALUE 32775 19 | #endif 20 | #endif 21 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:14.04 2 | MAINTAINER zeliard 3 | 4 | RUN sudo apt-get update 5 | RUN sudo apt-get install -y g++ 6 | RUN sudo apt-get install -y unzip 7 | RUN sudo apt-get install -y wget 8 | RUN sudo apt-get install -y build-essential 9 | WORKDIR /tmp 10 | 11 | RUN wget https://github.com/zeliard/EasyGameServer/archive/linux.zip 12 | RUN unzip linux.zip 13 | WORKDIR EasyGameServer-linux/EasyGameServer/EasyGameServerLinux/ 14 | 15 | RUN make 16 | RUN cp -r database/ ./Debug/ 17 | 18 | WORKDIR Debug 19 | 20 | CMD ["./EasyGameServerLinux"] 21 | 22 | EXPOSE 9001 23 | 24 | -------------------------------------------------------------------------------- /DummyClient/DummyClient.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30723.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DummyClient", "DummyClient\DummyClient.vcxproj", "{0B7CF1BF-E96A-4175-8EB6-CFDA37F86B6E}" 7 | EndProject 8 | Global 9 | GlobalSection(SubversionScc) = preSolution 10 | Svn-Managed = True 11 | Manager = AnkhSVN - Subversion Support for Visual Studio 12 | EndGlobalSection 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Win32 = Debug|Win32 15 | Release|Win32 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {0B7CF1BF-E96A-4175-8EB6-CFDA37F86B6E}.Debug|Win32.ActiveCfg = Debug|Win32 19 | {0B7CF1BF-E96A-4175-8EB6-CFDA37F86B6E}.Debug|Win32.Build.0 = Debug|Win32 20 | {0B7CF1BF-E96A-4175-8EB6-CFDA37F86B6E}.Release|Win32.ActiveCfg = Release|Win32 21 | {0B7CF1BF-E96A-4175-8EB6-CFDA37F86B6E}.Release|Win32.Build.0 = Release|Win32 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /DummyClient/DummyClient/ClientManager.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "DummyClient.h" 3 | #include "ClientSession.h" 4 | #include "ClientManager.h" 5 | #include 6 | 7 | void ClientManager::Start() 8 | { 9 | tcp::endpoint serv(boost::asio::ip::address::from_string(CONNECT_ADDR), CONNECT_PORT); 10 | 11 | for (int i = 0; i < mTotalDummyCount; ++i) 12 | { 13 | boost::shared_ptr newClient = boost::make_shared(mIoService, START_PLAYER_ID + i); 14 | newClient->Connect(serv); 15 | mClientList.push_back(newClient); 16 | } 17 | 18 | mIoService.run(); 19 | } -------------------------------------------------------------------------------- /DummyClient/DummyClient/ClientManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class ClientSession; 10 | 11 | class ClientManager 12 | { 13 | public: 14 | ClientManager(boost::asio::io_service& io_service, int total=1) 15 | : mIoService(io_service), mTotalDummyCount(total) 16 | {} 17 | 18 | void Start(); 19 | 20 | private: 21 | boost::asio::io_service& mIoService; 22 | 23 | std::vector> mClientList; 24 | 25 | int mTotalDummyCount; 26 | }; -------------------------------------------------------------------------------- /DummyClient/DummyClient/ClientSession.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/DummyClient/DummyClient/ClientSession.cpp -------------------------------------------------------------------------------- /DummyClient/DummyClient/ClientSession.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/DummyClient/DummyClient/ClientSession.h -------------------------------------------------------------------------------- /DummyClient/DummyClient/DummyClient.cpp: -------------------------------------------------------------------------------- 1 | // DummyClient.cpp : Defines the entry point for the console application. 2 | // 3 | 4 | #include "stdafx.h" 5 | #include "DummyClient.h" 6 | #include "ClientSession.h" 7 | #include "ClientManager.h" 8 | #include 9 | 10 | /// config values 11 | int MAX_CONNECTION = 0; 12 | char CONNECT_ADDR[32] = { 0, }; 13 | unsigned short CONNECT_PORT = 0; 14 | 15 | char* GetCommandOption(char** begin, char** end, const std::string& comparand) 16 | { 17 | char** itr = std::find(begin, end, comparand); 18 | if (itr != end && ++itr != end) 19 | return *itr; 20 | 21 | return nullptr; 22 | } 23 | 24 | ///---------------------------------------------------------------------- 25 | 26 | 27 | int main(int argc, char* argv[]) 28 | { 29 | MAX_CONNECTION = 100; 30 | strcpy_s(CONNECT_ADDR, "127.0.0.1"); 31 | CONNECT_PORT = 9001; 32 | 33 | if (argc < 2) 34 | { 35 | printf_s("Usage Example: DummyClients --ip 127.0.0.1 --port 9001 --session 100\n"); 36 | } 37 | else 38 | { 39 | char* ipAddr = GetCommandOption(argv, argv + argc, "--ip"); 40 | char* port = GetCommandOption(argv, argv + argc, "--port"); 41 | char* session = GetCommandOption(argv, argv + argc, "--session"); 42 | 43 | if (ipAddr) 44 | strcpy_s(CONNECT_ADDR, ipAddr); 45 | 46 | if (port) 47 | CONNECT_PORT = atoi(port); 48 | 49 | if (session) 50 | MAX_CONNECTION = atoi(session); 51 | 52 | } 53 | 54 | boost::asio::io_service io_service; 55 | 56 | try 57 | { 58 | auto mgr = boost::make_unique(io_service, MAX_CONNECTION); 59 | 60 | mgr->Start(); ///< block here 61 | } 62 | catch (std::exception& e) 63 | { 64 | std::cerr << e.what() << std::endl; 65 | } 66 | 67 | 68 | return 0; 69 | } 70 | 71 | -------------------------------------------------------------------------------- /DummyClient/DummyClient/DummyClient.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | extern int MAX_CONNECTION; 5 | extern char CONNECT_ADDR[32]; 6 | extern unsigned short CONNECT_PORT; 7 | 8 | #define START_PLAYER_ID 1001 9 | 10 | 11 | -------------------------------------------------------------------------------- /DummyClient/DummyClient/DummyClient.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {0B7CF1BF-E96A-4175-8EB6-CFDA37F86B6E} 15 | Win32Proj 16 | DummyClient 17 | 18 | 19 | 20 | Application 21 | true 22 | v120 23 | MultiByte 24 | 25 | 26 | Application 27 | false 28 | v120 29 | true 30 | MultiByte 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | a9bb9f8a 43 | 44 | 45 | true 46 | 47 | 48 | false 49 | 50 | 51 | 52 | 53 | 54 | Level3 55 | Disabled 56 | _WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 57 | 58 | 59 | Console 60 | true 61 | 62 | 63 | 64 | 65 | Level3 66 | 67 | 68 | MaxSpeed 69 | true 70 | true 71 | _WINSOCK_DEPRECATED_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 72 | 73 | 74 | Console 75 | true 76 | true 77 | true 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /DummyClient/DummyClient/DummyClient.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 6 | h;hh;hpp;hxx;hm;inl;inc;xsd 7 | 8 | 9 | {a16a404a-ad7b-4816-837c-127724a06a42} 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Main 18 | 19 | 20 | Main 21 | 22 | 23 | Packet 24 | 25 | 26 | Main 27 | 28 | 29 | Main 30 | 31 | 32 | Main 33 | 34 | 35 | 36 | 37 | Main 38 | 39 | 40 | Main 41 | 42 | 43 | Main 44 | 45 | 46 | Main 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /DummyClient/DummyClient/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | CONSOLE APPLICATION : DummyClient Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this DummyClient application for you. 6 | 7 | This file contains a summary of what you will find in each of the files that 8 | make up your DummyClient application. 9 | 10 | 11 | DummyClient.vcxproj 12 | This is the main project file for VC++ projects generated using an Application Wizard. 13 | It contains information about the version of Visual C++ that generated the file, and 14 | information about the platforms, configurations, and project features selected with the 15 | Application Wizard. 16 | 17 | DummyClient.vcxproj.filters 18 | This is the filters file for VC++ projects generated using an Application Wizard. 19 | It contains information about the association between the files in your project 20 | and the filters. This association is used in the IDE to show grouping of files with 21 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 22 | "Source Files" filter). 23 | 24 | DummyClient.cpp 25 | This is the main application source file. 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | Other standard files: 29 | 30 | StdAfx.h, StdAfx.cpp 31 | These files are used to build a precompiled header (PCH) file 32 | named DummyClient.pch and a precompiled types file named StdAfx.obj. 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | Other notes: 36 | 37 | AppWizard uses "TODO:" comments to indicate parts of the source code you 38 | should add to or customize. 39 | 40 | ///////////////////////////////////////////////////////////////////////////// 41 | -------------------------------------------------------------------------------- /DummyClient/DummyClient/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /DummyClient/DummyClient/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // DummyClient.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /DummyClient/DummyClient/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | // TODO: reference additional headers your program requires here 19 | -------------------------------------------------------------------------------- /DummyClient/DummyClient/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /EasyServer/Database/SQLiteSpy.db3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/Database/SQLiteSpy.db3 -------------------------------------------------------------------------------- /EasyServer/Database/SQLiteSpy.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/Database/SQLiteSpy.exe -------------------------------------------------------------------------------- /EasyServer/Database/user_example.db3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/Database/user_example.db3 -------------------------------------------------------------------------------- /EasyServer/EasyServer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EasyServer", "EasyServer\EasyServer.vcxproj", "{FE38EC36-C831-4AFE-A6AA-03C59E2BB81B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release|Win32 = Release|Win32 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {FE38EC36-C831-4AFE-A6AA-03C59E2BB81B}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {FE38EC36-C831-4AFE-A6AA-03C59E2BB81B}.Debug|Win32.Build.0 = Debug|Win32 18 | {FE38EC36-C831-4AFE-A6AA-03C59E2BB81B}.Debug|x64.ActiveCfg = Debug|x64 19 | {FE38EC36-C831-4AFE-A6AA-03C59E2BB81B}.Debug|x64.Build.0 = Debug|x64 20 | {FE38EC36-C831-4AFE-A6AA-03C59E2BB81B}.Release|Win32.ActiveCfg = Release|Win32 21 | {FE38EC36-C831-4AFE-A6AA-03C59E2BB81B}.Release|Win32.Build.0 = Release|Win32 22 | {FE38EC36-C831-4AFE-A6AA-03C59E2BB81B}.Release|x64.ActiveCfg = Release|x64 23 | {FE38EC36-C831-4AFE-A6AA-03C59E2BB81B}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /EasyServer/EasyServer/CircularBuffer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/CircularBuffer.cpp -------------------------------------------------------------------------------- /EasyServer/EasyServer/CircularBuffer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/CircularBuffer.h -------------------------------------------------------------------------------- /EasyServer/EasyServer/ClientManager.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/ClientManager.cpp -------------------------------------------------------------------------------- /EasyServer/EasyServer/ClientManager.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/ClientManager.h -------------------------------------------------------------------------------- /EasyServer/EasyServer/ClientSession.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Scheduler.h" 3 | #include "ClientSession.h" 4 | #include "..\..\PacketType.h" 5 | #include "ClientManager.h" 6 | #include "DatabaseJobContext.h" 7 | #include "DatabaseJobManager.h" 8 | 9 | 10 | bool ClientSession::OnConnect(SOCKADDR_IN* addr) 11 | { 12 | memcpy(&mClientAddr, addr, sizeof(SOCKADDR_IN)) ; 13 | 14 | /// 소켓을 넌블러킹으로 바꾸고 15 | u_long arg = 1 ; 16 | ioctlsocket(mSocket, FIONBIO, &arg) ; 17 | 18 | /// nagle 알고리즘 끄기 19 | int opt = 1 ; 20 | setsockopt(mSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&opt, sizeof(int)) ; 21 | 22 | printf("[DEBUG] Client Connected: IP=%s, PORT=%d\n", inet_ntoa(mClientAddr.sin_addr), ntohs(mClientAddr.sin_port)) ; 23 | 24 | mConnected = true ; 25 | 26 | return PostRecv() ; 27 | } 28 | 29 | bool ClientSession::PostRecv() 30 | { 31 | if ( !IsConnected() ) 32 | return false ; 33 | 34 | DWORD recvbytes = 0 ; 35 | DWORD flags = 0 ; 36 | WSABUF buf ; 37 | buf.len = (ULONG)mRecvBuffer.GetFreeSpaceSize() ; 38 | buf.buf = (char*)mRecvBuffer.GetBuffer() ; 39 | 40 | memset(&mOverlappedRecv, 0, sizeof(OverlappedIO)) ; 41 | mOverlappedRecv.mObject = this ; 42 | 43 | /// 비동기 입출력 시작 44 | if ( SOCKET_ERROR == WSARecv(mSocket, &buf, 1, &recvbytes, &flags, &mOverlappedRecv, RecvCompletion) ) 45 | { 46 | if ( WSAGetLastError() != WSA_IO_PENDING ) 47 | return false ; 48 | } 49 | 50 | IncRefCount() ; 51 | 52 | return true ; 53 | } 54 | 55 | void ClientSession::Disconnect() 56 | { 57 | if ( !IsConnected() ) 58 | return ; 59 | 60 | printf("[DEBUG] Client Disconnected: IP=%s, PORT=%d\n", inet_ntoa(mClientAddr.sin_addr), ntohs(mClientAddr.sin_port)) ; 61 | 62 | /// 즉각 해제 63 | 64 | LINGER lingerOption; 65 | lingerOption.l_onoff = 1; 66 | lingerOption.l_linger = 0; 67 | 68 | /// no TCP TIME_WAIT 69 | if (SOCKET_ERROR == setsockopt(mSocket, SOL_SOCKET, SO_LINGER, (char*)&lingerOption, sizeof(LINGER))) 70 | { 71 | printf_s("[DEBUG] setsockopt linger option error: %d\n", GetLastError()); 72 | return; 73 | } 74 | 75 | closesocket(mSocket) ; 76 | 77 | mConnected = false ; 78 | } 79 | 80 | 81 | 82 | 83 | bool ClientSession::SendRequest(PacketHeader* pkt) 84 | { 85 | if ( !IsConnected() ) 86 | return false ; 87 | 88 | /// Send 요청은 버퍼에 쌓아놨다가 한번에 보낸다. 89 | if ( false == mSendBuffer.Write((char*)pkt, pkt->mSize) ) 90 | { 91 | /// 버퍼 용량 부족인 경우는 끊어버림 92 | Disconnect() ; 93 | return false ; 94 | } 95 | 96 | return true; 97 | 98 | } 99 | 100 | bool ClientSession::SendFlush() 101 | { 102 | if (!IsConnected()) 103 | return false; 104 | 105 | /// 보낼 데이터가 없으면 그냥 리턴 106 | if (mSendBuffer.GetContiguiousBytes() == 0) 107 | return true; 108 | 109 | DWORD sendbytes = 0; 110 | DWORD flags = 0; 111 | 112 | WSABUF buf; 113 | buf.len = (ULONG)mSendBuffer.GetContiguiousBytes(); 114 | buf.buf = (char*)mSendBuffer.GetBufferStart(); 115 | 116 | memset(&mOverlappedSend, 0, sizeof(OverlappedIO)); 117 | mOverlappedSend.mObject = this; 118 | 119 | /// 비동기 입출력 시작 120 | if (SOCKET_ERROR == WSASend(mSocket, &buf, 1, &sendbytes, flags, &mOverlappedSend, SendCompletion)) 121 | { 122 | if (WSAGetLastError() != WSA_IO_PENDING) 123 | return false; 124 | } 125 | 126 | IncRefCount(); 127 | 128 | return true; 129 | } 130 | 131 | void ClientSession::OnWriteComplete(size_t len) 132 | { 133 | /// 보내기 완료한 데이터는 버퍼에서 제거 134 | mSendBuffer.Remove(len) ; 135 | } 136 | 137 | bool ClientSession::Broadcast(PacketHeader* pkt) 138 | { 139 | if ( !SendRequest(pkt) ) 140 | return false ; 141 | 142 | if ( !IsConnected() ) 143 | return false ; 144 | 145 | GClientManager->BroadcastPacket(this, pkt) ; 146 | 147 | return true ; 148 | } 149 | 150 | void ClientSession::OnTick() 151 | { 152 | if (!IsConnected()) 153 | return; 154 | 155 | /// 클라별로 주기적으로 해야될 일은 여기에 156 | 157 | 158 | 159 | CallFuncAfter(PLAYER_HEART_BEAT, this, &ClientSession::OnTick); 160 | } 161 | 162 | void ClientSession::OnDbUpdate() 163 | { 164 | if (!IsConnected()) 165 | return; 166 | 167 | UpdatePlayerDataContext* updatePlayer = new UpdatePlayerDataContext(mSocket, mPlayerId) ; 168 | 169 | updatePlayer->mPosX = mPosX ; 170 | updatePlayer->mPosY = mPosY ; 171 | strcpy_s(updatePlayer->mComment, "updated_test") ; ///< 일단은 테스트를 위한 코멘트 172 | GDatabaseJobManager->PushDatabaseJobRequest(updatePlayer) ; 173 | 174 | CallFuncAfter(PLAYER_DB_UPDATE_INTERVAL, this, &ClientSession::OnDbUpdate); 175 | 176 | } 177 | 178 | 179 | void ClientSession::DatabaseJobDone(DatabaseJobContext* result) 180 | { 181 | CRASH_ASSERT( mSocket == result->mSockKey ) ; 182 | 183 | 184 | const type_info& typeInfo = typeid(*result) ; 185 | 186 | if ( typeInfo == typeid(LoadPlayerDataContext) ) 187 | { 188 | LoadPlayerDataContext* login = dynamic_cast(result) ; 189 | 190 | LoginDone(login->mPlayerId, (float)login->mPosX, (float)login->mPosY, login->mPlayerName) ; 191 | 192 | } 193 | else if ( typeInfo == typeid(UpdatePlayerDataContext) ) 194 | { 195 | UpdateDone() ; 196 | } 197 | else 198 | { 199 | CRASH_ASSERT(false) ; 200 | } 201 | 202 | } 203 | 204 | void ClientSession::UpdateDone() 205 | { 206 | /// 콘텐츠를 넣기 전까지는 딱히 해줄 것이 없다. 단지 테스트를 위해서.. 207 | printf("Player[%d] Update Done\n", mPlayerId) ; 208 | } 209 | 210 | 211 | 212 | void ClientSession::LoginDone(int pid, float x, float y, const char* name) 213 | { 214 | LoginResult outPacket ; 215 | 216 | outPacket.mPlayerId = mPlayerId = pid ; 217 | outPacket.mPosX = mPosX = x ; 218 | outPacket.mPosY = mPosY = y ; 219 | strcpy_s(mPlayerName, name) ; 220 | strcpy_s(outPacket.mName, name) ; 221 | 222 | SendRequest(&outPacket) ; 223 | 224 | mLogon = true ; 225 | 226 | /// heartbeat gogo 227 | OnTick(); 228 | 229 | /// first db update gogo 230 | OnDbUpdate(); 231 | } 232 | 233 | 234 | -------------------------------------------------------------------------------- /EasyServer/EasyServer/ClientSession.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/ClientSession.h -------------------------------------------------------------------------------- /EasyServer/EasyServer/Config.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/Config.h -------------------------------------------------------------------------------- /EasyServer/EasyServer/DatabaseJobContext.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "DatabaseJobContext.h" 3 | #include "SQLStatement.h" 4 | #include "DbHelper.h" 5 | 6 | 7 | 8 | bool LoadPlayerDataContext::OnExecute() 9 | { 10 | DbHelper dbhelper(SQL_SelectTest) ; 11 | dbhelper.BindParamInt(mPlayerId) ; 12 | 13 | /// 데이터가 없네? 14 | if ( RESULT_ROW != dbhelper.FetchRow() ) 15 | return false ; 16 | 17 | 18 | const unsigned char* name = dbhelper.GetResultParamText() ; 19 | mPosX = dbhelper.GetResultParamDouble() ; 20 | mPosY = dbhelper.GetResultParamDouble() ; 21 | mPosZ = dbhelper.GetResultParamDouble() ; 22 | 23 | strcpy_s(mPlayerName, (char*)name) ; 24 | 25 | 26 | return true ; 27 | } 28 | 29 | bool CreatePlayerDataContext::OnExecute() 30 | { 31 | DbHelper dbhelper(SQL_InsertTest) ; 32 | 33 | dbhelper.BindParamInt(mPlayerId) ; 34 | dbhelper.BindParamText(mPlayerName, strlen(mPlayerName)) ; 35 | dbhelper.BindParamDouble(mPosX) ; 36 | dbhelper.BindParamDouble(mPosY) ; 37 | dbhelper.BindParamDouble(mPosZ) ; 38 | dbhelper.BindParamText(mComment, strlen(mComment)) ; 39 | 40 | if ( RESULT_ERROR == dbhelper.FetchRow() ) 41 | return false ; 42 | 43 | return true ; 44 | } 45 | 46 | bool DeletePlayerDataContext::OnExecute() 47 | { 48 | DbHelper dbhelper(SQL_DeleteTest) ; 49 | dbhelper.BindParamInt(mPlayerId) ; 50 | 51 | if ( RESULT_ERROR == dbhelper.FetchRow() ) 52 | return false ; 53 | 54 | return true ; 55 | 56 | } 57 | 58 | bool UpdatePlayerDataContext::OnExecute() 59 | { 60 | DbHelper dbhelper(SQL_UpdateTest) ; 61 | 62 | dbhelper.BindParamDouble(mPosX) ; 63 | dbhelper.BindParamDouble(mPosY) ; 64 | dbhelper.BindParamDouble(mPosZ) ; 65 | dbhelper.BindParamText(mComment, strlen(mComment)) ; 66 | dbhelper.BindParamInt(mPlayerId) ; 67 | 68 | if ( RESULT_ERROR == dbhelper.FetchRow() ) 69 | return false ; 70 | 71 | return true ; 72 | 73 | } 74 | -------------------------------------------------------------------------------- /EasyServer/EasyServer/DatabaseJobContext.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/DatabaseJobContext.h -------------------------------------------------------------------------------- /EasyServer/EasyServer/DatabaseJobManager.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/DatabaseJobManager.cpp -------------------------------------------------------------------------------- /EasyServer/EasyServer/DatabaseJobManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "ProducerConsumerQueue.h" 5 | 6 | struct DatabaseJobContext ; 7 | 8 | class DatabaseJobManager 9 | { 10 | public: 11 | DatabaseJobManager() {} 12 | 13 | void ExecuteDatabaseJobs() ; 14 | 15 | void PushDatabaseJobRequest(DatabaseJobContext* jobContext) ; 16 | bool PopDatabaseJobResult(DatabaseJobContext*& jobContext) ; 17 | 18 | private: 19 | enum 20 | { 21 | MAX_DB_JOB = 127 22 | } ; 23 | 24 | ProducerConsumerQueue mDbJobRequestQueue; 25 | ProducerConsumerQueue mDbJobResultQueue; 26 | 27 | } ; 28 | 29 | extern DatabaseJobManager* GDatabaseJobManager ; -------------------------------------------------------------------------------- /EasyServer/EasyServer/DbHelper.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/DbHelper.cpp -------------------------------------------------------------------------------- /EasyServer/EasyServer/DbHelper.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/DbHelper.h -------------------------------------------------------------------------------- /EasyServer/EasyServer/EasyServer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/EasyServer.cpp -------------------------------------------------------------------------------- /EasyServer/EasyServer/EasyServer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum ThreadType 4 | { 5 | THREAD_MAIN = 1, 6 | THREAD_CLIENT = 2, 7 | THREAD_DATABASE = 3 8 | }; 9 | 10 | unsigned int WINAPI ClientHandlingThread( LPVOID lpParam ) ; 11 | unsigned int WINAPI DatabaseHandlingThread( LPVOID lpParam ) ; 12 | void CALLBACK TimerProc(LPVOID lpArg, DWORD dwTimerLowValue, DWORD dwTimerHighValue) ; 13 | 14 | -------------------------------------------------------------------------------- /EasyServer/EasyServer/EasyServer.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {FE38EC36-C831-4AFE-A6AA-03C59E2BB81B} 23 | Win32Proj 24 | EasyServer 25 | 26 | 27 | 28 | Application 29 | true 30 | v120 31 | Unicode 32 | 33 | 34 | Application 35 | true 36 | v120 37 | Unicode 38 | 39 | 40 | Application 41 | false 42 | v120 43 | true 44 | Unicode 45 | 46 | 47 | Application 48 | false 49 | v120 50 | true 51 | Unicode 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | true 71 | 72 | 73 | true 74 | 75 | 76 | false 77 | 78 | 79 | false 80 | 81 | 82 | 83 | Use 84 | Level3 85 | Disabled 86 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 87 | true 88 | 4996;4703 89 | 90 | 91 | Console 92 | true 93 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;DbgHelp.lib;%(AdditionalDependencies) 94 | 95 | 96 | 97 | 98 | Use 99 | Level3 100 | Disabled 101 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 102 | true 103 | 4996;4703 104 | 105 | 106 | Console 107 | true 108 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;DbgHelp.lib;%(AdditionalDependencies) 109 | 110 | 111 | 112 | 113 | Level3 114 | Use 115 | MaxSpeed 116 | true 117 | true 118 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 119 | true 120 | /d2Zi+ %(AdditionalOptions) 121 | 4996;4703 122 | 123 | 124 | Console 125 | true 126 | true 127 | true 128 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;DbgHelp.lib;%(AdditionalDependencies) 129 | 130 | 131 | 132 | 133 | Level3 134 | Use 135 | MaxSpeed 136 | true 137 | true 138 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 139 | true 140 | /d2Zi+ %(AdditionalOptions) 141 | 4996;4703 142 | 143 | 144 | Console 145 | true 146 | true 147 | true 148 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;DbgHelp.lib;%(AdditionalDependencies) 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | NotUsing 189 | NotUsing 190 | NotUsing 191 | NotUsing 192 | 193 | 194 | Create 195 | Create 196 | Create 197 | Create 198 | 199 | 200 | 201 | 202 | 203 | 204 | -------------------------------------------------------------------------------- /EasyServer/EasyServer/EasyServer.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {002996bc-5f49-4034-9846-d804baed220a} 6 | 7 | 8 | {3cfbe6f1-5834-4652-a3f4-358ccb895128} 9 | 10 | 11 | {25fda20e-051c-4cae-8314-1442428c9b70} 12 | 13 | 14 | {70ad0489-0679-4018-996a-e52df58bf401} 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Packet 23 | 24 | 25 | Utils 26 | 27 | 28 | Utils 29 | 30 | 31 | Utils 32 | 33 | 34 | Utils 35 | 36 | 37 | Utils 38 | 39 | 40 | Main 41 | 42 | 43 | Main 44 | 45 | 46 | Main 47 | 48 | 49 | Main 50 | 51 | 52 | Main 53 | 54 | 55 | Main 56 | 57 | 58 | Main 59 | 60 | 61 | Main 62 | 63 | 64 | Main 65 | 66 | 67 | Utils 68 | 69 | 70 | Utils 71 | 72 | 73 | Utils 74 | 75 | 76 | Utils\SQLite3 77 | 78 | 79 | Utils\SQLite3 80 | 81 | 82 | 83 | 84 | Utils 85 | 86 | 87 | Utils 88 | 89 | 90 | Utils 91 | 92 | 93 | Main 94 | 95 | 96 | Main 97 | 98 | 99 | Packet 100 | 101 | 102 | Main 103 | 104 | 105 | Main 106 | 107 | 108 | Main 109 | 110 | 111 | Main 112 | 113 | 114 | Utils 115 | 116 | 117 | Utils 118 | 119 | 120 | Utils\SQLite3 121 | 122 | 123 | -------------------------------------------------------------------------------- /EasyServer/EasyServer/Exception.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Exception.h" 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | #define MAX_BUFF_SIZE 1024 9 | 10 | void MakeDump(EXCEPTION_POINTERS* e) 11 | { 12 | TCHAR tszFileName[MAX_BUFF_SIZE] = { 0 }; 13 | SYSTEMTIME stTime = { 0 }; 14 | GetSystemTime(&stTime); 15 | StringCbPrintf(tszFileName, 16 | _countof(tszFileName), 17 | _T("%s_%4d%02d%02d_%02d%02d%02d.dmp"), 18 | _T("EasyGameServerDump"), 19 | stTime.wYear, 20 | stTime.wMonth, 21 | stTime.wDay, 22 | stTime.wHour, 23 | stTime.wMinute, 24 | stTime.wSecond); 25 | 26 | HANDLE hFile = CreateFile(tszFileName, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); 27 | if (hFile == INVALID_HANDLE_VALUE) 28 | return; 29 | 30 | MINIDUMP_EXCEPTION_INFORMATION exceptionInfo; 31 | exceptionInfo.ThreadId = GetCurrentThreadId(); 32 | exceptionInfo.ExceptionPointers = e; 33 | exceptionInfo.ClientPointers = FALSE; 34 | 35 | MiniDumpWriteDump( 36 | GetCurrentProcess(), 37 | GetCurrentProcessId(), 38 | hFile, 39 | MINIDUMP_TYPE(MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory | MiniDumpWithFullMemory), 40 | e ? &exceptionInfo : NULL, 41 | NULL, 42 | NULL); 43 | 44 | if (hFile) 45 | { 46 | CloseHandle(hFile); 47 | hFile = NULL; 48 | } 49 | 50 | } 51 | 52 | LONG WINAPI ExceptionFilter(EXCEPTION_POINTERS* exceptionInfo) 53 | { 54 | if ( IsDebuggerPresent() ) 55 | return EXCEPTION_CONTINUE_SEARCH ; 56 | 57 | THREADENTRY32 te32; 58 | DWORD myThreadId = GetCurrentThreadId(); 59 | DWORD myProcessId = GetCurrentProcessId(); 60 | 61 | HANDLE hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); 62 | if (hThreadSnap != INVALID_HANDLE_VALUE) 63 | { 64 | te32.dwSize = sizeof(THREADENTRY32); 65 | 66 | if (Thread32First(hThreadSnap, &te32)) 67 | { 68 | do 69 | { 70 | /// 내 프로세스 내의 스레드중 나 자신 스레드만 빼고 멈추게.. 71 | if (te32.th32OwnerProcessID == myProcessId && te32.th32ThreadID != myThreadId) 72 | { 73 | HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, FALSE, te32.th32ThreadID); 74 | if (hThread) 75 | { 76 | SuspendThread(hThread); 77 | } 78 | } 79 | 80 | } while (Thread32Next(hThreadSnap, &te32)); 81 | 82 | } 83 | 84 | CloseHandle(hThreadSnap); 85 | } 86 | 87 | 88 | /// dump file 남기자. 89 | MakeDump(exceptionInfo); 90 | 91 | /// 여기서 쫑 92 | ExitProcess(1); 93 | 94 | return EXCEPTION_EXECUTE_HANDLER ; 95 | } -------------------------------------------------------------------------------- /EasyServer/EasyServer/Exception.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | LONG WINAPI ExceptionFilter(EXCEPTION_POINTERS* exceptionInfo) ; 4 | 5 | inline void CRASH_ASSERT(bool isOk) 6 | { 7 | if ( isOk ) 8 | return ; 9 | 10 | int* crashVal = 0 ; 11 | *crashVal = 0xDEADBEEF ; 12 | } 13 | -------------------------------------------------------------------------------- /EasyServer/EasyServer/ObjectPool.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/ObjectPool.h -------------------------------------------------------------------------------- /EasyServer/EasyServer/PacketHandling.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/PacketHandling.cpp -------------------------------------------------------------------------------- /EasyServer/EasyServer/ProducerConsumerQueue.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/ProducerConsumerQueue.h -------------------------------------------------------------------------------- /EasyServer/EasyServer/ReadMe.txt: -------------------------------------------------------------------------------- 1 | # HOMEWORK TO DO 2 | 3 | - ClientSession에서 Player Contents 부분 분리할 것 4 | (network layer와 contents layer 분리) 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /EasyServer/EasyServer/RefCountable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct RefCountable 4 | { 5 | RefCountable() : mRefCount(0) 6 | {} 7 | virtual ~RefCountable() 8 | {} 9 | 10 | void IncRefCount() { ++mRefCount; } 11 | void DecRefCount() { --mRefCount; } 12 | int GetRefCount() { return mRefCount; } 13 | 14 | int mRefCount; 15 | }; 16 | -------------------------------------------------------------------------------- /EasyServer/EasyServer/SQLStatement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | const char* SQL_InsertTest = "INSERT INTO players VALUES(?, ?, ?, ?, ?, ?)" ; 4 | const char* SQL_SelectTest = "SELECT name, pos_x, pos_y, pos_z FROM players WHERE pid=?" ; 5 | const char* SQL_UpdateTest = "UPDATE players SET pos_x=?, pos_y=?, pos_z=?, comment=? WHERE pid=?" ; 6 | const char* SQL_DeleteTest = "DELETE FROM players WHERE pid=?" ; 7 | 8 | -------------------------------------------------------------------------------- /EasyServer/EasyServer/Scheduler.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Scheduler.h" 3 | 4 | 5 | Scheduler::Scheduler() 6 | { 7 | mCurrentTick = GetTickCount(); 8 | } 9 | 10 | 11 | void Scheduler::PushTask(RefCountable* owner, Task&& task, uint32_t after) 12 | { 13 | int64_t dueTimeTick = after + mCurrentTick; 14 | 15 | owner->IncRefCount(); ///< for scheduler 16 | mTaskQueue.push(JobElement(owner, std::move(task), dueTimeTick)); 17 | } 18 | 19 | 20 | void Scheduler::DoTasks() 21 | { 22 | /// tick update 23 | mCurrentTick = GetTickCount(); 24 | 25 | while (!mTaskQueue.empty()) 26 | { 27 | JobElement timerJobElem = mTaskQueue.top(); 28 | 29 | if (mCurrentTick < timerJobElem.mExecutionTick) 30 | break; 31 | 32 | /// do task! 33 | timerJobElem.mTask(); 34 | 35 | timerJobElem.mOwner->DecRefCount(); ///< for scheduler 36 | 37 | mTaskQueue.pop(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /EasyServer/EasyServer/Scheduler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "RefCountable.h" 6 | #include "ThreadLocal.h" 7 | 8 | typedef std::function Task; 9 | 10 | struct JobElement 11 | { 12 | JobElement(RefCountable* owner, Task&& task, int64_t execTick) 13 | : mOwner(owner), mTask(std::move(task)), mExecutionTick(execTick) 14 | {} 15 | 16 | RefCountable* mOwner; 17 | Task mTask; 18 | int64_t mExecutionTick; 19 | }; 20 | 21 | struct JobComparator 22 | { 23 | bool operator()(const JobElement& lhs, const JobElement& rhs) 24 | { 25 | return lhs.mExecutionTick > rhs.mExecutionTick; 26 | } 27 | }; 28 | 29 | 30 | typedef std::priority_queue, JobComparator> TaskPriorityQueue; 31 | 32 | class Scheduler 33 | { 34 | public: 35 | 36 | Scheduler(); 37 | 38 | void PushTask(RefCountable* owner, Task&& task, uint32_t after); 39 | 40 | void DoTasks(); 41 | 42 | private: 43 | TaskPriorityQueue mTaskQueue; 44 | DWORD mCurrentTick; 45 | }; 46 | 47 | 48 | template 49 | void CallFuncAfter(uint32_t after, T instance, F memfunc, Args&&... args) 50 | { 51 | static_assert(true == std::is_convertible::value, "only allowed when RefCountable*"); 52 | 53 | LScheduler->PushTask(static_cast(instance), std::bind(memfunc, instance, std::forward(args)...), after); 54 | } -------------------------------------------------------------------------------- /EasyServer/EasyServer/ThreadLocal.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "ThreadLocal.h" 3 | 4 | __declspec(thread) int LThreadType = -1; 5 | __declspec(thread) Scheduler* LScheduler = nullptr; 6 | 7 | 8 | -------------------------------------------------------------------------------- /EasyServer/EasyServer/ThreadLocal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Scheduler; 4 | 5 | extern __declspec(thread) int LThreadType; 6 | extern __declspec(thread) Scheduler* LScheduler; 7 | -------------------------------------------------------------------------------- /EasyServer/EasyServer/sqlite3ext.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2006 June 7 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This header file defines the SQLite interface for use by 13 | ** shared libraries that want to be imported as extensions into 14 | ** an SQLite instance. Shared libraries that intend to be loaded 15 | ** as extensions by SQLite should #include this file instead of 16 | ** sqlite3.h. 17 | */ 18 | #ifndef _SQLITE3EXT_H_ 19 | #define _SQLITE3EXT_H_ 20 | #include "sqlite3.h" 21 | 22 | typedef struct sqlite3_api_routines sqlite3_api_routines; 23 | 24 | /* 25 | ** The following structure holds pointers to all of the SQLite API 26 | ** routines. 27 | ** 28 | ** WARNING: In order to maintain backwards compatibility, add new 29 | ** interfaces to the end of this structure only. If you insert new 30 | ** interfaces in the middle of this structure, then older different 31 | ** versions of SQLite will not be able to load each others' shared 32 | ** libraries! 33 | */ 34 | struct sqlite3_api_routines { 35 | void * (*aggregate_context)(sqlite3_context*,int nBytes); 36 | int (*aggregate_count)(sqlite3_context*); 37 | int (*bind_blob)(sqlite3_stmt*,int,const void*,int n,void(*)(void*)); 38 | int (*bind_double)(sqlite3_stmt*,int,double); 39 | int (*bind_int)(sqlite3_stmt*,int,int); 40 | int (*bind_int64)(sqlite3_stmt*,int,sqlite_int64); 41 | int (*bind_null)(sqlite3_stmt*,int); 42 | int (*bind_parameter_count)(sqlite3_stmt*); 43 | int (*bind_parameter_index)(sqlite3_stmt*,const char*zName); 44 | const char * (*bind_parameter_name)(sqlite3_stmt*,int); 45 | int (*bind_text)(sqlite3_stmt*,int,const char*,int n,void(*)(void*)); 46 | int (*bind_text16)(sqlite3_stmt*,int,const void*,int,void(*)(void*)); 47 | int (*bind_value)(sqlite3_stmt*,int,const sqlite3_value*); 48 | int (*busy_handler)(sqlite3*,int(*)(void*,int),void*); 49 | int (*busy_timeout)(sqlite3*,int ms); 50 | int (*changes)(sqlite3*); 51 | int (*close)(sqlite3*); 52 | int (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*, 53 | int eTextRep,const char*)); 54 | int (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*, 55 | int eTextRep,const void*)); 56 | const void * (*column_blob)(sqlite3_stmt*,int iCol); 57 | int (*column_bytes)(sqlite3_stmt*,int iCol); 58 | int (*column_bytes16)(sqlite3_stmt*,int iCol); 59 | int (*column_count)(sqlite3_stmt*pStmt); 60 | const char * (*column_database_name)(sqlite3_stmt*,int); 61 | const void * (*column_database_name16)(sqlite3_stmt*,int); 62 | const char * (*column_decltype)(sqlite3_stmt*,int i); 63 | const void * (*column_decltype16)(sqlite3_stmt*,int); 64 | double (*column_double)(sqlite3_stmt*,int iCol); 65 | int (*column_int)(sqlite3_stmt*,int iCol); 66 | sqlite_int64 (*column_int64)(sqlite3_stmt*,int iCol); 67 | const char * (*column_name)(sqlite3_stmt*,int); 68 | const void * (*column_name16)(sqlite3_stmt*,int); 69 | const char * (*column_origin_name)(sqlite3_stmt*,int); 70 | const void * (*column_origin_name16)(sqlite3_stmt*,int); 71 | const char * (*column_table_name)(sqlite3_stmt*,int); 72 | const void * (*column_table_name16)(sqlite3_stmt*,int); 73 | const unsigned char * (*column_text)(sqlite3_stmt*,int iCol); 74 | const void * (*column_text16)(sqlite3_stmt*,int iCol); 75 | int (*column_type)(sqlite3_stmt*,int iCol); 76 | sqlite3_value* (*column_value)(sqlite3_stmt*,int iCol); 77 | void * (*commit_hook)(sqlite3*,int(*)(void*),void*); 78 | int (*complete)(const char*sql); 79 | int (*complete16)(const void*sql); 80 | int (*create_collation)(sqlite3*,const char*,int,void*, 81 | int(*)(void*,int,const void*,int,const void*)); 82 | int (*create_collation16)(sqlite3*,const void*,int,void*, 83 | int(*)(void*,int,const void*,int,const void*)); 84 | int (*create_function)(sqlite3*,const char*,int,int,void*, 85 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 86 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), 87 | void (*xFinal)(sqlite3_context*)); 88 | int (*create_function16)(sqlite3*,const void*,int,int,void*, 89 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 90 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), 91 | void (*xFinal)(sqlite3_context*)); 92 | int (*create_module)(sqlite3*,const char*,const sqlite3_module*,void*); 93 | int (*data_count)(sqlite3_stmt*pStmt); 94 | sqlite3 * (*db_handle)(sqlite3_stmt*); 95 | int (*declare_vtab)(sqlite3*,const char*); 96 | int (*enable_shared_cache)(int); 97 | int (*errcode)(sqlite3*db); 98 | const char * (*errmsg)(sqlite3*); 99 | const void * (*errmsg16)(sqlite3*); 100 | int (*exec)(sqlite3*,const char*,sqlite3_callback,void*,char**); 101 | int (*expired)(sqlite3_stmt*); 102 | int (*finalize)(sqlite3_stmt*pStmt); 103 | void (*free)(void*); 104 | void (*free_table)(char**result); 105 | int (*get_autocommit)(sqlite3*); 106 | void * (*get_auxdata)(sqlite3_context*,int); 107 | int (*get_table)(sqlite3*,const char*,char***,int*,int*,char**); 108 | int (*global_recover)(void); 109 | void (*interruptx)(sqlite3*); 110 | sqlite_int64 (*last_insert_rowid)(sqlite3*); 111 | const char * (*libversion)(void); 112 | int (*libversion_number)(void); 113 | void *(*malloc)(int); 114 | char * (*mprintf)(const char*,...); 115 | int (*open)(const char*,sqlite3**); 116 | int (*open16)(const void*,sqlite3**); 117 | int (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**); 118 | int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**); 119 | void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*); 120 | void (*progress_handler)(sqlite3*,int,int(*)(void*),void*); 121 | void *(*realloc)(void*,int); 122 | int (*reset)(sqlite3_stmt*pStmt); 123 | void (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*)); 124 | void (*result_double)(sqlite3_context*,double); 125 | void (*result_error)(sqlite3_context*,const char*,int); 126 | void (*result_error16)(sqlite3_context*,const void*,int); 127 | void (*result_int)(sqlite3_context*,int); 128 | void (*result_int64)(sqlite3_context*,sqlite_int64); 129 | void (*result_null)(sqlite3_context*); 130 | void (*result_text)(sqlite3_context*,const char*,int,void(*)(void*)); 131 | void (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*)); 132 | void (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*)); 133 | void (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*)); 134 | void (*result_value)(sqlite3_context*,sqlite3_value*); 135 | void * (*rollback_hook)(sqlite3*,void(*)(void*),void*); 136 | int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*, 137 | const char*,const char*),void*); 138 | void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*)); 139 | char * (*snprintf)(int,char*,const char*,...); 140 | int (*step)(sqlite3_stmt*); 141 | int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*, 142 | char const**,char const**,int*,int*,int*); 143 | void (*thread_cleanup)(void); 144 | int (*total_changes)(sqlite3*); 145 | void * (*trace)(sqlite3*,void(*xTrace)(void*,const char*),void*); 146 | int (*transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*); 147 | void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*, 148 | sqlite_int64),void*); 149 | void * (*user_data)(sqlite3_context*); 150 | const void * (*value_blob)(sqlite3_value*); 151 | int (*value_bytes)(sqlite3_value*); 152 | int (*value_bytes16)(sqlite3_value*); 153 | double (*value_double)(sqlite3_value*); 154 | int (*value_int)(sqlite3_value*); 155 | sqlite_int64 (*value_int64)(sqlite3_value*); 156 | int (*value_numeric_type)(sqlite3_value*); 157 | const unsigned char * (*value_text)(sqlite3_value*); 158 | const void * (*value_text16)(sqlite3_value*); 159 | const void * (*value_text16be)(sqlite3_value*); 160 | const void * (*value_text16le)(sqlite3_value*); 161 | int (*value_type)(sqlite3_value*); 162 | char *(*vmprintf)(const char*,va_list); 163 | /* Added ??? */ 164 | int (*overload_function)(sqlite3*, const char *zFuncName, int nArg); 165 | /* Added by 3.3.13 */ 166 | int (*prepare_v2)(sqlite3*,const char*,int,sqlite3_stmt**,const char**); 167 | int (*prepare16_v2)(sqlite3*,const void*,int,sqlite3_stmt**,const void**); 168 | int (*clear_bindings)(sqlite3_stmt*); 169 | /* Added by 3.4.1 */ 170 | int (*create_module_v2)(sqlite3*,const char*,const sqlite3_module*,void*, 171 | void (*xDestroy)(void *)); 172 | /* Added by 3.5.0 */ 173 | int (*bind_zeroblob)(sqlite3_stmt*,int,int); 174 | int (*blob_bytes)(sqlite3_blob*); 175 | int (*blob_close)(sqlite3_blob*); 176 | int (*blob_open)(sqlite3*,const char*,const char*,const char*,sqlite3_int64, 177 | int,sqlite3_blob**); 178 | int (*blob_read)(sqlite3_blob*,void*,int,int); 179 | int (*blob_write)(sqlite3_blob*,const void*,int,int); 180 | int (*create_collation_v2)(sqlite3*,const char*,int,void*, 181 | int(*)(void*,int,const void*,int,const void*), 182 | void(*)(void*)); 183 | int (*file_control)(sqlite3*,const char*,int,void*); 184 | sqlite3_int64 (*memory_highwater)(int); 185 | sqlite3_int64 (*memory_used)(void); 186 | sqlite3_mutex *(*mutex_alloc)(int); 187 | void (*mutex_enter)(sqlite3_mutex*); 188 | void (*mutex_free)(sqlite3_mutex*); 189 | void (*mutex_leave)(sqlite3_mutex*); 190 | int (*mutex_try)(sqlite3_mutex*); 191 | int (*open_v2)(const char*,sqlite3**,int,const char*); 192 | int (*release_memory)(int); 193 | void (*result_error_nomem)(sqlite3_context*); 194 | void (*result_error_toobig)(sqlite3_context*); 195 | int (*sleep)(int); 196 | void (*soft_heap_limit)(int); 197 | sqlite3_vfs *(*vfs_find)(const char*); 198 | int (*vfs_register)(sqlite3_vfs*,int); 199 | int (*vfs_unregister)(sqlite3_vfs*); 200 | int (*xthreadsafe)(void); 201 | void (*result_zeroblob)(sqlite3_context*,int); 202 | void (*result_error_code)(sqlite3_context*,int); 203 | int (*test_control)(int, ...); 204 | void (*randomness)(int,void*); 205 | sqlite3 *(*context_db_handle)(sqlite3_context*); 206 | int (*extended_result_codes)(sqlite3*,int); 207 | int (*limit)(sqlite3*,int,int); 208 | sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*); 209 | const char *(*sql)(sqlite3_stmt*); 210 | int (*status)(int,int*,int*,int); 211 | int (*backup_finish)(sqlite3_backup*); 212 | sqlite3_backup *(*backup_init)(sqlite3*,const char*,sqlite3*,const char*); 213 | int (*backup_pagecount)(sqlite3_backup*); 214 | int (*backup_remaining)(sqlite3_backup*); 215 | int (*backup_step)(sqlite3_backup*,int); 216 | const char *(*compileoption_get)(int); 217 | int (*compileoption_used)(const char*); 218 | int (*create_function_v2)(sqlite3*,const char*,int,int,void*, 219 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 220 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), 221 | void (*xFinal)(sqlite3_context*), 222 | void(*xDestroy)(void*)); 223 | int (*db_config)(sqlite3*,int,...); 224 | sqlite3_mutex *(*db_mutex)(sqlite3*); 225 | int (*db_status)(sqlite3*,int,int*,int*,int); 226 | int (*extended_errcode)(sqlite3*); 227 | void (*log)(int,const char*,...); 228 | sqlite3_int64 (*soft_heap_limit64)(sqlite3_int64); 229 | const char *(*sourceid)(void); 230 | int (*stmt_status)(sqlite3_stmt*,int,int); 231 | int (*strnicmp)(const char*,const char*,int); 232 | int (*unlock_notify)(sqlite3*,void(*)(void**,int),void*); 233 | int (*wal_autocheckpoint)(sqlite3*,int); 234 | int (*wal_checkpoint)(sqlite3*,const char*); 235 | void *(*wal_hook)(sqlite3*,int(*)(void*,sqlite3*,const char*,int),void*); 236 | int (*blob_reopen)(sqlite3_blob*,sqlite3_int64); 237 | int (*vtab_config)(sqlite3*,int op,...); 238 | int (*vtab_on_conflict)(sqlite3*); 239 | /* Version 3.7.16 and later */ 240 | int (*close_v2)(sqlite3*); 241 | const char *(*db_filename)(sqlite3*,const char*); 242 | int (*db_readonly)(sqlite3*,const char*); 243 | int (*db_release_memory)(sqlite3*); 244 | const char *(*errstr)(int); 245 | int (*stmt_busy)(sqlite3_stmt*); 246 | int (*stmt_readonly)(sqlite3_stmt*); 247 | int (*stricmp)(const char*,const char*); 248 | int (*uri_boolean)(const char*,const char*,int); 249 | sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64); 250 | const char *(*uri_parameter)(const char*,const char*); 251 | char *(*vsnprintf)(int,char*,const char*,va_list); 252 | int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*); 253 | }; 254 | 255 | /* 256 | ** The following macros redefine the API routines so that they are 257 | ** redirected throught the global sqlite3_api structure. 258 | ** 259 | ** This header file is also used by the loadext.c source file 260 | ** (part of the main SQLite library - not an extension) so that 261 | ** it can get access to the sqlite3_api_routines structure 262 | ** definition. But the main library does not want to redefine 263 | ** the API. So the redefinition macros are only valid if the 264 | ** SQLITE_CORE macros is undefined. 265 | */ 266 | #ifndef SQLITE_CORE 267 | #define sqlite3_aggregate_context sqlite3_api->aggregate_context 268 | #ifndef SQLITE_OMIT_DEPRECATED 269 | #define sqlite3_aggregate_count sqlite3_api->aggregate_count 270 | #endif 271 | #define sqlite3_bind_blob sqlite3_api->bind_blob 272 | #define sqlite3_bind_double sqlite3_api->bind_double 273 | #define sqlite3_bind_int sqlite3_api->bind_int 274 | #define sqlite3_bind_int64 sqlite3_api->bind_int64 275 | #define sqlite3_bind_null sqlite3_api->bind_null 276 | #define sqlite3_bind_parameter_count sqlite3_api->bind_parameter_count 277 | #define sqlite3_bind_parameter_index sqlite3_api->bind_parameter_index 278 | #define sqlite3_bind_parameter_name sqlite3_api->bind_parameter_name 279 | #define sqlite3_bind_text sqlite3_api->bind_text 280 | #define sqlite3_bind_text16 sqlite3_api->bind_text16 281 | #define sqlite3_bind_value sqlite3_api->bind_value 282 | #define sqlite3_busy_handler sqlite3_api->busy_handler 283 | #define sqlite3_busy_timeout sqlite3_api->busy_timeout 284 | #define sqlite3_changes sqlite3_api->changes 285 | #define sqlite3_close sqlite3_api->close 286 | #define sqlite3_collation_needed sqlite3_api->collation_needed 287 | #define sqlite3_collation_needed16 sqlite3_api->collation_needed16 288 | #define sqlite3_column_blob sqlite3_api->column_blob 289 | #define sqlite3_column_bytes sqlite3_api->column_bytes 290 | #define sqlite3_column_bytes16 sqlite3_api->column_bytes16 291 | #define sqlite3_column_count sqlite3_api->column_count 292 | #define sqlite3_column_database_name sqlite3_api->column_database_name 293 | #define sqlite3_column_database_name16 sqlite3_api->column_database_name16 294 | #define sqlite3_column_decltype sqlite3_api->column_decltype 295 | #define sqlite3_column_decltype16 sqlite3_api->column_decltype16 296 | #define sqlite3_column_double sqlite3_api->column_double 297 | #define sqlite3_column_int sqlite3_api->column_int 298 | #define sqlite3_column_int64 sqlite3_api->column_int64 299 | #define sqlite3_column_name sqlite3_api->column_name 300 | #define sqlite3_column_name16 sqlite3_api->column_name16 301 | #define sqlite3_column_origin_name sqlite3_api->column_origin_name 302 | #define sqlite3_column_origin_name16 sqlite3_api->column_origin_name16 303 | #define sqlite3_column_table_name sqlite3_api->column_table_name 304 | #define sqlite3_column_table_name16 sqlite3_api->column_table_name16 305 | #define sqlite3_column_text sqlite3_api->column_text 306 | #define sqlite3_column_text16 sqlite3_api->column_text16 307 | #define sqlite3_column_type sqlite3_api->column_type 308 | #define sqlite3_column_value sqlite3_api->column_value 309 | #define sqlite3_commit_hook sqlite3_api->commit_hook 310 | #define sqlite3_complete sqlite3_api->complete 311 | #define sqlite3_complete16 sqlite3_api->complete16 312 | #define sqlite3_create_collation sqlite3_api->create_collation 313 | #define sqlite3_create_collation16 sqlite3_api->create_collation16 314 | #define sqlite3_create_function sqlite3_api->create_function 315 | #define sqlite3_create_function16 sqlite3_api->create_function16 316 | #define sqlite3_create_module sqlite3_api->create_module 317 | #define sqlite3_create_module_v2 sqlite3_api->create_module_v2 318 | #define sqlite3_data_count sqlite3_api->data_count 319 | #define sqlite3_db_handle sqlite3_api->db_handle 320 | #define sqlite3_declare_vtab sqlite3_api->declare_vtab 321 | #define sqlite3_enable_shared_cache sqlite3_api->enable_shared_cache 322 | #define sqlite3_errcode sqlite3_api->errcode 323 | #define sqlite3_errmsg sqlite3_api->errmsg 324 | #define sqlite3_errmsg16 sqlite3_api->errmsg16 325 | #define sqlite3_exec sqlite3_api->exec 326 | #ifndef SQLITE_OMIT_DEPRECATED 327 | #define sqlite3_expired sqlite3_api->expired 328 | #endif 329 | #define sqlite3_finalize sqlite3_api->finalize 330 | #define sqlite3_free sqlite3_api->free 331 | #define sqlite3_free_table sqlite3_api->free_table 332 | #define sqlite3_get_autocommit sqlite3_api->get_autocommit 333 | #define sqlite3_get_auxdata sqlite3_api->get_auxdata 334 | #define sqlite3_get_table sqlite3_api->get_table 335 | #ifndef SQLITE_OMIT_DEPRECATED 336 | #define sqlite3_global_recover sqlite3_api->global_recover 337 | #endif 338 | #define sqlite3_interrupt sqlite3_api->interruptx 339 | #define sqlite3_last_insert_rowid sqlite3_api->last_insert_rowid 340 | #define sqlite3_libversion sqlite3_api->libversion 341 | #define sqlite3_libversion_number sqlite3_api->libversion_number 342 | #define sqlite3_malloc sqlite3_api->malloc 343 | #define sqlite3_mprintf sqlite3_api->mprintf 344 | #define sqlite3_open sqlite3_api->open 345 | #define sqlite3_open16 sqlite3_api->open16 346 | #define sqlite3_prepare sqlite3_api->prepare 347 | #define sqlite3_prepare16 sqlite3_api->prepare16 348 | #define sqlite3_prepare_v2 sqlite3_api->prepare_v2 349 | #define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 350 | #define sqlite3_profile sqlite3_api->profile 351 | #define sqlite3_progress_handler sqlite3_api->progress_handler 352 | #define sqlite3_realloc sqlite3_api->realloc 353 | #define sqlite3_reset sqlite3_api->reset 354 | #define sqlite3_result_blob sqlite3_api->result_blob 355 | #define sqlite3_result_double sqlite3_api->result_double 356 | #define sqlite3_result_error sqlite3_api->result_error 357 | #define sqlite3_result_error16 sqlite3_api->result_error16 358 | #define sqlite3_result_int sqlite3_api->result_int 359 | #define sqlite3_result_int64 sqlite3_api->result_int64 360 | #define sqlite3_result_null sqlite3_api->result_null 361 | #define sqlite3_result_text sqlite3_api->result_text 362 | #define sqlite3_result_text16 sqlite3_api->result_text16 363 | #define sqlite3_result_text16be sqlite3_api->result_text16be 364 | #define sqlite3_result_text16le sqlite3_api->result_text16le 365 | #define sqlite3_result_value sqlite3_api->result_value 366 | #define sqlite3_rollback_hook sqlite3_api->rollback_hook 367 | #define sqlite3_set_authorizer sqlite3_api->set_authorizer 368 | #define sqlite3_set_auxdata sqlite3_api->set_auxdata 369 | #define sqlite3_snprintf sqlite3_api->snprintf 370 | #define sqlite3_step sqlite3_api->step 371 | #define sqlite3_table_column_metadata sqlite3_api->table_column_metadata 372 | #define sqlite3_thread_cleanup sqlite3_api->thread_cleanup 373 | #define sqlite3_total_changes sqlite3_api->total_changes 374 | #define sqlite3_trace sqlite3_api->trace 375 | #ifndef SQLITE_OMIT_DEPRECATED 376 | #define sqlite3_transfer_bindings sqlite3_api->transfer_bindings 377 | #endif 378 | #define sqlite3_update_hook sqlite3_api->update_hook 379 | #define sqlite3_user_data sqlite3_api->user_data 380 | #define sqlite3_value_blob sqlite3_api->value_blob 381 | #define sqlite3_value_bytes sqlite3_api->value_bytes 382 | #define sqlite3_value_bytes16 sqlite3_api->value_bytes16 383 | #define sqlite3_value_double sqlite3_api->value_double 384 | #define sqlite3_value_int sqlite3_api->value_int 385 | #define sqlite3_value_int64 sqlite3_api->value_int64 386 | #define sqlite3_value_numeric_type sqlite3_api->value_numeric_type 387 | #define sqlite3_value_text sqlite3_api->value_text 388 | #define sqlite3_value_text16 sqlite3_api->value_text16 389 | #define sqlite3_value_text16be sqlite3_api->value_text16be 390 | #define sqlite3_value_text16le sqlite3_api->value_text16le 391 | #define sqlite3_value_type sqlite3_api->value_type 392 | #define sqlite3_vmprintf sqlite3_api->vmprintf 393 | #define sqlite3_overload_function sqlite3_api->overload_function 394 | #define sqlite3_prepare_v2 sqlite3_api->prepare_v2 395 | #define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 396 | #define sqlite3_clear_bindings sqlite3_api->clear_bindings 397 | #define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob 398 | #define sqlite3_blob_bytes sqlite3_api->blob_bytes 399 | #define sqlite3_blob_close sqlite3_api->blob_close 400 | #define sqlite3_blob_open sqlite3_api->blob_open 401 | #define sqlite3_blob_read sqlite3_api->blob_read 402 | #define sqlite3_blob_write sqlite3_api->blob_write 403 | #define sqlite3_create_collation_v2 sqlite3_api->create_collation_v2 404 | #define sqlite3_file_control sqlite3_api->file_control 405 | #define sqlite3_memory_highwater sqlite3_api->memory_highwater 406 | #define sqlite3_memory_used sqlite3_api->memory_used 407 | #define sqlite3_mutex_alloc sqlite3_api->mutex_alloc 408 | #define sqlite3_mutex_enter sqlite3_api->mutex_enter 409 | #define sqlite3_mutex_free sqlite3_api->mutex_free 410 | #define sqlite3_mutex_leave sqlite3_api->mutex_leave 411 | #define sqlite3_mutex_try sqlite3_api->mutex_try 412 | #define sqlite3_open_v2 sqlite3_api->open_v2 413 | #define sqlite3_release_memory sqlite3_api->release_memory 414 | #define sqlite3_result_error_nomem sqlite3_api->result_error_nomem 415 | #define sqlite3_result_error_toobig sqlite3_api->result_error_toobig 416 | #define sqlite3_sleep sqlite3_api->sleep 417 | #define sqlite3_soft_heap_limit sqlite3_api->soft_heap_limit 418 | #define sqlite3_vfs_find sqlite3_api->vfs_find 419 | #define sqlite3_vfs_register sqlite3_api->vfs_register 420 | #define sqlite3_vfs_unregister sqlite3_api->vfs_unregister 421 | #define sqlite3_threadsafe sqlite3_api->xthreadsafe 422 | #define sqlite3_result_zeroblob sqlite3_api->result_zeroblob 423 | #define sqlite3_result_error_code sqlite3_api->result_error_code 424 | #define sqlite3_test_control sqlite3_api->test_control 425 | #define sqlite3_randomness sqlite3_api->randomness 426 | #define sqlite3_context_db_handle sqlite3_api->context_db_handle 427 | #define sqlite3_extended_result_codes sqlite3_api->extended_result_codes 428 | #define sqlite3_limit sqlite3_api->limit 429 | #define sqlite3_next_stmt sqlite3_api->next_stmt 430 | #define sqlite3_sql sqlite3_api->sql 431 | #define sqlite3_status sqlite3_api->status 432 | #define sqlite3_backup_finish sqlite3_api->backup_finish 433 | #define sqlite3_backup_init sqlite3_api->backup_init 434 | #define sqlite3_backup_pagecount sqlite3_api->backup_pagecount 435 | #define sqlite3_backup_remaining sqlite3_api->backup_remaining 436 | #define sqlite3_backup_step sqlite3_api->backup_step 437 | #define sqlite3_compileoption_get sqlite3_api->compileoption_get 438 | #define sqlite3_compileoption_used sqlite3_api->compileoption_used 439 | #define sqlite3_create_function_v2 sqlite3_api->create_function_v2 440 | #define sqlite3_db_config sqlite3_api->db_config 441 | #define sqlite3_db_mutex sqlite3_api->db_mutex 442 | #define sqlite3_db_status sqlite3_api->db_status 443 | #define sqlite3_extended_errcode sqlite3_api->extended_errcode 444 | #define sqlite3_log sqlite3_api->log 445 | #define sqlite3_soft_heap_limit64 sqlite3_api->soft_heap_limit64 446 | #define sqlite3_sourceid sqlite3_api->sourceid 447 | #define sqlite3_stmt_status sqlite3_api->stmt_status 448 | #define sqlite3_strnicmp sqlite3_api->strnicmp 449 | #define sqlite3_unlock_notify sqlite3_api->unlock_notify 450 | #define sqlite3_wal_autocheckpoint sqlite3_api->wal_autocheckpoint 451 | #define sqlite3_wal_checkpoint sqlite3_api->wal_checkpoint 452 | #define sqlite3_wal_hook sqlite3_api->wal_hook 453 | #define sqlite3_blob_reopen sqlite3_api->blob_reopen 454 | #define sqlite3_vtab_config sqlite3_api->vtab_config 455 | #define sqlite3_vtab_on_conflict sqlite3_api->vtab_on_conflict 456 | /* Version 3.7.16 and later */ 457 | #define sqlite3_close_v2 sqlite3_api->close_v2 458 | #define sqlite3_db_filename sqlite3_api->db_filename 459 | #define sqlite3_db_readonly sqlite3_api->db_readonly 460 | #define sqlite3_db_release_memory sqlite3_api->db_release_memory 461 | #define sqlite3_errstr sqlite3_api->errstr 462 | #define sqlite3_stmt_busy sqlite3_api->stmt_busy 463 | #define sqlite3_stmt_readonly sqlite3_api->stmt_readonly 464 | #define sqlite3_stricmp sqlite3_api->stricmp 465 | #define sqlite3_uri_boolean sqlite3_api->uri_boolean 466 | #define sqlite3_uri_int64 sqlite3_api->uri_int64 467 | #define sqlite3_uri_parameter sqlite3_api->uri_parameter 468 | #define sqlite3_uri_vsnprintf sqlite3_api->vsnprintf 469 | #define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2 470 | #endif /* SQLITE_CORE */ 471 | 472 | #ifndef SQLITE_CORE 473 | /* This case when the file really is being compiled as a loadable 474 | ** extension */ 475 | # define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0; 476 | # define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v; 477 | # define SQLITE_EXTENSION_INIT3 \ 478 | extern const sqlite3_api_routines *sqlite3_api; 479 | #else 480 | /* This case when the file is being statically linked into the 481 | ** application */ 482 | # define SQLITE_EXTENSION_INIT1 /*no-op*/ 483 | # define SQLITE_EXTENSION_INIT2(v) (void)v; /* unused parameter */ 484 | # define SQLITE_EXTENSION_INIT3 /*no-op*/ 485 | #endif 486 | 487 | #endif /* _SQLITE3EXT_H_ */ 488 | -------------------------------------------------------------------------------- /EasyServer/EasyServer/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/stdafx.cpp -------------------------------------------------------------------------------- /EasyServer/EasyServer/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/stdafx.h -------------------------------------------------------------------------------- /EasyServer/EasyServer/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeliard/EasyGameServer/786bffebb305eecc25b77379e682060f9ca01115/EasyServer/EasyServer/targetver.h -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 zeliard 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /PacketType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define MAX_CHAT_LEN 256 4 | 5 | #define MAX_NAME_LEN 30 6 | #define MAX_COMMENT_LEN 40 7 | 8 | enum PacketTypes 9 | { 10 | PKT_NONE = 0, 11 | 12 | PKT_CS_LOGIN = 1, 13 | PKT_SC_LOGIN = 2, 14 | 15 | PKT_CS_CHAT = 11, 16 | PKT_SC_CHAT = 12, 17 | 18 | PKT_CS_MOVE = 21, 19 | PKT_SC_MOVE = 22, 20 | 21 | PKT_MAX = 1024 22 | } ; 23 | 24 | #pragma pack(push, 1) 25 | 26 | struct PacketHeader 27 | { 28 | PacketHeader() : mSize(0), mType(PKT_NONE) {} 29 | short mSize ; 30 | short mType ; 31 | } ; 32 | 33 | 34 | 35 | struct LoginRequest : public PacketHeader 36 | { 37 | LoginRequest() 38 | { 39 | mSize = sizeof(LoginRequest) ; 40 | mType = PKT_CS_LOGIN ; 41 | mPlayerId = -1 ; 42 | } 43 | 44 | int mPlayerId ; 45 | } ; 46 | 47 | struct LoginResult : public PacketHeader 48 | { 49 | LoginResult() 50 | { 51 | mSize = sizeof(LoginResult) ; 52 | mType = PKT_SC_LOGIN ; 53 | mPlayerId = -1 ; 54 | memset(mName, 0, MAX_NAME_LEN) ; 55 | } 56 | 57 | int mPlayerId ; 58 | float mPosX ; 59 | float mPosY ; 60 | char mName[MAX_NAME_LEN] ; 61 | 62 | } ; 63 | 64 | struct ChatBroadcastRequest : public PacketHeader 65 | { 66 | ChatBroadcastRequest() 67 | { 68 | mSize = sizeof(ChatBroadcastRequest) ; 69 | mType = PKT_CS_CHAT ; 70 | mPlayerId = -1 ; 71 | 72 | memset(mChat, 0, MAX_CHAT_LEN) ; 73 | } 74 | 75 | int mPlayerId ; 76 | char mChat[MAX_CHAT_LEN] ; 77 | } ; 78 | 79 | struct ChatBroadcastResult : public PacketHeader 80 | { 81 | ChatBroadcastResult() 82 | { 83 | mSize = sizeof(ChatBroadcastResult) ; 84 | mType = PKT_SC_CHAT ; 85 | mPlayerId = -1 ; 86 | 87 | memset(mName, 0, MAX_NAME_LEN) ; 88 | memset(mChat, 0, MAX_CHAT_LEN) ; 89 | } 90 | 91 | int mPlayerId ; 92 | char mName[MAX_NAME_LEN] ; 93 | char mChat[MAX_CHAT_LEN] ; 94 | } ; 95 | 96 | 97 | struct MoveRequest : public PacketHeader 98 | { 99 | MoveRequest() 100 | { 101 | mSize = sizeof(MoveRequest); 102 | mType = PKT_CS_MOVE; 103 | mPlayerId = -1; 104 | mPosX = 0; 105 | mPosY = 0; 106 | } 107 | 108 | int mPlayerId; 109 | float mPosX; 110 | float mPosY; 111 | }; 112 | 113 | struct MoveBroadcastResult : public PacketHeader 114 | { 115 | MoveBroadcastResult() 116 | { 117 | mSize = sizeof(MoveBroadcastResult); 118 | mType = PKT_SC_MOVE; 119 | mPlayerId = -1; 120 | mPosX = 0; 121 | mPosY = 0; 122 | } 123 | 124 | int mPlayerId; 125 | float mPosX; 126 | float mPosY; 127 | }; 128 | 129 | 130 | 131 | #pragma pack(pop) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | EasyGameServer (for cocos2dx) 2 | ============== 3 | This is a game server (base framework) which supports real-time/stateful games using TCP 4 | 5 | ## Branches 6 | 7 | * [Linux Version](https://github.com/zeliard/EasyGameServer/tree/linux) 8 | * [Windows Version](https://github.com/zeliard/EasyGameServer/tree/windows) 9 | * Same with the master branch 10 | --------------------------------------------------------------------------------