added gnutls backend and moved backend code into new files
[ircu2.10.12-pk.git] / ircd / m_away.c
index 79127a30c8b9fba17d69fb975ca2759e8f9f73bd..ef440c19ab37a54009864dd76bdbbcf0cc5c897c 100644 (file)
  *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
  *                    non-NULL pointers.
  */
-#if 0
-/*
- * No need to include handlers.h here the signatures must match
- * and we don't need to force a rebuild of all the handlers everytime
- * we add a new one to the list. --Bleep
- */
-#include "handlers.h"
-#endif /* 0 */
+#include "config.h"
+
 #include "client.h"
 #include "ircd.h"
 #include "ircd_alloc.h"
+#include "ircd_log.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
 #include "msg.h"
@@ -98,7 +93,8 @@
 #include "s_user.h"
 #include "send.h"
 
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
+#include <string.h>
 
 /*
  * user_set_away - set user away state
@@ -129,14 +125,13 @@ static int user_set_away(struct User* user, char* message)
      */
     unsigned int len = strlen(message);
 
-    if (len > TOPICLEN) {
-      message[TOPICLEN] = '\0';
-      len = TOPICLEN;
+    if (len > AWAYLEN) {
+      message[AWAYLEN] = '\0';
+      len = AWAYLEN;
     }
     if (away)
-      away = (char*) MyRealloc(away, len + 1);
-    else
-      away = (char*) MyMalloc(len + 1);
+      MyFree(away);
+    away = (char*) MyMalloc(len + 1);
     assert(0 != away);
 
     user->away = away;
@@ -147,7 +142,7 @@ static int user_set_away(struct User* user, char* message)
 
 
 /*
- * m_away - generic message handler template
+ * m_away - generic message handler
  * - Added 14 Dec 1988 by jto.
  *
  * parv[0] = sender prefix
@@ -159,12 +154,15 @@ static int user_set_away(struct User* user, char* message)
 int m_away(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {
   char* away_message = parv[1];
+  int was_away = cli_user(sptr)->away != 0;
 
   assert(0 != cptr);
   assert(cptr == sptr);
 
-  if (user_set_away(cli_user(sptr), away_message)) {
-    sendcmdto_serv_butone(sptr, CMD_AWAY, cptr, ":%s", away_message);
+  if (user_set_away(cli_user(sptr), away_message))
+  {
+    if (!was_away)    
+      sendcmdto_serv_butone(sptr, CMD_AWAY, cptr, ":%s", away_message);
     send_reply(sptr, RPL_NOWAWAY);
   }
   else {
@@ -175,7 +173,7 @@ int m_away(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 }
 
 /*
- * ms_away - server message handler template
+ * ms_away - server message handler
  * - Added 14 Dec 1988 by jto.
  *
  * parv[0] = sender prefix