Esempio n. 1
0
void C4StartupNetListEntry::SetRefQuery(const char *szAddress, enum QueryType eQueryType)
{
	// safety: clear previous
	ClearRef();
	// setup layout
	const_cast<C4Facet &>(reinterpret_cast<const C4Facet &>(pIcon->GetFacet()))
	  = (const C4Facet &) C4Startup::Get()->Graphics.fctNetGetRef;
	pIcon->SetAnimated(true, 1);
	pIcon->SetBounds(rctIconLarge);
	// init a new ref client to query
	sRefClientAddress.Copy(szAddress);
	this->eQueryType = eQueryType;
	pRefClient = new C4Network2RefClient();
	if (!pRefClient->Init() || !pRefClient->SetServer(szAddress))
	{
		// should not happen
		sInfoText[0].Clear();
		SetError(pRefClient->GetError(), TT_RefReqWait);
		return;
	}
	// set info
	sInfoText[0].Format(LoadResStr("IDS_NET_CLIENTONNET"), GetQueryTypeName(eQueryType), pRefClient->getServerName());
	sInfoText[1].Copy(LoadResStr("IDS_NET_INFOQUERY"));
	UpdateSmallState(); UpdateText();
	pRefClient->SetNotify(&Application.InteractiveThread);
	// masterserver: always on top
	if (eQueryType == NRQT_Masterserver)
		iSortOrder = 100;
	// register proc
	C4InteractiveThread &Thread = Application.InteractiveThread;
	Thread.AddProc(pRefClient);
	// start querying!
	QueryReferences();
}
Esempio n. 2
0
void CAtomRef::Copy( const CAtomRef & atom )
{
    ADDTOCALLSTACK("CAtomRef::Copy");
    // Copy's are fast.
    if ( m_pDef == atom.m_pDef )
        return;
    ClearRef();
    m_pDef = atom.m_pDef;
    m_pDef->m_iUseCount++;
}
Esempio n. 3
0
void CAtomRef::SetStr( LPCTSTR pszText )
{
    ADDTOCALLSTACK("CAtomRef::SetStr");
    ClearRef();
    if ( pszText == NULL )
        return;

    // Find it in the atom table first.
    int iCompareRes;
    size_t index = g_AtomManager.FindKeyNear( pszText, iCompareRes );
    if ( iCompareRes == 0 )
    {
        // already here just increment useage.
        m_pDef = g_AtomManager.GetAt( index );
        m_pDef->m_iUseCount++;
    }
    else
    {
        // Insertion sort.
        m_pDef = new CAtomDef( pszText );
        g_AtomManager.AddPresorted( index, iCompareRes, m_pDef );
    }
}
Esempio n. 4
0
C4StartupNetListEntry::~C4StartupNetListEntry()
{
	ClearRef();
}
Esempio n. 5
0
void C4StartupNetListEntry::SetReference(C4Network2Reference *pRef)
{
	// safety: clear previous
	ClearRef();
	// set info
	this->pRef = pRef;
	int32_t iIcon = pRef->getIcon();
	if (!Inside<int32_t>(iIcon, 0, C4StartupScenSel_IconCount-1)) iIcon = C4StartupScenSel_DefaultIcon_Scenario;
	pIcon->SetFacet(C4Startup::Get()->Graphics.fctScenSelIcons.GetPhase(iIcon));
	pIcon->SetAnimated(false, 0);
	pIcon->SetBounds(rctIconSmall);
	int32_t iPlrCnt = pRef->isEditor() ? pRef->Parameters.PlayerInfos.GetActivePlayerCount(false) : pRef->Parameters.Clients.getClientCnt();
	C4Client *pHost = pRef->Parameters.Clients.getHost();
	sInfoText[0].Format(LoadResStr("IDS_NET_REFONCLIENT"), pRef->getTitle(), pHost ? pHost->getName() : "unknown");
	if (pRef->isEditor())
	{
		sInfoText[1].Format(LoadResStr("IDS_NET_INFOEDITOR"),
			(int)iPlrCnt,
			StdStrBuf(pRef->getGameStatus().getDescription(), true).getData());
	}
	else
	{
		sInfoText[1].Format(LoadResStr("IDS_NET_INFOPLRSGOALDESC"),
			(int)iPlrCnt,
			(int)pRef->Parameters.MaxPlayers,
			pRef->getGameGoalString().getData(),
			StdStrBuf(pRef->getGameStatus().getDescription(), true).getData());
	}
	if (pRef->getTime() > 0)
	{
		StdStrBuf strDuration; strDuration.Format("%02d:%02d:%02d", pRef->getTime()/3600, (pRef->getTime() % 3600) / 60, pRef->getTime() % 60);
		sInfoText[1].Append(" - "); sInfoText[1].Append(strDuration);
	}
	sInfoText[2].Format(LoadResStr("IDS_DESC_VERSION"), pRef->getGameVersion().GetString().getData());
	sInfoText[3].Format("%s: %s", LoadResStr("IDS_CTL_COMMENT"), pRef->getComment());
	StdStrBuf sAddress;
	for (int i=0; i<pRef->getAddrCnt(); ++i)
	{
		if (i) sAddress.Append(", ");
		sAddress.Append(pRef->getAddr(i).toString());
	}
	// editor reference
	if (pRef->isEditor())
		AddStatusIcon(C4GUI::Ico_Editor, LoadResStr("IDS_CNS_CONSOLE"));
	// password
	if (pRef->isPasswordNeeded())
		AddStatusIcon(C4GUI::Ico_Ex_LockedFrontal, LoadResStr("IDS_NET_INFOPASSWORD"));
	// league
	if (pRef->Parameters.isLeague())
		AddStatusIcon(C4GUI::Ico_Ex_League, pRef->Parameters.getLeague());
	// lobby active
	if (pRef->getGameStatus().isLobbyActive())
		AddStatusIcon(C4GUI::Ico_Lobby, LoadResStr("IDS_DESC_EXPECTING"));
	// game running
	if (pRef->getGameStatus().isPastLobby())
		AddStatusIcon(C4GUI::Ico_GameRunning, LoadResStr("IDS_NET_INFOINPROGR"));
	// runtime join
	if (pRef->isJoinAllowed() && pRef->getGameStatus().isPastLobby()) // A little workaround to determine RuntimeJoin...
		AddStatusIcon(C4GUI::Ico_RuntimeJoin, LoadResStr("IDS_NET_RUNTIMEJOINFREE"));
	// official server
	if (pRef->isOfficialServer() && !Config.Network.UseAlternateServer) // Offical server icon is only displayed if references are obtained from official league server
	{
		fIsImportant = true;
		AddStatusIcon(C4GUI::Ico_OfficialServer, LoadResStr("IDS_NET_OFFICIALSERVER"));
	}
	// list participating player/client names
	if (pRef->isEditor())
	{
		sInfoText[4].Format("%s%s", LoadResStr("IDS_DESC_CLIENTS"), iPlrCnt ? pRef->Parameters.Clients.GetAllClientNames().getData() : LoadResStr("IDS_CTL_NONE"));
	}
	else
	{
		sInfoText[4].Format("%s: %s", LoadResStr("IDS_CTL_PLAYER"), iPlrCnt ? pRef->Parameters.PlayerInfos.GetActivePlayerNames(false).getData() : LoadResStr("IDS_CTL_NONE"));
	}
	// disabled if join is not possible for some reason
	C4GameVersion verThis;
	if (!pRef->isJoinAllowed() || !(pRef->getGameVersion() == verThis))
	{
		fIsEnabled = false;
	}
	// store sort order
	iSortOrder = pRef->getSortOrder();
	// all references expire after a while
	SetTimeout(TT_Reference);
	UpdateSmallState(); UpdateText();
}