/* EQ2Emulator: Everquest II Server Emulator Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net) This file is part of EQ2Emulator. EQ2Emulator is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. EQ2Emulator is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with EQ2Emulator. If not, see . */ #ifdef WIN32 // VS6 doesn't like the length of STL generated names: disabling #pragma warning(disable:4786) #endif #include #include #include #include #include #include #include #include #include "misc.h" #include "types.h" using namespace std; #define ENC(c) (((c) & 0x3f) + ' ') #define DEC(c) (((c) - ' ') & 0x3f) map DBFieldNames; #ifndef WIN32 #ifdef FREEBSD int print_stacktrace() { printf("Insert stack trace here...\n"); return(0); } #else //!WIN32 && !FREEBSD == linux #include int print_stacktrace() { void *ba[20]; int n = backtrace (ba, 20); if (n != 0) { char **names = backtrace_symbols (ba, n); if (names != NULL) { int i; cerr << "called from " << (char*)names[0] << endl; for (i = 1; i < n; ++i) cerr << " " << (char*)names[i] << endl; free (names); } } return(0); } #endif //!FREEBSD #endif //!WIN32 int Deflate(unsigned char* in_data, int in_length, unsigned char* out_data, int max_out_length) { z_stream zstream; int zerror; zstream.next_in = in_data; zstream.avail_in = in_length; zstream.zalloc = Z_NULL; zstream.zfree = Z_NULL; zstream.opaque = Z_NULL; deflateInit(&zstream, Z_FINISH); zstream.next_out = out_data; zstream.avail_out = max_out_length; zerror = deflate(&zstream, Z_FINISH); if (zerror == Z_STREAM_END) { deflateEnd(&zstream); return zstream.total_out; } else { cout << "Error: Deflate: deflate() returned " << zerror << " '"; if (zstream.msg) cout << zstream.msg; cout << "'" << endl; zerror = deflateEnd(&zstream); return 0; } } int Inflate(unsigned char* indata, int indatalen, unsigned char* outdata, int outdatalen, bool iQuiet) { z_stream zstream; int zerror = 0; int i; zstream.next_in = indata; zstream.avail_in = indatalen; zstream.next_out = outdata; zstream.avail_out = outdatalen; zstream.zalloc = Z_NULL; zstream.zfree = Z_NULL; zstream.opaque = Z_NULL; i = inflateInit2( &zstream, 15 ); if (i != Z_OK) { return 0; } zerror = inflate( &zstream, Z_FINISH ); if(zerror == Z_STREAM_END) { inflateEnd( &zstream ); return zstream.total_out; } else { if (!iQuiet) { cout << "Error: Inflate: inflate() returned " << zerror << " '"; if (zstream.msg) cout << zstream.msg; cout << "'" << endl; } if (zerror == -4 && zstream.msg == 0) { return 0; } zerror = inflateEnd( &zstream ); return 0; } } void dump_message_column(unsigned char *buffer, unsigned long length, string leader, FILE *to) { unsigned long i,j; unsigned long rows,offset=0; rows=(length/16)+1; for(i=0;i= 0x41 && val <=0x5A) || (val >= 0x61 && val <=0x7A)) return true; else return false; } int GetItemNameCrc(string item_name){ const char *src = item_name.c_str(); uLong crc = crc32(0L, Z_NULL, 0); crc = crc32(crc, (unsigned const char *)src,strlen(src)) + 1; return sint32(crc) * -1; } unsigned int GetNameCrc(string name) { const char* src = name.c_str(); uLong crc = crc32(0L, Z_NULL, 0); crc = crc32(crc, (unsigned const char*)src, strlen(src)) + 1; return int32(crc)-1; }