/[LeafOK_CVS]/pvpgn-1.7.4/src/d2dbs/dbsdupecheck.c
ViewVC logotype

Contents of /pvpgn-1.7.4/src/d2dbs/dbsdupecheck.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Tue Jun 6 03:41:38 2006 UTC (19 years, 9 months ago) by sysadm
Branch: GNU, MAIN
CVS Tags: arelease, HEAD
Changes since 1.1: +0 -0 lines
Content type: text/x-csrc
no message

1 /*
2 * Copyright (C) 2001 faster (lqx@cic.tsinghua.edu.cn)
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"
19 #include "setup.h"
20
21 #include <stdio.h>
22 #ifdef STDC_HEADERS
23 # include <stdlib.h>
24 #else
25 # ifdef HAVE_MALLOC_H
26 # include <malloc.h>
27 # endif
28 #endif
29 #ifdef HAVE_STRING_H
30 # include <string.h>
31 #else
32 # ifdef HAVE_STRINGS_H
33 # include <strings.h>
34 # endif
35 # ifdef HAVE_MEMORY_H
36 # include <memory.h>
37 # endif
38 #endif
39 #include "compat/strcasecmp.h"
40 #include <ctype.h>
41 #ifdef HAVE_LIMITS_H
42 # include <limits.h>
43 #endif
44 #include "dbsdupecheck.h"
45 #include "common/setup_after.h"
46 #include "common/bn_type.h"
47 #include "common/eventlog.h"
48
49 const char * delimiter = "JM";
50
51 int is_delimit(char * data)
52 {
53 if ((data[0]==delimiter[0]) && (data[1]==delimiter[1])) return 1;
54 else return 0;
55 }
56
57 void * find_delimiter(char * data, unsigned int datalen)
58 {
59 char * datap = data;
60 unsigned int count;
61 for (count=1; count<datalen;count++)
62 {
63 if (is_delimit(datap)) return datap;
64 }
65 return NULL;
66 }
67
68 #define SKIPLEN 750
69
70 extern int dbsdupecheck(char * data, unsigned int datalen)
71 {
72 char * pointer, * datap;
73 unsigned int restlen;
74
75 unsigned short itemcount, counter;
76 unsigned long uid;
77
78 // skip characters that have never played yet
79 if (datalen< SKIPLEN) return DBSDUPECHECK_CONTAINS_NO_DUPE;
80
81 // we skip the first SKIPLEN bytes containing various char infos wo don't care about
82 // this a) speeds things up
83 // and b) prevents us from detecting our magic index in a bad charname ;-)
84 datap = data+SKIPLEN;
85 restlen = datalen-SKIPLEN;
86
87 do
88 {
89 pointer = find_delimiter(datap,restlen);
90 restlen -= (pointer-datap);
91 datap = pointer;
92 }
93 while ((is_delimit(datap)!=1) || (is_delimit(datap+4)!=1)); // now we should have found "JMxxJM"
94
95 itemcount = bn_short_get(&datap[2]);
96
97 datap+=4;
98 restlen-=4;
99
100 for (counter=0; counter<itemcount; counter++)
101 {
102 if ((datap[4]&0x20)==0x20)
103 {
104 eventlog(eventlog_level_info,__FUNCTION__,"simple item");
105 datap+=14;
106 restlen-=14;
107 }
108 else
109 {
110 eventlog(eventlog_level_info,__FUNCTION__,"extended item");
111 uid = bn_int_get(&datap[14]);
112 eventlog(eventlog_level_info,__FUNCTION__,"unique ID: %lu",uid);
113 pointer = find_delimiter(datap,restlen);
114 restlen-= (pointer-datap);
115 datap = pointer;
116 }
117 }
118
119 return DBSDUPECHECK_CONTAINS_NO_DUPE;
120 }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1