|
Who level sorting [by George] |
|
|
|
Posted Wednesday, August 12th @ 11:39:11 PM, by George Greer in the Utils dept.
Added Jun 23, 1997. Click the link below to read it or download it.
From: George <greerga@miavx1.acs.muohio.edu>
Subject: Sorted do_who
The basic idea is to add to a linked list only when it finds the current
person is higher level then the lower person on the chain.
--------------------------------------------------------------------------
Add somewhere:
struct who_list {
char *name;
int level;
struct who_list *next;
};
--------------------------------------------------------------------------
in do_who:
Add to definitions:
struct who_list *who_head = NULL;
Near bottom replace:
send_to_char(buf, ch);
with:
who_head = add_to_who(who_head, buf, tch);
(at the place where the sprintf'd string is sent to the user per pc)
Also insert:
if (short_list && (num_can_see % 4))
send_to_char("\r\n", ch);
> if (who_head)
> output_who(who_head, ch);
if (num_can_see == 0)
sprintf(buf, "\r\nNo-one at all!\r\n");
--------------------------------------------------------------------------
Add anywhere:
struct who_list *add_to_who(struct who_list *head, char *str,
struct char_data *ch)
{
struct who_list *tmp, *prev = NULL, *to_add = NULL;
if (str && ch) {
CREATE(to_add, struct who_list, 1);
to_add->name = str_dup(str);
to_add->level = GET_LEVEL(ch);
to_add->next = NULL;
} else {
log("SYSERR: NULL str or ch in add_to_who");
return NULL;
}
if (!head)
return to_add;
for (tmp = head; tmp; tmp = tmp->next) {
if (to_add->level > tmp->level) { /* ok, add record */
if (prev)
prev->next = to_add;
if (head == tmp)
head = to_add;
to_add->next = tmp;
return head;
}
prev = tmp;
}
prev->next = to_add;
return head;
}
void output_who(struct who_list *head, struct char_data *ch)
{
struct who_list *tmp, *next;
if (!head) {
log("SYSERR: output_who: hey, no head?");
return;
}
for (tmp = head; tmp; tmp = next) {
next = tmp->next;
send_to_char(tmp->name, ch);
if (!tmp || !tmp->name)
log("SYSERR: output_who: trying to free invalid tmp->name");
else {
free(tmp->name);
}
if (!tmp)
log("SYSERR: output_who: trying to free invalid tmp struct");
else {
free(tmp);
}
}
}
That should be everything...I've murdered my do_who with additions.
<< Whois command [by Primacy] | Reply | View as text | Threaded | Who level sorting (QSort) [by Jorgen Sigvardsson] >> |
|
Related Links |
|
|
|
CircleMUD Snippets |
|
|
Note: Not all of these snippets will work perfectly with
your version of code, so be prepared to fix one
or two bugs that may arise, and please let me know
what you needed to do to fix it. Sending a corrected
version is always welcome.
|
Finally, if you wish to use any of the snippets from this
page, you are more than welcome, just mention the
authors in your credits. If you wish to release any
of these snippets to the public on another site,
contact me FIRST.
|
|
|
|
|
|
|