0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 00:32:35 +01:00

Speed up /unresv. Rehash bans now only happens if explicitly requested.

This commit is contained in:
Jilles Tjoelker 2007-11-30 23:35:48 +01:00
parent 60c96e64c1
commit 1328da8618

View file

@ -67,7 +67,7 @@ static void cluster_resv(struct Client *source_p, int temp_time,
static void handle_remote_unresv(struct Client *source_p, const char *name); static void handle_remote_unresv(struct Client *source_p, const char *name);
static void remove_resv(struct Client *source_p, const char *name); static void remove_resv(struct Client *source_p, const char *name);
static int remove_temp_resv(struct Client *source_p, const char *name); static int remove_resv_from_file(struct Client *source_p, const char *name);
/* /*
* mo_resv() * mo_resv()
@ -389,9 +389,6 @@ mo_unresv(struct Client *client_p, struct Client *source_p, int parc, const char
cluster_generic(source_p, "UNRESV", SHARED_UNRESV, CAP_CLUSTER, cluster_generic(source_p, "UNRESV", SHARED_UNRESV, CAP_CLUSTER,
"%s", parv[1]); "%s", parv[1]);
if(remove_temp_resv(source_p, parv[1]))
return 0;
remove_resv(source_p, parv[1]); remove_resv(source_p, parv[1]);
return 0; return 0;
} }
@ -438,30 +435,38 @@ handle_remote_unresv(struct Client *source_p, const char *name)
source_p->servptr->name, SHARED_UNRESV)) source_p->servptr->name, SHARED_UNRESV))
return; return;
if(remove_temp_resv(source_p, name))
return;
remove_resv(source_p, name); remove_resv(source_p, name);
return; return;
} }
static int static void
remove_temp_resv(struct Client *source_p, const char *name) remove_resv(struct Client *source_p, const char *name)
{ {
struct ConfItem *aconf = NULL; struct ConfItem *aconf = NULL;
if(IsChannelName(name)) if(IsChannelName(name))
{ {
if((aconf = hash_find_resv(name)) == NULL) if((aconf = hash_find_resv(name)) == NULL)
return 0; {
sendto_one_notice(source_p, ":No RESV for %s", name);
return;
}
/* its permanent, let remove_resv do it properly */
if(!aconf->hold) if(!aconf->hold)
return 0; {
if (!remove_resv_from_file(source_p, name))
return;
}
else
{
sendto_one_notice(source_p, ":RESV for [%s] is removed", name);
sendto_realops_snomask(SNO_GENERAL, L_ALL,
"%s has removed the RESV for: [%s]",
get_oper_name(source_p), name);
ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name);
}
del_from_resv_hash(name, aconf); del_from_resv_hash(name, aconf);
free_conf(aconf);
} }
else else
{ {
@ -478,35 +483,42 @@ remove_temp_resv(struct Client *source_p, const char *name)
} }
if(aconf == NULL) if(aconf == NULL)
return 0; {
sendto_one_notice(source_p, ":No RESV for %s", name);
return;
}
/* permanent, remove_resv() needs to do it properly */
if(!aconf->hold) if(!aconf->hold)
return 0; {
if (!remove_resv_from_file(source_p, name))
return;
}
else
{
sendto_one_notice(source_p, ":RESV for [%s] is removed", name);
sendto_realops_snomask(SNO_GENERAL, L_ALL,
"%s has removed the RESV for: [%s]",
get_oper_name(source_p), name);
ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name);
}
/* already have ptr from the loop above.. */ /* already have ptr from the loop above.. */
dlinkDestroy(ptr, &resv_conf_list); dlinkDestroy(ptr, &resv_conf_list);
free_conf(aconf);
} }
free_conf(aconf);
sendto_one_notice(source_p, ":RESV for [%s] is removed", name); return;
sendto_realops_snomask(SNO_GENERAL, L_ALL,
"%s has removed the RESV for: [%s]",
get_oper_name(source_p), name);
ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name);
return 1;
} }
/* remove_resv() /* remove_resv_from_file()
* *
* inputs - client removing the resv * inputs - client removing the resv
* - resv to remove * - resv to remove
* outputs - * outputs -
* side effects - resv if found, is removed * side effects - resv if found, is removed from conf
* - does not touch resv hash or resv_conf_list
*/ */
static void static int
remove_resv(struct Client *source_p, const char *name) remove_resv_from_file(struct Client *source_p, const char *name)
{ {
FILE *in, *out; FILE *in, *out;
char buf[BUFSIZE]; char buf[BUFSIZE];
@ -524,7 +536,7 @@ remove_resv(struct Client *source_p, const char *name)
if((in = fopen(filename, "r")) == NULL) if((in = fopen(filename, "r")) == NULL)
{ {
sendto_one_notice(source_p, ":Cannot open %s", filename); sendto_one_notice(source_p, ":Cannot open %s", filename);
return; return 0;
} }
oldumask = umask(0); oldumask = umask(0);
@ -534,7 +546,7 @@ remove_resv(struct Client *source_p, const char *name)
sendto_one_notice(source_p, ":Cannot open %s", temppath); sendto_one_notice(source_p, ":Cannot open %s", temppath);
fclose(in); fclose(in);
umask(oldumask); umask(oldumask);
return; return 0;
} }
umask(oldumask); umask(oldumask);
@ -585,27 +597,28 @@ remove_resv(struct Client *source_p, const char *name)
if(error_on_write) if(error_on_write)
{ {
sendto_one_notice(source_p, ":Couldn't write temp resv file, aborted"); sendto_one_notice(source_p, ":Couldn't write temp resv file, aborted");
return; return 0;
} }
else if(!found_resv) else if(!found_resv)
{ {
sendto_one_notice(source_p, ":No RESV for %s", name); sendto_one_notice(source_p, ":Cannot find RESV for %s in file", name);
if(temppath != NULL) if(temppath != NULL)
(void) unlink(temppath); (void) unlink(temppath);
return; return 0;
} }
if (rename(temppath, filename)) if (rename(temppath, filename))
{ {
sendto_one_notice(source_p, ":Couldn't rename temp file, aborted"); sendto_one_notice(source_p, ":Couldn't rename temp file, aborted");
return; return 0;
} }
rehash_bans(0);
sendto_one_notice(source_p, ":RESV for [%s] is removed", name); sendto_one_notice(source_p, ":RESV for [%s] is removed", name);
sendto_realops_snomask(SNO_GENERAL, L_ALL, sendto_realops_snomask(SNO_GENERAL, L_ALL,
"%s has removed the RESV for: [%s]", get_oper_name(source_p), name); "%s has removed the RESV for: [%s]", get_oper_name(source_p), name);
ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name); ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name);
return 1;
} }