Debian Codegraph @

src/d2cs/d2charlist.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2004 ls_sons ([email protected])
3 * Copyright (C) 2004 Olaf Freyer ([email protected])
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 #include "d2charlist.h"
22
23 #include <cstring>
24
25 #include "compat/strcasecmp.h"
26 #include "compat/strncasecmp.h"
27 #include "common/eventlog.h"
28 #include "common/xalloc.h"
29 #include "prefs.h"
30 #include "common/setup_after.h"
31
32 namespace pvpgn
33 {
34
35 namespace d2cs
36 {
37
38 extern int d2charlist_add_char(t_elist * list_head, t_d2charinfo_file * charinfo, unsigned int expiration_time)
39 {
40 t_d2charlist * charlist, *ccharlist;
41 char const * d2char_sort;
42 t_elist * curr;
43
44 d2char_sort = prefs_get_charlist_sort();
45 charlist = (t_d2charlist*)xmalloc(sizeof(t_d2charlist));
46 charlist->charinfo = charinfo;
47 charlist->expiration_time = expiration_time;
48
49 if (elist_empty(list_head))
50 elist_add(list_head, &charlist->list);
51 else
52 {
53 if (strcasecmp(d2char_sort, "name") == 0)
54 {
55 elist_for_each(curr, list_head)
56 {
57 ccharlist = elist_entry(curr, t_d2charlist, list);
58 if (strncasecmp((char*)charinfo->header.charname, (char*)ccharlist->charinfo->header.charname, std::strlen((char*)charinfo->header.charname)) < 0)
59 break;
60 }
61 elist_add_tail(curr, &charlist->list);
62 }
63 else if (strcasecmp(d2char_sort, "ctime") == 0)
64 {
65 elist_for_each(curr, list_head)
66 {
67 ccharlist = elist_entry(curr, t_d2charlist, list);
68 if (bn_int_get(charinfo->header.create_time) < bn_int_get(ccharlist->charinfo->header.create_time))
69 break;
70 }
71 elist_add_tail(curr, &charlist->list);
72 }
73 else if (strcasecmp(d2char_sort, "mtime") == 0)
74 {
75 elist_for_each(curr, list_head)
76 {
77 ccharlist = elist_entry(curr, t_d2charlist, list);
78 if (bn_int_get(charinfo->header.last_time) < bn_int_get(ccharlist->charinfo->header.last_time))
79 break;
80 }
81 elist_add_tail(curr, &charlist->list);
82 }
83 else if (strcasecmp(d2char_sort, "level") == 0)
84 {
85 elist_for_each(curr, list_head)
86 {
87 ccharlist = elist_entry(curr, t_d2charlist, list);
88 if (bn_int_get(charinfo->summary.experience) < bn_int_get(ccharlist->charinfo->summary.experience))
89 break;
90 }
91 elist_add_tail(curr, &charlist->list);
92 }
93 else
94 {
95 eventlog(eventlog_level_debug, __FUNCTION__, "unsorted");
96 elist_add_tail(list_head, &charlist->list);
97 }
98 }
99 return 0;
100 }
101
102 }
103
104 }