Bryan Drewery 10 лет назад
Родитель
Сommit
8f0234e2c1
3 измененных файлов с 32 добавлено и 50 удалено
  1. 27 44
      src/auth.cc
  2. 0 3
      src/auth.h
  3. 5 3
      src/mod/irc.mod/msgcmds.cc

+ 27 - 44
src/auth.cc

@@ -39,7 +39,6 @@
 
 
 #include "stat.h"
 #include "stat.h"
 
 
-bd::HashTable<bd::String, Auth*> Auth::ht_handle(10);
 bd::HashTable<bd::String, Auth*> Auth::ht_host(10);
 bd::HashTable<bd::String, Auth*> Auth::ht_host(10);
 bd::HashTable<bd::String, Auth*> Auth::ht_nick(10);
 bd::HashTable<bd::String, Auth*> Auth::ht_nick(10);
 
 
@@ -48,31 +47,21 @@ Auth::Auth(const char *_nick, const char *_host, struct userrec *u)
   Status(AUTHING);
   Status(AUTHING);
   strlcpy(nick, _nick, NICKLEN);
   strlcpy(nick, _nick, NICKLEN);
   strlcpy(host, _host, UHOSTLEN);
   strlcpy(host, _host, UHOSTLEN);
-  if (u) {
-    user = u;
-    strlcpy(handle, u->handle, sizeof(handle));
-  } else {
-    user = NULL;
-    handle[0] = '*';
-    handle[1] = 0;
-  }
-
+  user = u;
 
 
   ht_host[host] = this;
   ht_host[host] = this;
   ht_nick[_nick] = this;
   ht_nick[_nick] = this;
-  if (user)
-    ht_handle[handle] = this;
 
 
-  sdprintf(STR("New auth created! (%s!%s) [%s]"), nick, host, handle);
+  sdprintf(STR("New auth created! (%s!%s) [%s]"), nick, host,
+      u ? u->handle : "*");
   authtime = atime = now;
   authtime = atime = now;
   idx = -1;
   idx = -1;
 }
 }
 
 
 Auth::~Auth()
 Auth::~Auth()
 {
 {
-  sdprintf(STR("Removing auth: (%s!%s) [%s]"), nick, host, handle);
-  if (user)
-    ht_handle.remove(handle);
+  sdprintf(STR("Removing auth: (%s!%s) [%s]"), nick, host,
+      user ? user->handle : "*");
   ht_host.remove(host);
   ht_host.remove(host);
   ht_nick.remove(nick);
   ht_nick.remove(nick);
 }
 }
@@ -99,17 +88,8 @@ Auth *Auth::Find(const char *_host)
 
 
   if (ht_host.contains(_host)) {
   if (ht_host.contains(_host)) {
     Auth *auth = ht_host[_host];
     Auth *auth = ht_host[_host];
-    sdprintf(STR("Found auth: (%s!%s) [%s]"), auth->nick, auth->host, auth->handle);
-    return auth;
-  }
-  return NULL;
-}
-
-Auth *Auth::Find(const char *handle, bool _hand)
-{
-  if (ht_handle.contains(handle)) {
-    Auth *auth = ht_handle[handle];
-    sdprintf(STR("Found auth (by handle): %s (%s!%s)"), handle, auth->nick, auth->host);
+    sdprintf(STR("Found auth: (%s!%s) [%s]"), auth->nick, auth->host,
+        auth->user ? auth->user->handle : "*");
     return auth;
     return auth;
   }
   }
   return NULL;
   return NULL;
@@ -118,7 +98,8 @@ Auth *Auth::Find(const char *handle, bool _hand)
 static void auth_clear_users_block(const bd::String key, Auth* auth, void *param)
 static void auth_clear_users_block(const bd::String key, Auth* auth, void *param)
 {
 {
   if (auth->user) {
   if (auth->user) {
-    sdprintf(STR("Clearing USER for auth: (%s!%s) [%s]"), auth->nick, auth->host, auth->handle);
+    sdprintf(STR("Clearing USER for auth: (%s!%s) [%s]"), auth->nick,
+        auth->host, auth->user ? auth->user->handle : "*");
     auth->user = NULL;
     auth->user = NULL;
   }
   }
 }
 }
@@ -130,21 +111,19 @@ void Auth::NullUsers(const char *nick)
   } else {
   } else {
     if (ht_nick.contains(nick)) {
     if (ht_nick.contains(nick)) {
       Auth *auth = ht_nick[nick];
       Auth *auth = ht_nick[nick];
-      if (auth->user) {
-        ht_handle.remove(auth->handle);
-      }
       auth->user = NULL;
       auth->user = NULL;
-      auth->handle[0] = '\0';
     }
     }
   }
   }
 }
 }
 
 
 static void auth_fill_users_block(const bd::String key, Auth* auth, void* param)
 static void auth_fill_users_block(const bd::String key, Auth* auth, void* param)
 {
 {
-  if (strcmp(auth->handle, "*")) {
-    sdprintf(STR("Filling USER for auth: (%s!%s) [%s]"), auth->nick, auth->host, auth->handle);
-    auth->user = get_user_by_handle(userlist, auth->handle);
-  }
+  char from[NICKLEN + UHOSTLEN];
+
+  sdprintf(STR("Filling USER for auth: (%s!%s) [%s]"), auth->nick, auth->host,
+      auth->user ? auth->user->handle : "*");
+  simple_snprintf(from, sizeof(from), "%s!%s", auth->nick, auth->host);
+  auth->user = get_user_by_host(from);
 }
 }
 
 
 void Auth::FillUsers()
 void Auth::FillUsers()
@@ -158,7 +137,6 @@ static void auth_expire_block(const bd::String key, Auth* auth, void* param)
   if (auth->Authed() && ((now - auth->atime) >= (60 * 60))) {
   if (auth->Authed() && ((now - auth->atime) >= (60 * 60))) {
     Auth::ht_host.remove(key);
     Auth::ht_host.remove(key);
     Auth::ht_nick.remove(auth->nick);
     Auth::ht_nick.remove(auth->nick);
-    Auth::ht_handle.remove(auth->handle);
     delete auth;
     delete auth;
   }
   }
 }
 }
@@ -173,7 +151,8 @@ void Auth::ExpireAuths()
 
 
 static void auth_delete_all_block(const bd::String, Auth* auth, void* param)
 static void auth_delete_all_block(const bd::String, Auth* auth, void* param)
 {
 {
-  putlog(LOG_DEBUG, "*", STR("Removing (%s!%s) [%s], from auth list."), auth->nick, auth->host, auth->handle);
+  putlog(LOG_DEBUG, "*", STR("Removing (%s!%s) [%s], from auth list."),
+      auth->nick, auth->host, auth->user ? auth->user->handle : "*");
   delete auth;
   delete auth;
 }
 }
 
 
@@ -184,7 +163,6 @@ void Auth::DeleteAll()
     ht_host.each(auth_delete_all_block);
     ht_host.each(auth_delete_all_block);
     ht_host.clear();
     ht_host.clear();
     ht_nick.clear();
     ht_nick.clear();
-    ht_handle.clear();
   }
   }
 }
 }
 
 
@@ -201,7 +179,7 @@ sdprintf(STR("GETIDX: auth: %s, idx: %d"), nick, idx);
       idx = -1;
       idx = -1;
     else if (!dcc[idx].irc || dcc[idx].simul == -1)
     else if (!dcc[idx].irc || dcc[idx].simul == -1)
       idx = -1;
       idx = -1;
-    else if (strcmp(dcc[idx].nick, handle))
+    else if (user && strcmp(dcc[idx].nick, user->handle))
       idx = -1;
       idx = -1;
     else {
     else {
       sdprintf(STR("FIRST FOUND: %d"), idx);
       sdprintf(STR("FIRST FOUND: %d"), idx);
@@ -215,7 +193,8 @@ sdprintf(STR("GETIDX: auth: %s, idx: %d"), nick, idx);
 
 
   for (i = 0; i < dcc_total; i++) {
   for (i = 0; i < dcc_total; i++) {
     if (dcc[i].type && dcc[i].irc &&
     if (dcc[i].type && dcc[i].irc &&
-       (((chname && chname[0]) && !strcmp(dcc[i].simulbot, chname) && !strcmp(dcc[i].nick, handle)) ||
+       (((chname && chname[0]) && !strcmp(dcc[i].simulbot, chname) &&
+         user && !strcmp(dcc[i].nick, user->handle)) ||
        (!(chname && chname[0]) && !strcmp(dcc[i].simulbot, nick)))) {
        (!(chname && chname[0]) && !strcmp(dcc[i].simulbot, nick)))) {
       putlog(LOG_DEBUG, "*", STR("Simul found old idx for %s/%s: (%s!%s)"), nick, chname, nick, host);
       putlog(LOG_DEBUG, "*", STR("Simul found old idx for %s/%s: (%s!%s)"), nick, chname, nick, host);
       dcc[i].simultime = now;
       dcc[i].simultime = now;
@@ -230,6 +209,8 @@ sdprintf(STR("GETIDX: auth: %s, idx: %d"), nick, idx);
   idx = new_dcc(&DCC_CHAT, sizeof(struct chat_info));
   idx = new_dcc(&DCC_CHAT, sizeof(struct chat_info));
 
 
   if (idx != -1) {
   if (idx != -1) {
+    char from[NICKLEN + UHOSTLEN];
+
     dcc[idx].sock = -1;
     dcc[idx].sock = -1;
     dcc[idx].timeval = now;
     dcc[idx].timeval = now;
     dcc[idx].irc = 1;
     dcc[idx].irc = 1;
@@ -240,10 +221,11 @@ sdprintf(STR("GETIDX: auth: %s, idx: %d"), nick, idx);
     strlcpy(dcc[idx].simulbot, nick, sizeof(dcc[idx].simulbot));
     strlcpy(dcc[idx].simulbot, nick, sizeof(dcc[idx].simulbot));
     strlcpy(dcc[idx].u.chat->con_chan, chname ? chname : "*", sizeof(dcc[idx].u.chat->con_chan));
     strlcpy(dcc[idx].u.chat->con_chan, chname ? chname : "*", sizeof(dcc[idx].u.chat->con_chan));
     dcc[idx].u.chat->strip_flags = STRIP_ALL;
     dcc[idx].u.chat->strip_flags = STRIP_ALL;
-    strlcpy(dcc[idx].nick, handle, sizeof(dcc[idx].nick));
+    strlcpy(dcc[idx].nick, user ? user->handle : "*", sizeof(dcc[idx].nick));
     strlcpy(dcc[idx].host, host, sizeof(dcc[idx].host));
     strlcpy(dcc[idx].host, host, sizeof(dcc[idx].host));
     dcc[idx].addr = 0L;
     dcc[idx].addr = 0L;
-    dcc[idx].user = user ? user : get_user_by_handle(userlist, handle);
+    simple_snprintf(from, sizeof(from), "%s!%s", nick, host);
+    dcc[idx].user = user ? user : get_user_by_host(from);
     return 1;
     return 1;
   }
   }
 
 
@@ -256,7 +238,8 @@ static void auth_tell_block(const bd::String key, Auth* auth, void* param)
   int idx = (int) lparam;
   int idx = (int) lparam;
 
 
   dprintf(idx, "(%s!%s) [%s] authtime: %li, atime: %li, Status: %d\n", auth->nick, 
   dprintf(idx, "(%s!%s) [%s] authtime: %li, atime: %li, Status: %d\n", auth->nick, 
-        auth->host, auth->handle, (long)auth->authtime, (long)auth->atime, auth->Status());
+        auth->host, auth->user ? auth->user->handle : "*",
+        (long)auth->authtime, (long)auth->atime, auth->Status());
 }
 }
 
 
 void Auth::TellAuthed(int idx)
 void Auth::TellAuthed(int idx)

+ 0 - 3
src/auth.h

@@ -25,7 +25,6 @@ class Auth {
   void NewNick(const char *nick);
   void NewNick(const char *nick);
 
 
   static Auth *Find(const char * host);
   static Auth *Find(const char * host);
-  static Auth *Find(const char * handle, bool _hand);
   static void NullUsers(const char *nick = NULL);
   static void NullUsers(const char *nick = NULL);
   static void FillUsers();
   static void FillUsers();
   static void ExpireAuths();
   static void ExpireAuths();
@@ -41,9 +40,7 @@ class Auth {
   char rand[51];
   char rand[51];
   char nick[NICKLEN];
   char nick[NICKLEN];
   char host[UHOSTLEN];
   char host[UHOSTLEN];
-  char handle[HANDLEN + 1];
 
 
-  static bd::HashTable<bd::String, Auth*> ht_handle;
   static bd::HashTable<bd::String, Auth*> ht_host;
   static bd::HashTable<bd::String, Auth*> ht_host;
   static bd::HashTable<bd::String, Auth*> ht_nick;
   static bd::HashTable<bd::String, Auth*> ht_nick;
 
 

+ 5 - 3
src/mod/irc.mod/msgcmds.cc

@@ -294,9 +294,11 @@ static int msg_invite(char *nick, char *host, struct userrec *u, char *par)
 static void logc(const char *cmd, Auth *a, char *chname, char *par)
 static void logc(const char *cmd, Auth *a, char *chname, char *par)
 {
 {
   if (chname && chname[0])
   if (chname && chname[0])
-    putlog(LOG_CMDS, "*", "(%s!%s) !%s! %s %c%s %s", a->nick, a->host, a->handle, chname, auth_prefix[0], cmd, par ? par : "");
+    putlog(LOG_CMDS, "*", "(%s!%s) !%s! %s %c%s %s", a->nick, a->host,
+        a->user ? a->user->handle : "*", chname, auth_prefix[0], cmd, par ? par : "");
   else
   else
-    putlog(LOG_CMDS, "*", "(%s!%s) !%s! %c%s %s", a->nick, a->host, a->handle, auth_prefix[0], cmd, par ? par : "");
+    putlog(LOG_CMDS, "*", "(%s!%s) !%s! %c%s %s", a->nick, a->host,
+        a->user ? a->user->handle : "*", auth_prefix[0], cmd, par ? par : "");
 }
 }
 #define LOGC(cmd) logc(cmd, a, chname, par)
 #define LOGC(cmd) logc(cmd, a, chname, par)
   
   
@@ -338,7 +340,7 @@ static int msg_authstart(char *nick, char *host, struct userrec *u, char *par)
 static void
 static void
 AuthFinish(Auth *auth)
 AuthFinish(Auth *auth)
 {
 {
-  putlog(LOG_CMDS, "*", STR("(%s!%s) !%s! +AUTH"), auth->nick, auth->host, auth->handle);
+  putlog(LOG_CMDS, "*", STR("(%s!%s) !%s! +AUTH"), auth->nick, auth->host, auth->user ? auth->user->handle : "*");
   auth->Done();
   auth->Done();
   bd::String msg;
   bd::String msg;
   msg = bd::String::printf(STR("You are now authorized for cmds, see %chelp"), auth_prefix[0]);
   msg = bd::String::printf(STR("You are now authorized for cmds, see %chelp"), auth_prefix[0]);