コード例 #1
0
void CEasyNetLinkService::PrintInfo(UINT LogChannel)
{
	CLogManager::GetInstance()->PrintLog(LogChannel,ILogPrinter::LOG_LEVEL_NORMAL,0,
		_T("ServiceID=[%s] ListenAddress=%s:%u"),
		CClassifiedID(m_ReportID).ToStr(),
		GetLocalAddress().GetIPString(),
		GetLocalAddress().GetPort());
}
コード例 #2
0
ファイル: CConnClient.cpp プロジェクト: LaoZhongGu/RushGame
void CConnClient::OnServerCommand(const CGas2GacGC_Tell_Guids* pCmd)
{
	str_guid_t szGuidServer;
	str_guid_t szGuidConnection;

	GuidToString(pCmd->guidConnection, szGuidConnection);
	ErrLogMsg("Conn Guid", szGuidConnection);

	GuidToString(pCmd->guidServer, szGuidServer);	
	ErrLogMsg("Server GUID", szGuidServer);

	m_pSlowSigner = new CSlowSigner( pCmd->guidConnection );
	//memcpy( m_guidConn , pCmd->guidConnection , sizeof( m_guidConn) );

	CAddress address;

	if (GetRemoteAddress(address))
	{
		string strAddr;
		address.GetAddressAndPort(strAddr);
		ErrLogMsg("Server Addr", strAddr.c_str());
	}

	if (GetLocalAddress(address))
	{	
		string strAddr;
		address.GetAddressAndPort(strAddr);
		ErrLogMsg("Client Addr", strAddr.c_str());
	}
}
コード例 #3
0
ファイル: net.c プロジェクト: ewirch/qfusion
/*
* NET_Init
*/
void NET_Init( void )
{
    assert( !net_initialized );

    Sys_NET_Init();

    GetLocalAddress();

    net_initialized = qtrue;
}
コード例 #4
0
void CAgentService::LoadVariable()
{
	VAROBJECT 	*pObject;
	ENVENTRY	env_t;
	char		szBuffer[100];
	long		addr=0;
	int			n;

	// Initialize Variable
	VARAPI_Initialize(VARCONF_FILENAME, m_Root_node, TRUE);

	GetLocalAddress(szBuffer);
	addr = inet_addr(szBuffer);
	pObject = VARAPI_GetObjectByName("ethIpAddr");
	if (pObject != NULL) memcpy(pObject->var.stream.p, &addr, sizeof(IPADDR));

	memset(&env_t, 0, sizeof(ENVENTRY));
	GetEnvInfo(env_t.envKernelVersion, env_t.envGccVersion, env_t.envCpuName, &env_t.envCpuMips);

	pObject = VARAPI_GetObjectByName("envKernelVersion");
	if (pObject != NULL) strcpy(pObject->var.stream.p, env_t.envKernelVersion);

	pObject = VARAPI_GetObjectByName("envGccVersion");
	if (pObject != NULL) strcpy(pObject->var.stream.p, env_t.envGccVersion);

	pObject = VARAPI_GetObjectByName("envCpuName");
	if (pObject != NULL) strcpy(pObject->var.stream.p, env_t.envCpuName);

	pObject = VARAPI_GetObjectByName("envCpuMips");
	if (pObject != NULL) pObject->var.stream.u32 = HostToLittleShort(env_t.envCpuMips);

    /** Rewriter(Q) : testmode가 무엇인지 확인해야 함 */
	GetFileValue("/app/conf/testmode", &n);
	m_bGprsPerfTestMode = (n > 0) ? TRUE : FALSE;

    if(GetFileString("/app/conf/mcusystype", szBuffer, sizeof(szBuffer), "OUTDOOR", TRUE)
            && strncasecmp(szBuffer,"INDOOR",strlen("INDOOR"))==0) {
        m_nSystemType = MCU_TYPE_INDOOR;
    }

    /*-- Pulse Meter Type을 읽어온다 --*/
    LoadSensorType();

    /*-- Patch 정보를 읽어온다 --*/
    LoadPatchList();

    /*-- Patch 5-1949 --*/
#if     defined(__PATCH_5_1949__)
    m_nDebugLevel &= (*m_pbPatch_5_1949 ? 0x00 : 0xFF);
#endif
    
}
コード例 #5
0
ファイル: AsyncLogThread.cpp プロジェクト: victorzjl/BPE
void CHpsAsyncLogThread::StartInThread()
{
	m_tmDetailLog.Start();
	m_tmSelfcheck.Start();
	m_tmReport.Start();
	m_tmConnectWarn.Start();
	m_logConfg.Load();
	m_logConfg.GetLogParam("default", m_defautLogKey1, m_defautLogKey2);


	char pIp[16] = { 0 };
	if (GetLocalAddress(pIp))
	{
		m_strIp = pIp;
	}
	else
	{
		m_strIp = "0.0.0.0";
	}
	

	time_t curTime;
    time(&curTime);   

    std::stringstream sout; 
    sout<<"{";     

    //session manager thread
    sout<< "\"HPS SessionManagerThread\":{\"error_id\":" << "60075000"
    << ",\"stat\":" << 0
    << ",\"msg\":\"" << "ThreadNum is \""
    << ",\"timestamp\":" << curTime
    << ",\"ip\":\""<< m_strIp << "\""<< "}"; 

     //sos session
    sout<< ",\"HPS SosSession\":{\"error_id\":" << "60075001"
    << ",\"stat\":" << 0
    << ",\"msg\":\"" << "ActiveSosSessionNum is "
    << ", DeadSosSession is " 
    << "\",\"timestamp\":" << curTime
    << ",\"ip\":\""<< m_strIp << "\"}"; 
     
    sout<< "}";

	{
		boost::mutex::scoped_lock sl(m_mutex);
	    m_strSelfCheck = sout.str(); 
	}
}
コード例 #6
0
// Wraps GetLocalAddress() to provide a Python method interface.
// Takes no arguments.
//
// Returns local device address as Python string.
static PyObject* LightBlue_GetLocalAddress(PyObject* self, PyObject* args) 
{
    TBTDevAddr addr;
    TBuf8<6*2+5> addrString;
    
    if (!PyArg_ParseTuple(args, ""))
        return NULL;    
    
    TInt err = GetLocalAddress(addr);
    if (err) 
        return SPyErr_SetFromSymbianOSErr(err);
        
    DevAddressToString(addr, addrString);
    
    return Py_BuildValue("s#", addrString.Ptr(), addrString.Length());
}
コード例 #7
0
ファイル: CConnClient.cpp プロジェクト: LaoZhongGu/RushGame
void CConnClient::ShutDown(const char* szMsg)
{
	if(m_bShutting)
		return;
	m_bShutting = true;
	CCoreSceneMgrClient::Inst()->DestroyMainSceneIfNotBeingUsedByLogic();
	CTimeSystemClient::Inst()->UnRegister(this);
	if (IntShutDown() && szMsg)
	{
		ostringstream strm;
		CAddress addr;
		const char* szUserName = GetValue("UserName");
		szUserName = szUserName?szUserName:"";
		GetLocalAddress(addr);
		LogTime(strm);
		strm << " account:" << szUserName << " reason:" << szMsg << " localip:" << addr.GetAddress() << " remoteip: " << endl;
		LogOnOffLineMsg(strm.str().c_str());
	}
	Inst()=NULL;
}
コード例 #8
0
ファイル: irc.cpp プロジェクト: StealthCash/STX
void ThreadIRCSeed()
{
    // Don't connect to IRC if we won't use IPv4 connections.
    if (IsLimited(NET_IPV4))
        return;

    // ... or if we won't make outbound connections and won't accept inbound ones.
    if (mapArgs.count("-connect") && fNoListen)
        return;

    // ... or if IRC is not enabled.
    if (GetBoolArg("-irc", false))
        return;
    
    int nErrorWait = 10;
    int nRetryWait = 10;
    int nNameRetry = 0;

    for(;;)
    {
        boost::this_thread::interruption_point();
        CService addrConnect("92.243.23.21", 6667); // irc.lfnet.org

        CService addrIRC("irc.lfnet.org", 6667, true);
        if (addrIRC.IsValid())
            addrConnect = addrIRC;

        SOCKET hSocket;
        if (!ConnectSocket(addrConnect, hSocket, nConnectTimeout))
        {
            LogPrintf("IRC connect failed\n");
            nErrorWait = nErrorWait * 11 / 10;
            if (Wait(nErrorWait += 60))
                continue;
            else
                return;
        };

        if (!RecvUntil(hSocket, "Found your hostname", "using your IP address instead", "Couldn't look up your hostname", "ignoring hostname"))
        {
            closesocket(hSocket);
            hSocket = INVALID_SOCKET;
            nErrorWait = nErrorWait * 11 / 10;
            if (Wait(nErrorWait += 60))
                continue;
            else
                return;
        };

        CNetAddr addrIPv4("1.2.3.4"); // arbitrary IPv4 address to make GetLocal prefer IPv4 addresses
        CService addrLocal;
        std::string strMyName;
        // Don't use our IP as our nick if we're not listening
        // or if it keeps failing because the nick is already in use.
        if (!fNoListen && GetLocal(addrLocal, &addrIPv4) && nNameRetry<3)
            strMyName = EncodeAddress(GetLocalAddress(&addrConnect));
        if (strMyName == "")
            strMyName = strprintf("x%u", GetRand(1000000000));

        Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str());
        Send(hSocket, strprintf("USER %s 8 * : %s\r", strMyName.c_str(), strMyName.c_str()).c_str());

        int nRet = RecvUntil(hSocket, " 004 ", " 433 ");
        if (nRet != 1)
        {
            closesocket(hSocket);
            hSocket = INVALID_SOCKET;
            if (nRet == 2)
            {
                LogPrintf("IRC name already in use\n");
                nNameRetry++;
                Wait(10);
                continue;
            };
            nErrorWait = nErrorWait * 11 / 10;
            if (Wait(nErrorWait += 60))
                continue;
            else
                return;
        };
        
        nNameRetry = 0;
        MilliSleep(500);

        // Get our external IP from the IRC server and re-nick before joining the channel
        CNetAddr addrFromIRC;
        if (GetIPFromIRC(hSocket, strMyName, addrFromIRC))
        {
            LogPrintf("GetIPFromIRC() returned %s\n", addrFromIRC.ToString().c_str());
            // Don't use our IP as our nick if we're not listening
            if (!fNoListen && addrFromIRC.IsRoutable())
            {
                // IRC lets you to re-nick
                AddLocal(addrFromIRC, LOCAL_IRC);
                strMyName = EncodeAddress(GetLocalAddress(&addrConnect));
                Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str());
            };
        };

        if (fTestNet)
        {
            Send(hSocket, "JOIN #sdcoinTEST\r");
            Send(hSocket, "WHO #sdcoinTEST\r");
        } else
        {
            // randomly join #StealthCash00-#StealthCash05
            //int channel_number = GetRandInt(5);

            // Channel number is always 0 for initial release
            int channel_number = 0;
            Send(hSocket, strprintf("JOIN #sdcoin%02d\r", channel_number).c_str());
            Send(hSocket, strprintf("WHO #sdcoin%02d\r", channel_number).c_str());
        };

        int64_t nStart = GetTime();
        std::string strLine;
        strLine.reserve(10000);
        while (RecvLineIRC(hSocket, strLine))
        {
            boost::this_thread::interruption_point();
            if (strLine.empty() || strLine.size() > 900 || strLine[0] != ':')
                continue;

            std::vector<std::string> vWords;
            ParseString(strLine, ' ', vWords);
            if (vWords.size() < 2)
                continue;

            char pszName[10000];
            pszName[0] = '\0';

            if (vWords[1] == "352" && vWords.size() >= 8)
            {
                // index 7 is limited to 16 characters
                // could get full length name at index 10, but would be different from join messages
                strlcpy(pszName, vWords[7].c_str(), sizeof(pszName));
                LogPrintf("IRC got who\n");
            };

            if (vWords[1] == "JOIN" && vWords[0].size() > 1)
            {
                // :[email protected] JOIN :#channelname
                strlcpy(pszName, vWords[0].c_str() + 1, sizeof(pszName));
                if (strchr(pszName, '!'))
                    *strchr(pszName, '!') = '\0';
                LogPrintf("IRC got join\n");
            };

            if (pszName[0] == 'u')
            {
                CAddress addr;
                if (DecodeAddress(pszName, addr))
                {
                    addr.nTime = GetAdjustedTime();
                    if (addrman.Add(addr, addrConnect, 51 * 60))
                        LogPrintf("IRC got new address: %s\n", addr.ToString().c_str());
                    nGotIRCAddresses++;
                } else
                {
                    LogPrintf("IRC decode failed\n");
                };
            };
        };
        closesocket(hSocket);
        hSocket = INVALID_SOCKET;

        if (GetTime() - nStart > 20 * 60)
        {
            nErrorWait /= 3;
            nRetryWait /= 3;
        };

        nRetryWait = nRetryWait * 11 / 10;
        if (!Wait(nRetryWait += 60))
            return;
    };
}
コード例 #9
0
ファイル: httpmt.c プロジェクト: Budskii/ulib-win
BOOL StartHTTP(LPHTTPSERVINFO lpInfo)
{
	SOCKADDR_IN		saServer;		
	LPSERVENT		lpServEnt;		
	unsigned		ThreadAddr;
	char			szBuf[256];		
	char			szAddress[80];
	DWORD			dwAddrStrLen;
    int				nRet;			

	//
	// Save the Window handle and message
	// ID for further use
	//
	ghwnd    = lpInfo->hwnd;
	guAppMsg = lpInfo->uMsgApp;
	if (lpInfo->lpRootDir != NULL)
		strcpy(szWebRoot, lpInfo->lpRootDir);
	else
		strcpy(szWebRoot, "/WebPages");

	//
	// Create the exit signal event object
	//
	ghExit = CreateEvent(NULL,		// Security
						 TRUE,		// Manual reset
						 FALSE,		// Initial State
						 NULL);		// Name
	if (ghExit == NULL)
		return FALSE;

 	//
	// Create a TCP/IP stream socket
	//
	listenSocket = socket(AF_INET, 
						  SOCK_STREAM, 
						  IPPROTO_TCP);
	if (listenSocket == INVALID_SOCKET)
	{
		LogWinSockError(ghwnd, 
						"Could not create listen socket",
						WSAGetLastError());
		return FALSE;
	}

	//
	// If a specific port number was specified
	// then use it
	//
	if (lpInfo->nPort != 0)
		saServer.sin_port = htons(lpInfo->nPort);
	else
	{
		//
		// Find a port number
		//
		lpServEnt = getservbyname("http", "tcp");
		if (lpServEnt != NULL)
			saServer.sin_port = lpServEnt->s_port;
		else
			saServer.sin_port = htons(HTTPPORT);
	}

	//
	// Fill in the rest of the address structure
	//
	saServer.sin_family = AF_INET;
	saServer.sin_addr.s_addr = INADDR_ANY;

	//
	// bind our name to the socket
	//
	nRet = bind(listenSocket, 
				(LPSOCKADDR)&saServer, 
				sizeof(struct sockaddr));
	if (nRet == SOCKET_ERROR)
	{
		LogWinSockError(ghwnd,
						 "bind() error",
						 WSAGetLastError());
		closesocket(listenSocket);
		return FALSE;
	}

	//
	// Set the socket to listen
	//
	nRet = listen(listenSocket, SOMAXCONN);
	if (nRet == SOCKET_ERROR)
	{
		LogWinSockError(ghwnd,
						 "listen() error",
						 WSAGetLastError());
		closesocket(listenSocket);
		return FALSE;
	}

	//
	// Create the listening thread
	//
	gdwListenThread = _beginthreadex(
							NULL,		 // Security
							0,			 // Stack size
							ListenThread,// Function address
							&ghExit,	 // Argument
							0,			 // Init flag
							&ThreadAddr);// Thread address
	if (!gdwListenThread)
	{
		LogEvent(ghwnd, 
				 "Could not create listening thread: %d",
				 GetLastError());
		closesocket(listenSocket);
		return FALSE;
	}

	//
	// Display the host name and address
	//
	gethostname(szBuf, sizeof(szBuf));
	dwAddrStrLen = sizeof(szAddress);
	GetLocalAddress(szAddress, &dwAddrStrLen);
	LogEvent(ghwnd, 
			 "HTTP Server Started: %s [%s] on port %d",
			 szBuf,
			 szAddress,
			 htons(saServer.sin_port));

	return TRUE;
}
コード例 #10
0
ファイル: PinAgent.cpp プロジェクト: AmesianX/tree-cbass
int _tmain(int argc, _TCHAR* argv[])
{

	WORD sockVersion;
	WSADATA wsaData;
	int rVal;
	DWORD thread;


	//wsock32 initialized for usage
	sockVersion = MAKEWORD(1,1);
	WSAStartup(sockVersion, &wsaData);

	//create server socket
	SOCKET serverSocket = socket(AF_INET, SOCK_STREAM, 0);

	if(serverSocket == INVALID_SOCKET)
	{
	   printf("Failed socket()");
	   return -1;
	}

	SOCKADDR_IN sin;
	sin.sin_family = PF_INET;
	sin.sin_port = htons(SERVER_PORT);
	sin.sin_addr.s_addr = INADDR_ANY;

	//bind the socket
	rVal = bind(serverSocket, (LPSOCKADDR)&sin, sizeof(sin));
	if(rVal == SOCKET_ERROR)
	{
	   printf("Failed bind()");
	   WSACleanup();
	   return -1;
	}

	//get socket to listen
	rVal = listen(serverSocket, 10);
	if(rVal == SOCKET_ERROR)
	{
	   printf("Failed listen()");
	   WSACleanup();
	   return -1;
	}

	char			szBuf[256];		
	char			szAddress[80];
	DWORD			dwAddrStrLen;
	//
	// Display the host name and address
	//
	gethostname(szBuf, sizeof(szBuf));
	dwAddrStrLen = sizeof(szAddress);
	GetLocalAddress(szAddress, &dwAddrStrLen);
	printf( "PinTrace Remote Agent: %s [%s] on port %d\n",szBuf,szAddress,SERVER_PORT);

	SOCKET clientSocket;

	while ( 1 ) {

		/*  Wait for a connection, then accept() it  */
		if ( (clientSocket = accept(serverSocket, NULL, NULL) ) == INVALID_SOCKET) {
		   printf("Failed accept()");
		}
		else
		{
			printf("Client connected\r\n");
			CreateThread(NULL, 0,process_pintrace,(LPVOID)clientSocket, 0, &thread);
		}
	}


	//close server socket
	closesocket(serverSocket);

	WSACleanup();

	return S_OK;
}
コード例 #11
0
ファイル: WinMain.cpp プロジェクト: Skintillion/UAS2
int CALLBACK MainWindowProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	static HWND hWndStart;
	static HWND hWndClearObjs;
	static HWND hWndDiscAll;
	static HWND hWndDBTYPE;
	static HWND hWndDBIP;
	static HWND hWndDBNAME;
	static HWND hWndDBUSER;
	static HWND hWndDBPASSWORD;
	static HWND hWndCONFIG;
	static HWND hWndACCESSFILE;
	static HWND hWndPrivate;
	static HWND hWndUpdate;

	static HWND hWndSettings[30];
	static BOOL fExit = FALSE;
	static HWND hWndExit;
	static UINT s_uTaskbarRestart;
	static BOOL fMinimized = FALSE;

	switch ( msg )
	{	
		case WM_INITDIALOG:
		{
			HICON hIcon;
			hIcon = LoadIcon( g_hInstance, MAKEINTRESOURCE( IDI_ICON ) );
			SendMessage( hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon );
			SendMessage( hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon );
			DeleteObject( hIcon );

			s_uTaskbarRestart = RegisterWindowMessage( TEXT( "TaskbarCreated" ) );

			g_hWndConsole	= GetDlgItem( hWnd, IDC_CONSOLE );
			g_hWndHelpTitle	= GetDlgItem( hWnd, IDC_HELP_TITLE );
			g_hWndHelp		= GetDlgItem( hWnd, IDC_HELP_TEXT );
			hWndDBTYPE		= GetDlgItem( hWnd, IDC_DBTYPE );
			hWndDBIP		= GetDlgItem( hWnd, IDC_DBIP );
			hWndDBNAME		= GetDlgItem( hWnd, IDC_DBNAME );
			hWndDBUSER		= GetDlgItem( hWnd, IDC_DBUSER );
			hWndDBPASSWORD	= GetDlgItem( hWnd, IDC_DBPASSWORD );
			hWndACCESSFILE	= GetDlgItem( hWnd, IDC_ACCESS_FILE );
			hWndCONFIG		= GetDlgItem( hWnd, IDC_CONFIG );
			hWndPrivate		= GetDlgItem( hWnd, IDC_SERVER );
			hWndUpdate		= GetDlgItem( hWnd, IDC_BTN_UPDATE );

			hWndSettings[0]	= GetDlgItem( hWnd, IDC_STATIP );
			hWndSettings[1]	= GetDlgItem( hWnd, IDC_STATCP );
			hWndSettings[2]	= GetDlgItem( hWnd, IDC_STATWP );
			hWndSettings[3]	= GetDlgItem( hWnd, IDC_STATDBIP );
			hWndSettings[4]	= GetDlgItem( hWnd, IDC_STATDBN );
			hWndSettings[5]	= GetDlgItem( hWnd, IDC_STATDBU );
			hWndSettings[6]	= GetDlgItem( hWnd, IDC_STATDBPASS );
			hWndSettings[7]	= GetDlgItem( hWnd, IDC_LOCALIP );
			hWndSettings[8]	= GetDlgItem( hWnd, IDC_CHARPORT );
			hWndSettings[9]	= GetDlgItem( hWnd, IDC_WORLDPORT );
			hWndSettings[10]	= GetDlgItem( hWnd, IDC_MYSQL_DB );
			hWndSettings[11]	= GetDlgItem( hWnd, IDC_MSSQL_DB );
			hWndSettings[12]	= GetDlgItem( hWnd, IDC_ACCESS_DB );
			hWndSettings[13]	= GetDlgItem( hWnd, IDC_SETTING_FRAME );
			hWndSettings[14]	= GetDlgItem( hWnd, IDC_FRAME_DB );
			hWndSettings[15]	= GetDlgItem( hWnd, IDC_STAT_MAXUSERS );
			hWndSettings[16]	= GetDlgItem( hWnd, IDC_MAX_USERS );
			hWndSettings[17]	= GetDlgItem( hWnd, IDC_STAT_SNAME );
			hWndSettings[18]	= GetDlgItem( hWnd, IDC_ED_SNAME );
							
			WSADATA		wsaData;
			struct hostent *host;
			USHORT		wVersionRequested = 0x0202;
 
			UpdateConsole( " Initializing Winsock 2.0 ... ", !WSAStartup( wVersionRequested, &wsaData ) );
			
			host = NULL;
/*
			////////// Read in Data
			FILE *pcStatConfig = fopen( "status.ini","rt" );

			if ( pcStatConfig )
			{
				char line[100];

				while ( !feof( pcStatConfig ) )
				{
					fgets( line, 100, pcStatConfig );
					char temp[100];
					char strData[50];
					char value[50];

					memcpy(temp,line,sizeof(line));
					char* pszSepTemp = strchr(temp, (int)'=');

					if(pszSepTemp == NULL)
					{
					}
					else
					{
						*pszSepTemp = '\0';
						sprintf(strData,"%s",temp);
					}

					char* pszSep = strchr(line, (int)'=');	

					if(pszSep == NULL)
					{
						// No data
					}
					else
					{
						*pszSep = '\0';
						++pszSep;
						char* pszValue = strchr(pszSep, (int)';');
						if(pszValue == NULL){
						}
						else
						{
							*pszValue = '\0';
						}
					
						sprintf(value,"%s",pszSep);
						
						if (lstrcmpi(strData,"Server") == 0)
							{
								if( lstrcmpi(value,"Private") == 0)
								{
									UpdateConsole(" Server: Private\r\n");
									cMasterServer::cStatus->m_fPrivate = 1;
								}
								else
								{
									UpdateConsole(" Server: Public\r\n");
									cMasterServer::cStatus->m_fPrivate = 0;
								}
							}
						else if(lstrcmpi(strData,"Host") == 0)
							{
								if(isalpha(value[0]))
								{
									//Do DNS Lookup for IP
									host = gethostbyname(value);
									memcpy(cMasterServer::cStatus->m_strHost,inet_ntoa(*(struct in_addr *) host->h_addr_list[0]),16);
								}
								else
								{
									memcpy(cMasterServer::cStatus->m_strHost,value,sizeof(value));
								}	
							}
						else if(lstrcmpi(strData,"Port") == 0)
							{
								cMasterServer::cStatus->m_sPort = atoi(value);
							}
						else if(lstrcmpi(strData,"Path") == 0)
							{
								memcpy(cMasterServer::cStatus->m_strHTTP,value,sizeof(value));
							}					
						else if(lstrcmpi(strData,"ID") == 0)
							{
								cMasterServer::cStatus->m_sID = atol(value);
							}
						else if(lstrcmpi(strData,"Serial") == 0)
							{
								memcpy(cMasterServer::cStatus->m_sSer,value,sizeof(value));
							}
						else if(lstrcmpi(strData,"Key") == 0)
							{
								memcpy(cMasterServer::cStatus->m_sKey,value,sizeof(value));
							}
						else if(lstrcmpi(strData,"Client") == 0)
							{
								memcpy(cMasterServer::cStatus->m_cVersion,value,sizeof(value));
							}
						else if(lstrcmpi(strData,"MaxUsers") == 0)
							{
								cMasterServer::cStatus->m_dwMax = atol(value);
							}
						else
							{
							//	UpdateConsole("Error in status.ini   %s\r\n", strData);
							}
					}
				}
				fclose( pcStatConfig );
			}
			else
			{
				cMasterServer::cStatus->m_fPrivate = true;

			}
*/
			cMasterServer::cStatus->m_fPrivate = true;

			//////////////////
			SetDlgItemText( hWnd, IDC_VERSIONTEXT, SERVERVERSION);
			SetDlgItemText( hWnd, IDC_VERSIONTEXT2, STRFILEVER);

			DWORD dwLength;
			DWORD dwType = REG_SZ;
			char szTemp[5];
			char szDBType[2];
			char szStatusTemp[20];
			char szHostTemp[64];

			HKEY hKey;
			RegCreateKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\UAS", NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL );
		
			////////////////////////
			// Server Status Settings
			dwLength = sizeof( szStatusTemp );
			if ( ( RegQueryValueEx( hKey, "Private", NULL, &dwType, (BYTE*)&szStatusTemp, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				cMasterServer::cStatus->m_fPrivate = atoi(szStatusTemp);
				CheckDlgButton( hWnd, IDC_SERVER, cMasterServer::cStatus->m_fPrivate );
			}
			else
			{
				CheckDlgButton( hWnd, IDC_SERVER, 1 );
				cMasterServer::cStatus->m_fPrivate = 1;
			}
			
			dwLength = sizeof( szHostTemp );
			if ( ( RegQueryValueEx( hKey, "Status Host", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				if(isalpha(szHostTemp[0]))
				{
					//Do DNS Lookup for IP
					host = gethostbyname(szHostTemp);
					memcpy(cMasterServer::cStatus->m_strHost,inet_ntoa(*(struct in_addr *) host->h_addr_list[0]),16);
					SetDlgItemText( hWnd, IDC_ED_HOST, szHostTemp );
				}
				else
				{
					memcpy(cMasterServer::cStatus->m_strHost,szHostTemp,sizeof(szHostTemp));
					SetDlgItemText( hWnd, IDC_ED_HOST, szHostTemp );
				}
			}
			else
			{
				SetDlgItemText( hWnd, IDC_ED_HOST, "127.0.0.1" );
				memcpy(cMasterServer::cStatus->m_strHost,"127.0.0.1",10);
			}
						
			dwLength = sizeof( szTemp );
			if ( ( RegQueryValueEx( hKey, "HTTP Port", NULL, &dwType, (BYTE*)&szTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_ED_PORT, szTemp );
				cMasterServer::cStatus->m_sPort = atoi(szTemp);
			}
			else
			{
				SetDlgItemText( hWnd, IDC_ED_PORT, "80" );
				cMasterServer::cStatus->m_sPort = 80;
			}

			dwLength = sizeof( szTemp );
			if ( ( RegQueryValueEx( hKey, "Server ID", NULL, &dwType, (BYTE*)&szTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_ED_ID, szTemp );
				cMasterServer::cStatus->m_sID = atol(szTemp);
			}
			else
			{
				SetDlgItemText( hWnd, IDC_ED_ID, "0" );
				cMasterServer::cStatus->m_sID = 0;
			}

			dwLength = sizeof( szHostTemp );
			if ( ( RegQueryValueEx( hKey, "Server Serial", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_ED_SERIAL, szHostTemp );
				memcpy(cMasterServer::cStatus->m_sSer,szHostTemp,sizeof(szHostTemp));
			}
			else
			{
				SetDlgItemText( hWnd, IDC_ED_SERIAL, "0" );
				memcpy(cMasterServer::cStatus->m_sSer,"0",2);
			}
			
			dwLength = sizeof( szHostTemp );
			if ( ( RegQueryValueEx( hKey, "Server Key", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_ED_KEY, szHostTemp );
				memcpy(cMasterServer::cStatus->m_sKey,szHostTemp,sizeof(szHostTemp));
			}
			else
			{
				SetDlgItemText( hWnd, IDC_ED_KEY, "000000" );
				memcpy(cMasterServer::cStatus->m_sKey,"000000",7);
			}

			dwLength = sizeof( szHostTemp );
			if ( ( RegQueryValueEx( hKey, "Client Support", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_ED_CLIENT, szHostTemp );
				memcpy(cMasterServer::cStatus->m_cVersion,szHostTemp,sizeof(szHostTemp));
			}
			else
			{
				SetDlgItemText( hWnd, IDC_ED_CLIENT, "53" );
				memcpy(cMasterServer::cStatus->m_cVersion,"53",3);
			}
						
			dwLength = sizeof( szHostTemp );
			if ( ( RegQueryValueEx( hKey, "HTTP Path", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_ED_URL, szHostTemp );
				memcpy(cMasterServer::cStatus->m_strHTTP,szHostTemp,sizeof(szHostTemp));
			}
			else
			{
				SetDlgItemText( hWnd, IDC_ED_URL, "/" );
				memcpy(cMasterServer::cStatus->m_strHTTP,"/",2);
			}
			
			////////////////////////
			// Server Settings
			// Server Name
			dwLength = sizeof( szHostTemp );
			if ( ( RegQueryValueEx( hKey, "Server Name", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_STAT_NAME, szHostTemp );
				SetDlgItemText( hWnd, IDC_ED_SNAME, szHostTemp );
				memcpy(cMasterServer::m_szServerName,szHostTemp,sizeof(szHostTemp));
			}
			else
			{
				SetDlgItemText( hWnd, IDC_ED_SNAME, "World Name" );
				SetDlgItemText( hWnd, IDC_STAT_NAME, "World Name" );
				sprintf(cMasterServer::m_szServerName,"World Name" );
			}

			dwLength = sizeof( szHostTemp );
			if ( ( RegQueryValueEx( hKey, "Max Clients", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_MAX_USERS, szHostTemp );
				cMasterServer::cStatus->m_dwMax = atol(szHostTemp);
			}
			else
			{
				SetDlgItemText( hWnd, IDC_MAX_USERS, "0" );
				cMasterServer::cStatus->m_dwMax = 0x0L;
			}

			//Character Server Port
			dwLength = sizeof( szTemp );
			if ( ( RegQueryValueEx( hKey, "CharPort", NULL, &dwType, (BYTE*)&szTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
				SetDlgItemText( hWnd, IDC_CHARPORT, szTemp );
			else
				SetDlgItemText( hWnd, IDC_CHARPORT, "9002" );

			// World Server Port
			dwLength = sizeof( szTemp );
			if ( ( RegQueryValueEx( hKey, "WorldPort", NULL, &dwType, (BYTE*)&szTemp, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
				SetDlgItemText( hWnd, IDC_WORLDPORT, szTemp );
			else
				SetDlgItemText( hWnd, IDC_WORLDPORT, "9004" );
			
			/////////////
			// Database Settings
	
			dwLength = sizeof( szDBType );
			if ( ( RegQueryValueEx( hKey, "DBType", NULL, &dwType, (BYTE*)&szDBType, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{	// Set Radio button depending on Value
				SetDlgItemText( hWnd, IDC_DBTYPE, szDBType );
				g_DBType = szDBType[0] - 0x30;
				switch(g_DBType)
				{
					case 1:
					{
						CheckDlgButton( hWnd, IDC_ACCESS_DB, 1 );
						CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
						CheckDlgButton( hWnd, IDC_MYSQL_DB, 0 );
									
						// Disable dialog boxes
						EnableWindow( hWndDBIP, FALSE );
						EnableWindow( hWndDBNAME, FALSE );
						EnableWindow( hWndDBUSER, FALSE );
						EnableWindow( hWndDBPASSWORD, FALSE );
						break;
					}
					case 2:
					{					
						CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
						CheckDlgButton( hWnd, IDC_MSSQL_DB, 1 );
						CheckDlgButton( hWnd, IDC_MYSQL_DB, 0 );
						
						// Enable dialog boxes
						EnableWindow( hWndDBIP, TRUE );
						EnableWindow( hWndDBNAME, TRUE );
						EnableWindow( hWndDBUSER, TRUE );
						EnableWindow( hWndDBPASSWORD, TRUE );
						break;
					}
					case 3:
					{
						CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
						CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
						CheckDlgButton( hWnd, IDC_MYSQL_DB, 1 );
						
						// Enable dialog boxes
						EnableWindow( hWndDBIP, TRUE );
						EnableWindow( hWndDBNAME, TRUE );
						EnableWindow( hWndDBUSER, TRUE );
						EnableWindow( hWndDBPASSWORD, TRUE );
						break;
					}

					default:
					{
						CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
						CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
						CheckDlgButton( hWnd, IDC_MYSQL_DB, 1 );
									
						// Enable dialog boxes
						EnableWindow( hWndDBIP, TRUE );
						EnableWindow( hWndDBNAME, TRUE );
						EnableWindow( hWndDBUSER, TRUE );
						EnableWindow( hWndDBPASSWORD, TRUE );
						break;
					}
				}
			}
			else
			{
				// DBType = Default -- MySQL db
				CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
				CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
				CheckDlgButton( hWnd, IDC_MYSQL_DB, 1 );
			}

			dwLength = sizeof( g_szDBIP );
			if ( ( RegQueryValueEx( hKey, "DBIP", NULL, &dwType, (BYTE*)&g_szDBIP, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
				SetDlgItemText( hWnd, IDC_DBIP, g_szDBIP );
			else
				SetDlgItemText( hWnd, IDC_DBIP, "0.0.0.0" );
			
			dwLength = sizeof( g_szDBNAME );
			if ( ( RegQueryValueEx( hKey, "DBNAME", NULL, &dwType, (BYTE*)&g_szDBNAME, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
				SetDlgItemText( hWnd, IDC_DBNAME, g_szDBNAME );
			else
				SetDlgItemText( hWnd, IDC_DBNAME, "uas2" );
			
			dwLength = sizeof( g_szDBUSER );
			if ( ( RegQueryValueEx( hKey, "DBUSER", NULL, &dwType, (BYTE*)&g_szDBUSER, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
				SetDlgItemText( hWnd, IDC_DBUSER, g_szDBUSER );
			else
				SetDlgItemText( hWnd, IDC_DBUSER, "uas2" );
			
			dwLength = sizeof( g_szDBPASSWORD );
			if ( ( RegQueryValueEx( hKey, "DBPASSWORD", NULL, &dwType, (BYTE*)&g_szDBPASSWORD, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
				SetDlgItemText( hWnd, IDC_DBPASSWORD, g_szDBPASSWORD );
			else
				SetDlgItemText( hWnd, IDC_DBPASSWORD, "" );
//////////////////////////////////////////////////////////////////

			// Local IP
			dwLength = sizeof( g_szLocalIP );
			if ( ( RegQueryValueEx( hKey, "LocalIP", NULL, &dwType, (BYTE*)&g_szLocalIP, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
				SetDlgItemText( hWnd, IDC_LOCALIP, g_szLocalIP );
			else
			{
				char szLocalHostName[80];
				DWORD dwSize = sizeof( szLocalHostName );
				if ( GetLocalAddress( szLocalHostName, &dwSize ) == 0 )
					SetDlgItemText( hWnd, IDC_LOCALIP, szLocalHostName );
				else
					SetDlgItemText( hWnd, IDC_LOCALIP, "127.0.0.1" );
			}
	
			// Access Database 
			char	szDirBuff[MAX_PATH+1];
			dwLength = sizeof( cWorldManager::g_szAccessFile );
			if ( ( RegQueryValueEx( hKey, "ACCESSMDB", NULL, &dwType, (BYTE*)&cWorldManager::g_szAccessFile, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_ACCESS_FILE, cWorldManager::g_szAccessFile );
			}
			else
			{
				int index = GetCurrentDirectory(MAX_PATH, szDirBuff);
				sprintf(cWorldManager::g_szAccessFile,"%s\\UAS2.mdb", szDirBuff );
				SetDlgItemText( hWnd, IDC_ACCESS_FILE,cWorldManager::g_szAccessFile );
			}

			RegCloseKey( hKey );

			hWndStart = GetDlgItem( hWnd, IDB_START );
			hWndClearObjs = GetDlgItem( hWnd, IDB_CLEAROBJECTS );
			hWndDiscAll = GetDlgItem( hWnd, IDB_DISC_ALL );
			hWndExit = GetDlgItem( hWnd, IDB_EXIT );

			/////// Server Status Data ///////////////////////////////////////////////
			char szPort[5];
			char szTempIP[16];
			SOCKADDR_IN	saServer;

			GetDlgItemText( hWnd, IDC_LOCALIP, szTempIP, sizeof( szTempIP ) );
			saServer.sin_addr.s_addr	= inet_addr( szTempIP );
		
			cMasterServer::cStatus->m_bServer[0] = saServer.sin_addr.S_un.S_un_b.s_b1;
			cMasterServer::cStatus->m_bServer[1] = saServer.sin_addr.S_un.S_un_b.s_b2;
			cMasterServer::cStatus->m_bServer[2] = saServer.sin_addr.S_un.S_un_b.s_b3;
			cMasterServer::cStatus->m_bServer[3] = saServer.sin_addr.S_un.S_un_b.s_b4;

			GetDlgItemText( hWnd, IDC_CHARPORT, szPort, sizeof( szPort ) );
			cMasterServer::cStatus->m_ServerPort = atoi( szPort );
			///////////////////////////////////////////////////////////////////////////
			MoveWindow( hWnd,0 , 0 , CONSOLE_WIDTH_NORM ,CONSOLE_HEIGHT_NORM , TRUE );

			cMasterServer::cStatus->ServerLoad();

			break;	// case WM_INITDIALOG
		}

		case WM_GETMINMAXINFO:
		{
			LPMINMAXINFO( lParam )->ptMinTrackSize.x = 340;
			LPMINMAXINFO( lParam )->ptMinTrackSize.y = CONSOLE_HEIGHT_NORM;//150
			break;	// case WM_GETMINMAXINFO
		}

		case WM_SIZE:
		{
			MoveWindow( g_hWndConsole, 8, 95, LOWORD( lParam ) - 15, HIWORD( lParam ) - 100, TRUE );

			if( wParam == SIZE_MINIMIZED )
			{
				SystrayAdd( hWnd );
				ShowWindow( hWnd, SW_HIDE );
				fMinimized = TRUE;
			}
			else if( wParam == SIZE_RESTORED )
			{
				SystrayDelete( hWnd );
				fMinimized = FALSE;	
			}

			break;	// case WM_SIZE
		}

		case WM_NOTIFY:
		{
			break;	// case WM_NOTIFY
		}

		case WM_COMMAND:
		{	
			switch ( GET_WM_COMMAND_ID( wParam, lParam ) )
			{
				case IDC_LOCALIP:
					{
						UpdateHelpTitle( "Local IP:\r\n");
						UpdateHelp( "The IP address or DNS name of the hosting server. The default value is the IP address 127.0.0.1 (the loopback IP address).\r\n");
						break;
					}
				case IDC_SERVER:
					{
						UpdateHelpTitle( "Private Server Checkbox:\r\n");
						UpdateHelp( "When checked, server will not send updates to the status website. The option does not affect how the server operates.\r\n");
						break;
					}
				case IDC_CHARPORT:
					{
						UpdateHelpTitle( "Character Server Port:\r\n");
						UpdateHelp( "The number of the TCP or UDP port used to connect to the Character Server. The default value is 9002.\r\n");
						break;
					}
				case IDC_MAX_USERS:
					{
						UpdateHelpTitle( "Maximum Clients:\r\n");
						UpdateHelp( "The maximum number of clients the server allows. Not implemented.\r\n");
						break;
					}
				case IDC_WORLDPORT:
					{
						UpdateHelpTitle( "World Server Port:\r\n");
						UpdateHelp( "The number of the TCP or UDP port used to connect to the World Server. The default value is 9004.\r\n");
						break;
					}
				case IDC_ED_SNAME:
					{
						UpdateHelpTitle( "World Name:\r\n");
						UpdateHelp( "The name used to identify the world hosted by this server. Appears in the MOTD during login process.\r\n");
						break;
					}

				case IDC_ACCESS_FILE:
					{
						UpdateHelpTitle( "Microsoft Access File:\r\n");
						UpdateHelp( "The full path to the UAS2 Microsoft Access (.mdb) database file. The default path is the working directory.\r\n");
						break;
					}
				case IDC_DBIP:
					{
						UpdateHelpTitle( "Database IP:\r\n");
						UpdateHelp( "The IP address of the database server.  The value must be an IP address and not a DNS name.\r\n");
						break;
					}
				case IDC_DBNAME:
					{
						UpdateHelpTitle( "Database Name:\r\n");
						UpdateHelp( "The name of the UAS2 database.\r\n");
						break;
					}
				case IDC_DBUSER:
					{
						UpdateHelpTitle( "Database User:\r\n");
						UpdateHelp( "A username with permission to access the database.\r\n");
						break;
					}
				case IDC_DBPASSWORD:
					{
						UpdateHelpTitle( "Database Password:\r\n");
						UpdateHelp( "The password for the corresponding username.\r\n");
						break;
					}

				case IDC_ED_HOST:
					{
						UpdateHelpTitle( "State Website Host:\r\n");
						UpdateHelp( "The IP address or DNS name of the website hosting the server status pages.\r\n");
						break;
					}
				case IDC_ED_URL:
					{
						UpdateHelpTitle( "URL Path:\r\n");
						UpdateHelp( "The URL path to the server status webpage. Must start with '/' and end with '/'.\r\n");
						break;
					}
				case IDC_ED_PORT:
					{
						UpdateHelpTitle( "Access Port:\r\n");
						UpdateHelp( "The number of the TCP or UDP port used to access the server status website. The default port number is 80 (HTTP).\r\n");
						break;
					}
				case IDC_ED_ID:
					{
						UpdateHelpTitle( "Server ID:\r\n");
						UpdateHelp( "The server ID for the server status listing. Supplied by the host website during registration.\r\n");
						break;
					}
				case IDC_ED_KEY:
					{
						UpdateHelpTitle( "Key ID:\r\n");
						UpdateHelp( "The key ID for the server status listing. Supplied by the host website during registration.\r\n");
						break;
					}
				case IDC_ED_CLIENT:
					{
						UpdateHelpTitle( "Client Version:\r\n");
						UpdateHelp( "Specifies which client(s) are supported with this server. Supplied by the host website during registration.\r\n");
						break;
					}
				case IDC_ED_SERIAL:
					{
						UpdateHelpTitle( "Serial Code:\r\n");
						UpdateHelp( "The serial code for your server to use when connecting to the server status host website. Supplied by the host website during registration.\r\n");
						break;
					}

				case IDC_WBBOX:
					{
						UpdateHelpTitle( "World Broadcast:\r\n");
						UpdateHelp( "A message that may be sent to all users presently connected to the world.\r\n");
						break;
					}

				case IDB_EXIT:
					{
						UpdateConsole( "\r\n Exiting server. Please wait ...\r\n" );
						cMasterServer::cStatus->ServerOffline();
						PostMessage( hWnd, WM_CLOSE, 0, 0 );
						EnableWindow( hWndExit, FALSE );
						break;	// case IDB_EXIT
					}

				case IDB_CLEAROBJECTS:
					if ( g_fStarted )
					{
						cMasterServer::ClearAllObjects( );
						UpdateConsole( " All spawned objects cleared!\r\n" );
						break;
					}
					break;

				case IDB_DISC_ALL:
				{
					if( g_fStarted )
					{
						cMasterServer::DisconnectAllClients( );
						UpdateConsole( " All clients disconnected!\r\n" );
						break;
					}
					break;
				}

				//Karki
				case IDC_WB:
					if ( g_fStarted )
					{
						UpdateConsole( " World broadcast sent!\r\n" );
						char szWBTemp[255];
						GetDlgItemText( hWnd, IDC_WBBOX, szWBTemp, sizeof( szWBTemp ) );
						cMasterServer::ServerMessage( ColorGreen, NULL, "%s", szWBTemp );
					}
					break;

				case IDB_START:
				{
					if ( g_fStarted )
					{					
						EnableWindow( hWndStart, FALSE );
						EnableWindow( hWndClearObjs, FALSE );
						EnableWindow( hWndDiscAll, FALSE );
						
						g_fStarted = !cMasterServer::Unload( );

						if( ( fExit ) && ( !g_fStarted ) )
						{
							SystrayDelete( hWnd );
							DestroyWindow( hWnd );
							PostQuitMessage( 0 );
						}
						
						SetWindowText( hWndStart, "&Start Server" );
						EnableWindow( hWndStart, TRUE );
					}
					else
					{
						g_fStarted = TRUE;

						char szTemp[5];

						GetDlgItemText( hWnd, IDC_LOCALIP, g_szLocalIP, sizeof( g_szLocalIP ) );
						GetDlgItemText( hWnd, IDC_DBTYPE, szTemp, sizeof( szTemp ) );
						g_DBType = szTemp[0] - 0x30;
						GetDlgItemText( hWnd, IDC_DBIP, g_szDBIP, sizeof( g_szDBIP ) );
						GetDlgItemText( hWnd, IDC_DBNAME, g_szDBNAME, sizeof( g_szDBNAME ) );
						GetDlgItemText( hWnd, IDC_DBUSER, g_szDBUSER, sizeof( g_szDBUSER ) );
						GetDlgItemText( hWnd, IDC_DBPASSWORD, g_szDBPASSWORD, sizeof( g_szDBPASSWORD ) );
						GetDlgItemText( hWnd, IDC_ACCESS_FILE, cWorldManager::g_szAccessFile, sizeof( cWorldManager::g_szAccessFile ) );

						SetDlgItemText( hWnd, IDB_START, "&Stop Server");
							
						GetDlgItemText( hWnd, IDC_CHARPORT, szTemp, sizeof( szTemp ) );
						g_nCharPort = atoi( szTemp );

						GetDlgItemText( hWnd, IDC_WORLDPORT, szTemp, sizeof( szTemp ) );
						g_nWorldPort = atoi( szTemp );

						cDatabase::SetupDB(g_DBType,g_szDBIP,g_szDBNAME,g_szDBUSER,g_szDBPASSWORD);

						cMasterServer::Load( );

						EnableWindow( hWndClearObjs, TRUE );
						EnableWindow( hWndDiscAll, TRUE );
					}
					break;	// case IDB_START
				}

				case ID_SYSTRAY_ACE:
				{
					ShowWindow( hWnd, SW_RESTORE );
					SetForegroundWindow( hWnd );
					SendMessage( hWnd, WM_ACTIVATEAPP, ( WPARAM )TRUE, ( LPARAM )NULL );
					break;
				}

				case ID_SYSTRAY_EXIT:
				{
					PostMessage( hWnd, WM_CLOSE, 0, 0 );
					break;
				}

				case IDC_CONFIG:
				{
					if(g_fConfig == FALSE)
					{
						UpdateHelpTitle("Configuration Settings:\r\n");
						UpdateHelp("Changes will not take effect until the server program is restarted.\r\n");
						MoveWindow( hWnd,0 , 0 , CONSOLE_WIDTH_OPT ,CONSOLE_HEIGHT_OPT , TRUE );
						ShowWindow( hWndDBIP, SW_SHOW );
						ShowWindow( hWndDBNAME, SW_SHOW );
						ShowWindow( hWndDBUSER, SW_SHOW );
						ShowWindow( hWndDBPASSWORD, SW_SHOW );
						ShowWindow( hWndACCESSFILE, SW_SHOW );
						ShowWindow( hWndPrivate, SW_SHOW );
						SetWindowText( hWndCONFIG, "Status" );
						for(int i = 0; i< 30;i++)
						{
							ShowWindow( hWndSettings[i], SW_SHOW );
						}
						ShowWindow( g_hWndConsole, SW_HIDE );
						g_fConfig = TRUE;
					}
					else
					{
						MoveWindow( hWnd,0 , 0 , CONSOLE_WIDTH_NORM ,CONSOLE_HEIGHT_NORM , TRUE );						
						ShowWindow( hWndDBIP, SW_HIDE );
						ShowWindow( hWndDBNAME, SW_HIDE );
						ShowWindow( hWndDBUSER, SW_HIDE );
						ShowWindow( hWndDBPASSWORD, SW_HIDE );
						ShowWindow( hWndACCESSFILE, SW_HIDE );
						ShowWindow( hWndPrivate, SW_HIDE );
						SetWindowText( hWndCONFIG, "Settings" );
						for(int i = 0; i< 30;i++)
						{
							ShowWindow( hWndSettings[i], SW_HIDE );
						}
						ShowWindow( g_hWndConsole, SW_SHOW );
						g_fConfig = FALSE;
					}

					break;
				}

				case IDC_ACCESS_DB:
				{
					// Disable Dialog boxes
					EnableWindow( hWndDBIP, FALSE );
					EnableWindow( hWndDBNAME, FALSE );
					EnableWindow( hWndDBUSER, FALSE );
					EnableWindow( hWndDBPASSWORD, FALSE );
					EnableWindow( hWndACCESSFILE, TRUE );

					CheckDlgButton( hWnd, IDC_ACCESS_DB, 1 );
					CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
					CheckDlgButton( hWnd, IDC_MYSQL_DB, 0 );

					SetDlgItemText( hWnd, IDC_DBTYPE, "1" );

					UpdateHelpTitle( "Microsoft Access:\r\n");
					UpdateHelp( "A relational database management system supported by the server. Requires the use of a Microsoft Access (.mdb) database file.\r\n");

					break;
				}

				case IDC_MSSQL_DB:
				{
					// Enable Dialog boxes
					EnableWindow( hWndDBIP, TRUE );
					EnableWindow( hWndDBNAME, TRUE );
					EnableWindow( hWndDBUSER, TRUE );
					EnableWindow( hWndDBPASSWORD, TRUE );
					EnableWindow( hWndACCESSFILE, FALSE );
					
					CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
					CheckDlgButton( hWnd, IDC_MSSQL_DB, 1 );
					CheckDlgButton( hWnd, IDC_MYSQL_DB, 0 );

					SetDlgItemText( hWnd, IDC_DBTYPE, "2" );
					
					UpdateHelpTitle( "MS SQL:\r\n");
					UpdateHelp( "A relational database management system supported by the server. Requires access to an MS SQL database.\r\n");
						
					break;
				}

				case IDC_MYSQL_DB:
				{
					// Enable Dialog boxes
					EnableWindow( hWndDBIP, TRUE );
					EnableWindow( hWndDBNAME, TRUE );
					EnableWindow( hWndDBUSER, TRUE );
					EnableWindow( hWndDBPASSWORD, TRUE );
					EnableWindow( hWndACCESSFILE, FALSE );
					
					CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
					CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
					CheckDlgButton( hWnd, IDC_MYSQL_DB, 1 );

					SetDlgItemText( hWnd, IDC_DBTYPE, "3" );
					
					UpdateHelpTitle( "MySQL:\r\n");
					UpdateHelp( "A relational database management system supported by the server. Requires access to a MySQL database.\r\n");

					break;
				}

				case IDC_BTN_UPDATE:
				{
					char szTemp[5];
					char szDBType[2];
					char szDBTemp[20];

					HKEY hKey;
					RegCreateKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\UAS", NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
					
					GetDlgItemText( hWnd, IDC_LOCALIP, g_szLocalIP, sizeof( g_szLocalIP ) );
					RegSetValueEx( hKey, "LocalIP", NULL, REG_SZ, (BYTE*)g_szLocalIP, lstrlen( g_szLocalIP ) );
					
					GetDlgItemText( hWnd, IDC_CHARPORT, szTemp, sizeof( szTemp ) );
					RegSetValueEx( hKey, "CharPort", NULL, REG_SZ, (BYTE*)szTemp, lstrlen( szTemp ) );

					GetDlgItemText( hWnd, IDC_WORLDPORT, szTemp, sizeof( szTemp ) );
					RegSetValueEx( hKey, "WorldPort", NULL, REG_SZ, (BYTE*)szTemp, lstrlen( szTemp ) );

					// Database Settings //////////////////////////////////////////////////////////////
					GetDlgItemText( hWnd, IDC_DBTYPE, szDBType, sizeof( szDBType ) );
					RegSetValueEx( hKey, "DBTYPE", NULL, REG_SZ, (BYTE*)szDBType, lstrlen( szDBType ) );

					GetDlgItemText( hWnd, IDC_DBIP, szDBTemp, sizeof( szDBTemp ) );
					RegSetValueEx( hKey, "DBIP", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
					
					GetDlgItemText( hWnd, IDC_DBNAME, szDBTemp, sizeof( szDBTemp ) );
					RegSetValueEx( hKey, "DBNAME", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
					
					GetDlgItemText( hWnd, IDC_DBUSER, szDBTemp, sizeof( szDBTemp ) );
					RegSetValueEx( hKey, "DBUSER", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
					
					GetDlgItemText( hWnd, IDC_DBPASSWORD, szDBTemp, sizeof( szDBTemp ) );
					RegSetValueEx( hKey, "DBPASSWORD", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
					
					char szAccessTemp[MAX_PATH+20];
					GetDlgItemText( hWnd, IDC_ACCESS_FILE, szAccessTemp, sizeof( szAccessTemp ) );
					RegSetValueEx( hKey, "ACCESSMDB", NULL, REG_SZ, (BYTE*)szAccessTemp, lstrlen( szAccessTemp ) );

					///////////////////////////////////////////////////////////////////////////////////
					// Status Server Settings
					char szHostTemp[64];

					int nState;
					nState = IsDlgButtonChecked( hWnd, IDC_SERVER);
					sprintf(szDBTemp,"%d",nState);
					RegSetValueEx( hKey, "Private", NULL, REG_SZ, (BYTE*)szDBTemp, sizeof(szDBTemp) );

					GetDlgItemText( hWnd, IDC_ED_HOST, szHostTemp, sizeof( szHostTemp ) );
					RegSetValueEx( hKey, "Status Host", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
								
					GetDlgItemText( hWnd, IDC_ED_PORT, szDBTemp, sizeof( szDBTemp ) );
					RegSetValueEx( hKey, "HTTP Port", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
											
					GetDlgItemText( hWnd, IDC_ED_ID, szDBTemp, sizeof( szDBTemp ) );
					RegSetValueEx( hKey, "Server ID", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
														
					GetDlgItemText( hWnd, IDC_ED_SNAME, szHostTemp, sizeof( szHostTemp ) );
					RegSetValueEx( hKey, "Server Name", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
					memcpy(cMasterServer::m_szServerName,szHostTemp,sizeof(szHostTemp));
																	
					GetDlgItemText( hWnd, IDC_ED_SERIAL, szHostTemp, sizeof( szHostTemp ) );
					RegSetValueEx( hKey, "Server Serial", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
																	
					GetDlgItemText( hWnd, IDC_ED_KEY, szHostTemp, sizeof( szHostTemp ) );
					RegSetValueEx( hKey, "Server Key", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
																	
					GetDlgItemText( hWnd, IDC_ED_URL, szHostTemp, sizeof( szHostTemp ) );
					RegSetValueEx( hKey, "HTTP Path", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
																				
					GetDlgItemText( hWnd, IDC_ED_CLIENT, szHostTemp, sizeof( szHostTemp ) );
					RegSetValueEx( hKey, "Client Support", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
																				
					GetDlgItemText( hWnd, IDC_MAX_USERS, szHostTemp, sizeof( szHostTemp ) );
					RegSetValueEx( hKey, "Max Clients", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
					/////////////////////////////////////////////////////////////////////////////////////
					
					RegCloseKey( hKey );
					break;
				}
				default:
					break;	// case default
			}
			break;	// case WM_COMMAND
		}

		case MYWM_NOTIFYICON:
		{
			switch (lParam)
			{
				case WM_LBUTTONDOWN:
				{
					ShowWindow( hWnd, SW_RESTORE );
					SetForegroundWindow( hWnd );
					SendMessage( hWnd, WM_ACTIVATEAPP, ( WPARAM )TRUE, ( LPARAM )NULL );
					break;
				}

				case WM_RBUTTONUP:
				{
					HMENU hTrayMenu;
					HMENU hMenu;
					POINT point;

					SetForegroundWindow( hWnd );

					hTrayMenu = LoadMenu( g_hInstance, MAKEINTRESOURCE( ID_SYSTRAY ) );
					hMenu = GetSubMenu( hTrayMenu, 0 );
					GetCursorPos( &point );

					TrackPopupMenu( hMenu, TPM_RIGHTBUTTON, point.x, point.y, 0, hWnd, NULL );
					DestroyMenu( hMenu );
					DestroyMenu( hTrayMenu );

					PostMessage( hWnd, WM_NULL, 0, 0 ); 

					break;
				}
			}
			break;
		}
		case WM_CLOSE:
		{
			char szTemp[5];
			
			HKEY hKey;
			RegCreateKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\UAS", NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
			
			GetDlgItemText( hWnd, IDC_LOCALIP, g_szLocalIP, sizeof( g_szLocalIP ) );
			RegSetValueEx( hKey, "LocalIP", NULL, REG_SZ, (BYTE*)g_szLocalIP, lstrlen( g_szLocalIP ) );
			
			GetDlgItemText( hWnd, IDC_CHARPORT, szTemp, sizeof( szTemp ) );
			RegSetValueEx( hKey, "CharPort", NULL, REG_SZ, (BYTE*)szTemp, lstrlen( szTemp ) );

			GetDlgItemText( hWnd, IDC_WORLDPORT, szTemp, sizeof( szTemp ) );
			RegSetValueEx( hKey, "WorldPort", NULL, REG_SZ, (BYTE*)szTemp, lstrlen( szTemp ) );

			// Database Settings //////////////////////////////////////////////////////////////
			char szDBType[2];
			char szDBTemp[20];

			GetDlgItemText( hWnd, IDC_DBTYPE, szDBType, sizeof( szDBType ) );
			RegSetValueEx( hKey, "DBTYPE", NULL, REG_SZ, (BYTE*)szDBType, lstrlen( szDBType ) );

			GetDlgItemText( hWnd, IDC_DBIP, szDBTemp, sizeof( szDBTemp ) );
			RegSetValueEx( hKey, "DBIP", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
			
			GetDlgItemText( hWnd, IDC_DBNAME, szDBTemp, sizeof( szDBTemp ) );
			RegSetValueEx( hKey, "DBNAME", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
			
			GetDlgItemText( hWnd, IDC_DBUSER, szDBTemp, sizeof( szDBTemp ) );
			RegSetValueEx( hKey, "DBUSER", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
			
			GetDlgItemText( hWnd, IDC_DBPASSWORD, szDBTemp, sizeof( szDBTemp ) );
			RegSetValueEx( hKey, "DBPASSWORD", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
			
			char szAccessTemp[MAX_PATH+20];
			GetDlgItemText( hWnd, IDC_ACCESS_FILE, szAccessTemp, sizeof( szAccessTemp ) );
			RegSetValueEx( hKey, "ACCESSMDB", NULL, REG_SZ, (BYTE*)szAccessTemp, lstrlen( szAccessTemp ) );
			///////////////////////////////////////////////////////////////////////////////////
			// Status Server Settings
			char szHostTemp[64];

			int nState;
			nState = IsDlgButtonChecked( hWnd, IDC_SERVER);
			sprintf(szDBTemp,"%d",nState);
			RegSetValueEx( hKey, "Private", NULL, REG_SZ, (BYTE*)szDBTemp, sizeof(szDBTemp) );

			GetDlgItemText( hWnd, IDC_ED_HOST, szHostTemp, sizeof( szHostTemp ) );
			RegSetValueEx( hKey, "Status Host", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
						
			GetDlgItemText( hWnd, IDC_ED_PORT, szDBTemp, sizeof( szDBTemp ) );
			RegSetValueEx( hKey, "HTTP Port", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
									
			GetDlgItemText( hWnd, IDC_ED_ID, szDBTemp, sizeof( szDBTemp ) );
			RegSetValueEx( hKey, "Server ID", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
												
			GetDlgItemText( hWnd, IDC_ED_SNAME, szHostTemp, sizeof( szHostTemp ) );
			RegSetValueEx( hKey, "Server Name", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
															
			GetDlgItemText( hWnd, IDC_ED_SERIAL, szHostTemp, sizeof( szHostTemp ) );
			RegSetValueEx( hKey, "Server Serial", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
															
			GetDlgItemText( hWnd, IDC_ED_KEY, szHostTemp, sizeof( szHostTemp ) );
			RegSetValueEx( hKey, "Server Key", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
															
			GetDlgItemText( hWnd, IDC_ED_URL, szHostTemp, sizeof( szHostTemp ) );
			RegSetValueEx( hKey, "HTTP Path", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
																		
			GetDlgItemText( hWnd, IDC_ED_CLIENT, szHostTemp, sizeof( szHostTemp ) );
			RegSetValueEx( hKey, "Client Support", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
																				
			GetDlgItemText( hWnd, IDC_MAX_USERS, szHostTemp, sizeof( szHostTemp ) );
			RegSetValueEx( hKey, "Max Clients", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
			/////////////////////////////////////////////////////////////////////////////////////
			
			RegCloseKey( hKey );

			if ( g_fStarted )
			{
				fExit = TRUE;
				SendMessage( hWnd, WM_COMMAND, IDB_START, TRUE );
			}
			else
			{
				WSACleanup();
				SystrayDelete( hWnd );
				DestroyWindow( hWnd );
				PostQuitMessage( 0 );
			}

			break;	// case WM_CLOSE
		}

		default:
			if( ( msg == s_uTaskbarRestart ) && ( fMinimized ) )
			{
				SystrayDelete( hWnd );
				SystrayAdd( hWnd );
				break;
			}
	}
	return FALSE;
}
コード例 #12
0
ファイル: activemasternode.cpp プロジェクト: thephez/dash
void CActiveDeterministicMasternodeManager::Init()
{
    LOCK(cs_main);

    if (!fMasternodeMode) return;

    if (!deterministicMNManager->IsDeterministicMNsSporkActive()) return;

    // Check that our local network configuration is correct
    if (!fListen) {
        // listen option is probably overwritten by smth else, no good
        state = MASTERNODE_ERROR;
        strError = "Masternode must accept connections from outside. Make sure listen configuration option is not overwritten by some another parameter.";
        LogPrintf("CActiveDeterministicMasternodeManager::Init -- ERROR: %s\n", strError);
        return;
    }

    if (!GetLocalAddress(activeMasternodeInfo.service)) {
        state = MASTERNODE_ERROR;
        return;
    }

    CDeterministicMNList mnList = deterministicMNManager->GetListAtChainTip();

    CDeterministicMNCPtr dmn = mnList.GetMNByOperatorKey(*activeMasternodeInfo.blsPubKeyOperator);
    if (!dmn) {
        // MN not appeared on the chain yet
        return;
    }

    if (!mnList.IsMNValid(dmn->proTxHash)) {
        if (mnList.IsMNPoSeBanned(dmn->proTxHash)) {
            state = MASTERNODE_POSE_BANNED;
        } else {
            state = MASTERNODE_REMOVED;
        }
        return;
    }

    mnListEntry = dmn;

    LogPrintf("CActiveDeterministicMasternodeManager::Init -- proTxHash=%s, proTx=%s\n", mnListEntry->proTxHash.ToString(), mnListEntry->ToString());

    if (activeMasternodeInfo.service != mnListEntry->pdmnState->addr) {
        state = MASTERNODE_ERROR;
        strError = "Local address does not match the address from ProTx";
        LogPrintf("CActiveDeterministicMasternodeManager::Init -- ERROR: %s", strError);
        return;
    }

    if (Params().NetworkIDString() != CBaseChainParams::REGTEST) {
        // Check socket connectivity
        LogPrintf("CActiveDeterministicMasternodeManager::Init -- Checking inbound connection to '%s'\n", activeMasternodeInfo.service.ToString());
        SOCKET hSocket;
        bool fConnected = ConnectSocket(activeMasternodeInfo.service, hSocket, nConnectTimeout) && IsSelectableSocket(hSocket);
        CloseSocket(hSocket);

        if (!fConnected) {
            state = MASTERNODE_ERROR;
            strError = "Could not connect to " + activeMasternodeInfo.service.ToString();
            LogPrintf("CActiveDeterministicMasternodeManager::Init -- ERROR: %s\n", strError);
            return;
        }
    }

    activeMasternodeInfo.proTxHash = mnListEntry->proTxHash;
    activeMasternodeInfo.outpoint = mnListEntry->collateralOutpoint;
    state = MASTERNODE_READY;
}