Exemplo n.º 1
0
/**
 * NickCatchTimer
 *
 * Used to regain a user's nickname
 *
 * @param Now current time
 * @param IRCConnection irc connection
 */
bool NickCatchTimer(time_t Now, void *IRCConnection) {
	CIRCConnection *IRC = (CIRCConnection *)IRCConnection;
	CUser *Owner = IRC->GetOwner();
	const char *AwayNick;

	if (Owner != NULL) {
		AwayNick = IRC->GetOwner()->GetAwayNick();
	} else {
		AwayNick = NULL;
	}

	if (Owner && Owner->GetClientConnectionMultiplexer() != NULL) {
		IRC->m_NickCatchTimer = NULL;

		return false;
	}

	if (IRC->GetCurrentNick() != NULL && AwayNick != NULL && strcmp(IRC->GetCurrentNick(), AwayNick) != 0) {
		IRC->WriteLine("NICK %s", AwayNick);
	}

	IRC->m_NickCatchTimer = NULL;

	return false;
}
Exemplo n.º 2
0
/**
 * IRCPingTimer
 *
 * Checks the IRC connection for timeouts.
 *
 * @param Now the current time
 * @param IRCConnection the CIRCConnection object
 */
bool IRCPingTimer(time_t Now, void *IRCConnection) {
	CIRCConnection *IRC = (CIRCConnection *)IRCConnection;

	if (IRC->GetSocket() == INVALID_SOCKET) {
		return true;
	}

	if (g_CurrentTime - IRC->m_LastResponse > 300) {
		const char *ServerName;
		
		ServerName = IRC->GetServer();

		if (ServerName == NULL) {
			ServerName = "sbnc";
		}

		IRC->WriteLine("PING :%s", ServerName);
		IRC->m_EatPong = true;

		/* we're using "Now" here, because that's the time when the
		 * check should've returned a PONG, this might be useful when
		 * we're in a time warp */
		if (Now - IRC->m_LastResponse > 600) {
			IRC->Kill("Server does not respond.");
		}
	}

	return true;
}