⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 奇迹世界 部分源代码奇迹世界 部分源代码奇迹世界 部分源代码
💻 CPP
字号:
// GameServer.cpp : 能贾 览侩 橇肺弊伐俊 措茄 柳涝痢阑 沥狼钦聪促.
//

#include "stdafx.h"
#include <SolarSimpleConsole.h>
#include <Stackwalker.h>
#include "main.h"
#include "FieldServer.h"
#include "BattleServer.h"
#include <ISolarConsole_Define.h>
#include <ISolarConsole_Guid.h>
#include <ISolarConsole.h>
#include <SUNConsole.h>
#include <time.h>

SolarSimpleConsole	g_Console;
ISolarConsole * g_pIConsole = NULL;
SUNConsole g_SUNConsole;
#include <SolarDump.h>

#include "ServiceApp.h"

class GameServiceApp : public ServiceApp
{
public :
	GameServiceApp(const char* pServiceName)
		: ServiceApp(pServiceName)
	{
	}

	virtual DWORD		OnInit (DWORD argc, LPTSTR *argv, DWORD *specificError)	
	{ 
		__UNUSED(argc);
		__UNUSED(argv);
		__UNUSED(specificError);
		return 0; 
	}

	virtual VOID		Update()
	{	
		// 辑滚 檬扁拳
/*		if( !g_pGameServer->Init() )
		{
			DISPMSG(   "Server initialization failed!" );
			assert(false);
		}
*/
		DISPMSG( "==================================================\n" );
		DISPMSG( "  SUN Online GameServer Initialization Complete.\n" );
		DISPMSG( "==================================================\n" );

		g_pGameServer->Run();
	}

	virtual VOID		OnStop()
	{
		g_SUNConsole.Release();	
	}
};

__DECLARE_SERVICE( GameServiceApp, "GameServer" );


extern "C"
{
	int WinMainCRTStartup();
}

static int SunAllocHook(int nAllocType, void *pvData,
      size_t nSize, int nBlockUse, long lRequest,
      const unsigned char * szFileName, int nLine )
{
	__UNUSED(nAllocType);
	__UNUSED(pvData);
	__UNUSED(nBlockUse);
	__UNUSED(szFileName);
	__UNUSED(nLine);

	if (lRequest >= 492604)	// 389862
	{
		//if (nSize == 32)
		{
			__asm int 3;
		}
	}
	

	return TRUE;
}

int SunEntryPoint()
{
//	_CrtSetAllocHook(SunAllocHook);
	return WinMainCRTStartup();
}

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	__UNUSED(hInstance);
	__UNUSED(hPrevInstance);
	__UNUSED(nCmdShow);

	StartMemoryLeakCheck();
	//BreakPointOnMemoryLeak(98198);
	//BreakPointOnMemoryLeak(10084);

	SolarDump dp;

	srand(time(NULL));


	BOOL bConsoleMode = (strstr( lpCmdLine, "service" ) == NULL);

#ifdef _USING_SIMPLE_CONSOLE
	if( !g_SUNConsole.Init( eSIMPLE_CONSOLE ) )
#else
	if( !g_SUNConsole.Init( eCOMPLEX_CONSOLE ) )
#endif 
	{
		ASSERT( !"Solar console Initialization failed!" );
		return 0;
	}

	// 疙飞 牢荐 颇教
	if( !ParseArguments( (LPTSTR)lpCmdLine ) )
	{
		DISPMSG(   "Invalid argument!\n" );
		system( "pause" );
		goto END_RELEASE;
	}

	// 辑滚 矫累
	if (bConsoleMode)
	{		
		// 辑滚 檬扁拳
		if( !g_pGameServer->Init() )
		{
			DISPMSG(   "Server initialization failed!" );
			system( "pause" );
			goto END_RELEASE;
		}

		DISPMSG(   "==================================================\n" );
		DISPMSG(   "  SUN Online GameServer Initialization Complete.\n" );
		DISPMSG(   "==================================================\n" );

		g_pGameServer->Run();

		// 辑滚 辆丰
		DISPMSG(   "Server is terminated...\n" );
	}
	else
	{
		DISPMSG(   "<<<<< Service Mode >>>>>\n" );
		__START_SERVICE( GameServiceApp );
	}


END_RELEASE:
	if( g_pGameServer )
	{
		g_pGameServer->Release();
		SAFE_DELETE(g_pGameServer);
	}

	g_SUNConsole.Release();

	return 0;
}

VOID ReleaseSolarConsole()
{
#if (0)
	g_pIConsole->DestroyConsole();
	g_pIConsole->Release();
	CoUninitialize();
#else
	g_Console.Release();
#endif
}

