void C4UpdateDlg::UpdateText()
{
	if (!UpdateRunning)
		return;
#ifdef _WIN32
	AddLine("Win32 is currently not using the C4UpdateDlg!");
	UpdateRunning = false;
#else
	char c4group_output_buf[513];
	ssize_t amount_read;
	// transfer output to log window
	amount_read = read(c4group_output[0], c4group_output_buf, 512);
	// error
	if (amount_read == -1)
	{
		if (errno == EAGAIN)
			return;
		StdStrBuf Errormessage = FormatString("read error from c4group: %s", strerror(errno));
		Log(Errormessage.getData());
		AddLine(Errormessage.getData());
		UpdateRunning = false;
		succeeded = false;
	}
	// EOF: Update done.
	else if (amount_read == 0)
	{
		// Close c4group output
		close(c4group_output[0]);
		// If c4group did not exit but something else caused EOF, then that's bad. But don't hang.
		int child_status = 0;
		if (waitpid(pid, &child_status, WNOHANG) == -1)
		{
			LogF("error in waitpid: %s", strerror(errno));
			AddLineFmt("error in waitpid: %s", strerror(errno));
			succeeded = false;
		}
		// check if c4group failed.
		else if (WIFEXITED(child_status) && WEXITSTATUS(child_status))
		{
			LogF("c4group returned status %d", WEXITSTATUS(child_status));
			AddLineFmt("c4group returned status %d", WEXITSTATUS(child_status));
			succeeded = false;
		}
		else if (WIFSIGNALED(child_status))
		{
			LogF("c4group killed with signal %d", WTERMSIG(child_status));
			AddLineFmt("c4group killed with signal %d", WTERMSIG(child_status));
			succeeded = false;
		}
		else
		{
			Log("Done.");
			AddLine("Done.");
		}
		UpdateRunning = false;
	}
	else
	{
		c4group_output_buf[amount_read] = 0;
		// Fixme: This adds spurious newlines in the middle of the output.
		LogF("%s", c4group_output_buf);
		AddLineFmt("%s", c4group_output_buf);
	}
#endif

	// Scroll to bottom
	if (pTextWin)
	{
		pTextWin->UpdateHeight();
		pTextWin->ScrollToBottom();
	}
}
Example #2
0
void C4Network2ClientDlg::UpdateText()
{
	// begin updating (clears previous text)
	BeginUpdateText();
	// get core
	const C4Client *pClient = Game.Clients.getClientByID(iClientID);
	if (!pClient)
	{
		// client ID unknown
		AddLineFmt(LoadResStr("IDS_NET_CLIENT_INFO_UNKNOWNID"), iClientID);
	}
	else
	{
		// get client (may be nullptr for local info)
		C4Network2Client *pNetClient = pClient->getNetClient();
		// show some info
		StdCopyStrBuf strInfo;
		if (!pClient->isActivated()) { strInfo.Append(LoadResStr("IDS_MSG_INACTIVE")); strInfo.Append(" "); }
		if (pClient->isLocal()) { strInfo.Append(LoadResStr("IDS_MSG_LOCAL")); strInfo.Append(" "); }
		strInfo.AppendFormat("%s %s (ID #%d)%s",
			LoadResStr(pClient->isHost() ? "IDS_MSG_HOST" : "IDS_MSG_CLIENT"),
			pClient->getName(),
			iClientID,
			::Network.isHost() && pNetClient && !pNetClient->isReady() ? " (!ack)" : "");
		AddLine(strInfo.getData());
		// show addresses
		int iCnt;
		if ((iCnt=pNetClient->getAddrCnt()))
		{
			AddLine(LoadResStr("IDS_NET_CLIENT_INFO_ADDRESSES"));
			for (int i=0; i<iCnt; ++i)
			{
				C4Network2Address addr = pNetClient->getAddr(i);
				AddLineFmt("  %d: %s",
				           i,                        // adress index
				           addr.toString().getData());
			}
		}
		else
			AddLine(LoadResStr("IDS_NET_CLIENT_INFO_NOADDRESSES"));
		// show connection
		if (pNetClient)
		{
			// connections
			if (pNetClient->isConnected())
			{
				AddLineFmt(LoadResStr("IDS_NET_CLIENT_INFO_CONNECTIONS"),
				           pNetClient->getMsgConn() == pNetClient->getDataConn() ? "Msg/Data" : "Msg",
				           ::Network.NetIO.getNetIOName(pNetClient->getMsgConn()->getNetClass()),
						   pNetClient->getMsgConn()->getPeerAddr().ToString().getData(),
				           pNetClient->getMsgConn()->getPingTime());
				if (pNetClient->getMsgConn() != pNetClient->getDataConn())
					AddLineFmt(LoadResStr("IDS_NET_CLIENT_INFO_CONNDATA"),
					           ::Network.NetIO.getNetIOName(pNetClient->getDataConn()->getNetClass()),
					           pNetClient->getDataConn()->getPeerAddr().ToString().getData(),
					           pNetClient->getDataConn()->getPingTime());
			}
			else
				AddLine(LoadResStr("IDS_NET_CLIENT_INFO_NOCONNECTIONS"));
		}
	}
	// update done
	EndUpdateText();
}