+static HELPSERV_USERCMD(usercmd_close) {
+ struct helpserv_request *newest=NULL;
+ struct helpserv_reqlist *nick_list, *hand_list;
+ char close_reason[MAXLEN], reqnum[12];
+ struct userNode *req_user=NULL;
+ unsigned long old_req;
+ unsigned int i;
+ int num_requests=0, from_opserv=0;
+
+ REQUIRE_PARMS(1);
+
+ sprintf(reqnum, "%lu", req->id);
+
+ if (num_requests > 1) {
+ helpserv_notice(user, "HSMSG_REQ_FOUNDMANY");
+ return 0;
+ }
+
+ helpserv_notice(user, "HSMSG_REQ_CLOSED", req->id);
+
+ if (req->user) {
+ req_user = req->user;
+ helpserv_message(hs, req->user, MSGTYPE_REQ_CLOSED);
+ if (req->handle)
+ helpserv_page(PGSRC_STATUS, "HSMSG_PAGE_CLOSE_REQUEST_1", req->id, req->user->nick, req->handle->handle, user->nick);
+ else
+ helpserv_page(PGSRC_STATUS, "HSMSG_PAGE_CLOSE_REQUEST_2", req->id, req->user->nick, user->nick);
+ } else {
+ if (req->handle)
+ helpserv_page(PGSRC_STATUS, "HSMSG_PAGE_CLOSE_REQUEST_3", req->id, req->handle->handle, user->nick);
+ else
+ helpserv_page(PGSRC_STATUS, "HSMSG_PAGE_CLOSE_REQUEST_4", req->id, user->nick);
+ }
+
+ /* Set these to keep track of the lists after the request is gone, but
+ * not if free_request() will helpserv_reqlist_free() them. */
+ nick_list = req->parent_nick_list;
+ if (nick_list && (nick_list->used == 1))
+ nick_list = NULL;
+ hand_list = req->parent_hand_list;
+ if (hand_list && (hand_list->used == 1))
+ hand_list = NULL;
+ old_req = req->id;
+
+ if (argc >= 1) {
+ if (user->handle_info)
+ snprintf(close_reason, MAXLEN, "Closed by %s: %s", user->handle_info->handle, unsplit_string(argv+1, argc-1, NULL));
+ else
+ snprintf(close_reason, MAXLEN, "Closed by %s: %s", user->nick, unsplit_string(argv+1, argc-1, NULL));
+ } else {
+ if (user->handle_info)
+ sprintf(close_reason, "Closed by %s", user->nick);
+ else
+ sprintf(close_reason, "Closed by %s", user->handle_info->handle);
+ }
+ helpserv_log_request(req, close_reason);
+ dict_remove(hs->requests, reqnum);
+
+ /* Look for other requests associated with them */
+ if (nick_list) {
+ for (i=0; i < nick_list->used; i++) {
+ req = nick_list->list[i];
+
+ if (req->hs != hs)
+ continue;
+ if (!newest || (newest->opened < req->opened))
+ newest = req;
+ }
+
+ if (newest)
+ helpserv_msguser(newest->user, "HSMSG_REQ_FOUND_ANOTHER", old_req, newest->id);
+ }
+
+ if (req_user && hs->auto_devoice) {
+ struct modeNode *mn = GetUserMode(hs->helpchan, req_user);
+ if ((!newest || !newest->helper) && mn && (mn->modes & MODE_VOICE)) {
+ struct mod_chanmode change;
+ mod_chanmode_init(&change);
+ change.argc = 1;
+ change.args[0].mode = MODE_REMOVE | MODE_VOICE;
+ change.args[0].u.member = mn;
+ mod_chanmode_announce(hs->helpserv, hs->helpchan, &change);
+ }
+ }
+
+ return 0;
+}
+