Fix hostmask generation for hostnames without dots.
[srvx.git] / src / proto-common.c
index bd392e0f3eaa845039e05ef6db0027d99571ff4e..64a43d927739d4910941a7dd82c222f520e35f35 100644 (file)
@@ -1,5 +1,5 @@
 /* proto-common.c - common IRC protocol parsing/sending support
- * Copyright 2000-2004 srvx Development Team
+ * Copyright 2000-2006 srvx Development Team
  *
  * This file is part of srvx.
  *
@@ -92,7 +92,7 @@ uplink_readable(struct io_fd *fd) {
 void
 socket_destroyed(struct io_fd *fd)
 {
-    if (fd && fd->eof)
+    if (fd && fd->state != IO_CONNECTED)
         log_module(MAIN_LOG, LOG_ERROR, "Connection to server lost.");
     socket_io_fd = NULL;
     cManager.uplink->state = DISCONNECTED;
@@ -275,7 +275,8 @@ close_socket(void)
         replay_connected = 0;
         socket_destroyed(socket_io_fd);
     } else {
-        ioset_close(socket_io_fd->fd, 1);
+        ioset_close(socket_io_fd, 1);
+        socket_io_fd = NULL;
     }
 }
 
@@ -464,10 +465,30 @@ privmsg_invalid(char *name, void *data)
     irc_numeric(pd->user, ERR_NOSUCHNICK, "%s@%s :No such nick", name, self->name);
 }
 
+struct part_desc {
+    struct userNode *user;
+    const char *text;
+};
+
 static void
 part_helper(struct chanNode *cn, void *data)
 {
-    DelChannelUser(data, cn, false, 0);
+    struct part_desc *desc = data;
+    DelChannelUser(desc->user, cn, desc->text, false);
+}
+
+static CMD_FUNC(cmd_part)
+{
+    struct part_desc desc;
+
+    if (argc < 2)
+        return 0;
+    desc.user = GetUserH(origin);
+    if (!desc.user)
+        return 0;
+    desc.text = (argc > 2) ? argv[argc - 1] : NULL;
+    parse_foreach(argv[1], part_helper, NULL, NULL, NULL, &desc);
+    return 1;
 }
 
 void
@@ -717,8 +738,8 @@ generate_hostmask(struct userNode *user, int options)
         for (ii=cnt=0; hostname[ii]; ii++)
             if (hostname[ii] == '.')
                 cnt++;
-        if (cnt == 1) {
-            /* only a two-level domain name; leave hostname */
+        if (cnt == 0 || cnt == 1) {
+            /* only a one- or two-level domain name; leave hostname */
         } else if (cnt == 2) {
             for (ii=0; user->hostname[ii] != '.'; ii++) ;
             /* Add 3 to account for the *. and \0. */