Fix bug #44 - [Request] IP log in the memory
This commit is contained in:
@@ -141,7 +141,7 @@ const char* command_get_syntax(struct commands_handler* handler)
|
||||
case 'n': strcat(args, "<nick>"); break;
|
||||
case 'c': strcat(args, "<cid>"); break;
|
||||
case 'a': strcat(args, "<addr>"); break;
|
||||
case 'M': strcat(args, "<message>"); break;
|
||||
case 'm': strcat(args, "<message>"); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -384,6 +384,11 @@ static int command_history(struct hub_info* hub, struct hub_user* user, struct h
|
||||
}
|
||||
|
||||
buffer = hub_malloc(bufsize+4);
|
||||
if (!buffer)
|
||||
{
|
||||
return command_status(hub, user, cmd, "Not enough memory.");
|
||||
}
|
||||
|
||||
buffer[0] = 0;
|
||||
strcat(buffer, tmp);
|
||||
strcat(buffer, "\n");
|
||||
@@ -401,6 +406,43 @@ static int command_history(struct hub_info* hub, struct hub_user* user, struct h
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int command_log(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd)
|
||||
{
|
||||
char* buffer;
|
||||
struct linked_list* messages = hub->logout_info;
|
||||
struct hub_logout_info* log;
|
||||
int ret = 0;
|
||||
char tmp[1024];
|
||||
|
||||
if (!list_size(messages))
|
||||
{
|
||||
return command_status(hub, user, cmd, "No entries logged.");
|
||||
}
|
||||
|
||||
buffer = hub_malloc(32 + (list_size(messages) * (sizeof(struct hub_logout_info) + 25)));
|
||||
if (!buffer)
|
||||
{
|
||||
return command_status(hub, user, cmd, "Not enough memory.");
|
||||
}
|
||||
|
||||
buffer[0] = 0;
|
||||
strcat(buffer, "Log entries");
|
||||
strcat(buffer, "\n");
|
||||
|
||||
log = (struct hub_logout_info*) list_get_first(messages);
|
||||
while (log)
|
||||
{
|
||||
sprintf(tmp, "%s %s, %s (%s)\n", get_timestamp(log->time), log->cid, log->nick, ip_convert_to_string(&log->addr));
|
||||
strcat(buffer, tmp);
|
||||
log = (struct hub_logout_info*) list_get_next(messages);
|
||||
}
|
||||
strcat(buffer, "\n");
|
||||
|
||||
ret = command_status(hub, user, cmd, buffer);
|
||||
hub_free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CRASH_DEBUG
|
||||
static int command_crash(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd)
|
||||
{
|
||||
@@ -468,7 +510,8 @@ static struct commands_handler command_handlers[] = {
|
||||
{ "myip", 4, 0, cred_guest, command_myip, "Show your own IP." },
|
||||
{ "getip", 5, "n", cred_operator, command_getip, "Show IP address for a user" },
|
||||
{ "whoip", 5, "a", cred_operator, command_whoip, "Show users matching IP range" },
|
||||
{ "broadcast", 9, "M", cred_operator, command_broadcast,"Send a message to all users" },
|
||||
{ "broadcast", 9, "m", cred_operator, command_broadcast,"Send a message to all users" },
|
||||
{ "log", 3, 0, cred_operator, command_log, "Display log" },
|
||||
#ifdef CRASH_DEBUG
|
||||
{ "crash", 5, 0, cred_admin, command_crash, "Crash the hub (DEBUG)." },
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user