+static void
+chanserv_expire_channel(void *data)
+{
+ struct chanData *channel = data;
+ char reason[MAXLEN];
+ sprintf(reason, "channel expired.");
+ channel->expiry = 0;
+ spamserv_cs_unregister(NULL, channel->channel, expire, NULL);
+ unregister_channel(channel, reason);
+}
+
+static MODCMD_FUNC(chan_opt_expire)
+{
+ struct chanData *cData = channel->channel_info;
+ unsigned long value = cData->expiry;
+
+ if(argc > 1)
+ {
+ if((!IsOper(user) || !user->handle_info || (user->handle_info->opserv_level < chanserv_conf.nodelete_level)))
+ {
+ reply("MSG_SETTING_PRIVILEGED", argv[0]);
+ return 0;
+ }
+ unsigned long expiry,duration;
+
+ /* The two directions can have different ACLs. */
+ if(!strcmp(argv[1], "0"))
+ expiry = 0;
+ else if((duration = ParseInterval(argv[1])))
+ expiry = now + duration;
+ else
+ {
+ reply("MSG_INVALID_DURATION", argv[1]);
+ return 0;
+ }
+
+ if (expiry != value)
+ {
+ if(value) {
+ //unset old timer
+ timeq_del(value, chanserv_expire_channel, cData, 0);
+ }
+ value = expiry;
+ cData->expiry = value;
+ if(value > 0) {
+ //New timer!
+ timeq_add(expiry, chanserv_expire_channel, cData);
+ }
+ }
+ }
+
+ if(cData->expiry > now) {
+ char expirestr[INTERVALLEN];
+ reply("CSMSG_SET_EXPIRE", intervalString(expirestr, cData->expiry - now, user->handle_info));
+ } else
+ reply("CSMSG_SET_EXPIRE_OFF");
+ return 1;
+}
+