]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/tcpclient.cpp
Updated TODO and fixed the hashing algorithm for P10 numerics + others' nickname...
[irc/gameservirc.git] / gameserv / tcpclient.cpp
index 70007f2d790900c6efad7680ce0e2b7d3c14e4c8..3e355d61757fc68384e983cd7d767c85f7684e81 100644 (file)
@@ -36,12 +36,12 @@ using std::cerr;
 using std::endl;
 
 char *PACKAGE = "GameServ";
-char *VERSION = "1.1.9";
+char *VERSION = "1.2.0 +devel";
 
 int sock;
 int day;
 
-List<aClient> clients;
+List<aClient> clients[U_TABLE_SIZE];
 
 void save_day();
 void load_day();
@@ -238,8 +238,14 @@ int main(int argc, char *argv[])
                if ((tempPtr = find((source + 1))))
                {
                    char *nick;
+                   unsigned long oldhv, newhv;
                    nick = strtok(NULL, " ");
+                   oldhv = HASH((unsigned char *) tempPtr->getNick(),
+                               U_TABLE_SIZE);
+                   newhv = HASH((unsigned char *) nick, U_TABLE_SIZE);
                    tempPtr->setNick(nick);
+                   clients[oldhv].remove(tempPtr);
+                   clients[newhv].insertAtBack(tempPtr);
                }
            }
            else
@@ -289,8 +295,8 @@ int main(int argc, char *argv[])
                #else
                    notice(s_GameServ, nick, welcomemsg, nick);
                #endif
-
-               clients.insertAtBack(newuser);
+               unsigned long hv = HASH((unsigned char *) nick, U_TABLE_SIZE);
+               clients[hv].insertAtBack(newuser);
                delete newuser;
            }
       #if defined(P10)
@@ -304,11 +310,28 @@ int main(int argc, char *argv[])
            if (z == ':')
                source++;
 
+           unsigned long hv = HASH((unsigned char *) source, U_TABLE_SIZE);
            if ((quitter = find(source)))
-               clients.remove(quitter);
+               clients[hv].remove(quitter);
            if ((quitter = findIRCplayer(source)))
            {
+               if (player_fight(quitter))
+               {
+                   // Stop the fight on the other client
+                   aClient *otherplayer = quitter->stats->battle;
+                   otherplayer->stats->battle = NULL;
+                   notice(s_GameServ, otherplayer->getNick(), "%s "\
+                          "has quit IRC. The fight stops here.",
+                          quitter->stats->name);
+               }
+               quitter->stats->battle = NULL;
+               quitter->stats->fight = NULL;
+               quitter->stats->master = NULL;
+
                quitter->setNick("!NULL!");
+               #ifdef P10
+                   quitter->setRealNick("!NULL!");
+               #endif
                quitter->stats->user = NULL; // Unidentify them
            }
 
@@ -345,11 +368,39 @@ int main(int argc, char *argv[])
            else if (stricmp(dest, c_Forest) == 0)
                forest(source, rest);
       #endif
+      #if defined(P10)
+       } else if (stricmp(cmd, "J") == 0) {
+      #else
        } else if (stricmp(cmd, "JOIN") == 0) {
+      #endif
            char *channel;
+           aClient *joiner;
            channel = strtok(NULL, " ");
-           if (stricmp(channel, c_Forest) == 0 && is_playing(source + 1))
-               raw(":%S MODE %s +v %s", c_Forest, (source + 1));
+
+            char z = source[0];
+
+            if (z == ':')
+                source++;
+
+           joiner = find(source);
+
+           if (stricmp(channel, c_Forest) == 0 && is_playing(joiner))
+           {
+               #ifdef DEBUGMODE
+                   log("Player %s (IRC: %s) joined %s", 
+                       joiner->stats->name, 
+                       #ifdef P10
+                           joiner->getRealNick(),
+                       #else
+                           joiner->getNick(),
+                       #endif
+                       c_Forest);
+               #endif
+               raw(":%S MODE %s +v %s", c_Forest, (source));
+           }
+
+           if (z == ':')
+               source--;
 
        #if defined(BAHAMUT)
        } else if (stricmp(cmd, "SJOIN") == 0) {
@@ -415,7 +466,8 @@ aClient *find(const char *nick)
 aClient *findbyrealnick(char *realnick)
 {
    ListNode <aClient> *newPtr;
-    newPtr = clients.First();
+   unsigned long hv = HASH((unsigned char *) realnick, U_TABLE_SIZE);
+    newPtr = clients[hv].First();
 
     aClient *client = NULL;
 
@@ -442,7 +494,8 @@ aClient *findbyrealnick(char *realnick)
 aClient *findbynick(char *nick)
 {
     ListNode <aClient> *newPtr;
-    newPtr = clients.First();
+    unsigned long hv = HASH((unsigned char *) nick, U_TABLE_SIZE);
+    newPtr = clients[hv].First();
 
     aClient *client = NULL;
 
@@ -466,7 +519,8 @@ aClient *findIRCplayer(const char *nick)
     ListNode <aClient> *newPtr;
     aClient *p = NULL;
 
-    for (newPtr = players.First(); newPtr; newPtr = newPtr->Next())
+    unsigned long hv = HASH((unsigned char *) nick, U_TABLE_SIZE);
+    for (newPtr = players[hv].First(); newPtr; newPtr = newPtr->Next())
     {
        p = newPtr->getData();
        #ifdef P10
@@ -483,8 +537,8 @@ aClient *findplayer(const char *name)
 {
     ListNode <aClient> *newPtr;
     Player *p = NULL;
-
-    for (newPtr = players.First(); newPtr; newPtr = newPtr->Next())
+    unsigned long hv = HASH((unsigned char *) name, U_TABLE_SIZE);
+    for (newPtr = players[hv].First(); newPtr; newPtr = newPtr->Next())
     {
        p = newPtr->getData()->stats;
        if (stricmp(p->name, name) == 0)
@@ -497,7 +551,8 @@ aClient *findplayer(const char *name)
 aClient *findbynick(const char *nick)
 {
     ListNode <aClient> *newPtr;
-    newPtr = clients.First();
+    unsigned long hv = HASH((unsigned char *) nick, U_TABLE_SIZE);
+    newPtr = clients[hv].First();
 
     aClient *client = NULL;