├── CMakeLists.txt ├── LICENSE ├── README.md ├── dep ├── CMakeLists.txt └── zlib │ ├── CMakeLists.txt │ ├── adler32.c │ ├── compress.c │ ├── crc32.c │ ├── crc32.h │ ├── deflate.c │ ├── deflate.h │ ├── example.c │ ├── gzclose.c │ ├── gzguts.h │ ├── gzlib.c │ ├── gzread.c │ ├── gzwrite.c │ ├── infback.c │ ├── inffast.c │ ├── inffast.h │ ├── inffixed.h │ ├── inflate.c │ ├── inflate.h │ ├── inftrees.c │ ├── inftrees.h │ ├── minigzip.c │ ├── trees.c │ ├── trees.h │ ├── uncompr.c │ ├── zconf.h │ ├── zlib.h │ ├── zutil.c │ └── zutil.h └── src ├── Auth ├── AuthCmd.h ├── AuthResult.h ├── AuthSession.cpp ├── AuthSession.h ├── CMakeLists.txt ├── RealmList.cpp └── RealmList.h ├── CMakeLists.txt ├── Main.cpp ├── Shared ├── CMakeLists.txt ├── Common.h ├── Config.h ├── Cryptography │ ├── BigNumber.cpp │ ├── BigNumber.h │ ├── HMACSHA1.cpp │ ├── HMACSHA1.h │ ├── PacketRC4.cpp │ ├── PacketRC4.h │ ├── RC4.cpp │ ├── RC4.h │ ├── SHA1.cpp │ ├── SHA1.h │ ├── SHA256.cpp │ ├── SHA256.h │ ├── SRP6.cpp │ ├── SRP6.h │ ├── WardenRC4.cpp │ └── WardenRC4.h ├── Network │ ├── ByteBuffer.cpp │ ├── ByteBuffer.h │ ├── ByteConverter.h │ ├── TCPSocket.cpp │ └── TCPSocket.h ├── Session.cpp └── Session.h └── World ├── Addon.cpp ├── Addon.h ├── CMakeLists.txt ├── Cache.cpp ├── Cache.h ├── Character.h ├── CharacterList.cpp ├── CharacterList.h ├── ChatMgr.cpp ├── ChatMgr.h ├── EventMgr.cpp ├── EventMgr.h ├── Handlers ├── AuthHandler.cpp ├── ChannelHandler.cpp ├── CharacterHandler.cpp ├── ChatHandler.cpp ├── MiscHandler.cpp ├── QueryHandler.cpp └── WardenHandler.cpp ├── ObjectGuid.cpp ├── ObjectGuid.h ├── Opcodes.h ├── Player.h ├── Position.h ├── SharedDefines.h ├── Warden.cpp ├── Warden.h ├── WorldPacket.h ├── WorldSession.cpp ├── WorldSession.h ├── WorldSocket.cpp └── WorldSocket.h /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 Dehravor 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | # Initialize 17 | cmake_minimum_required(VERSION 2.6) 18 | project(Clientless) 19 | 20 | # C++11 21 | if (CMAKE_COMPILER_IS_GNUCXX) 22 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -rdynamic") 23 | endif() 24 | 25 | # OpenSSL 26 | find_package(OpenSSL 0.9.7 REQUIRED) 27 | 28 | # Add dependencies 29 | add_subdirectory(dep) 30 | 31 | # Add sources 32 | add_subdirectory(src) 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Clientless 2 | ============= 3 | 4 | Clientless is a World of Warcraft client emulator based on TrinityCore. 5 | 6 | [![Build Status](https://drone.io/github.com/Dehravor/Clientless/status.png)](https://drone.io/github.com/Dehravor/Clientless/latest) 7 | 8 | ## Usage 9 | 10 | After starting the client for the first time you'll need to provide the following details. 11 | 12 | + The realmlist of your server (e.g hu.logon.tauri.hu) 13 | + Your account name and password 14 | + The name of the realm you are trying to connect (e.g [HU] Tauri WoW Server) 15 | + The name of your character 16 | 17 | These values can be saved (settings.ini) so you'll be able to login automatically when you start the program again. 18 | 19 | ## How to customize 20 | 21 | Custom packet handlers can be added easily. 22 | 23 | + First, you need to declare your function's prototype in *WorldSession.h* 24 | 25 | ``` 26 | void HandleCharacterEnum(WorldPacket &recvPacket); 27 | ``` 28 | 29 | + Then you have to associate the desired opcode with your handler function in *WorldSession.cpp* 30 | 31 | ``` 32 | BIND_OPCODE_HANDLER(SMSG_CHAR_ENUM, HandleCharacterEnum) 33 | ``` 34 | 35 | + Finally, you need to define your handler somewhere. You may create your own .cpp files or use *MiscHandler.cpp* in World/Handlers directory. 36 | 37 | ``` 38 | void WorldSession::HandleCharacterEnum(WorldPacket &recvPacket) 39 | { 40 | ... 41 | } 42 | ``` 43 | 44 | Packet sending should be straightforward if you are used to TrinityCore's structure. 45 | 46 | Requirements 47 | ------- 48 | 49 | + CMake ≥ 2.6 50 | + OpenSSL ≥ 0.9.7 51 | + C++11 Compiler 52 | + Windows/Linux -------------------------------------------------------------------------------- /dep/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 Dehravor 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | add_subdirectory(zlib) -------------------------------------------------------------------------------- /dep/zlib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2008-2014 TrinityCore 2 | # 3 | # This file is free software; as a special exception the author gives 4 | # unlimited permission to copy and/or distribute it, with or without 5 | # modifications, as long as this notice is preserved. 6 | # 7 | # This program is distributed in the hope that it will be useful, but 8 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 9 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | 11 | SET(zlib_STAT_SRCS 12 | adler32.c 13 | compress.c 14 | crc32.c 15 | deflate.c 16 | example.c 17 | infback.c 18 | inffast.c 19 | inflate.c 20 | inftrees.c 21 | trees.c 22 | uncompr.c 23 | zutil.c 24 | ) 25 | 26 | include_directories( 27 | ${CMAKE_CURRENT_SOURCE_DIR} 28 | ) 29 | 30 | add_library(zlib STATIC ${zlib_STAT_SRCS}) 31 | -------------------------------------------------------------------------------- /dep/zlib/adler32.c: -------------------------------------------------------------------------------- 1 | /* adler32.c -- compute the Adler-32 checksum of a data stream 2 | * Copyright (C) 1995-2011 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #include "zutil.h" 9 | 10 | #define local static 11 | 12 | local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); 13 | 14 | #define BASE 65521 /* largest prime smaller than 65536 */ 15 | #define NMAX 5552 16 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 17 | 18 | #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} 19 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 20 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 21 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 22 | #define DO16(buf) DO8(buf,0); DO8(buf,8); 23 | 24 | /* use NO_DIVIDE if your processor does not do division in hardware -- 25 | try it both ways to see which is faster */ 26 | #ifdef NO_DIVIDE 27 | /* note that this assumes BASE is 65521, where 65536 % 65521 == 15 28 | (thank you to John Reiser for pointing this out) */ 29 | # define CHOP(a) \ 30 | do { \ 31 | unsigned long tmp = a >> 16; \ 32 | a &= 0xffffUL; \ 33 | a += (tmp << 4) - tmp; \ 34 | } while (0) 35 | # define MOD28(a) \ 36 | do { \ 37 | CHOP(a); \ 38 | if (a >= BASE) a -= BASE; \ 39 | } while (0) 40 | # define MOD(a) \ 41 | do { \ 42 | CHOP(a); \ 43 | MOD28(a); \ 44 | } while (0) 45 | # define MOD63(a) \ 46 | do { /* this assumes a is not negative */ \ 47 | z_off64_t tmp = a >> 32; \ 48 | a &= 0xffffffffL; \ 49 | a += (tmp << 8) - (tmp << 5) + tmp; \ 50 | tmp = a >> 16; \ 51 | a &= 0xffffL; \ 52 | a += (tmp << 4) - tmp; \ 53 | tmp = a >> 16; \ 54 | a &= 0xffffL; \ 55 | a += (tmp << 4) - tmp; \ 56 | if (a >= BASE) a -= BASE; \ 57 | } while (0) 58 | #else 59 | # define MOD(a) a %= BASE 60 | # define MOD28(a) a %= BASE 61 | # define MOD63(a) a %= BASE 62 | #endif 63 | 64 | /* ========================================================================= */ 65 | uLong ZEXPORT adler32(adler, buf, len) 66 | uLong adler; 67 | const Bytef *buf; 68 | uInt len; 69 | { 70 | unsigned long sum2; 71 | unsigned n; 72 | 73 | /* split Adler-32 into component sums */ 74 | sum2 = (adler >> 16) & 0xffff; 75 | adler &= 0xffff; 76 | 77 | /* in case user likes doing a byte at a time, keep it fast */ 78 | if (len == 1) { 79 | adler += buf[0]; 80 | if (adler >= BASE) 81 | adler -= BASE; 82 | sum2 += adler; 83 | if (sum2 >= BASE) 84 | sum2 -= BASE; 85 | return adler | (sum2 << 16); 86 | } 87 | 88 | /* initial Adler-32 value (deferred check for len == 1 speed) */ 89 | if (buf == Z_NULL) 90 | return 1L; 91 | 92 | /* in case short lengths are provided, keep it somewhat fast */ 93 | if (len < 16) { 94 | while (len--) { 95 | adler += *buf++; 96 | sum2 += adler; 97 | } 98 | if (adler >= BASE) 99 | adler -= BASE; 100 | MOD28(sum2); /* only added so many BASE's */ 101 | return adler | (sum2 << 16); 102 | } 103 | 104 | /* do length NMAX blocks -- requires just one modulo operation */ 105 | while (len >= NMAX) { 106 | len -= NMAX; 107 | n = NMAX / 16; /* NMAX is divisible by 16 */ 108 | do { 109 | DO16(buf); /* 16 sums unrolled */ 110 | buf += 16; 111 | } while (--n); 112 | MOD(adler); 113 | MOD(sum2); 114 | } 115 | 116 | /* do remaining bytes (less than NMAX, still just one modulo) */ 117 | if (len) { /* avoid modulos if none remaining */ 118 | while (len >= 16) { 119 | len -= 16; 120 | DO16(buf); 121 | buf += 16; 122 | } 123 | while (len--) { 124 | adler += *buf++; 125 | sum2 += adler; 126 | } 127 | MOD(adler); 128 | MOD(sum2); 129 | } 130 | 131 | /* return recombined sums */ 132 | return adler | (sum2 << 16); 133 | } 134 | 135 | /* ========================================================================= */ 136 | local uLong adler32_combine_(adler1, adler2, len2) 137 | uLong adler1; 138 | uLong adler2; 139 | z_off64_t len2; 140 | { 141 | unsigned long sum1; 142 | unsigned long sum2; 143 | unsigned rem; 144 | 145 | /* for negative len, return invalid adler32 as a clue for debugging */ 146 | if (len2 < 0) 147 | return 0xffffffffUL; 148 | 149 | /* the derivation of this formula is left as an exercise for the reader */ 150 | MOD63(len2); /* assumes len2 >= 0 */ 151 | rem = (unsigned)len2; 152 | sum1 = adler1 & 0xffff; 153 | sum2 = rem * sum1; 154 | MOD(sum2); 155 | sum1 += (adler2 & 0xffff) + BASE - 1; 156 | sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; 157 | if (sum1 >= BASE) sum1 -= BASE; 158 | if (sum1 >= BASE) sum1 -= BASE; 159 | if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); 160 | if (sum2 >= BASE) sum2 -= BASE; 161 | return sum1 | (sum2 << 16); 162 | } 163 | 164 | /* ========================================================================= */ 165 | uLong ZEXPORT adler32_combine(adler1, adler2, len2) 166 | uLong adler1; 167 | uLong adler2; 168 | z_off_t len2; 169 | { 170 | return adler32_combine_(adler1, adler2, len2); 171 | } 172 | 173 | uLong ZEXPORT adler32_combine64(adler1, adler2, len2) 174 | uLong adler1; 175 | uLong adler2; 176 | z_off64_t len2; 177 | { 178 | return adler32_combine_(adler1, adler2, len2); 179 | } 180 | -------------------------------------------------------------------------------- /dep/zlib/compress.c: -------------------------------------------------------------------------------- 1 | /* compress.c -- compress a memory buffer 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Compresses the source buffer into the destination buffer. The level 13 | parameter has the same meaning as in deflateInit. sourceLen is the byte 14 | length of the source buffer. Upon entry, destLen is the total size of the 15 | destination buffer, which must be at least 0.1% larger than sourceLen plus 16 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 17 | 18 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 19 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, 20 | Z_STREAM_ERROR if the level parameter is invalid. 21 | */ 22 | int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) 23 | Bytef *dest; 24 | uLongf *destLen; 25 | const Bytef *source; 26 | uLong sourceLen; 27 | int level; 28 | { 29 | z_stream stream; 30 | int err; 31 | 32 | stream.next_in = (Bytef*)source; 33 | stream.avail_in = (uInt)sourceLen; 34 | #ifdef MAXSEG_64K 35 | /* Check for source > 64K on 16-bit machine: */ 36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 | #endif 38 | stream.next_out = dest; 39 | stream.avail_out = (uInt)*destLen; 40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 | 42 | stream.zalloc = (alloc_func)0; 43 | stream.zfree = (free_func)0; 44 | stream.opaque = (voidpf)0; 45 | 46 | err = deflateInit(&stream, level); 47 | if (err != Z_OK) return err; 48 | 49 | err = deflate(&stream, Z_FINISH); 50 | if (err != Z_STREAM_END) { 51 | deflateEnd(&stream); 52 | return err == Z_OK ? Z_BUF_ERROR : err; 53 | } 54 | *destLen = stream.total_out; 55 | 56 | err = deflateEnd(&stream); 57 | return err; 58 | } 59 | 60 | /* =========================================================================== 61 | */ 62 | int ZEXPORT compress (dest, destLen, source, sourceLen) 63 | Bytef *dest; 64 | uLongf *destLen; 65 | const Bytef *source; 66 | uLong sourceLen; 67 | { 68 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 69 | } 70 | 71 | /* =========================================================================== 72 | If the default memLevel or windowBits for deflateInit() is changed, then 73 | this function needs to be updated. 74 | */ 75 | uLong ZEXPORT compressBound (sourceLen) 76 | uLong sourceLen; 77 | { 78 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 79 | (sourceLen >> 25) + 13; 80 | } 81 | -------------------------------------------------------------------------------- /dep/zlib/gzclose.c: -------------------------------------------------------------------------------- 1 | /* gzclose.c -- zlib gzclose() function 2 | * Copyright (C) 2004, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "gzguts.h" 7 | 8 | /* gzclose() is in a separate file so that it is linked in only if it is used. 9 | That way the other gzclose functions can be used instead to avoid linking in 10 | unneeded compression or decompression routines. */ 11 | int ZEXPORT gzclose(file) 12 | gzFile file; 13 | { 14 | #ifndef NO_GZCOMPRESS 15 | gz_statep state; 16 | 17 | if (file == NULL) 18 | return Z_STREAM_ERROR; 19 | state = (gz_statep)file; 20 | 21 | return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); 22 | #else 23 | return gzclose_r(file); 24 | #endif 25 | } 26 | -------------------------------------------------------------------------------- /dep/zlib/gzguts.h: -------------------------------------------------------------------------------- 1 | /* gzguts.h -- zlib internal header definitions for gz* operations 2 | * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #ifdef _LARGEFILE64_SOURCE 7 | # ifndef _LARGEFILE_SOURCE 8 | # define _LARGEFILE_SOURCE 1 9 | # endif 10 | # ifdef _FILE_OFFSET_BITS 11 | # undef _FILE_OFFSET_BITS 12 | # endif 13 | #endif 14 | 15 | #ifdef HAVE_HIDDEN 16 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 17 | #else 18 | # define ZLIB_INTERNAL 19 | #endif 20 | 21 | #include 22 | #include "zlib.h" 23 | #ifdef STDC 24 | # include 25 | # include 26 | # include 27 | #endif 28 | #include 29 | 30 | #ifdef _WIN32 31 | # include 32 | #endif 33 | 34 | #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) 35 | # include 36 | #endif 37 | 38 | #ifdef NO_DEFLATE /* for compatibility with old definition */ 39 | # define NO_GZCOMPRESS 40 | #endif 41 | 42 | #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) 43 | # ifndef HAVE_VSNPRINTF 44 | # define HAVE_VSNPRINTF 45 | # endif 46 | #endif 47 | 48 | #if defined(__CYGWIN__) 49 | # ifndef HAVE_VSNPRINTF 50 | # define HAVE_VSNPRINTF 51 | # endif 52 | #endif 53 | 54 | #if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410) 55 | # ifndef HAVE_VSNPRINTF 56 | # define HAVE_VSNPRINTF 57 | # endif 58 | #endif 59 | 60 | #ifndef HAVE_VSNPRINTF 61 | # ifdef MSDOS 62 | /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), 63 | but for now we just assume it doesn't. */ 64 | # define NO_vsnprintf 65 | # endif 66 | # ifdef __TURBOC__ 67 | # define NO_vsnprintf 68 | # endif 69 | # ifdef WIN32 70 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ 71 | # if !defined(vsnprintf) && !defined(NO_vsnprintf) 72 | # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) 73 | # define vsnprintf _vsnprintf 74 | # endif 75 | # endif 76 | # endif 77 | # ifdef __SASC 78 | # define NO_vsnprintf 79 | # endif 80 | # ifdef VMS 81 | # define NO_vsnprintf 82 | # endif 83 | # ifdef __OS400__ 84 | # define NO_vsnprintf 85 | # endif 86 | # ifdef __MVS__ 87 | # define NO_vsnprintf 88 | # endif 89 | #endif 90 | 91 | #ifndef local 92 | # define local static 93 | #endif 94 | /* compile with -Dlocal if your debugger can't find static symbols */ 95 | 96 | /* gz* functions always use library allocation functions */ 97 | #ifndef STDC 98 | extern voidp malloc OF((uInt size)); 99 | extern void free OF((voidpf ptr)); 100 | #endif 101 | 102 | /* get errno and strerror definition */ 103 | #if defined UNDER_CE 104 | # include 105 | # define zstrerror() gz_strwinerror((DWORD)GetLastError()) 106 | #else 107 | # ifndef NO_STRERROR 108 | # include 109 | # define zstrerror() strerror(errno) 110 | # else 111 | # define zstrerror() "stdio error (consult errno)" 112 | # endif 113 | #endif 114 | 115 | /* provide prototypes for these when building zlib without LFS */ 116 | #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 117 | ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); 118 | ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); 119 | ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); 120 | ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); 121 | #endif 122 | 123 | /* default memLevel */ 124 | #if MAX_MEM_LEVEL >= 8 125 | # define DEF_MEM_LEVEL 8 126 | #else 127 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 128 | #endif 129 | 130 | /* default i/o buffer size -- double this for output when reading */ 131 | #define GZBUFSIZE 8192 132 | 133 | /* gzip modes, also provide a little integrity check on the passed structure */ 134 | #define GZ_NONE 0 135 | #define GZ_READ 7247 136 | #define GZ_WRITE 31153 137 | #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ 138 | 139 | /* values for gz_state how */ 140 | #define LOOK 0 /* look for a gzip header */ 141 | #define COPY 1 /* copy input directly */ 142 | #define GZIP 2 /* decompress a gzip stream */ 143 | 144 | /* internal gzip file state data structure */ 145 | typedef struct { 146 | /* exposed contents for gzgetc() macro */ 147 | struct gzFile_s x; /* "x" for exposed */ 148 | /* x.have: number of bytes available at x.next */ 149 | /* x.next: next output data to deliver or write */ 150 | /* x.pos: current position in uncompressed data */ 151 | /* used for both reading and writing */ 152 | int mode; /* see gzip modes above */ 153 | int fd; /* file descriptor */ 154 | char *path; /* path or fd for error messages */ 155 | unsigned size; /* buffer size, zero if not allocated yet */ 156 | unsigned want; /* requested buffer size, default is GZBUFSIZE */ 157 | unsigned char *in; /* input buffer */ 158 | unsigned char *out; /* output buffer (double-sized when reading) */ 159 | int direct; /* 0 if processing gzip, 1 if transparent */ 160 | /* just for reading */ 161 | int how; /* 0: get header, 1: copy, 2: decompress */ 162 | z_off64_t start; /* where the gzip data started, for rewinding */ 163 | int eof; /* true if end of input file reached */ 164 | int past; /* true if read requested past end */ 165 | /* just for writing */ 166 | int level; /* compression level */ 167 | int strategy; /* compression strategy */ 168 | /* seek request */ 169 | z_off64_t skip; /* amount to skip (already rewound if backwards) */ 170 | int seek; /* true if seek request pending */ 171 | /* error information */ 172 | int err; /* error code */ 173 | char *msg; /* error message */ 174 | /* zlib inflate or deflate stream */ 175 | z_stream strm; /* stream structure in-place (not a pointer) */ 176 | } gz_state; 177 | typedef gz_state FAR *gz_statep; 178 | 179 | /* shared functions */ 180 | void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); 181 | #if defined UNDER_CE 182 | char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); 183 | #endif 184 | 185 | /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t 186 | value -- needed when comparing unsigned to z_off64_t, which is signed 187 | (possible z_off64_t types off_t, off64_t, and long are all signed) */ 188 | #ifdef INT_MAX 189 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) 190 | #else 191 | unsigned ZLIB_INTERNAL gz_intmax OF((void)); 192 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) 193 | #endif 194 | -------------------------------------------------------------------------------- /dep/zlib/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); 12 | -------------------------------------------------------------------------------- /dep/zlib/inffixed.h: -------------------------------------------------------------------------------- 1 | /* inffixed.h -- table for decoding fixed codes 2 | * Generated automatically by makefixed(). 3 | */ 4 | 5 | /* WARNING: this file should *not* be used by applications. 6 | It is part of the implementation of this library and is 7 | subject to change. Applications should only use zlib.h. 8 | */ 9 | 10 | static const code lenfix[512] = { 11 | {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, 12 | {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, 13 | {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, 14 | {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, 15 | {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, 16 | {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, 17 | {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, 18 | {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, 19 | {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, 20 | {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, 21 | {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, 22 | {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, 23 | {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, 24 | {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, 25 | {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, 26 | {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, 27 | {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, 28 | {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, 29 | {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, 30 | {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, 31 | {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, 32 | {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, 33 | {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, 34 | {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, 35 | {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, 36 | {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, 37 | {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, 38 | {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, 39 | {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, 40 | {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, 41 | {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, 42 | {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, 43 | {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, 44 | {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, 45 | {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, 46 | {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, 47 | {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, 48 | {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, 49 | {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, 50 | {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, 51 | {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, 52 | {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, 53 | {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, 54 | {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, 55 | {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, 56 | {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, 57 | {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, 58 | {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, 59 | {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, 60 | {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, 61 | {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, 62 | {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, 63 | {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, 64 | {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, 65 | {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, 66 | {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, 67 | {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, 68 | {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, 69 | {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, 70 | {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, 71 | {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, 72 | {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, 73 | {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, 74 | {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, 75 | {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, 76 | {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, 77 | {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, 78 | {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, 79 | {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, 80 | {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, 81 | {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, 82 | {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, 83 | {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, 84 | {0,9,255} 85 | }; 86 | 87 | static const code distfix[32] = { 88 | {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, 89 | {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, 90 | {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, 91 | {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, 92 | {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, 93 | {22,5,193},{64,5,0} 94 | }; 95 | -------------------------------------------------------------------------------- /dep/zlib/inflate.h: -------------------------------------------------------------------------------- 1 | /* inflate.h -- internal inflate state definition 2 | * Copyright (C) 1995-2009 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* define NO_GZIP when compiling if you want to disable gzip header and 12 | trailer decoding by inflate(). NO_GZIP would be used to avoid linking in 13 | the crc code when it is not needed. For shared libraries, gzip decoding 14 | should be left enabled. */ 15 | #ifndef NO_GZIP 16 | # define GUNZIP 17 | #endif 18 | 19 | /* Possible inflate modes between inflate() calls */ 20 | typedef enum { 21 | HEAD, /* i: waiting for magic header */ 22 | FLAGS, /* i: waiting for method and flags (gzip) */ 23 | TIME, /* i: waiting for modification time (gzip) */ 24 | OS, /* i: waiting for extra flags and operating system (gzip) */ 25 | EXLEN, /* i: waiting for extra length (gzip) */ 26 | EXTRA, /* i: waiting for extra bytes (gzip) */ 27 | NAME, /* i: waiting for end of file name (gzip) */ 28 | COMMENT, /* i: waiting for end of comment (gzip) */ 29 | HCRC, /* i: waiting for header crc (gzip) */ 30 | DICTID, /* i: waiting for dictionary check value */ 31 | DICT, /* waiting for inflateSetDictionary() call */ 32 | TYPE, /* i: waiting for type bits, including last-flag bit */ 33 | TYPEDO, /* i: same, but skip check to exit inflate on new block */ 34 | STORED, /* i: waiting for stored size (length and complement) */ 35 | COPY_, /* i/o: same as COPY below, but only first time in */ 36 | COPY, /* i/o: waiting for input or output to copy stored block */ 37 | TABLE, /* i: waiting for dynamic block table lengths */ 38 | LENLENS, /* i: waiting for code length code lengths */ 39 | CODELENS, /* i: waiting for length/lit and distance code lengths */ 40 | LEN_, /* i: same as LEN below, but only first time in */ 41 | LEN, /* i: waiting for length/lit/eob code */ 42 | LENEXT, /* i: waiting for length extra bits */ 43 | DIST, /* i: waiting for distance code */ 44 | DISTEXT, /* i: waiting for distance extra bits */ 45 | MATCH, /* o: waiting for output space to copy string */ 46 | LIT, /* o: waiting for output space to write literal */ 47 | CHECK, /* i: waiting for 32-bit check value */ 48 | LENGTH, /* i: waiting for 32-bit length (gzip) */ 49 | DONE, /* finished check, done -- remain here until reset */ 50 | BAD, /* got a data error -- remain here until reset */ 51 | MEM, /* got an inflate() memory error -- remain here until reset */ 52 | SYNC /* looking for synchronization bytes to restart inflate() */ 53 | } inflate_mode; 54 | 55 | /* 56 | State transitions between above modes - 57 | 58 | (most modes can go to BAD or MEM on error -- not shown for clarity) 59 | 60 | Process header: 61 | HEAD -> (gzip) or (zlib) or (raw) 62 | (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> 63 | HCRC -> TYPE 64 | (zlib) -> DICTID or TYPE 65 | DICTID -> DICT -> TYPE 66 | (raw) -> TYPEDO 67 | Read deflate blocks: 68 | TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK 69 | STORED -> COPY_ -> COPY -> TYPE 70 | TABLE -> LENLENS -> CODELENS -> LEN_ 71 | LEN_ -> LEN 72 | Read deflate codes in fixed or dynamic block: 73 | LEN -> LENEXT or LIT or TYPE 74 | LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 75 | LIT -> LEN 76 | Process trailer: 77 | CHECK -> LENGTH -> DONE 78 | */ 79 | 80 | /* state maintained between inflate() calls. Approximately 10K bytes. */ 81 | struct inflate_state { 82 | inflate_mode mode; /* current inflate mode */ 83 | int last; /* true if processing last block */ 84 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 85 | int havedict; /* true if dictionary provided */ 86 | int flags; /* gzip header method and flags (0 if zlib) */ 87 | unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 88 | unsigned long check; /* protected copy of check value */ 89 | unsigned long total; /* protected copy of output count */ 90 | gz_headerp head; /* where to save gzip header information */ 91 | /* sliding window */ 92 | unsigned wbits; /* log base 2 of requested window size */ 93 | unsigned wsize; /* window size or zero if not using window */ 94 | unsigned whave; /* valid bytes in the window */ 95 | unsigned wnext; /* window write index */ 96 | unsigned char FAR *window; /* allocated sliding window, if needed */ 97 | /* bit accumulator */ 98 | unsigned long hold; /* input bit accumulator */ 99 | unsigned bits; /* number of bits in "in" */ 100 | /* for string and stored block copying */ 101 | unsigned length; /* literal or length of data to copy */ 102 | unsigned offset; /* distance back to copy string from */ 103 | /* for table and code decoding */ 104 | unsigned extra; /* extra bits needed */ 105 | /* fixed and dynamic code tables */ 106 | code const FAR *lencode; /* starting table for length/literal codes */ 107 | code const FAR *distcode; /* starting table for distance codes */ 108 | unsigned lenbits; /* index bits for lencode */ 109 | unsigned distbits; /* index bits for distcode */ 110 | /* dynamic table building */ 111 | unsigned ncode; /* number of code length code lengths */ 112 | unsigned nlen; /* number of length code lengths */ 113 | unsigned ndist; /* number of distance code lengths */ 114 | unsigned have; /* number of code lengths in lens[] */ 115 | code FAR *next; /* next available space in codes[] */ 116 | unsigned short lens[320]; /* temporary storage for code lengths */ 117 | unsigned short work[288]; /* work area for code table building */ 118 | code codes[ENOUGH]; /* space for code tables */ 119 | int sane; /* if false, allow invalid distance too far */ 120 | int back; /* bits back of last unprocessed length/lit */ 121 | unsigned was; /* initial length of match */ 122 | }; 123 | -------------------------------------------------------------------------------- /dep/zlib/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2005, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Structure for decoding tables. Each entry provides either the 12 | information needed to do the operation requested by the code that 13 | indexed that table entry, or it provides a pointer to another 14 | table that indexes more bits of the code. op indicates whether 15 | the entry is a pointer to another table, a literal, a length or 16 | distance, an end-of-block, or an invalid code. For a table 17 | pointer, the low four bits of op is the number of index bits of 18 | that table. For a length or distance, the low four bits of op 19 | is the number of extra bits to get after the code. bits is 20 | the number of bits in this code or part of the code to drop off 21 | of the bit buffer. val is the actual byte to output in the case 22 | of a literal, the base length or distance, or the offset from 23 | the current table to the next table. Each entry is four bytes. */ 24 | typedef struct { 25 | unsigned char op; /* operation, extra bits, table bits */ 26 | unsigned char bits; /* bits in this part of the code */ 27 | unsigned short val; /* offset in table or code value */ 28 | } code; 29 | 30 | /* op values as set by inflate_table(): 31 | 00000000 - literal 32 | 0000tttt - table link, tttt != 0 is the number of table index bits 33 | 0001eeee - length or distance, eeee is the number of extra bits 34 | 01100000 - end of block 35 | 01000000 - invalid code 36 | */ 37 | 38 | /* Maximum size of the dynamic table. The maximum number of code structures is 39 | 1444, which is the sum of 852 for literal/length codes and 592 for distance 40 | codes. These values were found by exhaustive searches using the program 41 | examples/enough.c found in the zlib distribtution. The arguments to that 42 | program are the number of symbols, the initial root table size, and the 43 | maximum bit length of a code. "enough 286 9 15" for literal/length codes 44 | returns returns 852, and "enough 30 6 15" for distance codes returns 592. 45 | The initial root table size (9 or 6) is found in the fifth argument of the 46 | inflate_table() calls in inflate.c and infback.c. If the root table size is 47 | changed, then these maximum sizes would be need to be recalculated and 48 | updated. */ 49 | #define ENOUGH_LENS 852 50 | #define ENOUGH_DISTS 592 51 | #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) 52 | 53 | /* Type of code to build for inflate_table() */ 54 | typedef enum { 55 | CODES, 56 | LENS, 57 | DISTS 58 | } codetype; 59 | 60 | int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, 61 | unsigned codes, code FAR * FAR *table, 62 | unsigned FAR *bits, unsigned short FAR *work)); 63 | -------------------------------------------------------------------------------- /dep/zlib/uncompr.c: -------------------------------------------------------------------------------- 1 | /* uncompr.c -- decompress a memory buffer 2 | * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Decompresses the source buffer into the destination buffer. sourceLen is 13 | the byte length of the source buffer. Upon entry, destLen is the total 14 | size of the destination buffer, which must be large enough to hold the 15 | entire uncompressed data. (The size of the uncompressed data must have 16 | been saved previously by the compressor and transmitted to the decompressor 17 | by some mechanism outside the scope of this compression library.) 18 | Upon exit, destLen is the actual size of the compressed buffer. 19 | 20 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 21 | enough memory, Z_BUF_ERROR if there was not enough room in the output 22 | buffer, or Z_DATA_ERROR if the input data was corrupted. 23 | */ 24 | int ZEXPORT uncompress (dest, destLen, source, sourceLen) 25 | Bytef *dest; 26 | uLongf *destLen; 27 | const Bytef *source; 28 | uLong sourceLen; 29 | { 30 | z_stream stream; 31 | int err; 32 | 33 | stream.next_in = (Bytef*)source; 34 | stream.avail_in = (uInt)sourceLen; 35 | /* Check for source > 64K on 16-bit machine: */ 36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 | 38 | stream.next_out = dest; 39 | stream.avail_out = (uInt)*destLen; 40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 | 42 | stream.zalloc = (alloc_func)0; 43 | stream.zfree = (free_func)0; 44 | 45 | err = inflateInit(&stream); 46 | if (err != Z_OK) return err; 47 | 48 | err = inflate(&stream, Z_FINISH); 49 | if (err != Z_STREAM_END) { 50 | inflateEnd(&stream); 51 | if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 52 | return Z_DATA_ERROR; 53 | return err; 54 | } 55 | *destLen = stream.total_out; 56 | 57 | err = inflateEnd(&stream); 58 | return err; 59 | } 60 | -------------------------------------------------------------------------------- /dep/zlib/zutil.h: -------------------------------------------------------------------------------- 1 | /* zutil.h -- internal interface and configuration of the compression library 2 | * Copyright (C) 1995-2012 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* @(#) $Id$ */ 12 | 13 | #ifndef ZUTIL_H 14 | #define ZUTIL_H 15 | 16 | #ifdef HAVE_HIDDEN 17 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 18 | #else 19 | # define ZLIB_INTERNAL 20 | #endif 21 | 22 | #include "zlib.h" 23 | 24 | #if defined(STDC) && !defined(Z_SOLO) 25 | # if !(defined(_WIN32_WCE) && defined(_MSC_VER)) 26 | # include 27 | # endif 28 | # include 29 | # include 30 | #endif 31 | 32 | #ifdef Z_SOLO 33 | typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */ 34 | #endif 35 | 36 | #ifndef local 37 | # define local static 38 | #endif 39 | /* compile with -Dlocal if your debugger can't find static symbols */ 40 | 41 | typedef unsigned char uch; 42 | typedef uch FAR uchf; 43 | typedef unsigned short ush; 44 | typedef ush FAR ushf; 45 | typedef unsigned long ulg; 46 | 47 | extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 48 | /* (size given to avoid silly warnings with Visual C++) */ 49 | 50 | #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 51 | 52 | #define ERR_RETURN(strm,err) \ 53 | return (strm->msg = (char*)ERR_MSG(err), (err)) 54 | /* To be used only when the state is known to be valid */ 55 | 56 | /* common constants */ 57 | 58 | #ifndef DEF_WBITS 59 | # define DEF_WBITS MAX_WBITS 60 | #endif 61 | /* default windowBits for decompression. MAX_WBITS is for compression only */ 62 | 63 | #if MAX_MEM_LEVEL >= 8 64 | # define DEF_MEM_LEVEL 8 65 | #else 66 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 67 | #endif 68 | /* default memLevel */ 69 | 70 | #define STORED_BLOCK 0 71 | #define STATIC_TREES 1 72 | #define DYN_TREES 2 73 | /* The three kinds of block type */ 74 | 75 | #define MIN_MATCH 3 76 | #define MAX_MATCH 258 77 | /* The minimum and maximum match lengths */ 78 | 79 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 80 | 81 | /* target dependencies */ 82 | 83 | #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 84 | # define OS_CODE 0x00 85 | # ifndef Z_SOLO 86 | # if defined(__TURBOC__) || defined(__BORLANDC__) 87 | # if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 88 | /* Allow compilation with ANSI keywords only enabled */ 89 | void _Cdecl farfree( void *block ); 90 | void *_Cdecl farmalloc( unsigned long nbytes ); 91 | # else 92 | # include 93 | # endif 94 | # else /* MSC or DJGPP */ 95 | # include 96 | # endif 97 | # endif 98 | #endif 99 | 100 | #ifdef AMIGA 101 | # define OS_CODE 0x01 102 | #endif 103 | 104 | #if defined(VAXC) || defined(VMS) 105 | # define OS_CODE 0x02 106 | # define F_OPEN(name, mode) \ 107 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 108 | #endif 109 | 110 | #if defined(ATARI) || defined(atarist) 111 | # define OS_CODE 0x05 112 | #endif 113 | 114 | #ifdef OS2 115 | # define OS_CODE 0x06 116 | # if defined(M_I86) && !defined(Z_SOLO) 117 | # include 118 | # endif 119 | #endif 120 | 121 | #if defined(MACOS) || defined(TARGET_OS_MAC) 122 | # define OS_CODE 0x07 123 | # ifndef Z_SOLO 124 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 125 | # include /* for fdopen */ 126 | # else 127 | # ifndef fdopen 128 | # define fdopen(fd,mode) NULL /* No fdopen() */ 129 | # endif 130 | # endif 131 | # endif 132 | #endif 133 | 134 | #ifdef TOPS20 135 | # define OS_CODE 0x0a 136 | #endif 137 | 138 | #ifdef WIN32 139 | # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ 140 | # define OS_CODE 0x0b 141 | # endif 142 | #endif 143 | 144 | #ifdef __50SERIES /* Prime/PRIMOS */ 145 | # define OS_CODE 0x0f 146 | #endif 147 | 148 | #if defined(_BEOS_) || defined(RISCOS) 149 | # define fdopen(fd,mode) NULL /* No fdopen() */ 150 | #endif 151 | 152 | #if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX 153 | # if defined(_WIN32_WCE) 154 | # define fdopen(fd,mode) NULL /* No fdopen() */ 155 | # ifndef _PTRDIFF_T_DEFINED 156 | typedef int ptrdiff_t; 157 | # define _PTRDIFF_T_DEFINED 158 | # endif 159 | # else 160 | # define fdopen(fd,type) _fdopen(fd,type) 161 | # endif 162 | #endif 163 | 164 | #if defined(__BORLANDC__) && !defined(MSDOS) 165 | #pragma warn -8004 166 | #pragma warn -8008 167 | #pragma warn -8066 168 | #endif 169 | 170 | /* provide prototypes for these when building zlib without LFS */ 171 | #if !defined(_WIN32) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) 172 | ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); 173 | ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); 174 | #endif 175 | 176 | /* common defaults */ 177 | 178 | #ifndef OS_CODE 179 | # define OS_CODE 0x03 /* assume Unix */ 180 | #endif 181 | 182 | #ifndef F_OPEN 183 | # define F_OPEN(name, mode) fopen((name), (mode)) 184 | #endif 185 | 186 | /* functions */ 187 | 188 | #if defined(pyr) || defined(Z_SOLO) 189 | # define NO_MEMCPY 190 | #endif 191 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 192 | /* Use our own functions for small and medium model with MSC <= 5.0. 193 | * You may have to use the same strategy for Borland C (untested). 194 | * The __SC__ check is for Symantec. 195 | */ 196 | # define NO_MEMCPY 197 | #endif 198 | #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 199 | # define HAVE_MEMCPY 200 | #endif 201 | #ifdef HAVE_MEMCPY 202 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 203 | # define zmemcpy _fmemcpy 204 | # define zmemcmp _fmemcmp 205 | # define zmemzero(dest, len) _fmemset(dest, 0, len) 206 | # else 207 | # define zmemcpy memcpy 208 | # define zmemcmp memcmp 209 | # define zmemzero(dest, len) memset(dest, 0, len) 210 | # endif 211 | #else 212 | void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 213 | int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 214 | void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); 215 | #endif 216 | 217 | /* Diagnostic functions */ 218 | #ifdef DEBUG 219 | # include 220 | extern int ZLIB_INTERNAL z_verbose; 221 | extern void ZLIB_INTERNAL z_error OF((char *m)); 222 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 223 | # define Trace(x) {if (z_verbose>=0) fprintf x ;} 224 | # define Tracev(x) {if (z_verbose>0) fprintf x ;} 225 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 226 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 227 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 228 | #else 229 | # define Assert(cond,msg) 230 | # define Trace(x) 231 | # define Tracev(x) 232 | # define Tracevv(x) 233 | # define Tracec(c,x) 234 | # define Tracecv(c,x) 235 | #endif 236 | 237 | #ifndef Z_SOLO 238 | voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, 239 | unsigned size)); 240 | void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); 241 | #endif 242 | 243 | #define ZALLOC(strm, items, size) \ 244 | (*((strm)->zalloc))((strm)->opaque, (items), (size)) 245 | #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 246 | #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 247 | 248 | /* Reverse the bytes in a 32-bit value */ 249 | #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ 250 | (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) 251 | 252 | #endif /* ZUTIL_H */ 253 | -------------------------------------------------------------------------------- /src/Auth/AuthCmd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | #include 22 | 23 | enum AuthCmd : uint8_t 24 | { 25 | AUTH_LOGON_CHALLENGE = 0x00, 26 | AUTH_LOGON_PROOF = 0x01, 27 | AUTH_RECONNECT_CHALLENGE = 0x02, 28 | AUTH_RECONNECT_PROOF = 0x03, 29 | REALM_LIST = 0x10, 30 | XFER_INITIATE = 0x30, 31 | XFER_DATA = 0x31, 32 | XFER_ACCEPT = 0x32, 33 | XFER_RESUME = 0x33, 34 | XFER_CANCEL = 0x34 35 | }; -------------------------------------------------------------------------------- /src/Auth/AuthResult.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | #include 22 | 23 | enum AuthResult : uint8_t 24 | { 25 | WOW_SUCCESS = 0x00, 26 | WOW_FAIL_BANNED = 0x03, 27 | WOW_FAIL_UNKNOWN_ACCOUNT = 0x04, 28 | WOW_FAIL_INCORRECT_PASSWORD = 0x05, 29 | WOW_FAIL_ALREADY_ONLINE = 0x06, 30 | WOW_FAIL_NO_TIME = 0x07, 31 | WOW_FAIL_DB_BUSY = 0x08, 32 | WOW_FAIL_VERSION_INVALID = 0x09, 33 | WOW_FAIL_VERSION_UPDATE = 0x0A, 34 | WOW_FAIL_INVALID_SERVER = 0x0B, 35 | WOW_FAIL_SUSPENDED = 0x0C, 36 | WOW_FAIL_FAIL_NOACCESS = 0x0D, 37 | WOW_SUCCESS_SURVEY = 0x0E, 38 | WOW_FAIL_PARENTCONTROL = 0x0F, 39 | WOW_FAIL_LOCKED_ENFORCED = 0x10, 40 | WOW_FAIL_TRIAL_ENDED = 0x11, 41 | WOW_FAIL_USE_BATTLENET = 0x12, 42 | WOW_FAIL_ANTI_INDULGENCE = 0x13, 43 | WOW_FAIL_EXPIRED = 0x14, 44 | WOW_FAIL_NO_GAME_ACCOUNT = 0x15, 45 | WOW_FAIL_CHARGEBACK = 0x16, 46 | WOW_FAIL_INTERNET_GAME_ROOM_WITHOUT_BNET = 0x17, 47 | WOW_FAIL_GAME_ACCOUNT_LOCKED = 0x18, 48 | WOW_FAIL_UNLOCKABLE_LOCK = 0x19, 49 | WOW_FAIL_CONVERSION_REQUIRED = 0x20, 50 | WOW_FAIL_DISCONNECTED = 0xFF 51 | }; -------------------------------------------------------------------------------- /src/Auth/AuthSession.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | #include "Common.h" 20 | #include "AuthResult.h" 21 | #include "AuthCmd.h" 22 | #include "Session.h" 23 | #include "Network/TCPSocket.h" 24 | #include "Cryptography/SRP6.h" 25 | 26 | class AuthSession 27 | { 28 | public: 29 | AuthSession(std::shared_ptr session); 30 | ~AuthSession(); 31 | 32 | bool Authenticate(); 33 | private: 34 | bool SendLogonChallenge(); 35 | bool SendLogonProof(); 36 | bool SendRealmlistRequest(); 37 | 38 | bool HandleLogonChallengeResponse(); 39 | bool HandleLogonProofResponse(); 40 | bool HandleRealmlistResponse(); 41 | 42 | private: 43 | std::shared_ptr session_; 44 | TCPSocket socket_; 45 | SRP6 srp6_; 46 | std::string token_; 47 | 48 | void SendPacket(ByteBuffer& buffer); 49 | 50 | std::string AuthResultToStr(AuthResult result); 51 | }; -------------------------------------------------------------------------------- /src/Auth/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 Dehravor 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | file(GLOB sources_localdir *.cpp *.h) 17 | 18 | set(Auth_SRCS 19 | ${sources_localdir} 20 | ) 21 | 22 | include_directories( 23 | ${CMAKE_SOURCE_DIR} 24 | ${CMAKE_SOURCE_DIR}/dep 25 | ${CMAKE_SOURCE_DIR}/src 26 | ${CMAKE_SOURCE_DIR}/src/Shared 27 | ${CMAKE_CURRENT_SOURCE_DIR} 28 | ${OPENSSL_INCLUDE_DIR} 29 | ) 30 | 31 | add_library(Auth STATIC 32 | ${Auth_SRCS} 33 | ) 34 | 35 | target_link_libraries(Auth 36 | Shared 37 | ) -------------------------------------------------------------------------------- /src/Auth/RealmList.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "RealmList.h" 19 | #include "Config.h" 20 | 21 | void RealmList::Populate(uint32_t count, ByteBuffer &buffer) 22 | { 23 | list_.clear(); 24 | list_.resize(count); 25 | 26 | for (uint32_t i = 0; i < count; i++) 27 | { 28 | Realm realm; 29 | 30 | buffer >> realm.Icon; 31 | buffer >> realm.Lock; 32 | realm.Flags = buffer.read(); 33 | buffer >> realm.Name; 34 | buffer >> realm.Address; 35 | buffer >> realm.Population; 36 | buffer >> realm.Characters; 37 | buffer >> realm.Timezone; 38 | buffer >> realm.ID; 39 | 40 | if (realm.Flags & REALM_FLAG_SPECIFYBUILD) 41 | { 42 | buffer >> realm.MajorVersion; 43 | buffer >> realm.MinorVersion; 44 | buffer >> realm.BugfixVersion; 45 | buffer >> realm.Build; 46 | } 47 | 48 | list_[i] = realm; 49 | } 50 | 51 | buffer.read_skip(); 52 | buffer.read_skip(); 53 | } 54 | 55 | void RealmList::Print() 56 | { 57 | std::cout << "[Realmlist]" << std::endl; 58 | 59 | for (Realm const& realm : list_) 60 | { 61 | if (realm.Flags & REALM_FLAG_SPECIFYBUILD) 62 | { 63 | if (realm.MajorVersion != GameVersion[0] || realm.MinorVersion != GameVersion[1] || realm.BugfixVersion != GameVersion[2] || realm.Build != GameBuild) 64 | continue; 65 | } 66 | 67 | std::cout << " - " << realm.Name << " [" << realm.Address << "] (" << (realm.Flags & REALM_FLAG_OFFLINE ? "Offline" : "Online") << ")" << std::endl; 68 | } 69 | } 70 | 71 | Realm const* RealmList::GetRealmByName(std::string name) 72 | { 73 | for (Realm const& realm : list_) 74 | { 75 | if (realm.Name == name) 76 | return &realm; 77 | } 78 | 79 | return nullptr; 80 | } -------------------------------------------------------------------------------- /src/Auth/RealmList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | #include "Common.h" 20 | #include "Network/ByteBuffer.h" 21 | #include 22 | 23 | enum RealmFlags : uint8_t 24 | { 25 | REALM_FLAG_NONE = 0x00, 26 | REALM_FLAG_INVALID = 0x01, 27 | REALM_FLAG_OFFLINE = 0x02, 28 | REALM_FLAG_SPECIFYBUILD = 0x04, 29 | REALM_FLAG_UNK1 = 0x08, 30 | REALM_FLAG_UNK2 = 0x10, 31 | REALM_FLAG_RECOMMENDED = 0x20, 32 | REALM_FLAG_NEW = 0x40, 33 | REALM_FLAG_FULL = 0x80 34 | }; 35 | 36 | struct Realm 37 | { 38 | uint8_t Icon; 39 | bool Lock; 40 | RealmFlags Flags; 41 | std::string Name; 42 | std::string Address; 43 | float Population; 44 | uint8_t Characters; 45 | uint8_t Timezone; 46 | uint8_t ID; 47 | uint8_t MajorVersion; 48 | uint8_t MinorVersion; 49 | uint8_t BugfixVersion; 50 | uint16_t Build; 51 | }; 52 | 53 | class RealmList 54 | { 55 | public: 56 | void Populate(uint32_t count, ByteBuffer &buffer); 57 | void Print(); 58 | 59 | Realm const* GetRealmByName(std::string name); 60 | private: 61 | std::vector list_; 62 | }; -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 Dehravor 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | add_subdirectory(Shared) 17 | add_subdirectory(Auth) 18 | add_subdirectory(World) 19 | 20 | include_directories( 21 | ${CMAKE_SOURCE_DIR} 22 | ${CMAKE_SOURCE_DIR}/dep 23 | ${CMAKE_SOURCE_DIR}/src 24 | ${CMAKE_SOURCE_DIR}/src/Shared 25 | ${CMAKE_SOURCE_DIR}/src/World/Includes 26 | ${CMAKE_CURRENT_SOURCE_DIR} 27 | ${OPENSSL_INCLUDE_DIR} 28 | ) 29 | 30 | add_executable(Clientless Main.cpp) 31 | target_link_libraries(Clientless 32 | ${OPENSSL_LIBRARIES} 33 | Shared 34 | Auth 35 | World 36 | ) 37 | -------------------------------------------------------------------------------- /src/Main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "Config.h" 19 | #include "Session.h" 20 | #include "Auth/AuthSession.h" 21 | #include "World/WorldSession.h" 22 | 23 | int main(int argc, char* argv[]) 24 | { 25 | std::cout << "[Clientless World of Warcraft]" << std::endl; 26 | std::cout << " - Version: " << uint32_t(GameVersion[0]) << "." << uint32_t(GameVersion[1]) << "." << uint32_t(GameVersion[2]) << " (" << GameBuild << ")" << std::endl; 27 | std::cout << " - OS: " << OS << " Platform: " << Platform << " Locale: " << Locale[0] << Locale[1] << Locale[2] << Locale[3] << std::endl; 28 | 29 | std::shared_ptr session(new Session()); 30 | 31 | if (!session->LoadSavedData()) 32 | session->RequestData(); 33 | 34 | session->Print(); 35 | 36 | AuthSession auth(session); 37 | 38 | if (!auth.Authenticate()) 39 | { 40 | std::cerr << "Couldn't authenticate!" << std::endl; 41 | return 1; 42 | } 43 | 44 | WorldSession world(session); 45 | world.Enter(); 46 | 47 | while (world.GetSocket()->IsConnected()) 48 | { 49 | std::string cmd; 50 | std::getline(std::cin, cmd); 51 | 52 | world.HandleConsoleCommand(cmd); 53 | } 54 | 55 | return 0; 56 | } -------------------------------------------------------------------------------- /src/Shared/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 Dehravor 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | file(GLOB_RECURSE sources_Cryptography Cryptography/*.cpp Cryptography/*.h) 17 | file(GLOB_RECURSE sources_Network Network/*.cpp Network/*.h) 18 | 19 | file(GLOB sources_localdir *.cpp *.h) 20 | 21 | set(Shared_SRCS 22 | ${sources_Cryptography} 23 | ${sources_Network} 24 | ${sources_localdir} 25 | ) 26 | 27 | include_directories( 28 | ${CMAKE_SOURCE_DIR} 29 | ${CMAKE_SOURCE_DIR}/dep 30 | ${CMAKE_SOURCE_DIR}/src 31 | ${CMAKE_CURRENT_SOURCE_DIR} 32 | ${CMAKE_CURRENT_SOURCE_DIR}/Cryptography 33 | ${CMAKE_CURRENT_SOURCE_DIR}/Network 34 | ${OPENSSL_INCLUDE_DIR} 35 | ) 36 | 37 | add_library(Shared STATIC 38 | ${Shared_SRCS} 39 | ) 40 | 41 | target_link_libraries(Shared 42 | ${OPENSSL_LIBRARIES} 43 | ) 44 | 45 | if (WIN32) 46 | target_link_libraries(Shared ws2_32) 47 | elseif(UNIX) 48 | target_link_libraries(Shared pthread) 49 | endif (WIN32) -------------------------------------------------------------------------------- /src/Shared/Common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (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, see . 17 | */ 18 | 19 | #pragma once 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | enum TimeConstants 27 | { 28 | MINUTE = 60, 29 | HOUR = MINUTE * 60, 30 | DAY = HOUR * 24, 31 | WEEK = DAY * 7, 32 | MONTH = DAY * 30, 33 | YEAR = MONTH * 12, 34 | IN_MILLISECONDS = 1000 35 | }; -------------------------------------------------------------------------------- /src/Shared/Config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | #include "Common.h" 20 | 21 | static const std::string GameName = "WoW"; 22 | static const uint8_t GameVersion[3] = { 4, 3, 4 }; // Expansion, Major, Minor 23 | static const uint16_t GameBuild = 15595; 24 | static const std::string Platform = "x86"; // x86 | x64 | PPC 25 | static const std::string OS = "OSX"; // Win | OSX 26 | static const uint8_t Locale[4] = { 'e', 'n', 'U', 'S' }; // enUS | enGB | frFR | deDE | koKR | zhCN | zhTW | ruRU | esES | esMX | ptBR 27 | static const uint32_t TimeZone = 0x3C; 28 | static const uint32_t IP = 0x0100007F; -------------------------------------------------------------------------------- /src/Shared/Cryptography/BigNumber.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include "Cryptography/BigNumber.h" 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | BigNumber::BigNumber() 27 | : bn_(BN_new()) 28 | { } 29 | 30 | BigNumber::BigNumber(BigNumber const& bn) 31 | : bn_(BN_dup(bn.bn_)) 32 | { } 33 | 34 | BigNumber::BigNumber(uint32_t val) 35 | : bn_(BN_new()) 36 | { 37 | BN_set_word(bn_, val); 38 | } 39 | 40 | BigNumber::BigNumber(uint8_t const* buffer, int32_t length) 41 | : bn_(BN_new()) 42 | { 43 | SetBinary(buffer, length); 44 | } 45 | 46 | BigNumber::~BigNumber() 47 | { 48 | BN_free(bn_); 49 | } 50 | 51 | void BigNumber::SetZero() 52 | { 53 | BN_zero(bn_); 54 | } 55 | 56 | void BigNumber::SetOne() 57 | { 58 | BN_one(bn_); 59 | } 60 | 61 | void BigNumber::SetUInt32(uint32_t value) 62 | { 63 | BN_set_word(bn_, value); 64 | } 65 | 66 | void BigNumber::SetUInt64(uint64_t value) 67 | { 68 | BN_add_word(bn_, (uint32_t)(value >> 32)); 69 | BN_lshift(bn_, bn_, 32); 70 | BN_add_word(bn_, (uint32_t)(value & 0xFFFFFFFF)); 71 | } 72 | 73 | void BigNumber::SetBinary(uint8_t const* bytes, int32_t len) 74 | { 75 | uint8_t* array = new uint8_t[len]; 76 | 77 | for (int i = 0; i < len; i++) 78 | array[i] = bytes[len - 1 - i]; 79 | 80 | BN_bin2bn(array, len, bn_); 81 | 82 | delete[] array; 83 | } 84 | void BigNumber::SetRandom(int32_t length) 85 | { 86 | BN_rand(bn_, length, 0, 1); 87 | } 88 | 89 | void BigNumber::SetHexString(const char* str) 90 | { 91 | BN_hex2bn(&bn_, str); 92 | } 93 | 94 | void BigNumber::Negate() 95 | { 96 | bn_->neg = (!((bn_)->neg)) & 1; 97 | } 98 | 99 | bool BigNumber::IsNegative() 100 | { 101 | return bn_->neg == 1; 102 | } 103 | 104 | bool BigNumber::IsZero() 105 | { 106 | return BN_is_zero(bn_); 107 | } 108 | 109 | bool BigNumber::IsOne() 110 | { 111 | return BN_is_one(bn_); 112 | } 113 | 114 | bool BigNumber::IsOdd() 115 | { 116 | return BN_is_odd(bn_); 117 | } 118 | 119 | bool BigNumber::IsEven() 120 | { 121 | return !BN_is_odd(bn_); 122 | } 123 | 124 | bool BigNumber::operator==(BigNumber const& bn) 125 | { 126 | return BN_cmp(bn_, bn.bn_) == 0; 127 | } 128 | 129 | bool BigNumber::operator>(BigNumber const& bn) 130 | { 131 | return BN_cmp(bn_, bn.bn_) == 1; 132 | } 133 | 134 | bool BigNumber::operator<(BigNumber const& bn) 135 | { 136 | return BN_cmp(bn_, bn.bn_) == -1; 137 | } 138 | 139 | BigNumber& BigNumber::operator=(BigNumber const& bn) 140 | { 141 | if (this == &bn) 142 | return *this; 143 | 144 | BN_copy(bn_, bn.bn_); 145 | return *this; 146 | } 147 | 148 | BigNumber BigNumber::operator+=(BigNumber const& bn) 149 | { 150 | BN_add(bn_, bn_, bn.bn_); 151 | return *this; 152 | } 153 | 154 | BigNumber BigNumber::operator-=(BigNumber const& bn) 155 | { 156 | BN_sub(bn_, bn_, bn.bn_); 157 | return *this; 158 | } 159 | 160 | BigNumber BigNumber::operator*=(BigNumber const& bn) 161 | { 162 | BN_CTX *bnctx; 163 | 164 | bnctx = BN_CTX_new(); 165 | BN_mul(bn_, bn_, bn.bn_, bnctx); 166 | BN_CTX_free(bnctx); 167 | 168 | return *this; 169 | } 170 | 171 | BigNumber BigNumber::operator/=(BigNumber const& bn) 172 | { 173 | BN_CTX *bnctx; 174 | 175 | bnctx = BN_CTX_new(); 176 | BN_div(bn_, nullptr, bn_, bn.bn_, bnctx); 177 | BN_CTX_free(bnctx); 178 | 179 | return *this; 180 | } 181 | 182 | BigNumber BigNumber::operator%=(BigNumber const& bn) 183 | { 184 | BN_CTX *bnctx; 185 | 186 | bnctx = BN_CTX_new(); 187 | BN_mod(bn_, bn_, bn.bn_, bnctx); 188 | BN_CTX_free(bnctx); 189 | 190 | return *this; 191 | } 192 | 193 | BigNumber BigNumber::Exp(BigNumber const& bn) 194 | { 195 | BigNumber ret; 196 | BN_CTX *bnctx; 197 | 198 | bnctx = BN_CTX_new(); 199 | BN_exp(ret.bn_, bn_, bn.bn_, bnctx); 200 | BN_CTX_free(bnctx); 201 | 202 | return ret; 203 | } 204 | 205 | BigNumber BigNumber::ModExp(BigNumber const& bn1, BigNumber const& bn2) 206 | { 207 | BigNumber ret; 208 | BN_CTX *bnctx; 209 | 210 | bnctx = BN_CTX_new(); 211 | BN_mod_exp(ret.bn_, bn_, bn1.bn_, bn2.bn_, bnctx); 212 | BN_CTX_free(bnctx); 213 | 214 | return ret; 215 | } 216 | 217 | int32_t BigNumber::GetNumBytes(void) const 218 | { 219 | return BN_num_bytes(bn_); 220 | } 221 | 222 | uint32_t BigNumber::AsDword() 223 | { 224 | return (uint32_t)BN_get_word(bn_); 225 | } 226 | 227 | bool BigNumber::isZero() const 228 | { 229 | return BN_is_zero(bn_); 230 | } 231 | 232 | std::unique_ptr BigNumber::AsByteArray(int32_t minSize, bool littleEndian) const 233 | { 234 | int length = (minSize >= GetNumBytes()) ? minSize : GetNumBytes(); 235 | 236 | uint8_t* array = new uint8_t[length]; 237 | 238 | // If we need more bytes than length of BigNumber set the rest to 0 239 | if (length > GetNumBytes()) 240 | memset((void*)array, 0, length); 241 | 242 | BN_bn2bin(bn_, (unsigned char *)array); 243 | 244 | // openssl's BN stores data internally in big endian format, reverse if little endian desired 245 | if (littleEndian) 246 | std::reverse(array, array + length); 247 | 248 | std::unique_ptr ret(array); 249 | return ret; 250 | } 251 | 252 | char* BigNumber::AsHexStr() const 253 | { 254 | return BN_bn2hex(bn_); 255 | } 256 | 257 | char* BigNumber::AsDecStr() const 258 | { 259 | return BN_bn2dec(bn_); 260 | } 261 | 262 | -------------------------------------------------------------------------------- /src/Shared/Cryptography/BigNumber.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | #include 22 | #include 23 | 24 | struct bignum_st; 25 | 26 | class BigNumber 27 | { 28 | public: 29 | BigNumber(); 30 | BigNumber(BigNumber const& bn); 31 | BigNumber(uint32_t val); 32 | BigNumber(uint8_t const* buffer, int32_t length); 33 | ~BigNumber(); 34 | 35 | void SetZero(); 36 | void SetOne(); 37 | void SetUInt32(uint32_t value); 38 | void SetUInt64(uint64_t value); 39 | void SetBinary(uint8_t const* bytes, int32_t len); 40 | void SetRandom(int32_t length); 41 | void SetHexString(const char* str); 42 | 43 | void Negate(); 44 | bool IsNegative(); 45 | bool IsZero(); 46 | bool IsOne(); 47 | bool IsOdd(); 48 | bool IsEven(); 49 | 50 | bool operator==(BigNumber const& bn); 51 | bool operator>(BigNumber const& bn); 52 | bool operator<(BigNumber const& bn); 53 | 54 | BigNumber& operator=(BigNumber const& bn); 55 | 56 | BigNumber operator+=(BigNumber const& bn); 57 | BigNumber operator+(BigNumber const& bn) 58 | { 59 | BigNumber t(*this); 60 | return t += bn; 61 | } 62 | 63 | BigNumber operator-=(BigNumber const& bn); 64 | BigNumber operator-(BigNumber const& bn) 65 | { 66 | BigNumber t(*this); 67 | return t -= bn; 68 | } 69 | 70 | BigNumber operator*=(BigNumber const& bn); 71 | BigNumber operator*(BigNumber const& bn) 72 | { 73 | BigNumber t(*this); 74 | return t *= bn; 75 | } 76 | 77 | BigNumber operator/=(BigNumber const& bn); 78 | BigNumber operator/(BigNumber const& bn) 79 | { 80 | BigNumber t(*this); 81 | return t /= bn; 82 | } 83 | 84 | BigNumber operator%=(BigNumber const& bn); 85 | BigNumber operator%(BigNumber const& bn) 86 | { 87 | BigNumber t(*this); 88 | return t %= bn; 89 | } 90 | 91 | bool isZero() const; 92 | 93 | BigNumber ModExp(BigNumber const& bn1, BigNumber const& bn2); 94 | BigNumber Exp(BigNumber const&); 95 | 96 | int32_t GetNumBytes(void) const; 97 | 98 | struct bignum_st* BN() { return bn_; } 99 | 100 | uint32_t AsDword(); 101 | 102 | std::unique_ptr AsByteArray(int32_t minSize = 0, bool littleEndian = true) const; 103 | 104 | char* AsHexStr() const; 105 | char* AsDecStr() const; 106 | 107 | private: 108 | struct bignum_st *bn_; 109 | }; 110 | 111 | -------------------------------------------------------------------------------- /src/Shared/Cryptography/HMACSHA1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include "HMACSHA1.h" 21 | #include "BigNumber.h" 22 | 23 | HMACSHA1::HMACSHA1(uint8_t* seed, uint32_t len) 24 | { 25 | HMAC_CTX_init(&ctx_); 26 | HMAC_Init_ex(&ctx_, seed, len, EVP_sha1(), nullptr); 27 | } 28 | 29 | HMACSHA1::~HMACSHA1() 30 | { 31 | HMAC_CTX_cleanup(&ctx_); 32 | } 33 | 34 | void HMACSHA1::Update(const uint8_t* data, int32_t len) 35 | { 36 | HMAC_Update(&ctx_, data, len); 37 | } 38 | 39 | void HMACSHA1::Update(const std::string &str) 40 | { 41 | Update((const uint8_t*)str.c_str(), str.length()); 42 | } 43 | 44 | void HMACSHA1::Update(const BigNumber &bn) 45 | { 46 | Update(bn.AsByteArray().get(), bn.GetNumBytes()); 47 | } 48 | 49 | void HMACSHA1::Finalize() 50 | { 51 | HMAC_Final(&ctx_, digest_, &digestLength_); 52 | } 53 | -------------------------------------------------------------------------------- /src/Shared/Cryptography/HMACSHA1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | #include "Common.h" 22 | #include 23 | #include 24 | 25 | class BigNumber; 26 | 27 | class HMACSHA1 28 | { 29 | public: 30 | HMACSHA1(uint8_t* seed, uint32_t len); 31 | ~HMACSHA1(); 32 | 33 | void Update(const uint8_t* data, int32_t len); 34 | void Update(const std::string &str); 35 | void Update(const BigNumber &bn); 36 | void Finalize(); 37 | 38 | uint8_t* GetDigest() { return digest_; } 39 | uint32_t GetDigestLength() { return digestLength_; } 40 | private: 41 | HMAC_CTX ctx_; 42 | uint8_t digest_[EVP_MAX_MD_SIZE]; 43 | uint32_t digestLength_; 44 | }; -------------------------------------------------------------------------------- /src/Shared/Cryptography/PacketRC4.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include "PacketRC4.h" 21 | #include "BigNumber.h" 22 | #include "HMACSHA1.h" 23 | #include 24 | 25 | PacketRC4::PacketRC4() : ready_(false), decrypt_(20), encrypt_(20) 26 | { 27 | } 28 | 29 | PacketRC4::~PacketRC4() 30 | { 31 | } 32 | 33 | void PacketRC4::Initialize(const BigNumber* key) 34 | { 35 | // Decryption 36 | uint8_t decryptKey[16] = { 0xCC, 0x98, 0xAE, 0x04, 0xE8, 0x97, 0xEA, 0xCA, 0x12, 0xDD, 0xC0, 0x93, 0x42, 0x91, 0x53, 0x57 }; 37 | 38 | HMACSHA1 decryptHMAC(decryptKey, 16); 39 | decryptHMAC.Update(*key); 40 | decryptHMAC.Finalize(); 41 | 42 | decrypt_.Initialize(decryptHMAC.GetDigest()); 43 | 44 | // Encryption 45 | uint8_t encryptKey[16] = { 0xC2, 0xB3, 0x72, 0x3C, 0xC6, 0xAE, 0xD9, 0xB5, 0x34, 0x3C, 0x53, 0xEE, 0x2F, 0x43, 0x67, 0xCE }; 46 | 47 | HMACSHA1 encryptHMAC(encryptKey, 16); 48 | encryptHMAC.Update(*key); 49 | encryptHMAC.Finalize(); 50 | 51 | encrypt_.Initialize(encryptHMAC.GetDigest()); 52 | 53 | // Drop-N 54 | uint8_t drop[1024]; 55 | memset(drop, 0, 1024); 56 | 57 | encrypt_.Update(drop, 1024); 58 | decrypt_.Update(drop, 1024); 59 | 60 | ready_ = true; 61 | } 62 | 63 | void PacketRC4::Reset() 64 | { 65 | ready_ = false; 66 | } 67 | 68 | void PacketRC4::DecryptReceived(uint8_t* data, int32_t len) 69 | { 70 | if (!ready_) 71 | return; 72 | 73 | decrypt_.Update(data, len); 74 | } 75 | 76 | void PacketRC4::EncryptSend(uint8_t* data, int32_t len) 77 | { 78 | if (!ready_) 79 | return; 80 | 81 | encrypt_.Update(data, len); 82 | } 83 | -------------------------------------------------------------------------------- /src/Shared/Cryptography/PacketRC4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include "RC4.h" 23 | 24 | class BigNumber; 25 | 26 | class PacketRC4 27 | { 28 | public: 29 | PacketRC4(); 30 | ~PacketRC4(); 31 | 32 | void Initialize(const BigNumber* key); 33 | void Reset(); 34 | void DecryptReceived(uint8_t* data, int32_t len); 35 | void EncryptSend(uint8_t* data, int32_t len); 36 | bool IsInitialized() { return ready_; } 37 | 38 | private: 39 | bool ready_; 40 | RC4 decrypt_; 41 | RC4 encrypt_; 42 | }; -------------------------------------------------------------------------------- /src/Shared/Cryptography/RC4.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include "RC4.h" 21 | 22 | RC4::RC4(int32_t len) : ctx_() 23 | { 24 | EVP_CIPHER_CTX_init(&ctx_); 25 | EVP_EncryptInit_ex(&ctx_, EVP_rc4(), nullptr, nullptr, nullptr); 26 | EVP_CIPHER_CTX_set_key_length(&ctx_, len); 27 | } 28 | 29 | RC4::RC4(uint8_t* seed, int32_t len) : ctx_() 30 | { 31 | EVP_CIPHER_CTX_init(&ctx_); 32 | EVP_EncryptInit_ex(&ctx_, EVP_rc4(), nullptr, nullptr, nullptr); 33 | EVP_CIPHER_CTX_set_key_length(&ctx_, len); 34 | EVP_EncryptInit_ex(&ctx_, nullptr, nullptr, seed, nullptr); 35 | } 36 | 37 | RC4::~RC4() 38 | { 39 | EVP_CIPHER_CTX_cleanup(&ctx_); 40 | } 41 | 42 | void RC4::Initialize(uint8_t* seed) 43 | { 44 | EVP_EncryptInit_ex(&ctx_, nullptr, nullptr, seed, nullptr); 45 | } 46 | 47 | void RC4::Update(uint8_t* data, int32_t len) 48 | { 49 | int32_t outlen = 0; 50 | EVP_EncryptUpdate(&ctx_, data, &outlen, data, len); 51 | EVP_EncryptFinal_ex(&ctx_, data, &outlen); 52 | } 53 | -------------------------------------------------------------------------------- /src/Shared/Cryptography/RC4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | #include 22 | #include 23 | 24 | class RC4 25 | { 26 | public: 27 | RC4(int32_t len); 28 | RC4(uint8_t* seed, int32_t len); 29 | ~RC4(); 30 | 31 | void Initialize(uint8_t* seed); 32 | void Update(uint8_t* data, int32_t len); 33 | private: 34 | EVP_CIPHER_CTX ctx_; 35 | }; 36 | -------------------------------------------------------------------------------- /src/Shared/Cryptography/SHA1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include "SHA1.h" 21 | #include "BigNumber.h" 22 | 23 | SHA1::SHA1() : digestLength_(0) 24 | { 25 | EVP_MD_CTX_init(&ctx_); 26 | EVP_DigestInit_ex(&ctx_, EVP_sha1(), nullptr); 27 | } 28 | 29 | SHA1::~SHA1() 30 | { 31 | EVP_MD_CTX_cleanup(&ctx_); 32 | } 33 | 34 | void SHA1::Update(const uint8_t* data, int32_t len) 35 | { 36 | EVP_DigestUpdate(&ctx_, data, len); 37 | } 38 | 39 | void SHA1::Update(const std::string &str) 40 | { 41 | Update((const uint8_t*)str.c_str(), str.length()); 42 | } 43 | 44 | void SHA1::Update(const BigNumber &bn) 45 | { 46 | Update(bn.AsByteArray().get(), bn.GetNumBytes()); 47 | } 48 | 49 | void SHA1::Finalize() 50 | { 51 | EVP_DigestFinal_ex(&ctx_, digest_, &digestLength_); 52 | } 53 | -------------------------------------------------------------------------------- /src/Shared/Cryptography/SHA1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | #include "Common.h" 22 | #include 23 | 24 | class BigNumber; 25 | 26 | class SHA1 27 | { 28 | public: 29 | SHA1(); 30 | ~SHA1(); 31 | 32 | void Update(const uint8_t* data, int32_t len); 33 | void Update(const std::string &str); 34 | void Update(const BigNumber &bn); 35 | void Finalize(); 36 | 37 | uint8_t* GetDigest() { return digest_; }; 38 | uint32_t GetDigestLength() { return digestLength_; }; 39 | private: 40 | EVP_MD_CTX ctx_; 41 | uint8_t digest_[EVP_MAX_MD_SIZE]; 42 | uint32_t digestLength_; 43 | }; 44 | -------------------------------------------------------------------------------- /src/Shared/Cryptography/SHA256.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include "SHA256.h" 21 | #include "BigNumber.h" 22 | 23 | SHA256::SHA256() : digestLength_(0) 24 | { 25 | EVP_MD_CTX_init(&ctx_); 26 | EVP_DigestInit_ex(&ctx_, EVP_sha256(), nullptr); 27 | } 28 | 29 | SHA256::~SHA256() 30 | { 31 | EVP_MD_CTX_cleanup(&ctx_); 32 | } 33 | 34 | void SHA256::Update(const uint8_t* data, int32_t len) 35 | { 36 | EVP_DigestUpdate(&ctx_, data, len); 37 | } 38 | 39 | void SHA256::Update(const std::string &str) 40 | { 41 | Update((const uint8_t*)str.c_str(), str.length()); 42 | } 43 | 44 | void SHA256::Update(BigNumber &bn) 45 | { 46 | Update(bn.AsByteArray().get(), bn.GetNumBytes()); 47 | } 48 | 49 | void SHA256::Finalize() 50 | { 51 | EVP_DigestFinal_ex(&ctx_, digest_, &digestLength_); 52 | } 53 | -------------------------------------------------------------------------------- /src/Shared/Cryptography/SHA256.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | #include "Common.h" 22 | #include 23 | 24 | class BigNumber; 25 | 26 | class SHA256 27 | { 28 | public: 29 | SHA256(); 30 | ~SHA256(); 31 | 32 | void Update(const uint8_t* data, int32_t len); 33 | void Update(const std::string &str); 34 | void Update(BigNumber &bn); 35 | void Finalize(); 36 | 37 | uint8_t* GetDigest() { return digest_; }; 38 | uint32_t GetDigestLength() { return digestLength_; }; 39 | private: 40 | EVP_MD_CTX ctx_; 41 | uint8_t digest_[EVP_MAX_MD_SIZE]; 42 | uint32_t digestLength_; 43 | }; -------------------------------------------------------------------------------- /src/Shared/Cryptography/SRP6.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "SRP6.h" 19 | #include 20 | 21 | SRP6::SRP6() 22 | { 23 | } 24 | 25 | SRP6::~SRP6() 26 | { 27 | } 28 | 29 | void SRP6::Reset() 30 | { 31 | AccountName = ""; 32 | AccountPassword = ""; 33 | N.SetZero(); 34 | g.SetZero(); 35 | k.SetUInt32(3); 36 | a.SetRandom(19 * 8); 37 | B.SetZero(); 38 | s.SetZero(); 39 | A.SetZero(); 40 | I.SetZero(); 41 | x.SetZero(); 42 | u.SetZero(); 43 | S.SetZero(); 44 | K.SetZero(); 45 | M1.SetZero(); 46 | M2.SetZero(); 47 | } 48 | 49 | void SRP6::SetCredentials(std::string name, std::string password) 50 | { 51 | AccountName = name; 52 | AccountPassword = password; 53 | } 54 | void SRP6::SetServerModulus(uint8_t* buffer, uint32_t length) 55 | { 56 | N.SetBinary(buffer, length); 57 | } 58 | 59 | void SRP6::SetServerGenerator(uint8_t* buffer, uint32_t length) 60 | { 61 | g.SetBinary(buffer, length); 62 | } 63 | 64 | void SRP6::SetServerEphemeralB(uint8_t* buffer, uint32_t length) 65 | { 66 | B.SetBinary(buffer, length); 67 | } 68 | 69 | void SRP6::SetServerSalt(uint8_t* buffer, uint32_t length) 70 | { 71 | s.SetBinary(buffer, length); 72 | } 73 | 74 | void SRP6::Calculate() 75 | { 76 | // Safeguards 77 | 78 | if (B.IsZero() || (B % N).IsZero()) 79 | { 80 | std::cerr << "SRP safeguard: B (mod N) was zero!" << std::endl; 81 | return; 82 | } 83 | 84 | if (a > N || a == N) 85 | { 86 | std::cerr << "SRP safeguard: a must be less than N!" << std::endl; 87 | return; 88 | } 89 | 90 | // I = H(g) xor H(N) 91 | 92 | SHA1 hg; 93 | hg.Update(g); 94 | hg.Finalize(); 95 | 96 | SHA1 hN; 97 | hN.Update(N); 98 | hN.Finalize(); 99 | 100 | uint8_t bI[20]; 101 | 102 | for (uint32_t i = 0; i < 20; i++) 103 | bI[i] = hg.GetDigest()[i] ^ hN.GetDigest()[i]; 104 | 105 | I.SetBinary(bI, 20); 106 | 107 | // x = H(s, H(C, ":", P)); 108 | 109 | SHA1 hCredentials; 110 | hCredentials.Update(AccountName + ":" + AccountPassword); 111 | hCredentials.Finalize(); 112 | 113 | SHA1 hx; 114 | hx.Update(s); 115 | hx.Update(hCredentials.GetDigest(), hCredentials.GetDigestLength()); 116 | hx.Finalize(); 117 | 118 | x.SetBinary(hx.GetDigest(), hx.GetDigestLength()); 119 | 120 | // A 121 | 122 | A = g.ModExp(a, N); 123 | 124 | // u = H(A, B) 125 | 126 | SHA1 hu; 127 | hu.Update(A); 128 | hu.Update(B); 129 | hu.Finalize(); 130 | 131 | u.SetBinary(hu.GetDigest(), hu.GetDigestLength()); 132 | 133 | if (u.IsZero()) 134 | { 135 | std::cerr << "SRP safeguard: 'u' must not be zero!" << std::endl; 136 | return; 137 | } 138 | 139 | // S 140 | 141 | S = (B - k * g.ModExp(x, N)).ModExp((a + u * x), N); 142 | 143 | if (S.IsZero() || S.IsNegative()) 144 | { 145 | std::cerr << "SRP safeguard: S must be greater than 0!" << std::endl; 146 | return; 147 | } 148 | 149 | // K 150 | 151 | uint8_t SPart[2][16]; 152 | 153 | for (int i = 0; i < 16; i++) 154 | { 155 | SPart[0][i] = S.AsByteArray()[i * 2]; 156 | SPart[1][i] = S.AsByteArray()[i * 2 + 1]; 157 | } 158 | 159 | SHA1 hEven; 160 | hEven.Update(SPart[0], 16); 161 | hEven.Finalize(); 162 | 163 | SHA1 hOdd; 164 | hOdd.Update(SPart[1], 16); 165 | hOdd.Finalize(); 166 | 167 | uint8_t bK[40]; 168 | 169 | for (uint32_t i = 0; i < 20; i++) 170 | { 171 | bK[i * 2] = hEven.GetDigest()[i]; 172 | bK[i * 2 + 1] = hOdd.GetDigest()[i]; 173 | } 174 | 175 | K.SetBinary(bK, sizeof(bK)); 176 | 177 | // M1 = H(I, H(C), s, A, B, K) 178 | 179 | SHA1 hUsername; 180 | hUsername.Update(AccountName); 181 | hUsername.Finalize(); 182 | 183 | SHA1 hM1; 184 | hM1.Update(I); 185 | hM1.Update(hUsername.GetDigest(), hUsername.GetDigestLength()); 186 | hM1.Update(s); 187 | hM1.Update(A); 188 | hM1.Update(B); 189 | hM1.Update(K); 190 | hM1.Finalize(); 191 | 192 | M1.SetBinary(hM1.GetDigest(), hM1.GetDigestLength()); 193 | 194 | // M2 = H(A, M1, K) 195 | 196 | SHA1 hM2; 197 | hM2.Update(A); 198 | hM2.Update(M1); 199 | hM2.Update(K); 200 | hM2.Finalize(); 201 | 202 | M2.SetBinary(hM2.GetDigest(), hM2.GetDigestLength()); 203 | 204 | /* 205 | print("%s", "N: %s", N.AsHexString().c_str()); 206 | print("%s", "g: %s", g.AsHexString().c_str()); 207 | print("%s", "k: %s", k.AsHexString().c_str()); 208 | print("%s", "B: %s", B.AsHexString().c_str()); 209 | print("%s", "s: %s", s.AsHexString().c_str()); 210 | print("%s", "a: %s", a.AsHexString().c_str()); 211 | print("%s", "A: %s", A.AsHexString().c_str()); 212 | print("%s", "I: %s", I.AsHexString().c_str()); 213 | print("%s", "x: %s", x.AsHexString().c_str()); 214 | print("%s", "u: %s", u.AsHexString().c_str()); 215 | print("%s", "S: %s", S.AsHexString().c_str()); 216 | print("%s", "K: %s", K.AsHexString().c_str()); 217 | print("%s", "M1: %s", M1.AsHexString().c_str()); 218 | print("%s", "M2: %s", M2.AsHexString().c_str()); 219 | */ 220 | } 221 | 222 | bool SRP6::IsValidM2(uint8_t* buffer, uint32_t length) 223 | { 224 | BigNumber temp(buffer, length); 225 | return temp == M2; 226 | } 227 | -------------------------------------------------------------------------------- /src/Shared/Cryptography/SRP6.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | #include "Common.h" 20 | #include "Cryptography/BigNumber.h" 21 | #include "Cryptography/SHA1.h" 22 | 23 | class SRP6 24 | { 25 | public: 26 | SRP6(); 27 | ~SRP6(); 28 | 29 | void Reset(); 30 | void SetCredentials(std::string name, std::string password); 31 | void SetServerModulus(uint8_t* buffer, uint32_t length); 32 | void SetServerGenerator(uint8_t* buffer, uint32_t length); 33 | void SetServerEphemeralB(uint8_t* buffer, uint32_t length); 34 | void SetServerSalt(uint8_t* buffer, uint32_t length); 35 | void Calculate(); 36 | bool IsValidM2(uint8_t* buffer, uint32_t length); 37 | 38 | BigNumber* GetClientEphemeralA() { return &A; } 39 | BigNumber* GetClientM1() { return &M1; } 40 | BigNumber* GetClientK() { return &K; } 41 | 42 | private: 43 | std::string AccountName; 44 | std::string AccountPassword; 45 | 46 | BigNumber N; // Modulus 47 | BigNumber g; // Generator 48 | BigNumber k; // Multiplier 49 | BigNumber B; // Server public 50 | BigNumber s; // Server salt 51 | BigNumber a; // Client secret 52 | BigNumber A; // Client public 53 | BigNumber I; // g hash ^ N hash 54 | BigNumber x; // Client credentials 55 | BigNumber u; // Scrambling 56 | BigNumber S; // Key 57 | BigNumber K; // Key based on S 58 | BigNumber M1; // M1 59 | BigNumber M2; // M2 60 | }; 61 | -------------------------------------------------------------------------------- /src/Shared/Cryptography/WardenRC4.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include "WardenRC4.h" 21 | #include "SHA1.h" 22 | #include 23 | 24 | WardenRC4::WardenRC4() : ready_(false), encryptionStream_(16), decryptionStream_(16) 25 | { 26 | } 27 | 28 | WardenRC4::~WardenRC4() 29 | { 30 | } 31 | 32 | void WardenRC4::Initialize(const BigNumber* key) 33 | { 34 | uint32_t half = key->GetNumBytes() / 2; 35 | 36 | memset(buffer_[0], 0, 20); 37 | 38 | SHA1 firstHash; 39 | firstHash.Update(key->AsByteArray().get(), half); 40 | firstHash.Finalize(); 41 | 42 | uint32_t dglen = firstHash.GetDigestLength(); 43 | memcpy(buffer_[1], firstHash.GetDigest(), firstHash.GetDigestLength()); 44 | 45 | SHA1 secondHash; 46 | secondHash.Update(key->AsByteArray().get() + half, half); 47 | secondHash.Finalize(); 48 | 49 | memcpy(buffer_[2], secondHash.GetDigest(), secondHash.GetDigestLength()); 50 | 51 | FillUp(); 52 | 53 | uint8_t encryptionKey[16], decryptionKey[16]; 54 | 55 | Generate(&encryptionKey[0], 16); 56 | encryptionStream_.Initialize(encryptionKey); 57 | 58 | Generate(&decryptionKey[0], 16); 59 | decryptionStream_.Initialize(decryptionKey); 60 | 61 | ready_ = true; 62 | } 63 | 64 | bool WardenRC4::IsInitialized() 65 | { 66 | return ready_; 67 | } 68 | 69 | void WardenRC4::Encrypt(uint8_t* data, uint32_t size) 70 | { 71 | if (!ready_) 72 | return; 73 | 74 | encryptionStream_.Update(data, size); 75 | } 76 | 77 | void WardenRC4::Decrypt(uint8_t* data, uint32_t size) 78 | { 79 | if (!ready_) 80 | return; 81 | 82 | decryptionStream_.Update(data, size); 83 | } 84 | 85 | void WardenRC4::FillUp() 86 | { 87 | SHA1 hash; 88 | hash.Update(buffer_[1], 20); 89 | hash.Update(buffer_[0], 20); 90 | hash.Update(buffer_[2], 20); 91 | hash.Finalize(); 92 | 93 | memcpy(buffer_[0], hash.GetDigest(), hash.GetDigestLength()); 94 | 95 | taken_ = 0; 96 | } 97 | 98 | void WardenRC4::Generate(uint8_t* buffer, uint32_t size) 99 | { 100 | for (uint32_t i = 0; i < size; ++i) 101 | { 102 | if (taken_ == 20) 103 | FillUp(); 104 | 105 | assert(taken_ < 20); 106 | 107 | buffer[i] = buffer_[0][taken_]; 108 | taken_++; 109 | } 110 | } -------------------------------------------------------------------------------- /src/Shared/Cryptography/WardenRC4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | #include 22 | #include "RC4.h" 23 | #include "BigNumber.h" 24 | 25 | class WardenRC4 26 | { 27 | public: 28 | WardenRC4(); 29 | ~WardenRC4(); 30 | 31 | void Initialize(const BigNumber* key); 32 | bool IsInitialized(); 33 | 34 | void Encrypt(uint8_t* data, uint32_t size); 35 | void Decrypt(uint8_t* data, uint32_t size); 36 | 37 | private: 38 | bool ready_; 39 | uint32_t taken_; 40 | uint8_t buffer_[3][20]; 41 | RC4 encryptionStream_; 42 | RC4 decryptionStream_; 43 | 44 | void FillUp(); 45 | void Generate(uint8_t* buffer, uint32_t size); 46 | }; -------------------------------------------------------------------------------- /src/Shared/Network/ByteBuffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include "ByteBuffer.h" 21 | #include 22 | 23 | #if _MSC_VER 24 | #define snprintf _snprintf_s 25 | #endif 26 | 27 | ByteBufferPositionException::ByteBufferPositionException(bool add, size_t pos, 28 | size_t size, size_t valueSize) 29 | { 30 | std::ostringstream ss; 31 | 32 | ss << "Attempted to " << (add ? "put" : "get") << " value with size: " 33 | << valueSize << " in ByteBuffer (pos: " << pos << " size: " << size 34 | << ")"; 35 | 36 | message().assign(ss.str()); 37 | } 38 | 39 | ByteBufferSourceException::ByteBufferSourceException(size_t pos, size_t size, 40 | size_t valueSize) 41 | { 42 | std::ostringstream ss; 43 | ss << "Attempted to put a " 44 | << (valueSize > 0 ? "nullptr" : "zero-sized value") 45 | << " in ByteBuffer (pos: " << pos << " size: " << size << ")"; 46 | 47 | message().assign(ss.str()); 48 | } 49 | 50 | void ByteBuffer::print_storage() const 51 | { 52 | std::ostringstream o; 53 | o << "STORAGE_SIZE: " << size(); 54 | for (uint32_t i = 0; i < size(); ++i) 55 | o << read(i) << " - "; 56 | o << " "; 57 | std::cout << o.str() << std::endl; 58 | } 59 | 60 | void ByteBuffer::textlike() const 61 | { 62 | std::ostringstream o; 63 | o << "STORAGE_SIZE: " << size(); 64 | for (uint32_t i = 0; i < size(); ++i) 65 | { 66 | char buf[1]; 67 | snprintf(buf, 1, "%c", read(i)); 68 | o << buf; 69 | } 70 | o << " "; 71 | std::cout << o.str() << std::endl; 72 | } 73 | 74 | void ByteBuffer::hexlike() const 75 | { 76 | std::cout << "BEGIN" << std::endl; 77 | 78 | for (uint32_t i = 0; i < size(); i++) 79 | printf("0x%02X ", read(i)); 80 | 81 | std::cout << std::endl << "END" << std::endl; 82 | } 83 | -------------------------------------------------------------------------------- /src/Shared/Network/ByteConverter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /** ByteConverter reverse your byte order. This is use 21 | for cross platform where they have different endians. 22 | */ 23 | 24 | #pragma once 25 | #include 26 | #include 27 | 28 | namespace ByteConverter 29 | { 30 | template 31 | inline void convert(char *val) 32 | { 33 | std::swap(*val, *(val + T - 1)); 34 | convert(val + 1); 35 | } 36 | 37 | template<> inline void convert<0>(char *) { } 38 | template<> inline void convert<1>(char *) { } // ignore central byte 39 | 40 | template inline void apply(T *val) 41 | { 42 | convert((char *)(val)); 43 | } 44 | 45 | inline bool IsBigEndian() 46 | { 47 | union { 48 | uint32_t i; 49 | char c[4]; 50 | } bint = { 0x01020304 }; 51 | 52 | return bint.c[0] == 1; 53 | } 54 | } 55 | 56 | template inline void EndianConvert(T& val) 57 | { 58 | if (!ByteConverter::IsBigEndian()) 59 | return; 60 | 61 | ByteConverter::apply(&val); 62 | } 63 | 64 | template inline void EndianConvertReverse(T& val) 65 | { 66 | if (ByteConverter::IsBigEndian()) 67 | return; 68 | 69 | ByteConverter::apply(&val); 70 | } 71 | 72 | template inline void EndianConvertPtr(void* val) 73 | { 74 | if (!ByteConverter::IsBigEndian()) 75 | return; 76 | 77 | ByteConverter::apply(val); 78 | } 79 | 80 | template inline void EndianConvertPtrReverse(void* val) 81 | { 82 | if (ByteConverter::IsBigEndian()) 83 | return; 84 | 85 | ByteConverter::apply(val); 86 | } 87 | 88 | template void EndianConvert(T*); // will generate link error 89 | template void EndianConvertReverse(T*); // will generate link error 90 | 91 | inline void EndianConvert(uint8_t&) { } 92 | inline void EndianConvert(int8_t&) { } 93 | inline void EndianConvertReverse(uint8_t&) { } 94 | inline void EndianConvertReverse(int8_t&) { } 95 | -------------------------------------------------------------------------------- /src/Shared/Network/TCPSocket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "TCPSocket.h" 19 | 20 | #ifdef _WIN32 21 | #include 22 | #else 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #define SD_BOTH SHUT_RDWR 30 | #define INVALID_SOCKET (SOCKET)(~0) 31 | #define SOCKET_ERROR (-1) 32 | #endif 33 | 34 | TCPSocket::TCPSocket() : socket_(INVALID_SOCKET) 35 | { 36 | #ifdef _WIN32 37 | WSADATA data; 38 | WSAStartup(MAKEWORD(2, 2), &data); 39 | #endif 40 | } 41 | 42 | TCPSocket::~TCPSocket() 43 | { 44 | #ifdef _WIN32 45 | WSACleanup(); 46 | #endif 47 | } 48 | 49 | bool TCPSocket::Connect(std::string address) 50 | { 51 | size_t pos = address.find(':'); 52 | 53 | std::string host = address.substr(0, pos); 54 | std::string port = "3724"; 55 | 56 | if (pos != std::string::npos) 57 | port = address.substr(pos+1); 58 | 59 | struct addrinfo hints; 60 | memset(&hints, 0, sizeof(hints)); 61 | hints.ai_family = AF_INET; 62 | hints.ai_socktype = SOCK_STREAM; 63 | 64 | struct addrinfo* serverinfo = nullptr; 65 | 66 | if (getaddrinfo(host.c_str(), port.c_str(), &hints, &serverinfo)) 67 | return false; 68 | 69 | struct addrinfo* tmp = nullptr; 70 | 71 | for (tmp = serverinfo; tmp != nullptr; tmp = tmp->ai_next) 72 | { 73 | socket_ = socket(tmp->ai_family, tmp->ai_socktype, tmp->ai_protocol); 74 | 75 | if (socket_ == INVALID_SOCKET) 76 | continue; 77 | 78 | if (connect(socket_, tmp->ai_addr, tmp->ai_addrlen) == SOCKET_ERROR) 79 | { 80 | Disconnect(); 81 | continue; 82 | } 83 | 84 | break; 85 | } 86 | 87 | freeaddrinfo(serverinfo); 88 | return socket_ != INVALID_SOCKET; 89 | } 90 | 91 | void TCPSocket::Disconnect() 92 | { 93 | if (socket_ != INVALID_SOCKET) 94 | { 95 | shutdown(socket_, SD_BOTH); 96 | 97 | #ifdef _WIN32 98 | closesocket(socket_); 99 | #else 100 | close(socket_); 101 | #endif 102 | 103 | socket_ = INVALID_SOCKET; 104 | } 105 | } 106 | 107 | bool TCPSocket::IsConnected() 108 | { 109 | return socket_ != INVALID_SOCKET; 110 | } 111 | 112 | int32_t TCPSocket::Read(char* buffer, uint32_t length) 113 | { 114 | int32_t result = recv(socket_, buffer, length, MSG_WAITALL); 115 | 116 | if (!result) 117 | { 118 | Disconnect(); 119 | return 0; 120 | } 121 | 122 | if (result == SOCKET_ERROR) 123 | { 124 | Disconnect(); 125 | return 0; 126 | } 127 | 128 | assert(result == length); 129 | 130 | return result; 131 | } 132 | 133 | int32_t TCPSocket::Read(ByteBuffer* buffer, uint32_t length) 134 | { 135 | char* tmp = new char[length]; 136 | 137 | int32_t result = Read(tmp, length); 138 | buffer->append(tmp, length); 139 | 140 | delete[] tmp; 141 | return result; 142 | } 143 | 144 | int32_t TCPSocket::Send(uint8_t const* buffer, uint32_t length) 145 | { 146 | int32_t result = send(socket_, reinterpret_cast(buffer), length, 0); 147 | 148 | if (!result) 149 | { 150 | Disconnect(); 151 | return 0; 152 | } 153 | 154 | if (result == SOCKET_ERROR) 155 | { 156 | Disconnect(); 157 | return 0; 158 | } 159 | 160 | assert(result == length); 161 | 162 | return result; 163 | } -------------------------------------------------------------------------------- /src/Shared/Network/TCPSocket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include "ByteBuffer.h" 21 | 22 | #ifdef _WIN32 23 | #include 24 | #else 25 | typedef unsigned int SOCKET; 26 | #endif 27 | 28 | class TCPSocket 29 | { 30 | public: 31 | TCPSocket(); 32 | ~TCPSocket(); 33 | 34 | virtual bool Connect(std::string address); 35 | virtual void Disconnect(); 36 | bool IsConnected(); 37 | 38 | int32_t Read(char* buffer, uint32_t length); 39 | int32_t Read(ByteBuffer* buffer, uint32_t length); 40 | int32_t Send(uint8_t const* buffer, uint32_t length); 41 | 42 | private: 43 | SOCKET socket_; 44 | }; -------------------------------------------------------------------------------- /src/Shared/Session.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "Session.h" 19 | #include 20 | #include 21 | #include 22 | 23 | void Session::RequestData() 24 | { 25 | std::cout << "[Session]" << std::endl; 26 | std::cout << "Please enter the address of your server: set realmlist "; 27 | std::getline(std::cin, authServerAddress_); 28 | 29 | std::cout << "Please enter your account name: "; 30 | std::getline(std::cin, accountName_); 31 | 32 | std::transform(accountName_.begin(), accountName_.end(), accountName_.begin(), toupper); 33 | 34 | std::cout << "Please enter your account password: "; 35 | std::getline(std::cin, accountPassword_); 36 | 37 | std::transform(accountPassword_.begin(), accountPassword_.end(), accountPassword_.begin(), toupper); 38 | 39 | std::cout << "Please enter your realm's name: "; 40 | std::getline(std::cin, realmName_); 41 | 42 | std::cout << "Please enter your character's name: "; 43 | std::getline(std::cin, characterName_); 44 | 45 | std::string choice; 46 | std::cout << "Would you like to save these values? [Y/N]: "; 47 | std::getline(std::cin, choice); 48 | 49 | if (choice == "Y" || choice == "y") 50 | { 51 | if (SaveData()) 52 | std::cout << "Successfully saved!" << std::endl; 53 | else 54 | std::cerr << "Save failed!" << std::endl; 55 | } 56 | } 57 | 58 | bool Session::LoadSavedData() 59 | { 60 | std::ifstream file("settings.ini"); 61 | 62 | if (!file) 63 | return false; 64 | 65 | if (!std::getline(file, authServerAddress_)) 66 | return false; 67 | 68 | if (!std::getline(file, accountName_)) 69 | return false; 70 | 71 | std::transform(accountName_.begin(), accountName_.end(), accountName_.begin(), toupper); 72 | 73 | if (!std::getline(file, accountPassword_)) 74 | return false; 75 | 76 | std::transform(accountPassword_.begin(), accountPassword_.end(), accountPassword_.begin(), toupper); 77 | 78 | if (!std::getline(file, realmName_)) 79 | return false; 80 | 81 | if (!std::getline(file, characterName_)) 82 | return false; 83 | 84 | return true; 85 | } 86 | 87 | bool Session::SaveData() 88 | { 89 | std::ofstream file("settings.ini"); 90 | 91 | if (!file) 92 | return false; 93 | 94 | file << authServerAddress_ << std::endl; 95 | file << accountName_ << std::endl; 96 | file << accountPassword_ << std::endl; 97 | file << realmName_ << std::endl; 98 | file << characterName_ << std::endl; 99 | 100 | if (!file) 101 | return false; 102 | 103 | return true; 104 | } 105 | 106 | void Session::Print() 107 | { 108 | std::cout << "[Current session]" << std::endl; 109 | std::cout << " - Authentication server: " << authServerAddress_ << std::endl; 110 | std::cout << " - Account name: " << accountName_ << std::endl; 111 | std::cout << " - Realm name: " << realmName_ << std::endl; 112 | std::cout << " - Character name: " << characterName_ << std::endl; 113 | } 114 | 115 | std::string Session::GetAuthenticationServerAddress() 116 | { 117 | return authServerAddress_; 118 | } 119 | 120 | std::string Session::GetAccountName() 121 | { 122 | return accountName_; 123 | } 124 | 125 | std::string Session::GetAccountPassword() 126 | { 127 | return accountPassword_; 128 | } 129 | 130 | std::string Session::GetRealmName() 131 | { 132 | return realmName_; 133 | } 134 | 135 | std::string Session::GetCharacterName() 136 | { 137 | return characterName_; 138 | } 139 | 140 | void Session::SetRealm(const Realm& realm) 141 | { 142 | realm_ = realm; 143 | } 144 | 145 | const Realm& Session::GetRealm() 146 | { 147 | return realm_; 148 | } 149 | 150 | void Session::SetKey(const BigNumber& key) 151 | { 152 | key_ = key; 153 | } 154 | 155 | const BigNumber& Session::GetKey() 156 | { 157 | return key_; 158 | } -------------------------------------------------------------------------------- /src/Shared/Session.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #pragma once 21 | #include 22 | #include "Cryptography/BigNumber.h" 23 | #include "Auth/RealmList.h" 24 | 25 | class Session 26 | { 27 | public: 28 | void RequestData(); 29 | bool LoadSavedData(); 30 | bool SaveData(); 31 | void Print(); 32 | 33 | std::string GetAuthenticationServerAddress(); 34 | std::string GetAccountName(); 35 | std::string GetAccountPassword(); 36 | std::string GetRealmName(); 37 | std::string GetCharacterName(); 38 | void SetRealm(const Realm& realm); 39 | const Realm& GetRealm(); 40 | void SetKey(const BigNumber& key); 41 | const BigNumber& GetKey(); 42 | 43 | private: 44 | std::string authServerAddress_; 45 | std::string accountName_; 46 | std::string accountPassword_; 47 | std::string realmName_; 48 | std::string characterName_; 49 | Realm realm_; 50 | BigNumber key_; 51 | }; -------------------------------------------------------------------------------- /src/World/Addon.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "Addon.h" 19 | #include 20 | 21 | std::vector const AddonDatabase = { 22 | { "Blizzard_AchievementUI", true, 0x4C1C776D, 0 }, 23 | { "Blizzard_ArchaeologyUI", true, 0x4C1C776D, 0 }, 24 | { "Blizzard_ArenaUI", true, 0x4C1C776D, 0 }, 25 | { "Blizzard_AuctionUI", true, 0x4C1C776D, 0 }, 26 | { "Blizzard_BarbershopUI", true, 0x4C1C776D, 0 }, 27 | { "Blizzard_BattlefieldMinimap", true, 0x4C1C776D, 0 }, 28 | { "Blizzard_BindingUI", true, 0x4C1C776D, 0 }, 29 | { "Blizzard_Calendar", true, 0x4C1C776D, 0 }, 30 | { "Blizzard_ClientSavedVariables", true, 0x4C1C776D, 0 }, 31 | { "Blizzard_CombatLog", true, 0x4C1C776D, 0 }, 32 | { "Blizzard_CombatText", true, 0x4C1C776D, 0 }, 33 | { "Blizzard_CompactRaidFrames", true, 0x4C1C776D, 0 }, 34 | { "Blizzard_CUFProfiles", true, 0x4C1C776D, 0 }, 35 | { "Blizzard_DebugTools", true, 0x4C1C776D, 0 }, 36 | { "Blizzard_EncounterJournal", true, 0x4C1C776D, 0 }, 37 | { "Blizzard_GlyphUI", true, 0x4C1C776D, 0 }, 38 | { "Blizzard_GMChatUI", true, 0x4C1C776D, 0 }, 39 | { "Blizzard_GMSurveyUI", true, 0x4C1C776D, 0 }, 40 | { "Blizzard_GuildBankUI", true, 0x4C1C776D, 0 }, 41 | { "Blizzard_GuildControlUI", true, 0x4C1C776D, 0 }, 42 | { "Blizzard_GuildUI", true, 0x4C1C776D, 0 }, 43 | { "Blizzard_InspectUI", true, 0x4C1C776D, 0 }, 44 | { "Blizzard_ItemAlterationUI", true, 0x4C1C776D, 0 }, 45 | { "Blizzard_ItemSocketingUI", true, 0x4C1C776D, 0 }, 46 | { "Blizzard_LookingForGuildUI", true, 0x4C1C776D, 0 }, 47 | { "Blizzard_MacroUI", true, 0x4C1C776D, 0 }, 48 | { "Blizzard_MovePad", true, 0x4C1C776D, 0 }, 49 | { "Blizzard_RaidUI", true, 0x4C1C776D, 0 }, 50 | { "Blizzard_ReforgingUI", true, 0x4C1C776D, 0 }, 51 | { "Blizzard_TalentUI", true, 0x4C1C776D, 0 }, 52 | { "Blizzard_TimeManager", true, 0x4C1C776D, 0 }, 53 | { "Blizzard_TokenUI", true, 0x4C1C776D, 0 }, 54 | { "Blizzard_TradeSkillUI", true, 0x4C1C776D, 0 }, 55 | { "Blizzard_TrainerUI", true, 0x4C1C776D, 0 }, 56 | { "Blizzard_VoidStorageUI", true, 0x4C1C776D, 0 } 57 | }; -------------------------------------------------------------------------------- /src/World/Addon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | #include "Common.h" 20 | #include 21 | 22 | struct Addon 23 | { 24 | std::string Name; 25 | bool Enabled; 26 | uint32_t CRC; 27 | uint32_t Unknown; 28 | }; 29 | 30 | extern std::vector const AddonDatabase; -------------------------------------------------------------------------------- /src/World/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 Dehravor 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | file(GLOB_RECURSE sources_Handlers Handlers/*.cpp Handlers/*.h) 17 | file(GLOB_RECURSE sources_Includes Includes/*.cpp Includes/*.h) 18 | 19 | file(GLOB sources_localdir *.cpp *.h) 20 | 21 | set(World_SRCS 22 | ${sources_Handlers} 23 | ${sources_Includes} 24 | ${sources_localdir} 25 | ) 26 | 27 | include_directories( 28 | ${CMAKE_SOURCE_DIR} 29 | ${CMAKE_SOURCE_DIR}/dep 30 | ${CMAKE_SOURCE_DIR}/src 31 | ${CMAKE_SOURCE_DIR}/src/Shared 32 | ${CMAKE_CURRENT_SOURCE_DIR} 33 | ${CMAKE_CURRENT_SOURCE_DIR}/Handlers 34 | ${CMAKE_CURRENT_SOURCE_DIR}/Includes 35 | ${OPENSSL_INCLUDE_DIR} 36 | ) 37 | 38 | add_library(World STATIC 39 | ${World_SRCS} 40 | ) 41 | 42 | target_link_libraries(World 43 | Shared 44 | zlib 45 | ) -------------------------------------------------------------------------------- /src/World/Cache.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "Cache.h" 19 | #include 20 | #include 21 | 22 | template 23 | Cache::Cache(const std::string fileName) 24 | { 25 | fileName_ = fileName; 26 | } 27 | 28 | template 29 | bool Cache::Load() 30 | { 31 | std::ifstream input(fileName_); 32 | 33 | if (!input) 34 | return false; 35 | 36 | T entry; 37 | input.read(reinterpret_cast(&entry), sizeof(T)); 38 | 39 | while (!input.eof()) 40 | { 41 | entries_.push_back(entry); 42 | input.read(reinterpret_cast(&entry), sizeof(T)); 43 | } 44 | 45 | input.close(); 46 | return true; 47 | } 48 | 49 | template 50 | bool Cache::Save() 51 | { 52 | std::ofstream output(fileName_, std::ios_base::app); 53 | 54 | if (!output) 55 | return false; 56 | 57 | for (const T& entry : entries_) 58 | { 59 | auto itr = std::find(newEntries_.begin(), newEntries_.end(), entry.GUID); 60 | 61 | if (itr == newEntries_.end()) 62 | continue; 63 | 64 | output.write(reinterpret_cast(&entry), sizeof(T)); 65 | } 66 | 67 | newEntries_.clear(); 68 | 69 | if (!output) 70 | return false; 71 | 72 | return true; 73 | } 74 | 75 | template 76 | void Cache::Add(T& value) 77 | { 78 | 79 | entries_.push_back(value); 80 | newEntries_.push_back(value.GUID); 81 | } 82 | 83 | template 84 | bool Cache::Has(const T& value) const 85 | { 86 | int count = std::count_if(entries_.begin(), entries_.end(), [value](const T& entry) { 87 | return entry.GUID == value.GUID; 88 | }); 89 | 90 | return count > 0; 91 | } 92 | 93 | template 94 | bool Cache::Has(uint64_t GUID) const 95 | { 96 | int count = std::count_if(entries_.begin(), entries_.end(), [GUID](const T& entry) { 97 | return entry.GUID == GUID; 98 | }); 99 | 100 | return count > 0; 101 | } 102 | 103 | template 104 | const T* Cache::Get(uint64_t GUID) const 105 | { 106 | auto itr = std::find_if(entries_.begin(), entries_.end(), [GUID](const T& entry) { 107 | return entry.GUID == GUID; 108 | }); 109 | 110 | if (itr == entries_.end()) 111 | return nullptr; 112 | 113 | return &(*itr); 114 | } 115 | 116 | template 117 | void Cache::Remove(const T& value) 118 | { 119 | std::remove_if(entries_.begin(), entries_.end(), [value](const T& entry) { 120 | return entry.GUID == value.GUID; 121 | }); 122 | } 123 | 124 | template class Cache; -------------------------------------------------------------------------------- /src/World/Cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | #include "Common.h" 20 | #include "SharedDefines.h" 21 | #include 22 | 23 | #pragma pack(push, 1) 24 | 25 | struct PlayerNameEntry 26 | { 27 | uint64_t GUID; 28 | char Name[64]; 29 | Races PlayerRace; 30 | Genders PlayerGender; 31 | Classes PlayerClass; 32 | }; 33 | 34 | #pragma pack(pop) 35 | 36 | template 37 | class Cache 38 | { 39 | public: 40 | Cache(const std::string fileName); 41 | 42 | bool Load(); 43 | bool Save(); 44 | 45 | void Add(T& value); 46 | bool Has(const T& value) const; 47 | bool Has(uint64_t GUID) const; 48 | const T* Get(uint64_t GUID) const; 49 | void Remove(const T& value); 50 | 51 | private: 52 | std::vector entries_; 53 | std::vector newEntries_; 54 | std::string fileName_; 55 | }; 56 | 57 | typedef Cache PlayerNameCache; -------------------------------------------------------------------------------- /src/World/Character.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | #include "Common.h" 20 | #include "Position.h" 21 | #include "ObjectGuid.h" 22 | #include "SharedDefines.h" 23 | 24 | struct CharacterDisplay 25 | { 26 | uint8_t Skin; 27 | uint8_t Face; 28 | uint8_t HairStyle; 29 | uint8_t HairColor; 30 | uint8_t FacialHair; 31 | }; 32 | 33 | struct CharacterPet 34 | { 35 | uint32_t DisplayId; 36 | uint32_t Level; 37 | uint32_t Family; 38 | }; 39 | 40 | struct CharacterItems 41 | { 42 | uint32_t DisplayId; 43 | uint8_t InventoryType; 44 | uint32_t EnchantAuraId; 45 | }; 46 | 47 | struct CharacterBags 48 | { 49 | uint32_t DisplayId; 50 | uint8_t InventoryType; 51 | uint32_t EnchantId; 52 | }; 53 | 54 | struct Character 55 | { 56 | ObjectGuid Guid; 57 | std::string Name; 58 | Races Race; 59 | Classes Class; 60 | Genders Gender; 61 | CharacterDisplay Display; 62 | uint8_t Level; 63 | uint32_t AreaId; 64 | uint32_t MapId; 65 | Position4D Position; 66 | ObjectGuid GuildGuid; 67 | uint32_t Flags; 68 | uint32_t CustomizationFlags; 69 | uint8_t Slot; 70 | bool IsFirstLogin; 71 | CharacterPet Pet; 72 | CharacterItems Items[19]; 73 | CharacterBags Bags[4]; 74 | 75 | bool IsAlliance() const 76 | { 77 | switch (Race) 78 | { 79 | case RACE_HUMAN: 80 | case RACE_NIGHTELF: 81 | case RACE_GNOME: 82 | case RACE_DWARF: 83 | case RACE_DRAENEI: 84 | case RACE_WORGEN: 85 | return true; 86 | default: 87 | return false; 88 | } 89 | 90 | return false; 91 | } 92 | 93 | bool IsHorde() const 94 | { 95 | return !IsAlliance(); 96 | } 97 | 98 | std::string GetRaceAsStr() const 99 | { 100 | switch (Race) 101 | { 102 | case RACE_HUMAN: 103 | return "Human"; 104 | case RACE_ORC: 105 | return "Orc"; 106 | case RACE_DWARF: 107 | return "Dwarf"; 108 | case RACE_NIGHTELF: 109 | return "Night elf"; 110 | case RACE_UNDEAD_PLAYER: 111 | return "Undead"; 112 | case RACE_TAUREN: 113 | return "Tauren"; 114 | case RACE_GNOME: 115 | return "Gnome"; 116 | case RACE_TROLL: 117 | return "Troll"; 118 | case RACE_BLOODELF: 119 | return "Blood elf"; 120 | case RACE_DRAENEI: 121 | return "Draenei"; 122 | case RACE_GOBLIN: 123 | return "Goblin"; 124 | case RACE_WORGEN: 125 | return "Worgen"; 126 | default: 127 | return "Unknown"; 128 | } 129 | 130 | return ""; 131 | } 132 | 133 | std::string GetClassAsStr() const 134 | { 135 | switch (Class) 136 | { 137 | case CLASS_WARRIOR: 138 | return "Warrior"; 139 | case CLASS_PALADIN: 140 | return "Paladin"; 141 | case CLASS_HUNTER: 142 | return "Hunter"; 143 | case CLASS_ROGUE: 144 | return "Rogue"; 145 | case CLASS_PRIEST: 146 | return "Priest"; 147 | case CLASS_DEATH_KNIGHT: 148 | return "Death Knight"; 149 | case CLASS_SHAMAN: 150 | return "Shaman"; 151 | case CLASS_MAGE: 152 | return "Mage"; 153 | case CLASS_WARLOCK: 154 | return "Warlock"; 155 | case CLASS_DRUID: 156 | return "Druid"; 157 | default: 158 | return "Unknown"; 159 | } 160 | 161 | return ""; 162 | } 163 | }; -------------------------------------------------------------------------------- /src/World/CharacterList.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "CharacterList.h" 19 | 20 | void CharacterList::Populate(uint32_t count, WorldPacket &recvPacket) 21 | { 22 | list_.clear(); 23 | list_.resize(count); 24 | 25 | for (uint8_t i = 0; i < count; i++) 26 | { 27 | Character character; 28 | 29 | character.Guid[3] = recvPacket.ReadBit(); 30 | character.GuildGuid[1] = recvPacket.ReadBit(); 31 | character.GuildGuid[7] = recvPacket.ReadBit(); 32 | character.GuildGuid[2] = recvPacket.ReadBit(); 33 | character.Name.resize(recvPacket.ReadBits(7)); 34 | character.Guid[4] = recvPacket.ReadBit(); 35 | character.Guid[7] = recvPacket.ReadBit(); 36 | character.GuildGuid[3] = recvPacket.ReadBit(); 37 | character.Guid[5] = recvPacket.ReadBit(); 38 | character.GuildGuid[6] = recvPacket.ReadBit(); 39 | character.Guid[1] = recvPacket.ReadBit(); 40 | character.GuildGuid[5] = recvPacket.ReadBit(); 41 | character.GuildGuid[4] = recvPacket.ReadBit(); 42 | character.IsFirstLogin = recvPacket.ReadBit(); 43 | character.Guid[0] = recvPacket.ReadBit(); 44 | character.Guid[2] = recvPacket.ReadBit(); 45 | character.Guid[6] = recvPacket.ReadBit(); 46 | character.GuildGuid[0] = recvPacket.ReadBit(); 47 | 48 | list_[i] = character; 49 | } 50 | 51 | for (uint8_t i = 0; i < count; i++) 52 | { 53 | list_[i].Class = recvPacket.read(); 54 | 55 | for (uint8_t j = 0; j < 19; j++) 56 | { 57 | recvPacket >> list_[i].Items[j].InventoryType; 58 | recvPacket >> list_[i].Items[j].DisplayId; 59 | recvPacket >> list_[i].Items[j].EnchantAuraId; 60 | } 61 | 62 | for (uint8_t j = 0; j < 4; j++) 63 | { 64 | recvPacket >> list_[i].Bags[j].DisplayId; 65 | recvPacket >> list_[i].Bags[j].EnchantId; 66 | recvPacket >> list_[i].Bags[j].InventoryType; 67 | } 68 | 69 | recvPacket >> list_[i].Pet.Family; 70 | recvPacket.ReadByteSeq(list_[i].GuildGuid[2]); 71 | recvPacket >> list_[i].Slot; 72 | recvPacket >> list_[i].Display.HairStyle; 73 | recvPacket.ReadByteSeq(list_[i].GuildGuid[3]); 74 | recvPacket >> list_[i].Pet.DisplayId; 75 | recvPacket >> list_[i].Flags; 76 | recvPacket >> list_[i].Display.HairColor; 77 | recvPacket.ReadByteSeq(list_[i].Guid[4]); 78 | recvPacket >> list_[i].MapId; 79 | recvPacket.ReadByteSeq(list_[i].GuildGuid[5]); 80 | recvPacket >> list_[i].Position.Z; 81 | recvPacket.ReadByteSeq(list_[i].GuildGuid[6]); 82 | recvPacket >> list_[i].Pet.Level; 83 | recvPacket.ReadByteSeq(list_[i].Guid[3]); 84 | recvPacket >> list_[i].Position.Y; 85 | recvPacket >> list_[i].CustomizationFlags; 86 | recvPacket >> list_[i].Display.FacialHair; 87 | recvPacket.ReadByteSeq(list_[i].Guid[7]); 88 | list_[i].Gender = recvPacket.read(); 89 | list_[i].Name = recvPacket.ReadString(list_[i].Name.size()); 90 | recvPacket >> list_[i].Display.Face; 91 | recvPacket.ReadByteSeq(list_[i].Guid[0]); 92 | recvPacket.ReadByteSeq(list_[i].Guid[2]); 93 | recvPacket.ReadByteSeq(list_[i].GuildGuid[1]); 94 | recvPacket.ReadByteSeq(list_[i].GuildGuid[7]); 95 | recvPacket >> list_[i].Position.X; 96 | recvPacket >> list_[i].Display.Skin; 97 | list_[i].Race = recvPacket.read(); 98 | recvPacket >> list_[i].Level; 99 | recvPacket.ReadByteSeq(list_[i].Guid[6]); 100 | recvPacket.ReadByteSeq(list_[i].GuildGuid[4]); 101 | recvPacket.ReadByteSeq(list_[i].GuildGuid[0]); 102 | recvPacket.ReadByteSeq(list_[i].Guid[5]); 103 | recvPacket.ReadByteSeq(list_[i].Guid[1]); 104 | recvPacket >> list_[i].AreaId; 105 | } 106 | } 107 | 108 | void CharacterList::Print() const 109 | { 110 | std::cout << "[Characterlist]" << std::endl; 111 | 112 | for (Character const& character : list_) 113 | std::cout << " - " << character.Name << " (" << character.GetRaceAsStr() << " " << character.GetClassAsStr() << ") [Level " << uint32_t(character.Level) << "]" << std::endl; 114 | } 115 | 116 | Character const* CharacterList::GetCharacterByName(std::string name) const 117 | { 118 | for (auto &character : list_) 119 | { 120 | if (character.Name == name) 121 | return &character; 122 | } 123 | 124 | return nullptr; 125 | } -------------------------------------------------------------------------------- /src/World/CharacterList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | #include "Common.h" 20 | #include "WorldPacket.h" 21 | #include "Character.h" 22 | 23 | class CharacterList 24 | { 25 | public: 26 | void Populate(uint32_t count, WorldPacket &recvPacket); 27 | void Print() const; 28 | 29 | Character const* GetCharacterByName(std::string name) const; 30 | private: 31 | std::vector list_; 32 | }; -------------------------------------------------------------------------------- /src/World/ChatMgr.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "ChatMgr.h" 19 | #include "WorldSession.h" 20 | 21 | ChatMgr::ChatMgr(WorldSession* session) : session_(session) 22 | { 23 | 24 | } 25 | 26 | void ChatMgr::EnqueueMessage(const ChatMessage& message) 27 | { 28 | std::shared_ptr copy(new ChatMessage(message)); 29 | 30 | std::lock_guard lock(chatMutex_); 31 | queue_.push(copy); 32 | } 33 | 34 | void ChatMgr::ProcessMessages() 35 | { 36 | std::shared_ptr message = nullptr; 37 | 38 | // Access queue 39 | { 40 | std::lock_guard lock(chatMutex_); 41 | 42 | if (queue_.empty()) 43 | return; 44 | 45 | message = queue_.front(); 46 | 47 | // If sender's name query has not arrived yet 48 | if (message->SenderGUID.IsPlayer() && message->SenderName.empty()) 49 | { 50 | const PlayerNameCache* cache = session_->GetPlayerNameCache(); 51 | 52 | if (!cache->Has(message->SenderGUID)) 53 | return; 54 | 55 | const PlayerNameEntry* entry = cache->Get(message->SenderGUID); 56 | message->SenderName = entry->Name; 57 | } 58 | 59 | // If receiver's name query has not arrived yet 60 | if (message->ReceiverGUID.IsPlayer() && message->ReceiverName.empty()) 61 | { 62 | const PlayerNameCache* cache = session_->GetPlayerNameCache(); 63 | 64 | if (!cache->Has(message->ReceiverGUID)) 65 | return; 66 | 67 | const PlayerNameEntry* entry = cache->Get(message->ReceiverGUID); 68 | message->ReceiverName = entry->Name; 69 | } 70 | 71 | queue_.pop(); 72 | } 73 | 74 | if (!message) 75 | return; 76 | 77 | switch (message->Tag) 78 | { 79 | case CHAT_TAG_AFK: 80 | message->SenderName = "" + message->SenderName; 81 | break; 82 | case CHAT_TAG_DND: 83 | message->SenderName = "" + message->SenderName; 84 | break; 85 | case CHAT_TAG_GM: 86 | message->SenderName = "" + message->SenderName; 87 | break; 88 | case CHAT_TAG_DEV: 89 | message->SenderName = "" + message->SenderName; 90 | break; 91 | } 92 | 93 | message->SenderName = "[" + message->SenderName + "]"; 94 | 95 | switch (message->Type) 96 | { 97 | case CHAT_MSG_SYSTEM: 98 | std::cout << message->Message << std::endl; 99 | break; 100 | case CHAT_MSG_SAY: 101 | case CHAT_MSG_MONSTER_SAY: 102 | std::cout << message->SenderName << " says: " << message->Message << std::endl; 103 | break; 104 | case CHAT_MSG_YELL: 105 | case CHAT_MSG_MONSTER_YELL: 106 | std::cout << message->SenderName << " yells: " << message->Message << std::endl; 107 | break; 108 | case CHAT_MSG_PARTY: 109 | case CHAT_MSG_MONSTER_PARTY: 110 | std::cout << "[Party]" << message->SenderName << ": " << message->Message << std::endl; 111 | break; 112 | case CHAT_MSG_PARTY_LEADER: 113 | std::cout << "[Party Leader]" << message->SenderName << ": " << message->Message << std::endl; 114 | break; 115 | case CHAT_MSG_RAID: 116 | std::cout << "[Raid]" << message->SenderName << ": " << message->Message << std::endl; 117 | break; 118 | case CHAT_MSG_RAID_WARNING: 119 | std::cout << "[Raid Warning]" << message->SenderName << ": " << message->Message << std::endl; 120 | break; 121 | case CHAT_MSG_GUILD: 122 | std::cout << "[Guild]" << message->SenderName << ": " << message->Message << std::endl; 123 | break; 124 | case CHAT_MSG_OFFICER: 125 | std::cout << "[Officer]" << message->SenderName << ": " << message->Message << std::endl; 126 | break; 127 | case CHAT_MSG_WHISPER: 128 | case CHAT_MSG_MONSTER_WHISPER: 129 | std::cout << message->SenderName << " whispers: " << message->Message << std::endl; 130 | break; 131 | case CHAT_MSG_EMOTE: 132 | case CHAT_MSG_MONSTER_EMOTE: 133 | std::cout << message->SenderName << " " << message->Message << std::endl; 134 | break; 135 | case CHAT_MSG_CHANNEL: 136 | std::cout << "[" << message->ChannelName << "] " << message->SenderName << ": " << message->Message << std::endl; 137 | break; 138 | } 139 | } -------------------------------------------------------------------------------- /src/World/ChatMgr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | #include "Common.h" 20 | #include "SharedDefines.h" 21 | #include "ObjectGuid.h" 22 | #include 23 | #include 24 | 25 | enum ChatType : uint8_t 26 | { 27 | CHAT_MSG_ADDON = 0xFF, 28 | CHAT_MSG_SYSTEM = 0x00, 29 | CHAT_MSG_SAY = 0x01, 30 | CHAT_MSG_PARTY = 0x02, 31 | CHAT_MSG_RAID = 0x03, 32 | CHAT_MSG_GUILD = 0x04, 33 | CHAT_MSG_OFFICER = 0x05, 34 | CHAT_MSG_YELL = 0x06, 35 | CHAT_MSG_WHISPER = 0x07, 36 | CHAT_MSG_WHISPER_FOREIGN = 0x08, 37 | CHAT_MSG_WHISPER_INFORM = 0x09, 38 | CHAT_MSG_EMOTE = 0x0A, 39 | CHAT_MSG_TEXT_EMOTE = 0x0B, 40 | CHAT_MSG_MONSTER_SAY = 0x0C, 41 | CHAT_MSG_MONSTER_PARTY = 0x0D, 42 | CHAT_MSG_MONSTER_YELL = 0x0E, 43 | CHAT_MSG_MONSTER_WHISPER = 0x0F, 44 | CHAT_MSG_MONSTER_EMOTE = 0x10, 45 | CHAT_MSG_CHANNEL = 0x11, 46 | CHAT_MSG_CHANNEL_JOIN = 0x12, 47 | CHAT_MSG_CHANNEL_LEAVE = 0x13, 48 | CHAT_MSG_CHANNEL_LIST = 0x14, 49 | CHAT_MSG_CHANNEL_NOTICE = 0x15, 50 | CHAT_MSG_CHANNEL_NOTICE_USER = 0x16, 51 | CHAT_MSG_AFK = 0x17, 52 | CHAT_MSG_DND = 0x18, 53 | CHAT_MSG_IGNORED = 0x19, 54 | CHAT_MSG_SKILL = 0x1A, 55 | CHAT_MSG_LOOT = 0x1B, 56 | CHAT_MSG_MONEY = 0x1C, 57 | CHAT_MSG_OPENING = 0x1D, 58 | CHAT_MSG_TRADESKILLS = 0x1E, 59 | CHAT_MSG_PET_INFO = 0x1F, 60 | CHAT_MSG_COMBAT_MISC_INFO = 0x20, 61 | CHAT_MSG_COMBAT_XP_GAIN = 0x21, 62 | CHAT_MSG_COMBAT_HONOR_GAIN = 0x22, 63 | CHAT_MSG_COMBAT_FACTION_CHANGE = 0x23, 64 | CHAT_MSG_BG_SYSTEM_NEUTRAL = 0x24, 65 | CHAT_MSG_BG_SYSTEM_ALLIANCE = 0x25, 66 | CHAT_MSG_BG_SYSTEM_HORDE = 0x26, 67 | CHAT_MSG_RAID_LEADER = 0x27, 68 | CHAT_MSG_RAID_WARNING = 0x28, 69 | CHAT_MSG_RAID_BOSS_EMOTE = 0x29, 70 | CHAT_MSG_RAID_BOSS_WHISPER = 0x2A, 71 | CHAT_MSG_FILTERED = 0x2B, 72 | CHAT_MSG_BATTLEGROUND = 0x2C, 73 | CHAT_MSG_BATTLEGROUND_LEADER = 0x2D, 74 | CHAT_MSG_RESTRICTED = 0x2E, 75 | CHAT_MSG_BATTLENET = 0x2F, 76 | CHAT_MSG_ACHIEVEMENT = 0x30, 77 | CHAT_MSG_GUILD_ACHIEVEMENT = 0x31, 78 | CHAT_MSG_ARENA_POINTS = 0x32, 79 | CHAT_MSG_PARTY_LEADER = 0x33, 80 | CHAT_MSG_TARGETICONS = 0x34, 81 | CHAT_MSG_BN_WHISPER = 0x35, 82 | CHAT_MSG_BN_WHISPER_INFORM = 0x36, 83 | CHAT_MSG_BN_CONVERSATION = 0x37, 84 | CHAT_MSG_BN_CONVERSATION_NOTICE = 0x38, 85 | CHAT_MSG_BN_CONVERSATION_LIST = 0x39, 86 | CHAT_MSG_BN_INLINE_TOAST_ALERT = 0x3A, 87 | CHAT_MSG_BN_INLINE_TOAST_BROADCAST = 0x3B, 88 | CHAT_MSG_BN_INLINE_TOAST_BROADCAST_INFORM = 0x3C, 89 | CHAT_MSG_BN_INLINE_TOAST_CONVERSATION = 0x3D, 90 | CHAT_MSG_BN_WHISPER_PLAYER_OFFLINE = 0x3E, 91 | CHAT_MSG_COMBAT_GUILD_XP_GAIN = 0x3F, 92 | CHAT_MSG_CURRENCY = 0x40 93 | }; 94 | 95 | enum ChatTag : uint8_t 96 | { 97 | CHAT_TAG_NONE = 0x00, 98 | CHAT_TAG_AFK = 0x01, 99 | CHAT_TAG_DND = 0x02, 100 | CHAT_TAG_GM = 0x04, 101 | CHAT_TAG_UNK1 = 0x08, 102 | CHAT_TAG_DEV = 0x10, 103 | CHAT_TAG_UNK2 = 0x40, 104 | CHAT_TAG_COM = 0x80 105 | }; 106 | 107 | struct ChatMessage 108 | { 109 | ChatType Type; 110 | Languages Language; 111 | uint32_t Flags; 112 | ObjectGuid SenderGUID; 113 | std::string SenderName; 114 | ObjectGuid ReceiverGUID; 115 | std::string ReceiverName; 116 | ChatTag Tag; 117 | std::string ChannelName; 118 | std::string AddonPrefix; 119 | std::string Message; 120 | }; 121 | 122 | class WorldSession; 123 | 124 | class ChatMgr 125 | { 126 | public: 127 | ChatMgr(WorldSession* session); 128 | 129 | void EnqueueMessage(const ChatMessage& message); 130 | void ProcessMessages(); 131 | 132 | private: 133 | std::mutex chatMutex_; 134 | WorldSession* session_; 135 | std::queue> queue_; 136 | }; -------------------------------------------------------------------------------- /src/World/EventMgr.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "EventMgr.h" 19 | #include "Common.h" 20 | #include 21 | using namespace std::chrono; 22 | 23 | Event::Event(EventId id) : id_(id), enabled_(false), period_(0), remaining_(0) 24 | { 25 | 26 | } 27 | 28 | EventId Event::GetId() 29 | { 30 | return id_; 31 | } 32 | 33 | void Event::SetPeriod(uint32_t period) 34 | { 35 | period_ = period; 36 | remaining_ = period; 37 | } 38 | 39 | void Event::SetCallback(EventCallback callback) 40 | { 41 | callback_ = callback; 42 | } 43 | 44 | void Event::SetEnabled(bool enabled) 45 | { 46 | enabled_ = enabled; 47 | } 48 | 49 | void Event::Update(uint32_t diff) 50 | { 51 | if (!enabled_) 52 | return; 53 | 54 | if (remaining_ <= 0) 55 | { 56 | callback_(); 57 | remaining_ = period_; 58 | } 59 | else 60 | remaining_ -= diff; 61 | } 62 | 63 | EventMgr::EventMgr() : isRunning_(false) 64 | { 65 | 66 | } 67 | 68 | EventMgr::~EventMgr() 69 | { 70 | isRunning_ = false; 71 | 72 | if (thread_.joinable()) 73 | thread_.join(); 74 | } 75 | 76 | void EventMgr::AddEvent(std::shared_ptr event) 77 | { 78 | std::lock_guard lock(eventMutex_); 79 | events_.push_back(event); 80 | } 81 | 82 | void EventMgr::RemoveEvent(EventId id) 83 | { 84 | std::lock_guard lock(eventMutex_); 85 | events_.remove_if([id](std::shared_ptr const& event) { 86 | return event->GetId() == id; 87 | }); 88 | } 89 | 90 | std::shared_ptr EventMgr::GetEvent(EventId id) 91 | { 92 | std::lock_guard lock(eventMutex_); 93 | auto itr = std::find_if(events_.begin(), events_.end(), [id](const std::shared_ptr event) { 94 | return event->GetId() == id; 95 | }); 96 | 97 | if (itr == events_.end()) 98 | return nullptr; 99 | 100 | return *itr; 101 | } 102 | 103 | void EventMgr::Start() 104 | { 105 | assert(!isRunning_); 106 | 107 | isRunning_ = true; 108 | thread_ = std::thread(&EventMgr::ProcessEvents, this); 109 | } 110 | 111 | void EventMgr::Stop() 112 | { 113 | isRunning_ = false; 114 | 115 | if (thread_.joinable()) 116 | thread_.join(); 117 | } 118 | 119 | void EventMgr::ProcessEvents() 120 | { 121 | uint32_t diff = 0; 122 | 123 | while (isRunning_) 124 | { 125 | system_clock::time_point start = high_resolution_clock::now(); 126 | 127 | std::lock_guard lock(eventMutex_); 128 | 129 | for (std::shared_ptr event : events_) 130 | event->Update(diff); 131 | 132 | std::this_thread::sleep_for(milliseconds(5)); 133 | system_clock::time_point end = high_resolution_clock::now(); 134 | diff = uint32_t(duration_cast(end - start).count()); 135 | } 136 | 137 | std::lock_guard lock(eventMutex_); 138 | events_.clear(); 139 | } -------------------------------------------------------------------------------- /src/World/EventMgr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | enum EventId 27 | { 28 | EVENT_PROCESS_INCOMING = 0, 29 | EVENT_SEND_KEEP_ALIVE = 1, 30 | EVENT_SEND_PING = 2, 31 | EVENT_PROCESS_CHAT_MESSAGES = 3 32 | }; 33 | 34 | typedef std::function EventCallback; 35 | 36 | class Event 37 | { 38 | public: 39 | Event(EventId id); 40 | 41 | EventId GetId(); 42 | 43 | void SetPeriod(uint32_t period); 44 | void SetEnabled(bool enabled); 45 | void SetCallback(EventCallback callback); 46 | 47 | void Update(uint32_t diff); 48 | private: 49 | EventId id_; 50 | bool enabled_; 51 | uint32_t period_; 52 | int32_t remaining_; 53 | EventCallback callback_; 54 | }; 55 | 56 | class EventMgr 57 | { 58 | public: 59 | EventMgr(); 60 | ~EventMgr(); 61 | 62 | void AddEvent(std::shared_ptr event); 63 | void RemoveEvent(EventId id); 64 | std::shared_ptr GetEvent(EventId id); 65 | 66 | void Start(); 67 | void Stop(); 68 | 69 | private: 70 | std::thread thread_; 71 | bool isRunning_; 72 | std::recursive_mutex eventMutex_; 73 | std::list> events_; 74 | 75 | void ProcessEvents(); 76 | }; -------------------------------------------------------------------------------- /src/World/Handlers/AuthHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "WorldSession.h" 19 | #include "Cryptography/SHA1.h" 20 | #include "Config.h" 21 | #include "Addon.h" 22 | #include 23 | 24 | void WorldSession::HandleConnectionVerification(WorldPacket &recvPacket) 25 | { 26 | std::string serverString; 27 | recvPacket >> serverString; 28 | 29 | if (serverString != "RLD OF WARCRAFT CONNECTION - SERVER TO CLIENT") 30 | { 31 | std::cerr << "Connection verification failed. Invalid string received: " << serverString << std::endl; 32 | return; 33 | } 34 | 35 | std::string clientString = "D OF WARCRAFT CONNECTION - CLIENT TO SERVER"; 36 | 37 | WorldPacket response(MSG_VERIFY_CONNECTIVITY, clientString.length() + 1); 38 | response << clientString; 39 | SendPacket(response); 40 | } 41 | 42 | void WorldSession::HandleAuthenticationChallenge(WorldPacket &recvPacket) 43 | { 44 | // Read server values 45 | uint32_t keys[8]; 46 | 47 | for (int i = 0; i < 8; i++) 48 | recvPacket >> keys[i]; 49 | 50 | recvPacket >> serverSeed_; 51 | 52 | uint8_t unk; 53 | recvPacket >> unk; 54 | 55 | // Generate our proof 56 | uint32_t zero = 0; 57 | 58 | SHA1 proof; 59 | proof.Update(session_->GetAccountName()); 60 | proof.Update((uint8_t*)&zero, sizeof(uint32_t)); 61 | proof.Update((uint8_t*)&clientSeed_, sizeof(uint32_t)); 62 | proof.Update((uint8_t*)&serverSeed_, sizeof(uint32_t)); 63 | proof.Update(session_->GetKey()); 64 | proof.Finalize(); 65 | 66 | uint8_t* digest = proof.GetDigest(); 67 | 68 | WorldPacket response(CMSG_AUTH_SESSION); 69 | response << uint32_t(0); // 00 00 00 00 [4.3.4 15595 enUS] 70 | response << uint32_t(0); // 00 00 00 00 [4.3.4 15595 enUS] 71 | response << uint8_t(0); // 00 [4.3.4 15595 enUS] 72 | response << digest[10]; 73 | response << digest[18]; 74 | response << digest[12]; 75 | response << digest[5]; 76 | response << uint64_t(3); // 03 00 00 00 00 00 00 00 [4.3.4 15595 enUS] 77 | response << digest[15]; 78 | response << digest[9]; 79 | response << digest[19]; 80 | response << digest[4]; 81 | response << digest[7]; 82 | response << digest[16]; 83 | response << digest[3]; 84 | response << uint16_t(GameBuild); 85 | response << digest[8]; 86 | response << uint32_t(1); // 01 00 00 00 [4.3.4 15595 enUS] 87 | response << uint8_t(1); 88 | response << digest[17]; 89 | response << digest[6]; 90 | response << digest[0]; 91 | response << digest[1]; 92 | response << digest[11]; 93 | response << uint32_t(clientSeed_); 94 | response << digest[2]; 95 | response << uint32_t(0); // 00 00 00 00 [4.3.4 15595 enUS] 96 | response << digest[14]; 97 | response << digest[13]; 98 | 99 | ByteBuffer addonData; 100 | addonData << uint32_t(AddonDatabase.size()); 101 | 102 | for (auto const& addon : AddonDatabase) 103 | { 104 | addonData << addon.Name; 105 | addonData << uint8_t(addon.Enabled); 106 | addonData << uint32_t(addon.CRC); 107 | addonData << uint32_t(addon.Unknown); 108 | } 109 | 110 | addonData << uint32_t(0x4B44A47C); // 7C A4 44 4B [4.3.4 15595 enUS] 111 | 112 | uLongf compressedSize = compressBound(addonData.size()); 113 | 114 | ByteBuffer addonDataCompressed; 115 | addonDataCompressed.resize(compressedSize); 116 | 117 | if (compress(addonDataCompressed.contents(), &compressedSize, addonData.contents(), addonData.size()) != Z_OK) 118 | assert(false); 119 | 120 | response << uint32_t(4 + compressedSize); 121 | response << uint32_t(addonData.size()); 122 | response.append(addonDataCompressed.contents(), compressedSize); 123 | 124 | response.WriteBit(0); 125 | response.WriteBits(session_->GetAccountName().length(), 12); 126 | response.FlushBits(); 127 | response.WriteString(session_->GetAccountName()); 128 | 129 | SendPacket(response); 130 | } 131 | 132 | enum AuthResult : uint8_t 133 | { 134 | AUTH_OK = 12, 135 | AUTH_FAILED = 13, 136 | AUTH_REJECT = 14, 137 | AUTH_BAD_SERVER_PROOF = 15, 138 | AUTH_UNAVAILABLE = 16, 139 | AUTH_SYSTEM_ERROR = 17, 140 | AUTH_BILLING_ERROR = 18, 141 | AUTH_BILLING_EXPIRED = 19, 142 | AUTH_VERSION_MISMATCH = 20, 143 | AUTH_UNKNOWN_ACCOUNT = 21, 144 | AUTH_INCORRECT_PASSWORD = 22, 145 | AUTH_SESSION_EXPIRED = 23, 146 | AUTH_SERVER_SHUTTING_DOWN = 24, 147 | AUTH_ALREADY_LOGGING_IN = 25, 148 | AUTH_LOGIN_SERVER_NOT_FOUND = 26, 149 | AUTH_WAIT_QUEUE = 27, 150 | AUTH_BANNED = 28, 151 | AUTH_ALREADY_ONLINE = 29, 152 | AUTH_NO_TIME = 30, 153 | AUTH_DB_BUSY = 31, 154 | AUTH_SUSPENDED = 32, 155 | AUTH_PARENTAL_CONTROL = 33, 156 | AUTH_LOCKED_ENFORCED = 34, 157 | }; 158 | 159 | void WorldSession::HandleAuthenticationResponse(WorldPacket &recvPacket) 160 | { 161 | uint32_t billingTimeRemaining, billingTimeRested, queuePosition; 162 | uint8_t billingPlanFlags, result, expansion; 163 | bool hasQueueInfo, hasAccountInfo; 164 | 165 | hasQueueInfo = recvPacket.ReadBit(); 166 | 167 | if (hasQueueInfo) 168 | recvPacket.ReadBit(); 169 | 170 | hasAccountInfo = recvPacket.ReadBit(); 171 | 172 | if (hasAccountInfo) 173 | { 174 | recvPacket >> billingTimeRemaining; 175 | recvPacket >> billingPlanFlags; 176 | recvPacket >> billingTimeRested; 177 | recvPacket >> expansion; 178 | } 179 | 180 | recvPacket >> result; 181 | 182 | if (hasQueueInfo) 183 | { 184 | recvPacket >> queuePosition; 185 | 186 | if (queuePosition > 0) 187 | std::cout << session_->GetRealmName() << " is full. Position in queue: " << queuePosition << std::endl; 188 | else 189 | std::cout << session_->GetRealmName() << " is full. Please wait..." << std::endl; 190 | 191 | return; 192 | } 193 | 194 | if (!hasAccountInfo) 195 | return; 196 | 197 | std::cout << "[World]" << std::endl; 198 | std::cout << "Successfully authenticated!" << std::endl; 199 | 200 | WorldPacket packet(CMSG_REALM_SPLIT, 4); 201 | packet << uint32_t(0xFFFFFFFF); 202 | SendPacket(packet); 203 | 204 | packet.Initialize(CMSG_CHAR_ENUM, 0); 205 | SendPacket(packet); 206 | } -------------------------------------------------------------------------------- /src/World/Handlers/ChannelHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "WorldSession.h" 19 | 20 | void WorldSession::JoinChannel(const std::string name, const std::string password) 21 | { 22 | WorldPacket packet(CMSG_JOIN_CHANNEL); 23 | packet << uint32_t(0); 24 | packet.WriteBit(0); 25 | packet.WriteBit(0); 26 | packet.WriteBits(name.length(), 8); 27 | packet.WriteBits(password.length(), 8); 28 | packet.FlushBits(); 29 | packet.WriteString(name); 30 | packet.WriteString(password); 31 | SendPacket(packet); 32 | } 33 | 34 | enum ChatNotify : uint8_t 35 | { 36 | CHAT_JOINED_NOTICE = 0x00, //+ "%s joined channel."; 37 | CHAT_LEFT_NOTICE = 0x01, //+ "%s left channel."; 38 | //CHAT_SUSPENDED_NOTICE = 0x01, // "%s left channel."; 39 | CHAT_YOU_JOINED_NOTICE = 0x02, //+ "Joined Channel: [%s]"; -- You joined 40 | //CHAT_YOU_CHANGED_NOTICE = 0x02, // "Changed Channel: [%s]"; 41 | CHAT_YOU_LEFT_NOTICE = 0x03, //+ "Left Channel: [%s]"; -- You left 42 | CHAT_WRONG_PASSWORD_NOTICE = 0x04, //+ "Wrong password for %s."; 43 | CHAT_NOT_MEMBER_NOTICE = 0x05, //+ "Not on channel %s."; 44 | CHAT_NOT_MODERATOR_NOTICE = 0x06, //+ "Not a moderator of %s."; 45 | CHAT_PASSWORD_CHANGED_NOTICE = 0x07, //+ "[%s] Password changed by %s."; 46 | CHAT_OWNER_CHANGED_NOTICE = 0x08, //+ "[%s] Owner changed to %s."; 47 | CHAT_PLAYER_NOT_FOUND_NOTICE = 0x09, //+ "[%s] Player %s was not found."; 48 | CHAT_NOT_OWNER_NOTICE = 0x0A, //+ "[%s] You are not the channel owner."; 49 | CHAT_CHANNEL_OWNER_NOTICE = 0x0B, //+ "[%s] Channel owner is %s."; 50 | CHAT_MODE_CHANGE_NOTICE = 0x0C, //? 51 | CHAT_ANNOUNCEMENTS_ON_NOTICE = 0x0D, //+ "[%s] Channel announcements enabled by %s."; 52 | CHAT_ANNOUNCEMENTS_OFF_NOTICE = 0x0E, //+ "[%s] Channel announcements disabled by %s."; 53 | CHAT_MODERATION_ON_NOTICE = 0x0F, //+ "[%s] Channel moderation enabled by %s."; 54 | CHAT_MODERATION_OFF_NOTICE = 0x10, //+ "[%s] Channel moderation disabled by %s."; 55 | CHAT_MUTED_NOTICE = 0x11, //+ "[%s] You do not have permission to speak."; 56 | CHAT_PLAYER_KICKED_NOTICE = 0x12, //? "[%s] Player %s kicked by %s."; 57 | CHAT_BANNED_NOTICE = 0x13, //+ "[%s] You are bannedStore from that channel."; 58 | CHAT_PLAYER_BANNED_NOTICE = 0x14, //? "[%s] Player %s bannedStore by %s."; 59 | CHAT_PLAYER_UNBANNED_NOTICE = 0x15, //? "[%s] Player %s unbanned by %s."; 60 | CHAT_PLAYER_NOT_BANNED_NOTICE = 0x16, //+ "[%s] Player %s is not bannedStore."; 61 | CHAT_PLAYER_ALREADY_MEMBER_NOTICE = 0x17, //+ "[%s] Player %s is already on the channel."; 62 | CHAT_INVITE_NOTICE = 0x18, //+ "%2$s has invited you to join the channel '%1$s'."; 63 | CHAT_INVITE_WRONG_FACTION_NOTICE = 0x19, //+ "Target is in the wrong alliance for %s."; 64 | CHAT_WRONG_FACTION_NOTICE = 0x1A, //+ "Wrong alliance for %s."; 65 | CHAT_INVALID_NAME_NOTICE = 0x1B, //+ "Invalid channel name"; 66 | CHAT_NOT_MODERATED_NOTICE = 0x1C, //+ "%s is not moderated"; 67 | CHAT_PLAYER_INVITED_NOTICE = 0x1D, //+ "[%s] You invited %s to join the channel"; 68 | CHAT_PLAYER_INVITE_BANNED_NOTICE = 0x1E, //+ "[%s] %s has been bannedStore."; 69 | CHAT_THROTTLED_NOTICE = 0x1F, //+ "[%s] The number of messages that can be sent to this channel is limited, please wait to send another message."; 70 | CHAT_NOT_IN_AREA_NOTICE = 0x20, //+ "[%s] You are not in the correct area for this channel."; -- The user is trying to send a chat to a zone specific channel, and they're not physically in that zone. 71 | CHAT_NOT_IN_LFG_NOTICE = 0x21, //+ "[%s] You must be queued in looking for group before joining this channel."; -- The user must be in the looking for group system to join LFG chat channels. 72 | CHAT_VOICE_ON_NOTICE = 0x22, //+ "[%s] Channel voice enabled by %s."; 73 | CHAT_VOICE_OFF_NOTICE = 0x23 //+ "[%s] Channel voice disabled by %s."; 74 | }; 75 | 76 | void WorldSession::HandleChannelNotification(WorldPacket &recvPacket) 77 | { 78 | ChatNotify type = recvPacket.read(); 79 | 80 | std::string channelName; 81 | recvPacket >> channelName; 82 | 83 | switch (type) 84 | { 85 | case CHAT_YOU_JOINED_NOTICE: 86 | std::cout << "Joined Channel: [" << channelName << "]" << std::endl; 87 | break; 88 | case CHAT_YOU_LEFT_NOTICE: 89 | std::cout << "Left Channel: [" << channelName << "]" << std::endl; 90 | break; 91 | default: 92 | break; 93 | } 94 | } -------------------------------------------------------------------------------- /src/World/Handlers/CharacterHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "WorldSession.h" 19 | #include "CharacterList.h" 20 | 21 | void WorldSession::HandleCharacterEnum(WorldPacket &recvPacket) 22 | { 23 | recvPacket.ReadBits(23); 24 | recvPacket.ReadBit(); 25 | 26 | uint32_t count = recvPacket.ReadBits(17); 27 | 28 | if (!count) 29 | { 30 | std::cerr << "You don't have any characters on this realm. Please create one first!" << std::endl; 31 | socket_.Disconnect(); 32 | return; 33 | } 34 | 35 | CharacterList characterlist; 36 | characterlist.Populate(count, recvPacket); 37 | characterlist.Print(); 38 | 39 | if (Character const* character = characterlist.GetCharacterByName(session_->GetCharacterName())) 40 | { 41 | // Copy character structure 42 | player_ = Player(*character); 43 | 44 | WorldPacket packet(CMSG_LOAD_SCREEN, 5); 45 | packet << uint32_t(player_.MapId); 46 | packet.WriteBit(0x80); // unk, from [4.3.4 15595 enUS] 47 | packet.FlushBits(); 48 | SendPacket(packet); 49 | 50 | packet.Initialize(CMSG_VIOLENCE_LEVEL, 1); 51 | packet << uint8_t(0x02); // violenceLevel, from [4.3.4 15595 enUS] 52 | SendPacket(packet); 53 | 54 | packet.Initialize(CMSG_PLAYER_LOGIN, 8); 55 | packet.WriteBit(player_.Guid[2]); 56 | packet.WriteBit(player_.Guid[3]); 57 | packet.WriteBit(player_.Guid[0]); 58 | packet.WriteBit(player_.Guid[6]); 59 | packet.WriteBit(player_.Guid[4]); 60 | packet.WriteBit(player_.Guid[5]); 61 | packet.WriteBit(player_.Guid[1]); 62 | packet.WriteBit(player_.Guid[7]); 63 | 64 | packet.WriteByteSeq(player_.Guid[2]); 65 | packet.WriteByteSeq(player_.Guid[7]); 66 | packet.WriteByteSeq(player_.Guid[0]); 67 | packet.WriteByteSeq(player_.Guid[3]); 68 | packet.WriteByteSeq(player_.Guid[5]); 69 | packet.WriteByteSeq(player_.Guid[6]); 70 | packet.WriteByteSeq(player_.Guid[1]); 71 | packet.WriteByteSeq(player_.Guid[4]); 72 | SendPacket(packet); 73 | 74 | if (std::shared_ptr pingEvent = eventMgr_.GetEvent(EVENT_SEND_PING)) 75 | pingEvent->SetEnabled(true); 76 | 77 | if (std::shared_ptr keepAliveEvent = eventMgr_.GetEvent(EVENT_SEND_KEEP_ALIVE)) 78 | keepAliveEvent->SetEnabled(true); 79 | 80 | if (std::shared_ptr chatProcessEvent = eventMgr_.GetEvent(EVENT_PROCESS_CHAT_MESSAGES)) 81 | chatProcessEvent->SetEnabled(true); 82 | } 83 | else 84 | { 85 | std::cerr << "There is no character named '" << session_->GetCharacterName() << "' on this account! Please choose another one!" << std::endl; 86 | socket_.Disconnect(); 87 | } 88 | } -------------------------------------------------------------------------------- /src/World/Handlers/ChatHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "WorldSession.h" 19 | 20 | void WorldSession::HandleMessageChat(WorldPacket &recvPacket) 21 | { 22 | ChatMessage message; 23 | message.Type = recvPacket.read(); 24 | message.Language = recvPacket.read(); 25 | recvPacket >> message.SenderGUID; 26 | recvPacket >> message.Flags; 27 | 28 | switch (message.Type) 29 | { 30 | case CHAT_MSG_MONSTER_SAY: 31 | case CHAT_MSG_MONSTER_PARTY: 32 | case CHAT_MSG_MONSTER_YELL: 33 | case CHAT_MSG_MONSTER_WHISPER: 34 | case CHAT_MSG_MONSTER_EMOTE: 35 | case CHAT_MSG_RAID_BOSS_EMOTE: 36 | case CHAT_MSG_RAID_BOSS_WHISPER: 37 | case CHAT_MSG_BATTLENET: 38 | { 39 | recvPacket.read_skip(); 40 | recvPacket >> message.SenderName; 41 | recvPacket >> message.ReceiverGUID; 42 | 43 | if (!message.ReceiverGUID.IsEmpty() && !message.ReceiverGUID.IsPlayer() && !message.ReceiverGUID.IsPet()) 44 | { 45 | recvPacket.read_skip(); 46 | recvPacket >> message.ReceiverName; 47 | } 48 | 49 | if (message.Language == LANG_ADDON) 50 | recvPacket >> message.AddonPrefix; 51 | 52 | break; 53 | } 54 | case CHAT_MSG_WHISPER_FOREIGN: 55 | { 56 | recvPacket.read_skip(); 57 | recvPacket >> message.SenderName; 58 | recvPacket >> message.ReceiverGUID; 59 | 60 | if (message.Language == LANG_ADDON) 61 | recvPacket >> message.AddonPrefix; 62 | 63 | break; 64 | } 65 | case CHAT_MSG_BG_SYSTEM_NEUTRAL: 66 | case CHAT_MSG_BG_SYSTEM_ALLIANCE: 67 | case CHAT_MSG_BG_SYSTEM_HORDE: 68 | { 69 | recvPacket >> message.ReceiverGUID; 70 | 71 | if (!message.ReceiverGUID.IsEmpty() && !message.ReceiverGUID.IsPlayer()) 72 | { 73 | recvPacket.read_skip(); 74 | recvPacket >> message.ReceiverName; 75 | } 76 | 77 | if (message.Language == LANG_ADDON) 78 | recvPacket >> message.AddonPrefix; 79 | 80 | break; 81 | } 82 | case CHAT_MSG_ACHIEVEMENT: 83 | case CHAT_MSG_GUILD_ACHIEVEMENT: 84 | { 85 | recvPacket >> message.ReceiverGUID; 86 | 87 | if (message.Language == LANG_ADDON) 88 | recvPacket >> message.AddonPrefix; 89 | 90 | break; 91 | } 92 | default: 93 | { 94 | if (recvPacket.GetOpcode() == SMSG_GM_MESSAGECHAT) 95 | { 96 | recvPacket.read_skip(); 97 | recvPacket >> message.SenderName; 98 | } 99 | 100 | if (message.Type == CHAT_MSG_CHANNEL) 101 | recvPacket >> message.ChannelName; 102 | 103 | recvPacket >> message.ReceiverGUID; 104 | 105 | if (message.Language == LANG_ADDON) 106 | recvPacket >> message.AddonPrefix; 107 | 108 | break; 109 | } 110 | } 111 | 112 | recvPacket.read_skip(); 113 | recvPacket >> message.Message; 114 | 115 | ChatTag tag = recvPacket.read(); 116 | 117 | if (message.Type == CHAT_MSG_ACHIEVEMENT || message.Type == CHAT_MSG_GUILD_ACHIEVEMENT) 118 | { 119 | uint32_t achievementId; 120 | recvPacket >> achievementId; 121 | } 122 | else if (message.Type == CHAT_MSG_RAID_BOSS_WHISPER || message.Type == CHAT_MSG_RAID_BOSS_EMOTE) 123 | { 124 | float displayTime; 125 | bool hideInChatFrame; 126 | 127 | recvPacket >> displayTime; 128 | recvPacket >> hideInChatFrame; 129 | } 130 | 131 | if (message.SenderGUID.IsPlayer()) 132 | { 133 | if (!playerNames_.Has(message.SenderGUID)) 134 | SendNameQuery(message.SenderGUID); 135 | } 136 | 137 | if (message.ReceiverGUID.IsPlayer()) 138 | { 139 | if (!playerNames_.Has(message.ReceiverGUID)) 140 | SendNameQuery(message.ReceiverGUID); 141 | } 142 | 143 | if (message.Language == LANG_ADDON) 144 | return; 145 | 146 | chatMgr_.EnqueueMessage(message); 147 | } -------------------------------------------------------------------------------- /src/World/Handlers/MiscHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "WorldSession.h" 19 | #include 20 | 21 | void WorldSession::HandleMOTD(WorldPacket &recvPacket) 22 | { 23 | uint32_t lineCount; 24 | recvPacket >> lineCount; 25 | 26 | for (uint32_t i = 0; i < lineCount; i++) 27 | std::cout << recvPacket.read() << std::endl; 28 | } 29 | 30 | void WorldSession::HandlePong(WorldPacket &recvPacket) 31 | { 32 | uint32_t ping; 33 | recvPacket >> ping; 34 | 35 | std::chrono::high_resolution_clock::time_point now = std::chrono::high_resolution_clock::now(); 36 | std::chrono::milliseconds ms = std::chrono::duration_cast(now.time_since_epoch()); 37 | 38 | ping_ = uint32_t(lastPingTime_ - ms.count()); 39 | lastPingTime_ = 0; 40 | } 41 | 42 | void WorldSession::SendPing() 43 | { 44 | std::chrono::high_resolution_clock::time_point now = std::chrono::high_resolution_clock::now(); 45 | std::chrono::milliseconds ms = std::chrono::duration_cast(now.time_since_epoch()); 46 | 47 | lastPingTime_ = ms.count(); 48 | 49 | WorldPacket packet(CMSG_PING); 50 | packet << uint32_t(ping_); 51 | packet << uint32_t(ping_ / 2); 52 | SendPacket(packet); 53 | } 54 | 55 | void WorldSession::HandleTimeSyncRequest(WorldPacket &recvPacket) 56 | { 57 | uint32_t timeSyncCounter; 58 | recvPacket >> timeSyncCounter; 59 | 60 | std::chrono::high_resolution_clock::time_point now = std::chrono::high_resolution_clock::now(); 61 | std::chrono::milliseconds ms = std::chrono::duration_cast(now.time_since_epoch()); 62 | 63 | WorldPacket packet(CMSG_TIME_SYNC_RESP, 8); 64 | packet << timeSyncCounter; 65 | packet << uint32_t(ms.count()); 66 | SendPacket(packet); 67 | 68 | playerNames_.Save(); 69 | } -------------------------------------------------------------------------------- /src/World/Handlers/QueryHandler.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Anonymous2/Clientless/85422aec3984dd178f9a6d507a799f2489ea884c/src/World/Handlers/QueryHandler.cpp -------------------------------------------------------------------------------- /src/World/Handlers/WardenHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "WorldSession.h" 19 | 20 | void WorldSession::HandleWardenData(WorldPacket &recvPacket) 21 | { 22 | warden_.HandleData(recvPacket); 23 | } -------------------------------------------------------------------------------- /src/World/ObjectGuid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | * more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program. If not, see . 18 | */ 19 | 20 | #include "ObjectGuid.h" 21 | #include 22 | #include 23 | 24 | ObjectGuid const ObjectGuid::Empty = ObjectGuid(); 25 | 26 | char const* ObjectGuid::GetTypeName(HighGuid high) 27 | { 28 | switch (high) 29 | { 30 | case HIGHGUID_ITEM: return "Item"; 31 | case HIGHGUID_PLAYER: return "Player"; 32 | case HIGHGUID_GAMEOBJECT: return "Gameobject"; 33 | case HIGHGUID_TRANSPORT: return "Transport"; 34 | case HIGHGUID_UNIT: return "Creature"; 35 | case HIGHGUID_PET: return "Pet"; 36 | case HIGHGUID_VEHICLE: return "Vehicle"; 37 | case HIGHGUID_DYNAMICOBJECT: return "DynObject"; 38 | case HIGHGUID_CORPSE: return "Corpse"; 39 | case HIGHGUID_AREATRIGGER: return "AreaTrigger"; 40 | case HIGHGUID_BATTLEGROUND: return "Battleground"; 41 | case HIGHGUID_MO_TRANSPORT: return "MoTransport"; 42 | case HIGHGUID_INSTANCE: return "InstanceID"; 43 | case HIGHGUID_GROUP: return "Group"; 44 | case HIGHGUID_GUILD: return "Guild"; 45 | default: 46 | return ""; 47 | } 48 | } 49 | 50 | std::string ObjectGuid::ToString() const 51 | { 52 | std::ostringstream str; 53 | str << "GUID Full: 0x" << std::hex << std::setw(16) << std::setfill('0') << _data._guid << std::dec; 54 | str << " Type: " << GetTypeName(); 55 | if (HasEntry()) 56 | str << (IsPet() ? " Pet number: " : " Entry: ") << GetEntry() << " "; 57 | 58 | str << " Low: " << GetCounter(); 59 | return str.str(); 60 | } 61 | 62 | ByteBuffer& operator<<(ByteBuffer& buf, ObjectGuid const& guid) 63 | { 64 | buf << uint64_t(guid.GetRawValue()); 65 | return buf; 66 | } 67 | 68 | 69 | ByteBuffer& operator>>(ByteBuffer& buf, ObjectGuid& guid) 70 | { 71 | guid.Set(buf.read()); 72 | return buf; 73 | } 74 | 75 | ByteBuffer& operator<<(ByteBuffer& buf, PackedGuid const& guid) 76 | { 77 | buf.append(guid._packedGuid); 78 | return buf; 79 | } 80 | 81 | ByteBuffer& operator>>(ByteBuffer& buf, PackedGuidReader const& guid) 82 | { 83 | buf.readPackGUID(*reinterpret_cast(guid.GuidPtr)); 84 | return buf; 85 | } -------------------------------------------------------------------------------- /src/World/Player.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | #include "Common.h" 20 | #include "Character.h" 21 | 22 | struct Player : public Character 23 | { 24 | Player() { } 25 | Player(Character character) : Character(character) { } 26 | 27 | std::list Spells; 28 | std::map SpellCooldowns; 29 | std::map SpellCategoryCooldowns; 30 | }; -------------------------------------------------------------------------------- /src/World/Position.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | struct Position2D 21 | { 22 | float X; 23 | float Y; 24 | }; 25 | 26 | struct Position3D : public Position2D 27 | { 28 | float Z; 29 | }; 30 | 31 | struct Position4D : public Position3D 32 | { 33 | float O; 34 | }; -------------------------------------------------------------------------------- /src/World/SharedDefines.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | #include 22 | 23 | enum Genders : uint8_t 24 | { 25 | GENDER_MALE = 0, 26 | GENDER_FEMALE = 1, 27 | GENDER_NONE = 2 28 | }; 29 | 30 | enum Races : uint8_t 31 | { 32 | RACE_NONE = 0, 33 | RACE_HUMAN = 1, 34 | RACE_ORC = 2, 35 | RACE_DWARF = 3, 36 | RACE_NIGHTELF = 4, 37 | RACE_UNDEAD_PLAYER = 5, 38 | RACE_TAUREN = 6, 39 | RACE_GNOME = 7, 40 | RACE_TROLL = 8, 41 | RACE_GOBLIN = 9, 42 | RACE_BLOODELF = 10, 43 | RACE_DRAENEI = 11, 44 | RACE_WORGEN = 22 45 | }; 46 | 47 | enum Classes : uint8_t 48 | { 49 | CLASS_NONE = 0, 50 | CLASS_WARRIOR = 1, 51 | CLASS_PALADIN = 2, 52 | CLASS_HUNTER = 3, 53 | CLASS_ROGUE = 4, 54 | CLASS_PRIEST = 5, 55 | CLASS_DEATH_KNIGHT = 6, 56 | CLASS_SHAMAN = 7, 57 | CLASS_MAGE = 8, 58 | CLASS_WARLOCK = 9, 59 | CLASS_DRUID = 11 60 | }; 61 | 62 | enum TeamId : uint8_t 63 | { 64 | TEAM_ALLIANCE = 0, 65 | TEAM_HORDE, 66 | TEAM_NEUTRAL 67 | }; 68 | 69 | enum Team : uint16_t 70 | { 71 | HORDE = 67, 72 | ALLIANCE = 469 73 | }; 74 | 75 | enum Languages : uint32_t 76 | { 77 | LANG_UNIVERSAL = 0, 78 | LANG_ORCISH = 1, 79 | LANG_DARNASSIAN = 2, 80 | LANG_TAURAHE = 3, 81 | LANG_DWARVISH = 6, 82 | LANG_COMMON = 7, 83 | LANG_DEMONIC = 8, 84 | LANG_TITAN = 9, 85 | LANG_THALASSIAN = 10, 86 | LANG_DRACONIC = 11, 87 | LANG_KALIMAG = 12, 88 | LANG_GNOMISH = 13, 89 | LANG_TROLL = 14, 90 | LANG_GUTTERSPEAK = 33, 91 | LANG_DRAENEI = 35, 92 | LANG_ZOMBIE = 36, 93 | LANG_GNOMISH_BINARY = 37, 94 | LANG_GOBLIN_BINARY = 38, 95 | LANG_WORGEN = 39, 96 | LANG_GOBLIN = 40, 97 | LANG_ADDON = 0xFFFFFFFF // used by addons, in 2.4.0 not exist, replaced by messagetype? 98 | }; -------------------------------------------------------------------------------- /src/World/Warden.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | #include "Common.h" 20 | #include "WorldPacket.h" 21 | #include "Cryptography/WardenRC4.h" 22 | #include 23 | 24 | enum WardenOpcodes : uint8_t 25 | { 26 | WARDEN_CMSG_MODULE_MISSING = 0, 27 | WARDEN_CMSG_MODULE_OK = 1, 28 | WARDEN_CMSG_CHEAT_CHECKS_RESULT = 2, 29 | WARDEN_CMSG_MEM_CHECKS_RESULT = 3, 30 | WARDEN_CMSG_HASH_RESULT = 4, 31 | WARDEN_CMSG_MODULE_FAILED = 5, 32 | 33 | WARDEN_SMSG_MODULE_USE = 0, 34 | WARDEN_SMSG_MODULE_CACHE = 1, 35 | WARDEN_SMSG_CHEAT_CHECKS_REQUEST = 2, 36 | WARDEN_SMSG_MODULE_INITIALIZE = 3, 37 | WARDEN_SMSG_MEM_CHECKS_REQUEST = 4, 38 | WARDEN_SMSG_HASH_REQUEST = 5 39 | }; 40 | 41 | struct WardenModule 42 | { 43 | uint8_t Hash[32]; 44 | uint8_t DecryptionKey[16]; 45 | uint32_t Size; 46 | uint32_t DecompressedSize; 47 | ByteBuffer WMOD; 48 | ByteBuffer BLL; 49 | uint8_t ServerSeed[16]; 50 | }; 51 | 52 | class WorldSession; 53 | 54 | class Warden 55 | { 56 | public: 57 | Warden(WorldSession* session); 58 | 59 | void Initialize(const BigNumber* key); 60 | void PreparePacket(WorldPacket &packet, WardenOpcodes opcode); 61 | void SendPacket(WorldPacket &packet); 62 | bool VerifyModule(); 63 | void DecompressModule(); 64 | void InitializeModule(); 65 | 66 | void HandleData(WorldPacket &recvPacket); 67 | void HandleModuleInfo(WorldPacket &recvPacket); 68 | void HandleModuleData(WorldPacket &recvPacket); 69 | void HandleModuleHashRequest(WorldPacket &recvPacket); 70 | 71 | static const std::vector RSAPrivatePower; 72 | static const std::vector RSAPrivateModulus; 73 | 74 | private: 75 | WorldSession* session_; 76 | WardenRC4 crypt_; 77 | std::unique_ptr module_; 78 | }; -------------------------------------------------------------------------------- /src/World/WorldPacket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * Copyright (C) 2008-2014 TrinityCore 4 | * Copyright (C) 2005-2009 MaNGOS 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include "Network/ByteBuffer.h" 23 | #include "Opcodes.h" 24 | 25 | class WorldPacket : public ByteBuffer 26 | { 27 | public: 28 | WorldPacket() : ByteBuffer(0), opcode_(NULL_OPCODE) 29 | { 30 | } 31 | 32 | explicit WorldPacket(Opcodes opcode, size_t res = 200) : ByteBuffer(res), opcode_(opcode) 33 | { 34 | } 35 | 36 | WorldPacket(const WorldPacket &packet) : ByteBuffer(packet), opcode_(packet.opcode_) 37 | { 38 | } 39 | 40 | void Initialize(Opcodes opcode, size_t newres = 200) 41 | { 42 | clear(); 43 | storage_.reserve(newres); 44 | opcode_ = opcode; 45 | } 46 | 47 | Opcodes GetOpcode() const { return opcode_; } 48 | void SetOpcode(Opcodes opcode) { opcode_ = opcode; } 49 | 50 | protected: 51 | Opcodes opcode_; 52 | }; -------------------------------------------------------------------------------- /src/World/WorldSession.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "WorldSession.h" 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "EventMgr.h" 25 | 26 | struct WorldOpcodeHandler 27 | { 28 | Opcodes opcode; 29 | std::function callback; 30 | }; 31 | 32 | WorldSession::WorldSession(std::shared_ptr session) 33 | : session_(session), socket_(this), serverSeed_(0), chatMgr_(this), warden_(this), 34 | playerNames_("cache_players.dat"), lastPingTime_(0), ping_(0) 35 | { 36 | clientSeed_ = static_cast(time(nullptr)); 37 | playerNames_.Load(); 38 | } 39 | 40 | WorldSession::~WorldSession() 41 | { 42 | playerNames_.Save(); 43 | } 44 | 45 | #define BIND_OPCODE_HANDLER(a, b) { a, std::bind(&WorldSession::b, this, std::placeholders::_1) } 46 | 47 | const std::vector WorldSession::GetOpcodeHandlers() 48 | { 49 | return { 50 | // AuthHandler.cpp 51 | BIND_OPCODE_HANDLER(MSG_VERIFY_CONNECTIVITY, HandleConnectionVerification), 52 | BIND_OPCODE_HANDLER(SMSG_AUTH_CHALLENGE, HandleAuthenticationChallenge), 53 | BIND_OPCODE_HANDLER(SMSG_AUTH_RESPONSE, HandleAuthenticationResponse), 54 | 55 | // ChannelHandler.cpp 56 | BIND_OPCODE_HANDLER(SMSG_CHANNEL_NOTIFY, HandleChannelNotification), 57 | 58 | // CharacterHandler.cpp 59 | BIND_OPCODE_HANDLER(SMSG_CHAR_ENUM, HandleCharacterEnum), 60 | 61 | // ChatHandler.cpp 62 | BIND_OPCODE_HANDLER(SMSG_MESSAGECHAT, HandleMessageChat), 63 | BIND_OPCODE_HANDLER(SMSG_GM_MESSAGECHAT, HandleMessageChat), 64 | 65 | // MiscHandler.cpp 66 | BIND_OPCODE_HANDLER(SMSG_MOTD, HandleMOTD), 67 | BIND_OPCODE_HANDLER(SMSG_PONG, HandlePong), 68 | BIND_OPCODE_HANDLER(SMSG_TIME_SYNC_REQ, HandleTimeSyncRequest), 69 | 70 | // QueryHandler.cpp 71 | BIND_OPCODE_HANDLER(SMSG_NAME_QUERY_RESPONSE, HandleNameQueryResponse), 72 | 73 | // WardenHandler.cpp 74 | BIND_OPCODE_HANDLER(SMSG_WARDEN_DATA, HandleWardenData) 75 | }; 76 | } 77 | 78 | void WorldSession::HandlePacket(std::shared_ptr recvPacket) 79 | { 80 | static const std::vector handlers = GetOpcodeHandlers(); 81 | 82 | auto itr = std::find_if(handlers.begin(), handlers.end(), [recvPacket](const WorldOpcodeHandler& handler) { 83 | return recvPacket->GetOpcode() == handler.opcode; 84 | }); 85 | 86 | if (itr == handlers.end()) 87 | return; 88 | 89 | try 90 | { 91 | itr->callback(*recvPacket); 92 | } 93 | catch (ByteBufferException const& exception) 94 | { 95 | std::cerr << "ByteBufferException occured while handling a world packet!" << std::endl; 96 | std::cerr << "Opcode: 0x" << std::hex << std::uppercase << recvPacket->GetOpcode() << std::endl; 97 | std::cerr << exception.what() << std::endl; 98 | } 99 | } 100 | 101 | void WorldSession::SendPacket(WorldPacket &packet) 102 | { 103 | socket_.EnqueuePacket(packet); 104 | } 105 | 106 | void WorldSession::Enter() 107 | { 108 | if (!socket_.Connect(session_->GetRealm().Address)) 109 | return; 110 | 111 | eventMgr_.Stop(); 112 | { 113 | std::shared_ptr packetProcessEvent(new Event(EVENT_PROCESS_INCOMING)); 114 | packetProcessEvent->SetPeriod(10); 115 | packetProcessEvent->SetEnabled(true); 116 | packetProcessEvent->SetCallback([this]() { 117 | while (std::shared_ptr packet = socket_.GetNextPacket()) 118 | HandlePacket(packet); 119 | }); 120 | 121 | eventMgr_.AddEvent(packetProcessEvent); 122 | 123 | std::shared_ptr keepAliveEvent(new Event(EVENT_SEND_KEEP_ALIVE)); 124 | keepAliveEvent->SetPeriod(MINUTE * IN_MILLISECONDS); 125 | keepAliveEvent->SetEnabled(false); 126 | keepAliveEvent->SetCallback([this]() { 127 | WorldPacket packet(CMSG_KEEP_ALIVE, 0); 128 | SendPacket(packet); 129 | }); 130 | 131 | eventMgr_.AddEvent(keepAliveEvent); 132 | 133 | std::shared_ptr pingEvent(new Event(EVENT_SEND_PING)); 134 | pingEvent->SetPeriod((MINUTE / 2) * IN_MILLISECONDS); 135 | pingEvent->SetEnabled(false); 136 | pingEvent->SetCallback([this]() { 137 | SendPing(); 138 | }); 139 | 140 | eventMgr_.AddEvent(pingEvent); 141 | 142 | std::shared_ptr chatProcessEvent(new Event(EVENT_PROCESS_CHAT_MESSAGES)); 143 | chatProcessEvent->SetPeriod(100); 144 | chatProcessEvent->SetEnabled(false); 145 | chatProcessEvent->SetCallback([this]() { 146 | chatMgr_.ProcessMessages(); 147 | }); 148 | 149 | eventMgr_.AddEvent(chatProcessEvent); 150 | } 151 | eventMgr_.Start(); 152 | } 153 | 154 | void WorldSession::HandleConsoleCommand(std::string cmd) 155 | { 156 | std::vector args; 157 | std::stringstream ss(cmd); 158 | std::string tmp; 159 | 160 | while (std::getline(ss, tmp, ' ')) 161 | args.push_back(tmp); 162 | 163 | cmd = args[0]; 164 | 165 | if (cmd == "quit" || cmd == "disconnect" || cmd == "logout") 166 | { 167 | socket_.Disconnect(); 168 | } 169 | } 170 | 171 | WorldSocket* WorldSession::GetSocket() 172 | { 173 | return &socket_; 174 | } 175 | 176 | const PlayerNameCache* WorldSession::GetPlayerNameCache() 177 | { 178 | return &playerNames_; 179 | } -------------------------------------------------------------------------------- /src/World/WorldSession.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | #include "Common.h" 20 | #include "Session.h" 21 | #include "Opcodes.h" 22 | #include "WorldPacket.h" 23 | #include "SharedDefines.h" 24 | #include "Player.h" 25 | #include "ObjectGuid.h" 26 | #include "EventMgr.h" 27 | #include "WorldSocket.h" 28 | #include "Warden.h" 29 | #include "Cache.h" 30 | #include "ChatMgr.h" 31 | #include 32 | 33 | struct WorldOpcodeHandler; 34 | 35 | class WorldSession 36 | { 37 | friend class WorldSocket; 38 | friend class Warden; 39 | 40 | public: 41 | WorldSession(std::shared_ptr session); 42 | ~WorldSession(); 43 | 44 | void Enter(); 45 | void HandleConsoleCommand(std::string cmd); 46 | 47 | WorldSocket* GetSocket(); 48 | const PlayerNameCache* GetPlayerNameCache(); 49 | private: 50 | std::shared_ptr session_; 51 | uint32_t clientSeed_; 52 | uint32_t serverSeed_; 53 | 54 | WorldSocket socket_; 55 | EventMgr eventMgr_; 56 | ChatMgr chatMgr_; 57 | Player player_; 58 | Warden warden_; 59 | PlayerNameCache playerNames_; 60 | 61 | uint64_t lastPingTime_; 62 | uint32_t ping_; 63 | 64 | const std::vector GetOpcodeHandlers(); 65 | void HandlePacket(std::shared_ptr recvPacket); 66 | void SendPacket(WorldPacket &packet); 67 | 68 | // AuthHandler.cpp 69 | private: 70 | void HandleConnectionVerification(WorldPacket &recvPacket); 71 | void HandleAuthenticationChallenge(WorldPacket &recvPacket); 72 | void HandleAuthenticationResponse(WorldPacket &recvPacket); 73 | 74 | // ChannelHandler.cpp 75 | private: 76 | void JoinChannel(const std::string name, const std::string password = ""); 77 | void HandleChannelNotification(WorldPacket &recvPacket); 78 | 79 | // CharacterHandler.cpp 80 | private: 81 | void HandleCharacterEnum(WorldPacket &recvPacket); 82 | 83 | // ChatHandler.cpp 84 | private: 85 | void HandleMessageChat(WorldPacket &recvPacket); 86 | 87 | // MiscHandler.cpp 88 | private: 89 | void HandleMOTD(WorldPacket &recvPacket); 90 | void HandlePong(WorldPacket &recvPacket); 91 | void SendPing(); 92 | void HandleTimeSyncRequest(WorldPacket &recvPacket); 93 | 94 | // QueryHandler.cpp 95 | private: 96 | void SendNameQuery(ObjectGuid guid); 97 | void HandleNameQueryResponse(WorldPacket &recvPacket); 98 | 99 | // WardenHandler.cpp 100 | private: 101 | void HandleWardenData(WorldPacket &recvPacket); 102 | }; -------------------------------------------------------------------------------- /src/World/WorldSocket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #include "WorldSocket.h" 19 | #include "WorldSession.h" 20 | 21 | #ifndef _WIN32 22 | #include 23 | #endif 24 | 25 | WorldSocket::WorldSocket(WorldSession* session) : session_(session) 26 | { 27 | } 28 | 29 | WorldSocket::~WorldSocket() 30 | { 31 | if (IsConnected()) 32 | Disconnect(); 33 | 34 | if (senderThread_.joinable()) 35 | senderThread_.join(); 36 | 37 | if (receiverThread_.joinable()) 38 | receiverThread_.join(); 39 | } 40 | 41 | bool WorldSocket::Connect(std::string address) 42 | { 43 | assert(!IsConnected()); 44 | 45 | if (senderThread_.joinable()) 46 | senderThread_.join(); 47 | 48 | if (receiverThread_.joinable()) 49 | receiverThread_.join(); 50 | 51 | inflateStream_.zalloc = Z_NULL; 52 | inflateStream_.zfree = Z_NULL; 53 | inflateStream_.opaque = Z_NULL; 54 | inflateInit(&inflateStream_); 55 | 56 | if (!TCPSocket::Connect(address)) 57 | return false; 58 | 59 | packetCrypt_.Reset(); 60 | 61 | senderThread_ = std::thread(&WorldSocket::RunSenderThread, this); 62 | receiverThread_ = std::thread(&WorldSocket::RunReceiverThread, this); 63 | return true; 64 | } 65 | 66 | void WorldSocket::Disconnect() 67 | { 68 | TCPSocket::Disconnect(); 69 | 70 | std::lock_guard sendLock(sendMutex_); 71 | 72 | while (!sendQueue_.empty()) 73 | sendQueue_.pop(); 74 | 75 | std::lock_guard receiveLock(receiveMutex_); 76 | 77 | while (!receiveQueue_.empty()) 78 | receiveQueue_.pop(); 79 | 80 | inflateEnd(&inflateStream_); 81 | } 82 | 83 | void WorldSocket::EnqueuePacket(WorldPacket &packet) 84 | { 85 | std::shared_ptr copy(new WorldPacket(packet)); 86 | 87 | std::lock_guard lock(sendMutex_); 88 | sendQueue_.push(copy); 89 | } 90 | 91 | std::shared_ptr WorldSocket::GetNextPacket() 92 | { 93 | if (receiveQueue_.empty()) 94 | return nullptr; 95 | 96 | std::lock_guard lock(receiveMutex_); 97 | std::shared_ptr packet = receiveQueue_.front(); 98 | receiveQueue_.pop(); 99 | 100 | return packet; 101 | } 102 | 103 | void WorldSocket::RunSenderThread() 104 | { 105 | while (IsConnected()) 106 | { 107 | if (!sendQueue_.empty()) 108 | { 109 | // Acquire next packet 110 | std::lock_guard lock(sendMutex_); 111 | std::shared_ptr packet = sendQueue_.front(); 112 | sendQueue_.pop(); 113 | 114 | ByteBuffer prepared; 115 | 116 | uint16_t size = htons(packet->size() + 4); 117 | uint32_t opcode = uint32_t(packet->GetOpcode()); 118 | 119 | packetCrypt_.EncryptSend((uint8_t*)&size, 2); 120 | packetCrypt_.EncryptSend((uint8_t*)&opcode, 4); 121 | 122 | prepared << size; 123 | prepared << opcode; 124 | 125 | if (!packet->empty()) 126 | prepared.append(packet->contents(), packet->size()); 127 | 128 | Send(prepared.contents(), prepared.size()); 129 | 130 | if (packet->GetOpcode() == CMSG_AUTH_SESSION) 131 | packetCrypt_.Initialize(&session_->session_->GetKey()); 132 | } 133 | else 134 | std::this_thread::sleep_for(std::chrono::milliseconds(1)); 135 | } 136 | } 137 | 138 | void WorldSocket::RunReceiverThread() 139 | { 140 | uint8_t header[5]; 141 | uint32_t size; 142 | Opcodes opcode; 143 | 144 | while (IsConnected()) 145 | { 146 | // Read normal header (4 bytes) 147 | Read((char*)&header[0], 4); 148 | 149 | if (!IsConnected()) 150 | break; 151 | 152 | packetCrypt_.DecryptReceived(&header[0], 4); 153 | 154 | // Read additional header byte if necessary (1 byte) 155 | if (header[0] & 0x80) 156 | { 157 | Read((char*)&header[4], 1); 158 | 159 | if (!IsConnected()) 160 | break; 161 | 162 | packetCrypt_.DecryptReceived(&header[4], 1); 163 | } 164 | 165 | // Calculate size and opcode 166 | if (header[0] & 0x80) 167 | { 168 | size = ((header[0] & 0x7F) << 16) | (header[1] << 8) | header[2]; 169 | opcode = static_cast(header[3] | (header[4] << 8)); 170 | } 171 | else 172 | { 173 | size = (header[0] << 8) | header[1]; 174 | opcode = static_cast(header[2] | (header[3] << 8)); 175 | } 176 | 177 | size -= sizeof(Opcodes); 178 | 179 | // Read body 180 | std::shared_ptr packet(new WorldPacket(opcode, size)); 181 | packet->resize(size); 182 | 183 | if (size) 184 | Read(reinterpret_cast(packet->contents()), size); 185 | 186 | if (!IsConnected()) 187 | break; 188 | 189 | if (packet->GetOpcode() & COMPRESSED_OPCODE_MASK) 190 | DecompressPacket(packet); 191 | 192 | std::lock_guard lock(receiveMutex_); 193 | receiveQueue_.push(packet); 194 | } 195 | 196 | std::cout << "Disconnected from the server." << std::endl; 197 | } 198 | 199 | void WorldSocket::DecompressPacket(std::shared_ptr packet) 200 | { 201 | // Calculate real header 202 | Opcodes opcode = static_cast(packet->GetOpcode() ^ COMPRESSED_OPCODE_MASK); 203 | 204 | uint32_t size; 205 | (*packet) >> size; 206 | 207 | // Decompress packet 208 | std::vector decompressedBytes; 209 | decompressedBytes.resize(size); 210 | 211 | inflateStream_.avail_in = packet->size() - packet->rpos(); 212 | inflateStream_.next_in = const_cast(packet->contents() + packet->rpos()); 213 | inflateStream_.avail_out = size; 214 | inflateStream_.next_out = &decompressedBytes[0]; 215 | 216 | if (inflate(&inflateStream_, Z_NO_FLUSH) != Z_OK) 217 | assert(false); 218 | 219 | assert(inflateStream_.avail_in == 0); 220 | 221 | packet->Initialize(opcode, size); 222 | packet->append(&decompressedBytes[0], size); 223 | } 224 | -------------------------------------------------------------------------------- /src/World/WorldSocket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Dehravor 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (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, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "Common.h" 21 | #include "Network/TCPSocket.h" 22 | #include "Cryptography/PacketRC4.h" 23 | #include "WorldPacket.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | class WorldSession; 30 | 31 | class WorldSocket : public TCPSocket 32 | { 33 | public: 34 | WorldSocket(WorldSession* session); 35 | ~WorldSocket(); 36 | 37 | bool Connect(std::string address) override; 38 | void Disconnect() override; 39 | 40 | void EnqueuePacket(WorldPacket &packet); 41 | std::shared_ptr GetNextPacket(); 42 | private: 43 | void RunSenderThread(); 44 | void RunReceiverThread(); 45 | 46 | void DecompressPacket(std::shared_ptr packet); 47 | private: 48 | WorldSession* session_; 49 | 50 | std::thread senderThread_; 51 | std::recursive_mutex sendMutex_; 52 | std::queue> sendQueue_; 53 | 54 | std::thread receiverThread_; 55 | std::recursive_mutex receiveMutex_; 56 | std::queue> receiveQueue_; 57 | 58 | PacketRC4 packetCrypt_; 59 | z_stream_s inflateStream_; 60 | }; --------------------------------------------------------------------------------