| 1 |
/*
|
| 2 |
* Copyright (C) 2004 ls_sons (ls@gamelife.org)
|
| 3 |
* Copyright (C) 2004 Olaf Freyer (aaron@cs.tu-berlin.de)
|
| 4 |
*
|
| 5 |
* This program is free software; you can redistribute it and/or
|
| 6 |
* modify it under the terms of the GNU General Public License
|
| 7 |
* as published by the Free Software Foundation; either version 2
|
| 8 |
* of the License, or (at your option) any later version.
|
| 9 |
*
|
| 10 |
* This program is distributed in the hope that it will be useful,
|
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
* GNU General Public License for more details.
|
| 14 |
*
|
| 15 |
* You should have received a copy of the GNU General Public License
|
| 16 |
* along with this program; if not, write to the Free Software
|
| 17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 18 |
*/
|
| 19 |
#include "common/setup_before.h"
|
| 20 |
#include "setup.h"
|
| 21 |
|
| 22 |
#ifdef HAVE_STRING_H
|
| 23 |
# include <string.h>
|
| 24 |
#else
|
| 25 |
# ifdef HAVE_STRINGS_H
|
| 26 |
# include <strings.h>
|
| 27 |
# endif
|
| 28 |
# ifdef HAVE_MEMORY_H
|
| 29 |
# include <memory.h>
|
| 30 |
# endif
|
| 31 |
#endif
|
| 32 |
#ifdef STDC_HEADERS
|
| 33 |
# include <stdlib.h>
|
| 34 |
#else
|
| 35 |
# ifdef HAVE_MALLOC_H
|
| 36 |
# include <malloc.h>
|
| 37 |
# endif
|
| 38 |
#endif
|
| 39 |
|
| 40 |
#include "connection.h"
|
| 41 |
#include "prefs.h"
|
| 42 |
#include "common/eventlog.h"
|
| 43 |
#include "compat/strcasecmp.h"
|
| 44 |
#include "compat/strncasecmp.h"
|
| 45 |
#include "compat/strdup.h"
|
| 46 |
#include "common/xalloc.h"
|
| 47 |
#include "common/elist.h"
|
| 48 |
#include "d2charlist.h"
|
| 49 |
#include "common/setup_after.h"
|
| 50 |
|
| 51 |
extern int d2charlist_add_char(t_elist * list_head, t_d2charinfo_file * charinfo, unsigned int expiration_time)
|
| 52 |
{
|
| 53 |
t_d2charlist * charlist, * ccharlist;
|
| 54 |
char const * d2char_sort;
|
| 55 |
t_elist * curr;
|
| 56 |
|
| 57 |
d2char_sort = prefs_get_charlist_sort();
|
| 58 |
charlist = xmalloc(sizeof(t_d2charlist));
|
| 59 |
charlist->charinfo = charinfo;
|
| 60 |
charlist->expiration_time = expiration_time;
|
| 61 |
|
| 62 |
if (elist_empty(list_head))
|
| 63 |
elist_add(list_head,&charlist->list);
|
| 64 |
else
|
| 65 |
{
|
| 66 |
if (strcasecmp(d2char_sort, "name")==0)
|
| 67 |
{
|
| 68 |
elist_for_each(curr,list_head)
|
| 69 |
{
|
| 70 |
ccharlist = elist_entry(curr,t_d2charlist,list);
|
| 71 |
if (strncasecmp(charinfo->header.charname,ccharlist->charinfo->header.charname,strlen(charinfo->header.charname))<0)
|
| 72 |
break;
|
| 73 |
}
|
| 74 |
elist_add_tail(curr,&charlist->list);
|
| 75 |
}
|
| 76 |
else if (strcasecmp(d2char_sort, "mtime")==0)
|
| 77 |
{
|
| 78 |
elist_for_each(curr,list_head)
|
| 79 |
{
|
| 80 |
ccharlist = elist_entry(curr,t_d2charlist,list);
|
| 81 |
if (bn_int_get(charinfo->header.last_time) < bn_int_get(ccharlist->charinfo->header.last_time))
|
| 82 |
break;
|
| 83 |
}
|
| 84 |
elist_add_tail(curr,&charlist->list);
|
| 85 |
}
|
| 86 |
else if (strcasecmp(d2char_sort, "level")==0)
|
| 87 |
{
|
| 88 |
elist_for_each(curr,list_head)
|
| 89 |
{
|
| 90 |
ccharlist = elist_entry(curr,t_d2charlist,list);
|
| 91 |
if (bn_int_get(charinfo->summary.experience) < bn_int_get(ccharlist->charinfo->summary.experience))
|
| 92 |
break;
|
| 93 |
}
|
| 94 |
elist_add_tail(curr,&charlist->list);
|
| 95 |
}
|
| 96 |
else
|
| 97 |
{
|
| 98 |
eventlog(eventlog_level_debug,__FUNCTION__,"unsorted");
|
| 99 |
elist_add_tail(list_head,&charlist->list);
|
| 100 |
}
|
| 101 |
}
|
| 102 |
return 0;
|
| 103 |
}
|
| 104 |
|