]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/news.cpp
Finally got level.h/cpp compiling into the project... beginning to store
[irc/gameservirc.git] / gameserv / news.cpp
index e558528ebe20c22de257a61c9b77938177f7b5c2..57b7c561e1e3417edad4b206d089268f414c951b 100644 (file)
@@ -1,11 +1,13 @@
 #include "extern.h"
 #include <fstream>
+#include <stdio.h>
 
 using std::ofstream;
 using std::ifstream;
 
 List<myString> todaysnews;
 void addNews(List<myString> &news, const char *fmt, ...);
+void clearNews(List<myString> &news) {news.deleteNodes();};
 void showNews(char *nick, List<myString> &news);
 void saveNews(char *filename, List<myString> &news);
 void loadNews(char *filename, List<myString> &news);
@@ -15,8 +17,6 @@ void addNews(List<myString> &news, const char *fmt, ...)
     if (fmt[0] == '\0')
         return;
 
-    log("Adding news item: fmt = %s", fmt);
-
     va_list args;
     char *input;
     input = new char[1024];
@@ -48,6 +48,7 @@ void addNews(List<myString> &news, const char *fmt, ...)
         log("New News Item: %s", input);
     #endif
 
+    notice(s_GameServ, c_Forest, "News Flash: %s", input);
     myString *nstring;
     nstring = new myString(input);
     news.insertAtBack(nstring);
@@ -77,11 +78,9 @@ void showNews(char *nick, List<myString> &news)
 
 void saveNews(char *filename, List<myString> &news)
 {
-    if (news.isEmpty())
-       return;
-
     ofstream outfile;
     outfile.open(filename);
+
     if (outfile.fail())
     {
        log("Error opening %s", filename);
@@ -100,9 +99,6 @@ void saveNews(char *filename, List<myString> &news)
 
 void loadNews(char *filename, List<myString> &news)
 {
-    if (news.isEmpty())
-       return;
-
     // First clear the old news out
     ListNode<myString> *it, *temp;
     it = news.First();
@@ -129,6 +125,11 @@ void loadNews(char *filename, List<myString> &news)
 
     while (infile.getline(buf, 1024, '\n'))
     {
+       if (buf[0] == '\0' || buf[0] == '\n')
+       {
+           delete [] buf;
+           return;
+       }
        string = new myString(buf);
        news.insertAtBack(string);
        delete string;
@@ -136,3 +137,8 @@ void loadNews(char *filename, List<myString> &news)
 
     delete [] buf;
 }
+
+void do_news(char *u)
+{
+    showNews(u, todaysnews);
+}