BOOL InitSolarConsole()
{
#if (0)
	CoInitialize(NULL);

	// 贾扼能贾 能贾芒 檬扁拳
	HRESULT hr;	
	hr = CoCreateInstance( CLSID_SOLAR_CONSOLE, NULL, CLSCTX_INPROC_SERVER, IID_SOLARConsole, (void**)&g_pIConsole );	
	if( FAILED( hr ) ) 
	{
		ASSERT( !"ISolarConsole.dll阑 殿废窍瘤 臼疽嚼聪促.regsvr32 xxx.dll" );
		return FALSE;
	}

	LOGFONT logFont;
	logFont.lfHeight			= 17; 
	logFont.lfWidth				= 0; 
	logFont.lfEscapement		= 0; 
	logFont.lfOrientation		= 0; 
	logFont.lfWeight			= FW_BOLD; 
	logFont.lfItalic			= 0; 
	logFont.lfUnderline			= 0; 
	logFont.lfStrikeOut			= 0; 
	logFont.lfCharSet			= HANGUL_CHARSET; 
	logFont.lfOutPrecision		= 0; 
	logFont.lfClipPrecision		= 0; 
	logFont.lfQuality			= 0; 
	logFont.lfPitchAndFamily	= 0; 
	strcpy(logFont.lfFaceName, "奔覆"); 

	HWND hWnd;

	SOLAR_CONSOLE_DESC	desc;
	desc.pszConsoleTitle					= "Game Server - SUN Online Server Console";
	desc.pszLogFileName						= "GameServer";
	desc.dwConsoleStyle						= SCS_ENABLE_WRITETOFILE;
	desc.dwRefreshRateDelayTime				= 1000;
	desc.dwNoMoreRefreshDelayTime			= 16000;
	desc.dwBufferingLineNum					= 2000;
	desc.wConsoleWidthSize					= 800;
	desc.wConsoleHeightSize					= 400;
	desc.pLogFont							= &logFont;
	desc.fnCommand							= NULL;
	/*
	SOLAR_MENU_INFO pMenu[3];
	pMenu[0].pszMenuName					= "abc1";
	pMenu[0].cbMenuCommand					= Menu1;
	pMenu[1].pszMenuName					= "abc2";
	pMenu[1].cbMenuCommand					= Menu2;
	pMenu[2].pszMenuName					= "abc3";
	pMenu[2].cbMenuCommand					= Menu3;
	*/
	desc.wMenuNum							= 0;
	desc.pMemnuInfo							= NULL;

	g_pIConsole->CreateConsole( desc, &hWnd );
#else
	// 贾扼 缴敲能贾 能贾芒 檬扁拳
	CONSOLE_DESC cdesc;
	ZeroMemory( &cdesc, sizeof(cdesc) );
	cdesc.bUsingConsoleInput	= FALSE;
	cdesc.bUsingRedirect		= TRUE;
	g_Console.Init( &cdesc );
#endif

	return TRUE;
}

/**
	@remarks
			漂沥 argument甫 胶飘傅栏肺 掘绢辰促.
	@param	idx
			掘绢尘 argument 锅龋
	@param	szCommandLine
			argument 胶飘傅
	@param	[out]pszTargetBuf
			胶飘傅阑 罐阑 滚欺
	@param	nMaxBufSize
			胶飘傅阑 罐阑 滚欺狼 农扁
	@retval BOOL
			idx锅掳 牢磊啊 粮犁窍瘤 臼栏搁 FALSE
*/
BOOL GetCommandLineArg( int idx, char *szCommandLine, char *pszTargetBuf, int nMaxBufSize )
{
	char sep[] = " ";
	char line[255];

	strncpy( line, szCommandLine, 255 );

	char *token = strtok( line, sep );

	while( token && idx )
	{
		token = strtok( NULL, sep );
		--idx;
	}

	if( token != NULL )
		strncpy( pszTargetBuf, token, nMaxBufSize );
	else
	{
		pszTargetBuf[0] = NULL;
		return FALSE;
	}

	return TRUE;
}

/**
	@remarks
			Argument俊 蝶扼 FieldServer or BattleServer 牢胶畔胶 积己
	@param	lpCmdLine
			橇肺弊伐 疙飞 牢荐
	@retval BOOL
			牢磊 俺荐啊 嘎瘤 臼绰 版快 FALSE甫 府畔茄促.
*/
BOOL ParseArguments( char *lpCmdLine )
{
	char	szArg[255];
	GetCommandLineArg( 0, lpCmdLine, szArg, 255 );

	if( stricmp( szArg, "" ) == 0 )
	{
		return FALSE;
	}

	if( stricmp( szArg, "field" ) == 0 )
	{
		g_pGameServer = new FieldServer;
	}
	else if( stricmp( szArg, "battle" ) == 0 )
	{
		g_pGameServer = new BattleServer;
	}

	return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -