This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Undernet IRC Server Source Code.".

The branch, master has been updated
       via  5959f7b04b78640a4961f86620a9f6c9f62944ef (commit)
       via  8b15fd9928e3c1dc4dc8d57730bde33d2400ed25 (commit)
       via  4b6b85a822048464f5923b9e26386dbd918a4c06 (commit)
      from  f861105d50ce6271a77ebefc49851ab7214a2f45 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5959f7b04b78640a4961f86620a9f6c9f62944ef
Author: Michael Poole <[email protected]>
Date:   Mon May 29 15:42:33 2017 -0400

    ms_xreply: Use FindNClient().

diff --git a/ircd/m_xreply.c b/ircd/m_xreply.c
index 38ddc3a..9f845a8 100644
--- a/ircd/m_xreply.c
+++ b/ircd/m_xreply.c
@@ -60,7 +60,7 @@ int ms_xreply(struct Client* cptr, struct Client* sptr, int 
parc, char* parv[])
   reply = parv[3];
 
   /* Look up the target */
-  acptr = parv[1][2] ? findNUser(parv[1]) : FindNServer(parv[1]);
+  acptr = FindNClient(parv[1]);
   if (!acptr)
     return send_reply(sptr, SND_EXPLICIT | ERR_NOSUCHSERVER,
                      "* :Server has disconnected");
commit 8b15fd9928e3c1dc4dc8d57730bde33d2400ed25
Author: Michael Poole <[email protected]>
Date:   Mon May 29 15:39:08 2017 -0400

    FindNClient: New helper function for numnick lookups.

diff --git a/include/numnicks.h b/include/numnicks.h
index cc29823..dccfe92 100644
--- a/include/numnicks.h
+++ b/include/numnicks.h
@@ -78,6 +78,7 @@ extern void SetYXXServerName(struct Client* myself, unsigned 
int numeric);
 
 extern int            markMatchexServer(const char* cmask, int minlen);
 extern struct Client* find_match_server(char* mask);
+extern struct Client *FindNClient(const char* numnick);
 extern struct Client* findNUser(const char* yxx);
 extern struct Client* FindNServer(const char* numeric);
 
diff --git a/ircd/numnicks.c b/ircd/numnicks.c
index 086af25..bc85e0b 100644
--- a/ircd/numnicks.c
+++ b/ircd/numnicks.c
@@ -158,19 +158,38 @@ const char* inttobase64(char* buf, unsigned int v, 
unsigned int count)
   return buf;
 }
 
-/** Look up a server by numnick string.
+/** Look up an IRC "client" by numnick string.
  * See @ref numnicks for more details.
- * @param[in] numeric %Numeric nickname of server (may contain trailing junk).
- * @return %Server with that numnick (or NULL).
+ * @param[in] numnick %Numeric nickname of server or user.
+ * @return %Client with that numnick (or NULL).
  */
-static struct Client* FindXNServer(const char* numeric)
+struct Client *FindNClient(const char* numnick)
 {
-  char buf[3];
-  buf[0] = *numeric++;
-  buf[1] = *numeric;
-  buf[2] = '\0';
-  Debug((DEBUG_DEBUG, "FindXNServer: %s(%d)", buf, base64toint(buf)));
-  return server_list[base64toint(buf)];
+  unsigned int i = 0, nn = 0;
+  struct Client *srv;
+
+  while (numnick[i] != '\0') {
+    nn = (nn << NUMNICKLOG) | convert2n[(unsigned char)numnick[i++]];
+  }
+
+  switch (i) {
+  case 1: /* S */
+  case 2: /* SS */
+    return server_list[nn];
+  case 3: /* SCC */
+    srv = server_list[nn >> (2 * NUMNICKLOG)];
+    break;
+  case 4: /* SCCC */
+  case 5: /* SSCCC */
+    srv = server_list[nn >> (3 * NUMNICKLOG)];
+  default:
+    return NULL;
+  }
+
+  if (srv)
+    return cli_serv(srv)->client_list[nn & cli_serv(srv)->nn_mask];
+
+  return NULL;
 }
 
 /** Look up a server by numnick string.
@@ -180,18 +199,8 @@ static struct Client* FindXNServer(const char* numeric)
  */
 struct Client* FindNServer(const char* numeric)
 {
-  unsigned int len = strlen(numeric);
-
-  if (len < 3) {
-    Debug((DEBUG_DEBUG, "FindNServer: %s(%d)", numeric, base64toint(numeric)));
-    return server_list[base64toint(numeric)];
-  }
-  else if (len == 3) {
-    Debug((DEBUG_DEBUG, "FindNServer: %c(%d)", *numeric, 
-           convert2n[(unsigned char) *numeric]));
-    return server_list[convert2n[(unsigned char) *numeric]];
-  }
-  return FindXNServer(numeric);
+  struct Client* cli = FindNClient(numeric);
+  return (cli && cli_serv(cli)) ? cli : NULL;
 }
 
 /** Look up a user by numnick string.
@@ -201,20 +210,8 @@ struct Client* FindNServer(const char* numeric)
  */
 struct Client* findNUser(const char* yxx)
 {
-  struct Client* server = 0;
-  if (5 == strlen(yxx)) {
-    if (0 != (server = FindXNServer(yxx))) {
-      Debug((DEBUG_DEBUG, "findNUser: %s(%d)", yxx, 
-             base64toint(yxx + 2) & cli_serv(server)->nn_mask));
-      return cli_serv(server)->client_list[base64toint(yxx + 2) & 
cli_serv(server)->nn_mask];
-    }
-  }
-  else if (0 != (server = FindNServer(yxx))) {
-    Debug((DEBUG_DEBUG, "findNUser: %s(%d)",
-           yxx, base64toint(yxx + 1) & cli_serv(server)->nn_mask));
-    return cli_serv(server)->client_list[base64toint(yxx + 1) & 
cli_serv(server)->nn_mask];
-  }
-  return 0;
+  struct Client* cli = FindNClient(yxx);
+  return (cli && cli_user(cli)) ? cli : NULL;
 }
 
 /** Remove a client from a server's user array.
commit 4b6b85a822048464f5923b9e26386dbd918a4c06
Author: Michael Poole <[email protected]>
Date:   Mon May 29 14:59:05 2017 -0400

    ircd_relay: Use !(ptr) rather than 0 == (ptr).

diff --git a/ircd/ircd_relay.c b/ircd/ircd_relay.c
index 0d39f6c..96af645 100644
--- a/ircd/ircd_relay.c
+++ b/ircd/ircd_relay.c
@@ -438,7 +438,7 @@ void server_relay_private_message(struct Client* sptr, 
const char* name, const c
   /*
    * nickname addressed?
    */
-  if (0 == (acptr = findNUser(name)) || !IsUser(acptr)) {
+  if (!(acptr = findNUser(name)) || !IsUser(acptr)) {
     send_reply(sptr, SND_EXPLICIT | ERR_NOSUCHNICK, "* :Target left %s. "
               "Failed to deliver: [%.20s]", feature_str(FEAT_NETWORK),
                text);
@@ -469,7 +469,7 @@ void server_relay_private_notice(struct Client* sptr, const 
char* name, const ch
   /*
    * nickname addressed?
    */
-  if (0 == (acptr = findNUser(name)) || !IsUser(acptr))
+  if (!(acptr = findNUser(name)) || !IsUser(acptr))
     return;
 
   if (is_silenced(sptr, acptr))
-----------------------------------------------------------------------

Summary of changes:
 include/numnicks.h |  1 +
 ircd/ircd_relay.c  |  4 ++--
 ircd/m_xreply.c    |  2 +-
 ircd/numnicks.c    | 69 ++++++++++++++++++++++++++----------------------------
 4 files changed, 37 insertions(+), 39 deletions(-)


hooks/post-receive
-- 
Undernet IRC Server Source Code.
_______________________________________________
Patches mailing list
[email protected]
http://undernet.sbg.org/mailman/listinfo/patches

Reply via email to