X-Git-Url: https://jfr.im/git/irc/gameservirc.git/blobdiff_plain/466692a56e4c0c2bdc1a72e4a59e3ec34964f958..1f8a5387bcfe3f34d29a1a58c8f5132bbd165ec7:/gameserv/news.cpp diff --git a/gameserv/news.cpp b/gameserv/news.cpp index 371ce81..df06e70 100644 --- a/gameserv/news.cpp +++ b/gameserv/news.cpp @@ -6,6 +6,7 @@ using std::ifstream; List todaysnews; void addNews(List &news, const char *fmt, ...); +void clearNews(List &news) {news.deleteNodes();}; void showNews(char *nick, List &news); void saveNews(char *filename, List &news); void loadNews(char *filename, List &news); @@ -18,6 +19,7 @@ void addNews(List &news, const char *fmt, ...) va_list args; char *input; input = new char[1024]; + memset(input, 0, 1024); const char *t = fmt; va_start(args, fmt); @@ -44,6 +46,7 @@ void addNews(List &news, const char *fmt, ...) #ifdef DEBUGMODE log("New News Item: %s", input); #endif + myString *nstring; nstring = new myString(input); news.insertAtBack(nstring); @@ -73,11 +76,9 @@ void showNews(char *nick, List &news) void saveNews(char *filename, List &news) { - if (news.isEmpty()) - return; - ofstream outfile; outfile.open(filename); + if (outfile.fail()) { log("Error opening %s", filename); @@ -96,9 +97,6 @@ void saveNews(char *filename, List &news) void loadNews(char *filename, List &news) { - if (news.isEmpty()) - return; - // First clear the old news out ListNode *it, *temp; it = news.First(); @@ -125,6 +123,11 @@ void loadNews(char *filename, List &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; @@ -132,3 +135,8 @@ void loadNews(char *filename, List &news) delete [] buf; } + +void do_news(char *u) +{ + showNews(u, todaysnews); +}