Debian Codegraph @

src/d2dbs/charlock.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2001 faster ([email protected])
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/
19 #include "setup.h"cxx . . $ `<file>/src/d2dbs/setup.h`/
20 #include "charlock.h"cxx . . $ `<file>/src/d2dbs/charlock.h`/
21
22 #include <limits>
23 #include <cstring>
24 #include <cctype>
25
26 #include "compat/strcasecmp.h"cxx . . $ `<file>/src/compat/strcasecmp.h`/
27 #include "common/xalloc.h"cxx . . $ `<file>/src/common/xalloc.h`/
28 #include "common/introtate.h"cxx . . $ `<file>/src/common/introtate.h`/
29 #include "common/xstring.h"cxx . . $ `<file>/src/common/xstring.h`/
30 #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/
31
32 namespace pvpgncxx . . $ pvpgn/
33 {
34
35 namespace d2dbscxx . . $ pvpgn/d2dbs/
36 {
37
38 /* FIXME: for simplification, no multiple realm support now */
39
40 /* local functions */
41 static int cl_insert_to_gsq_listcxx . . $ pvpgn/d2dbs/cl_insert_to_gsq_list(ff8101443120eb92).(unsigned int gsid, t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo# *pcl);
42 static int cl_delete_from_gsq_listcxx . . $ pvpgn/d2dbs/cl_delete_from_gsq_list(845c1249eef1b6dd).(t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo# *pcl);
43 static unsigned int string_hashcxx . . $ pvpgn/d2dbs/string_hash(c61c63047ce273de).(char const *string);
44
45
46 /* variables */
47 static unsigned int clitbl_lencxx . . $ pvpgn/d2dbs/clitbl_len. = 0;
48 static unsigned int gsqtbl_lencxx . . $ pvpgn/d2dbs/gsqtbl_len. = 0;
49 static t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo# * * clitblcxx . . $ pvpgn/d2dbs/clitbl. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
50 static t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo# * * gsqtblcxx . . $ pvpgn/d2dbs/gsqtbl. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
51
52
53 int cl_initcxx . . $ pvpgn/d2dbs/cl_init(21cb2064190e2a90).(unsigned int tbllen, unsigned int maxgs)
54 {
55 if (!tbllen || !maxgs) return -1;
56 cl_destroycxx . . $ pvpgn/d2dbs/cl_destroy(b126dc7c1de90089).();
57
58 clitblcxx . . $ pvpgn/d2dbs/clitbl. = (t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo#**)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(tbllen*sizeof(t_charlockinfo**));
59 gsqtblcxx . . $ pvpgn/d2dbs/gsqtbl. = (t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo#**)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(maxgs*sizeof(t_charlockinfo**));
60 stdcxx . . $ std/::memset(clitblcxx . . $ pvpgn/d2dbs/clitbl., 0, tbllen*sizeof(t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo#**));
61 stdcxx . . $ std/::memset(gsqtblcxx . . $ pvpgn/d2dbs/gsqtbl., 0, maxgs*sizeof(t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo#**));
62 clitbl_lencxx . . $ pvpgn/d2dbs/clitbl_len. = tbllen;
63 gsqtbl_lencxx . . $ pvpgn/d2dbs/gsqtbl_len. = maxgs;
64 return 0;
65 }
66
67
68 int cl_destroycxx . . $ pvpgn/d2dbs/cl_destroy(b126dc7c1de90089).(void)
69 {
70 unsigned int i;
71 t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo# * ptl, *ptmp;
72
73 if (clitblcxx . . $ pvpgn/d2dbs/clitbl.) {
74 for (i = 0; i < clitbl_lencxx . . $ pvpgn/d2dbs/clitbl_len.; i++) {
75 ptl = clitblcxx . . $ pvpgn/d2dbs/clitbl.[i];
76 while (ptl) {
77 ptmp = ptl;
78 ptl = ptl->nextcxx . . $ pvpgn/d2dbs/raw_charlockinfo#next.;
79 xfreecxx . . $ `src/common/xalloc.h:51:9`!(ptmp);
80 }
81 }
82 xfreecxx . . $ `src/common/xalloc.h:51:9`!(clitbl);
83 }
84 if (gsqtblcxx . . $ pvpgn/d2dbs/gsqtbl.) xfreecxx . . $ `src/common/xalloc.h:51:9`!(gsqtbl);
85 clitblcxx . . $ pvpgn/d2dbs/clitbl. = gsqtblcxx . . $ pvpgn/d2dbs/gsqtbl. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
86 clitbl_lencxx . . $ pvpgn/d2dbs/clitbl_len. = gsqtbl_lencxx . . $ pvpgn/d2dbs/gsqtbl_len. = 0;
87 return 0;
88 }
89
90
91 int cl_query_charlock_statuscxx . . $ pvpgn/d2dbs/cl_query_charlock_status(4831365868175e25).(unsigned char *charname,
92 unsigned char *realmname, unsigned int *gsid)
93 {
94 t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo# *pcl;
95 unsigned int hashval;
96
97 if (!charname || !realmname) return -1;
98 if (!clitbl_lencxx . . $ pvpgn/d2dbs/clitbl_len. || !gsqtblcxx . . $ pvpgn/d2dbs/gsqtbl.) return -1;
99 if (stdcxx . . $ std/::strlen((char*)charname) >= MAX_CHARNAME_LENcxx . . $ MAX_CHARNAME_LEN.) return -1;
100
101 hashval = string_hashcxx . . $ pvpgn/d2dbs/string_hash(c61c63047ce273de).((char*)charname) % clitbl_lencxx . . $ pvpgn/d2dbs/clitbl_len.;
102 pcl = clitblcxx . . $ pvpgn/d2dbs/clitbl.[hashval];
103 while (pcl)
104 {
105 if (strcasecmp((char*)pcl->charnamecxx . . $ pvpgn/d2dbs/raw_charlockinfo#charname., (char*)charname) == 0) {
106 *gsid = pcl->gsidcxx . . $ pvpgn/d2dbs/raw_charlockinfo#gsid.;
107 return 1; /* found the char, it is locked */
108 }
109 pcl = pcl->nextcxx . . $ pvpgn/d2dbs/raw_charlockinfo#next.;
110 }
111 return 0; /* not found, it is unlocked */
112 }
113
114
115 int cl_lock_charcxx . . $ pvpgn/d2dbs/cl_lock_char(35b1a3e46acdbfa7).(unsigned char *charname,
116 unsigned char *realmname, unsigned int gsid)
117 {
118 t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo# *pcl, *ptmp;
119 unsigned int hashval;
120
121 if (!charname || !realmname) return -1;
122 if (!clitbl_lencxx . . $ pvpgn/d2dbs/clitbl_len. || !gsqtblcxx . . $ pvpgn/d2dbs/gsqtbl.) return -1;
123 if (stdcxx . . $ std/::strlen((char*)charname) >= MAX_CHARNAME_LENcxx . . $ MAX_CHARNAME_LEN.) return -1;
124
125 hashval = string_hashcxx . . $ pvpgn/d2dbs/string_hash(c61c63047ce273de).((char*)charname) % clitbl_lencxx . . $ pvpgn/d2dbs/clitbl_len.;
126 pcl = clitblcxx . . $ pvpgn/d2dbs/clitbl.[hashval];
127 ptmp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
128 while (pcl)
129 {
130 if (strcasecmp((char*)pcl->charnamecxx . . $ pvpgn/d2dbs/raw_charlockinfo#charname., (char*)charname) == 0)
131 return 0; /* found the char is already locked */
132 ptmp = pcl;
133 pcl = pcl->nextcxx . . $ pvpgn/d2dbs/raw_charlockinfo#next.;
134 }
135
136 /* not found, locked it */
137 pcl = (t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo#*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(sizeof(t_charlockinfo));
138 stdcxx . . $ std/::memset(pcl, 0, sizeof(t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo#));
139 stdcxx . . $ std/::strncpy((char*)pcl->charnamecxx . . $ pvpgn/d2dbs/raw_charlockinfo#charname., (char*)charname, MAX_CHARNAME_LENcxx . . $ MAX_CHARNAME_LEN. - 1);
140 stdcxx . . $ std/::strncpy((char*)pcl->realmnamecxx . . $ pvpgn/d2dbs/raw_charlockinfo#realmname., (char*)realmname, MAX_REALMNAME_LENcxx . . $ MAX_REALMNAME_LEN. - 1);
141 pcl->gsidcxx . . $ pvpgn/d2dbs/raw_charlockinfo#gsid. = gsid;
142
143 /* add to hash table link list */
144 if (ptmp) ptmp->nextcxx . . $ pvpgn/d2dbs/raw_charlockinfo#next. = pcl;
145 else clitblcxx . . $ pvpgn/d2dbs/clitbl.[hashval] = pcl;
146 /* add to gs specified link list */
147 cl_insert_to_gsq_listcxx . . $ pvpgn/d2dbs/cl_insert_to_gsq_list(ff8101443120eb92).(gsid, pcl);
148
149 return 0;
150 }
151
152
153 int cl_unlock_charcxx . . $ pvpgn/d2dbs/cl_unlock_char(35b1a3e46acdbfa7).(unsigned char *charname, unsigned char *realmname, unsigned int gsid)
154 {
155 t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo# *pcl, *ptmp;
156 unsigned int hashval;
157
158 if (!charname || !realmname) return -1;
159 if (!clitbl_lencxx . . $ pvpgn/d2dbs/clitbl_len. || !gsqtblcxx . . $ pvpgn/d2dbs/gsqtbl.) return 0;
160 if (stdcxx . . $ std/::strlen((char*)charname) >= MAX_CHARNAME_LENcxx . . $ MAX_CHARNAME_LEN.) return -1;
161
162 hashval = string_hashcxx . . $ pvpgn/d2dbs/string_hash(c61c63047ce273de).((char*)charname) % clitbl_lencxx . . $ pvpgn/d2dbs/clitbl_len.;
163 pcl = clitblcxx . . $ pvpgn/d2dbs/clitbl.[hashval];
164 ptmp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
165 while (pcl)
166 {
167 if ((strcasecmp((char*)pcl->charnamecxx . . $ pvpgn/d2dbs/raw_charlockinfo#charname., (char*)charname) == 0) && (pcl->gsidcxx . . $ pvpgn/d2dbs/raw_charlockinfo#gsid. == gsid)) {
168 cl_delete_from_gsq_listcxx . . $ pvpgn/d2dbs/cl_delete_from_gsq_list(845c1249eef1b6dd).(pcl);
169 if (ptmp) ptmp->nextcxx . . $ pvpgn/d2dbs/raw_charlockinfo#next. = pcl->nextcxx . . $ pvpgn/d2dbs/raw_charlockinfo#next.;
170 else clitblcxx . . $ pvpgn/d2dbs/clitbl.[hashval] = pcl->nextcxx . . $ pvpgn/d2dbs/raw_charlockinfo#next.;
171 xfreecxx . . $ `src/common/xalloc.h:51:9`!(pcl);
172 return 0;
173 }
174 ptmp = pcl;
175 pcl = pcl->nextcxx . . $ pvpgn/d2dbs/raw_charlockinfo#next.;
176 }
177 return 0;
178 }
179
180
181 int cl_unlock_all_char_by_gsidcxx . . $ pvpgn/d2dbs/cl_unlock_all_char_by_gsid(4c679297bf94b9eb).(unsigned int gsid)
182 {
183 unsigned int index_pos;
184 t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo# *pcl, *pnext;
185
186 index_pos = gsid % gsqtbl_lencxx . . $ pvpgn/d2dbs/gsqtbl_len.;
187 pcl = gsqtblcxx . . $ pvpgn/d2dbs/gsqtbl.[index_pos];
188 while (pcl)
189 {
190 pnext = pcl->gsqnextcxx . . $ pvpgn/d2dbs/raw_charlockinfo#gsqnext.;
191 cl_unlock_charcxx . . $ pvpgn/d2dbs/cl_unlock_char(35b1a3e46acdbfa7).(pcl->charnamecxx . . $ pvpgn/d2dbs/raw_charlockinfo#charname., pcl->realmnamecxx . . $ pvpgn/d2dbs/raw_charlockinfo#realmname., gsid);
192 pcl = pnext;
193 }
194 return 0;
195 }
196
197
198 static int cl_insert_to_gsq_listcxx . . $ pvpgn/d2dbs/cl_insert_to_gsq_list(ff8101443120eb92).(unsigned int gsid, t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo# *pcl)
199 {
200 unsigned int index_pos;
201 t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo# *ptmp;
202
203 if (!pcl) return -1;
204
205 index_pos = gsid % gsqtbl_lencxx . . $ pvpgn/d2dbs/gsqtbl_len.;
206 ptmp = gsqtblcxx . . $ pvpgn/d2dbs/gsqtbl.[index_pos];
207 gsqtblcxx . . $ pvpgn/d2dbs/gsqtbl.[index_pos] = pcl;
208 if (ptmp) {
209 pcl->gsqnextcxx . . $ pvpgn/d2dbs/raw_charlockinfo#gsqnext. = ptmp;
210 ptmp->gsqprevcxx . . $ pvpgn/d2dbs/raw_charlockinfo#gsqprev. = pcl;
211 }
212 return 0;
213 }
214
215
216 static int cl_delete_from_gsq_listcxx . . $ pvpgn/d2dbs/cl_delete_from_gsq_list(845c1249eef1b6dd).(t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo# *pcl)
217 {
218 unsigned int index_pos;
219 t_charlockinfocxx . . $ pvpgn/d2dbs/t_charlockinfo# *pprev, *pnext;
220
221 if (!pcl) return -1;
222
223 index_pos = (pcl->gsidcxx . . $ pvpgn/d2dbs/raw_charlockinfo#gsid.) % gsqtbl_lencxx . . $ pvpgn/d2dbs/gsqtbl_len.;
224 pprev = pcl->gsqprevcxx . . $ pvpgn/d2dbs/raw_charlockinfo#gsqprev.;
225 pnext = pcl->gsqnextcxx . . $ pvpgn/d2dbs/raw_charlockinfo#gsqnext.;
226 if (pprev) pprev->gsqnextcxx . . $ pvpgn/d2dbs/raw_charlockinfo#gsqnext. = pnext;
227 else gsqtblcxx . . $ pvpgn/d2dbs/gsqtbl.[index_pos] = pnext;
228 if (pnext) pnext->gsqprevcxx . . $ pvpgn/d2dbs/raw_charlockinfo#gsqprev. = pprev;
229
230 return 0;
231 }
232
233
234 static unsigned int string_hashcxx . . $ pvpgn/d2dbs/string_hash(c61c63047ce273de).(char const *string)
235 {
236 unsigned int i;
237 unsigned int pos;
238 unsigned int hash;
239 unsigned int ch;
240
241 if (!string) return 0;
242
243 for (hash = 0, pos = 0, i = 0; i < stdcxx . . $ std/::strlen(string); i++)
244 {
245 ch = safe_tolowercxx . . $ `src/common/xstring.h:41:10`!(string[i]);
246 hash ^= ROTLcxx . . $ `src/common/introtate.h:50:9`!(ch, pos, (std::numeric_limits<unsigned int>::digits));
247 pos += (stdcxx . . $ std/::numeric_limitscxx . . $ std/numeric_limits#<unsigned char>::digitscxx . . $ std/numeric_limits#digits.) - 1;
248 }
249
250 return hash;
251 }
252
253 }
254
255 }