]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-info.c
ngircd: change MOTD file handling
[ngircd-alex.git] / src / ngircd / irc-info.c
index 0a50e9fdbc45a903d1672c7a4d5c34affb46a953..ad585fe236151dc68f013ad22a81896512de767a 100644 (file)
@@ -1231,45 +1231,30 @@ static inline bool Show_MOTD_SSLInfo(UNUSED CLIENT *c) { return true; }
 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);