Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
kdbprocessthread.cpp
Package: SwordOnline.rar [view]
Upload User: dzyhzl
Upload Date: 2019-04-29
Package Size: 56270k
Code Size: 4k
Category:
Game Server Simulator
Development Platform:
C/C++
- #include "stdafx.h"
- #include <objbase.h>
- #include <initguid.h>
- #include "KRoleInfomation.h"
- #include "KRoleDBServer.h"
- #include "KException.h"
- #include "S3DBINTERFACE.H"
- #include "KDBProcessThread.h"
- #include "KRoleDBHeader.h"
- #include "....HeadersKProtocolDef.h"
- #include "..MultiServerCommontstring.h"
- using OnlineGameLib::Win32::_tstring;
- #pragma warning(disable:4786)
- #include <crtdbg.h>
- #include <list>
- #include "stdio.h"
- using namespace std;
- static const int g_snMaxPlayerCount = 5000;
- static const int g_snPrecision = 10;
- static const int g_snMaxBuffer = 15;
- static const int g_snBufferSize = 1024;
- IServer *g_pNetServer = NULL;
- static HMODULE hDllModule;
- DWORD g_dwPerSaveTime = 100;//每次存档的时间
- DWORD g_dwMaxUnModifyTime;
- list<TCmd*> g_MainThreadCmdList;
- list<TGetRoleInfoFromDB*> g_DBLoadThreadCmdList;
- list<TCmd*> g_NetServiceThreadCmdList;
- extern BOOL InitNetEngine();
- extern RoleDBServer::KNetServer g_NetServer;
- unsigned char g_LoadDBThreadMark = MARK1;
- unsigned char g_SaveDBThreadMark = MARK1;
- unsigned char g_NetServerMark = MARK1;;
- unsigned char g_MainLoopMark = MARK1;
- int g_nMistakeCount = 0;
- size_t g_dwSendLen = 0;
- size_t g_dwRecvLen = 0;
- OnlineGameLib::Win32::CCriticalSection g_RoleInfoMutex;
- OnlineGameLib::Win32::CCriticalSection g_RoleInfoSetMutex;
- OnlineGameLib::Win32::CCriticalSection g_MainMsgListMutex;
- OnlineGameLib::Win32::CCriticalSection g_NetMsgListMutex;
- OnlineGameLib::Win32::CCriticalSection g_GetRoleInfoMutex;
- TThreadData g_ThreadData[4];
- char * GetRoleNameFromRoleBuffer(char * pRoleBuffer)
- {
- if (pRoleBuffer == NULL)
- return NULL;
- try
- {
- TRoleData *pRoleData = (TRoleData*) pRoleBuffer;
- return pRoleData->BaseInfo.szName;
- }
- catch(...)
- {
- g_nMistakeCount ++;
- throw KException("GetRoleNameFromRoleBuffer", "内存有问题");
- }
- }
- int InitServer()
- {
- int nReturn;
- S3DBI_InitDBInterface();
- nReturn = InitNetEngine();
- return nReturn;
- }
- DWORD ReleaseServer()
- {
- for(int i = 0; i < 4; i ++)
- TerminateThread(g_ThreadData[i].hThread,0);
- g_pNetServer->CloseService();
- g_pNetServer->Cleanup();
- g_pNetServer->Release();
- ::FreeLibrary( hDllModule );
- S3DBI_ReleaseDBInterface();
- return 1;
- }
- typedef HRESULT ( __stdcall * pfnCreateServerInterface )(
- REFIID riid,
- void **ppv
- );
- void __stdcall ServerEventNotify(
- LPVOID lpParam,
- const unsigned long &ulnID,
- const unsigned long &ulnEventType )
- {
- switch( ulnEventType )
- {
- case enumClientConnectCreate:
- g_NetServer.RegisterClient(ulnID);
- break;
- case enumClientConnectClose:
- g_NetServer.DestoryClient(ulnID);
- break;
- }
- }
- BOOL InitNetEngine()
- {
- hDllModule = ::LoadLibrary( "heaven.dll" );
- if ( hDllModule )
- {
- pfnCreateServerInterface pFactroyFun = ( pfnCreateServerInterface )GetProcAddress( hDllModule, "CreateInterface" );
- IServerFactory *pServerFactory = NULL;
- if ( SUCCEEDED( pFactroyFun( IID_IServerFactory, reinterpret_cast< void ** >( &pServerFactory ) ) ) )
- {
- pServerFactory->SetEnvironment( g_snMaxPlayerCount, g_snPrecision, g_snMaxBuffer, g_snBufferSize );
- pServerFactory->CreateServerInterface( IID_IIOCPServer, reinterpret_cast< void ** >( &g_pNetServer ) );
- pServerFactory->Release();
- }
- }
- else
- return FALSE;
- g_pNetServer->Startup();
- g_pNetServer->RegisterMsgFilter( reinterpret_cast< void * >( g_pNetServer ), ServerEventNotify );
- g_pNetServer->OpenService( 0, 5001 );
- return 1;
- }