#include "ngircd.h"
#include "conn-func.h"
#include "conn-zip.h"
-#include "client.h"
#include "channel.h"
#include "conf.h"
#include "defines.h"
GLOBAL bool
IRC_Show_MOTD( CLIENT *Client )
{
- char line[127];
- FILE *fd;
+ const char *line;
+ size_t len_tot, len_str;
assert( Client != NULL );
- if (Conf_MotdPhrase[0]) {
- if (!Show_MOTD_Start(Client))
- return DISCONNECTED;
- if (!Show_MOTD_Sendline(Client, Conf_MotdPhrase))
- return DISCONNECTED;
- goto out;
- }
+ len_tot = array_bytes(&Conf_Motd);
+ if (len_tot == 0 && !Conn_UsesSSL(Client_Conn(Client)))
+ return IRC_WriteStrClient(Client, ERR_NOMOTD_MSG, Client_ID(Client));
- fd = fopen( Conf_MotdFile, "r" );
- if( ! fd ) {
- Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
- if (Conn_UsesSSL(Client_Conn(Client))) {
- if (!Show_MOTD_Start(Client))
- return DISCONNECTED;
- goto out;
- }
- return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) );
- }
+ if (!Show_MOTD_Start(Client))
+ return DISCONNECTED;
- if (!Show_MOTD_Start( Client )) {
- fclose(fd);
- return false;
- }
+ line = array_start(&Conf_Motd);
+ while (len_tot > 0) {
+ len_str = strlen(line) + 1;
- while (fgets( line, (int)sizeof line, fd )) {
- ngt_TrimLastChr( line, '\n');
+ assert(len_tot >= len_str);
+ len_tot -= len_str;
- if( ! Show_MOTD_Sendline( Client, line)) {
- fclose( fd );
- return false;
- }
+ if (!Show_MOTD_Sendline(Client, line))
+ return DISCONNECTED;
+ line += len_str;
}
- fclose(fd);
-out:
+
if (!Show_MOTD_SSLInfo(Client))
return DISCONNECTED;
return Show_MOTD_End(Client);