예제 #1
0
파일: Main.cpp 프로젝트: 1suming/pap2
int main(int argc, char* argv[])
{
    int         nResult      = false;
    int         nRetCode     = false;  
    int         nLogInitFlag = false;
    int         nRdbFlag     = false;
    KGLOG_PARAM LogParam;  

    KSO3RoleDBUpdater* pKSO3RoleDBUpdater = NULL;

#ifdef WIN32
    SetConsoleInfo();
#endif
    setlocale(LC_ALL, "");
    g_SetRootPath(NULL);

    strncpy(LogParam.szPath, "logs", sizeof(LogParam.szPath));
    LogParam.szPath[sizeof(LogParam.szPath) - 1] = '\0';
    strncpy(LogParam.szIdent, "SO3RoleDBUpdaterTest", sizeof(LogParam.szIdent));
    LogParam.szIdent[sizeof(LogParam.szIdent) - 1] = '\0';
    LogParam.Options = (KGLOG_OPTIONS)(KGLOG_OPTION_FILE | KGLOG_OPTION_CONSOLE);
    LogParam.nMaxLineEachFile = 160000;

    nRetCode = KGLogInit(LogParam, NULL);
    KGLOG_PROCESS_ERROR(nRetCode);
    nLogInitFlag = true;  

    pKSO3RoleDBUpdater = new KSO3RoleDBUpdater();
    KGLOG_PROCESS_ERROR(pKSO3RoleDBUpdater);

    nRetCode = pKSO3RoleDBUpdater->Init();
    KGLOG_PROCESS_ERROR(nRetCode);
    nRdbFlag = true;
    KGLogPrintf(KGLOG_INFO, "SO3RoleDBUpdaterTest had started up ... ...");

    nRetCode = pKSO3RoleDBUpdater->Run();
    KGLOG_PROCESS_ERROR(nRetCode);

    KGLogPrintf(KGLOG_INFO, "SO3RoleDB UpdateTest Complete...");

    nResult = true;
Exit0:
    if (nRdbFlag)
    {
        pKSO3RoleDBUpdater->UnInit();
        nRdbFlag = false;
    }

    KG_DELETE(pKSO3RoleDBUpdater);

    if (nLogInitFlag)
    {
        KGLogUnInit(NULL);
        nLogInitFlag = false;
    }
    
    return nResult ? 0 : 1;
}
예제 #2
0
void SetConsoleFontSizeTo(HWND inConWnd, int inSizeY, int inSizeX, const wchar_t *asFontName, WORD anTextColors /*= 0*/, WORD anPopupColors /*= 0*/)
{
	_ASSERTE(_WIN32_WINNT_VISTA==0x600);
	OSVERSIONINFOEXW osvi = {sizeof(osvi), HIBYTE(_WIN32_WINNT_VISTA), LOBYTE(_WIN32_WINNT_VISTA)};
	DWORDLONG const dwlConditionMask = VerSetConditionMask(VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL), VER_MINORVERSION, VER_GREATER_EQUAL);
	if (VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask))
	{
		// We have Vista
		apiSetConsoleFontSize(GetStdHandle(STD_OUTPUT_HANDLE), inSizeY, inSizeX, asFontName);
	}
	else 
	{
		// We have older NT (Win2k, WinXP)
		// So... using undocumented hack

		const COLORREF DefaultColors[16] =
		{
			0x00000000, 0x00800000, 0x00008000, 0x00808000,
			0x00000080, 0x00800080, 0x00008080, 0x00c0c0c0,
			0x00808080,	0x00ff0000, 0x0000ff00, 0x00ffff00,
			0x000000ff, 0x00ff00ff,	0x0000ffff, 0x00ffffff
		};

		if (!gpConsoleInfoStr)
		{
			gpConsoleInfoStr = (CONSOLE_INFO*)LocalAlloc(LPTR, sizeof(CONSOLE_INFO));

			if (!gpConsoleInfoStr)
			{
				_ASSERTE(gpConsoleInfoStr!=NULL);
				return; // memory allocation failed
			}

			gpConsoleInfoStr->Length = sizeof(CONSOLE_INFO);
		}

		if (!anTextColors)
		{
			CONSOLE_SCREEN_BUFFER_INFO csbi = {};
			GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
			anTextColors = csbi.wAttributes ? csbi.wAttributes : MAKEWORD(0x7, 0x0);
		}
		if (!anPopupColors)
		{
			anPopupColors = MAKEWORD(0x5, 0xf);
		}

		// get current size/position settings rather than using defaults..
		GetConsoleSizeInfo(gpConsoleInfoStr);
		// set these to zero to keep current settings
		gpConsoleInfoStr->FontSize.X				= inSizeX;
		gpConsoleInfoStr->FontSize.Y				= inSizeY;
		gpConsoleInfoStr->FontFamily				= 0;//0x30;//FF_MODERN|FIXED_PITCH;//0x30;
		gpConsoleInfoStr->FontWeight				= 0;//0x400;
		lstrcpynW(gpConsoleInfoStr->FaceName, asFontName ? asFontName : L"Lucida Console", countof(gpConsoleInfoStr->FaceName)); //-V303
		gpConsoleInfoStr->CursorSize				= 25;
		gpConsoleInfoStr->FullScreen				= FALSE;
		gpConsoleInfoStr->QuickEdit					= FALSE;
		//gpConsoleInfoStr->AutoPosition			= 0x10000;
		gpConsoleInfoStr->AutoPosition				= FALSE;
		RECT rcCon; GetWindowRect(inConWnd, &rcCon);
		gpConsoleInfoStr->WindowPosX = rcCon.left;
		gpConsoleInfoStr->WindowPosY = rcCon.top;
		gpConsoleInfoStr->InsertMode				= TRUE;
		gpConsoleInfoStr->ScreenColors				= anTextColors; //MAKEWORD(0x7, 0x0);
		gpConsoleInfoStr->PopupColors				= anPopupColors; //MAKEWORD(0x5, 0xf);
		gpConsoleInfoStr->HistoryNoDup				= FALSE;
		gpConsoleInfoStr->HistoryBufferSize			= 50;
		gpConsoleInfoStr->NumberOfHistoryBuffers	= 32; //-V112

		// Issue 700: Default history buffers count too small.
		HKEY hkConsole = NULL;
		LONG lRegRc;
		if (0 == (lRegRc = RegCreateKeyEx(HKEY_CURRENT_USER, L"Console\\ConEmu", 0, NULL, 0, KEY_READ, NULL, &hkConsole, NULL)))
		{
			DWORD nSize = sizeof(DWORD), nValue, nType;
			struct {
				LPCWSTR pszName;
				DWORD nMin, nMax;
				ULONG *pnVal;
			} BufferValues[] = {
				{L"HistoryBufferSize", 16, 999, &gpConsoleInfoStr->HistoryBufferSize},
				{L"NumberOfHistoryBuffers", 16, 999, &gpConsoleInfoStr->NumberOfHistoryBuffers}
			};
			for (size_t i = 0; i < countof(BufferValues); ++i)
			{
				lRegRc = RegQueryValueEx(hkConsole, BufferValues[i].pszName, NULL, &nType, (LPBYTE)&nValue, &nSize);
				if ((lRegRc == 0) && (nType == REG_DWORD) && (nSize == sizeof(DWORD)))
				{
					if (nValue < BufferValues[i].nMin)
						nValue = BufferValues[i].nMin;
					else if (nValue > BufferValues[i].nMax)
						nValue = BufferValues[i].nMax;

					if (nValue != *BufferValues[i].pnVal)
						*BufferValues[i].pnVal = nValue;
				}
			}
		}

		// color table
		for(size_t i = 0; i < 16; i++)
			gpConsoleInfoStr->ColorTable[i] = DefaultColors[i];

		gpConsoleInfoStr->CodePage					= GetConsoleOutputCP();//0;//0x352;
		gpConsoleInfoStr->Hwnd						= inConWnd;
		gpConsoleInfoStr->ConsoleTitle[0] = 0;

		// Send data to console window
		SetConsoleInfo(inConWnd, gpConsoleInfoStr);
	}
}
	// Sets the console font properties.
	void SetFontProperties(int fontX, int fontY, wchar_t *fontName)
	{
		HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);

		/* Retrieving pointers for Windows Vista/7 Functions */
		PGetCurrentConsoleFontEx pGetCurrentConsoleFontEx = (PGetCurrentConsoleFontEx)
			GetProcAddress(GetModuleHandle("kernel32.dll"), "GetCurrentConsoleFontEx");
		PSetCurrentConsoleFontEx pSetCurrentConsoleFontEx = (PSetCurrentConsoleFontEx)
			GetProcAddress(GetModuleHandle("kernel32.dll"), "SetCurrentConsoleFontEx");

		/* Check for pointers: if they exist, we have Vista/7 and we can use them */
		if (pGetCurrentConsoleFontEx && pSetCurrentConsoleFontEx)
		{
			CONSOLE_FONT_INFOEX cfi = { sizeof(CONSOLE_FONT_INFOEX) };

			/* Tell the font info how big it is, to avoid memory corruption */
			cfi.cbSize = sizeof(CONSOLE_FONT_INFOEX);
			pGetCurrentConsoleFontEx(hOutput, TRUE, &cfi);

			/* Set the font type to name indicated by wide string literal */
			/* Set to 0 to keep current settings */
			lstrcpyW(cfi.FaceName, fontName);
			cfi.dwFontSize.X = fontX;
			cfi.dwFontSize.Y = fontY;
			cfi.FontFamily = 0; /* Set to 0x30 for Terminal font */
			cfi.FontWeight = 0;

			/* Set the console font info */
			pSetCurrentConsoleFontEx(hOutput, TRUE, &cfi);
		}
		else  /* We don't have access to the vista functions */
		{
			CONSOLE_INFO2 ci = { sizeof(ci) };
			HWND hwndConsole = GetConsoleWindow();

			GetConsoleSizeInfo(&ci, hOutput);

			/* Set to 0 to keep current settings */
			ci.FontSize.X = fontX;
			ci.FontSize.Y = fontY;
			ci.FontFamily = 0; /* Set to 0x30 for Terminal font */
			ci.FontWeight = 0;

			lstrcpyW(ci.FaceName, fontName);
			ci.CursorSize = 100;
			ci.FullScreen = FALSE;
			ci.QuickEdit = FALSE;
			ci.AutoPosition = 0x10000;
			ci.InsertMode = TRUE;
			ci.ScreenColors = MAKEWORD(0x7, 0x0);
			ci.PopupColors = MAKEWORD(0x5, 0xf);
			ci.HistoryNoDup = TRUE;
			ci.HistoryBufferSize = 50;
			ci.NumberOfHistoryBuffers = 4;

			ci.CodePage = 0;
			ci.Hwnd = hwndConsole;
			lstrcpyW(ci.ConsoleTitle, L"");

			SetConsoleInfo(hwndConsole, &ci);
		}
	}
