Esempio n. 1
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;
}
Esempio n. 2
0
/**
 * PlayToUser
 *
 * Sends the log to the specified user.
 *
 * @param Client the user who should receive the log
 * @param Type specifies how the log should be sent, can be one of:
 *             Log_Notices - use IRC notices
 *             Log_Messages - use IRC messages
 *             Log_Motd - use IRC motd replies
 */
void CLog::PlayToUser(CClientConnection *Client, LogType Type) const {
	FILE *LogFile;

	CIRCConnection *IRC = Client->GetOwner()->GetIRCConnection();
	const char *Nick = NULL;
	const char *Server = NULL;

	if (m_File != NULL) {
		fclose(m_File);
	}

	if (m_Filename != NULL && (LogFile = fopen(m_Filename, "r")) != NULL) {
		char Line[500];

		while (!feof(LogFile)) {
			char *LinePtr = fgets(Line, sizeof(Line), LogFile);

			if (LinePtr == NULL) {
				continue;
			}
			char *TempLinePtr = Line;

			while (*TempLinePtr) {
				if (*TempLinePtr == '\r' || *TempLinePtr == '\n') {
					*TempLinePtr = '\0';

					break;
				}

				TempLinePtr++;
			}

			if (Type == Log_Notice) {
				Client->RealNotice(Line);
			} else if (Type == Log_Message) {
				Client->Privmsg(Line);
			} else if (Type == Log_Motd) {
				if (IRC != NULL) {
					Nick = IRC->GetCurrentNick();
					Server = IRC->GetServer();
				} else {
					Nick = Client->GetNick();
					Server = "bouncer.shroudbnc.info";
				}

				if (Client != NULL) {
					Client->WriteLine(":%s 372 %s :%s", Server, Nick, Line);
				}
			}
		}

		fclose(LogFile);
		m_File = NULL;
	}

	if (Type == Log_Motd && Client != NULL && Nick != NULL && Server != NULL) {
		Client->WriteLine(":%s 376 %s :End of /MOTD command.", Server, Nick);
	}
}