Example #1
0
void dns_save_send(DNS_HANDLE pDcb, PCHAR pDomainName, USHORT sAddr, UCHAR iBankOffset, UCHAR iType)
{
	PCHAR pBuf;
	BOOLEAN bDns1Failed, bDns2Failed;

	bDns1Failed = IsValidIP(Sys_pDnsIp) ? FALSE : TRUE;
	bDns2Failed = IsValidIP(Sys_pDnsIp2) ? FALSE : TRUE;
	if (bDns1Failed && bDns2Failed)
	{
		dns_failed(sAddr, iBankOffset);
		return;
	}

	pBuf = heap_save_str(pDomainName);
	if (pBuf)
	{
		pDcb->iBankOffset = iBankOffset;
		pDcb->sCallBack = sAddr;
		pDcb->iState = DS_PENDING;
		rand_array(pDcb->pID, DNS_ID_LEN);
		pDcb->iType = iType;
		pDcb->pName = pBuf;
		pDcb->bDns1Failed = bDns1Failed;
		pDcb->bDns2Failed = bDns2Failed;
		dns_send(pDcb);
	}
	else
	{
		// dns module resource limited, try later
		dns_failed(sAddr, iBankOffset);
	}
}
Example #2
0
LPDESC DESC_MANAGER::AcceptDesc(LPFDWATCH fdw, socket_t s)
{
	socket_t                    desc;
	LPDESC						newd;
	static struct sockaddr_in   peer;
	static char					host[MAX_HOST_LENGTH + 1];

	if ((desc = socket_accept(s, &peer)) == -1)
		return NULL;

	strlcpy(host, inet_ntoa(peer.sin_addr), sizeof(host));

	if (g_bAuthServer)
	{
		if (IsBanIP(peer.sin_addr))
		{
			sys_log(0, "connection from %s was banned.", host);
			socket_close(desc);
			return NULL;
		}
	}

	if (!IsValidIP(admin_ip, host)) // admin_ip 에 등록된 IP 는 최대 사용자 수에 구애받지 않는다.
	{
		if (m_iSocketsConnected >= MAX_ALLOW_USER)
		{
			sys_err("max connection reached. MAX_ALLOW_USER = %d", MAX_ALLOW_USER);
			socket_close(desc);
			return NULL;
		}
	}

	newd = M2_NEW DESC;
	crc_t handshake = CreateHandshake();

	if (!newd->Setup(fdw, desc, peer, ++m_iHandleCount, handshake))
	{
		socket_close(desc);
		M2_DELETE(newd);
		return NULL;
	}

	m_map_handshake.insert(DESC_HANDSHAKE_MAP::value_type(handshake, newd));
	m_map_handle.insert(DESC_HANDLE_MAP::value_type(newd->GetHandle(), newd));

	m_set_pkDesc.insert(newd);
	++m_iSocketsConnected;
	return (newd);
}
Example #3
0
CBan* CBanManager::AddBan ( const char* szIP, CClient* pBanner, const char* szReason, time_t tTimeOfUnban )
{
    if ( IsValidIP ( szIP ) && !IsSpecificallyBanned ( szIP ) )
    {
        CBan* pBan = AddBan ( pBanner, szReason, tTimeOfUnban );
        pBan->SetIP ( szIP );

        g_pNetServer->AddBan ( szIP );

        // Save the list
        SaveBanList ();
        return pBan;
    }

    return NULL;
}
Example #4
0
CBan* CBanManager::AddBan ( CPlayer* pPlayer, CClient* pBanner, const char* szReason, time_t tTimeOfUnban )
{
    if ( pPlayer )
    {
        char szIP[256] = { '\0' };
        pPlayer->GetSourceIP ( szIP );

        if ( IsValidIP ( szIP ) && !IsSpecificallyBanned ( szIP ) )
        {
            CBan* pBan = AddBan ( pBanner, szReason, tTimeOfUnban );
            pBan->SetNick ( pPlayer->GetNick() );
            pBan->SetIP ( szIP );

            g_pNetServer->AddBan ( szIP );

            // Save the list
            SaveBanList ();
            return pBan;
        }
    }

    return NULL;
}
Example #5
0
bool CBanManager::LoadBanList ( void )
{
    // Create the XML
    CXMLFile* pFile = g_pServerInterface->GetXML ()->CreateXML ( m_strPath );
    if ( !pFile )
    {
        return false;
    }

    // Parse it
    if ( !pFile->Parse () )
    {
        delete pFile;
        CLogger::ErrorPrintf ( "Error parsing banlist\n" );
        return false;
    }

    // Grab the XML root node
    CXMLNode* pRootNode = pFile->GetRootNode ();
    if ( !pRootNode )
    {
        pRootNode = pFile->CreateRootNode ( "banlist" );
    }

    // Is the rootnode's name <banlist>?
    if ( pRootNode->GetTagName ().compare ( "banlist" ) != 0 )
    {
        CLogger::ErrorPrintf ( "Wrong root node ('banlist')\n" );
        return false;
    }

    // Iterate the nodes
    CXMLNode* pNode = NULL;
    unsigned int uiCount = pRootNode->GetSubNodeCount ();

    for ( unsigned int i = 0; i < uiCount; i++ )
    {
        // Grab the node
        pNode = pRootNode->GetSubNode ( i );

        if ( pNode )
        {
            if ( pNode->GetTagName ().compare ( "ban" ) == 0 )
            {
                std::string strIP = SafeGetValue ( pNode, "ip" ),
                            strSerial = SafeGetValue ( pNode, "serial" ),
                            strAccount = SafeGetValue ( pNode, "account" );
                if ( !strIP.empty() || !strSerial.empty() || !strAccount.empty() )
                {
                    CBan* pBan = AddBan ();
                    if ( IsValidIP ( strIP.c_str() ) )
                    {
                        pBan->SetIP ( strIP );
                        g_pNetServer->AddBan ( strIP.c_str() );
                    }
                    pBan->SetAccount ( strAccount );
                    pBan->SetSerial ( strSerial );
                    pBan->SetBanner ( SafeGetValue ( pNode, "banner" ) );
                    pBan->SetNick ( SafeGetValue ( pNode, "nick" ) );
                    pBan->SetReason ( SafeGetValue ( pNode, "reason" ) );

                    std::string strTime = SafeGetValue ( pNode, "time" );
                    if ( !strTime.empty() ) pBan->SetTimeOfBan ( ( time_t ) atoi ( strTime.c_str() ) );

                    strTime = SafeGetValue ( pNode, "unban" );
                    if ( !strTime.empty() ) pBan->SetTimeOfUnban ( ( time_t ) atoi ( strTime.c_str() ) );
                }
            }
        }
    }

    delete pFile;
    return true;
}
Example #6
0
int main(int argc, const char* argv[])
{
	// 分析命令行选项
	CmdArgParser cmdParser("", TCtoC_str(CStrFormat(_T("服务版本: %d.%d.%d"), g_majorVer, g_minorVer, g_thirdVer)));

	CStringA sip;
	VERIFY(cmdParser.AddStr(
			sip, "-ip", "", "IP",
			"服务的TCP监听IP,默认监听本机所有IP"
			));

	int tcpPort = g_serveIPP.port_;
	VERIFY(cmdParser.AddInt(
			tcpPort, "-p",
			1, GET_INT_MAX_VALUE(WORD),
			tcpPort, "port",
			"服务的TCP监听端口"
			));

	if(!cmdParser.RunParse(argc, argv))
		return -1;

	if(!sip.IsEmpty())
	{
		if(!IsValidIP((const char*)sip, &g_serveIPP.ip_))
		{
			NPLogError((_T("非法ip参数: %s"), (LPCTSTR)CtoTC_str((const char*)sip)));
			return -1;
		}
	}
	g_serveIPP.port_ = tcpPort;

	//用户定义_S

	CPCC_Startup pcc;
	int rt_st = pcc.Startup();
	if(rt_st < 0)
	{
		return rt_st;
	}
	//

	//用户定义_E
	// 设置基本系统参数
#if defined(WIN32)
	SetCurrentDirectory(GetExeDir());
#endif
	tcps_SetLogPrint(LogPrint__, NULL);

	// 构造rpc服务对象
	// 可在构造PCC_CenterSessionMaker时传递一 void* 参数给会话对象
	// 如:PCC_CenterSessionMaker sessionMaker(param);
	// 在会话对象中可使用this->m_sessionMaker.m_userParameter获得
	PCC_CenterSessionMaker sessionMaker;
	iscm_IRPCServeMan* rpcMan = NULL;
	TCPSError err = iscm_MakeRPCServeMan(rpcMan, g_serveIPP.port_, g_serveIPP.ip_, &sessionMaker, TCPS_MAX_TOTAL_SESSIONS/2);
	if(TCPS_OK == err)
	{
		// 运行主循环
		NPLogInfo(("Running serve..."));
		struct TCheck
		{
			static BOOL RunCheck(void* /*param*/)
				{	return !g_exitFlag;	}
		};
#if defined(WIN32)
		typedef HWND (WINAPI* FNGetConsoleWindow)();
		FNGetConsoleWindow fnGetConsoleWindow
			= (FNGetConsoleWindow)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "GetConsoleWindow");
		HWND wnd;
		if(fnGetConsoleWindow && NULL!=(wnd=fnGetConsoleWindow()))
		{
			char ch[1024];
			int l = GetWindowTextA(wnd, ch, sizeof(ch)-16);
			char ippStr[32];
			GetIPPortTxt(g_serveIPP, ippStr);
			sprintf(ch+l, " - %s", ippStr);
			SetWindowTextA(wnd, ch);
		}
#endif
		RunMainLoop(TCheck::RunCheck, NULL);
		g_exitFlag = true;
		NPLogInfo(("Exiting serve..."));
	}
	else
	{
		NPLogError(("iscm_MakeRPCServeMan(%d) failed, %s(%d)", tcpPort, tcps_GetErrTxt(err), err));
	}

	// 析构rpc服务对象
	if(rpcMan)
		rpcMan->DeleteThis();

//#if defined(_NP_IS_X86) || defined(_NP_IS_X64)
//	NPCRT_API_SetPerformancePolicy(false, true);
//#endif

	// 销毁tcps/iscm库中所有的全局对象(拥有线程的)
	tcps_DestroyAllGlobalObjects();

	return 0;
}