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