+static MODCMD_FUNC(cmd_authlog)
+{
+ struct handle_info *hi = user->handle_info;
+ struct helpfile_table tbl;
+ struct authlogEntry *authlog;
+ int i = 0;
+
+ for(authlog = hi->authlog; authlog; authlog = authlog->next) {
+ i++;
+ }
+
+ tbl.length = i+1;
+ tbl.width = 4;
+ tbl.flags = 0;
+ tbl.flags = TABLE_NO_FREE;
+ tbl.contents = malloc(tbl.length * sizeof(tbl.contents[0]));
+ tbl.contents[0] = malloc(tbl.width * sizeof(tbl.contents[0][0]));
+ tbl.contents[0][0] = "Hostmask";
+ tbl.contents[0][1] = "Login";
+ tbl.contents[0][2] = "Logout";
+ tbl.contents[0][3] = "Quit Reason";
+
+ if(!tbl.length) {
+ table_send(cmd->parent->bot, user->nick, 0, NULL, tbl);
+ reply("MSG_NONE");
+ free(tbl.contents[0]);
+ free(tbl.contents);
+ return 0;
+ }
+
+ char *str, *ptr;
+ char intervalBuf[INTERVALLEN];
+ i = 0;
+ for(authlog = hi->authlog; authlog; authlog = authlog->next) {
+ tbl.contents[++i] = malloc(tbl.width * sizeof(tbl.contents[0][0]));
+ tbl.contents[i][0] = authlog->hostmask;
+ str = intervalString(intervalBuf, now - authlog->login_time, hi);
+ ptr = malloc(strlen(str)+1);
+ strcpy(ptr, str);
+ tbl.contents[i][1] = ptr;
+ if(authlog->logout_time)
+ str = intervalString(intervalBuf, now - authlog->logout_time, hi);
+ else
+ str = (authlog->user ? "Never" : "Unknown");
+ ptr = malloc(strlen(str)+1);
+ strcpy(ptr, str);
+ tbl.contents[i][2] = ptr;
+ tbl.contents[i][3] = (authlog->quit_reason ? authlog->quit_reason : "-");
+ }
+
+ table_send(cmd->parent->bot, user->nick, 0, NULL, tbl);
+ for(i = 1; i < tbl.length; ++i)
+ {
+ free((char *) tbl.contents[i][1]);
+ free((char *) tbl.contents[i][2]);
+ free(tbl.contents[i]);
+ }
+ free(tbl.contents[0]);
+ free(tbl.contents);
+
+ return 0;
+}
+