added user invite timeout
authorpk910 <philipp@zoelle1.de>
Thu, 7 Jul 2011 11:24:14 +0000 (13:24 +0200)
committerpk910 <philipp@zoelle1.de>
Thu, 7 Jul 2011 11:28:27 +0000 (13:28 +0200)
src/chanserv.c
src/hash.c
src/hash.h

index 897790d7fa32152ca158fd9bc5e1ff357f9e1357..0a8faccdb31985fcc9dd72642960db8e8aac9254 100644 (file)
@@ -57,6 +57,7 @@
 #define KEY_NODELETE_LEVEL          "nodelete_level"
 #define KEY_MAX_USERINFO_LENGTH     "max_userinfo_length"
 #define KEY_GIVEOWNERSHIP_PERIOD    "giveownership_timeout"
+#define KEY_INVITED_INTERVAL           "invite_timeout"
 
 /* ChanServ database */
 #define KEY_CHANNELS                "channels"
@@ -499,6 +500,8 @@ static struct
     unsigned long   db_backup_frequency;
     unsigned long   channel_expire_frequency;
     unsigned long   dnr_expire_frequency;
+    
+    unsigned long   invited_timeout;
 
     unsigned long   info_delay;
     unsigned long   adjust_delay;
@@ -541,6 +544,12 @@ struct listData
     struct helpfile_table table;
 };
 
+struct ChanUser
+{
+       struct userNode *user;
+    struct chanNode *chan;
+};
+
 enum note_access_type
 {
     NOTE_SET_CHANNEL_ACCESS,
@@ -4286,10 +4295,28 @@ static CHANSERV_FUNC(cmd_mode)
     return 1;
 }
 
+static void
+chanserv_del_invite_mark(void *data)
+{
+       struct ChanUser *chanuser = data;
+       struct chanNode *channel = chanuser->chan;
+       unsigned int i;
+       if(!channel) return;
+       for(i = 0; i < channel->invited.used; i++)
+    {
+        if(channel->invited.list[i] == chanuser->user) {
+                       userList_remove(&channel->invited, chanuser->user);
+               }
+       }
+       free(chanuser);
+}
+
 static CHANSERV_FUNC(cmd_invite)
 {
     struct userData *uData;
     struct userNode *invite;
+    struct ChanUser *chanuser;
+    unsigned int i;
 
     uData = GetChannelUser(channel->channel_info, user->handle_info);
 
@@ -4309,6 +4336,14 @@ static CHANSERV_FUNC(cmd_invite)
         reply("CSMSG_ALREADY_PRESENT", invite->nick, channel->name);
         return 0;
     }
+    
+    for(i = 0; i < channel->invited.used; i++)
+    {
+        if(channel->invited.list[i] == invite) {
+            reply("CSMSG_ALREADY_INVITED", invite->nick, channel->name);
+            return 0;
+        }
+    }
 
     if(user != invite)
     {
@@ -4324,6 +4359,12 @@ static CHANSERV_FUNC(cmd_invite)
     if(argc > 1)
         reply("CSMSG_INVITED_USER", argv[1], channel->name);
 
+    userList_append(&channel->invited, invite);
+    chanuser = calloc(1, sizeof(*chanuser));
+    chanuser->user=invite;
+    chanuser->chan=channel;
+    timeq_add(now + chanserv_conf.invited_timeout, chanserv_del_invite_mark, chanuser);
+
     return 1;
 }
 
@@ -6492,6 +6533,13 @@ handle_join(struct modeNode *mNode)
     if(channel->members.used > cData->max)
         cData->max = channel->members.used;
 
+    for(i = 0; i < channel->invited.used; i++)
+    {
+        if(channel->invited.list[i] == user) {
+            userList_remove(&channel->invited, user);
+        }
+    }
+
     /* Check for bans.  If they're joining through a ban, one of two
      * cases applies:
      *   1: Join during a netburst, by riding the break.  Kick them
@@ -7056,6 +7104,8 @@ chanserv_conf_read(void)
     chanserv_conf.channel_expire_delay = str ? ParseInterval(str) : 86400*30;
     str = database_get_data(conf_node, KEY_DNR_EXPIRE_FREQ, RECDB_QSTRING);
     chanserv_conf.dnr_expire_frequency = str ? ParseInterval(str) : 3600;
+    str = database_get_data(conf_node, KEY_INVITED_INTERVAL, RECDB_QSTRING);
+    chanserv_conf.invited_timeout = str ? ParseInterval(str) : 600*2;
     str = database_get_data(conf_node, KEY_NODELETE_LEVEL, RECDB_QSTRING);
     chanserv_conf.nodelete_level = str ? atoi(str) : 1;
     str = database_get_data(conf_node, KEY_MAX_CHAN_USERS, RECDB_QSTRING);
index c214cffcfee5a346bfe59466779115705b5f8886..eb2d54acfa07f608eb5e9ea8d88c8bb78c0e2b14 100644 (file)
@@ -382,6 +382,7 @@ AddChannel(const char *name, unsigned long time_, const char *modes, char *banli
         strcpy(cNode->name, name);
         banList_init(&cNode->banlist);
         modeList_init(&cNode->members);
+        userList_init(&cNode->invited);
         mod_chanmode(NULL, cNode, argv, nn, MCP_FROM_SERVER);
         dict_insert(channels, cNode->name, cNode);
         cNode->timestamp = time_;
@@ -469,6 +470,7 @@ DelChannel(struct chanNode *channel)
 
     modeList_clean(&channel->members);
     banList_clean(&channel->banlist);
+    userList_clean(&channel->invited);
     free(channel);
 }
 
index 8d3cb211914f21180b0c8a93a9672245bc260e5e..582561fd5f37292638933ae3fc0595ed096b07ea 100644 (file)
@@ -144,6 +144,7 @@ struct chanNode {
     struct modeList members;
     struct banList banlist;
     struct policer join_policer;
+    struct userList invited;
     unsigned int join_flooded : 1;
     unsigned int bad_channel : 1;