]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/list.h
Added a logout command and fixed some of the do_fight code
[irc/gameservirc.git] / gameserv / list.h
index 01b28fa660d4cd37a144a1d22b0a31cac94d14c8..e51d6f5a2a1dfd3d9a0561092916cd30879555e2 100644 (file)
@@ -1,10 +1,16 @@
 #ifndef LIST_H
 #define LIST_H
 
-#include <iostream.h>
+#include <iostream>
 #include <cassert>
 #include "listnode.h"
 #include "aClient.h"
+#include "extern.h"
+#include "options.h"
+
+using std::cout;
+using std::endl;
+using std::flush;
 
 template <class T>
 class List {
@@ -36,7 +42,9 @@ List<T>::~List()
 {
     if (!isEmpty())
     {
-       cout << "Destroying Nodes" << endl;
+       #ifdef DEBUGMODE
+           log("Destroying Nodes");
+       #endif
 
        ListNode<T> *currentPtr = firstPtr, *tempPtr;
 
@@ -44,14 +52,16 @@ List<T>::~List()
        {
            tempPtr = currentPtr;
            currentPtr = currentPtr->Next();
-//         if (!tempPtr->getData()->stats || tempPtr->getData()->stats->started == 0)
-           cout << "Deleting Memory address: " << tempPtr->getData() << endl << flush;
+
+           #ifdef DEBUGMODE
+               log("Deleting Memory address: %s", tempPtr->getData());
+           #endif
            
                delete tempPtr;
-//         else
-//             tempPtr->getData()->stats->started = 0;
        }
-       cout << "All Nodes destroyed" << endl;
+       #ifdef DEBUGMODE
+           log("All Nodes destroyed");
+       #endif
     }
 }
 
@@ -159,6 +169,7 @@ ListNode<T> *List<T>::Find( T *value )
     return NULL;
 }
 
+#ifdef DEBUGMODE
 template <class T>
 void List<T>::print() const
 {
@@ -172,16 +183,16 @@ void List<T>::print() const
     currentPtr = firstPtr;
     while (currentPtr)
     {
-       cout << "aClient: " << currentPtr->getData() << flush;
+       cout << "aClient: " << *currentPtr->getData() << flush;
 
         if (currentPtr->getData()->stats)
-           cout << "  Player Name: " << &currentPtr->getData()->stats->name 
-                << "   Password: " << &currentPtr->getData()->stats->password << flush;
+           cout << "  Player Name: " << currentPtr->getData()->stats->name 
+                << "   Password: " << currentPtr->getData()->stats->password << flush;
        cout << endl;
        currentPtr = currentPtr->next;
     }
-
 }
+#endif
 
 template <class T>
 bool List<T>::remove(T *remPtr)
@@ -199,15 +210,18 @@ bool List<T>::remove(T *remPtr)
        {
            if (firstPtr == lastPtr)
            {
-               cout << "One Element. Deleting it" << endl << flush;
+               #ifdef DEBUGMODE
+                   log("One Element. Deleting it");
+               #endif
                firstPtr = lastPtr = NULL;
                delete newPtr;
                return true;
            }
            else if (newPtr != lastPtr && newPtr != firstPtr)
            {
-               cout << "Many elements, this one is in the middle. Deleting it"
-                    << ", linking front to back, and back to front." << endl << flush;
+               #ifdef DEBUGMODE
+                   log("Many elements, this one is in the middle. Deleting it, linking front to back, and back to front.");
+               #endif
                newPtr->prev->next = newPtr->next;
                newPtr->next->prev = newPtr->prev;
                delete newPtr;
@@ -215,8 +229,9 @@ bool List<T>::remove(T *remPtr)
            }
            else if (newPtr == lastPtr)
            {
-               cout << "This was the last element. Deleting it, and pointing the tail to "
-                    << "its previous element." << endl << flush;
+               #ifdef DEBUGMODE
+                   log("This was the last element. Deleting it, and pointing the tail to its previous element.");
+               #endif
                lastPtr = newPtr->prev;
                lastPtr->next = 0;
                delete newPtr;
@@ -224,8 +239,9 @@ bool List<T>::remove(T *remPtr)
            }
            else if (newPtr == firstPtr)
            {
-               cout << "This was the first element. Deleting it, and pointing the head to "
-                    << "its next element." << endl << flush;
+               #ifdef DEBUGMODE
+                   log("This was the first element. Deleting it, and pointing the head to its next element.");
+               #endif
                firstPtr = newPtr->next;
                firstPtr->prev = 0;
                delete newPtr;