예제 #4
0
int main(int argc, char* argv[])
{
    int         nResult             = false;
    int         nRetCode            = false;
    int         nLogInitFlag        = false;
    int         nMemInitFlag        = false;
    BOOL        bMemoryPoolInit     = false;
    BOOL        bHeapCheckInitFlag  = false;
    BOOL        bSOEditorInitFlag   = false;
    KGLOG_PARAM LogParam;
    char        szCWD[MAX_PATH];
    char*       pszRetCWD       = NULL;

#ifdef WIN32
    SetConsoleInfo();
#endif

#ifdef __GNUC__
    nRetCode = fork();
    if (nRetCode != 0)
    {
        // if fork error(-1), exit !
        // if parent process(!=0), exit !
        return 0;
    }

    setsid();
    //umask(0);
#endif

#if defined( __GNUC__ ) && defined( _DEBUG )
    HeapLeakChecker HeapChecker("HeapChecker");
    bHeapCheckInitFlag = true;
#endif

    tzset(); // initialize time conversion information (timezone)

    pszRetCWD = getcwd(szCWD, sizeof(szCWD));
    KG_PROCESS_ERROR(pszRetCWD);

    memset(&LogParam, 0, sizeof(LogParam));
    snprintf(LogParam.szPath, sizeof(LogParam.szPath), "%s/logs", szCWD);
    strcpy(LogParam.szIdent, "SOEditorServer");
    LogParam.nMaxLineEachFile = 65536;
    LogParam.Options = (KGLOG_OPTIONS)(KGLOG_OPTION_FILE | KGLOG_OPTION_CONSOLE);

    nRetCode = KGLogInit(LogParam, NULL);
    KG_PROCESS_ERROR(nRetCode);
    nLogInitFlag = true;

    nRetCode = KG_MemoryInit(NULL);
    KG_PROCESS_ERROR(nRetCode);
    nMemInitFlag = true;

    nRetCode = KMemory::Initialize(NULL);
    KGLOG_PROCESS_ERROR(nRetCode);
    bMemoryPoolInit = true;

    KGLogPrintf(KGLOG_INFO, "%s\n", "Editor server for JXOnline III");
    KGLogPrintf(KGLOG_INFO, "%s\n", "Build at " __TIME__ " " __DATE__);

#if defined(_WIN64) || defined(__x86_64__)
    KGLogPrintf(KGLOG_INFO, "%s\n", "x64 Version");
#endif

#if defined( __GNUC__ ) && defined( _DEBUG )
    if (bHeapCheckInitFlag && HeapChecker.IsActive())
    {
        KGLogPrintf(KGLOG_INFO, "Perftools heap leak checker is active -- Performance may suffer");
    }
    else
    {
        KGLogPrintf(KGLOG_INFO, "Heap checker is not active, to activate set the HEAPCHECK environment variable.");
    }
#endif

    g_pSOEditor = new KSOEditor();
    KGLOG_PROCESS_ERROR(g_pSOEditor);

    nRetCode = g_pSOEditor->Init();
    KGLOG_PROCESS_ERROR(nRetCode);
    bSOEditorInitFlag = true;

    KGLogPrintf(KGLOG_INFO, "Editor server startup ... ... [OK]\n");

#ifdef WIN32
    KGLogPrintf(KGLOG_INFO, "Press [Ctrl + C] to exit !\n");
#endif

#ifdef __GNUC__
    nRetCode = SetDaemon();
    KGLOG_PROCESS_ERROR(nRetCode);
#endif

    g_pSOEditor->Run();

    g_pSOEditor->UnInit();

    KGLogPrintf(KGLOG_INFO, "Game server exit !");

    nResult = true;
Exit0:

#ifdef WIN32
    puts("\nPress any key to exit !");
    getch();
#endif

    if (bSOEditorInitFlag)
    {
        g_pSOEditor->UnInit();
        bSOEditorInitFlag = false;
    }

    if (g_pSOEditor)
    {
        delete g_pSOEditor;
        g_pSOEditor = NULL;
    }

    if (bMemoryPoolInit)
    {
        KMemory::Finalize();
        bMemoryPoolInit = false;
    }

    if (nMemInitFlag)
    {
        KG_MemoryUnInit(NULL);
        nMemInitFlag = false;
    }

    if (nLogInitFlag)
    {
        KGLogUnInit(NULL);
        nLogInitFlag = false;
    }

#if defined( __GNUC__ ) && defined( _DEBUG )
    if (bHeapCheckInitFlag && !HeapChecker.NoLeaks())
    {
        bHeapCheckInitFlag = false;
        assert(NULL == "Heap Memory Leak");
    }
#endif
    return 0;
}
예제 #5
0
파일: main.cpp 프로젝트: viticm/pap2
int main(int argc, char *argv[])
{
    int nResult  = false;
    int nRetCode = false;
    KGLOG_PARAM LogParam  = {"Logs", "Jx3DBChecker", (KGLOG_OPTIONS)(KGLOG_OPTION_FILE | KGLOG_OPTION_CONSOLE), 100000};
    int nKGLogInitFlag    = false;
    KG_Jx3DBChecker Jx3DBChecker;
    int nJx3DBCheckerFlag = false;
    time_t lStartTime = 0;
    time_t lStopTime  = 0;
    struct tm *ptmTime = NULL;
    unsigned uRunningSeconds = 0;


#ifdef WIN32
    SetConsoleInfo();
#ifdef _DEBUG
    EnableMemLeakCheck();
#endif
#endif

    lStartTime = time(NULL);
    ptmTime = localtime(&lStartTime);
    KG_PROCESS_ERROR(ptmTime);
    printf(
        "Start Time: %d-%d-%d %d:%d:%d\n", 
        ptmTime->tm_year + 1900, 
        ptmTime->tm_mon + 1, 
        ptmTime->tm_mday,
        ptmTime->tm_hour, 
        ptmTime->tm_min, 
        ptmTime->tm_sec
    );

    puts("[Jx3DBChecker] Initializing ...");

    nRetCode = _SetRuntimeEnvironment(argv[0]);
    KG_PROCESS_ERROR(nRetCode);

    nRetCode = KGLogInit(LogParam, NULL);
    KG_PROCESS_ERROR(nRetCode);
    nKGLogInitFlag = true;

    nRetCode = Jx3DBChecker.Init();
    KGLOG_PROCESS_ERROR(nRetCode);
    nJx3DBCheckerFlag = true;

    nRetCode = Jx3DBChecker.Run();
    KGLOG_PROCESS_ERROR(nRetCode);

    lStopTime = time(NULL);
    ptmTime = localtime(&lStopTime);
    KGLOG_PROCESS_ERROR(ptmTime);
    printf(
        "Stop Time: %d-%d-%d %d:%d:%d\n", 
        ptmTime->tm_year + 1900, 
        ptmTime->tm_mon + 1, 
        ptmTime->tm_mday,
        ptmTime->tm_hour, 
        ptmTime->tm_min, 
        ptmTime->tm_sec
    );

    uRunningSeconds = (unsigned)(lStopTime - lStartTime);
    printf(
        "Program Running Time: %d days ,%d hours ,%d minutes, %d seconds.\n", 
        (uRunningSeconds / (60 * 60 * 24)),
        ((uRunningSeconds % (60 * 60 * 24)) / (60 * 60)),
        ((uRunningSeconds % (60 * 60)) / 60),
        (uRunningSeconds % 60)
    );

    nResult = true;
Exit0:
    if (nJx3DBCheckerFlag)
    {
        Jx3DBChecker.UnInit();
        nJx3DBCheckerFlag = false;
    }
    if (nKGLogInitFlag)
    {
        KGLogUnInit(NULL);
        nKGLogInitFlag = false;
    }
    return nResult ? 0 : 1;
}
예제 #6
0
파일: palette.c 프로젝트: AronKovacs/KonJI
/******************************************************************************
  SetConsolePalette

  Sets the console palette and font size.
******************************************************************************/
VOID WINAPI SetConsolePalette(COLORREF palette[], int fontX, int fontY, wchar_t *fontName)
{ 
  int i;
  HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);

    /* Retrieving pointers for Windows Vista/7 Functions */
  PGetCurrentConsoleFontEx pGetCurrentConsoleFontEx = (PGetCurrentConsoleFontEx)
    GetProcAddress(GetModuleHandle("kernel32.dll"), "GetCurrentConsoleFontEx");
  PSetCurrentConsoleFontEx pSetCurrentConsoleFontEx = (PSetCurrentConsoleFontEx)
    GetProcAddress(GetModuleHandle("kernel32.dll"), "SetCurrentConsoleFontEx");
  PGetConsoleScreenBufferInfoEx pGetConsoleScreenBufferInfoEx = (PGetConsoleScreenBufferInfoEx)
    GetProcAddress(GetModuleHandle("kernel32.dll"), "GetConsoleScreenBufferInfoEx");
  PSetConsoleScreenBufferInfoEx pSetConsoleScreenBufferInfoEx = (PSetConsoleScreenBufferInfoEx)
    GetProcAddress(GetModuleHandle("kernel32.dll"), "SetConsoleScreenBufferInfoEx");

    /* Check for pointers: if they exist, we have Vista/7 and we can use them */
  if (pGetCurrentConsoleFontEx && pSetCurrentConsoleFontEx &&
      pGetConsoleScreenBufferInfoEx && pSetConsoleScreenBufferInfoEx)
  {
    CONSOLE_SCREEN_BUFFER_INFOEX cbi; 
    CONSOLE_FONT_INFOEX cfi = {sizeof(CONSOLE_FONT_INFOEX)};

      /* Tell the font info how big it is, to avoid memory corruption */
    cfi.cbSize = sizeof(CONSOLE_FONT_INFOEX);
    pGetCurrentConsoleFontEx(hOutput, TRUE, &cfi);

      /* Set the font type to name indicated by wide string literal */
      /* Set to 0 to keep current settings */
    lstrcpyW(cfi.FaceName, fontName);
    cfi.dwFontSize.X = fontX;  
    cfi.dwFontSize.Y = fontY;
    cfi.FontFamily = 0; /* Set to 0x30 for Terminal font */
    cfi.FontWeight = 0;

      /* Set the console font info */
    pSetCurrentConsoleFontEx(hOutput, TRUE, &cfi);

      /* Get the size of the structure before filling the struct */
    cbi.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX);
    pGetConsoleScreenBufferInfoEx(hOutput, &cbi);

      /* Loop through the given palette, copying the data into the color table */
    for (i = 0 ; i < 16 ; ++i)
    {
      cbi.ColorTable[i] = palette[i];
    }
    
      /* Set the console screen buffer info */
    pSetConsoleScreenBufferInfoEx(hOutput, &cbi);
  }
  else  /* We don't have access to the vista functions */
  {
    int i;
    CONSOLE_INFO ci = { sizeof(ci) };
    HWND hwndConsole = GetConsoleWindow();

    GetConsoleSizeInfo(&ci, hOutput);

      /* Set to 0 to keep current settings */
    ci.FontSize.X = fontX;
    ci.FontSize.Y = fontY;
    ci.FontFamily = 0; /* Set to 0x30 for Terminal font */
    ci.FontWeight = 0;

    lstrcpyW(ci.FaceName, fontName); 
    ci.CursorSize = 100;
    ci.FullScreen = FALSE;
    ci.QuickEdit = FALSE;
    ci.AutoPosition = 0x10000;
    ci.InsertMode = TRUE;
    ci.ScreenColors = MAKEWORD(0x7, 0x0);
    ci.PopupColors = MAKEWORD(0x5, 0xf); 
    ci.HistoryNoDup = TRUE; 
    ci.HistoryBufferSize = 50; 
    ci.NumberOfHistoryBuffers = 4; 

    for(i = 0; i < 16; i++)
    {
      ci.ColorTable[i] = palette[i];
    }

    ci.CodePage = 0; 
    ci.Hwnd = hwndConsole;
    lstrcpyW(ci.ConsoleTitle, L""); 

    SetConsoleInfo(hwndConsole, &ci); 
  }
}