/* ====================================================================
 * 파    일 :	gameSrv.h
 * 목    적 :	
 * 작 성 자 :	곽철중
 * 작 성 일 :	06/12/21
 * 주의사항 :	
 * =================================================================== */
#ifndef __GAME_SERVER_H__
#define __GAME_SERVER_H__

//#ifndef WINVER
//#define WINVER          0x0500
//#endif
//
//#ifndef _WIN32_WINNT
//#define _WIN32_WINNT    0x0500
//#endif

#ifndef WSA_STARTUP_VER
#define WSA_STARTUP_VER 0x0002
#endif

#pragma once

// 윈속2    헤더 - link "ws2_32.lib"
#include <winsock2.h>
// 윈도우즈 헤더
#include <windows.h>
#include <winerror.h>
#include <lmerr.h>
#include <stdio.h>

#include "wsastartup.h"


#ifndef __DEFAULT_DEFINE__
#define __DEFAULT_DEFINE__

#define	DEFAULT_SQL_ACCOUNT		0x1000 // SQL Account  Request default type
#define	DEFAULT_SQL_GAME		0x2000 // SQL Game     "
#define	DEFAULT_GAME_PROCESS	0x4000 // Game Process "

#endif // __DEFAULT_DEFINE__


#include "sqlaccount.h"
#include "sqlgame.h"
#include "sender.h"
#include "recver.h"
#include "gameprocess.h"
#include "verbose.h"

class cGameSrv : public cWSAStartup
{
private:
// 서비스 및 공용 환경변수.
	SERVICE_STATUS_HANDLE mServiceStatusHandle;
	SERVICE_STATUS        mServiceStatus;

	TCHAR*                mCompanyName;
	TCHAR*                mServiceName;
	TCHAR*                mDisplayName;
	TCHAR*                mDescription;
	TCHAR*                mUserName;
	bool                  mRunService;
	WORD                  mVersion;

private:
// 환경변수
	DWORD                  mServerNo;
	DWORD                  mChannelNo;
	TCHAR                  mServerAddr[MAX_PATH];
	TCHAR                  mServerBroadcastRecv[MAX_PATH];
	TCHAR                  mServerBroadcastSend[MAX_PATH];
	TCHAR                  mServerFirewall[MAX_PATH];

private:
// 클래스.
	cSQLAccount*          mSqlAccount;
	cSQLGame*             mSqlGame;
	cSender*              mSender;
	cRecver*              mRecver;
	cGameProcess*         mGameProcess;
	cVerbose*             mVerbose;

private:
// 서비스 제어 메소드.
	bool                  InstallService     ( LPCTSTR binaryPathName, DWORD startType = SERVICE_DEMAND_START );
	bool                  UninstallService   ( void );

private:
// 응용프로그램 제어 메소드.
	DWORD                 Initialization     ( DWORD argc, LPTSTR* argv, DWORD* error );
	void                  Destroy            ( void );
	void                  Run                ( void );

private:
// Command Line 제어 메소드.
	int                   ErrorInsert        ( char* msg );

public:
// 클래스 생성 및 공용 메소드.
	cGameSrv(void);

	BOOL                  ConsolCtrlHandler  ( DWORD opcode );
	void                  ConsoleRun         ( DWORD argc, LPTSTR* argv );

	void                  ServiceCtrlHandler ( DWORD opcode );
	void                  ServiceRun         ( DWORD argc, LPTSTR* argv );

public:
// 클래스 공유 메소드.
	TCHAR*                GetServiceName     ( ) { return mServiceName; }
	TCHAR*                GetHostName        ( ) { return mFixedInfo->HostName; }

	cSQLAccount*          GetSQLAccount      ( ) { return mSqlAccount; }
	cSQLGame*             GetSQLGame         ( ) { return mSqlGame; }
	cSender*              GetSender          ( ) { return mSender; }
	cRecver*              GetRecver          ( ) { return mRecver; }
	cGameProcess*         GetGameProcess     ( ) { return mGameProcess; }

	bool                  PostServerEvent    ( char* message );

public:
// 클래스 파괴 메소드.
	virtual ~cGameSrv(void);
};

DWORD ErrorCode2String ( VOID** msgBuf, DWORD lastError = GetLastError(), WORD priLangId = LANG_NEUTRAL, WORD subLangId = SUBLANG_DEFAULT );

extern cGameSrv* g_gameSrv;
extern bool      g_verbose;
extern bool      g_fps;
extern bool      g_packet;

#endif // __GAME_SERVER_H__