├── .gitignore ├── CppExperience ├── .gitignore ├── CppExperience.sln ├── CppExperience.vcxproj ├── STL迭代器失效.cpp ├── main.cpp ├── 智能指针.cpp └── 消息队列和共享内存.cpp ├── README.md └── linuxserverplatform ├── CenterServer ├── CenterServer.vcxproj └── CenterServer.vcxproj.user ├── Common ├── Common.vcxproj ├── Common.vcxproj.filters └── Common.vcxproj.user ├── Documentation ├── c++ │ ├── c++11有用新特性.txt │ ├── c++多态内存布局.docx │ ├── memcpy和memmove │ │ ├── Makefile │ │ └── main.cpp │ └── 程序优化.txt ├── lua │ ├── Lua_API_CH.chm │ └── lua原理图.gif ├── 常用命令 │ ├── git命令.txt │ ├── linux命令.txt │ ├── mysql命令.txt │ └── redis命令.txt ├── 服务器部署 │ ├── 启动程序必读.txt │ ├── 安装lua开发环境.docx │ └── 搭建linux c++开发环境.docx ├── 算法 │ └── 腾讯面试算法2020-6-9 │ │ ├── Makefile │ │ └── main.cpp ├── 计划.txt └── 计算机网络 │ ├── 网络编程.txt │ └── 计算机网络.doc ├── GameManage ├── GameManage.vcxproj └── GameManage.vcxproj.user ├── HttpServer ├── HttpServer.vcxproj └── HttpServer.vcxproj.user ├── Kernel ├── Kernel.vcxproj ├── Kernel.vcxproj.filters └── Kernel.vcxproj.user ├── LinuxRun ├── Database │ ├── database-haowan │ │ ├── php服务器sql脚本 │ │ │ ├── web_创建表.sql │ │ │ ├── web_清理数据.sql │ │ │ └── web_默认配置.sql │ │ └── 游戏服sql脚本 │ │ │ ├── NewHM(不包含php).sql │ │ │ ├── 清理数据库.sql │ │ │ └── 生成机器人.sql │ ├── database_haotain │ │ ├── php服务器sql脚本 │ │ │ ├── web_创建表.sql │ │ │ ├── web_清理数据.sql │ │ │ └── web_默认配置.sql │ │ └── 游戏服sql脚本 │ │ │ ├── NewHM(不包含php).sql │ │ │ ├── 清理数据库.sql │ │ │ └── 生成机器人.sql │ ├── lua数据库 │ │ ├── db_dblmgame.sql │ │ └── db_dblmutils.sql │ └── 新增的sql语句 │ │ ├── logonbaseinfo.sql │ │ └── workbaseinfo.sql ├── RedisGame │ ├── redis.conf │ └── start-server.sh ├── RedisPHP │ ├── redis.conf │ └── start-server.sh ├── libs │ └── install_libs.sh └── shell │ ├── coredumpshell.sh │ └── deletejson.sh ├── LoaderServer ├── LoaderServer.vcxproj └── LoaderServer.vcxproj.user ├── LogonServer ├── LogonServer.vcxproj └── LogonServer.vcxproj.user ├── README.md ├── WorkServer ├── WorkServer.vcxproj └── WorkServer.vcxproj.user ├── games ├── 12101105_ZJH │ ├── .gitignore │ ├── 12101105_ZJH.vcxproj │ └── 12101105_ZJH.vcxproj.user ├── 23510004_SXTDH │ └── 23510004_SXTDH.vcxproj ├── 30100008_NN │ ├── .gitignore │ ├── 30100008_NN.vcxproj │ └── 30100008_NN.vcxproj.user ├── 36610103_DDZ │ └── 36610103_DDZ.vcxproj ├── 37460003_PHZ │ └── 37460003_PHZ.vcxproj ├── 40000100_LHD │ └── 40000100_LHD.vcxproj └── 50000001_BOOS │ └── 50000001_BOOS.vcxproj ├── linuxserverplatform.sln ├── src ├── CenterServer │ ├── BaseCenterServer.cpp │ ├── BaseCenterServer.h │ ├── CenterServerManage.cpp │ ├── CenterServerManage.h │ ├── CenterServerModule.cpp │ ├── CenterServerModule.h │ ├── Makefile │ └── main.cpp ├── Common │ ├── BillManage.cpp │ ├── HttpServer.cpp │ ├── MD5.cpp │ ├── Makefile │ ├── MyCurl.cpp │ ├── RedisBase.cpp │ ├── RedisCenter.cpp │ ├── RedisCommon.cpp │ ├── RedisLoader.cpp │ ├── RedisLogon.cpp │ ├── RedisPHP.cpp │ └── Util.cpp ├── GameManage │ ├── BaseMainManage.cpp │ ├── GameDataBaseHandle.cpp │ ├── GameDesk.cpp │ ├── GameMainManage.cpp │ ├── Makefile │ └── gameUserManage.cpp ├── Kernel │ ├── CXObj.cpp │ ├── DataBase.cpp │ ├── DataLine.cpp │ ├── Exception.cpp │ ├── Function.cpp │ ├── GServerConnect.cpp │ ├── GameLogManage.cpp │ ├── INIFile.cpp │ ├── Lock.cpp │ ├── Makefile │ ├── MysqlHelper.cpp │ ├── RRlockQueue.cpp │ ├── ServerTimer.cpp │ ├── TCPSocket.cpp │ ├── TcpConnect.cpp │ ├── UnlockQueue.cpp │ ├── WebSocket.cpp │ ├── Xor.cpp │ ├── base64.cpp │ ├── configManage.cpp │ ├── log.cpp │ ├── sha1.cpp │ └── shmem.cpp ├── LoaderServer │ ├── LoaderServerModule.cpp │ ├── LoaderServerModule.h │ ├── Makefile │ └── main.cpp ├── LogonServer │ ├── BaseLogonServer.cpp │ ├── BaseLogonServer.h │ ├── GameLogonDataBase.cpp │ ├── GameLogonDataBase.h │ ├── GameLogonManage.cpp │ ├── GameLogonManage.h │ ├── GameLogonModule.cpp │ ├── GameLogonModule.h │ ├── LogonGServerManage.cpp │ ├── LogonGServerManage.h │ ├── LogonUserManage.cpp │ ├── LogonUserManage.h │ ├── Makefile │ └── main.cpp ├── Makefile ├── WorkServer │ ├── BaseWorkServer.cpp │ ├── BaseWorkServer.h │ ├── GameWorkDataBase.cpp │ ├── GameWorkDataBase.h │ ├── GameWorkManage.cpp │ ├── GameWorkManage.h │ ├── GameWorkModule.cpp │ ├── GameWorkModule.h │ ├── Makefile │ └── main.cpp ├── bin │ ├── config.ini │ ├── dirtywords.txt │ ├── install_myself_lib.sh │ ├── restart.sh │ ├── robotPosition.txt │ ├── startcserver.sh │ ├── startgserver.sh │ ├── startlserver.sh │ ├── startwserver.sh │ ├── stopall.sh │ ├── stopcserver.sh │ ├── stopgserver.sh │ └── stoplserver.sh ├── games │ ├── 12101105_ZJH │ │ ├── 12101105_s.ini │ │ ├── Makefile │ │ ├── ServerManage.cpp │ │ ├── ServerManage.h │ │ ├── UpGradeDLL.cpp │ │ ├── UpGradeLogic.cpp │ │ ├── UpGradeLogic.h │ │ └── UpgradeMessage.h │ ├── 23510004_SXTDH │ │ ├── 23510004_s.ini │ │ ├── CLogicBase.h │ │ ├── CheckCPGAction.cpp │ │ ├── CheckCPGAction.h │ │ ├── CheckCPGActionEx.cpp │ │ ├── CheckCPGActionEx.h │ │ ├── CheckHuPai.cpp │ │ ├── CheckHuPai.h │ │ ├── CheckHuPaiEx.cpp │ │ ├── CheckHuPaiEx.h │ │ ├── GameData.cpp │ │ ├── GameData.h │ │ ├── GameDataEx.cpp │ │ ├── GameDataEx.h │ │ ├── Makefile │ │ ├── Mj_Message.h │ │ ├── SHSrvDLL.cpp │ │ ├── ServerManage.cpp │ │ ├── ServerManage.h │ │ ├── mj.h │ │ └── upgrademessage.h │ ├── 30100008_NN │ │ ├── 30100008_s.ini │ │ ├── Makefile │ │ ├── ServerManage.cpp │ │ ├── ServerManage.h │ │ ├── UpGradeDLL.cpp │ │ ├── UpGradeLogic.cpp │ │ ├── UpGradeLogic.h │ │ └── UpgradeMessage.h │ ├── 36610103_DDZ │ │ ├── 36610103_s.ini │ │ ├── GameTaskLogic.cpp │ │ ├── GameTaskLogic.h │ │ ├── Makefile │ │ ├── ServerManage.cpp │ │ ├── ServerManage.h │ │ ├── UpGradeDLL.cpp │ │ ├── UpGradeLogic.cpp │ │ ├── UpGradeLogic.h │ │ └── UpgradeMessage.h │ ├── 37460003_PHZ │ │ ├── 37460003_s.ini │ │ ├── GameData.cpp │ │ ├── GameData.h │ │ ├── Makefile │ │ ├── Playback.cpp │ │ ├── Playback.h │ │ ├── ServerManage.cpp │ │ ├── ServerManage.h │ │ ├── UpGradeDLL.cpp │ │ ├── UpGradeLogic.cpp │ │ ├── UpGradeLogic.h │ │ └── UpgradeMessage.h │ ├── 40000100_LHD │ │ ├── 40000100_s.ini │ │ ├── GameDefine.h │ │ ├── GameServer.cpp │ │ ├── Makefile │ │ ├── NewServerManage.cpp │ │ ├── NewServerManage.h │ │ ├── UpGradeLogic.cpp │ │ ├── UpGradeLogic.h │ │ └── UpgradeMessage.h │ ├── 50000001_BOOS │ │ ├── 50000001_s.ini │ │ ├── CMD_Game.h │ │ ├── ControlHead.h │ │ ├── Dexter.h │ │ ├── FishLKPath.pat │ │ ├── GameLogic.cpp │ │ ├── GameLogic.h │ │ ├── GameServer.cpp │ │ ├── Makefile │ │ ├── PolygonShape.cpp │ │ ├── PolygonShape.h │ │ ├── TableFrameSink.cpp │ │ └── TableFrameSink.h │ └── Makefile ├── httpserver │ ├── CMakeLists.txt │ ├── Makefile │ ├── README.md │ ├── common │ │ └── logging.h │ └── src │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ ├── daemonize.h │ │ ├── handlers.cpp │ │ ├── handlers.h │ │ ├── main.cpp │ │ ├── server.cpp │ │ ├── server.h │ │ ├── worker.cpp │ │ └── worker.h ├── include │ ├── DataBase │ │ ├── binary_log_types.h │ │ ├── my_alloc.h │ │ ├── my_command.h │ │ ├── my_list.h │ │ ├── mysql.h │ │ ├── mysql │ │ │ ├── client_plugin.h │ │ │ └── psi │ │ │ │ └── psi_memory.h │ │ ├── mysql_com.h │ │ ├── mysql_time.h │ │ ├── mysql_version.h │ │ ├── plugin_auth_common.h │ │ ├── psi_base.h │ │ └── typelib.h │ ├── ServerCommon │ │ ├── AsyncEventMsg.h │ │ ├── BaseMainManage.h │ │ ├── BillManage.h │ │ ├── CXObj.h │ │ ├── CommonHead.h │ │ ├── DataBase.h │ │ ├── DataLine.h │ │ ├── Define.h │ │ ├── ErrorCode.h │ │ ├── Exception.h │ │ ├── Function.h │ │ ├── GServerConnect.h │ │ ├── GameDataBaseHandle.h │ │ ├── GameDesk.h │ │ ├── GameLogManage.h │ │ ├── GameMainManage.h │ │ ├── HttpServer.h │ │ ├── INIFile.h │ │ ├── Interface.h │ │ ├── InternalMessageDefine.h │ │ ├── KernelDefine.h │ │ ├── Lock.h │ │ ├── LuaModuleInit.h │ │ ├── MD5.h │ │ ├── MyCurl.h │ │ ├── MysqlHelper.h │ │ ├── NewMessageDefine.h │ │ ├── PlatformMessage.h │ │ ├── RRlockQueue.h │ │ ├── RedisBase.h │ │ ├── RedisCenter.h │ │ ├── RedisCommon.h │ │ ├── RedisLoader.h │ │ ├── RedisLogon.h │ │ ├── RedisPHP.h │ │ ├── ServerTimer.h │ │ ├── TCPSocket.h │ │ ├── TcpConnect.h │ │ ├── UnlockQueue.h │ │ ├── Util.h │ │ ├── WebSocket.h │ │ ├── Xor.h │ │ ├── base64.h │ │ ├── basemessage.h │ │ ├── comstruct.h │ │ ├── configManage.h │ │ ├── gameUserManage.h │ │ ├── log.h │ │ ├── sha1.h │ │ ├── shm_obj_pool.h │ │ ├── shm_stl.h │ │ ├── shmem.h │ │ └── tableDefine.h │ ├── curl │ │ ├── curl.h │ │ ├── curlver.h │ │ ├── easy.h │ │ ├── mprintf.h │ │ ├── multi.h │ │ ├── stdcheaders.h │ │ ├── system.h │ │ ├── typecheck-gcc.h │ │ └── urlapi.h │ ├── hiredis │ │ ├── adapters │ │ │ ├── ae.h │ │ │ ├── glib.h │ │ │ ├── ivykis.h │ │ │ ├── libev.h │ │ │ ├── libevent.h │ │ │ ├── libuv.h │ │ │ ├── macosx.h │ │ │ └── qt.h │ │ ├── alloc.h │ │ ├── async.h │ │ ├── hiredis.h │ │ ├── read.h │ │ └── sds.h │ ├── json │ │ ├── autolink.h │ │ ├── config.h │ │ ├── features.h │ │ ├── forwards.h │ │ ├── json.h │ │ ├── reader.h │ │ ├── value.h │ │ └── writer.h │ └── libevent │ │ ├── evdns.h │ │ ├── event.h │ │ ├── event2 │ │ ├── buffer.h │ │ ├── buffer_compat.h │ │ ├── bufferevent.h │ │ ├── bufferevent_compat.h │ │ ├── bufferevent_ssl.h │ │ ├── bufferevent_struct.h │ │ ├── dns.h │ │ ├── dns_compat.h │ │ ├── dns_struct.h │ │ ├── event-config.h │ │ ├── event.h │ │ ├── event_compat.h │ │ ├── event_struct.h │ │ ├── http.h │ │ ├── http_compat.h │ │ ├── http_struct.h │ │ ├── keyvalq_struct.h │ │ ├── listener.h │ │ ├── rpc.h │ │ ├── rpc_compat.h │ │ ├── rpc_struct.h │ │ ├── tag.h │ │ ├── tag_compat.h │ │ ├── thread.h │ │ ├── util.h │ │ ├── visibility.h │ │ └── watch.h │ │ ├── evhttp.h │ │ ├── evrpc.h │ │ └── evutil.h ├── jemalloc │ └── jemalloc_cpp.cpp ├── lua │ ├── WorkServer │ │ └── luacode.zip │ ├── auxiliar.c │ ├── auxiliar.h │ ├── buffer.c │ ├── buffer.h │ ├── except.c │ ├── except.h │ ├── inet.c │ ├── inet.h │ ├── io.c │ ├── io.h │ ├── ls_mysql.c │ ├── luasocket.c │ ├── luasocket.h │ ├── luasql.c │ ├── luasql.h │ ├── mime.c │ ├── mime.h │ ├── options.c │ ├── options.h │ ├── pb.c │ ├── select.c │ ├── select.h │ ├── socket.h │ ├── tcp.c │ ├── tcp.h │ ├── timeout.c │ ├── timeout.h │ ├── udp.c │ ├── udp.h │ ├── unix.c │ ├── unix.h │ ├── usocket.c │ └── usocket.h ├── protobuf │ ├── AsyncEventMsg.pb.cc │ ├── AsyncEventMsg.pb.h │ ├── AsyncEventMsg.proto │ ├── test.pb.cc │ ├── test.pb.h │ └── test.proto └── test │ ├── Makefile │ ├── Shm.cpp │ ├── TestUnLockQueue.cpp │ └── main.cpp └── test ├── test.vcxproj └── test.vcxproj.user /CppExperience/.gitignore: -------------------------------------------------------------------------------- 1 | /obj 2 | /bin 3 | /.vs 4 | -------------------------------------------------------------------------------- /CppExperience/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | extern void IntelligentPointer(); 19 | extern void Iterator(); 20 | extern int TestLinuxList(); 21 | extern void TestLinuxShm(); 22 | 23 | class A 24 | { 25 | public: 26 | A(); 27 | ~A(); 28 | int sadfsdf; 29 | 30 | virtual int fun() { return 1; } 31 | private: 32 | 33 | }; 34 | 35 | A::A() 36 | { 37 | } 38 | 39 | A::~A() 40 | { 41 | } 42 | 43 | class B :public A 44 | { 45 | public: 46 | B(); 47 | ~B(); 48 | int sfdfdggedr; 49 | 50 | virtual int fun() override { return 3; } 51 | 52 | private: 53 | 54 | }; 55 | 56 | B::B() 57 | { 58 | } 59 | 60 | B::~B() 61 | { 62 | } 63 | 64 | void funsw() 65 | { 66 | int* p = new int[100]; 67 | } 68 | 69 | void macc_fun() 70 | { 71 | int* p = (int*)malloc(1469); 72 | } 73 | 74 | int main() 75 | { 76 | IntelligentPointer(); 77 | funsw(); 78 | macc_fun(); 79 | sleep(2); 80 | 81 | //printf("测试utf-8\n"); 82 | 83 | //TestLinuxList(); 84 | //TestLinuxShm(); 85 | 86 | //IntelligentPointer(); 87 | //Iterator(); 88 | 89 | 90 | printf("-----------程序结束------------\n"); 91 | 92 | return 0; 93 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 开发环境 2 | 本框架开发环境可以是windows,编辑、调试、编译都可以在windows下进行,大大提高开发效率。windows需要安装以下软件: 3 | 1、VS2019 4 | 2、vmware + centos7 5 | 3、xshell 6 | 7 | # 编译环境 8 | 1、windows下编译:g++/gcc + vmware + centos7 + ssh + 各种第三方库 + vs2019 + win10 9 | 10 | 2、linux下编译(根据文档安装第三方库):cd src && make && make install 11 | 12 | 13 | # 技术 14 | c++棋牌游戏服务器框架。支持TCP、websocket、http协议、支持分布式、mysql、redis、lua 15 | 16 | -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/c++/c++11有用新特性.txt: -------------------------------------------------------------------------------- 1 | 1、类型与变量相关 2 | 1.1、 auto 3 | for (auto i: V) {} 4 | 1.2、 字符串和数字转换 5 | to_string stoi、stol、stoul、stoll、stoull、stof、stod、stold 6 | 1.3、 生成随机数 7 | std::random_device rd; 8 | int randint = rd(); 9 | 1.4、 原子变量 10 | std::atomic 11 | 12 | 2、容器 13 | 2.1、tuple元组 和 花括号初始化 14 | using result = std::tuple; 15 | result res {1,'a',1.0}; 16 | return res; 17 | 2.2、hash正式进入stl 18 | unordered_map、unordered_set、unordered_multimap、unordered_multiset 19 | 2.3、emplace 少调用一次拷贝构造函数 20 | std::map myMap; 21 | myMap[1] = 5; myMap.emplace(6666, 9999999); 22 | 2.4、shrink_to_fit() 23 | std::vector v{ 1, 2, 3, 4, 5 }; 24 | v.push_back(1); 25 | std::cout << "before shrink_to_fit: " << v.capacity() << std::endl; 26 | v.shrink_to_fit(); 27 | std::cout << "after shrink_to_fit: " << v.capacity() << std::endl; 28 | 29 | 3、类 30 | std::move()配合右值引用使用,下面这个例子可以完全减少内存拷贝,内存移动 31 | std::unordered_map > ltmap; 32 | std::vector aVec = { a,a,a }; 33 | ltmap.insert(std::make_pair(0, aVec)); 34 | ltmap.emplace(1, std::move(aVec)); 35 | 继承:子类的虚函数多态实现要加override显式的表明,否则会让人误认为是子类自己的虚函数; 36 | 不让子类多态实现的虚函数也要记得加入final; 37 | 38 | 4、函数式编程 39 | 4.1、函数指针 40 | void readcb(std::function fun, void* param) 41 | 42 | 5、动态指针 43 | CppExperience 项目中有更多关于智能指针的示例 44 | 关于智能指针有更详细的解释:https://blog.csdn.net/zy19940906/article/details/50470087 45 | 46 | 6、多线程与互斥同步(互斥锁,条件变量) 47 | std::mutex mtx; // 全局互斥锁. 48 | std::condition_variable cv; // 全局条件变量. 49 | bool ready = false; // 全局标志位. 50 | void do_print_id(int id) 51 | { 52 | std::unique_lock lck(mtx); 53 | while (!ready) // 如果标志位不为 true, 则等待... 54 | cv.wait(lck); // 当前线程被阻塞, 当全局标志位变为 true 之后, 55 | } 56 | int main() 57 | { 58 | std::thread threads[10]; 59 | for (int i = 0; i < 10; ++i) 60 | threads[i] = std::thread(do_print_id, i); 61 | 62 | for (auto& th : threads) 63 | th.join(); 64 | 65 | return 0; 66 | } -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/c++/c++多态内存布局.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luotan-123/libevent-server/98652b1b5150402ae771ca0393b2ca7fadb11b8d/linuxserverplatform/Documentation/c++/c++多态内存布局.docx -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/c++/memcpy和memmove/Makefile: -------------------------------------------------------------------------------- 1 | CPP = g++ 2 | CFLAGS = -g -Wall -O -std=c++11 3 | 4 | main:main.o 5 | $(CPP) main.o -o main 6 | main.o:main.cpp 7 | $(CPP) $(CFLAGS) -c main.cpp 8 | clean: 9 | rm -f main.o main 10 | -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/c++/memcpy和memmove/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // 注意在vc上面,memcpy和memmove没有任何区别 5 | // 只有在linux g++上才有区别 6 | void mymemcpy(void* dst, void* src, int len) 7 | { 8 | char* pdst = (char*)dst; 9 | const char* psrc = (const char*)src; 10 | for (int i = 0; i < len; i++) 11 | { 12 | pdst[i] = psrc[i]; 13 | } 14 | } 15 | 16 | int main() 17 | { 18 | char buf1[64] = "0123456789"; 19 | char buf2[64] = "0123456789"; 20 | char buf3[64] = "0123456789"; 21 | 22 | //memcpy(buf1 + 3, buf1, 6); 23 | //memmove(buf2 + 3, buf2, 6); 24 | //mymemcpy(buf3 + 3, buf3, 6); 25 | 26 | memcpy(buf1 + 3, buf1 + 1, 7); 27 | memmove(buf2 + 3, buf2 + 1, 7); 28 | mymemcpy(buf3 + 3, buf3 + 1, 7); 29 | 30 | printf("buf1(memcpy)=%s\nbuf2(mmmove)=%s\nbuf3(mymcpy)=%s\n", buf1, buf2, buf3); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/c++/程序优化.txt: -------------------------------------------------------------------------------- 1 | 长期优化 2 | 1、原系统long类型改成int ,unsigned long 改成 unsigned int 3 | 2、检查printf和sprintf函数,int->%d, long->%ld, long long->%lld, unsigned int->%u, unsigned long ->%lu, unsigned long long -> %llu 4 | 3、内存优化:自己分配内存、内存越界检查、内存泄露检查、解决内存碎片。目前比较好的内存分配器:ptmalloc、tcmalloc、jemalloc 5 | 4、cpu优化:一少、一多策略。少指的是执行cpu时间少(算法时间复杂度,代码优化),多指的是多利用cpu执行,并发或者并行执行(并发执行) 6 | 5、优化代码,增加更多c++11新特性 7 | 8 | 9 | 关于pb的优势: 10 | 1.Protocol Buffer 利用 varint 原理压缩数据以后,二进制数据非常紧凑,option 也算是压缩体积的一个举措。所以 pb 体积更小,如果选用它作为网络数据传输,势必相同数据,消耗的网络流量更少。但是并没有压缩到极限,float、double 浮点型都没有压缩。 11 | 2.Protocol Buffer 比 JSON 和 XML 少了 {、}、: 这些符号,体积也减少一些。再加上 varint 压缩,gzip 压缩以后体积更小! 12 | Protocol Buffer 是 Tag - Value (Tag - Length - Value)的编码方式的实现,减少了分隔符的使用,数据存储更加紧凑。 13 | 3。Protocol Buffer 另外一个核心价值在于提供了一套工具,一个编译工具,自动化生成 get/set 代码。简化了多语言交互的复杂度,使得编码解码工作有了生产力。 14 | 4.Protocol Buffer 不是自我描述的,离开了数据描述 .proto 文件,就无法理解二进制数据流。这点即是优点,使数据具有一定的“加密性”,也是缺点,数据可读性极差。所以 Protocol Buffer 非常适合内部服务之间 RPC 调用和传递数据。 15 | 5.Protocol Buffer 具有向后兼容的特性,更新数据结构以后,老版本依旧可以兼容,这也是 Protocol Buffer 诞生之初被寄予解决的问题。因为编译器对不识别的新增字段会跳过不处理。 16 | 17 | 18 | 构架再好,模块内部实现更重要 19 | 20 | 21 | 部分问题解决方案 22 | ------------------------------------------------------------------------------------------------------------------------------------------------ 23 | 1、对于正在运行的进程,解决死循环办法 24 | gdb 25 | attach 42834 附加进程调试 26 | info thread 查看线程信息,就可以看到死循环线程执行的函数 27 | bt 查看该线程函数堆栈 28 | frame 1 切换到函数栈,list查看代码 29 | 30 | --------------------------- 31 | 多线程环境下malloc/free 函数崩溃原因 32 | 原因1: 33 | 主线程栈上消耗Memory超过12,568,257 bytes时,进程Crash 34 | 从线程栈上消耗Memory超过10,479,656 bytes时,进程Crash 35 | 原因2: 36 | malloc/free多线程情况调用非常频繁 37 | 解决办法: 38 | 用jemlloc或者tcmalloc内存分配器 39 | 40 | --------------------------- 41 | 内存优化,分析,泄露检测 42 | 可以利用jemalloc的profile, 43 | 注意编译的时候./configure --enable-prof 44 | 并需要通过环境变量控制 export MALLOC_CONF="prof:true,prof_prefix:jeprof.out" 或者 45 | vim ~/.bash_profile 添加下面两行 46 | MALLOC_CONF="prof:true,prof_prefix:jeprof.out" 47 | export MALLOC_CONF 48 | 执行source ~/.bash_profile 生效 49 | 50 | 51 | 2、数据库数据超过几十亿条的处理办法(大数据库处理) 52 | 53 | -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/lua/Lua_API_CH.chm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luotan-123/libevent-server/98652b1b5150402ae771ca0393b2ca7fadb11b8d/linuxserverplatform/Documentation/lua/Lua_API_CH.chm -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/lua/lua原理图.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luotan-123/libevent-server/98652b1b5150402ae771ca0393b2ca7fadb11b8d/linuxserverplatform/Documentation/lua/lua原理图.gif -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/常用命令/git命令.txt: -------------------------------------------------------------------------------- 1 | 1、git创建本地分支 2 | git checkout -b tianhe 3 | 2、创建远程分支 4 | git push origin tianhe:tianhe 5 | 3、本地分支关联远程分支 6 | git branch --set-upstream-to=origin/tianhe tianhe 7 | 8 | linux 安装git 9 | sudo yum install git 10 | 11 | 保存账号和密码 12 | git config --global credential.helper store -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/常用命令/linux命令.txt: -------------------------------------------------------------------------------- 1 | 一、查找进程,关闭进程 2 | 1. ps -ef |grep redis 3 | ps:将某个进程显示出来 4 | -A  显示所有程序。 5 | -e  此参数的效果和指定"A"参数相同。 6 | -f  显示UID,PPIP,C与STIME栏位。 7 | grep命令是查找 8 | 中间的|是管道命令 是指ps命令与grep同时执行 9 | 这条命令的意思是显示有关redis有关的进程 10 | 2. kill[参数][进程号] 11 | kill -9 4394 12 | kill就是给某个进程id发送了一个信号。默认发送的信号是SIGTERM,而kill -9发送的信号是SIGKILL, 13 | 即exit。exit信号不会被系统阻塞,所以kill -9能顺利杀掉进程。当然你也可以使用kill发送其他信号给进程。 14 | 15 | 二、链接命令 16 | 相当于创建快捷方式,可以用来创建动态库命令 17 | ln -s /usr/local/bin/protoc /usr/bin 18 | ln -s /root/linuxserverplatform/bin/LogonServer /usr/bin 19 | 20 | 21 | 三、生成core 22 | 1、执行coredumpshell.sh 脚本 23 | 24 | 四、查询命令目录 25 | which 命令名称 26 | 27 | 五、只显示目录 28 | 1. ls -F | grep '/$' 29 | 2.ls -l | grep '^d' 30 | 31 | 六、去掉windows\r 32 | vim 命令模式下输入 :set fileformat=unix 33 | 34 | 七、gdb输出堆信息 35 | frame 8 (8是堆的层次) 36 | p pThis->m_bRun 37 | 38 | 八、改变文件权限 -R 表示递归目录下所有文件 39 | 修改文件所属组群:chgrp 用户名 文件名 -R 40 | 修改文件拥有者:chown 用户名 文件名 -R 41 | 42 | 九、查看端口占用 43 | ss -lntpd | grep :3306 44 | 45 | 10、设计开机启动脚本 46 | vim /etc/rc.d/rc.local 47 | bash /root/linuxserverplatform/LinuxRun/RedisGame/start-server.sh 48 | chmod +x /etc/rc.d/rc.local 49 | 50 | 11、删除windows \r 51 | vim 相关文件,执行下面指令 52 | set fileformat=unix 53 | 54 | 12、根据进程名字杀死进程 55 | pkill -ce "Server" 56 | 57 | 13、查找并删除 58 | find ./ -name "core.*" | xargs rm -rf 59 | 60 | -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/常用命令/mysql命令.txt: -------------------------------------------------------------------------------- 1 | mysql相关: 2 | 1、修改密码强度 3 | set global validate_password_policy=0; 4 | set global validate_password_length=1; 5 | 下面是mysql8 6 | set global validate_password.policy=0; 7 | set global validate_password.length=1; 8 | ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; 9 | 2、关闭自动更新 10 | yum -y remove mysql57-community-release-el7-10.noarch 11 | 3、设置权限 12 | grant all privileges on *.* to 'root'@'192.168.19.%' identified by 'root' with grant option; 13 | flush privileges; 14 | //mysql8 15 | create user 'root'@'%' identified with mysql_native_password by 'root'; 16 | grant all privileges on *.* to 'root'@'%' with grant option; 17 | flush privileges; 18 | 4、重启mysql 19 | systemctl restart mysqld.service 20 | service mysql restart -- ubuntu 21 | service mysqld restart -- centos 22 | 5、设置不区分大小写 23 | vim /etc/my.cnf 24 | 或者sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 25 | lower_case_table_names=1 26 | 6、安装mysql 27 | https://www.cnblogs.com/yanglang/p/10782941.html 28 | 29 | 操作系统相关: 30 | 1、关闭防火墙 31 | service iptables stop 32 | service firewalld stop 33 | systemctl disable firewalld 防止开机启动 -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/常用命令/redis命令.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luotan-123/libevent-server/98652b1b5150402ae771ca0393b2ca7fadb11b8d/linuxserverplatform/Documentation/常用命令/redis命令.txt -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/服务器部署/启动程序必读.txt: -------------------------------------------------------------------------------- 1 | 1、设置动态(静态)库加载目录 2 | vim /etc/ld.so.conf 3 | 文件中加入一行 /usr/local/lib/ 4 | 执行 root权限运行 ldconfig 5 | 6 | 2、生产core文件 7 | 启动coredumpshell.sh,重启系统生效。重启后,还需要以root执行以下命令。不执行core会生成在当前目录。 8 | echo -e "/tmp/linuxserverplatform-corefile/core-%e-%p-%t" > /proc/sys/kernel/core_pattern 9 | vim /etc/sysctl.conf 配置 net.ipv4.tcp_tw_recycle=1 让TIME-WAIT状态快速回收 10 | sysctl -p立即生效 11 | 12 | 3、安装环境 13 | 如果之前已经安装过以下第三方库,就没必要安装 14 | 用到的轮子: 15 | 1、curl (centos下已经编译好库,不需要安装) 16 | 2、jemalloc (必须安装) 17 | 3、libevent(centos下已经编译好库,不需要安装) 18 | 4、libjson (centos下已经编译好库,不需要安装) 19 | 5、protobuf(必须安装) 20 | 6、redis (选择安装) 21 | hiredis 已经编译成静态库。redis-server、redis-cli、redis-sentinel自己部署。 22 | 如果安装,由于redis依赖库hiredis、jemalloc、lua本服务器也用到。lua尽量用最新版安装,不要用redis自带的。hiredis最好安装。jemalloc可以选择redis自带或者最新版。 23 | 7、libmysqlclient(centos下已经编译好库,不需要安装) 24 | 8、lua (需要下载安装,包括一些其它杂项,参考lua安装相关文档) -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/服务器部署/安装lua开发环境.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luotan-123/libevent-server/98652b1b5150402ae771ca0393b2ca7fadb11b8d/linuxserverplatform/Documentation/服务器部署/安装lua开发环境.docx -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/服务器部署/搭建linux c++开发环境.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luotan-123/libevent-server/98652b1b5150402ae771ca0393b2ca7fadb11b8d/linuxserverplatform/Documentation/服务器部署/搭建linux c++开发环境.docx -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/算法/腾讯面试算法2020-6-9/Makefile: -------------------------------------------------------------------------------- 1 | CPP = g++ 2 | CFLAGS = -g -Wall -O -std=c++11 3 | 4 | main:main.o 5 | $(CPP) main.o -o main 6 | main.o:main.cpp 7 | $(CPP) $(CFLAGS) -c main.cpp 8 | clean: 9 | rm -f main.o main 10 | -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/计划.txt: -------------------------------------------------------------------------------- 1 | 新计划 2020/08/15: 2 | 1、从github下载工具,给服务器做压力测试 3 | 2、shell编程 4 | 3、学习mysql、 5 | 4、Python 6 | 5、go语言 7 | 6、redis集群部署方案 8 | 7、MongoDB 9 | 10 | 11 | 旧计划 2019/10/01 12 | 1、支持websocket协议(已经完成) 13 | 2、支持http协议。(已经初步完成) 14 | 方法:不必重复造轮子,直接网上查 15 | 3、实现c++和lua之间的相互调用(完成) 16 | 4、redis用集群,分布式数据存取,高可靠(未完成) 17 | 5、go语言学习开发(未完成) 18 | 6、github下载压力测试工具,给linux框架做抗压力测试(未完成) 19 | 7、linux项目makefile的编写(完成) 20 | 8、部署服务器shell,开启关闭服务器进程的shell(未完成) 21 | 9、对gserver和gate-logon-server做QBS统计(已经完成) 22 | 10、熟悉rabbitmq(简书已经有使用代码) 23 | 24 | -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/计算机网络/网络编程.txt: -------------------------------------------------------------------------------- 1 | 1、libevent是非阻塞编程,监听socket一定要设置成非阻塞 2 | 3 | 2、新连接的socket,要获取socket发送和接收缓存大小,并设置? 4 | 答案:服务器只需要设置监听socket,就成功设置了新连接socket, 5 | 如果没有设置,服务器新连接socket默认收发缓冲区会有一个默认值,这个默认和客户端的收发缓冲区保持一致 6 | linux客户端socket没必要设置收发缓冲区,当连接成功服务器,系统会设置一个很大值 7 | 建议:服务器端对于新连接的socket,判断一下是否满足数据包大小,再去设置收发缓冲区 8 | cat /proc/sys/net/ipv4/tcp_rmem cat /proc/sys/net/ipv4/tcp_wmem 9 | 10 | 3、如果bufferevent的读缓冲区有数据没有读取完,回调函数是否一直执行? 11 | 答案:不会一直触发 12 | 13 | 4、不能设置成边缘触发,因为担心会有单个数据包服务器不能及时处理? 14 | 答案:bufferevent_enable可以很方便设置边缘触发,目前没有发现异样 15 | 16 | 5、event_base_loop循环的时候,其它线程是否可以添加事件,线程安全? 17 | 答案:可以通过创建一对连接的socket进行通信,来跨平台添加事件 18 | 19 | 6、libevent能多线程编程? 20 | 答案:可以很好的高并发编程 21 | 22 | 7、libevent确定是否可以像epoll,设置最大监听文件描述符大小 23 | 答案:不可以,libevent默认值是32000,在epoll_init函数中有 24 | 25 | 8、bufferevent如何用线程锁 26 | evbuffer_lock(input); 27 | evbuffer_unlock(input); -------------------------------------------------------------------------------- /linuxserverplatform/Documentation/计算机网络/计算机网络.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luotan-123/libevent-server/98652b1b5150402ae771ca0393b2ca7fadb11b8d/linuxserverplatform/Documentation/计算机网络/计算机网络.doc -------------------------------------------------------------------------------- /linuxserverplatform/LinuxRun/Database/database-haowan/php服务器sql脚本/web_清理数据.sql: -------------------------------------------------------------------------------- 1 | truncate table web_admin_action; 2 | truncate table web_admin_log; 3 | truncate table web_agent_apply; 4 | truncate table web_agent_apply_pos; 5 | truncate table web_agent_audit; 6 | truncate table web_agent_bind; 7 | truncate table web_agent_exchange; 8 | truncate table web_agent_feedback; 9 | truncate table web_agent_member; 10 | truncate table web_agent_recharge; 11 | truncate table web_api_record; 12 | truncate table web_bank_record; 13 | truncate table web_bill_detail; 14 | truncate table web_club; 15 | truncate table web_club_member; 16 | truncate table web_code_invitation; 17 | truncate table web_email; 18 | truncate table web_feedback; 19 | truncate table web_feedback_reply; 20 | truncate table web_friend; 21 | truncate table web_friend_notify; 22 | truncate table web_friend_reward; 23 | truncate table web_give_record; 24 | truncate table web_home_feedback; 25 | truncate table web_horn; 26 | truncate table web_notice; 27 | truncate table web_pay_orders; 28 | truncate table web_phone_code; 29 | truncate table web_recharge_commission; 30 | truncate table web_server_black; 31 | truncate table web_server_white; 32 | truncate table web_share_code; 33 | truncate table web_share_record; 34 | truncate table web_sign_record; 35 | truncate table web_support_record; 36 | truncate table web_turntable_record; 37 | truncate table web_vip_room; 38 | truncate table web_agent_bind_reward; 39 | truncate table web_pay_bank_card; 40 | truncate table web_pay_take_record; 41 | truncate table web_agent_pump_money; 42 | truncate table web_agent_pump_jewels; 43 | truncate table web_agent_achievement; 44 | truncate table web_agent_bill; 45 | truncate table web_agent_extractable; 46 | truncate table web_pay_goods_contact; 47 | -------------------------------------------------------------------------------- /linuxserverplatform/LinuxRun/Database/database-haowan/游戏服sql脚本/清理数据库.sql: -------------------------------------------------------------------------------- 1 | truncate table friendsGroupAccounts; 2 | truncate table friendsGroupDeskListCost; 3 | truncate table statistics_firecoinchange; 4 | truncate table statistics_gamerecordinfo; 5 | truncate table statistics_jewelschange; 6 | truncate table statistics_logonandlogout; 7 | truncate table statistics_moneychange; 8 | truncate table statistics_rewardspool; 9 | truncate table statistics_roomwincount; 10 | truncate table userInfo; 11 | truncate table rewardsPool; -------------------------------------------------------------------------------- /linuxserverplatform/LinuxRun/Database/database-haowan/游戏服sql脚本/生成机器人.sql: -------------------------------------------------------------------------------- 1 | DROP PROCEDURE IF EXISTS insert_robot; 2 | 3 | DELIMITER;; 4 | CREATE PROCEDURE insert_robot() 5 | 6 | BEGIN 7 | DECLARE i INT DEFAULT 117000; #设置账号初始值 8 | 9 | WHILE i < 118000 #设置账号截止值 10 | DO 11 | insert into userInfo(userID,account,passwd,isVirtual,sex) values(i,concat('HMRobot',i),'e10adc3949ba59abbe56e057f20f883e',1,floor(rand()*2)); # 更改'HMRobot'可以改变机器人登陆前缀 12 | SET i=i+1; 13 | END WHILE; 14 | 15 | commit; 16 | 17 | END;; 18 | 19 | CALL insert_robot(); 20 | 21 | #随机生成机器人名字 22 | update userInfo set name=concat(substring('赵钱孙李周吴郑王冯陈诸卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤滕殷罗毕郝邬安常乐于时傅皮齐康伍余元卜顾孟平黄和穆萧尹姚邵堪汪祁毛禹狄米贝明臧计伏成戴谈宋茅庞熊纪舒屈项祝董粱杜阮蓝闵席季麻强贾路娄危江童颜郭梅盛林刁钟徐邱骆高夏蔡田樊胡凌霍虞万支柯咎管卢莫经房裘干解应宗丁宣贲邓郁单杭洪包诸左石崔吉钮龚',floor(1+190*rand()),1),substring('明国华建文平志伟东海强晓生光林小民永杰军金健一忠洪江福祥中正振勇耀春大宁亮宇兴宝少剑云学仁涛瑞飞鹏安亚泽世汉达卫利胜敏群波成荣新峰刚家龙德庆斌辉良玉俊立浩天宏子松克清长嘉红山贤阳乐锋智青跃元武广思雄锦威启昌铭维义宗英凯鸿森超坚旭政传康继翔栋仲权奇礼楠炜友年震鑫雷兵万星骏伦绍麟雨行才希彦兆贵源有景升惠臣慧开章润高佳虎根远力进泉茂毅富博霖顺信凡豪树和恩向道川彬柏磊敬书鸣芳培全炳基冠晖京欣廷哲保秋君劲轩帆若连勋祖锡吉崇钧田石奕发洲彪钢运伯满庭申湘皓承梓雪孟其潮冰怀鲁裕翰征谦航士尧标洁城寿枫革纯风化逸腾岳银鹤琳显焕来心凤睿勤延凌昊西羽百捷定琦圣佩麒虹如靖日咏会久昕黎桂玮燕可越彤雁孝宪萌颖艺夏桐月瑜沛诚夫声冬奎扬双坤镇楚水铁喜之迪泰方同滨邦先聪朝善非恒晋汝丹为晨乃秀岩辰洋然厚灿卓杨钰兰怡灵淇美琪亦晶舒菁真涵爽雅爱依静棋宜男蔚芝菲露娜珊雯淑曼萍珠诗璇琴素梅玲蕾艳紫珍丽仪梦倩伊茜妍碧芬儿岚婷菊妮媛莲娟一',floor(1+400*rand()),1),substring('明国华建文平志伟东海强晓生光林小民永杰军金健一忠洪江福祥中正振勇耀春大宁亮宇兴宝少剑云学仁涛瑞飞鹏安亚泽世汉达卫利胜敏群波成荣新峰刚家龙德庆斌辉良玉俊立浩天宏子松克清长嘉红山贤阳乐锋智青跃元武广思雄锦威启昌铭维义宗英凯鸿森超坚旭政传康继翔栋仲权奇礼楠炜友年震鑫雷兵万星骏伦绍麟雨行才希彦兆贵源有景升惠臣慧开章润高佳虎根远力进泉茂毅富博霖顺信凡豪树和恩向道川彬柏磊敬书鸣芳培全炳基冠晖京欣廷哲保秋君劲轩帆若连勋祖锡吉崇钧田石奕发洲彪钢运伯满庭申湘皓承梓雪孟其潮冰怀鲁裕翰征谦航士尧标洁城寿枫革纯风化逸腾岳银鹤琳显焕来心凤睿勤延凌昊西羽百捷定琦圣佩麒虹如靖日咏会久昕黎桂玮燕可越彤雁孝宪萌颖艺夏桐月瑜沛诚夫声冬奎扬双坤镇楚水铁喜之迪泰方同滨邦先聪朝善非恒晋汝丹为晨乃秀岩辰洋然厚灿卓杨钰兰怡灵淇美琪亦晶舒菁真涵爽雅爱依静棋宜男蔚芝菲露娜珊雯淑曼萍珠诗璇琴素梅玲蕾艳紫珍丽仪梦倩伊茜妍碧芬儿岚婷菊妮媛莲娟一',floor(1+400*rand()),1)) where isVirtual=1 -------------------------------------------------------------------------------- /linuxserverplatform/LinuxRun/Database/database_haotain/php服务器sql脚本/web_清理数据.sql: -------------------------------------------------------------------------------- 1 | truncate table web_admin_action; 2 | truncate table web_admin_log; 3 | truncate table web_agent_apply; 4 | truncate table web_agent_apply_pos; 5 | truncate table web_agent_audit; 6 | truncate table web_agent_bind; 7 | truncate table web_agent_exchange; 8 | truncate table web_agent_feedback; 9 | truncate table web_agent_member; 10 | truncate table web_agent_recharge; 11 | truncate table web_api_record; 12 | truncate table web_bank_record; 13 | truncate table web_bill_detail; 14 | truncate table web_club; 15 | truncate table web_club_member; 16 | truncate table web_code_invitation; 17 | truncate table web_email; 18 | truncate table web_feedback; 19 | truncate table web_feedback_reply; 20 | truncate table web_friend; 21 | truncate table web_friend_notify; 22 | truncate table web_friend_reward; 23 | truncate table web_give_record; 24 | truncate table web_home_feedback; 25 | truncate table web_horn; 26 | truncate table web_notice; 27 | truncate table web_pay_orders; 28 | truncate table web_phone_code; 29 | truncate table web_recharge_commission; 30 | truncate table web_server_black; 31 | truncate table web_server_white; 32 | truncate table web_share_code; 33 | truncate table web_share_record; 34 | truncate table web_sign_record; 35 | truncate table web_support_record; 36 | truncate table web_turntable_record; 37 | truncate table web_vip_room; 38 | truncate table web_agent_bind_reward; 39 | truncate table web_pay_bank_card; 40 | truncate table web_pay_take_record; 41 | truncate table web_agent_pump_money; 42 | truncate table web_agent_pump_jewels; 43 | -------------------------------------------------------------------------------- /linuxserverplatform/LinuxRun/Database/database_haotain/游戏服sql脚本/清理数据库.sql: -------------------------------------------------------------------------------- 1 | truncate table friendsGroupAccounts; 2 | truncate table friendsGroupDeskListCost; 3 | truncate table statistics_firecoinchange; 4 | truncate table statistics_gamerecordinfo; 5 | truncate table statistics_jewelschange; 6 | truncate table statistics_logonandlogout; 7 | truncate table statistics_moneychange; 8 | truncate table statistics_rewardspool; 9 | truncate table statistics_roomwincount; 10 | truncate table userInfo; 11 | truncate table rewardsPool; -------------------------------------------------------------------------------- /linuxserverplatform/LinuxRun/Database/database_haotain/游戏服sql脚本/生成机器人.sql: -------------------------------------------------------------------------------- 1 | DROP PROCEDURE IF EXISTS insert_robot; 2 | 3 | DELIMITER;; 4 | CREATE PROCEDURE insert_robot() 5 | 6 | BEGIN 7 | DECLARE i INT DEFAULT 11700000; #设置账号初始值 8 | 9 | WHILE i < 11800000 #设置账号截止值 10 | DO 11 | insert into userInfo(userID,account,passwd,isVirtual,sex) values(i,concat('HMRobot',i),'e10adc3949ba59abbe56e057f20f883e',1,floor(rand()*2)); # 更改'HMRobot'可以改变机器人登陆前缀 12 | SET i=i+1; 13 | END WHILE; 14 | 15 | commit; 16 | 17 | END;; 18 | 19 | CALL insert_robot(); 20 | 21 | #随机生成机器人名字 22 | update userInfo set name=concat(substring('赵钱孙李周吴郑王冯陈诸卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤滕殷罗毕郝邬安常乐于时傅皮齐康伍余元卜顾孟平黄和穆萧尹姚邵堪汪祁毛禹狄米贝明臧计伏成戴谈宋茅庞熊纪舒屈项祝董粱杜阮蓝闵席季麻强贾路娄危江童颜郭梅盛林刁钟徐邱骆高夏蔡田樊胡凌霍虞万支柯咎管卢莫经房裘干解应宗丁宣贲邓郁单杭洪包诸左石崔吉钮龚',floor(1+190*rand()),1),substring('明国华建文平志伟东海强晓生光林小民永杰军金健一忠洪江福祥中正振勇耀春大宁亮宇兴宝少剑云学仁涛瑞飞鹏安亚泽世汉达卫利胜敏群波成荣新峰刚家龙德庆斌辉良玉俊立浩天宏子松克清长嘉红山贤阳乐锋智青跃元武广思雄锦威启昌铭维义宗英凯鸿森超坚旭政传康继翔栋仲权奇礼楠炜友年震鑫雷兵万星骏伦绍麟雨行才希彦兆贵源有景升惠臣慧开章润高佳虎根远力进泉茂毅富博霖顺信凡豪树和恩向道川彬柏磊敬书鸣芳培全炳基冠晖京欣廷哲保秋君劲轩帆若连勋祖锡吉崇钧田石奕发洲彪钢运伯满庭申湘皓承梓雪孟其潮冰怀鲁裕翰征谦航士尧标洁城寿枫革纯风化逸腾岳银鹤琳显焕来心凤睿勤延凌昊西羽百捷定琦圣佩麒虹如靖日咏会久昕黎桂玮燕可越彤雁孝宪萌颖艺夏桐月瑜沛诚夫声冬奎扬双坤镇楚水铁喜之迪泰方同滨邦先聪朝善非恒晋汝丹为晨乃秀岩辰洋然厚灿卓杨钰兰怡灵淇美琪亦晶舒菁真涵爽雅爱依静棋宜男蔚芝菲露娜珊雯淑曼萍珠诗璇琴素梅玲蕾艳紫珍丽仪梦倩伊茜妍碧芬儿岚婷菊妮媛莲娟一',floor(1+400*rand()),1),substring('明国华建文平志伟东海强晓生光林小民永杰军金健一忠洪江福祥中正振勇耀春大宁亮宇兴宝少剑云学仁涛瑞飞鹏安亚泽世汉达卫利胜敏群波成荣新峰刚家龙德庆斌辉良玉俊立浩天宏子松克清长嘉红山贤阳乐锋智青跃元武广思雄锦威启昌铭维义宗英凯鸿森超坚旭政传康继翔栋仲权奇礼楠炜友年震鑫雷兵万星骏伦绍麟雨行才希彦兆贵源有景升惠臣慧开章润高佳虎根远力进泉茂毅富博霖顺信凡豪树和恩向道川彬柏磊敬书鸣芳培全炳基冠晖京欣廷哲保秋君劲轩帆若连勋祖锡吉崇钧田石奕发洲彪钢运伯满庭申湘皓承梓雪孟其潮冰怀鲁裕翰征谦航士尧标洁城寿枫革纯风化逸腾岳银鹤琳显焕来心凤睿勤延凌昊西羽百捷定琦圣佩麒虹如靖日咏会久昕黎桂玮燕可越彤雁孝宪萌颖艺夏桐月瑜沛诚夫声冬奎扬双坤镇楚水铁喜之迪泰方同滨邦先聪朝善非恒晋汝丹为晨乃秀岩辰洋然厚灿卓杨钰兰怡灵淇美琪亦晶舒菁真涵爽雅爱依静棋宜男蔚芝菲露娜珊雯淑曼萍珠诗璇琴素梅玲蕾艳紫珍丽仪梦倩伊茜妍碧芬儿岚婷菊妮媛莲娟一',floor(1+400*rand()),1)) where isVirtual=1 -------------------------------------------------------------------------------- /linuxserverplatform/LinuxRun/Database/新增的sql语句/logonbaseinfo.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : 192.168.198.171 5 | Source Server Version : 80020 6 | Source Host : 192.168.198.171:3306 7 | Source Database : newframe 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 80020 11 | File Encoding : 65001 12 | 13 | Date: 2020-06-05 17:13:36 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for logonbaseinfo 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `logonbaseinfo`; 22 | CREATE TABLE `logonbaseinfo` ( 23 | `logonID` int NOT NULL DEFAULT '0' COMMENT '网关服主id', 24 | `ip` varchar(24) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT '' COMMENT '网关服ip地址', 25 | `intranetIP` varchar(24) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT '' COMMENT '内网ip', 26 | `port` int DEFAULT '3015' COMMENT '网关服端口', 27 | `webSocketPort` int DEFAULT '3017' COMMENT 'websocket端口', 28 | `maxPeople` int DEFAULT '3000' COMMENT '网关服最多容纳的最大人数', 29 | `maxWebSocketPeople` int DEFAULT '2000' COMMENT '网关服websocket最多容纳的最大人数', 30 | `status` tinyint DEFAULT '0' COMMENT '0:关闭状态,1:开启状态', 31 | `curPeople` int DEFAULT '0' COMMENT '当前人数', 32 | `curWebSocketPeople` int DEFAULT '0' COMMENT '当前人数', 33 | `socketCount` int DEFAULT '0' COMMENT 'socket数量', 34 | `webSocketCount` int DEFAULT '0' COMMENT 'socket数量', 35 | PRIMARY KEY (`logonID`) 36 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 37 | 38 | -- ---------------------------- 39 | -- Records of logonbaseinfo 40 | -- ---------------------------- 41 | INSERT INTO `logonbaseinfo` VALUES ('1', '192.168.198.171', '127.0.0.1', '3016', '3017', '3000', '2000', '0', '0', '0', '107', '0'); 42 | -------------------------------------------------------------------------------- /linuxserverplatform/LinuxRun/Database/新增的sql语句/workbaseinfo.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : 192.168.198.171 5 | Source Server Version : 50645 6 | Source Host : 192.168.198.171:3306 7 | Source Database : newframe 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50645 11 | File Encoding : 65001 12 | 13 | Date: 2020-05-29 18:21:53 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for workbaseinfo 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `workbaseinfo`; 22 | CREATE TABLE `workbaseinfo` ( 23 | `workID` int(6) NOT NULL DEFAULT '0' COMMENT '逻辑服主id', 24 | `status` tinyint(2) DEFAULT '0' COMMENT '0:关闭状态,1:开启状态', 25 | `gateconnected` tinyint(2) DEFAULT '1' COMMENT '是否连接网关', 26 | PRIMARY KEY (`workID`) 27 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 28 | 29 | -- ---------------------------- 30 | -- Records of workbaseinfo 31 | -- ---------------------------- 32 | INSERT INTO `workbaseinfo` VALUES ('1', '0', '1'); 33 | -------------------------------------------------------------------------------- /linuxserverplatform/LinuxRun/RedisGame/start-server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ./redis-server redis.conf & 3 | -------------------------------------------------------------------------------- /linuxserverplatform/LinuxRun/RedisPHP/start-server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ./redis-server redis.conf & 3 | -------------------------------------------------------------------------------- /linuxserverplatform/LinuxRun/libs/install_libs.sh: -------------------------------------------------------------------------------- 1 | cp -i ./libcrypto.so.10 /usr/local/lib/ 2 | cp -i ./libcurl.so.4 /usr/local/lib/ 3 | cp -i ./libevent-2.2.so.1 /usr/local/lib/ 4 | cp -i ./libevent_pthreads-2.2.so.1 /usr/local/lib/ 5 | cp -i ./libhiredis.a /usr/local/lib/ 6 | cp -i ./libjson.so /usr/local/lib/ 7 | cp -i ./libmysqlclient.so.20 /usr/local/lib/ 8 | cp -i ./libssh2.so.1 /usr/local/lib/ 9 | cp -i ./libssl.so.10 /usr/local/lib/ 10 | 11 | echo "copy success !!!" 12 | 13 | ln -is /usr/local/lib/libcurl.so.4 /usr/local/lib/libcurl.so 14 | ln -is /usr/local/lib/libevent-2.2.so.1 /usr/local/lib/libevent.so 15 | ln -is /usr/local/lib/libevent_pthreads-2.2.so.1 /usr/local/lib/libevent_pthreads.so 16 | ln -is /usr/local/lib/libmysqlclient.so.20 /usr/local/lib/libmysqlclient.so 17 | 18 | echo "link success !!!" 19 | -------------------------------------------------------------------------------- /linuxserverplatform/LinuxRun/shell/coredumpshell.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ### Filename: coredumpshell.sh 4 | ### Description: enable coredump and format the name of core file on centos system 5 | 6 | # enable coredump whith unlimited file-size for all users 7 | echo -e "\n# enable coredump whith unlimited file-size for all users\n* soft core unlimited" >> /etc/security/limits.conf 8 | 9 | # set the path of core file with permission 777 10 | cd /tmp && mkdir -p linuxserverplatform-corefile && chmod 777 linuxserverplatform-corefile 11 | 12 | # format the name of core file. 13 | # %% – 符号% 14 | # %p – 进程号 15 | # %u – 进程用户id 16 | # %g – 进程用户组id 17 | # %s – 生成core文件时收到的信号 18 | # %t – 生成core文件的时间戳(seconds since 0:00h, 1 Jan 1970) 19 | # %h – 主机名 20 | # %e – 程序文件名 21 | echo -e "/tmp/linuxserverplatform-corefile/core-%e-%p-%t" > /proc/sys/kernel/core_pattern 22 | 23 | # for centos7 system(update 2017.2.3 21:44) 24 | echo -e "/tmp/linuxserverplatform-corefile/core-%e-%p-%t" > /etc/sysctl.conf 25 | 26 | # suffix of the core file name 27 | echo -e "1" > /proc/sys/kernel/core_uses_pid 28 | -------------------------------------------------------------------------------- /linuxserverplatform/LinuxRun/shell/deletejson.sh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luotan-123/libevent-server/98652b1b5150402ae771ca0393b2ca7fadb11b8d/linuxserverplatform/LinuxRun/shell/deletejson.sh -------------------------------------------------------------------------------- /linuxserverplatform/README.md: -------------------------------------------------------------------------------- 1 | # 说明 2 | Documentation里面,有linux开发环境安装相关文档,包括一些重要的第三方库 3 | 4 | # projects 5 | c++ 项目 6 | 基于libevent、jemalloc的棋牌游戏服务器框架 7 | 包含游戏,扑鱼、斗地主、麻将、跑胡子 8 | 9 | # 用到的轮子: 10 | 如果之前已经安装过以下第三方库,就没必要安装 11 | 12 | 用到的轮子: 13 | 14 | 1、curl (centos下已经编译好库,不需要安装) 15 | 16 | 2、jemalloc (必须安装) 17 | 18 | 3、libevent(centos下已经编译好库,不需要安装) 19 | 20 | 4、libjson (centos下已经编译好库,不需要安装) 21 | 22 | 5、protobuf(必须安装) 23 | 24 | 6、redis (选择安装) 25 | 26 | hiredis 已经编译成静态库。redis-server、redis-cli、redis-sentinel自己部署。 27 | 如果安装,由于redis依赖库hiredis、jemalloc、lua本服务器也用到。lua尽量用最新版安装,不要用redis自带的。hiredis最好安装。jemalloc可以选择redis自带或者最新版。 28 | 29 | 7、libmysqlclient(centos下已经编译好库,不需要安装) 30 | 31 | 8、lua (需要下载安装,包括一些其它杂项,参考lua安装相关文档) 32 | -------------------------------------------------------------------------------- /linuxserverplatform/games/12101105_ZJH/.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj 3 | -------------------------------------------------------------------------------- /linuxserverplatform/games/12101105_ZJH/12101105_ZJH.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /linuxserverplatform/games/30100008_NN/.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj 3 | -------------------------------------------------------------------------------- /linuxserverplatform/games/30100008_NN/30100008_NN.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /linuxserverplatform/src/CenterServer/CenterServerModule.cpp: -------------------------------------------------------------------------------- 1 | #include "CommonHead.h" 2 | #include "CenterServerModule.h" 3 | 4 | 5 | CCenterServerModule::CCenterServerModule() 6 | { 7 | 8 | } 9 | 10 | CCenterServerModule::~CCenterServerModule() 11 | { 12 | 13 | } 14 | 15 | bool CCenterServerModule::InitService(ManageInfoStruct * pInitData) 16 | { 17 | INFO_LOG("CenterServerModule InitService begin ..."); 18 | if (!pInitData) 19 | { 20 | ERROR_LOG("invalid param input"); 21 | return false; 22 | } 23 | 24 | bool ret = false; 25 | 26 | ret = m_CenterServerManage.Init(pInitData); 27 | if (!ret) 28 | { 29 | ERROR_LOG("CenterServerManage Init failed"); 30 | return false; 31 | } 32 | 33 | INFO_LOG("CenterServerModule InitService end."); 34 | 35 | return true; 36 | } 37 | 38 | bool CCenterServerModule::UnInitService() 39 | { 40 | try 41 | { 42 | return m_CenterServerManage.UnInit(); 43 | } 44 | catch (CException * pException) 45 | { 46 | pException->Delete(); 47 | ERROR_LOG("CATCH:%s with %s\n", __FILE__, __FUNCTION__); 48 | } 49 | catch (...) 50 | { 51 | ERROR_LOG("CATCH:%s with %s\n", __FILE__, __FUNCTION__); 52 | } 53 | 54 | return false; 55 | } 56 | 57 | bool CCenterServerModule::StartService(UINT &errCode) 58 | { 59 | INFO_LOG("CenterServerModule StartService begin..."); 60 | 61 | errCode = 0; 62 | 63 | if (!m_CenterServerManage.Start()) 64 | { 65 | return false; 66 | } 67 | 68 | INFO_LOG("CenterServerModule StartService end"); 69 | 70 | return true; 71 | } 72 | 73 | bool CCenterServerModule::StoptService() 74 | { 75 | INFO_LOG("CenterServerModule StoptService begin..."); 76 | 77 | bool ret = m_CenterServerManage.Stop(); 78 | if (!ret) 79 | { 80 | ERROR_LOG("LogonManage Stop failed"); 81 | return false; 82 | } 83 | 84 | INFO_LOG("CenterServerModule StoptService end"); 85 | 86 | return true; 87 | } 88 | 89 | bool CCenterServerModule::DeleteService() 90 | { 91 | try 92 | { 93 | delete this; 94 | } 95 | catch (...) 96 | { 97 | ERROR_LOG("CATCH:%s with %s\n", __FILE__, __FUNCTION__); 98 | } 99 | 100 | return true; 101 | } 102 | 103 | bool CCenterServerModule::UpdateService() 104 | { 105 | return true; 106 | } -------------------------------------------------------------------------------- /linuxserverplatform/src/CenterServer/CenterServerModule.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CenterServerManage.h" 4 | 5 | //游戏登陆模块 6 | class CCenterServerModule : public IModuleManageService 7 | { 8 | public: 9 | CCenterServerManage m_CenterServerManage; //登陆管理 10 | 11 | public: 12 | CCenterServerModule(); 13 | virtual ~CCenterServerModule(); 14 | 15 | public: 16 | virtual bool InitService(ManageInfoStruct* pInitData); 17 | virtual bool UnInitService(); 18 | virtual bool StartService(UINT& errCode); 19 | virtual bool StoptService(); 20 | virtual bool DeleteService(); 21 | virtual bool UpdateService(); 22 | }; 23 | -------------------------------------------------------------------------------- /linuxserverplatform/src/CenterServer/Makefile: -------------------------------------------------------------------------------- 1 | # CenterServer的Makefile文件 2 | 3 | # 编译版本,可选debug和release 4 | #build_ver=debug 5 | 6 | ifeq ($(build_ver),release) 7 | BUILD_OPT= -g1 -O3 8 | else 9 | BUILD_OPT= -g2 -O0 10 | endif 11 | 12 | 13 | CPP = g++ 14 | CPPFLAGS = -I ../include -I ../include/ServerCommon -I ../include/curl -I ../include/DataBase -I ../include/libevent -I ../include/hiredis -I ../lua -I ../protobuf -I /usr/local/include -DLUA_COMPAT_5_1 $(BUILD_OPT) -Wall -std=c++11 15 | CFLAGS = -I ../include -I ../include/ServerCommon -I ../include/curl -I ../include/DataBase -I ../include/libevent -I ../include/hiredis -I ../lua -I ../protobuf -I /usr/local/include -DLUA_COMPAT_5_1 $(BUILD_OPT) -Wall -std=c11 16 | 17 | # 设置默认加载库位置 18 | CURDIR := $(shell pwd) 19 | PARENT_CURDIR = $(shell dirname $(CURDIR)) 20 | PARENT_BIN := $(PARENT_CURDIR)/bin/ 21 | 22 | LDFLAGS = -L ../bin -Wl,-rpath=$(PARENT_BIN) 23 | LIBS = -lpthread -lKernel -lCommon -levent -ljemalloc 24 | 25 | BINDIR := ../bin/ 26 | BIN := CenterServer 27 | OBJ := BaseCenterServer.o CenterServerManage.o CenterServerModule.o main.o jemalloc_cpp.o 28 | DEP = $(OBJ:.o=.dep) 29 | 30 | $(BINDIR)$(BIN):$(OBJ) 31 | $(CPP) -o $@ $(LDFLAGS) $^ $(LIBS) 32 | 33 | %.o:%.cpp 34 | $(CPP) -c $< $(CPPFLAGS) 35 | 36 | jemalloc_cpp.o:../jemalloc/jemalloc_cpp.cpp 37 | $(CPP) -c $< $(CPPFLAGS) 38 | 39 | #%.o:../protobuf/%.cc 40 | # $(CPP) -c $< $(CPPFLAGS) 41 | 42 | #%.o:../lua/%.c 43 | # $(CPP) -c -x c $< $(CFLAGS) 44 | 45 | 46 | # 生成依赖项 47 | %.dep:%.cpp 48 | $(CPP) -MM $< $(CPPFLAGS) > $@ 49 | 50 | #%.dep:../protobuf/%.cc 51 | # $(CPP) -MM $< $(CPPFLAGS) > $@ 52 | 53 | #%.dep:../lua/%.c 54 | # $(CPP) -MM -x c $< $(CFLAGS) > $@ 55 | 56 | -include $(DEP) 57 | 58 | 59 | install: 60 | @echo "CenterServer生成在../bin/目录中" 61 | 62 | clean: 63 | rm -rf *.o *.dep 64 | 65 | -------------------------------------------------------------------------------- /linuxserverplatform/src/Common/BillManage.cpp: -------------------------------------------------------------------------------- 1 | #include "CommonHead.h" 2 | #include "MysqlHelper.h" 3 | #include "Define.h" 4 | #include "Util.h" 5 | #include "log.h" 6 | #include 7 | #include "DataLine.h" 8 | #include "AsyncEventMsg.h" 9 | #include "BillManage.h" 10 | 11 | 12 | CBillManage::CBillManage() 13 | { 14 | } 15 | 16 | CBillManage::~CBillManage() 17 | { 18 | } 19 | 20 | CBillManage* CBillManage::Instance() 21 | { 22 | static CBillManage manage; 23 | return &manage; 24 | } 25 | 26 | void CBillManage::Release() 27 | { 28 | } 29 | 30 | void CBillManage::WriteBill(CDataBaseManage* m_pDBManage, const char* pFormat, ...) 31 | { 32 | if (m_pDBManage == NULL) 33 | { 34 | ERROR_LOG("数据句柄m_pDBManage=NULL"); 35 | return; 36 | } 37 | 38 | char sql[MAX_SQL_STATEMENT_SIZE] = ""; 39 | 40 | va_list args; 41 | va_start(args, pFormat); 42 | 43 | vsprintf(sql, pFormat, args); 44 | 45 | va_end(args); 46 | 47 | AsyncEventMsgSqlStatement msg; 48 | memcpy(msg.sql, sql, sizeof(sql)); 49 | 50 | if (!m_pDBManage->PushLine(&msg.dataLineHead, sizeof(msg) - sizeof(msg.sql) + strlen(msg.sql), ASYNC_EVENT_SQL_STATEMENT, DB_TYPE_LOG, 0)) 51 | { 52 | ERROR_LOG("投递队列失败:%s", sql); 53 | } 54 | } -------------------------------------------------------------------------------- /linuxserverplatform/src/Common/Makefile: -------------------------------------------------------------------------------- 1 | # Common的Makefile文件 2 | 3 | # 编译版本,可选debug和release 4 | #build_ver=debug 5 | 6 | ifeq ($(build_ver),release) 7 | BUILD_OPT= -g1 -O2 8 | else 9 | BUILD_OPT= -g2 -O0 10 | endif 11 | 12 | 13 | CPP = g++ 14 | CPPFLAGS = -I ../include -I ../include/ServerCommon -I ../include/curl -I ../include/DataBase -I ../include/libevent -I ../include/hiredis -I ../lua -I ../protobuf -I /usr/local/include -DLUA_COMPAT_5_1 $(BUILD_OPT) -Wall -fpic -std=c++11 15 | CFLAGS = -I ../include -I ../include/ServerCommon -I ../include/curl -I ../include/DataBase -I ../include/libevent -I ../include/hiredis -I ../lua -I ../protobuf -I /usr/local/include -DLUA_COMPAT_5_1 $(BUILD_OPT) -Wall -fpic -std=c11 16 | 17 | # 设置默认加载库位置 18 | CURDIR := $(shell pwd) 19 | PARENT_CURDIR = $(shell dirname $(CURDIR)) 20 | PARENT_BIN := $(PARENT_CURDIR)/bin/ 21 | 22 | LDFLAGS = -L ../bin -shared -Wl,-rpath=$(PARENT_BIN) 23 | LIBS = -lpthread -lKernel -lhiredis -lcurl -lprotobuf -ljemalloc -levent -levent_pthreads -llua -lmysqlclient 24 | 25 | BINDIR := ../bin/ 26 | BIN := libCommon.so 27 | OBJ := BillManage.o HttpServer.o MD5.o MyCurl.o RedisBase.o RedisCenter.o RedisCommon.o RedisLoader.o RedisLogon.o RedisPHP.o Util.o jemalloc_cpp.o auxiliar.o buffer.o except.o inet.o io.o ls_mysql.o luasocket.o luasql.o mime.o options.o pb.o select.o tcp.o timeout.o udp.o unix.o usocket.o AsyncEventMsg.pb.o 28 | DEP = $(OBJ:.o=.dep) 29 | 30 | $(BINDIR)$(BIN):$(OBJ) 31 | $(CPP) -o $@ $(LDFLAGS) $^ $(LIBS) 32 | 33 | %.o:%.cpp 34 | $(CPP) -c $< $(CPPFLAGS) 35 | 36 | jemalloc_cpp.o:../jemalloc/jemalloc_cpp.cpp 37 | $(CPP) -c $< $(CPPFLAGS) 38 | 39 | %.o:../protobuf/%.cc 40 | $(CPP) -c $< $(CPPFLAGS) 41 | 42 | %.o:../lua/%.c 43 | $(CPP) -c -x c $< $(CFLAGS) 44 | 45 | 46 | # 生成依赖项 47 | %.dep:%.cpp 48 | $(CPP) -MM $< $(CPPFLAGS) > $@ 49 | 50 | %.dep:../protobuf/%.cc 51 | $(CPP) -MM $< $(CPPFLAGS) > $@ 52 | 53 | %.dep:../lua/%.c 54 | $(CPP) -MM -x c $< $(CFLAGS) > $@ 55 | 56 | -include $(DEP) 57 | 58 | 59 | install: 60 | cp $(BINDIR)$(BIN) /usr/local/lib 61 | 62 | clean: 63 | rm -rf *.o *.dep 64 | 65 | -------------------------------------------------------------------------------- /linuxserverplatform/src/GameManage/Makefile: -------------------------------------------------------------------------------- 1 | # GameManage的Makefile文件 2 | 3 | # 编译版本,可选debug和release 4 | #build_ver=debug 5 | 6 | ifeq ($(build_ver),release) 7 | BUILD_OPT= -g1 -O3 8 | else 9 | BUILD_OPT= -g2 -O0 10 | endif 11 | 12 | 13 | CPP = g++ 14 | CPPFLAGS = -I ../include -I ../include/ServerCommon -I ../include/curl -I ../include/DataBase -I ../include/libevent -I ../include/hiredis -I ../lua -I ../protobuf -I /usr/local/include -DLUA_COMPAT_5_1 $(BUILD_OPT) -Wall -fpic -std=c++11 15 | CFLAGS = -I ../include -I ../include/ServerCommon -I ../include/curl -I ../include/DataBase -I ../include/libevent -I ../include/hiredis -I ../lua -I ../protobuf -I /usr/local/include -DLUA_COMPAT_5_1 $(BUILD_OPT) -Wall -fpic -std=c11 16 | 17 | # 设置默认加载库位置 18 | CURDIR := $(shell pwd) 19 | PARENT_CURDIR = $(shell dirname $(CURDIR)) 20 | PARENT_BIN := $(PARENT_CURDIR)/bin/ 21 | 22 | LDFLAGS = -L ../bin -shared -Wl,-rpath=$(PARENT_BIN) 23 | LIBS = -lpthread -lKernel -lCommon -ljson -lprotobuf -ljemalloc -lhiredis 24 | 25 | BINDIR := ../bin/ 26 | BIN := libGameManage.so 27 | OBJ := BaseMainManage.o GameDataBaseHandle.o GameDesk.o GameMainManage.o gameUserManage.o jemalloc_cpp.o 28 | DEP = $(OBJ:.o=.dep) 29 | 30 | $(BINDIR)$(BIN):$(OBJ) 31 | $(CPP) -o $@ $(LDFLAGS) $^ $(LIBS) 32 | 33 | %.o:%.cpp 34 | $(CPP) -c $< $(CPPFLAGS) 35 | 36 | jemalloc_cpp.o:../jemalloc/jemalloc_cpp.cpp 37 | $(CPP) -c $< $(CPPFLAGS) 38 | 39 | #%.o:../protobuf/%.cc 40 | # $(CPP) -c $< $(CPPFLAGS) 41 | 42 | #%.o:../lua/%.c 43 | # $(CPP) -c -x c $< $(CFLAGS) 44 | 45 | 46 | # 生成依赖项 47 | %.dep:%.cpp 48 | $(CPP) -MM $< $(CPPFLAGS) > $@ 49 | 50 | #%.dep:../protobuf/%.cc 51 | # $(CPP) -MM $< $(CPPFLAGS) > $@ 52 | 53 | #%.dep:../lua/%.c 54 | # $(CPP) -MM -x c $< $(CFLAGS) > $@ 55 | 56 | -include $(DEP) 57 | 58 | 59 | install: 60 | cp $(BINDIR)$(BIN) /usr/local/lib 61 | 62 | clean: 63 | rm -rf *.o *.dep 64 | 65 | -------------------------------------------------------------------------------- /linuxserverplatform/src/Kernel/CXObj.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "CXObj.h" 3 | 4 | byte* CXObj::pCurrentObj = NULL; 5 | -------------------------------------------------------------------------------- /linuxserverplatform/src/Kernel/Exception.cpp: -------------------------------------------------------------------------------- 1 | #include "CommonHead.h" 2 | #include "Exception.h" 3 | #include "log.h" 4 | #include 5 | 6 | //静态变量定义 7 | bool CException::m_bShowError = false; //是否显示错误 8 | 9 | CException::CException(const char* szErrorMessage, unsigned int uErrorCode, bool bAutoDelete) 10 | { 11 | m_uErrorCode = uErrorCode; 12 | m_bAutoDelete = bAutoDelete; 13 | if ((szErrorMessage != NULL) && (szErrorMessage[0] != 0)) 14 | { 15 | if (strlen(szErrorMessage) < (sizeof(m_szMessage) / sizeof(m_szMessage[0]))) 16 | { 17 | strcpy(m_szMessage, szErrorMessage); 18 | } 19 | else 20 | { 21 | strcpy(m_szMessage, "异常错误信息太长"); 22 | } 23 | } 24 | else 25 | { 26 | strcpy(m_szMessage, "没有异常信息"); 27 | } 28 | 29 | if (m_bShowError == true) 30 | { 31 | ERROR_LOG("%s", m_szMessage); 32 | } 33 | } 34 | 35 | 36 | CException::~CException() 37 | { 38 | } 39 | 40 | //获取错误代码 41 | UINT CException::GetErrorCode() const 42 | { 43 | if (this != NULL) return m_uErrorCode; 44 | return 0; 45 | } 46 | 47 | //删除函数 48 | bool CException::Delete() 49 | { 50 | if ((this != NULL) && (m_bAutoDelete == true)) 51 | { 52 | delete this; 53 | return true; 54 | } 55 | return false; 56 | } 57 | 58 | //获取错误信息 59 | char const* CException::GetErrorMessage(char* szBuffer, int iBufLength) const 60 | { 61 | if (this != NULL) 62 | { 63 | //拷贝错误信息 64 | if ((szBuffer != NULL) && (iBufLength > 0)) 65 | { 66 | int iCopyLength = Min_(iBufLength - 1, strlen(m_szMessage)); 67 | szBuffer[iCopyLength] = 0; 68 | memcpy(szBuffer, m_szMessage, iCopyLength * sizeof(char)); 69 | } 70 | return m_szMessage; 71 | } 72 | return NULL; 73 | } 74 | 75 | //设置是否显示错误 76 | bool CException::ShowErrorMessage(bool bShowError) 77 | { 78 | m_bShowError = bShowError; 79 | return m_bShowError; 80 | } -------------------------------------------------------------------------------- /linuxserverplatform/src/Kernel/Makefile: -------------------------------------------------------------------------------- 1 | # Kernel的Makefile文件 2 | 3 | # 编译版本,可选debug和release 4 | # build_ver=debug 5 | 6 | ifeq ($(build_ver),release) 7 | BUILD_OPT= -g1 -O3 8 | else 9 | BUILD_OPT= -g2 -O0 10 | endif 11 | 12 | 13 | CPP = g++ 14 | CPPFLAGS = -I ../include -I ../include/ServerCommon -I ../include/curl -I ../include/DataBase -I ../include/libevent -I /usr/local/include $(BUILD_OPT) -Wall -fpic -std=c++11 15 | 16 | LDFLAGS = -L ../bin -shared 17 | LIBS = -lpthread -lcurl -lmysqlclient -levent -levent_pthreads -ljemalloc 18 | 19 | BINDIR := ../bin/ 20 | BIN := libKernel.so 21 | OBJ := jemalloc_cpp.o base64.o configManage.o DataBase.o DataLine.o Exception.o Function.o GameLogManage.o GServerConnect.o INIFile.o Lock.o log.o MysqlHelper.o ServerTimer.o sha1.o TcpConnect.o TCPSocket.o WebSocket.o Xor.o shmem.o CXObj.o UnlockQueue.o RRlockQueue.o 22 | DEP = $(OBJ:.o=.dep) 23 | 24 | $(BINDIR)$(BIN):$(OBJ) 25 | $(CPP) -o $@ $(LDFLAGS) $^ $(LIBS) 26 | 27 | %.o:%.cpp 28 | $(CPP) -c $< $(CPPFLAGS) 29 | 30 | jemalloc_cpp.o:../jemalloc/jemalloc_cpp.cpp 31 | $(CPP) -c $< $(CPPFLAGS) 32 | 33 | 34 | # 生成依赖项 35 | %.dep:%.cpp 36 | $(CPP) -MM $< $(CPPFLAGS) > $@ 37 | 38 | -include $(DEP) 39 | 40 | 41 | install: 42 | cp $(BINDIR)$(BIN) /usr/local/lib 43 | 44 | clean: 45 | rm -rf *.o *.dep 46 | 47 | -------------------------------------------------------------------------------- /linuxserverplatform/src/Kernel/Xor.cpp: -------------------------------------------------------------------------------- 1 | #include "CommonHead.h" 2 | #include "Xor.h" 3 | 4 | static unsigned char sKey[] = "LT_linux_server_2020"; 5 | 6 | uint8_t* Xor::Encrypt(uint8_t* content, int length) 7 | { 8 | for (size_t i = 0; i < length; i++) 9 | { 10 | content[i] ^= sKey[i % (sizeof(sKey) - 1)]; 11 | } 12 | return content; 13 | } 14 | 15 | uint8_t* Xor::Decrypt(uint8_t* content, int length) 16 | { 17 | for (size_t i = 0; i < length; i++) 18 | { 19 | content[i] ^= sKey[i % (sizeof(sKey)-1)]; 20 | } 21 | return content; 22 | } 23 | -------------------------------------------------------------------------------- /linuxserverplatform/src/LoaderServer/LoaderServerModule.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GameMainManage.h" 4 | 5 | //房间启动信息结构 6 | struct GameRoomInitStruct 7 | { 8 | //进程模式 9 | UINT uRunStation; //运行状态 10 | HANDLE hProcessHandle; //进程句柄 11 | 12 | //动态库 模式 13 | void* hDllInstance; //组件句柄 14 | IModuleManageService* pIManageService; //服务接口 15 | 16 | //设置信息 17 | bool bEnable; //是否启用 18 | UINT uKindID; //类型 ID 19 | UINT uSortID; //排列 ID 20 | UINT uServiceID; //组件 ID 21 | char szRoomNote[50]; //房间备注 22 | ManageInfoStruct InitInfo; //初始化信息 23 | ServerDllInfoStruct ServiceInfo; //组件信息 24 | 25 | GameRoomInitStruct() 26 | { 27 | memset(this, 0, sizeof(GameRoomInitStruct)); 28 | } 29 | }; 30 | 31 | // 房间管理模块 32 | class CLoaderServerModule 33 | { 34 | public: 35 | CLoaderServerModule(); 36 | ~CLoaderServerModule(); 37 | 38 | int StartAllRoom(int& iStartCount, int& iFailCount); 39 | void StopAllRoom(); 40 | void StartRoomByRoomID(int roomID); 41 | void StopRoomByRoomID(int roomID); 42 | void UpdateAllRoom(); 43 | void UpdateRoomByRoomID(int roomID); 44 | 45 | private: 46 | bool LoadServiceInfo(GameRoomInitStruct* pGameRoomInfo); // 获取动态库信息 47 | void MakeInitData(GameRoomInitStruct* pGameRoomInfo, int roomID); //初始化数据 48 | bool StartGameRoom(GameRoomInitStruct* pGameRoomInfo); //启动游戏房间 49 | bool StopGameRoom(GameRoomInitStruct* pGameRoomInfo); //停止游戏房间 50 | private: 51 | std::map m_allRoomInfoMap; 52 | char m_szError[255]; //错误信息 53 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/LoaderServer/Makefile: -------------------------------------------------------------------------------- 1 | # LoaderServer的Makefile文件 2 | 3 | # 编译版本,可选debug和release 4 | #build_ver=debug 5 | 6 | ifeq ($(build_ver),release) 7 | BUILD_OPT= -g1 -O3 8 | else 9 | BUILD_OPT= -g2 -O0 10 | endif 11 | 12 | 13 | CPP = g++ 14 | CPPFLAGS = -I ../include -I ../include/ServerCommon -I ../include/curl -I ../include/DataBase -I ../include/libevent -I ../include/hiredis -I ../lua -I ../protobuf -I /usr/local/include -DLUA_COMPAT_5_1 $(BUILD_OPT) -Wall -std=c++11 15 | CFLAGS = -I ../include -I ../include/ServerCommon -I ../include/curl -I ../include/DataBase -I ../include/libevent -I ../include/hiredis -I ../lua -I ../protobuf -I /usr/local/include -DLUA_COMPAT_5_1 $(BUILD_OPT) -Wall -std=c11 16 | 17 | # 设置默认加载库位置 18 | CURDIR := $(shell pwd) 19 | PARENT_CURDIR = $(shell dirname $(CURDIR)) 20 | PARENT_BIN := $(PARENT_CURDIR)/bin/ 21 | 22 | LDFLAGS = -L ../bin -Wl,-rpath=$(PARENT_BIN) 23 | LIBS = -lKernel -lCommon -lGameManage -ldl -levent -ljemalloc 24 | 25 | BINDIR := ../bin/ 26 | BIN := LoaderServer 27 | OBJ := jemalloc_cpp.o LoaderServerModule.o main.o 28 | DEP = $(OBJ:.o=.dep) 29 | 30 | $(BINDIR)$(BIN):$(OBJ) 31 | $(CPP) -o $@ $(LDFLAGS) $^ $(LIBS) 32 | 33 | %.o:%.cpp 34 | $(CPP) -c $< $(CPPFLAGS) 35 | 36 | jemalloc_cpp.o:../jemalloc/jemalloc_cpp.cpp 37 | $(CPP) -c $< $(CPPFLAGS) 38 | 39 | #%.o:../protobuf/%.cc 40 | # $(CPP) -c $< $(CPPFLAGS) 41 | 42 | #%.o:../lua/%.c 43 | # $(CPP) -c -x c $< $(CFLAGS) 44 | 45 | 46 | # 生成依赖项 47 | %.dep:%.cpp 48 | $(CPP) -MM $< $(CPPFLAGS) > $@ 49 | 50 | #%.dep:../protobuf/%.cc 51 | # $(CPP) -MM $< $(CPPFLAGS) > $@ 52 | 53 | #%.dep:../lua/%.c 54 | # $(CPP) -MM -x c $< $(CFLAGS) > $@ 55 | 56 | -include $(DEP) 57 | 58 | 59 | install: 60 | @echo "LoaderServer生成在../bin/目录中" 61 | 62 | clean: 63 | rm -rf *.o *.dep 64 | 65 | -------------------------------------------------------------------------------- /linuxserverplatform/src/LogonServer/GameLogonDataBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "DataBase.h" 4 | 5 | //数据库处理者 6 | class CServiceDataBaseHandle : public CDataBaseHandle 7 | { 8 | public: 9 | CServiceDataBaseHandle(); 10 | virtual ~CServiceDataBaseHandle(); 11 | 12 | private: 13 | virtual UINT HandleDataBase(DataBaseLineHead * pSourceData); 14 | 15 | private: 16 | // 执行sql语句 17 | int OnHandleExecuteSQLStatement(DataBaseLineHead * pSourceData); 18 | // HTTP请求 19 | int OnHandleHTTP(DataBaseLineHead * pSourceData); 20 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/LogonServer/GameLogonModule.cpp: -------------------------------------------------------------------------------- 1 | #include "CommonHead.h" 2 | #include "GameLogonModule.h" 3 | 4 | 5 | CGameLogonModule::CGameLogonModule() 6 | { 7 | 8 | } 9 | 10 | CGameLogonModule::~CGameLogonModule() 11 | { 12 | 13 | } 14 | 15 | bool CGameLogonModule::InitService(ManageInfoStruct * pInitData) 16 | { 17 | INFO_LOG("GameLogonModule InitService begin ..."); 18 | if (!pInitData) 19 | { 20 | ERROR_LOG("invalid param input"); 21 | return false; 22 | } 23 | 24 | bool ret = false; 25 | 26 | ret = m_LogonManage.Init(pInitData, &m_DataBaseHandle); 27 | if (!ret) 28 | { 29 | ERROR_LOG("LogonManage Init failed"); 30 | return false; 31 | } 32 | 33 | INFO_LOG("GameLogonModule InitService end."); 34 | 35 | return true; 36 | } 37 | 38 | bool CGameLogonModule::UnInitService() 39 | { 40 | try 41 | { 42 | return m_LogonManage.UnInit(); 43 | } 44 | catch (CException * pException) 45 | { 46 | pException->Delete(); 47 | ERROR_LOG("CATCH:%s with %s\n", __FILE__, __FUNCTION__); 48 | } 49 | catch (...) 50 | { 51 | ERROR_LOG("CATCH:%s with %s\n", __FILE__, __FUNCTION__); 52 | } 53 | 54 | return false; 55 | } 56 | 57 | bool CGameLogonModule::StartService(UINT &errCode) 58 | { 59 | INFO_LOG("GameLogonModule StartService begin..."); 60 | 61 | errCode = 0; 62 | 63 | if (!m_LogonManage.Start()) 64 | { 65 | return false; 66 | } 67 | 68 | INFO_LOG("GameLogonModule StartService end"); 69 | 70 | return true; 71 | } 72 | 73 | bool CGameLogonModule::StoptService() 74 | { 75 | INFO_LOG("GameLogonModule StoptService begin..."); 76 | 77 | bool ret = m_LogonManage.Stop(); 78 | if (!ret) 79 | { 80 | ERROR_LOG("LogonManage Stop failed"); 81 | return false; 82 | } 83 | 84 | INFO_LOG("GameLogonModule StoptService end"); 85 | 86 | return true; 87 | } 88 | 89 | bool CGameLogonModule::DeleteService() 90 | { 91 | try 92 | { 93 | delete this; 94 | } 95 | catch (...) 96 | { 97 | ERROR_LOG("CATCH:%s with %s\n", __FILE__, __FUNCTION__); 98 | } 99 | 100 | return true; 101 | } 102 | 103 | bool CGameLogonModule::UpdateService() 104 | { 105 | return true; 106 | } -------------------------------------------------------------------------------- /linuxserverplatform/src/LogonServer/GameLogonModule.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GameLogonManage.h" 4 | #include "GameLogonDataBase.h" 5 | 6 | //游戏登陆模块 7 | class CGameLogonModule : public IModuleManageService 8 | { 9 | public: 10 | CGameLogonManage m_LogonManage; //登陆管理 11 | CServiceDataBaseHandle m_DataBaseHandle; //数据库数据处理模块 12 | 13 | public: 14 | CGameLogonModule(); 15 | virtual ~CGameLogonModule(); 16 | 17 | public: 18 | virtual bool InitService(ManageInfoStruct * pInitData); 19 | virtual bool UnInitService(); 20 | virtual bool StartService(UINT &errCode); 21 | virtual bool StoptService(); 22 | virtual bool DeleteService(); 23 | virtual bool UpdateService(); 24 | }; 25 | -------------------------------------------------------------------------------- /linuxserverplatform/src/LogonServer/LogonGServerManage.cpp: -------------------------------------------------------------------------------- 1 | #include "CommonHead.h" 2 | #include "log.h" 3 | #include "LogonGServerManage.h" 4 | 5 | CLogonGServerManage::CLogonGServerManage() 6 | { 7 | } 8 | 9 | CLogonGServerManage::~CLogonGServerManage() 10 | { 11 | Release(); 12 | } 13 | 14 | LogonGServerInfo * CLogonGServerManage::GetGServer(int roomID) 15 | { 16 | auto iter = m_logonGServerInfoMap.find(roomID); 17 | if (iter != m_logonGServerInfoMap.end()) 18 | { 19 | return iter->second; 20 | } 21 | 22 | return NULL; 23 | } 24 | 25 | bool CLogonGServerManage::AddGServer(int roomID, LogonGServerInfo* pGServer) 26 | { 27 | if (roomID <= 0 || !pGServer) 28 | { 29 | return false; 30 | } 31 | 32 | if (m_logonGServerInfoMap.find(roomID) != m_logonGServerInfoMap.end()) 33 | { 34 | return false; 35 | } 36 | 37 | m_logonGServerInfoMap.insert(std::make_pair(roomID, pGServer)); 38 | 39 | return true; 40 | } 41 | 42 | void CLogonGServerManage::DelGServer(int roomID) 43 | { 44 | auto iter = m_logonGServerInfoMap.find(roomID); 45 | if (iter == m_logonGServerInfoMap.end()) 46 | { 47 | ERROR_LOG("find gserver failed roomID:%d", roomID); 48 | return; 49 | } 50 | 51 | SAFE_DELETE(iter->second); 52 | m_logonGServerInfoMap.erase(iter); 53 | } 54 | 55 | void CLogonGServerManage::Release() 56 | { 57 | for (auto iter = m_logonGServerInfoMap.begin(); iter != m_logonGServerInfoMap.end(); iter++) 58 | { 59 | SAFE_DELETE(iter->second); 60 | } 61 | 62 | m_logonGServerInfoMap.clear(); 63 | } 64 | -------------------------------------------------------------------------------- /linuxserverplatform/src/LogonServer/LogonGServerManage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | // 大厅gserver结构 5 | struct LogonGServerInfo 6 | { 7 | int roomID; 8 | int socketIdx; 9 | void* pBufferevent; 10 | 11 | LogonGServerInfo() 12 | { 13 | roomID = 0; 14 | socketIdx = -1; 15 | pBufferevent = nullptr; 16 | } 17 | }; 18 | 19 | // 大厅gserver管理器 20 | class CLogonGServerManage 21 | { 22 | public: 23 | CLogonGServerManage(); 24 | ~CLogonGServerManage(); 25 | 26 | public: 27 | LogonGServerInfo* GetGServer(int roomID); 28 | bool AddGServer(int roomID, LogonGServerInfo* pGServer); 29 | void DelGServer(int roomID); 30 | void Release(); 31 | std::unordered_map& GetLogonGServerInfoMap() { return m_logonGServerInfoMap; } 32 | UINT GetGServerCount() { return m_logonGServerInfoMap.size(); } 33 | 34 | private: 35 | std::unordered_map m_logonGServerInfoMap; 36 | }; 37 | -------------------------------------------------------------------------------- /linuxserverplatform/src/LogonServer/LogonUserManage.cpp: -------------------------------------------------------------------------------- 1 | #include "CommonHead.h" 2 | #include "log.h" 3 | #include "LogonUserManage.h" 4 | 5 | CLogonUserManage::CLogonUserManage() 6 | { 7 | m_tcpSocketCount = 0; 8 | m_webSocketCount = 0; 9 | } 10 | 11 | CLogonUserManage::~CLogonUserManage() 12 | { 13 | Release(); 14 | } 15 | 16 | LogonUserInfo * CLogonUserManage::GetUser(int userID) 17 | { 18 | auto iter = m_logonUserInfoMap.find(userID); 19 | if (iter != m_logonUserInfoMap.end()) 20 | { 21 | return iter->second; 22 | } 23 | 24 | return NULL; 25 | } 26 | 27 | bool CLogonUserManage::AddUser(int userID, LogonUserInfo * pUser) 28 | { 29 | if (userID <= 0 || !pUser) 30 | { 31 | return false; 32 | } 33 | 34 | if (m_logonUserInfoMap.find(userID) != m_logonUserInfoMap.end()) 35 | { 36 | return false; 37 | } 38 | 39 | m_logonUserInfoMap.insert(std::make_pair(userID, pUser)); 40 | 41 | if (pUser->socketType == SOCKET_TYPE_WEBSOCKET) 42 | { 43 | m_webSocketCount++; 44 | } 45 | else 46 | { 47 | m_tcpSocketCount++; 48 | } 49 | 50 | return true; 51 | } 52 | 53 | void CLogonUserManage::DelUser(int userID) 54 | { 55 | auto iter = m_logonUserInfoMap.find(userID); 56 | if (iter == m_logonUserInfoMap.end()) 57 | { 58 | ERROR_LOG("find use failed userID:%d", userID); 59 | return; 60 | } 61 | 62 | if (iter->second->socketType == SOCKET_TYPE_WEBSOCKET) 63 | { 64 | m_webSocketCount--; 65 | } 66 | else 67 | { 68 | m_tcpSocketCount--; 69 | } 70 | 71 | SAFE_DELETE(iter->second); 72 | m_logonUserInfoMap.erase(iter); 73 | } 74 | 75 | void CLogonUserManage::Release() 76 | { 77 | for (auto iter = m_logonUserInfoMap.begin(); iter != m_logonUserInfoMap.end(); iter++) 78 | { 79 | SAFE_DELETE(iter->second); 80 | } 81 | 82 | m_tcpSocketCount = 0; 83 | m_webSocketCount = 0; 84 | m_logonUserInfoMap.clear(); 85 | } 86 | 87 | void CLogonUserManage::UserChangeSocketType(int srcSocketType, int dstSocketType) 88 | { 89 | if (srcSocketType == dstSocketType) 90 | { 91 | return; 92 | } 93 | 94 | if(dstSocketType == SOCKET_TYPE_WEBSOCKET) 95 | { 96 | m_webSocketCount++; 97 | m_tcpSocketCount--; 98 | } 99 | else 100 | { 101 | m_webSocketCount--; 102 | m_tcpSocketCount++; 103 | } 104 | } -------------------------------------------------------------------------------- /linuxserverplatform/src/LogonServer/LogonUserManage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | // 大厅玩家结构 5 | struct LogonUserInfo 6 | { 7 | int userID; 8 | int socketIdx; 9 | BYTE isVirtual; 10 | int roomID; 11 | void* pBufferevent; 12 | time_t logonTime; 13 | BYTE socketType; 14 | 15 | LogonUserInfo() 16 | { 17 | userID = 0; 18 | socketIdx = -1; 19 | isVirtual = 0; 20 | roomID = 0; 21 | pBufferevent = nullptr; 22 | logonTime = 0; 23 | socketType = SOCKET_TYPE_TCP; 24 | } 25 | }; 26 | 27 | // 大厅玩家管理器 28 | class CLogonUserManage 29 | { 30 | public: 31 | CLogonUserManage(); 32 | ~CLogonUserManage(); 33 | 34 | public: 35 | LogonUserInfo* GetUser(int userID); 36 | 37 | // AddUser之前需要把socket类型传进来 38 | bool AddUser(int userID, LogonUserInfo* pUser); 39 | void DelUser(int userID); 40 | void Release(); 41 | std::unordered_map& GetLogonUserInfoMap() { return m_logonUserInfoMap; } 42 | UINT GetUserCount() { return m_logonUserInfoMap.size(); } 43 | UINT GetTcpSocketUserCount() { return m_tcpSocketCount; } 44 | UINT GetWebSocketUserCount() { return m_webSocketCount; } 45 | void UserChangeSocketType(int srcSocketType, int dstSocketType); 46 | 47 | private: 48 | std::unordered_map m_logonUserInfoMap; // 大厅玩家管理器中只保存在线的玩家 49 | UINT m_tcpSocketCount; 50 | UINT m_webSocketCount; 51 | }; 52 | -------------------------------------------------------------------------------- /linuxserverplatform/src/LogonServer/Makefile: -------------------------------------------------------------------------------- 1 | # LogonServer的Makefile文件 2 | 3 | # 编译版本,可选debug和release 4 | #build_ver=debug 5 | 6 | ifeq ($(build_ver),release) 7 | BUILD_OPT= -g1 -O3 8 | else 9 | BUILD_OPT= -g2 -O0 10 | endif 11 | 12 | 13 | CPP = g++ 14 | CPPFLAGS = -I ../include -I ../include/ServerCommon -I ../include/curl -I ../include/DataBase -I ../include/libevent -I ../include/hiredis -I ../lua -I ../protobuf -I /usr/local/include -DLUA_COMPAT_5_1 $(BUILD_OPT) -Wall -std=c++11 15 | CFLAGS = -I ../include -I ../include/ServerCommon -I ../include/curl -I ../include/DataBase -I ../include/libevent -I ../include/hiredis -I ../lua -I ../protobuf -I /usr/local/include -DLUA_COMPAT_5_1 $(BUILD_OPT) -Wall -std=c11 16 | 17 | # 设置默认加载库位置 18 | CURDIR := $(shell pwd) 19 | PARENT_CURDIR = $(shell dirname $(CURDIR)) 20 | PARENT_BIN := $(PARENT_CURDIR)/bin/ 21 | 22 | LDFLAGS = -L ../bin -Wl,-rpath=$(PARENT_BIN) 23 | LIBS = -lpthread -lKernel -lCommon -levent -ljson -lcurl -lprotobuf -ljemalloc 24 | 25 | BINDIR := ../bin/ 26 | BIN := LogonServer 27 | OBJ := jemalloc_cpp.o BaseLogonServer.o GameLogonDataBase.o GameLogonManage.o GameLogonModule.o LogonGServerManage.o LogonUserManage.o main.o 28 | DEP = $(OBJ:.o=.dep) 29 | 30 | $(BINDIR)$(BIN):$(OBJ) 31 | $(CPP) -o $@ $(LDFLAGS) $^ $(LIBS) 32 | 33 | %.o:%.cpp 34 | $(CPP) -c $< $(CPPFLAGS) 35 | 36 | jemalloc_cpp.o:../jemalloc/jemalloc_cpp.cpp 37 | $(CPP) -c $< $(CPPFLAGS) 38 | 39 | #%.o:../protobuf/%.cc 40 | # $(CPP) -c $< $(CPPFLAGS) 41 | 42 | #%.o:../lua/%.c 43 | # $(CPP) -c -x c $< $(CFLAGS) 44 | 45 | 46 | # 生成依赖项 47 | %.dep:%.cpp 48 | $(CPP) -MM $< $(CPPFLAGS) > $@ 49 | 50 | #%.dep:../protobuf/%.cc 51 | # $(CPP) -MM $< $(CPPFLAGS) > $@ 52 | 53 | #%.dep:../lua/%.c 54 | # $(CPP) -MM -x c $< $(CFLAGS) > $@ 55 | 56 | -include $(DEP) 57 | 58 | 59 | install: 60 | @echo "LogonServer生成在../bin/目录中" 61 | 62 | clean: 63 | rm -rf *.o *.dep 64 | 65 | -------------------------------------------------------------------------------- /linuxserverplatform/src/Makefile: -------------------------------------------------------------------------------- 1 | # Top level makefile 2 | 3 | build_ver=debug 4 | export build_ver 5 | 6 | default: all 7 | 8 | .DEFAULT: 9 | cd Kernel && $(MAKE) 10 | cd Common && $(MAKE) 11 | cd CenterServer && $(MAKE) 12 | cd LogonServer && $(MAKE) 13 | cd WorkServer && $(MAKE) 14 | cd GameManage && $(MAKE) 15 | cd LoaderServer && $(MAKE) 16 | cd httpserver && cmake ./ && $(MAKE) 17 | cd games && $(MAKE) 18 | cd test && $(MAKE) 19 | 20 | install: 21 | cd Kernel && $(MAKE) $@ 22 | cd Common && $(MAKE) $@ 23 | cd CenterServer && $(MAKE) $@ 24 | cd LogonServer && $(MAKE) $@ 25 | cd WorkServer && $(MAKE) $@ 26 | cd GameManage && $(MAKE) $@ 27 | cd LoaderServer && $(MAKE) $@ 28 | cd games && $(MAKE) $@ 29 | 30 | clean: 31 | cd Kernel && $(MAKE) $@ 32 | cd Common && $(MAKE) $@ 33 | cd CenterServer && $(MAKE) $@ 34 | cd LogonServer && $(MAKE) $@ 35 | cd WorkServer && $(MAKE) $@ 36 | cd GameManage && $(MAKE) $@ 37 | cd LoaderServer && $(MAKE) $@ 38 | cd httpserver && $(MAKE) $@ 39 | cd games && $(MAKE) $@ 40 | cd test && $(MAKE) $@ 41 | 42 | .PHONY: install 43 | -------------------------------------------------------------------------------- /linuxserverplatform/src/WorkServer/GameWorkDataBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "DataBase.h" 4 | 5 | //数据库处理者 6 | class CServiceDataBaseHandle : public CDataBaseHandle 7 | { 8 | public: 9 | CServiceDataBaseHandle(); 10 | virtual ~CServiceDataBaseHandle(); 11 | 12 | private: 13 | virtual UINT HandleDataBase(DataBaseLineHead * pSourceData); 14 | 15 | private: 16 | // 执行sql语句 17 | int OnHandleExecuteSQLStatement(DataBaseLineHead * pSourceData); 18 | // HTTP请求 19 | int OnHandleHTTP(DataBaseLineHead * pSourceData); 20 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/WorkServer/GameWorkModule.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | class CGameWorkManage; 5 | class CServiceDataBaseHandle; 6 | 7 | //逻辑服务器模块,单例模式 8 | class CGameWorkModule : public IModuleManageService 9 | { 10 | public: 11 | CGameWorkManage* m_pWorkManage; //登陆管理 12 | CServiceDataBaseHandle* m_pDataBaseHandle; //数据库数据处理模块 13 | static CGameWorkModule* g_pGameWorkModule; //全局唯一指针 14 | 15 | private: 16 | CGameWorkModule(); 17 | public: 18 | static CGameWorkModule* Instance(); 19 | virtual ~CGameWorkModule(); 20 | 21 | public: 22 | virtual bool InitService(ManageInfoStruct * pInitData); 23 | virtual bool UnInitService(); 24 | virtual bool StartService(UINT &errCode); 25 | virtual bool StoptService(); 26 | virtual bool DeleteService(); 27 | virtual bool UpdateService(); 28 | }; 29 | 30 | #define WorkServerModule() CGameWorkModule::Instance() 31 | #define WorkManageModule() CGameWorkModule::Instance()->m_pWorkManage -------------------------------------------------------------------------------- /linuxserverplatform/src/WorkServer/Makefile: -------------------------------------------------------------------------------- 1 | # WorkServer的Makefile文件 2 | 3 | # 编译版本,可选debug和release 4 | #build_ver=debug 5 | 6 | ifeq ($(build_ver),release) 7 | BUILD_OPT= -g1 -O3 8 | else 9 | BUILD_OPT= -g2 -O0 10 | endif 11 | 12 | CPP = g++ 13 | CPPFLAGS = -I ../include -I ../include/ServerCommon -I ../include/curl -I ../include/DataBase -I ../include/libevent -I ../include/hiredis -I ../lua -I ../protobuf -I /usr/local/include -DLUA_COMPAT_5_1 $(BUILD_OPT) -Wall -std=c++11 14 | CFLAGS = -I ../include -I ../include/ServerCommon -I ../include/curl -I ../include/DataBase -I ../include/libevent -I ../include/hiredis -I ../lua -I ../protobuf -I /usr/local/include -DLUA_COMPAT_5_1 $(BUILD_OPT) -Wall -std=c11 15 | 16 | # 设置默认加载库位置 17 | CURDIR := $(shell pwd) 18 | PARENT_CURDIR = $(shell dirname $(CURDIR)) 19 | PARENT_BIN := $(PARENT_CURDIR)/bin/ 20 | 21 | LDFLAGS = -L ../bin -Wl,-rpath=$(PARENT_BIN) 22 | LIBS = -lpthread -lKernel -lCommon -levent -ljson -lcurl -lprotobuf -ljemalloc -llua -ldl -lhiredis 23 | 24 | BINDIR := ../bin/ 25 | BIN := WorkServer 26 | OBJ := jemalloc_cpp.o BaseWorkServer.o GameWorkDataBase.o GameWorkManage.o GameWorkModule.o main.o 27 | DEP = $(OBJ:.o=.dep) 28 | 29 | $(BINDIR)$(BIN):$(OBJ) 30 | $(CPP) -o $@ $(LDFLAGS) $^ $(LIBS) 31 | 32 | %.o:%.cpp 33 | $(CPP) -c $< $(CPPFLAGS) 34 | 35 | jemalloc_cpp.o:../jemalloc/jemalloc_cpp.cpp 36 | $(CPP) -c $< $(CPPFLAGS) 37 | 38 | #%.o:../protobuf/%.cc 39 | # $(CPP) -c $< $(CPPFLAGS) 40 | 41 | #%.o:../lua/%.c 42 | # $(CPP) -c -x c $< $(CFLAGS) 43 | 44 | 45 | # 生成依赖项 46 | %.dep:%.cpp 47 | $(CPP) -MM $< $(CPPFLAGS) > $@ 48 | 49 | #%.dep:../protobuf/%.cc 50 | # $(CPP) -MM $< $(CPPFLAGS) > $@ 51 | 52 | #%.dep:../lua/%.c 53 | # $(CPP) -MM -x c $< $(CFLAGS) > $@ 54 | 55 | -include $(DEP) 56 | 57 | 58 | install: 59 | @echo "WorkServer生成在../bin/目录中" 60 | 61 | clean: 62 | rm -rf *.o *.dep 63 | 64 | -------------------------------------------------------------------------------- /linuxserverplatform/src/bin/config.ini: -------------------------------------------------------------------------------- 1 | [COMMON_DB] 2 | ip=localhost 3 | user=root 4 | dbName=newframe 5 | passwd=root 6 | port=3306 7 | 8 | [LOG_DB] 9 | ip=localhost 10 | user=root 11 | dbName=newframe 12 | passwd=root 13 | port=3306 14 | 15 | [PHP_DB] 16 | ip=localhost 17 | user=root 18 | dbName=newframe 19 | passwd=root 20 | port=3306 21 | 22 | [CENTERSERVER] 23 | ip=127.0.0.1 24 | port=4015 25 | maxSocketCount=300 26 | 27 | [LOGONSERVER] 28 | logonID=1 29 | webSocket=0 30 | 31 | [LOADERSERVER] 32 | serviceName=hm 33 | logonserverPasswd=e10adc3949ba59abbe56e057f20f883e 34 | 35 | [WORKSERVER] 36 | workID=1 37 | 38 | [COMMON] 39 | logPath=./log/ 40 | WorkThreadNumber=2 41 | TimerThreadNumber=1 42 | recvThreadNumber=2 43 | -------------------------------------------------------------------------------- /linuxserverplatform/src/bin/install_myself_lib.sh: -------------------------------------------------------------------------------- 1 | cp ./libCommon.so /usr/local/lib/ 2 | cp ./libGameManage.so /usr/local/lib/ 3 | cp ./libKernel.so /usr/local/lib/ 4 | 5 | echo "copy success !!!" 6 | -------------------------------------------------------------------------------- /linuxserverplatform/src/bin/restart.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | bash ./stop.sh 3 | sleep 2 4 | bash ./start.sh 5 | 6 | -------------------------------------------------------------------------------- /linuxserverplatform/src/bin/robotPosition.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luotan-123/libevent-server/98652b1b5150402ae771ca0393b2ca7fadb11b8d/linuxserverplatform/src/bin/robotPosition.txt -------------------------------------------------------------------------------- /linuxserverplatform/src/bin/startcserver.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | program="CenterServer" 5 | ./$program & 6 | 7 | -------------------------------------------------------------------------------- /linuxserverplatform/src/bin/startgserver.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | program="LoaderServer" 5 | ./$program & 6 | 7 | -------------------------------------------------------------------------------- /linuxserverplatform/src/bin/startlserver.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | program="LogonServer" 5 | 6 | ./$program & 7 | -------------------------------------------------------------------------------- /linuxserverplatform/src/bin/startwserver.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | program="WorkServer" 5 | 6 | ./$program & 7 | 8 | -------------------------------------------------------------------------------- /linuxserverplatform/src/bin/stopall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | bash ./stopcserver.sh 3 | sleep 1 4 | bash ./stoplserver.sh 5 | sleep 1 6 | bash ./stopgserver.sh 7 | 8 | -------------------------------------------------------------------------------- /linuxserverplatform/src/bin/stopcserver.sh: -------------------------------------------------------------------------------- 1 | 2 | #!/bin/bash 3 | 4 | program="CenterServer" 5 | 6 | ps -ef | grep $program | cut -c 9-15 | xargs kill -9 7 | 8 | eStr=${program}" is stop!!!" 9 | 10 | echo $eStr 11 | 12 | -------------------------------------------------------------------------------- /linuxserverplatform/src/bin/stopgserver.sh: -------------------------------------------------------------------------------- 1 | 2 | #!/bin/bash 3 | 4 | program="LoaderServer" 5 | 6 | ps -ef | grep $program | cut -c 9-15 | xargs kill -9 7 | 8 | eStr=${program}" is stop!!!" 9 | 10 | echo $eStr 11 | 12 | -------------------------------------------------------------------------------- /linuxserverplatform/src/bin/stoplserver.sh: -------------------------------------------------------------------------------- 1 | 2 | #!/bin/bash 3 | 4 | program="LogonServer" 5 | 6 | ps -ef | grep $program | cut -c 9-15 | xargs kill -9 7 | 8 | eStr=${program}" is stop!!!" 9 | 10 | echo $eStr 11 | 12 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/12101105_ZJH/12101105_s.ini: -------------------------------------------------------------------------------- 1 | ;=================总配置==================== 2 | ;游戏基础配置 3 | [game] 4 | ;开始等待时间 5 | begintime=30 6 | ;思考时间 7 | thinktime=20 8 | ;底注 9 | DiZhu=1 10 | 11 | ;是否有癞子 12 | LaiZi=1 13 | ;235杀豹子 14 | BaoZi235=1 15 | ;豹子有喜 16 | BaoZiHaveXi=0 17 | ;总轮数 18 | iAllTurnCount=15 19 | ;比牌加倍 20 | CompareCardAdd=0 21 | ;焖牌 0 不焖,1 焖一轮,2 焖2轮 ,3 焖3轮 22 | MenPai=0 23 | ;特殊牌型比较 1 顺子>同花 ;2 顺子<同花 24 | TeSuPaiXing=2 25 | ;1经典模式,2疯狂模式 26 | gameIdx=1 27 | ;托管时间 28 | iGameAutoPlayTime=30 -------------------------------------------------------------------------------- /linuxserverplatform/src/games/12101105_ZJH/Makefile: -------------------------------------------------------------------------------- 1 | # 12101105_ZJH的Makefile文件 2 | 3 | # 编译版本,可选debug和release 4 | # build_ver=debug 5 | 6 | ifeq ($(build_ver),release) 7 | BUILD_OPT= -g1 -O3 8 | else 9 | BUILD_OPT= -g2 -O0 10 | endif 11 | 12 | 13 | CPP = g++ 14 | CPPFLAGS = -I ../../include -I ../../include/ServerCommon -I ../../include/curl -I ../../include/DataBase -I ../../include/libevent -I ../../include/hiredis -I ../../protobuf -I /usr/local/include $(BUILD_OPT) -Wall -fpic -std=c++11 15 | 16 | LDFLAGS = -L ../../bin -shared 17 | LIBS = -lKernel -lCommon -lGameManage -ljson -lprotobuf -ljemalloc 18 | 19 | BINDIR := ../../bin/ 20 | BIN := 12101105.so 21 | OBJ := ServerManage.o UpGradeDLL.o UpGradeLogic.o 22 | DEP = $(OBJ:.o=.dep) 23 | 24 | $(BINDIR)$(BIN):$(OBJ) 25 | $(CPP) -o $@ $(LDFLAGS) $^ $(LIBS) 26 | 27 | %.o:%.cpp 28 | $(CPP) -c $< $(CPPFLAGS) 29 | 30 | #%.o:../protobuf/%.cc 31 | # $(CPP) -c $< $(CPPFLAGS) 32 | 33 | 34 | # 生成依赖项 35 | %.dep:%.cpp 36 | $(CPP) -MM $< $(CPPFLAGS) > $@ 37 | 38 | -include $(DEP) 39 | 40 | 41 | install: 42 | cp 12101105_s.ini ../../bin/ 43 | @echo "12101105_ZJH生成在../../bin/目录中" 44 | 45 | clean: 46 | rm -rf *.o *.dep 47 | 48 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/12101105_ZJH/UpGradeDLL.cpp: -------------------------------------------------------------------------------- 1 | // UpGradeDLL.cpp : 定义 DLL 的初始化例程。 2 | // 3 | 4 | #include "ServerManage.h" 5 | 6 | 7 | //获取游戏组件信息 8 | extern "C" BOOL GetServiceInfo(ServerDllInfoStruct * pServiceInfo, UINT uVer) 9 | { 10 | //效验信息 11 | if ((uVer!=DEV_LIB_VER)||(pServiceInfo==NULL)) return FALSE; 12 | 13 | //写入信息 14 | memset(pServiceInfo,0,sizeof(ServerDllInfoStruct)); 15 | pServiceInfo->uServiceVer=GAME_MAX_VER; 16 | pServiceInfo->uNameID=NAME_ID; 17 | pServiceInfo->uDeskPeople=PLAY_COUNT; 18 | pServiceInfo->uSupportType=SUPPER_TYPE; 19 | strcpy(pServiceInfo->szGameName,GAMENAME); 20 | strcpy(pServiceInfo->szDllNote,"牌类 -- 景德镇两副头游戏组件"); 21 | return TRUE; 22 | } 23 | 24 | //获取游戏管理接口函数 25 | extern "C" IModuleManageService * CreateServiceInterface(UINT uVer) 26 | { 27 | if (uVer==DEV_LIB_VER) 28 | { 29 | try { return new CGameModuleTemplate; } 30 | catch (...) {} 31 | } 32 | return NULL; 33 | } 34 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/23510004_SXTDH/23510004_s.ini: -------------------------------------------------------------------------------- 1 | ;游戏基础配置 2 | [game] 3 | ;游戏底分 4 | iGameBase=1 5 | ;大胡还是平胡 6 | bDaHu=1 7 | ;是否报听 8 | bBaoTing=1 9 | ;是否只自摸 10 | bZhiZiMo=0 11 | ;是否带风牌 12 | bFenPai=0 13 | ;拦牌思考时间 14 | BlockTime=15 15 | ;出牌时间 16 | OutTime=15 17 | ;自动出牌时间 18 | AutoOutTime=1 19 | 20 | 21 | ;根据房间读取配置 22 | [23510004_88] 23 | ;游戏底分 24 | iGameBase=1 25 | ;大胡还是平胡 26 | bDaHu=1 27 | ;是否报听 28 | bBaoTing=0 29 | ;是否只自摸 30 | bZhiZiMo=0 31 | ;是否带风牌 32 | bFenPai=0 -------------------------------------------------------------------------------- /linuxserverplatform/src/games/23510004_SXTDH/CheckCPGAction.h: -------------------------------------------------------------------------------- 1 | #ifndef CHECKCPGACTION_H 2 | #define CHECKCPGACTION_H 3 | #include "GameDataEx.h" 4 | 5 | ///吃碰杠检测类 6 | class CheckCPGAction 7 | { 8 | public: 9 | CheckCPGAction(void); 10 | ~CheckCPGAction(void); 11 | public: 12 | ///初始化数据 13 | virtual void InitData(); 14 | 15 | ///能否吃牌 16 | virtual bool CanChi(GameDataEx *pGameData, BYTE station, BYTE pai, BYTE Result[][3], bool bChi[3]); 17 | 18 | ///能否碰牌 19 | virtual bool CanPeng(GameDataEx *pGameData, BYTE station, BYTE pai); 20 | 21 | //能否坎牌 22 | virtual bool CanKan(GameDataEx *pGameData, BYTE station, BYTE kan[]); 23 | 24 | ///能否杠牌 25 | virtual bool CanGang(GameDataEx *pGameData, BYTE station, BYTE pai, BYTE Result[][2], bool bMe = false); 26 | }; 27 | #endif -------------------------------------------------------------------------------- /linuxserverplatform/src/games/23510004_SXTDH/CheckCPGActionEx.h: -------------------------------------------------------------------------------- 1 | #ifndef CHECKCPGACTIONEX_H 2 | #define CHECKCPGACTIONEX_H 3 | #include "CheckCPGAction.h" 4 | #include "CheckHuPaiEx.h" 5 | ///吃碰杠检测类(重载) 6 | class CheckCPGActionEx :public CheckCPGAction 7 | { 8 | public: 9 | CheckCPGActionEx(void); 10 | ~CheckCPGActionEx(void); 11 | public: 12 | ///初始化数据 13 | virtual void InitData(); 14 | 15 | ///能否碰牌 16 | virtual bool CanPeng(GameDataEx *pGameData, BYTE station, BYTE pai); 17 | 18 | ///能否杠牌 19 | bool CanGang(GameDataEx *pGameData, BYTE station, BYTE pai, BYTE Result[][2], bool bMe = false, CheckHuPaiEx *pCheckHuData = NULL); 20 | 21 | //杠牌算分 22 | virtual void CountGangFen(GameDataEx *pGameData, int iStation, int iBeStation, BYTE byType); 23 | 24 | //计算杠分 25 | void CountGangFenEx(GameDataEx *pGameData); 26 | 27 | //减去抢杠胡所得杠分,减补杠分 28 | void MinusGangFen(GameDataEx *pGameData, int iStation, int iBeStation); 29 | }; 30 | #endif -------------------------------------------------------------------------------- /linuxserverplatform/src/games/23510004_SXTDH/CheckHuPaiEx.h: -------------------------------------------------------------------------------- 1 | #ifndef CHECKHUPAIEX_H 2 | #define CHECKHUPAIEX_H 3 | #include "CheckHuPai.h" 4 | ///事件处理类(重载) 5 | class CheckHuPaiEx :public CheckHuPai 6 | { 7 | public: 8 | int m_byTingMaxFan;//听牌可能的最大番 9 | int m_iHuFenType[PLAY_COUNT][MAX_HU_FEN_KIND]; 10 | public: 11 | CheckHuPaiEx(void); 12 | ~CheckHuPaiEx(void); 13 | //初始化数据 14 | virtual void InitData(); 15 | 16 | /////////检测是否能胡牌//////// 17 | virtual bool CanHu(GameDataEx *pGameData, BYTE station, BYTE byBeStation, BYTE lastpai, bool zimo); 18 | 19 | ///////////////麻将算分////////////////// 20 | void CountHuFen(GameDataEx *pGameData); 21 | 22 | //根据胡牌类型,获取胡牌倍数 23 | int GetHuTypeFans(GameDataEx *pGameData, BYTE m_byHuType[MAX_HUPAI_TYPE]); 24 | 25 | //检测能否听牌 26 | virtual bool CanTing(GameDataEx *pGameData, BYTE station, BYTE CanOut[]); 27 | 28 | //获取一张可听的牌 29 | BYTE GetCanTingCard(GameDataEx *pGameData, BYTE station); 30 | 31 | //提取糊牌 32 | virtual void ExtractHu(GameDataEx *pGameData, BYTE station, BYTE byHuCard[]); 33 | 34 | //从手牌中出一张牌,然后提取能糊的牌 35 | bool OutCardExtractHu(GameDataEx *pGameData, BYTE station, BYTE byOutCanHuCard[HAND_CARD_NUM], 36 | BYTE byHuCard[HAND_CARD_NUM][MAX_CANHU_CARD_NUM], BYTE byCardRemainNum[MAX_MJ_PAI]); 37 | 38 | //将将胡 39 | bool CheckAllJiang(GameDataEx *pGameData); 40 | 41 | ///计算七对中四张牌的数量 42 | int CountLongQi(); 43 | 44 | ///计算七对中四张牌的数量 45 | bool CheckHuGen(BYTE lastpai); 46 | 47 | //检测是否幺九七对 48 | bool CheckYaoJiuQiDui(GameDataEx *pGameData); 49 | 50 | //新七对检测 51 | bool CheckQiDuiEx(GameDataEx *pGameData); 52 | 53 | //检测两幅手牌的胡牌是否改变 54 | bool IsTingKouChange(GameDataEx *pGameData, BYTE station, BYTE byChangeCard[HAND_CARD_NUM]); 55 | }; 56 | #endif -------------------------------------------------------------------------------- /linuxserverplatform/src/games/23510004_SXTDH/Makefile: -------------------------------------------------------------------------------- 1 | # 23510004_SXTDH的Makefile文件 2 | 3 | # 编译版本,可选debug和release 4 | # build_ver=debug 5 | 6 | ifeq ($(build_ver),release) 7 | BUILD_OPT= -g1 -O3 8 | else 9 | BUILD_OPT= -g2 -O0 10 | endif 11 | 12 | 13 | CPP = g++ 14 | CPPFLAGS = -I ../../include -I ../../include/ServerCommon -I ../../include/curl -I ../../include/DataBase -I ../../include/libevent -I ../../include/hiredis -I ../../protobuf -I /usr/local/include $(BUILD_OPT) -Wall -fpic -std=c++11 15 | 16 | LDFLAGS = -L ../../bin -shared 17 | LIBS = -lKernel -lCommon -lGameManage -ljson -lprotobuf -ljemalloc 18 | 19 | BINDIR := ../../bin/ 20 | BIN := 23510004.so 21 | OBJ := CheckCPGAction.o CheckCPGActionEx.o CheckHuPai.o CheckHuPaiEx.o GameData.o GameDataEx.o ServerManage.o SHSrvDLL.o 22 | DEP = $(OBJ:.o=.dep) 23 | 24 | $(BINDIR)$(BIN):$(OBJ) 25 | $(CPP) -o $@ $(LDFLAGS) $^ $(LIBS) 26 | 27 | %.o:%.cpp 28 | $(CPP) -c $< $(CPPFLAGS) 29 | 30 | #%.o:../protobuf/%.cc 31 | # $(CPP) -c $< $(CPPFLAGS) 32 | 33 | 34 | # 生成依赖项 35 | %.dep:%.cpp 36 | $(CPP) -MM $< $(CPPFLAGS) > $@ 37 | 38 | -include $(DEP) 39 | 40 | 41 | install: 42 | cp 23510004_s.ini ../../bin/ 43 | @echo "23510004_SXTDH生成在../../bin/目录中" 44 | 45 | clean: 46 | rm -rf *.o *.dep 47 | 48 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/23510004_SXTDH/SHSrvDLL.cpp: -------------------------------------------------------------------------------- 1 | // UpGradeDLL.cpp : 定义 DLL 的初始化例程。 2 | // 3 | 4 | #include "ServerManage.h" 5 | 6 | //获取游戏组件信息 7 | extern "C" BOOL GetServiceInfo(ServerDllInfoStruct * pServiceInfo, UINT uVer) 8 | { 9 | //效验信息 10 | if ((uVer!=DEV_LIB_VER)||(pServiceInfo==NULL)) return FALSE; 11 | 12 | //写入信息 13 | memset(pServiceInfo,0,sizeof(ServerDllInfoStruct)); 14 | pServiceInfo->uServiceVer=GAME_MAX_VER; 15 | pServiceInfo->uNameID=NAME_ID; 16 | pServiceInfo->uDeskPeople=PLAY_COUNT; 17 | pServiceInfo->uSupportType=SUPPER_TYPE; 18 | strcpy(pServiceInfo->szGameName,GAMENAME); 19 | strcpy(pServiceInfo->szWriter,""); 20 | strcpy(pServiceInfo->szDllNote,"麻将类-山西推倒胡"); 21 | 22 | return TRUE; 23 | } 24 | 25 | //获取游戏管理接口函数 26 | extern "C" IModuleManageService * CreateServiceInterface(UINT uVer) 27 | { 28 | if (uVer==DEV_LIB_VER) 29 | { 30 | try { return new CGameModuleTemplate; } 31 | catch (...) {} 32 | } 33 | return NULL; 34 | } 35 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/30100008_NN/30100008_s.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luotan-123/libevent-server/98652b1b5150402ae771ca0393b2ca7fadb11b8d/linuxserverplatform/src/games/30100008_NN/30100008_s.ini -------------------------------------------------------------------------------- /linuxserverplatform/src/games/30100008_NN/Makefile: -------------------------------------------------------------------------------- 1 | # 30100008_NN的Makefile文件 2 | 3 | # 编译版本,可选debug和release 4 | # build_ver=debug 5 | 6 | ifeq ($(build_ver),release) 7 | BUILD_OPT= -g1 -O3 8 | else 9 | BUILD_OPT= -g2 -O0 10 | endif 11 | 12 | 13 | CPP = g++ 14 | CPPFLAGS = -I ../../include -I ../../include/ServerCommon -I ../../include/curl -I ../../include/DataBase -I ../../include/libevent -I ../../include/hiredis -I ../../protobuf -I /usr/local/include $(BUILD_OPT) -Wall -fpic -std=c++11 15 | 16 | LDFLAGS = -L ../../bin -shared 17 | LIBS = -lKernel -lCommon -lGameManage -ljson -lprotobuf -ljemalloc 18 | 19 | BINDIR := ../../bin/ 20 | BIN := 30100008.so 21 | OBJ := ServerManage.o UpGradeDLL.o UpGradeLogic.o 22 | DEP = $(OBJ:.o=.dep) 23 | 24 | $(BINDIR)$(BIN):$(OBJ) 25 | $(CPP) -o $@ $(LDFLAGS) $^ $(LIBS) 26 | 27 | %.o:%.cpp 28 | $(CPP) -c $< $(CPPFLAGS) 29 | 30 | #%.o:../protobuf/%.cc 31 | # $(CPP) -c $< $(CPPFLAGS) 32 | 33 | 34 | # 生成依赖项 35 | %.dep:%.cpp 36 | $(CPP) -MM $< $(CPPFLAGS) > $@ 37 | 38 | -include $(DEP) 39 | 40 | 41 | install: 42 | cp 30100008_s.ini ../../bin/ 43 | @echo "30100008_NN生成在../../bin/目录中" 44 | 45 | clean: 46 | rm -rf *.o *.dep 47 | 48 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/30100008_NN/UpGradeDLL.cpp: -------------------------------------------------------------------------------- 1 | // UpGradeDLL.cpp : 定义 DLL 的初始化例程。 2 | // 3 | 4 | #include "ServerManage.h" 5 | 6 | //获取游戏组件信息 7 | extern "C" int GetServiceInfo(ServerDllInfoStruct * pServiceInfo, UINT uVer) 8 | { 9 | //效验信息 10 | if ((uVer!=DEV_LIB_VER)||(pServiceInfo==NULL)) return false; 11 | 12 | //写入信息 13 | memset(pServiceInfo,0,sizeof(ServerDllInfoStruct)); 14 | pServiceInfo->uServiceVer=GAME_MAX_VER; 15 | pServiceInfo->uNameID=NAME_ID; 16 | pServiceInfo->uDeskPeople=PLAY_COUNT; 17 | pServiceInfo->uSupportType=SUPPER_TYPE; 18 | strcpy(pServiceInfo->szGameName,GAMENAME); 19 | ///lstrcpy(pServiceInfo->szGameTable,GAME_TABLE_NAME); 20 | ///lstrcpy(pServiceInfo->szDLLFileName,SERVER_DLL_NAME); 21 | strcpy(pServiceInfo->szDllNote,"牌类 -- 斗地主游戏组件"); 22 | return true; 23 | } 24 | 25 | //获取游戏管理接口函数 26 | extern "C" IModuleManageService * CreateServiceInterface(UINT uVer) 27 | { 28 | if (uVer==DEV_LIB_VER) 29 | { 30 | try { return new CGameModuleTemplate; } 31 | catch (...) {} 32 | } 33 | return NULL; 34 | } 35 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/36610103_DDZ/36610103_s.ini: -------------------------------------------------------------------------------- 1 | ;游戏基础配置 2 | [game] 3 | ;游戏顺序(1:逆时针 0:顺时针) 4 | TurnRule=1 5 | ;是否抢地主(1:游戏必须抢地主 0:由游戏决定地主) 6 | robnt=0 7 | ;是否可以加倍 8 | adddouble=1 9 | ;是否有明牌环节 10 | showcard=0 11 | ;游戏基础倍数(基础倍数必须>=1) 12 | BaseMutiple=1 13 | ;加倍限制(配置0为不限制) 14 | AddDoubleLimit=0 15 | ;房间最大输赢(配置0为不限制) 16 | GameMaxLimit=0 17 | ;游戏最大倍数(配置0为不限制) 18 | LimitPoint=0 19 | ;到达时间不出牌,是否托管 20 | TimeOutNoCardOut=1 21 | ;1:叫分模式,0:抢地主模式 22 | Model=1 23 | 24 | ;游戏时间配置 25 | [other] 26 | ;开始等待时间 27 | begintime=15 28 | ;思考时间 29 | thinktime=60 30 | ;抢地主时间 31 | RobNTTime=10 32 | ;叫分时间 33 | CallScoretime=15 34 | ;加棒时间 35 | adddoubletime=5 36 | 37 | [36610103_41] 38 | ;是否不洗牌 39 | XiPai=1 40 | [36610103_43] 41 | ;是否不洗牌 42 | XiPai=1 -------------------------------------------------------------------------------- /linuxserverplatform/src/games/36610103_DDZ/GameTaskLogic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "UpGradeLogic.h" 4 | 5 | 6 | class CGameTaskLogic :public CUpGradeGameLogic 7 | { 8 | public: 9 | CGameTaskLogic(void); 10 | public: 11 | ~CGameTaskLogic(void); 12 | 13 | private: 14 | 15 | BYTE m_byLastCardList[20] ; ///最后一手牌的列表 16 | BYTE m_byLastCardCount ; ///最后一手牌的数量 17 | 18 | BYTE m_byBackCardType ; ///底牌牌型 19 | 20 | BYTE m_byTaskType ; ///需随机产生 21 | BYTE m_bySpecifyShape ; ///指定的牌型 22 | BYTE m_bySpecifyCard ; ///指定的牌 23 | 24 | public: 25 | ///初始任务变量 26 | void InitGameTask(void) ; 27 | ///获取底牌牌型 28 | bool GetBackCardType(BYTE bbackCardList[] , int cbCardCount) ; 29 | ///底牌是否为顺子 30 | bool IsBackCardStraight(BYTE iCardList[],int iCardCount) ; 31 | // 获取指定牌面值牌的数量 32 | int GetCardNumCount(BYTE iCardList[], int iCardCount, BYTE bCardNum) ; 33 | ///获取随机任务 34 | void GetRandTask(int inDex) ; ///获取随机任务 35 | /// 设置任务变量 36 | void SetGameTask(GameTaskStruct &gameTask) ; 37 | ///设置最后一手牌的数据 38 | void SetLastCardData(BYTE iCardList[], BYTE iCardCount) ; 39 | ///判断是否完成任务了 40 | bool IsFinishTask(void) ; 41 | ///获取任务倍数 42 | int GetTaskMutiple(bool bFinish ) ; 43 | ///获取底牌倍数 44 | int GetBackCardMytiple(void) ; 45 | 46 | }; 47 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/36610103_DDZ/Makefile: -------------------------------------------------------------------------------- 1 | # 36610103_DDZ的Makefile文件 2 | 3 | # 编译版本,可选debug和release 4 | # build_ver=debug 5 | 6 | ifeq ($(build_ver),release) 7 | BUILD_OPT= -g1 -O3 8 | else 9 | BUILD_OPT= -g2 -O0 10 | endif 11 | 12 | 13 | CPP = g++ 14 | CPPFLAGS = -I ../../include -I ../../include/ServerCommon -I ../../include/curl -I ../../include/DataBase -I ../../include/libevent -I ../../include/hiredis -I ../../protobuf -I /usr/local/include $(BUILD_OPT) -Wall -fpic -std=c++11 15 | 16 | LDFLAGS = -L ../../bin -shared 17 | LIBS = -lKernel -lCommon -lGameManage -ljson -lprotobuf -ljemalloc 18 | 19 | BINDIR := ../../bin/ 20 | BIN := 36610103.so 21 | OBJ := GameTaskLogic.o ServerManage.o UpGradeDLL.o UpGradeLogic.o 22 | DEP = $(OBJ:.o=.dep) 23 | 24 | $(BINDIR)$(BIN):$(OBJ) 25 | $(CPP) -o $@ $(LDFLAGS) $^ $(LIBS) 26 | 27 | %.o:%.cpp 28 | $(CPP) -c $< $(CPPFLAGS) 29 | 30 | #%.o:../protobuf/%.cc 31 | # $(CPP) -c $< $(CPPFLAGS) 32 | 33 | 34 | # 生成依赖项 35 | %.dep:%.cpp 36 | $(CPP) -MM $< $(CPPFLAGS) > $@ 37 | 38 | -include $(DEP) 39 | 40 | 41 | install: 42 | cp 36610103_s.ini ../../bin/ 43 | @echo "36610103_DDZ生成在../../bin/目录中" 44 | 45 | clean: 46 | rm -rf *.o *.dep 47 | 48 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/36610103_DDZ/UpGradeDLL.cpp: -------------------------------------------------------------------------------- 1 | // UpGradeDLL.cpp : 定义 DLL 的初始化例程。 2 | // 3 | 4 | #include "ServerManage.h" 5 | 6 | 7 | //获取游戏组件信息 8 | extern "C" BOOL GetServiceInfo(ServerDllInfoStruct * pServiceInfo, UINT uVer) 9 | { 10 | //效验信息 11 | if ((uVer!=DEV_LIB_VER)||(pServiceInfo==NULL)) return FALSE; 12 | 13 | //写入信息 14 | memset(pServiceInfo,0,sizeof(ServerDllInfoStruct)); 15 | pServiceInfo->uServiceVer=GAME_MAX_VER; 16 | pServiceInfo->uNameID=NAME_ID; 17 | pServiceInfo->uDeskPeople=PLAY_COUNT; 18 | pServiceInfo->uSupportType=SUPPER_TYPE; 19 | strcpy(pServiceInfo->szGameName,GAMENAME); 20 | strcpy(pServiceInfo->szDllNote,"牌类 -- 斗地主游戏组件"); 21 | return TRUE; 22 | } 23 | 24 | //获取游戏管理接口函数 25 | extern "C" IModuleManageService * CreateServiceInterface(UINT uVer) 26 | { 27 | if (uVer==DEV_LIB_VER) 28 | { 29 | try { return new CGameModuleTemplate; } 30 | catch (...) {} 31 | } 32 | return NULL; 33 | } 34 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/37460003_PHZ/37460003_s.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luotan-123/libevent-server/98652b1b5150402ae771ca0393b2ca7fadb11b8d/linuxserverplatform/src/games/37460003_PHZ/37460003_s.ini -------------------------------------------------------------------------------- /linuxserverplatform/src/games/37460003_PHZ/Makefile: -------------------------------------------------------------------------------- 1 | # 37460003_PHZ的Makefile文件 2 | 3 | # 编译版本,可选debug和release 4 | #build_ver=debug 5 | 6 | ifeq ($(build_ver),release) 7 | BUILD_OPT= -g1 -O3 8 | else 9 | BUILD_OPT= -g2 -O0 10 | endif 11 | 12 | 13 | CPP = g++ 14 | CPPFLAGS = -I ../../include -I ../../include/ServerCommon -I ../../include/curl -I ../../include/DataBase -I ../../include/libevent -I ../../include/hiredis -I ../../protobuf -I /usr/local/include $(BUILD_OPT) -Wall -fpic -std=c++11 15 | 16 | LDFLAGS = -L ../../bin -shared 17 | LIBS = -lKernel -lCommon -lGameManage -ljson -lprotobuf -ljemalloc 18 | 19 | BINDIR := ../../bin/ 20 | BIN := 37460003.so 21 | OBJ := GameData.o Playback.o ServerManage.o UpGradeDLL.o UpGradeLogic.o 22 | DEP = $(OBJ:.o=.dep) 23 | 24 | $(BINDIR)$(BIN):$(OBJ) 25 | $(CPP) -o $@ $(LDFLAGS) $^ $(LIBS) 26 | 27 | %.o:%.cpp 28 | $(CPP) -c $< $(CPPFLAGS) 29 | 30 | #%.o:../protobuf/%.cc 31 | # $(CPP) -c $< $(CPPFLAGS) 32 | 33 | 34 | # 生成依赖项 35 | %.dep:%.cpp 36 | $(CPP) -MM $< $(CPPFLAGS) > $@ 37 | 38 | -include $(DEP) 39 | 40 | 41 | install: 42 | cp 37460003_s.ini ../../bin/ 43 | @echo "37460003_PHZ生成在../../bin/目录中" 44 | 45 | clean: 46 | rm -rf *.o *.dep 47 | 48 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/37460003_PHZ/Playback.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UpGradeLogic.h" 3 | 4 | class CServerGameDesk; 5 | class CGameLogic; 6 | 7 | //升级逻辑类 8 | class CPlayback 9 | { 10 | public: 11 | //构造函数 12 | CPlayback(void); 13 | ~CPlayback(void); 14 | 15 | public: 16 | void Clear(); 17 | void SetDeskLogicPoint(CGameLogic *pGameLogic) { m_pGameLogic = pGameLogic;}; 18 | void SaveUserInfor(CServerGameDesk *pDesk); 19 | void SendCard(BYTE byDataIndex[PLAY_COUNT][MAX_INDEX],int iJinNum[PLAY_COUNT]); //发牌 20 | void SaveCPGTWP(tagWeaveItem *tCPGTWP,BYTE byCardData,int iMenNums,BYTE byDataIndex[MAX_INDEX],int iJinNum,BYTE byDesk); //拦牌 21 | void SaveGetCard(BYTE byGetCardData,BYTE byCurrendUser,BYTE iMenNums,BYTE byDataIndex[MAX_INDEX],int iJinNum); //取牌 22 | void SaveOutCard(BYTE byGetCardData,BYTE byCurrendUser,BYTE iMenNums,BYTE byDataIndex[MAX_INDEX],int iJinNum); //出牌 23 | void SaveNotic(); 24 | void SaveHuInfor(); 25 | void SaveToHardDisk(CServerGameDesk *pDesk,char cTempCode[]); 26 | private: 27 | ofstream m_fVideoFile; 28 | int m_iVideoIndex; 29 | Json::Value m_element; 30 | Json::Value m_root; 31 | char m_VideoCode[20]; 32 | CGameLogic *m_pGameLogic; 33 | public: 34 | char m_szTempCode[20]; 35 | }; 36 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/37460003_PHZ/UpGradeDLL.cpp: -------------------------------------------------------------------------------- 1 | // UpGradeDLL.cpp : 定义 DLL 的初始化例程。 2 | // 3 | 4 | #include "ServerManage.h" 5 | 6 | 7 | //获取游戏组件信息 8 | extern "C" BOOL GetServiceInfo(ServerDllInfoStruct * pServiceInfo, UINT uVer) 9 | { 10 | //效验信息 11 | if ((uVer!=DEV_LIB_VER)||(pServiceInfo==NULL)) return FALSE; 12 | 13 | //写入信息 14 | memset(pServiceInfo,0,sizeof(ServerDllInfoStruct)); 15 | pServiceInfo->uServiceVer=GAME_MAX_VER; 16 | pServiceInfo->uNameID=NAME_ID; 17 | pServiceInfo->uDeskPeople=PLAY_COUNT; 18 | pServiceInfo->uSupportType=SUPPER_TYPE; 19 | strcpy(pServiceInfo->szGameName,GAMENAME); 20 | ///lstrcpy(pServiceInfo->szGameTable,GAME_TABLE_NAME); 21 | ///lstrcpy(pServiceInfo->szDLLFileName,SERVER_DLL_NAME); 22 | strcpy(pServiceInfo->szWriter,"无名"); 23 | strcpy(pServiceInfo->szDllNote,"跑胡子游戏组件"); 24 | return TRUE; 25 | } 26 | 27 | //获取游戏管理接口函数 28 | extern "C" IModuleManageService * CreateServiceInterface(UINT uVer) 29 | { 30 | if (uVer==DEV_LIB_VER) 31 | { 32 | try { return new CGameModuleTemplate; } 33 | catch (...) {} 34 | } 35 | return NULL; 36 | } 37 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/40000100_LHD/40000100_s.ini: -------------------------------------------------------------------------------- 1 | [game] 2 | ;空闲时间 3 | waitBeginTime=1 4 | ;下注时间 5 | noteKeepTime=15 6 | ;发牌时间 7 | sendCardKeepTime=2 8 | ;比牌时间 9 | compareKeepTime=5 10 | ;结算时间 11 | waitSettleTime=2 12 | ;最大坐庄局数 13 | maxZhuangGameCount=5 14 | ;抽水 15 | taxRate=5 16 | ;座位数量 17 | maxDeskCount=6 18 | ;是否开启机器人坐庄随机坐庄次数(0 否 1 是) 19 | randBankerCount = 1 20 | ;随机坐庄概率,每次会随机一次(1-100) 21 | randCount = 60 22 | ;机器人最多能坐下多少人 23 | CanSitCount = 4 24 | ;根据房间人数来确定坐下人数(注意 三个等级依次变大) 25 | ;小于等于3留2个位置 26 | GamePlayCount_1 = 3 27 | ;大于_1小于此值留4个位置 28 | GamePlayCount_2 = 5 29 | ; 大于此值机器人坐一个位置 30 | GamePlayCount_3 = 10 31 | 32 | ;3个场的上庄限制 33 | shangZhuangLimitMoney1=10000 34 | shangZhuangLimitMoney2=10000 35 | shangZhuangLimitMoney3=10000 36 | 37 | ;每个场的坐下限制 38 | sitLimitMoney1=2000 39 | sitLimitMoney2=3000 40 | sitLimitMoney3=5000 41 | 42 | ;每个场的下注限制 43 | allUserMaxNote1=10000 44 | allUserMaxNote2=10000 45 | allUserMaxNote3=10000 46 | 47 | 48 | ;3个场的下注 49 | noteList_1_0=1 50 | noteList_1_1=5 51 | noteList_1_2=10 52 | noteList_1_3=30 53 | noteList_1_4=50 54 | noteList_1_5=80 55 | 56 | noteList_2_0=5 57 | noteList_2_1=20 58 | noteList_2_2=50 59 | noteList_2_3=100 60 | noteList_2_4=300 61 | noteList_2_5=500 62 | 63 | noteList_3_0=10 64 | noteList_3_1=50 65 | noteList_3_2=300 66 | noteList_3_3=500 67 | noteList_3_4=800 68 | noteList_3_5=2000 -------------------------------------------------------------------------------- /linuxserverplatform/src/games/40000100_LHD/GameServer.cpp: -------------------------------------------------------------------------------- 1 | // GameServer.cpp : 2 | // 3 | 4 | #include "NewServerManage.h" 5 | 6 | //获取游戏组件信息 7 | extern "C" BOOL GetServiceInfo(ServerDllInfoStruct * pServiceInfo, UINT uVer) 8 | { 9 | //效验信息 10 | if ((DEV_LIB_VER != uVer) || (NULL == pServiceInfo)) 11 | { 12 | return FALSE; 13 | } 14 | 15 | //写入信息 16 | memset(pServiceInfo, 0, sizeof(ServerDllInfoStruct)); 17 | pServiceInfo->uServiceVer = GAME_MAX_VER; 18 | pServiceInfo->uNameID = NAME_ID; 19 | pServiceInfo->uDeskPeople = PLAY_COUNT; 20 | pServiceInfo->uSupportType = SUPPER_TYPE; 21 | strcpy(pServiceInfo->szGameName, GAMENAME); 22 | strcpy(pServiceInfo->szWriter, GAME_DLL_AUTHOR); 23 | strcpy(pServiceInfo->szDllNote, GAME_DLL_NOTE); 24 | return TRUE; 25 | } 26 | 27 | //获取游戏管理接口函数 28 | extern "C" IModuleManageService * CreateServiceInterface(UINT uVer) 29 | { 30 | if (DEV_LIB_VER == uVer) 31 | { 32 | try 33 | { 34 | return new CGameModuleTemplate; 35 | } 36 | catch (...) 37 | { 38 | } 39 | } 40 | return NULL; 41 | } 42 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/40000100_LHD/Makefile: -------------------------------------------------------------------------------- 1 | # 40000100_LHD的Makefile文件 2 | 3 | # 编译版本,可选debug和release 4 | # build_ver=debug 5 | 6 | ifeq ($(build_ver),release) 7 | BUILD_OPT= -g1 -O3 8 | else 9 | BUILD_OPT= -g2 -O0 10 | endif 11 | 12 | 13 | CPP = g++ 14 | CPPFLAGS = -I ../../include -I ../../include/ServerCommon -I ../../include/curl -I ../../include/DataBase -I ../../include/libevent -I ../../include/hiredis -I ../../protobuf -I /usr/local/include $(BUILD_OPT) -Wall -fpic -std=c++11 15 | 16 | LDFLAGS = -L ../../bin -shared 17 | LIBS = -lKernel -lCommon -lGameManage -ljson -lprotobuf -ljemalloc 18 | 19 | BINDIR := ../../bin/ 20 | BIN := 40000100.so 21 | OBJ := GameServer.o NewServerManage.o UpGradeLogic.o 22 | DEP = $(OBJ:.o=.dep) 23 | 24 | $(BINDIR)$(BIN):$(OBJ) 25 | $(CPP) -o $@ $(LDFLAGS) $^ $(LIBS) 26 | 27 | %.o:%.cpp 28 | $(CPP) -c $< $(CPPFLAGS) 29 | 30 | #%.o:../protobuf/%.cc 31 | # $(CPP) -c $< $(CPPFLAGS) 32 | 33 | install: 34 | cp 40000100_s.ini ../../bin/ 35 | @echo "40000100_LHD生成在../../bin/目录中" 36 | 37 | 38 | # 生成依赖项 39 | %.dep:%.cpp 40 | $(CPP) -MM $< $(CPPFLAGS) > $@ 41 | 42 | -include $(DEP) 43 | 44 | 45 | clean: 46 | rm -rf *.o *.dep 47 | 48 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/40000100_LHD/UpGradeLogic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //操作掩码 4 | #define UG_HUA_MASK 0xF0 //1111 0000 5 | #define UG_VALUE_MASK 0x0F //0000 1111 6 | 7 | #include 8 | 9 | #define MAKE_CARD_SHAPE(x) CARD_SHAPE_CATTLE_##x 10 | 11 | const int POKER_CARD_NUM = 54; // 扑克牌的张数 12 | const int POKER_CARD_NUM_NOKING = 52; // 扑克牌的张数(没有大小王) 13 | 14 | static const BYTE g_cardArray[54] = 15 | { 16 | //2 3 4 5 6 7 8 9 10 J Q K A 17 | 0x01, 0x02 ,0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, //方块 2 - A 18 | 0x11, 0x12 ,0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, //梅花 2 - A 19 | 0x21, 0x22 ,0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, //红桃 2 - A 20 | 0x31, 0x32 ,0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, //黑桃 2 - A 21 | 0x4E, 0x4F 22 | }; 23 | 24 | class CPokerGameLogic 25 | { 26 | public: 27 | CPokerGameLogic(); 28 | ~CPokerGameLogic(); 29 | 30 | public: 31 | //获取扑克数字 32 | int GetCardNum(BYTE iCard) { return (iCard&UG_VALUE_MASK)+1; } 33 | //获取扑克相对大小 34 | int GetCardBulk(BYTE iCard, int bExtVol = false); 35 | //获取扑克花色 36 | BYTE GetCardHuaKind(BYTE iCard); 37 | // 洗牌 38 | bool RandCard(std::vector& cardVec, int cardPairs); 39 | //比较牌列表A和B中最大的牌 0=AB 2=A=B 40 | int CompareCardValue(const BYTE* pCardListA, int cardCountA, const BYTE* pCardListB, int cardCountB); 41 | // 获取最大的牌 42 | BYTE GetMaxCardByNumber(const BYTE* pCardList, int cardCount); 43 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/games/50000001_BOOS/Dexter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GameDesk.h" 4 | #include 5 | 6 | 7 | // 重定义 8 | typedef unsigned char uchar; 9 | typedef unsigned short ushort; 10 | typedef unsigned int uint; 11 | typedef unsigned long ulong; 12 | typedef unsigned long long uint64; 13 | typedef unsigned long long ulonglong; 14 | typedef long long longlong; 15 | typedef long long int64; 16 | typedef unsigned short word; 17 | typedef unsigned int dword; 18 | typedef unsigned int hwnd; 19 | typedef unsigned int handle; 20 | typedef unsigned int hinstance; 21 | typedef unsigned char byte; 22 | typedef unsigned short WORD; 23 | typedef longlong LONGLONG; 24 | typedef char tchar; 25 | typedef char TCHAR; 26 | typedef unsigned int DWORD; 27 | typedef void VOID; 28 | typedef float FLOAT; 29 | #define Vector vector 30 | #define Static static 31 | #define int_max 2147483647 32 | #define int_min (-2147483647 - 1) 33 | #define uint_max 0xffffffff 34 | #define uint_min 0 35 | #define llong_max 0x7fffffffffffffff 36 | #define llong_min 0x8000000000000000 37 | #define ullong_max 0xffffffffffffffff 38 | #define ullong_min 0 39 | #define CopyMemory memcpy 40 | #define ZeroMemory bzero 41 | #define file FILE 42 | #define ASSERT assert 43 | 44 | // 标准定义 45 | #define _in 46 | #define _out 47 | #define MAX_PATH 256 48 | 49 | // 安全删除 50 | #ifndef SafeRelease 51 | #define SafeRelease(pObject) { if (pObject!=NULL) { pObject->Release(); pObject=NULL; } } 52 | #endif 53 | 54 | #ifndef SafeCloseHandle 55 | #define SafeCloseHandle(hHandle) { if (hHandle!=NULL) { CloseHandle(hHandle); hHandle=NULL; } } 56 | #endif 57 | 58 | #ifndef SafeDelete 59 | #define SafeDelete(pData) { if ( pData != NULL ) { delete pData; pData=NULL; } } 60 | #endif 61 | 62 | #ifndef SafeDeleteArray 63 | #define SafeDeleteArray(pData) { if ( pData != NULL ) { delete[] pData; pData=NULL; } } 64 | #endif 65 | 66 | #ifndef CountArray 67 | #define CountArray(Array) (sizeof(Array)/sizeof(Array[0])) 68 | #endif 69 | 70 | typedef struct tagPOINT 71 | { 72 | int x; 73 | int y; 74 | } POINT; 75 | 76 | struct CPoint : public tagPOINT 77 | { 78 | 79 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/games/50000001_BOOS/GameLogic.cpp: -------------------------------------------------------------------------------- 1 | #include "GameLogic.h" 2 | 3 | ////////////////////////////////////////////////////////////////////////////////// 4 | 5 | //构造函数 6 | CGameLogic::CGameLogic() 7 | { 8 | 9 | } 10 | 11 | //析构函数 12 | CGameLogic::~CGameLogic() 13 | { 14 | } 15 | 16 | 17 | ////////////////////////////////////////////////////////////////////////////////// 18 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/50000001_BOOS/GameLogic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CMD_Game.h" 4 | #define GL_PI ((FLOAT) 3.141592654f) 5 | ////////////////////////////////////////////////////////////////////////////////// 6 | 7 | ////////////////////////////////////////////////////////////////////////////////// 8 | 9 | //游戏逻辑 10 | class CGameLogic 11 | { 12 | //函数定义 13 | public: 14 | //构造函数 15 | CGameLogic(); 16 | //析构函数 17 | virtual ~CGameLogic(); 18 | 19 | }; 20 | 21 | ////////////////////////////////////////////////////////////////////////////////// -------------------------------------------------------------------------------- /linuxserverplatform/src/games/50000001_BOOS/GameServer.cpp: -------------------------------------------------------------------------------- 1 | #include "TableFrameSink.h" 2 | 3 | //获取游戏组件信息 4 | extern "C" BOOL GetServiceInfo(ServerDllInfoStruct * pServiceInfo, UINT uVer) 5 | { 6 | //效验信息 7 | if ((DEV_LIB_VER != uVer) || (NULL == pServiceInfo)) 8 | { 9 | return FALSE; 10 | } 11 | 12 | //写入信息 13 | memset(pServiceInfo, 0, sizeof(ServerDllInfoStruct)); 14 | pServiceInfo->uServiceVer = GAME_MAX_VER; 15 | pServiceInfo->uNameID = NAME_ID; 16 | pServiceInfo->uDeskPeople = PLAY_COUNT; 17 | pServiceInfo->uSupportType = SUPPER_TYPE; 18 | strcpy(pServiceInfo->szGameName, GAMENAME); 19 | strcpy(pServiceInfo->szWriter, GAME_DLL_AUTHOR); 20 | strcpy(pServiceInfo->szDllNote, GAME_DLL_NOTE); 21 | return TRUE; 22 | } 23 | 24 | //获取游戏管理接口函数 25 | extern "C" IModuleManageService * CreateServiceInterface(UINT uVer) 26 | { 27 | if (DEV_LIB_VER == uVer) 28 | { 29 | try 30 | { 31 | return new CGameModuleTemplate; 32 | } 33 | catch (...) 34 | { 35 | } 36 | } 37 | return NULL; 38 | } -------------------------------------------------------------------------------- /linuxserverplatform/src/games/50000001_BOOS/Makefile: -------------------------------------------------------------------------------- 1 | # 50000001_BOOS的Makefile文件 2 | 3 | # 编译版本,可选debug和release 4 | # build_ver=debug 5 | 6 | ifeq ($(build_ver),release) 7 | BUILD_OPT= -g1 -O3 8 | else 9 | BUILD_OPT= -g2 -O0 10 | endif 11 | 12 | 13 | CPP = g++ 14 | CPPFLAGS = -I ../../include -I ../../include/ServerCommon -I ../../include/curl -I ../../include/DataBase -I ../../include/libevent -I ../../include/hiredis -I ../../protobuf -I /usr/local/include $(BUILD_OPT) -Wall -fpic -std=c++11 15 | 16 | LDFLAGS = -L ../../bin -shared 17 | LIBS = -lKernel -lCommon -lGameManage -ljson -lprotobuf -ljemalloc 18 | 19 | BINDIR := ../../bin/ 20 | BIN := 50000001.so 21 | OBJ := GameLogic.o GameServer.o PolygonShape.o TableFrameSink.o 22 | DEP = $(OBJ:.o=.dep) 23 | 24 | $(BINDIR)$(BIN):$(OBJ) 25 | $(CPP) -o $@ $(LDFLAGS) $^ $(LIBS) 26 | 27 | %.o:%.cpp 28 | $(CPP) -c $< $(CPPFLAGS) 29 | 30 | #%.o:../protobuf/%.cc 31 | # $(CPP) -c $< $(CPPFLAGS) 32 | 33 | 34 | # 生成依赖项 35 | %.dep:%.cpp 36 | $(CPP) -MM $< $(CPPFLAGS) > $@ 37 | 38 | -include $(DEP) 39 | 40 | 41 | install: 42 | cp 50000001_s.ini ../../bin/ 43 | cp FishLKPath.pat ../../bin/ 44 | @echo "50000001_BOOS生成在../../bin/目录中" 45 | 46 | clean: 47 | rm -rf *.o *.dep 48 | 49 | -------------------------------------------------------------------------------- /linuxserverplatform/src/games/Makefile: -------------------------------------------------------------------------------- 1 | # games makefile 2 | 3 | default: all 4 | 5 | .DEFAULT: 6 | cd 23510004_SXTDH && $(MAKE) 7 | cd 36610103_DDZ && $(MAKE) 8 | cd 37460003_PHZ && $(MAKE) 9 | cd 40000100_LHD && $(MAKE) 10 | cd 50000001_BOOS && $(MAKE) 11 | cd 12101105_ZJH && $(MAKE) 12 | cd 30100008_NN && $(MAKE) 13 | 14 | install: 15 | cd 23510004_SXTDH && $(MAKE) $@ 16 | cd 36610103_DDZ && $(MAKE) $@ 17 | cd 37460003_PHZ && $(MAKE) $@ 18 | cd 40000100_LHD && $(MAKE) $@ 19 | cd 50000001_BOOS && $(MAKE) $@ 20 | cd 12101105_ZJH && $(MAKE) $@ 21 | cd 30100008_NN && $(MAKE) $@ 22 | 23 | clean: 24 | cd 23510004_SXTDH && $(MAKE) $@ 25 | cd 36610103_DDZ && $(MAKE) $@ 26 | cd 37460003_PHZ && $(MAKE) $@ 27 | cd 40000100_LHD && $(MAKE) $@ 28 | cd 50000001_BOOS && $(MAKE) $@ 29 | cd 12101105_ZJH && $(MAKE) $@ 30 | cd 30100008_NN && $(MAKE) $@ 31 | 32 | .PHONY: install 33 | -------------------------------------------------------------------------------- /linuxserverplatform/src/httpserver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(http-server) 2 | 3 | cmake_minimum_required(VERSION 2.8) 4 | 5 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -g") 6 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -g -std=c++11") 7 | 8 | add_definitions( 9 | #-DBOOST_LOG_DYN_LINK 10 | ) 11 | 12 | add_subdirectory(src) 13 | 14 | -------------------------------------------------------------------------------- /linuxserverplatform/src/httpserver/README.md: -------------------------------------------------------------------------------- 1 | # http-server 2 | multi-thread http server based on libevent writen in c++ 3 | 4 | 基于libevent实现的多线程http-server,相关代码已在生产环境使用(此示例已简化处理流程),长时间运行正常。 5 | 6 | 示例采用多线程(每个Worker对应一个线程),每个线程内一个event_base实例,同时监听在同一个server fd上(可以创建多个server监听多个端口)。 7 | 8 | 示例中采用了简单的同步处理方式,直接返回json数据 9 | 10 | 生产环境代码是在此基础上实现了请求的异步处理,特别需要注意的是采用异步方式时,同一个evhttp_request需要在接收的work线程内执行,否则会出现问题。 11 | 12 | 异步实现流程通常为: 13 | 14 | 1.  uri request handler接收到请求后,进行Header、参数以及body等的解析和验证工作; 15 | 16 | 2.  将解析的请求放入任务队列(任务与work线程建立映射,) 17 | 18 | 3.  任务线程池从任务队列取得任务,并异步执行 19 | 20 | 4.  异步执行结果会通过回调函数执行,需要根据步骤2建立的映射关系,转发到同一worker线程执行reply 21 | 22 | 5.  执行完毕,释放必要的资源。 23 | 24 | 25 | 26 | 在vps(单CPU,512M内存)上面进行测试结果如下: 27 | 28 | ] cat post.data   # post测试数据随意 29 | 30 | {"rqst": 1} 31 | 32 | ] ab -k -c 10 -n 1000000 -p post.data http://127.0.0.1:6666/post 33 | Concurrency Level: 10 34 | Time taken for tests: 1.877 seconds 35 | Requests per second: 34416.93 [#/sec] (mean) 36 | Time per request: 0.291 [ms] (mean) 37 | Time per request: 0.029 [ms] (mean, across all concurrent requests) 38 | 39 | 介绍:http://shamaoge.com/posts/392922 40 | -------------------------------------------------------------------------------- /linuxserverplatform/src/httpserver/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories( 3 | ${CMAKE_SOURCE_DIR}/ 4 | ${CMAKE_SOURCE_DIR}/common/ 5 | ${CMAKE_SOURCE_DIR}/src/ 6 | ) 7 | 8 | link_directories( 9 | ${CMAKE_SOURCE_DIR}/ 10 | ${CMAKE_SOURCE_DIR}/common/ 11 | ${CMAKE_SOURCE_DIR}/src/ 12 | ) 13 | 14 | set(SERVER_SRC 15 | main.cpp 16 | server.cpp 17 | worker.cpp 18 | handlers.cpp 19 | ) 20 | 21 | ADD_EXECUTABLE(http-server ${SERVER_SRC}) 22 | target_link_libraries(http-server 23 | event 24 | pthread 25 | ) 26 | 27 | -------------------------------------------------------------------------------- /linuxserverplatform/src/httpserver/src/daemonize.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | int daemonize(int nochdir, int noclose) 11 | { 12 | int fd; 13 | 14 | switch (fork()) { 15 | case -1: 16 | return (-1); 17 | case 0: 18 | break; 19 | default: 20 | _exit(EXIT_SUCCESS); 21 | } 22 | 23 | if (setsid() == -1) 24 | return (-1); 25 | 26 | if (nochdir == 0) { 27 | if(chdir("/") != 0) { 28 | perror("chdir"); 29 | return (-1); 30 | } 31 | } 32 | 33 | if (noclose == 0 && (fd = open("/dev/null", O_RDWR, 0)) != -1) { 34 | if(dup2(fd, STDIN_FILENO) < 0) { 35 | perror("dup2 stdin"); 36 | return (-1); 37 | } 38 | if(dup2(fd, STDOUT_FILENO) < 0) { 39 | perror("dup2 stdout"); 40 | return (-1); 41 | } 42 | if(dup2(fd, STDERR_FILENO) < 0) { 43 | perror("dup2 stderr"); 44 | return (-1); 45 | } 46 | 47 | if (fd > STDERR_FILENO) { 48 | if(close(fd) < 0) { 49 | perror("close"); 50 | return (-1); 51 | } 52 | } 53 | } 54 | return (0); 55 | } 56 | 57 | int daemonize() { 58 | daemonize(1, 0); 59 | } 60 | -------------------------------------------------------------------------------- /linuxserverplatform/src/httpserver/src/handlers.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | void general_request_handler(struct evhttp_request *req, void *arg); 8 | void ping_handler(struct evhttp_request *req, void *args); 9 | void post_handler(struct evhttp_request *req, void *args); 10 | 11 | typedef void (*_request_handler_)(struct evhttp_request *req, void *arg); 12 | struct request_handler_t { 13 | const char* path; 14 | _request_handler_ handler; 15 | void* arg; 16 | }; 17 | 18 | static request_handler_t request_handlers [] = { 19 | { "/ping", ping_handler, NULL }, 20 | { "/post", post_handler, NULL }, 21 | // ... more uri handlers ... 22 | { NULL, NULL, NULL}, 23 | }; 24 | 25 | 26 | -------------------------------------------------------------------------------- /linuxserverplatform/src/httpserver/src/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "logging.h" 10 | #include "daemonize.h" 11 | #include "server.h" 12 | 13 | int main(int argc, char **argv) { 14 | 15 | bool do_daemonize = false; 16 | if(do_daemonize) { 17 | if (sigignore(SIGHUP) == -1) { 18 | perror("Failed to ignore SIGHUP"); 19 | } 20 | if (daemonize() == -1) { 21 | fprintf(stderr, "failed to daemon() in order to daemonize\n"); 22 | exit(1); 23 | } 24 | } 25 | 26 | LOG_INFO<<"server starting ..."; 27 | 28 | http::Server server{6666, SOMAXCONN, 1}; 29 | server.Run(); 30 | 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /linuxserverplatform/src/httpserver/src/server.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "server.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "logging.h" 10 | 11 | #define _MIN_(a, b) (a)>=(b)?(b):(a) 12 | #define _MAX_(a, b) (a)>=(b)?(a):(b) 13 | 14 | namespace http { 15 | 16 | Server::Server(int32_t port, int32_t backlog, int32_t workers) : port_(port), backlog_(backlog), workers_n_(workers) { 17 | } 18 | 19 | Server::~Server() { 20 | } 21 | 22 | int Server::openServer() { 23 | int nfd = socket(AF_INET, SOCK_STREAM, 0); 24 | if (nfd < 0) { 25 | LOG_ERROR<<"socket error "; 26 | return -1; 27 | } 28 | 29 | int one = 1; 30 | int r = setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(int)); 31 | 32 | struct sockaddr_in addr; 33 | memset(&addr, 0, sizeof(addr)); 34 | addr.sin_family = AF_INET; 35 | addr.sin_addr.s_addr = INADDR_ANY; 36 | addr.sin_port = htons(port_); 37 | 38 | r = bind(nfd, (struct sockaddr*)&addr, sizeof(addr)); 39 | if (r < 0) { 40 | LOG_ERROR<<"bind error "<(new std::thread(&Worker::Run, &workers_[i]))); 63 | } 64 | return 0; 65 | } 66 | 67 | int Server::waitWorkers() { 68 | for(int i=0; ijoin(); 70 | worker_threads_[i].reset(); 71 | } 72 | return 0; 73 | } 74 | 75 | int Server::Run() { 76 | fd_ = openServer(); 77 | if(fd_ == -1) { 78 | return -1; 79 | } 80 | startWorkers(); 81 | waitWorkers(); 82 | return 0; 83 | } 84 | 85 | int Server::Stop() { 86 | for(int i=0; i 5 | #include 6 | 7 | #include "worker.h" 8 | 9 | namespace http { 10 | 11 | class Server { 12 | public: 13 | Server(int32_t port=6666, int32_t backlog=1024, int32_t workers=1); 14 | virtual ~Server(); 15 | 16 | int Run(); 17 | int Stop(); 18 | 19 | protected: 20 | int openServer(); 21 | int startWorkers(); 22 | int waitWorkers(); 23 | 24 | private: 25 | int fd_{-1}; 26 | int32_t port_{6666}; 27 | int32_t backlog_{1024}; 28 | int32_t workers_n_{10}; 29 | Worker workers_[100]; // TODO 30 | std::vector> worker_threads_; 31 | }; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /linuxserverplatform/src/httpserver/src/worker.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "worker.h" 3 | 4 | #include 5 | 6 | #include "handlers.h" 7 | #include "logging.h" 8 | 9 | namespace http { 10 | 11 | static void exit_cb_handler(int fd, short events, void* arg) { 12 | Worker* w = (Worker*)arg; 13 | char buf[1]; 14 | if(read(fd, buf, 1) != 1) { 15 | LOG_ERROR<<"read error"; 16 | return; 17 | } 18 | w->Exit(); 19 | } 20 | 21 | int Worker::Init(int server_fd) { 22 | 23 | evbase_ = event_base_new(); 24 | if (evbase_ == NULL) 25 | return -1; 26 | 27 | if (pipe(exit_pipes_)) { 28 | return -1; 29 | } 30 | 31 | // HTTP handlers 32 | struct evhttp *http = evhttp_new(evbase_); 33 | if (http == NULL) return -1; 34 | int r = evhttp_accept_socket(http, server_fd); 35 | if (r != 0) return -1; 36 | for(request_handler_t* h=request_handlers; h && h->path; h++) { 37 | evhttp_set_cb(http, h->path, h->handler, h->arg); 38 | } 39 | /* We want to accept arbitrary requests, so we need to set a "generic" 40 | * cb. We can also add callbacks for specific paths. */ 41 | evhttp_set_gencb(http, general_request_handler, NULL); 42 | 43 | //ev_result_ = event_new(evbase_, pipes_[0], EV_READ|EV_PERSIST, result_cb_handler, (void*)this); 44 | //event_add(ev_result_, NULL); 45 | 46 | exit_ev_ = event_new(evbase_, exit_pipes_[0], EV_READ|EV_PERSIST, exit_cb_handler, (void*)this); 47 | event_add(exit_ev_, NULL); 48 | 49 | return 0; 50 | } 51 | 52 | void Worker::Run() { 53 | if(evbase_ == nullptr) 54 | return; 55 | 56 | event_base_dispatch(evbase_); 57 | event_free(exit_ev_); 58 | event_base_free(evbase_); 59 | } 60 | 61 | void Worker::Stop() { 62 | char buf[1] = {'-'}; 63 | write(exit_pipes_[1], buf, 1); 64 | } 65 | void Worker::Exit() { 66 | if(evbase_) { 67 | event_base_loopexit(evbase_, NULL); 68 | //event_base_loopbreak(evbase_); 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /linuxserverplatform/src/httpserver/src/worker.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | 6 | namespace http { 7 | 8 | class Worker { 9 | public: 10 | int Init(int server_fd); 11 | void Run(); 12 | void Stop(); 13 | 14 | void Exit(); 15 | 16 | private: 17 | struct event_base *evbase_{nullptr}; 18 | struct event *exit_ev_{nullptr}; 19 | struct event *timer_event_{nullptr}; 20 | 21 | int exit_pipes_[2]; 22 | }; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/DataBase/binary_log_types.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, 2015 Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 15 | 16 | /** 17 | @file binary_log_types.h 18 | 19 | @brief This file contains the field type. 20 | 21 | 22 | @note This file can be imported both from C and C++ code, so the 23 | definitions have to be constructed to support this. 24 | */ 25 | 26 | #ifndef BINARY_LOG_TYPES_INCLUDED 27 | #define BINARY_LOG_TYPES_INCLUDED 28 | 29 | #ifdef __cplusplus 30 | extern "C" 31 | { 32 | #endif 33 | 34 | /* 35 | * Constants exported from this package. 36 | */ 37 | 38 | typedef enum enum_field_types { 39 | MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, 40 | MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG, 41 | MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE, 42 | MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP, 43 | MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24, 44 | MYSQL_TYPE_DATE, MYSQL_TYPE_TIME, 45 | MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR, 46 | MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR, 47 | MYSQL_TYPE_BIT, 48 | MYSQL_TYPE_TIMESTAMP2, 49 | MYSQL_TYPE_DATETIME2, 50 | MYSQL_TYPE_TIME2, 51 | MYSQL_TYPE_JSON=245, 52 | MYSQL_TYPE_NEWDECIMAL=246, 53 | MYSQL_TYPE_ENUM=247, 54 | MYSQL_TYPE_SET=248, 55 | MYSQL_TYPE_TINY_BLOB=249, 56 | MYSQL_TYPE_MEDIUM_BLOB=250, 57 | MYSQL_TYPE_LONG_BLOB=251, 58 | MYSQL_TYPE_BLOB=252, 59 | MYSQL_TYPE_VAR_STRING=253, 60 | MYSQL_TYPE_STRING=254, 61 | MYSQL_TYPE_GEOMETRY=255 62 | } enum_field_types; 63 | 64 | #define DATETIME_MAX_DECIMALS 6 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif // __cplusplus 69 | 70 | #endif /* BINARY_LOG_TYPES_INCLUDED */ 71 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/DataBase/my_command.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 15 | 16 | #ifndef _mysql_command_h 17 | #define _mysql_command_h 18 | 19 | /** 20 | @enum enum_server_command 21 | @brief You should add new commands to the end of this list, otherwise old 22 | servers won't be able to handle them as 'unsupported'. 23 | */ 24 | enum enum_server_command 25 | { 26 | COM_SLEEP, 27 | COM_QUIT, 28 | COM_INIT_DB, 29 | COM_QUERY, 30 | COM_FIELD_LIST, 31 | COM_CREATE_DB, 32 | COM_DROP_DB, 33 | COM_REFRESH, 34 | COM_SHUTDOWN, 35 | COM_STATISTICS, 36 | COM_PROCESS_INFO, 37 | COM_CONNECT, 38 | COM_PROCESS_KILL, 39 | COM_DEBUG, 40 | COM_PING, 41 | COM_TIME, 42 | COM_DELAYED_INSERT, 43 | COM_CHANGE_USER, 44 | COM_BINLOG_DUMP, 45 | COM_TABLE_DUMP, 46 | COM_CONNECT_OUT, 47 | COM_REGISTER_SLAVE, 48 | COM_STMT_PREPARE, 49 | COM_STMT_EXECUTE, 50 | COM_STMT_SEND_LONG_DATA, 51 | COM_STMT_CLOSE, 52 | COM_STMT_RESET, 53 | COM_SET_OPTION, 54 | COM_STMT_FETCH, 55 | COM_DAEMON, 56 | COM_BINLOG_DUMP_GTID, 57 | COM_RESET_CONNECTION, 58 | /* don't forget to update const char *command_name[] in sql_parse.cc */ 59 | 60 | /* Must be last */ 61 | COM_END 62 | }; 63 | 64 | #endif /* _mysql_command_h */ 65 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/DataBase/my_list.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 15 | 16 | #ifndef _list_h_ 17 | #define _list_h_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | typedef struct st_list { 24 | struct st_list *prev,*next; 25 | void *data; 26 | } LIST; 27 | 28 | typedef int (*list_walk_action)(void *,void *); 29 | 30 | extern LIST *list_add(LIST *root,LIST *element); 31 | extern LIST *list_delete(LIST *root,LIST *element); 32 | extern LIST *list_cons(void *data,LIST *root); 33 | extern LIST *list_reverse(LIST *root); 34 | extern void list_free(LIST *root,unsigned int free_data); 35 | extern unsigned int list_length(LIST *); 36 | extern int list_walk(LIST *,list_walk_action action,unsigned char * argument); 37 | 38 | #define list_rest(a) ((a)->next) 39 | #define list_push(a,b) (a)=list_cons((b),(a)) 40 | #define list_pop(A) {LIST *old=(A); (A)=list_delete(old,old); my_free(old); } 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | #endif 46 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/DataBase/mysql_time.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ 15 | 16 | #ifndef _mysql_time_h_ 17 | #define _mysql_time_h_ 18 | 19 | /* 20 | Time declarations shared between the server and client API: 21 | you should not add anything to this header unless it's used 22 | (and hence should be visible) in mysql.h. 23 | If you're looking for a place to add new time-related declaration, 24 | it's most likely my_time.h. See also "C API Handling of Date 25 | and Time Values" chapter in documentation. 26 | */ 27 | 28 | enum enum_mysql_timestamp_type 29 | { 30 | MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, 31 | MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 32 | }; 33 | 34 | 35 | /* 36 | Structure which is used to represent datetime values inside MySQL. 37 | 38 | We assume that values in this structure are normalized, i.e. year <= 9999, 39 | month <= 12, day <= 31, hour <= 23, hour <= 59, hour <= 59. Many functions 40 | in server such as my_system_gmt_sec() or make_time() family of functions 41 | rely on this (actually now usage of make_*() family relies on a bit weaker 42 | restriction). Also functions that produce MYSQL_TIME as result ensure this. 43 | There is one exception to this rule though if this structure holds time 44 | value (time_type == MYSQL_TIMESTAMP_TIME) days and hour member can hold 45 | bigger values. 46 | */ 47 | typedef struct st_mysql_time 48 | { 49 | unsigned int year, month, day, hour, minute, second; 50 | unsigned long second_part; /**< microseconds */ 51 | my_bool neg; 52 | enum enum_mysql_timestamp_type time_type; 53 | } MYSQL_TIME; 54 | 55 | #endif /* _mysql_time_h_ */ 56 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/DataBase/mysql_version.h: -------------------------------------------------------------------------------- 1 | /* Copyright Abandoned 1996,1999 TCX DataKonsult AB & Monty Program KB 2 | & Detron HB, 1996, 1999-2004, 2007 MySQL AB. 3 | This file is public domain and comes with NO WARRANTY of any kind 4 | */ 5 | 6 | /* Version numbers for protocol & mysqld */ 7 | 8 | #ifndef _mysql_version_h 9 | #define _mysql_version_h 10 | 11 | #define PROTOCOL_VERSION 10 12 | #define MYSQL_SERVER_VERSION "5.7.27" 13 | #define MYSQL_BASE_VERSION "mysqld-5.7" 14 | #define MYSQL_SERVER_SUFFIX_DEF "" 15 | #define FRM_VER 6 16 | #define MYSQL_VERSION_ID 50727 17 | #define MYSQL_PORT 3306 18 | #define MYSQL_PORT_DEFAULT 0 19 | #define MYSQL_UNIX_ADDR "/tmp/mysql.sock" 20 | #define MYSQL_CONFIG_NAME "my" 21 | #define MYSQL_COMPILATION_COMMENT "MySQL Community Server (GPL)" 22 | #define LIBMYSQL_VERSION "5.7.27" 23 | #define LIBMYSQL_VERSION_ID 50727 24 | #define SYS_SCHEMA_VERSION "1.5.1" 25 | 26 | #ifndef LICENSE 27 | #define LICENSE GPL 28 | #endif /* LICENSE */ 29 | 30 | #endif /* _mysql_version_h */ 31 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/DataBase/typelib.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ 15 | 16 | 17 | #ifndef _typelib_h 18 | #define _typelib_h 19 | 20 | #include "my_alloc.h" 21 | 22 | typedef struct st_typelib { /* Different types saved here */ 23 | unsigned int count; /* How many types */ 24 | const char *name; /* Name of typelib */ 25 | const char **type_names; 26 | unsigned int *type_lengths; 27 | } TYPELIB; 28 | 29 | extern my_ulonglong find_typeset(char *x, TYPELIB *typelib,int *error_position); 30 | extern int find_type_or_exit(const char *x, TYPELIB *typelib, 31 | const char *option); 32 | #define FIND_TYPE_BASIC 0 33 | /** makes @c find_type() require the whole name, no prefix */ 34 | #define FIND_TYPE_NO_PREFIX (1 << 0) 35 | /** always implicitely on, so unused, but old code may pass it */ 36 | #define FIND_TYPE_NO_OVERWRITE (1 << 1) 37 | /** makes @c find_type() accept a number */ 38 | #define FIND_TYPE_ALLOW_NUMBER (1 << 2) 39 | /** makes @c find_type() treat ',' as terminator */ 40 | #define FIND_TYPE_COMMA_TERM (1 << 3) 41 | 42 | extern int find_type(const char *x, const TYPELIB *typelib, unsigned int flags); 43 | extern void make_type(char *to,unsigned int nr,TYPELIB *typelib); 44 | extern const char *get_type(TYPELIB *typelib,unsigned int nr); 45 | extern TYPELIB *copy_typelib(MEM_ROOT *root, TYPELIB *from); 46 | 47 | extern TYPELIB sql_protocol_typelib; 48 | 49 | my_ulonglong find_set_from_flags(const TYPELIB *lib, unsigned int default_name, 50 | my_ulonglong cur_set, my_ulonglong default_set, 51 | const char *str, unsigned int length, 52 | char **err_pos, unsigned int *err_len); 53 | 54 | #endif /* _typelib_h */ 55 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/AsyncEventMsg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "DataBase.h" 4 | 5 | // 游戏服异步事件 2001-3000 6 | 7 | ////////////////////////////////////////////////////////////////////// 8 | #define ASYNC_EVENT_SQL_STATEMENT 2001 // 执行sql语句 9 | #define ASYNC_EVENT_UPLOAD_VIDEO 2002 // 上传录像 10 | #define ASYNC_EVENT_HTTP 2003 // http请求 11 | #define ASYNC_EVENT_LOG 2004 // 写入日志 12 | 13 | ////////////////////////////////////////////////////////////////////// 14 | #pragma pack(1) 15 | 16 | // 执行数据库语句 17 | struct AsyncEventMsgSqlStatement 18 | { 19 | DataBaseLineHead dataLineHead; 20 | bool bIsSelect; // 默认0:非查询性语句,错误返回字符串,1:查询语句,需要返回结果集合 21 | char sql[MAX_SQL_STATEMENT_SIZE]; 22 | 23 | AsyncEventMsgSqlStatement() 24 | { 25 | memset(this, 0, sizeof(AsyncEventMsgSqlStatement)); 26 | } 27 | }; 28 | 29 | // 上传录像 30 | struct AsyncEventMsgUploadVideo 31 | { 32 | DataBaseLineHead dataLineHead; //数据包头 33 | char videoCode[48]; 34 | 35 | AsyncEventMsgUploadVideo() 36 | { 37 | memset(this, 0, sizeof(AsyncEventMsgUploadVideo)); 38 | } 39 | }; 40 | 41 | // HTTP 请求 42 | struct AsyncEventMsgHTTP 43 | { 44 | DataBaseLineHead dataLineHead; //数据包头 45 | char url[1024]; 46 | 47 | AsyncEventMsgHTTP() 48 | { 49 | memset(this, 0, sizeof(AsyncEventMsgHTTP)); 50 | } 51 | }; 52 | 53 | #pragma pack() 54 | ////////////////////////////////////////////////////////////////////// 55 | // 数据库消息id 56 | const int ASYNC_MESSAGE_DATABASE_NO = 0; 57 | const int ASYNC_MESSAGE_DATABASE_TEST = 1; 58 | 59 | 60 | ////////////////////////////////////////////////////////////////////// 61 | // http 请求id 62 | const int HTTP_POST_TYPE_REGISTER = 1; //注册 63 | const int HTTP_POST_TYPE_LOGON = 2; //登陆 64 | const int HTTP_POST_TYPE_LOGOUT = 3; //登出 65 | const int HTTP_POST_TYPE_REQ_DATA = 4; //获取页面数据 66 | const int HTTP_POST_TYPE_MATCH_GIFT = 5; //比赛奖励 67 | const int HTTP_POST_TYPE_MATCH_FAIL = 6; //比赛失败 68 | 69 | ////////////////////////////////////////////////////////////////////// -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/BillManage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "DataBase.h" 4 | #include "NewMessageDefine.h" 5 | 6 | // 日子记录表 7 | #define TBL_STATI_LOGON_LOGOUT "statistics_logonandlogout" 8 | #define TBL_STATI_USER_MONEY_CHANGE "statistics_moneychange" 9 | #define TBL_STATI_USER_JEWELS_CHANGE "statistics_jewelschange" 10 | #define TBL_STATI_GAME_RECORD_INFO "statistics_gamerecordinfo" 11 | #define TBL_STATI_REWARDS_POOL "statistics_rewardspool" 12 | #define TBL_FG_RECORD_ACCOUNTS "friendsGroupAccounts" 13 | #define TBL_FG_COST_ACCOUNTS "friendsGroupDeskListCost" 14 | #define TBL_STATI_USER_FIRECOIN_CHANGE "statistics_firecoinchange" 15 | #define TBL_STATI_ROOM_WIN_COUNT "statistics_roomwincount" 16 | 17 | // 业绩记录 18 | #define TBL_WEB_AGENT_PUMP_JEWELS "web_agent_pump_jewels" 19 | #define TBL_WEB_AGENT_PUMP_MONEY "web_agent_pump_money" 20 | 21 | // 账单管理器 22 | class CBillManage 23 | { 24 | private: 25 | CBillManage(); 26 | ~CBillManage(); 27 | 28 | public: 29 | static CBillManage* Instance(); 30 | void Release(); 31 | 32 | void WriteBill(CDataBaseManage* m_pDBManage, const char* pFormat, ...); 33 | }; 34 | 35 | #define BillManage() CBillManage::Instance() -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/CXObj.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luotan-123/libevent-server/98652b1b5150402ae771ca0393b2ca7fadb11b8d/linuxserverplatform/src/include/ServerCommon/CXObj.h -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/CommonHead.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 公共头文件 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | // 常用类型别名 27 | typedef unsigned int UINT; 28 | typedef unsigned long int ULONG; 29 | typedef unsigned char BYTE; 30 | typedef unsigned long HANDLE; 31 | typedef bool BOOL; 32 | typedef long long __int64; 33 | 34 | // 版本定义 35 | #define VER_MAIN 3 36 | #define VER_MIDDLE 1 37 | #define VER_RESVERSE 1 38 | #define VER_BUILDTIME "2020" 39 | 40 | // 基础常量定义 41 | #define TRUE true 42 | #define FALSE false 43 | 44 | // 条件编译,生成jemalloc内存泄露分析文件 45 | #define JEMALLOC_PROFILE_MEMORY -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/DataBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "comstruct.h" 4 | #include "Interface.h" 5 | #include "Lock.h" 6 | #include "DataLine.h" 7 | #include "Exception.h" 8 | #include "MysqlHelper.h" 9 | 10 | class CDataLine; 11 | class CDataBaseManage; 12 | 13 | // 数据库处理类 14 | class CDataBaseManage 15 | { 16 | public: 17 | KernelInfoStruct* m_pKernelInfo;// 内核数据 18 | ManageInfoStruct* m_pInitInfo; // 初始化数据指针 19 | CDataLine m_DataLine; // 数据队列 20 | CMysqlHelper* m_pMysqlHelper; // 数据库模块 21 | 22 | protected: 23 | pthread_t m_hThread; // 线程句柄 24 | bool m_bInit; // 初始化标志 25 | bool m_bRun; // 运行标志 26 | IDataBaseHandleService* m_pHandleService; // 数据处理接口 27 | 28 | public: 29 | CDataBaseManage(); 30 | virtual ~CDataBaseManage(); 31 | 32 | public: 33 | //初始化函数 34 | bool Init(ManageInfoStruct* pInitInfo, KernelInfoStruct* pKernelInfo, IDataBaseHandleService* pHandleService, IAsynThreadResultService* pResultService); 35 | //取消初始化 36 | bool UnInit(); 37 | //开始服务 38 | bool Start(); 39 | //停止服务 40 | bool Stop(); 41 | //加入处理队列 42 | bool PushLine(DataBaseLineHead* pData, UINT uSize, UINT uHandleKind, UINT uIndex, UINT uMsgID); 43 | 44 | public: 45 | //检测数据连接 46 | bool CheckSQLConnect(); 47 | //重联数据库 48 | bool SQLConnectReset(); 49 | 50 | private: 51 | //数据库处理线程 52 | static void* DataServiceThread(void* pThreadData); 53 | }; 54 | 55 | ///***********************************************************************************************/// 56 | //数据库处理接口类 57 | class CDataBaseHandle : public IDataBaseHandleService 58 | { 59 | public: 60 | CDataBaseHandle(); 61 | virtual ~CDataBaseHandle(); 62 | 63 | protected: 64 | KernelInfoStruct* m_pKernelInfo; //内核数据 65 | ManageInfoStruct* m_pInitInfo; //初始化数据指针 66 | IAsynThreadResultService* m_pRusultService; //结果处理接口 67 | CDataBaseManage* m_pDataBaseManage; //数据库对象 68 | 69 | public: 70 | //设置参数 71 | virtual bool SetParameter(IAsynThreadResultService* pRusultService, CDataBaseManage* pDataBaseManage, ManageInfoStruct* pInitData, KernelInfoStruct* pKernelData); 72 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/DataLine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Lock.h" 4 | #include "InternalMessageDefine.h" 5 | 6 | // 消息队列最大字节数量 7 | const unsigned int MAX_DATALINE_LEN = 20 * 1024 * 1024; 8 | 9 | /* 10 | Struct :ListItemData 11 | Memo :链表项数据结构 12 | Parameter : 13 | stDataHead :数据包头 14 | pData :每个链表项数据的指针,使用用new方式申请的内存,注意,在出队列时,要显式的delete 该内存 15 | */ 16 | struct ListItemData 17 | { 18 | DataLineHead stDataHead; 19 | BYTE* pData; 20 | }; 21 | 22 | //数据队列类 23 | class CDataLine 24 | { 25 | private: 26 | unsigned int m_DataListSize; 27 | std::list m_DataList; 28 | CSignedLock m_csLock; 29 | 30 | public: 31 | CDataLine(); 32 | virtual ~CDataLine(); 33 | 34 | public: 35 | //清理所有数据 36 | bool CleanLineData(); 37 | //加入消息队列 38 | virtual UINT AddData(DataLineHead* pDataInfo, UINT uAddSize, UINT uDataKind, const void* pAppendData = NULL, UINT uAppendAddSize = 0); 39 | //提取消息数据 40 | virtual UINT GetData(DataLineHead** pDataBuffer); 41 | //获取队列大小 42 | size_t GetDataCount(); 43 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/Exception.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | ///***********************************************************************************************/// 4 | 5 | ///系统错误 6 | #define EX_UNKNOWN_ERROR 0 ///未知错误 7 | #define EX_VIRTUAL_MEM_LOW 1 ///虚拟内存不足 8 | #define EX_HEAP_MEM_LOW 2 ///堆内存不足 9 | 10 | //异常类 11 | class CException 12 | { 13 | protected: 14 | UINT m_uErrorCode; ///错误码 15 | bool m_bAutoDelete; ///是否自动删除 16 | char m_szMessage[255]; ///错误信息 17 | static bool m_bShowError; ///是否显示错误 18 | 19 | public: 20 | CException(const char* szErrorMessage, unsigned int uErrorCode = EX_UNKNOWN_ERROR, bool bAutoDelete = true); 21 | virtual ~CException(); 22 | 23 | public: 24 | //获取错误代码 25 | virtual UINT GetErrorCode() const; 26 | //获取错误信息 27 | virtual char const* GetErrorMessage(char* szBuffer, int iBufLength) const; 28 | //删除函数 29 | virtual bool Delete(); 30 | //设置是否显示错误 31 | static bool ShowErrorMessage(bool bShowError); 32 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/Function.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "KernelDefine.h" 4 | 5 | //时间参数 6 | typedef struct _SYSTEMTIME { 7 | int wYear; 8 | int wMonth; 9 | int wDayOfWeek; 10 | int wDay; 11 | int wHour; 12 | int wMinute; 13 | int wSecond; 14 | int wMilliseconds; 15 | long lMicroseconds; 16 | } SYSTEMTIME, * PSYSTEMTIME, * LPSYSTEMTIME; 17 | 18 | 19 | ////////////////////////////////////系统函数实现///////////////////////////////////////////// 20 | 21 | //计算数组维数 22 | #define CountArray(Array) (sizeof(Array)/sizeof(Array[0])) 23 | 24 | //安全删除指针 25 | #define SafeDelete(pData) { try { delete pData; } catch (...) { ERROR_LOG("CATCH:%s with %s\n",__FILE__,__FUNCTION__);} pData = NULL; } 26 | 27 | //安全删除指针 28 | #define SafeDeleteArray(pData) { if(pData){ try { delete [] pData; } catch (...) { ERROR_LOG("CATCH:%s with %s\n",__FILE__,__FUNCTION__);} pData = NULL;} } 29 | 30 | //安全删除指针 31 | #define SAFE_DELETE(pData) { if(pData){ try{ delete pData; } catch(...){ ERROR_LOG("CATCH: *** SAFE_DELETE(%s) crash! *** %s %d\n",#pData,__FILE__, __LINE__); } pData = nullptr; } } 32 | 33 | //获取动态数组指针大小,使用jemalloc,只有非标准类型才能使用 34 | extern int GetNewArraySize(void* pArray); 35 | 36 | //判断大小函数 37 | #define Min_(x,y) ((x)>(y)?(y):(x)) 38 | #define Max_(x,y) ((x)>(y)?(x):(y)) 39 | 40 | //获取系统时间 41 | extern void GetLocalTime(SYSTEMTIME* sysTime); 42 | 43 | //获取时间戳(单位:毫秒) 44 | extern long long GetSysMilliseconds(); 45 | 46 | //获取自系统开机以来的毫秒数 47 | extern unsigned long GetTickCount(); 48 | 49 | //获取线程pid,线程内部id pthread库函数 50 | extern pthread_t GetCurrentThreadId(); 51 | 52 | //获取线程pid,内核线程id 53 | extern pthread_t GetCurrentSysThreadId(); 54 | 55 | //根据进程名字获取进程id 56 | extern pid_t GetProcessPidByName(const char* procName); 57 | 58 | //设置守护进程 59 | void SetDaemon(); -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/GameDataBaseHandle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "AsyncEventMsg.h" 4 | 5 | //游戏数据库处理 6 | class CGameDataBaseHandle : public CDataBaseHandle 7 | { 8 | public: 9 | CGameDataBaseHandle(); 10 | virtual ~CGameDataBaseHandle(); 11 | 12 | private: 13 | virtual UINT HandleDataBase(DataBaseLineHead* pSourceData); 14 | 15 | private: 16 | // 上传录像 17 | int OnUploadVideo(DataBaseLineHead* pSourceData); 18 | // 执行sql语句 19 | int OnHandleExecuteSQLStatement(DataBaseLineHead* pSourceData); 20 | // HTTP请求 21 | int OnHandleHTTP(DataBaseLineHead* pSourceData); 22 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/GameLogManage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "Function.h" 6 | #include "Lock.h" 7 | 8 | struct LogFileElem 9 | { 10 | pthread_t threadID; 11 | int serverType; 12 | 13 | LogFileElem() 14 | { 15 | threadID = 0; 16 | serverType = 0; 17 | } 18 | 19 | bool operator<(const LogFileElem& elem)const 20 | { 21 | if (threadID < elem.threadID) 22 | { 23 | return true; 24 | } 25 | else if (serverType == elem.serverType) 26 | { 27 | if (serverType < elem.serverType) 28 | { 29 | return true; 30 | } 31 | } 32 | return false; 33 | } 34 | }; 35 | 36 | struct ThreadLogFiles 37 | { 38 | std::string errorLog; 39 | std::string costLog; 40 | 41 | void Clear() 42 | { 43 | errorLog.clear(); 44 | costLog.clear(); 45 | } 46 | }; 47 | 48 | // 游戏log管理 49 | class CGameLogManage 50 | { 51 | private: 52 | CGameLogManage(); 53 | ~CGameLogManage(); 54 | 55 | public: 56 | static CGameLogManage* Instance(); 57 | void Release(); 58 | 59 | // 外部接口添加线程日志 60 | void AddLogFile(pthread_t threadID, int threadType, int roomID = 0); 61 | // 获取对应线程的errorlog 62 | std::string GetErrorLog(pthread_t threadID); 63 | // 获取对应线程的costLog 64 | std::string GetCostLog(pthread_t threadID); 65 | 66 | // 增加指定文件的fp 67 | bool AddLogFileFp(std::string strFile, FILE* fp); 68 | // 获取指定文件的fp 69 | FILE* GetLogFileFp(std::string&& strFile); 70 | 71 | // 设置进程日志目录 72 | void SetLogPath(const std::string& path); 73 | // 获取进程日志目录 74 | std::string GetLogPath(); 75 | 76 | private: 77 | // 日志文件map 78 | std::map m_LogFilesMap; 79 | 80 | // 文件描述符map 81 | std::unordered_map m_filesFpMap; 82 | 83 | // 进程日志目录 84 | std::string m_logPath; 85 | 86 | // 线程锁 87 | CSignedLock m_csLock; 88 | }; 89 | 90 | #define GameLogManage() CGameLogManage::Instance() -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/HttpServer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "comstruct.h" 4 | #include "Interface.h" 5 | #include "Lock.h" 6 | #include "DataLine.h" 7 | #include "Exception.h" 8 | 9 | // 数据库处理类 10 | class CHttpServer 11 | { 12 | public: 13 | KernelInfoStruct* m_pKernelInfo;// 内核数据 14 | ManageInfoStruct* m_pInitInfo; // 初始化数据指针 15 | CDataLine m_DataLine; // 数据队列 16 | 17 | protected: 18 | pthread_t m_hThread; // 线程句柄 19 | bool m_bRun; // 运行标志 20 | IDataBaseHandleService* m_pHandleService; // 数据处理接口 21 | 22 | public: 23 | CHttpServer(); 24 | virtual ~CHttpServer(); 25 | 26 | public: 27 | //开始服务 28 | bool Start(); 29 | //停止服务 30 | bool Stop(); 31 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/INIFile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | #define CONFIGLEN 256 9 | 10 | enum INI_RES 11 | { 12 | INI_SUCCESS, //成功 13 | INI_ERROR, //普通错误 14 | INI_OPENFILE_ERROR, //打开文件失败 15 | INI_NO_ATTR //无对应的键值 16 | }; 17 | 18 | //构造函数 mode 字符串说明 19 | //r 以只读方式打开文件,该文件必须存在。 20 | //r + 以读 / 写方式打开文件,该文件必须存在。 21 | //rb + 以读 / 写方式打开一个二进制文件,只允许读 / 写数据。 22 | //rt + 以读 / 写方式打开一个文本文件,允许读和写。 23 | //w 打开只写文件,若文件存在则文件长度清为零,即该文件内容会消失;若文件不存在则创建该文件。 24 | //w + 打开可读 / 写文件,若文件存在则文件长度清为零,即该文件内容会消失;若文件不存在则创建该文件。 25 | //a 以附加的方式打开只写文件。若文件不存在,则会创建该文件;如果文件存在,则写入的数据会被加到文件尾后,即文件原先的内容会被保留(EOF 符保留)。 26 | //a + 以附加方式打开可读 / 写的文件。若文件不存在,则会创建该文件,如果文件存在,则写入的数据会被加到文件尾后,即文件原先的内容会被保留(EOF符不保留)。 27 | 28 | //子键索引 子键值 29 | typedef map KEYMAP; 30 | //主键索引 主键值 31 | typedef map MAINKEYMAP; 32 | 33 | // config 文件的基本操作类 34 | class CINIFile 35 | { 36 | public: 37 | // 构造函数 38 | CINIFile(string fileName, string mode = "r+"); 39 | // 析够函数 40 | virtual ~CINIFile(); 41 | public: 42 | // 判断文件是否存在 43 | static bool IsFileExist(string fileName); 44 | // 拷贝文件 45 | static void CopyFileTo(string destFileName, string srcFileName); 46 | // 获取当前目录 47 | static string GetAppPath(); 48 | // 打开config 文件 49 | INI_RES OpenFile(const char* pathName, const char* mode); 50 | // 关闭config 文件 51 | INI_RES CloseFile(); 52 | // 获取整形的键值 53 | int GetKeyVal(string secName, string keyName, int default_); 54 | // 获取无符号整形的键值 55 | UINT GetKeyVal(string secName, string keyName, UINT default_); 56 | // 获取长整形的键值 57 | long long GetKeyVal(string secName, string keyName, long long default_); 58 | // 获取double的键值 59 | double GetKeyVal(string secName, string keyName, double default_); 60 | // 获取键值的字符串 61 | string GetKeyVal(string secName, string keyName, string default_); 62 | // 设置键值的字符串 63 | void SetKeyValString(string secName, string keyName, string str); 64 | 65 | protected: 66 | // 读写config文件 67 | INI_RES GetKey(string secName, string keyName, string& value); 68 | void SetKey(string secName, string keyName, string value); 69 | protected: 70 | // 被打开的文件局柄 71 | FILE* m_fp; 72 | string m_szKey; 73 | MAINKEYMAP m_Map; 74 | bool m_bModify; 75 | }; 76 | 77 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/Interface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /********************************************************************************************/ 4 | ///服务接口定义 5 | /********************************************************************************************/ 6 | 7 | class CDataBaseManage; ///<数据库模块类 8 | struct NetMessageHead; ///<网络数据包头 9 | struct ManageInfoStruct; ///<初始化信息结构 10 | struct KernelInfoStruct; ///<内核信息结构 11 | struct DataBaseLineHead; ///<数据库队列头结构 12 | struct AsynThreadResultLine; ///<异步线程结果头结构 13 | class CDataLine; 14 | 15 | //服务器网络服务接口 16 | class IServerSocketService 17 | { 18 | ///接口函数 19 | public: 20 | //网络关闭处理 21 | virtual bool OnSocketCloseEvent(ULONG uAccessIP, UINT uIndex, UINT uConnectTime, BYTE socketType) = 0; 22 | //网络消息处理 23 | virtual bool OnSocketReadEvent(BYTE socketType, NetMessageHead* pNetHead, void* pData, UINT uSize, UINT uIndex) = 0; 24 | // 获取dataline 25 | virtual CDataLine* GetDataLine() = 0; 26 | }; 27 | 28 | ///异步线程结果服务接口 29 | class IAsynThreadResultService 30 | { 31 | ///接口函数 32 | public: 33 | ///异步线程结果处理 34 | virtual bool OnAsynThreadResultEvent(UINT uHandleKind, UINT uHandleResult, const void* pData, UINT uResultSize, UINT uIndex, UINT uMsgID) = 0; 35 | }; 36 | 37 | ///数据库处理服务接口 38 | class IDataBaseHandleService 39 | { 40 | ///接口函数 41 | public: 42 | ///设置参数 43 | virtual bool SetParameter(IAsynThreadResultService* pRusultService, CDataBaseManage* pDataBaseManage, ManageInfoStruct* pInitData, KernelInfoStruct* pKernelData) = 0; 44 | ///数据库处理接口 45 | virtual UINT HandleDataBase(DataBaseLineHead* pSourceData) = 0; 46 | }; 47 | 48 | ///组件管理接口 49 | class IModuleManageService 50 | { 51 | ///接口函数 52 | public: 53 | ///初始化函数 54 | virtual bool InitService(ManageInfoStruct* pInitData) = 0; 55 | ///取消初始化函数 56 | virtual bool UnInitService() = 0; 57 | ///初始化函数 58 | virtual bool StartService(UINT& errCode) = 0; 59 | ///初始化函数 60 | virtual bool StoptService() = 0; 61 | ///删除函数 62 | virtual bool DeleteService() = 0; 63 | ///更新函数 64 | virtual bool UpdateService() = 0; 65 | }; 66 | /********************************************************************************************/ 67 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/Lock.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CSignedLock; 4 | class CSignedLockObject 5 | { 6 | private: 7 | int m_iLockCount; //锁定计数 8 | CSignedLock* m_pLockObject; //锁定对象 9 | 10 | public: 11 | CSignedLockObject(CSignedLock* pLockObject, bool bAutoLock = true); 12 | ~CSignedLockObject(); 13 | 14 | public: 15 | void Lock(); 16 | void UnLock(); 17 | }; 18 | 19 | // pthread_mutex_init pthread_mutexattr_t 的第二个参数详细解释 20 | // PTHREAD_MUTEX_TIMED_NP,这是缺省值,也就是普通锁。当一个线程加锁以后,其余请求锁的线程将形成一个等待队列,并在解锁后按优先级获得锁。这种锁策略保证了资源分配的公平性。 21 | // PTHREAD_MUTEX_RECURSIVE_NP,嵌套锁,允许同一个线程对同一个锁成功获得多次,并通过多次unlock解锁。如果是不同线程请求,则在加锁线程解锁时重新竞争。 22 | // PTHREAD_MUTEX_ERRORCHECK_NP,检错锁,如果同一个线程请求同一个锁,则返回EDEADLK,否则与PTHREAD_MUTEX_TIMED_NP类型动作相同。这样保证当不允许多次加锁时不出现最简单情况下的死锁。 23 | // PTHREAD_MUTEX_ADAPTIVE_NP,适应锁,动作最简单的锁类型,仅等待解锁后重新竞争。 24 | 25 | class CSignedLock 26 | { 27 | friend class CSignedLockObject; 28 | 29 | private: 30 | pthread_mutex_t m_csLock; 31 | pthread_mutexattr_t m_attr; 32 | pthread_cond_t m_cond; 33 | 34 | public: 35 | CSignedLock(); 36 | ~CSignedLock(); 37 | 38 | void Notify() { pthread_cond_signal(&m_cond); } 39 | void NotifyAll() { pthread_cond_broadcast(&m_cond); } 40 | void Wait() { pthread_cond_wait(&m_cond, &m_csLock); } 41 | void TimedWait(const struct timespec* abstime) { pthread_cond_timedwait(&m_cond, &m_csLock, abstime); } 42 | 43 | private: 44 | void Lock() { pthread_mutex_lock(&m_csLock); } 45 | void UnLock() { pthread_mutex_unlock(&m_csLock); } 46 | }; 47 | 48 | /////////////////////////////管道事件/////////////////////////////////////// 49 | class CFIFOEvent 50 | { 51 | public: 52 | CFIFOEvent(const char* filename); 53 | ~CFIFOEvent() {} 54 | void WaitForEvent(); 55 | void SetEvent(); 56 | private: 57 | const char* m_fifoName; 58 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/LuaModuleInit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "lua.hpp" 4 | #include "luasocket.h" 5 | 6 | extern "C" 7 | { 8 | int luaopen_pb(lua_State* L); 9 | int luaopen_luasql_mysql(lua_State* L); 10 | } -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/MD5.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //MD5 加密类 4 | class MD5_CTX 5 | { 6 | //变量定义 7 | private: 8 | unsigned int state[4]; 9 | unsigned int count[2]; 10 | unsigned char buffer[64]; 11 | unsigned char PADDING[64]; 12 | 13 | //函数定义 14 | public: 15 | //构造函数 16 | MD5_CTX(); 17 | //析构函数 18 | virtual ~MD5_CTX(); 19 | void MD5Update ( unsigned char *input, unsigned int inputLen); 20 | void MD5Final (unsigned char digest[16]); 21 | 22 | //私有函数 23 | private: 24 | void MD5Init(); 25 | void MD5Transform (unsigned int state[4], unsigned char block[64]); 26 | void MD5_memcpy (unsigned char* output, unsigned char* input,unsigned int len); 27 | void Encode (unsigned char *output, unsigned int *input,unsigned int len); 28 | void Decode (unsigned int *output, unsigned char *input, unsigned int len); 29 | void MD5_memset (unsigned char* output,int value,unsigned int len); 30 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/MyCurl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "curl/curl.h" 6 | 7 | using namespace std; 8 | 9 | #define REMOTE_URL "ftp://%s:%s@%s/%d/%s.json" 10 | 11 | class MyCurl 12 | { 13 | public: 14 | MyCurl() {} 15 | ~MyCurl() {} 16 | 17 | typedef struct MemoryStruct 18 | { 19 | char *memory; 20 | size_t size; 21 | }tMemory; 22 | 23 | int getUrl(const string &url, const vector &vUrlHeader, string &result, bool bSSLCert = false); 24 | int postUrl(const string &url, const vector &vUrlHeader, const string &postFields, string &result, bool bSSLCert = false); 25 | int postUrlHttps(const string &url, const vector &vUrlHeader, const string &postFields, string &result, bool bSSLCert = false); 26 | static size_t parseStreamCallback(void *contents, size_t length, size_t nmemb, void *userp); 27 | static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp); 28 | static size_t getcontentlengthfunc(void *ptr, size_t size, size_t nmemb, void *stream); 29 | static size_t discardfunc(void *ptr, size_t size, size_t nmemb, void *stream); 30 | static size_t readfunc(void *ptr, size_t size, size_t nmemb, void *stream); 31 | int uploadUrl(const char *videocode, int gameID, int timeout, int tries); 32 | 33 | static string RsaPrivateKey; 34 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/RRlockQueue.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file RRlockQueue.h 3 | * @brief 环形缓冲区,支持多线程写、单线程读 4 | * @author luotan 5 | * @date 2020-08-08 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "InternalMessageDefine.h" 11 | #include "UnlockQueue.h" 12 | 13 | // 消息队列最大字节数量 14 | #define MAX_UNLOCKQUEUE_LEN (8 * 1024 * 1024) 15 | // 消息队列最大单包长度 16 | #define MAX_SINGLE_UNLOCKQUEUE_SIZE (256 * 1024) 17 | 18 | class RRlockQueue 19 | { 20 | 21 | public: 22 | RRlockQueue(QueueType qType = QUEUE_TYPE_SLEEP, unsigned int nTimeOnce = QUEUE_TIME_ONCE); 23 | virtual ~RRlockQueue(); 24 | 25 | public: 26 | //清理所有数据 27 | bool CleanLineData(); 28 | //加入消息队列 29 | virtual UINT AddData(DataLineHead* pDataInfo, UINT uAddSize, UINT uDataKind, const void* pAppendData = NULL, UINT uAppendAddSize = 0); 30 | //提取消息数据 31 | virtual UINT GetData(DataLineHead** pDataBuffer); 32 | //获取队列已经存储的数据大小(字节数) 33 | UINT GetDataCount(); 34 | 35 | private: 36 | pthread_mutex_t m_csLock; /* 互斥锁,控制写线程同步 */ 37 | UnlockQueue* m_pUnLockQueue; 38 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/RedisCenter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "RedisCommon.h" 4 | 5 | class CRedisCenter : public CRedisCommon 6 | { 7 | public: 8 | CRedisCenter(); 9 | virtual ~CRedisCenter(); 10 | 11 | public: 12 | // 初始化 13 | virtual bool Init(); 14 | // 关闭 15 | virtual bool Stop(); 16 | 17 | public: 18 | // bUnBind表示是否解绑 19 | bool SetUserPhone(int userID, const char* phone, bool bUnBind = false); 20 | 21 | // 闲聊绑定 22 | bool SetUserXianLiao(int userID, const char* xianliao); 23 | 24 | // 设置游戏服状态 25 | bool SetRoomServerStatus(int roomID, int status); 26 | 27 | // 设置登陆服状态 28 | bool SetLogonServerStatus(int logonID, int status); 29 | 30 | // 设置封号时间 31 | bool SetUserSealTime(int userID, int time); 32 | 33 | private: 34 | int NeedLoadAllUserData(); //判断是否需要加载数据库中所有用户数据到redis,0:不需要,1:需要,>1:异常错误 35 | bool LoadAllUserData(); //加载所有用户 36 | bool LoadAllRewardsPoolData(); //加载所有游戏奖池 37 | bool LoadAllAgentUser(); //加载所有代理 38 | bool LoadAllConfig(); //加载系统所有配置到redis 39 | bool LoadAllUserBag(); //加载用户背包数据 40 | 41 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/RedisLoader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "RedisCommon.h" 4 | 5 | class CRedisLoader : public CRedisCommon 6 | { 7 | public: 8 | CRedisLoader(); 9 | virtual ~CRedisLoader(); 10 | 11 | public: 12 | virtual bool Init(); 13 | virtual bool Stop(); 14 | 15 | //删除桌子 16 | bool DelPrivateDeskRecord(int deskMixID); 17 | void DelUserBuyDeskInfoInSet(int userID, const char* passwd); 18 | 19 | //记录人数信息 20 | bool SetPrivateDeskCurrUserCount(int deskMixID, int userCount); 21 | bool SetPrivateDeskCurrWatchUserCount(int deskMixID, int watchUserCount); 22 | 23 | //设置开房玩家列表 24 | bool SetPrivateDeskUserID(int deskMixID, int userID, int type);//0新增,1删除 25 | 26 | //胜局数相关 27 | bool SetUserWinCount(int userID); 28 | bool SetUserTotalGameCount(int userID); 29 | 30 | //设置桌子游戏局数 31 | bool SetPrivateDeskGameCount(int deskMixID, int gameCount); 32 | 33 | //生成战绩 34 | bool SetPrivateDeskGrade(GameGradeInfo& gameGradeInfo, long long& gradeID); 35 | bool SetPrivateDeskSimpleInfo(const std::vector& userIDVec, PrivateDeskGradeSimpleInfo& simpleInfo, const std::vector& gradeIDVec); 36 | 37 | //机器人索引 38 | int GetRobotInfoIndex(); 39 | 40 | //设置当前房间人数 41 | bool SetRoomServerPeopleCount(int roomID, int peopleCount); 42 | 43 | //关服保存桌子 44 | bool SaveFGDeskRoom(const PrivateDeskInfo &privateDeskInfo); 45 | 46 | //开服清理桌子 47 | bool CleanRoomAllData(int roomID); 48 | 49 | //获取房间所有创建的桌子 50 | bool GetAllDesk(int roomID, std::vector& vecRooms); 51 | 52 | // 设置超时数据 53 | bool SetPrivateDeskCheckTime(int deskMixID, int checkTime); 54 | 55 | //获取玩家控制参数 56 | bool GetUserControlParam(int userID, int &value); 57 | 58 | //比赛场 59 | long long GetPartOfMatchIndex(); 60 | bool DelFullPeopleMatchPeople(int gameID, int matchID, const std::vector &vecPeople); 61 | bool SetUserMatchStatus(int userID, BYTE matchType, int matchStatus); 62 | bool SetUserMatchRank(int userID, long long combineMatchID, int curMatchRank); 63 | bool SetTimeMatchPeopleRank(int matchID, const std::vector &vecPeople); 64 | int GetRobotUserID(); 65 | private: 66 | long long GetRoomMaxGradeIndex(int roomID); 67 | long long GetRoomMaxSimpleGradeIndex(int roomID); 68 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/RedisPHP.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "RedisBase.h" 4 | 5 | class CRedisPHP : public CRedisBase 6 | { 7 | public: 8 | CRedisPHP(); 9 | virtual ~CRedisPHP(); 10 | 11 | public: 12 | // 初始化 13 | virtual bool Init(); 14 | // 关闭 15 | virtual bool Stop(); 16 | // 获取redis Context 17 | redisContext* GetRedisContext(); 18 | public: 19 | /////////////////////////////////俱乐部相关///////////////////////////////////////// 20 | bool GetFGMember(int friendsGroupID, std::vector &memberUserIDVec); 21 | // 获取玩家俱乐部金币 22 | bool GetUserFriendsGroupMoney(int friendsGroupID, int userID, long long &money); 23 | // 设置玩家俱乐部金币 24 | bool SetUserFriendsGroupMoney(int friendsGroupID, int userID, long long money, bool bAdd = true, int reason = 0, int roomID = 0, int rateFireCoin = 0); 25 | // 获取玩家权限 26 | int GetUserPower(int friendsGroupID, int userID); 27 | // 获取俱乐部群主 28 | int GetFriendsGroupMasterID(int friendsGroupID); 29 | // 是否可以加入俱乐部房间 30 | bool IsCanJoinFriendsGroupRoom(int userID, int friendsGroupID); 31 | // 设置玩家俱乐部资源数量 32 | bool SetUserFriendsGroupResNums(int friendsGroupID, int userID, const char * resName, long long resNums, bool bAdd = false); 33 | // 获取通知时间 34 | bool GetFGNotifySendTime(long long llIndex, time_t &sendTime); 35 | // 清理玩家俱乐部通知 36 | void ClearUserFGNotifySet(int userID); 37 | // 清理所有通知 38 | void ClearAllFGNotifyInfo(); 39 | //获取俱乐部绑定的管理员ID 40 | bool GetfriendsGroupToUser(int friendsGroupID, int userID, int &ChouShui, int&ManagerId); 41 | 42 | 43 | /////////////////////////////////邮件模块///////////////////////////////////////// 44 | bool GetEmailSendTime(long long llIndex, int &sendTime); 45 | bool GetUserAllEmailID(int userID, std::vector &simpleEmailID, bool Asc = true); 46 | bool DelUserEmailInfo(int userID, long long emailID); 47 | void ClearUserEmailSet(int userID); 48 | void ClearAllEmailInfo(); 49 | 50 | //////////////////////////////////数据统计//////////////////////////////////////// 51 | long long AddUserResNums(int userID, const char * resName, long long changeResNums); 52 | 53 | //////////////////////////////////比赛场//////////////////////////////////////// 54 | // 将redis比赛信息,加载到内存 55 | bool LoadAllMatchInfo(std::map & matchInfoMap); 56 | // 获取比赛信息 57 | bool GetMatchInfo(int matchID, MatchInfo& matchInfo); 58 | // 设置比赛状态 59 | bool SetMatchStatus(int matchID, BYTE matchStatus); 60 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/ServerTimer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | 7 | #define MAX_TIMER_THRED_NUMS 4 // 定时器最大线程数量 8 | 9 | enum SERVERTIMER_TYPE 10 | { 11 | SERVERTIMER_TYPE_PERISIST = 0, // 持久定时器 12 | SERVERTIMER_TYPE_SINGLE, // 一次性定时器 13 | }; 14 | 15 | struct ServerTimerInfo 16 | { 17 | unsigned int elapse; // 定时器间隔(单位毫秒) 18 | long long starttime; // 起始时间(单位毫秒) 19 | BYTE timertype; // 定时器类型 SERVERTIMER_TYPE 20 | ServerTimerInfo() 21 | { 22 | elapse = 10; 23 | starttime = 0; 24 | timertype = SERVERTIMER_TYPE_PERISIST; 25 | } 26 | }; 27 | 28 | class CDataLine; 29 | class CSignedLock; 30 | class CServerTimer 31 | { 32 | public: 33 | CServerTimer(); 34 | ~CServerTimer(); 35 | bool Start(CDataLine* pDataLine, int timeonce = 100); 36 | bool Stop(); 37 | bool SetTimer(unsigned int uTimerID, unsigned int uElapse, BYTE timerType = SERVERTIMER_TYPE_PERISIST); //uElapse是毫秒单位,大于100ms 38 | bool KillTimer(unsigned int uTimerID); 39 | bool ExistsTimer(unsigned int uTimerID); 40 | 41 | private: 42 | // 定时器执行函数 43 | static void TimeoutCB(evutil_socket_t fd, short event, void* arg); 44 | // 定时器线程函数 45 | static void* ThreadCheckTimer(void* pThreadData); 46 | 47 | private: 48 | bool m_bRun; 49 | std::unordered_map m_timerMap; 50 | CDataLine* m_pDataLine; // 共享的dataline对象 51 | CSignedLock* m_pLock; // 线程锁 52 | int m_timeOnce; 53 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/TcpConnect.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | const int CLIENT_SOCKET_SEND_BUF = 64 * 1024; // 应用层发送缓冲区大小 4 | const int CLIENT_SOCKET_RECV_BUF = 256 * 1024; // 应用层接收缓冲区大小 5 | 6 | class CDataLine; 7 | class CTcpConnect; 8 | class CSignedLock; 9 | class CTcpClient 10 | { 11 | public: 12 | CTcpClient(); 13 | ~CTcpClient(); 14 | 15 | public: 16 | bool SetDataLine(CDataLine* pDataLine); 17 | bool SetTcpConnect(CTcpConnect* pCTcpConnect); 18 | void SetIndex(int index) { m_index = index; } 19 | int GetSocketIdx(); 20 | 21 | // 是否有效 22 | bool Enable(); 23 | bool OnRead(); 24 | 25 | bool Send(const void* pData, int size); 26 | 27 | bool OnClose(); 28 | 29 | void SetSocket(int sock) { m_socket = sock; } 30 | void SetConnection(bool isConneted) { m_isConnected = true; } 31 | 32 | bool IsConnected() { return m_isConnected; } 33 | 34 | int GetSocket() { return m_socket; } 35 | int GetRemainSendBufSize() { return m_remainSendBytes; } 36 | 37 | // 清空非永久属性(初始化或者重新启用一个对象调用) 38 | void Clear(); 39 | private: 40 | int m_index; 41 | int m_socket; 42 | bool m_isConnected; 43 | 44 | char m_recvBuf[CLIENT_SOCKET_RECV_BUF]; 45 | int m_remainRecvBytes; 46 | 47 | char m_sendBuf[CLIENT_SOCKET_SEND_BUF]; 48 | int m_remainSendBytes; 49 | 50 | CDataLine* m_pDataLine; //共享的dataline对象 51 | CSignedLock m_lock; 52 | CTcpConnect* m_pTcpConnect; //共享管理类 53 | }; 54 | 55 | class CTcpConnect 56 | { 57 | public: 58 | CTcpConnect(); 59 | ~CTcpConnect(); 60 | 61 | bool Start(CDataLine* pDataLine, const char* ip, int port, int serverType, int serverID); 62 | bool Stop(); 63 | 64 | bool Connect(); 65 | bool Send(UINT msgID, const void* pData, UINT size, int userID = 0, NetMessageHead * pNetHead = NULL); 66 | 67 | bool EventLoop(); 68 | bool CheckConnection(); //return ,连接状态:true,非连接状态:false 69 | 70 | bool ReStart(); 71 | private: 72 | char m_ip[24]; 73 | int m_port; 74 | CTcpClient m_tcpClient; 75 | CDataLine* m_pDataLine; 76 | int m_connectServerID; 77 | int m_connectServerType; 78 | bool m_bStart; 79 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/UnlockQueue.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file UnlockQueue.h 3 | * @brief 并发无锁队列。只适用于:单线程读、单线程写 4 | * @author luotan 5 | * @date 2020-08-06 6 | */ 7 | #ifndef _UNLOCK_QUEUE_H 8 | #define _UNLOCK_QUEUE_H 9 | 10 | #include 11 | 12 | enum QueueType 13 | { 14 | QUEUE_TYPE_NO = 0, // 无类型 cpu使用率200% 15 | QUEUE_TYPE_COND = 1, // 条件变量通知 cpu使用率190% 16 | QUEUE_TYPE_SLEEP = 2, // 线程休眠 cpu使用率200% 17 | }; 18 | 19 | #define QUEUE_TIME_ONCE 10000000 // 单位:纳秒 20 | 21 | class UnlockQueue 22 | { 23 | public: 24 | UnlockQueue(unsigned int nSize, QueueType qType = QUEUE_TYPE_COND, unsigned int nTimeOnce = QUEUE_TIME_ONCE); 25 | virtual ~UnlockQueue(); 26 | 27 | bool Initialize(); 28 | 29 | unsigned int Put(const unsigned char* pBuffer, unsigned int nLen); 30 | unsigned int Put(const unsigned char* pBufferHead, unsigned int nLenHead, const unsigned char* pBufferData, unsigned int nLenData); 31 | unsigned int Get(unsigned char* pBuffer, unsigned int nLen); 32 | 33 | inline void Clean() { m_nIn = m_nOut = 0; } 34 | inline unsigned int GetDataLen() const { return m_nIn - m_nOut; } 35 | inline unsigned int GetSize() { return m_nSize; } 36 | inline unsigned int GetRemainDataLen() { return m_nSize - m_nIn + m_nOut; } 37 | 38 | private: 39 | inline bool is_power_of_2(unsigned long n) { return (n != 0 && ((n & (n - 1)) == 0)); }; 40 | inline unsigned long roundup_power_of_two(unsigned long val); 41 | 42 | private: 43 | unsigned char* m_pBuffer; /* the buffer holding the data */ 44 | unsigned int m_nSize; /* the size of the allocated buffer */ 45 | unsigned int m_nIn; /* data is added at offset (in % size) */ 46 | unsigned int m_nOut; /* data is extracted from off. (out % size) */ 47 | QueueType m_qType; /* 队列类型 */ 48 | pthread_cond_t m_cond; /* 条件变量 */ 49 | pthread_mutex_t m_csLock; /* 互斥锁,配合条件变量使用 */ 50 | unsigned int m_nTimeOnce; /* 无消息的时候,休眠间隔,纳秒 */ 51 | }; 52 | 53 | #endif -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/Xor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | // 对称加密 6 | class Xor 7 | { 8 | public: 9 | static uint8_t* Encrypt(uint8_t* content, int length); 10 | 11 | static uint8_t* Decrypt(uint8_t* content, int length); 12 | }; 13 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/base64.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | #define SHA256_ROTL(a,b) (((a>>(32-b))&(0x7fffffff>>(31-b)))|(a<>b)&(0x7fffffff>>(b-1))) 12 | #define SHA256_Ch(x,y,z) ((x&y)^((~x)&z)) 13 | #define SHA256_Maj(x,y,z) ((x&y)^(x&z)^(y&z)) 14 | #define SHA256_E0(x) (SHA256_ROTL(x,30)^SHA256_ROTL(x,19)^SHA256_ROTL(x,10)) 15 | #define SHA256_E1(x) (SHA256_ROTL(x,26)^SHA256_ROTL(x,21)^SHA256_ROTL(x,7)) 16 | #define SHA256_O0(x) (SHA256_ROTL(x,25)^SHA256_ROTL(x,14)^SHA256_SR(x,3)) 17 | #define SHA256_O1(x) (SHA256_ROTL(x,15)^SHA256_ROTL(x,13)^SHA256_SR(x,10)) 18 | 19 | typedef unsigned char uint8_t; 20 | typedef unsigned short int uint16_t; 21 | typedef unsigned int uint32_t; 22 | 23 | #define SHA1_DIGEST_SIZE 20 24 | 25 | std::string base64_encode(unsigned char const* , unsigned int len); 26 | std::string base64_decode(std::string const& s); 27 | 28 | 29 | char* StrSHA256(const char* str, long long length, char* sha256); 30 | 31 | void crypt_sha1(uint8_t* buffer, int sz, uint8_t* output, int* e_sz); 32 | 33 | 34 | #define ZDBG 0 35 | #define SHFR(x, n) (((x) >> (n))) 36 | #define ROTR(x, n) (((x) >> (n)) | ((x) << ((sizeof(x) << 3) - (n)))) 37 | #define ROTL(x, n) (((x) << (n)) | ((x) >> ((sizeof(x) << 3) - (n)))) 38 | 39 | #define CHX(x, y, z) (((x) & (y)) ^ (~(x) & (z))) 40 | #define MAJ(x, y, z) (((x) & (y)) ^ ( (x) & (z)) ^ ((y) & (z))) 41 | 42 | #define BSIG0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) 43 | #define BSIG1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) 44 | #define SSIG0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHFR(x, 3)) 45 | #define SSIG1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHFR(x, 10)) 46 | 47 | #define SHA256_BLOCK_SIZE (512/8) 48 | #define SHA256_COVER_SIZE (SHA256_BLOCK_SIZE*2) 49 | 50 | 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | int zsha256(const uint8_t *src, uint32_t len, uint32_t *hash); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/basemessage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | /********************************************************************************************/ 5 | // 系统内核使用 (MAINID 使用 0 - 49 ) 6 | /********************************************************************************************/ 7 | ///连接消息 8 | #define MDM_CONNECT 1 ///连接消息类型 9 | #define ASS_CONNECT_SUCCESS 3 ///连接成功 10 | 11 | /********************************************************************************************/ 12 | #pragma pack(1) 13 | //网络数据包结构头 14 | /* 15 | 关于uIdentification的说明: 16 | 1、前端 -------> logonserver 或 logonserver -------> 前端, uIdentification = roomID 17 | 2、logonserver -----> gameserver 或 gameserver -----> logonserver,uIdentification = userID 18 | */ 19 | struct NetMessageHead 20 | { 21 | UINT uMessageSize; ///数据包大小 22 | UINT uMainID; ///处理主类型 23 | UINT uAssistantID; ///辅助处理类型 ID 24 | UINT uHandleCode; ///数据包处理代码 25 | UINT uIdentification; ///身份标识(不同的协议里面有不同的含义) 26 | 27 | NetMessageHead() 28 | { 29 | memset(this, 0, sizeof(NetMessageHead)); 30 | } 31 | }; 32 | 33 | struct WebSocketMsg 34 | { 35 | uint8_t fin; 36 | uint8_t opcode; 37 | uint8_t mask; 38 | uint8_t maskingKey[4]; 39 | uint32_t dataLength; //数据包总长度 40 | uint32_t payloadLength; //数据部分长度,不包含包头 41 | char* payload; //数据部分起始地址 42 | 43 | WebSocketMsg() 44 | { 45 | Init(); 46 | } 47 | 48 | void Init() 49 | { 50 | fin = 0; 51 | opcode = 0; 52 | mask = 0; 53 | maskingKey[0] = 0; 54 | dataLength = 0; 55 | payloadLength = 0; 56 | payload = nullptr; 57 | } 58 | }; 59 | 60 | //中心服包头 61 | struct CenterServerMessageHead 62 | { 63 | UINT msgID; // ID 64 | int userID; // 用户ID或者俱乐部id 65 | CenterServerMessageHead() 66 | { 67 | memset(this, 0, sizeof(CenterServerMessageHead)); 68 | } 69 | }; 70 | 71 | // 中心服务器消息头 72 | struct PlatformMessageHead 73 | { 74 | NetMessageHead MainHead; //主包头 75 | CenterServerMessageHead AssHead; //副包头 76 | 77 | PlatformMessageHead() 78 | { 79 | memset(this, 0, sizeof(PlatformMessageHead)); 80 | } 81 | }; 82 | 83 | #pragma pack() -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/comstruct.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #pragma pack(1) 4 | 5 | ///游戏组件信息结构 (服务器动态库组件获取) 6 | struct ServerDllInfoStruct 7 | { 8 | ///游戏组件信息 9 | UINT uServiceVer; ///服务版本 10 | UINT uNameID; ///游戏名字 ID 11 | UINT uSupportType; ///支持类型 12 | UINT uDeskPeople; ///游戏人数 13 | char szGameName[61]; ///游戏名字 14 | char szGameTable[61]; ///数据库表名字 15 | char szDLLFileName[61]; ///文件名字 16 | 17 | ///辅助信息 18 | char szWriter[61]; ///软件开发者 19 | char szDllNote[51]; ///备注信息 20 | }; 21 | 22 | //公共组件加载信息结构 (服务器设置数据) 23 | struct ManageInfoStruct 24 | { 25 | bool bPrivate; //是否私有房 26 | char szGameTable[31]; ///信息表名字 27 | char szGameRoomName[61]; ///服务器名字 28 | ///游戏信息 29 | UINT uNameID; ///游戏名字 ID 30 | ///设置信息 31 | UINT uComType; ///游戏类型 32 | UINT uDeskType; ///游戏桌类型,主要为添加百家乐桌 33 | UINT uBasePoint; ///游戏基础分 34 | UINT uLessPoint; ///游戏的最少分数 35 | UINT uMaxPoint; ///游戏的最大分数 36 | UINT uMaxLimite; ///最大封顶值 37 | UINT uRunPublish; ///逃跑扣分 38 | UINT uTax; ///税收比例 39 | UINT uListenPort; ///监听端口 40 | UINT uMaxPeople; ///最大连接数目 41 | char szCenterIP[24]; ///中心服ip 42 | ///服务器信息 43 | UINT uRoomID; ///游戏服务器 ID 号码 44 | int iRoomType; ///房间类型 45 | int iRoomSort; ///房间分类 46 | int iRoomLevel; ///房间等级 47 | UINT uDeskCount; ///游戏桌数目 48 | char bCanCombineDesk; ///是否可以组桌 49 | 50 | ManageInfoStruct() 51 | { 52 | memset(this, 0, sizeof(ManageInfoStruct)); 53 | } 54 | }; 55 | 56 | //内核数据 (服务器 动态库 组件启动设置) 57 | struct KernelInfoStruct 58 | { 59 | UINT uNameID; //游戏名字 ID 号码 60 | UINT uDeskPeople; //游戏人数 61 | BYTE bMaxVer; //软件最高版本 62 | BYTE bLessVer; //软件最低版本 63 | BYTE bStartTCPSocket; //是否启动网络 64 | UINT uTimerCount; //定时器数量 65 | 66 | KernelInfoStruct() 67 | { 68 | memset(this, 0, sizeof(KernelInfoStruct)); 69 | } 70 | }; 71 | 72 | #pragma pack() 73 | 74 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/gameUserManage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Define.h" 4 | 5 | // 玩家状态 6 | enum UserStatus 7 | { 8 | USER_STATUS_DEFAULT = 0, // 默认状态 9 | USER_STATUS_WATCH, // 旁观状态 10 | USER_STATUS_SITING, // 坐下 11 | USER_STATUS_AGREE, // 同意 12 | USER_STATUS_PLAYING, // 游戏中 13 | USER_STATUS_STAND, // 站起 14 | }; 15 | 16 | // 游戏玩家信息 17 | struct GameUserInfo 18 | { 19 | int userID; 20 | int socketIdx; 21 | bool IsOnline; // 是否在线 22 | int deskIdx; // 玩家所在的deskIdx (在玩家坐下的时候设置) 23 | BYTE deskStation; // 玩家的座位 24 | int playStatus; // 玩家状态 25 | long long money; // 玩家金币 26 | int jewels; // 玩家钻石 27 | char name[MAX_USER_NAME_LEN]; // 玩家昵称 28 | char headURL[MAX_USER_HEADURL_LEN]; 29 | char longitude[12]; // 经度 30 | char latitude[12]; // 纬度 31 | char address[64]; // 地址 32 | BYTE userStatus; // 玩家身份 33 | char ip[24]; 34 | BYTE isVirtual; // 是否虚拟 35 | BYTE sex; 36 | BYTE choiceDeskStation; // 玩家想选择的座位 37 | int fireCoin; // 玩家俱乐部火币 38 | char motto[128]; // 个性签名 39 | time_t lastOperateTime; // 上次操作时间 40 | int matchSocre; // 比赛积分 41 | int watchDeskIdx; // 旁观的桌子 42 | 43 | GameUserInfo() 44 | { 45 | Clear(); 46 | } 47 | 48 | void Clear() 49 | { 50 | memset(this, 0, sizeof(GameUserInfo)); 51 | socketIdx = -1; 52 | deskIdx = INVALID_DESKIDX; 53 | deskStation = INVALID_DESKSTATION; 54 | choiceDeskStation = INVALID_DESKSTATION; 55 | lastOperateTime = 0; 56 | } 57 | }; 58 | 59 | // 游戏玩家管理类, 管理一个游戏中玩家的信息 60 | class CGameMainManage; 61 | class CGameUserManage 62 | { 63 | public: 64 | CGameUserManage(); 65 | ~CGameUserManage(); 66 | 67 | void Release(); 68 | 69 | public: 70 | bool Init(); 71 | bool UnInit(); 72 | 73 | public: 74 | GameUserInfo* GetUser(int userID); 75 | bool AddUser(GameUserInfo* pUser); 76 | void DelUser(int userID); 77 | bool IsUserOnLine(int userID); 78 | void CheckInvalidStatusUser(CGameMainManage* pManage); 79 | int GetOnlineUserCount(); 80 | int GetUserCount(); 81 | 82 | private: 83 | std::unordered_map m_gameUserInfoMap; 84 | }; -------------------------------------------------------------------------------- /linuxserverplatform/src/include/ServerCommon/shmem.h: -------------------------------------------------------------------------------- 1 | #ifndef _SHMEM_H_ 2 | #define _SHMEM_H_ 3 | 4 | #include 5 | 6 | typedef struct ShmRecordNode 7 | { 8 | int iIdx; 9 | int iShmKey; 10 | unsigned int dwTotalSize; 11 | unsigned int dwNeedSize; 12 | }tagShmRecordNode; 13 | 14 | typedef std::vector ShmRecordInfoVec; 15 | 16 | 17 | //共享内存启动模式 18 | enum ENMShmStartMode 19 | { 20 | ESSM_Init = 1, //全新,即原来没有共享内存新创建 21 | ESSM_Resume = 2, //恢复,即共享原来已经存在,恢复使用 22 | }; 23 | 24 | #define MAX_KEY_TO_ADDRESS_NUM 50 //最大共享内存块个数 25 | 26 | //共享内存到进程空间地址的映射 27 | struct STShmKeyToAddress 28 | { 29 | int m_iKey; //标识key 30 | int m_iSize; //共享内存大小 31 | ENMShmStartMode m_enmStartMode; //启动模式 32 | void* m_vpMemAddr; //对应的地址 33 | unsigned int m_uiOffset; //当前已分配的偏移 34 | int m_iCount; //申请共享内存次数统计 35 | }; 36 | 37 | class CShmem 38 | { 39 | 40 | public: 41 | CShmem(); 42 | ~CShmem(); 43 | 44 | void* CreateShmem(const int aiKey, const unsigned int aiTotalSize, const unsigned int aiNeedSize, const char* pFile, int iLine, int aiMode = 0666); 45 | 46 | int DestroyShmem(const int aiKey, const unsigned int aiTotalSize); 47 | 48 | ENMShmStartMode GetStartFlag(const int aiKey, const int aiTotalSize); 49 | 50 | static void RecordShmInfo(int iShmKey, unsigned int dwTotalSize, unsigned int dwNeedSize); 51 | static void LogShmInfo(); 52 | 53 | private: 54 | 55 | //通过共享内存的key和大小获得其进程空间指针 56 | static STShmKeyToAddress* FindAddrOfKey(const int aiKey, const int aiTotalSize); 57 | //增加一个共享内存的key和大小与其进程空间指针的对应关系 58 | static int AddOneKeyToAddress(STShmKeyToAddress& stKeyToAddr); 59 | //删除一个共享内存的key和大小与其进程空间指针的对应关系 60 | static int DelOneKeyToAddress(const int aiKey, const int aiTotalSize); 61 | 62 | private: 63 | 64 | static int ms_iKeyToAddrNum; //当前已经存在的共享内存个数 65 | static STShmKeyToAddress ms_stKeyToAddr[MAX_KEY_TO_ADDRESS_NUM]; //共享内存到地址数组 66 | 67 | static ShmRecordInfoVec m_ShmRecordInfoVec; 68 | static bool m_bShmRecordInfoVecInit; 69 | 70 | }; 71 | 72 | 73 | #endif 74 | 75 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/curl/mprintf.h: -------------------------------------------------------------------------------- 1 | #ifndef CURLINC_MPRINTF_H 2 | #define CURLINC_MPRINTF_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2019, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at https://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | #include 26 | #include /* needed for FILE */ 27 | #include "curl.h" /* for CURL_EXTERN */ 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | CURL_EXTERN int curl_mprintf(const char *format, ...); 34 | CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...); 35 | CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...); 36 | CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength, 37 | const char *format, ...); 38 | CURL_EXTERN int curl_mvprintf(const char *format, va_list args); 39 | CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args); 40 | CURL_EXTERN int curl_mvsprintf(char *buffer, const char *format, va_list args); 41 | CURL_EXTERN int curl_mvsnprintf(char *buffer, size_t maxlength, 42 | const char *format, va_list args); 43 | CURL_EXTERN char *curl_maprintf(const char *format, ...); 44 | CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* CURLINC_MPRINTF_H */ 51 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/curl/stdcheaders.h: -------------------------------------------------------------------------------- 1 | #ifndef CURLINC_STDCHEADERS_H 2 | #define CURLINC_STDCHEADERS_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2019, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at https://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | #include 26 | 27 | size_t fread(void *, size_t, size_t, FILE *); 28 | size_t fwrite(const void *, size_t, size_t, FILE *); 29 | 30 | int strcasecmp(const char *, const char *); 31 | int strncasecmp(const char *, const char *, size_t); 32 | 33 | #endif /* CURLINC_STDCHEADERS_H */ 34 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/json/autolink.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_AUTOLINK_H_INCLUDED 2 | # define JSON_AUTOLINK_H_INCLUDED 3 | 4 | # include "config.h" 5 | 6 | # ifdef JSON_IN_CPPTL 7 | # include 8 | # endif 9 | 10 | # if !defined(JSON_NO_AUTOLINK) && !defined(JSON_DLL_BUILD) && !defined(JSON_IN_CPPTL) 11 | # define CPPTL_AUTOLINK_NAME "json" 12 | # undef CPPTL_AUTOLINK_DLL 13 | # ifdef JSON_DLL 14 | # define CPPTL_AUTOLINK_DLL 15 | # endif 16 | # include "autolink.h" 17 | # endif 18 | 19 | #endif // JSON_AUTOLINK_H_INCLUDED 20 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/json/config.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_CONFIG_H_INCLUDED 2 | # define JSON_CONFIG_H_INCLUDED 3 | 4 | /// If defined, indicates that json library is embedded in CppTL library. 5 | //# define JSON_IN_CPPTL 1 6 | 7 | /// If defined, indicates that json may leverage CppTL library 8 | //# define JSON_USE_CPPTL 1 9 | /// If defined, indicates that cpptl vector based map should be used instead of std::map 10 | /// as Value container. 11 | //# define JSON_USE_CPPTL_SMALLMAP 1 12 | /// If defined, indicates that Json specific container should be used 13 | /// (hash table & simple deque container with customizable allocator). 14 | /// THIS FEATURE IS STILL EXPERIMENTAL! 15 | //# define JSON_VALUE_USE_INTERNAL_MAP 1 16 | /// Force usage of standard new/malloc based allocator instead of memory pool based allocator. 17 | /// The memory pools allocator used optimization (initializing Value and ValueInternalLink 18 | /// as if it was a POD) that may cause some validation tool to report errors. 19 | /// Only has effects if JSON_VALUE_USE_INTERNAL_MAP is defined. 20 | //# define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1 21 | 22 | /// If defined, indicates that Json use exception to report invalid type manipulation 23 | /// instead of C assert macro. 24 | # define JSON_USE_EXCEPTION 1 25 | 26 | # ifdef JSON_IN_CPPTL 27 | # include 28 | # ifndef JSON_USE_CPPTL 29 | # define JSON_USE_CPPTL 1 30 | # endif 31 | # endif 32 | 33 | # ifdef JSON_IN_CPPTL 34 | # define JSON_API CPPTL_API 35 | # elif defined(JSON_DLL_BUILD) 36 | # define JSON_API __declspec(dllexport) 37 | # elif defined(JSON_DLL) 38 | # define JSON_API __declspec(dllimport) 39 | # else 40 | # define JSON_API 41 | # endif 42 | 43 | #endif // JSON_CONFIG_H_INCLUDED 44 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/json/features.h: -------------------------------------------------------------------------------- 1 | #ifndef CPPTL_JSON_FEATURES_H_INCLUDED 2 | # define CPPTL_JSON_FEATURES_H_INCLUDED 3 | 4 | # include "forwards.h" 5 | 6 | namespace Json { 7 | 8 | /** \brief Configuration passed to reader and writer. 9 | * This configuration object can be used to force the Reader or Writer 10 | * to behave in a standard conforming way. 11 | */ 12 | class JSON_API Features 13 | { 14 | public: 15 | /** \brief A configuration that allows all features and assumes all strings are UTF-8. 16 | * - C & C++ comments are allowed 17 | * - Root object can be any JSON value 18 | * - Assumes Value strings are encoded in UTF-8 19 | */ 20 | static Features all(); 21 | 22 | /** \brief A configuration that is strictly compatible with the JSON specification. 23 | * - Comments are forbidden. 24 | * - Root object must be either an array or an object value. 25 | * - Assumes Value strings are encoded in UTF-8 26 | */ 27 | static Features strictMode(); 28 | 29 | /** \brief Initialize the configuration like JsonConfig::allFeatures; 30 | */ 31 | Features(); 32 | 33 | /// \c true if comments are allowed. Default: \c true. 34 | bool allowComments_; 35 | 36 | /// \c true if root must be either an array or an object value. Default: \c false. 37 | bool strictRoot_; 38 | }; 39 | 40 | } // namespace Json 41 | 42 | #endif // CPPTL_JSON_FEATURES_H_INCLUDED 43 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/json/forwards.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_FORWARDS_H_INCLUDED 2 | # define JSON_FORWARDS_H_INCLUDED 3 | 4 | # include "config.h" 5 | 6 | namespace Json { 7 | 8 | // writer.h 9 | class FastWriter; 10 | class StyledWriter; 11 | 12 | // reader.h 13 | class Reader; 14 | 15 | // features.h 16 | class Features; 17 | 18 | // value.h 19 | typedef int Int; 20 | typedef unsigned int UInt; 21 | class StaticString; 22 | class Path; 23 | class PathArgument; 24 | class Value; 25 | class ValueIteratorBase; 26 | class ValueIterator; 27 | class ValueConstIterator; 28 | #ifdef JSON_VALUE_USE_INTERNAL_MAP 29 | class ValueAllocator; 30 | class ValueMapAllocator; 31 | class ValueInternalLink; 32 | class ValueInternalArray; 33 | class ValueInternalMap; 34 | #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP 35 | 36 | } // namespace Json 37 | 38 | 39 | #endif // JSON_FORWARDS_H_INCLUDED 40 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/json/json.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_JSON_H_INCLUDED 2 | # define JSON_JSON_H_INCLUDED 3 | 4 | # include "autolink.h" 5 | # include "value.h" 6 | # include "reader.h" 7 | # include "writer.h" 8 | # include "features.h" 9 | 10 | #endif // JSON_JSON_H_INCLUDED 11 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/libevent/evdns.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT1_EVDNS_H_INCLUDED_ 28 | #define EVENT1_EVDNS_H_INCLUDED_ 29 | 30 | /** @file evdns.h 31 | 32 | A dns subsystem for Libevent. 33 | 34 | The header is deprecated in Libevent 2.0 and later; please 35 | use instead. Depending on what functionality you 36 | need, you may also want to include more of the other 37 | headers. 38 | */ 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #endif /* EVENT1_EVDNS_H_INCLUDED_ */ 46 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/libevent/event2/rpc_compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT2_RPC_COMPAT_H_INCLUDED_ 28 | #define EVENT2_RPC_COMPAT_H_INCLUDED_ 29 | 30 | /** @file event2/rpc_compat.h 31 | 32 | @brief Deprecated versions of the functions in rpc.h: provided only for 33 | backwards compatibility. 34 | 35 | */ 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /** backwards compatible accessors that work only with gcc */ 42 | #if defined(__GNUC__) && !defined(__STRICT_ANSI__) 43 | 44 | #undef EVTAG_ASSIGN 45 | #undef EVTAG_GET 46 | #undef EVTAG_ADD 47 | 48 | #define EVTAG_ASSIGN(msg, member, args...) \ 49 | (*(msg)->base->member##_assign)(msg, ## args) 50 | #define EVTAG_GET(msg, member, args...) \ 51 | (*(msg)->base->member##_get)(msg, ## args) 52 | #define EVTAG_ADD(msg, member, args...) \ 53 | (*(msg)->base->member##_add)(msg, ## args) 54 | #endif 55 | #define EVTAG_LEN(msg, member) ((msg)->member##_length) 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ 62 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/libevent/event2/tag_compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT2_TAG_COMPAT_H_INCLUDED_ 28 | #define EVENT2_TAG_COMPAT_H_INCLUDED_ 29 | 30 | /** @file event2/tag_compat.h 31 | 32 | @brief Obsolete/deprecated functions from tag.h; provided only for backwards 33 | compatibility. 34 | */ 35 | 36 | /** 37 | @name Misnamed functions 38 | 39 | @deprecated These macros are deprecated because their names don't follow 40 | Libevent's naming conventions. Use evtag_encode_int and 41 | evtag_encode_int64 instead. 42 | 43 | @{ 44 | */ 45 | #define encode_int(evbuf, number) evtag_encode_int((evbuf), (number)) 46 | #define encode_int64(evbuf, number) evtag_encode_int64((evbuf), (number)) 47 | /**@}*/ 48 | 49 | #endif /* EVENT2_TAG_H_INCLUDED_ */ 50 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/libevent/evhttp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2000-2007 Niels Provos 3 | * Copyright 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT1_EVHTTP_H_INCLUDED_ 28 | #define EVENT1_EVHTTP_H_INCLUDED_ 29 | 30 | /** @file evhttp.h 31 | 32 | An http implementation subsystem for Libevent. 33 | 34 | The header is deprecated in Libevent 2.0 and later; please 35 | use instead. Depending on what functionality you 36 | need, you may also want to include more of the other 37 | headers. 38 | */ 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #endif /* EVENT1_EVHTTP_H_INCLUDED_ */ 46 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/libevent/evrpc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT1_EVRPC_H_INCLUDED_ 28 | #define EVENT1_EVRPC_H_INCLUDED_ 29 | 30 | /** @file evrpc.h 31 | 32 | An RPC system for Libevent. 33 | 34 | The header is deprecated in Libevent 2.0 and later; please 35 | use instead. Depending on what functionality you 36 | need, you may also want to include more of the other 37 | headers. 38 | */ 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #endif /* EVENT1_EVRPC_H_INCLUDED_ */ 46 | -------------------------------------------------------------------------------- /linuxserverplatform/src/include/libevent/evutil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef EVENT1_EVUTIL_H_INCLUDED_ 27 | #define EVENT1_EVUTIL_H_INCLUDED_ 28 | 29 | /** @file evutil.h 30 | 31 | Utility and compatibility functions for Libevent. 32 | 33 | The header is deprecated in Libevent 2.0 and later; please 34 | use instead. 35 | */ 36 | 37 | #include 38 | 39 | #endif /* EVENT1_EVUTIL_H_INCLUDED_ */ 40 | -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/WorkServer/luacode.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luotan-123/libevent-server/98652b1b5150402ae771ca0393b2ca7fadb11b8d/linuxserverplatform/src/lua/WorkServer/luacode.zip -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/auxiliar.h: -------------------------------------------------------------------------------- 1 | #ifndef AUXILIAR_H 2 | #define AUXILIAR_H 3 | /*=========================================================================*\ 4 | * Auxiliar routines for class hierarchy manipulation 5 | * LuaSocket toolkit (but completely independent of other LuaSocket modules) 6 | * 7 | * A LuaSocket class is a name associated with Lua metatables. A LuaSocket 8 | * group is a name associated with a class. A class can belong to any number 9 | * of groups. This module provides the functionality to: 10 | * 11 | * - create new classes 12 | * - add classes to groups 13 | * - set the class of objects 14 | * - check if an object belongs to a given class or group 15 | * - get the userdata associated to objects 16 | * - print objects in a pretty way 17 | * 18 | * LuaSocket class names follow the convention {}. Modules 19 | * can define any number of classes and groups. The module tcp.c, for 20 | * example, defines the classes tcp{master}, tcp{client} and tcp{server} and 21 | * the groups tcp{client,server} and tcp{any}. Module functions can then 22 | * perform type-checking on their arguments by either class or group. 23 | * 24 | * LuaSocket metatables define the __index metamethod as being a table. This 25 | * table has one field for each method supported by the class, and a field 26 | * "class" with the class name. 27 | * 28 | * The mapping from class name to the corresponding metatable and the 29 | * reverse mapping are done using lauxlib. 30 | * 31 | * RCS ID: $Id: auxiliar.h,v 1.9 2005/10/07 04:40:59 diego Exp $ 32 | \*=========================================================================*/ 33 | 34 | #include "lua.h" 35 | #include "lauxlib.h" 36 | 37 | int auxiliar_open(lua_State *L); 38 | void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func); 39 | void auxiliar_add2group(lua_State *L, const char *classname, const char *group); 40 | void auxiliar_setclass(lua_State *L, const char *classname, int objidx); 41 | void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx); 42 | void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx); 43 | void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx); 44 | void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx); 45 | int auxiliar_checkboolean(lua_State *L, int objidx); 46 | int auxiliar_tostring(lua_State *L); 47 | 48 | #endif /* AUXILIAR_H */ 49 | -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/buffer.h: -------------------------------------------------------------------------------- 1 | #ifndef BUF_H 2 | #define BUF_H 3 | /*=========================================================================*\ 4 | * Input/Output interface for Lua programs 5 | * LuaSocket toolkit 6 | * 7 | * Line patterns require buffering. Reading one character at a time involves 8 | * too many system calls and is very slow. This module implements the 9 | * LuaSocket interface for input/output on connected objects, as seen by 10 | * Lua programs. 11 | * 12 | * Input is buffered. Output is *not* buffered because there was no simple 13 | * way of making sure the buffered output data would ever be sent. 14 | * 15 | * The module is built on top of the I/O abstraction defined in io.h and the 16 | * timeout management is done with the timeout.h interface. 17 | * 18 | * RCS ID: $Id: buffer.h,v 1.12 2005/10/07 04:40:59 diego Exp $ 19 | \*=========================================================================*/ 20 | #include "lua.h" 21 | 22 | #include "io.h" 23 | #include "timeout.h" 24 | 25 | /* buffer size in bytes */ 26 | #define BUF_SIZE 8192 27 | 28 | /* buffer control structure */ 29 | typedef struct t_buffer_ { 30 | double birthday; /* throttle support info: creation time, */ 31 | size_t sent, received; /* bytes sent, and bytes received */ 32 | p_io io; /* IO driver used for this buffer */ 33 | p_timeout tm; /* timeout management for this buffer */ 34 | size_t first, last; /* index of first and last bytes of stored data */ 35 | char data[BUF_SIZE]; /* storage space for buffer data */ 36 | } t_buffer; 37 | typedef t_buffer *p_buffer; 38 | 39 | int buffer_open(lua_State *L); 40 | void buffer_init(p_buffer buf, p_io io, p_timeout tm); 41 | int buffer_meth_send(lua_State *L, p_buffer buf); 42 | int buffer_meth_receive(lua_State *L, p_buffer buf); 43 | int buffer_meth_getstats(lua_State *L, p_buffer buf); 44 | int buffer_meth_setstats(lua_State *L, p_buffer buf); 45 | int buffer_isempty(p_buffer buf); 46 | 47 | #endif /* BUF_H */ 48 | -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/except.h: -------------------------------------------------------------------------------- 1 | #ifndef EXCEPT_H 2 | #define EXCEPT_H 3 | /*=========================================================================*\ 4 | * Exception control 5 | * LuaSocket toolkit (but completely independent from other modules) 6 | * 7 | * This provides support for simple exceptions in Lua. During the 8 | * development of the HTTP/FTP/SMTP support, it became aparent that 9 | * error checking was taking a substantial amount of the coding. These 10 | * function greatly simplify the task of checking errors. 11 | * 12 | * The main idea is that functions should return nil as its first return 13 | * value when it finds an error, and return an error message (or value) 14 | * following nil. In case of success, as long as the first value is not nil, 15 | * the other values don't matter. 16 | * 17 | * The idea is to nest function calls with the "try" function. This function 18 | * checks the first value, and calls "error" on the second if the first is 19 | * nil. Otherwise, it returns all values it received. 20 | * 21 | * The protect function returns a new function that behaves exactly like the 22 | * function it receives, but the new function doesn't throw exceptions: it 23 | * returns nil followed by the error message instead. 24 | * 25 | * With these two function, it's easy to write functions that throw 26 | * exceptions on error, but that don't interrupt the user script. 27 | * 28 | * RCS ID: $Id: except.h,v 1.2 2005/09/29 06:11:41 diego Exp $ 29 | \*=========================================================================*/ 30 | 31 | #include "lua.h" 32 | 33 | int except_open(lua_State *L); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/inet.h: -------------------------------------------------------------------------------- 1 | #ifndef INET_H 2 | #define INET_H 3 | /*=========================================================================*\ 4 | * Internet domain functions 5 | * LuaSocket toolkit 6 | * 7 | * This module implements the creation and connection of internet domain 8 | * sockets, on top of the socket.h interface, and the interface of with the 9 | * resolver. 10 | * 11 | * The function inet_aton is provided for the platforms where it is not 12 | * available. The module also implements the interface of the internet 13 | * getpeername and getsockname functions as seen by Lua programs. 14 | * 15 | * The Lua functions toip and tohostname are also implemented here. 16 | * 17 | * RCS ID: $Id: inet.h,v 1.16 2005/10/07 04:40:59 diego Exp $ 18 | \*=========================================================================*/ 19 | #include "lua.h" 20 | #include "socket.h" 21 | #include "timeout.h" 22 | 23 | #ifdef _WIN32 24 | #define INET_ATON 25 | #endif 26 | 27 | int inet_open(lua_State *L); 28 | 29 | const char *inet_trycreate(p_socket ps, int type); 30 | const char *inet_tryconnect(p_socket ps, const char *address, 31 | unsigned short port, p_timeout tm); 32 | const char *inet_trybind(p_socket ps, const char *address, 33 | unsigned short port); 34 | 35 | int inet_meth_getpeername(lua_State *L, p_socket ps); 36 | int inet_meth_getsockname(lua_State *L, p_socket ps); 37 | 38 | #ifdef INET_ATON 39 | int inet_aton(const char *cp, struct in_addr *inp); 40 | #endif 41 | 42 | #endif /* INET_H */ 43 | -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/io.c: -------------------------------------------------------------------------------- 1 | /*=========================================================================*\ 2 | * Input/Output abstraction 3 | * LuaSocket toolkit 4 | * 5 | * RCS ID: $Id: io.c,v 1.6 2005/09/29 06:11:41 diego Exp $ 6 | \*=========================================================================*/ 7 | #include "io.h" 8 | 9 | /*=========================================================================*\ 10 | * Exported functions 11 | \*=========================================================================*/ 12 | /*-------------------------------------------------------------------------*\ 13 | * Initializes C structure 14 | \*-------------------------------------------------------------------------*/ 15 | void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) { 16 | io->send = send; 17 | io->recv = recv; 18 | io->error = error; 19 | io->ctx = ctx; 20 | } 21 | 22 | /*-------------------------------------------------------------------------*\ 23 | * I/O error strings 24 | \*-------------------------------------------------------------------------*/ 25 | const char *io_strerror(int err) { 26 | switch (err) { 27 | case IO_DONE: return NULL; 28 | case IO_CLOSED: return "closed"; 29 | case IO_TIMEOUT: return "timeout"; 30 | default: return "unknown error"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/io.h: -------------------------------------------------------------------------------- 1 | #ifndef IO_H 2 | #define IO_H 3 | /*=========================================================================*\ 4 | * Input/Output abstraction 5 | * LuaSocket toolkit 6 | * 7 | * This module defines the interface that LuaSocket expects from the 8 | * transport layer for streamed input/output. The idea is that if any 9 | * transport implements this interface, then the buffer.c functions 10 | * automatically work on it. 11 | * 12 | * The module socket.h implements this interface, and thus the module tcp.h 13 | * is very simple. 14 | * 15 | * RCS ID: $Id: io.h,v 1.11 2005/10/07 04:40:59 diego Exp $ 16 | \*=========================================================================*/ 17 | #include 18 | #include "lua.h" 19 | 20 | #include "timeout.h" 21 | 22 | /* IO error codes */ 23 | enum { 24 | IO_DONE = 0, /* operation completed successfully */ 25 | IO_TIMEOUT = -1, /* operation timed out */ 26 | IO_CLOSED = -2, /* the connection has been closed */ 27 | IO_UNKNOWN = -3 28 | }; 29 | 30 | /* interface to error message function */ 31 | typedef const char *(*p_error) ( 32 | void *ctx, /* context needed by send */ 33 | int err /* error code */ 34 | ); 35 | 36 | /* interface to send function */ 37 | typedef int (*p_send) ( 38 | void *ctx, /* context needed by send */ 39 | const char *data, /* pointer to buffer with data to send */ 40 | size_t count, /* number of bytes to send from buffer */ 41 | size_t *sent, /* number of bytes sent uppon return */ 42 | p_timeout tm /* timeout control */ 43 | ); 44 | 45 | /* interface to recv function */ 46 | typedef int (*p_recv) ( 47 | void *ctx, /* context needed by recv */ 48 | char *data, /* pointer to buffer where data will be writen */ 49 | size_t count, /* number of bytes to receive into buffer */ 50 | size_t *got, /* number of bytes received uppon return */ 51 | p_timeout tm /* timeout control */ 52 | ); 53 | 54 | /* IO driver definition */ 55 | typedef struct t_io_ { 56 | void *ctx; /* context needed by send/recv */ 57 | p_send send; /* send function pointer */ 58 | p_recv recv; /* receive function pointer */ 59 | p_error error; /* strerror function */ 60 | } t_io; 61 | typedef t_io *p_io; 62 | 63 | void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx); 64 | const char *io_strerror(int err); 65 | 66 | #endif /* IO_H */ 67 | 68 | -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/luasocket.h: -------------------------------------------------------------------------------- 1 | #ifndef LUASOCKET_H 2 | #define LUASOCKET_H 3 | /*=========================================================================*\ 4 | * LuaSocket toolkit 5 | * Networking support for the Lua language 6 | * Diego Nehab 7 | * 9/11/1999 8 | * 9 | * RCS ID: $Id: luasocket.h,v 1.25 2007/06/11 23:44:54 diego Exp $ 10 | \*=========================================================================*/ 11 | #include "lua.h" 12 | 13 | /*-------------------------------------------------------------------------*\ 14 | * Current socket library version 15 | \*-------------------------------------------------------------------------*/ 16 | #define LUASOCKET_VERSION "LuaSocket 2.0.2" 17 | #define LUASOCKET_COPYRIGHT "Copyright (C) 2004-2007 Diego Nehab" 18 | #define LUASOCKET_AUTHORS "Diego Nehab" 19 | 20 | /*-------------------------------------------------------------------------*\ 21 | * This macro prefixes all exported API functions 22 | \*-------------------------------------------------------------------------*/ 23 | #ifndef LUASOCKET_API 24 | #define LUASOCKET_API extern 25 | #endif 26 | 27 | /*-------------------------------------------------------------------------*\ 28 | * Initializes the library. 29 | \*-------------------------------------------------------------------------*/ 30 | #ifdef __cplusplus 31 | extern "C" 32 | { 33 | #endif 34 | int luaopen_socket_core(lua_State *L); 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | #endif /* LUASOCKET_H */ 39 | -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/luasql.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: luasql.h,v 1.12 2009/02/07 23:16:23 tomas Exp $ 3 | ** See Copyright Notice in license.html 4 | */ 5 | 6 | #ifndef _LUASQL_ 7 | #define _LUASQL_ 8 | 9 | #ifndef LUASQL_API 10 | #define LUASQL_API 11 | #endif 12 | 13 | #if !defined LUA_VERSION_NUM 14 | /* Lua 5.0 */ 15 | #define luaL_Reg luaL_reg 16 | 17 | #define lua_pushinteger(L, n) \ 18 | lua_pushnumber(L, (lua_Number)n) 19 | #endif 20 | 21 | #define LUASQL_PREFIX "LuaSQL: " 22 | #define LUASQL_TABLENAME "luasql" 23 | #define LUASQL_ENVIRONMENT "Each driver must have an environment metatable" 24 | #define LUASQL_CONNECTION "Each driver must have a connection metatable" 25 | #define LUASQL_CURSOR "Each driver must have a cursor metatable" 26 | 27 | LUASQL_API int luasql_faildirect (lua_State *L, const char *err); 28 | LUASQL_API int luasql_failmsg (lua_State *L, const char *err, const char *m); 29 | LUASQL_API int luasql_createmeta (lua_State *L, const char *name, const luaL_Reg *methods); 30 | LUASQL_API void luasql_setmeta (lua_State *L, const char *name); 31 | LUASQL_API void luasql_set_info (lua_State *L); 32 | 33 | #if !defined LUA_VERSION_NUM || LUA_VERSION_NUM==501 34 | void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); 35 | #endif 36 | 37 | extern char g_dbHost[128]; 38 | extern char g_dbUser[64]; 39 | extern char g_dbPassword[64]; 40 | extern int g_dbPort; 41 | 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/mime.h: -------------------------------------------------------------------------------- 1 | #ifndef MIME_H 2 | #define MIME_H 3 | /*=========================================================================*\ 4 | * Core MIME support 5 | * LuaSocket toolkit 6 | * 7 | * This module provides functions to implement transfer content encodings 8 | * and formatting conforming to RFC 2045. It is used by mime.lua, which 9 | * provide a higher level interface to this functionality. 10 | * 11 | * RCS ID: $Id: mime.h,v 1.15 2007/06/11 23:44:54 diego Exp $ 12 | \*=========================================================================*/ 13 | #include "lua.h" 14 | 15 | /*-------------------------------------------------------------------------*\ 16 | * Current MIME library version 17 | \*-------------------------------------------------------------------------*/ 18 | #define MIME_VERSION "MIME 1.0.2" 19 | #define MIME_COPYRIGHT "Copyright (C) 2004-2007 Diego Nehab" 20 | #define MIME_AUTHORS "Diego Nehab" 21 | 22 | /*-------------------------------------------------------------------------*\ 23 | * This macro prefixes all exported API functions 24 | \*-------------------------------------------------------------------------*/ 25 | #ifndef MIME_API 26 | #define MIME_API extern 27 | #endif 28 | 29 | MIME_API int luaopen_mime_core(lua_State *L); 30 | 31 | #endif /* MIME_H */ 32 | -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/options.h: -------------------------------------------------------------------------------- 1 | #ifndef OPTIONS_H 2 | #define OPTIONS_H 3 | /*=========================================================================*\ 4 | * Common option interface 5 | * LuaSocket toolkit 6 | * 7 | * This module provides a common interface to socket options, used mainly by 8 | * modules UDP and TCP. 9 | * 10 | * RCS ID: $Id: options.h,v 1.4 2005/10/07 04:40:59 diego Exp $ 11 | \*=========================================================================*/ 12 | 13 | #include "lua.h" 14 | #include "socket.h" 15 | 16 | typedef unsigned short u_short; 17 | 18 | /* option registry */ 19 | typedef struct t_opt { 20 | const char *name; 21 | int (*func)(lua_State *L, p_socket ps); 22 | } t_opt; 23 | typedef t_opt *p_opt; 24 | 25 | /* supported options */ 26 | int opt_dontroute(lua_State *L, p_socket ps); 27 | int opt_broadcast(lua_State *L, p_socket ps); 28 | int opt_reuseaddr(lua_State *L, p_socket ps); 29 | int opt_tcp_nodelay(lua_State *L, p_socket ps); 30 | int opt_keepalive(lua_State *L, p_socket ps); 31 | int opt_linger(lua_State *L, p_socket ps); 32 | int opt_reuseaddr(lua_State *L, p_socket ps); 33 | int opt_ip_multicast_ttl(lua_State *L, p_socket ps); 34 | int opt_ip_multicast_loop(lua_State *L, p_socket ps); 35 | int opt_ip_add_membership(lua_State *L, p_socket ps); 36 | int opt_ip_drop_membersip(lua_State *L, p_socket ps); 37 | 38 | /* invokes the appropriate option handler */ 39 | int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/select.h: -------------------------------------------------------------------------------- 1 | #ifndef SELECT_H 2 | #define SELECT_H 3 | /*=========================================================================*\ 4 | * Select implementation 5 | * LuaSocket toolkit 6 | * 7 | * Each object that can be passed to the select function has to export 8 | * method getfd() which returns the descriptor to be passed to the 9 | * underlying select function. Another method, dirty(), should return 10 | * true if there is data ready for reading (required for buffered input). 11 | * 12 | * RCS ID: $Id: select.h,v 1.7 2004/06/16 01:02:07 diego Exp $ 13 | \*=========================================================================*/ 14 | 15 | int select_open(lua_State *L); 16 | 17 | #endif /* SELECT_H */ 18 | -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/tcp.h: -------------------------------------------------------------------------------- 1 | #ifndef TCP_H 2 | #define TCP_H 3 | /*=========================================================================*\ 4 | * TCP object 5 | * LuaSocket toolkit 6 | * 7 | * The tcp.h module is basicly a glue that puts together modules buffer.h, 8 | * timeout.h socket.h and inet.h to provide the LuaSocket TCP (AF_INET, 9 | * SOCK_STREAM) support. 10 | * 11 | * Three classes are defined: master, client and server. The master class is 12 | * a newly created tcp object, that has not been bound or connected. Server 13 | * objects are tcp objects bound to some local address. Client objects are 14 | * tcp objects either connected to some address or returned by the accept 15 | * method of a server object. 16 | * 17 | * RCS ID: $Id: tcp.h,v 1.7 2005/10/07 04:40:59 diego Exp $ 18 | \*=========================================================================*/ 19 | #include "lua.h" 20 | 21 | #include "buffer.h" 22 | #include "timeout.h" 23 | #include "socket.h" 24 | 25 | typedef struct t_tcp_ { 26 | t_socket sock; 27 | t_io io; 28 | t_buffer buf; 29 | t_timeout tm; 30 | } t_tcp; 31 | 32 | typedef t_tcp *p_tcp; 33 | 34 | int tcp_open(lua_State *L); 35 | 36 | #endif /* TCP_H */ 37 | -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/timeout.h: -------------------------------------------------------------------------------- 1 | #ifndef TIMEOUT_H 2 | #define TIMEOUT_H 3 | /*=========================================================================*\ 4 | * Timeout management functions 5 | * LuaSocket toolkit 6 | * 7 | * RCS ID: $Id: timeout.h,v 1.14 2005/10/07 04:40:59 diego Exp $ 8 | \*=========================================================================*/ 9 | #include "lua.h" 10 | 11 | /* timeout control structure */ 12 | typedef struct t_timeout_ { 13 | double block; /* maximum time for blocking calls */ 14 | double total; /* total number of miliseconds for operation */ 15 | double start; /* time of start of operation */ 16 | } t_timeout; 17 | typedef t_timeout *p_timeout; 18 | 19 | int timeout_open(lua_State *L); 20 | void timeout_init(p_timeout tm, double block, double total); 21 | double timeout_get(p_timeout tm); 22 | double timeout_getretry(p_timeout tm); 23 | p_timeout timeout_markstart(p_timeout tm); 24 | double timeout_getstart(p_timeout tm); 25 | double timeout_gettime(void); 26 | int timeout_meth_settimeout(lua_State *L, p_timeout tm); 27 | 28 | #define timeout_iszero(tm) ((tm)->block == 0.0) 29 | 30 | #endif /* TIMEOUT_H */ 31 | -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/udp.h: -------------------------------------------------------------------------------- 1 | #ifndef UDP_H 2 | #define UDP_H 3 | /*=========================================================================*\ 4 | * UDP object 5 | * LuaSocket toolkit 6 | * 7 | * The udp.h module provides LuaSocket with support for UDP protocol 8 | * (AF_INET, SOCK_DGRAM). 9 | * 10 | * Two classes are defined: connected and unconnected. UDP objects are 11 | * originally unconnected. They can be "connected" to a given address 12 | * with a call to the setpeername function. The same function can be used to 13 | * break the connection. 14 | * 15 | * RCS ID: $Id: udp.h,v 1.10 2005/10/07 04:40:59 diego Exp $ 16 | \*=========================================================================*/ 17 | #include "lua.h" 18 | 19 | #include "timeout.h" 20 | #include "socket.h" 21 | 22 | /* can't be larger than wsocket.c MAXCHUNK!!! */ 23 | #define UDP_DATAGRAMSIZE 8192 24 | 25 | typedef struct t_udp_ { 26 | t_socket sock; 27 | t_timeout tm; 28 | } t_udp; 29 | typedef t_udp *p_udp; 30 | 31 | int udp_open(lua_State *L); 32 | 33 | #endif /* UDP_H */ 34 | -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/unix.h: -------------------------------------------------------------------------------- 1 | #ifndef UNIX_H 2 | #define UNIX_H 3 | /*=========================================================================*\ 4 | * Unix domain object 5 | * LuaSocket toolkit 6 | * 7 | * This module is just an example of how to extend LuaSocket with a new 8 | * domain. 9 | * 10 | * RCS ID: $Id: unix.h,v 1.9 2006/03/13 07:16:39 diego Exp $ 11 | \*=========================================================================*/ 12 | #include "lua.h" 13 | 14 | #include "buffer.h" 15 | #include "timeout.h" 16 | #include "socket.h" 17 | 18 | typedef struct t_unix_ { 19 | t_socket sock; 20 | t_io io; 21 | t_buffer buf; 22 | t_timeout tm; 23 | } t_unix; 24 | typedef t_unix *p_unix; 25 | 26 | int luaopen_socket_unix(lua_State *L); 27 | 28 | #endif /* UNIX_H */ 29 | -------------------------------------------------------------------------------- /linuxserverplatform/src/lua/usocket.h: -------------------------------------------------------------------------------- 1 | #ifndef USOCKET_H 2 | #define USOCKET_H 3 | /*=========================================================================*\ 4 | * Socket compatibilization module for Unix 5 | * LuaSocket toolkit 6 | * 7 | * RCS ID: $Id: usocket.h,v 1.7 2005/10/07 04:40:59 diego Exp $ 8 | \*=========================================================================*/ 9 | 10 | /*=========================================================================*\ 11 | * BSD include files 12 | \*=========================================================================*/ 13 | /* error codes */ 14 | #include 15 | /* close function */ 16 | #include 17 | /* fnctnl function and associated constants */ 18 | #include 19 | /* struct sockaddr */ 20 | #include 21 | /* socket function */ 22 | #include 23 | /* struct timeval */ 24 | #include 25 | /* gethostbyname and gethostbyaddr functions */ 26 | #include 27 | /* sigpipe handling */ 28 | #include 29 | /* IP stuff*/ 30 | #include 31 | #include 32 | /* TCP options (nagle algorithm disable) */ 33 | #include 34 | 35 | typedef int t_socket; 36 | typedef t_socket *p_socket; 37 | 38 | #define SOCKET_INVALID (-1) 39 | 40 | #endif /* USOCKET_H */ 41 | -------------------------------------------------------------------------------- /linuxserverplatform/src/protobuf/AsyncEventMsg.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package AsyncEventMsg; 3 | 4 | message AsyncEventMsg_Test_User{ 5 | int32 userID = 1; 6 | string name = 2; 7 | string headURL = 3; 8 | int64 money = 4; 9 | int32 winCount = 5; 10 | } 11 | 12 | message AsyncEventMsg_Test { 13 | repeated AsyncEventMsg_Test_User user = 1; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /linuxserverplatform/src/protobuf/test.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package test; 3 | 4 | enum Sex { 5 | BOY = 0; 6 | GIRL = 1; 7 | } 8 | 9 | message Student { 10 | int32 Id = 1; // id 11 | string Name = 2; // name 12 | Sex Sex = 3; 13 | } 14 | 15 | message Team { 16 | int32 Id = 1; 17 | string Name = 2; 18 | repeated Student Student = 3; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /linuxserverplatform/src/test/Makefile: -------------------------------------------------------------------------------- 1 | # test的Makefile文件 2 | 3 | # 编译版本,可选debug和release 4 | #build_ver=debug 5 | 6 | ifeq ($(build_ver),release) 7 | BUILD_OPT= -g1 -O3 8 | else 9 | BUILD_OPT= -g2 -O0 10 | endif 11 | 12 | 13 | CPP = g++ 14 | CPPFLAGS = -I ../include -I ../include/ServerCommon -I ../include/curl -I ../include/DataBase -I ../include/libevent -I ../include/hiredis -I ../lua -I ../protobuf -I /usr/local/include -DLUA_COMPAT_5_1 $(BUILD_OPT) -Wall -std=c++11 15 | CFLAGS = -I ../include -I ../include/ServerCommon -I ../include/curl -I ../include/DataBase -I ../include/libevent -I ../include/hiredis -I ../lua -I ../protobuf -I /usr/local/include -DLUA_COMPAT_5_1 $(BUILD_OPT) -Wall -std=c11 16 | 17 | # 设置默认加载库位置 18 | CURDIR := $(shell pwd) 19 | PARENT_CURDIR = $(shell dirname $(CURDIR)) 20 | PARENT_BIN := $(PARENT_CURDIR)/bin/ 21 | 22 | LDFLAGS = -L ../bin -Wl,-rpath=$(PARENT_BIN) 23 | LIBS = -lKernel -lCommon -lprotobuf -ljson -lpthread -levent -ljemalloc 24 | 25 | BINDIR := ../bin/ 26 | BIN := test 27 | OBJ := jemalloc_cpp.o test.pb.o main.o Shm.o TestUnLockQueue.o 28 | 29 | $(BINDIR)$(BIN):$(OBJ) 30 | $(CPP) -o $@ $(LDFLAGS) $^ $(LIBS) 31 | 32 | %.o:%.cpp 33 | $(CPP) -c $^ $(CPPFLAGS) 34 | 35 | jemalloc_cpp.o:../jemalloc/jemalloc_cpp.cpp 36 | $(CPP) -c $^ $(CPPFLAGS) 37 | 38 | %.o:../protobuf/%.cc 39 | $(CPP) -c $^ $(CPPFLAGS) 40 | 41 | #%.o:../lua/%.c 42 | # $(CPP) -c -x c $^ $(CFLAGS) 43 | 44 | install: 45 | @echo "test生成在../bin/目录中" 46 | 47 | clean: 48 | rm -rf *.o 49 | 50 | --------------------------------------------------------------------------------