├── stdafx.cpp
├── enet.lib
├── enet64.lib
├── Release
├── config.json
├── Descriptions.txt
├── dialogs
│ └── gazette.txt
└── corrupt.txt
├── enet server test.vcxproj.user
├── enet
├── utility.h
├── types.h
├── time.h
├── callbacks.h
├── list.h
├── unix.h
├── win32.h
├── protocol.h
└── enet.h
├── targetver.h
├── stdafx.h
├── enet server test.user
├── hash.h
├── enet server test.sln
├── enet server test.filters
├── bcrypt.h
├── bcrypt.cpp
├── HTTP
└── Program.cs
├── GTAPI.h
├── server.h
├── gamepacket.h
├── enet server test.vcxproj
└── player.h
/stdafx.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include "stdafx.h"
3 |
--------------------------------------------------------------------------------
/enet.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TaliGT/gtps-src-pack/HEAD/enet.lib
--------------------------------------------------------------------------------
/enet64.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TaliGT/gtps-src-pack/HEAD/enet64.lib
--------------------------------------------------------------------------------
/Release/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "port": 17095,
3 | "creator_name":["samuel"]
4 | }
--------------------------------------------------------------------------------
/Release/Descriptions.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TaliGT/gtps-src-pack/HEAD/Release/Descriptions.txt
--------------------------------------------------------------------------------
/Release/dialogs/gazette.txt:
--------------------------------------------------------------------------------
1 | set_default_color|`o
2 | add_label_with_icon|big|`eGrowtopia``|left|10574|
3 | end_dialog|gazette|Close|
--------------------------------------------------------------------------------
/enet server test.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/enet/utility.h:
--------------------------------------------------------------------------------
1 | /**
2 | @file utility.h
3 | @brief ENet utility header
4 | */
5 | #ifndef __ENET_UTILITY_H__
6 | #define __ENET_UTILITY_H__
7 |
8 | #define ENET_MAX(x, y) ((x) > (y) ? (x) : (y))
9 | #define ENET_MIN(x, y) ((x) < (y) ? (x) : (y))
10 |
11 | #endif /* __ENET_UTILITY_H__ */
12 |
13 |
--------------------------------------------------------------------------------
/targetver.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | // Including SDKDDKVer.h defines the highest available Windows platform.
4 |
5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
7 |
8 | #include
9 |
--------------------------------------------------------------------------------
/stdafx.h:
--------------------------------------------------------------------------------
1 | // stdafx.h : include file for standard system include files,
2 | // or project specific include files that are used frequently, but
3 | // are changed infrequently
4 | //
5 |
6 | #pragma once
7 |
8 | #ifdef _WIN32
9 | #include "targetver.h"
10 |
11 | #include
12 | #include
13 | #endif
14 |
15 |
16 | // TODO: reference additional headers your program requires here
17 |
--------------------------------------------------------------------------------
/enet/types.h:
--------------------------------------------------------------------------------
1 | /**
2 | @file types.h
3 | @brief type definitions for ENet
4 | */
5 | #ifndef __ENET_TYPES_H__
6 | #define __ENET_TYPES_H__
7 |
8 | typedef unsigned char enet_uint8; /**< unsigned 8-bit type */
9 | typedef unsigned short enet_uint16; /**< unsigned 16-bit type */
10 | typedef unsigned int enet_uint32; /**< unsigned 32-bit type */
11 |
12 | #endif /* __ENET_TYPES_H__ */
13 |
14 |
--------------------------------------------------------------------------------
/Release/corrupt.txt:
--------------------------------------------------------------------------------
1 | samuel
2 | samuel
3 | [load_player func]: samuel
4 | mrlucky
5 | mrlucky
6 | mrlucky
7 | mrlucky
8 | mrlucky
9 | mrlucky
10 | mrlucky
11 | mrlucky
12 | mrlucky
13 | mrlucky
14 | mrlucky
15 | mrlucky
16 | mrlucky
17 | mrlucky
18 | mrlucky
19 | mrlucky
20 | mrlucky
21 | mrlucky
22 | mrlucky
23 | mrlucky
24 | mrlucky
25 | mrlucky
26 | mrlucky
27 | samuel
28 | samuel
29 | samuel
30 |
--------------------------------------------------------------------------------
/enet/time.h:
--------------------------------------------------------------------------------
1 | /**
2 | @file time.h
3 | @brief ENet time constants and macros
4 | */
5 | #ifndef __ENET_TIME_H__
6 | #define __ENET_TIME_H__
7 |
8 | #define ENET_TIME_OVERFLOW 86400000
9 |
10 | #define ENET_TIME_LESS(a, b) ((a) - (b) >= ENET_TIME_OVERFLOW)
11 | #define ENET_TIME_GREATER(a, b) ((b) - (a) >= ENET_TIME_OVERFLOW)
12 | #define ENET_TIME_LESS_EQUAL(a, b) (! ENET_TIME_GREATER (a, b))
13 | #define ENET_TIME_GREATER_EQUAL(a, b) (! ENET_TIME_LESS (a, b))
14 |
15 | #define ENET_TIME_DIFFERENCE(a, b) ((a) - (b) >= ENET_TIME_OVERFLOW ? (b) - (a) : (a) - (b))
16 |
17 | #endif /* __ENET_TIME_H__ */
18 |
19 |
--------------------------------------------------------------------------------
/enet/callbacks.h:
--------------------------------------------------------------------------------
1 | /**
2 | @file callbacks.h
3 | @brief ENet callbacks
4 | */
5 | #ifndef __ENET_CALLBACKS_H__
6 | #define __ENET_CALLBACKS_H__
7 |
8 | #include
9 |
10 | typedef struct _ENetCallbacks
11 | {
12 | void * (ENET_CALLBACK * malloc) (size_t size);
13 | void (ENET_CALLBACK * free) (void * memory);
14 | void (ENET_CALLBACK * no_memory) (void);
15 | } ENetCallbacks;
16 |
17 | /** @defgroup callbacks ENet internal callbacks
18 | @{
19 | @ingroup private
20 | */
21 | extern void * enet_malloc (size_t);
22 | extern void enet_free (void *);
23 |
24 | /** @} */
25 |
26 | #endif /* __ENET_CALLBACKS_H__ */
27 |
28 |
--------------------------------------------------------------------------------
/enet server test.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ..\Release
5 | WindowsLocalDebugger
6 |
7 |
8 | ..\Release
9 | WindowsLocalDebugger
10 |
11 |
--------------------------------------------------------------------------------
/hash.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | #pragma warning(disable : 4307)
5 |
6 | #ifdef _WIN32
7 | #define INLINE __forceinline
8 | #else //for gcc/clang
9 | #define INLINE __attribute__((always_inline))
10 | #endif
11 |
12 |
13 | template
14 | class cexpr {
15 | public:
16 | static constexpr t value = val;
17 | };
18 | namespace hs {
19 | constexpr uint32_t val_32_const = 0x811c9dc5u;
20 | constexpr uint32_t prime_32_const = 0x1000193u;
21 | constexpr uint64_t val_64_const = 0xcbf29ce484222325u;
22 | constexpr uint64_t prime_64_const = 0x100000001b3u;
23 | INLINE constexpr uint32_t hash32(const char* const str, const uint32_t value = val_32_const) noexcept {
24 | return (str[0] == '\0') ? value : hash32(&str[1], (value ^ uint32_t(str[0])) * prime_32_const);
25 | }
26 | INLINE constexpr uint64_t hash64(const char* const str, const uint64_t value = val_64_const) noexcept {
27 | return (str[0] == '\0') ? value : hash64(&str[1], (value ^ uint64_t(str[0])) * prime_64_const);
28 | }
29 | } // namespace hs
30 | #define fnv32(s) (cexpr::value)
31 | #define fnv64(s) (cexpr::value)
--------------------------------------------------------------------------------
/enet/list.h:
--------------------------------------------------------------------------------
1 | /**
2 | @file list.h
3 | @brief ENet list management
4 | */
5 | #ifndef __ENET_LIST_H__
6 | #define __ENET_LIST_H__
7 |
8 | #include
9 |
10 | typedef struct _ENetListNode
11 | {
12 | struct _ENetListNode * next;
13 | struct _ENetListNode * previous;
14 | } ENetListNode;
15 |
16 | typedef ENetListNode * ENetListIterator;
17 |
18 | typedef struct _ENetList
19 | {
20 | ENetListNode sentinel;
21 | } ENetList;
22 |
23 | extern void enet_list_clear (ENetList *);
24 |
25 | extern ENetListIterator enet_list_insert (ENetListIterator, void *);
26 | extern void * enet_list_remove (ENetListIterator);
27 | extern ENetListIterator enet_list_move (ENetListIterator, void *, void *);
28 |
29 | extern size_t enet_list_size (ENetList *);
30 |
31 | #define enet_list_begin(list) ((list) -> sentinel.next)
32 | #define enet_list_end(list) (& (list) -> sentinel)
33 |
34 | #define enet_list_empty(list) (enet_list_begin (list) == enet_list_end (list))
35 |
36 | #define enet_list_next(iterator) ((iterator) -> next)
37 | #define enet_list_previous(iterator) ((iterator) -> previous)
38 |
39 | #define enet_list_front(list) ((void *) (list) -> sentinel.next)
40 | #define enet_list_back(list) ((void *) (list) -> sentinel.previous)
41 |
42 | #endif /* __ENET_LIST_H__ */
43 |
44 |
--------------------------------------------------------------------------------
/enet/unix.h:
--------------------------------------------------------------------------------
1 | /**
2 | @file unix.h
3 | @brief ENet Unix header
4 | */
5 | #ifndef __ENET_UNIX_H__
6 | #define __ENET_UNIX_H__
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | #ifdef MSG_MAXIOVLEN
16 | #define ENET_BUFFER_MAXIMUM MSG_MAXIOVLEN
17 | #endif
18 |
19 | typedef int ENetSocket;
20 |
21 | #define ENET_SOCKET_NULL -1
22 |
23 | #define ENET_HOST_TO_NET_16(value) (htons (value)) /**< macro that converts host to net byte-order of a 16-bit value */
24 | #define ENET_HOST_TO_NET_32(value) (htonl (value)) /**< macro that converts host to net byte-order of a 32-bit value */
25 |
26 | #define ENET_NET_TO_HOST_16(value) (ntohs (value)) /**< macro that converts net to host byte-order of a 16-bit value */
27 | #define ENET_NET_TO_HOST_32(value) (ntohl (value)) /**< macro that converts net to host byte-order of a 32-bit value */
28 |
29 | typedef struct
30 | {
31 | void * data;
32 | size_t dataLength;
33 | } ENetBuffer;
34 |
35 | #define ENET_CALLBACK
36 |
37 | #define ENET_API extern
38 |
39 | typedef fd_set ENetSocketSet;
40 |
41 | #define ENET_SOCKETSET_EMPTY(sockset) FD_ZERO (& (sockset))
42 | #define ENET_SOCKETSET_ADD(sockset, socket) FD_SET (socket, & (sockset))
43 | #define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLR (socket, & (sockset))
44 | #define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET (socket, & (sockset))
45 |
46 | #endif /* __ENET_UNIX_H__ */
47 |
48 |
--------------------------------------------------------------------------------
/enet server test.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.0.31717.71
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "enet server test", "enet server test.vcxproj", "{0F151D58-FD96-4DD5-A8D9-02A5F1D781D3}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {0F151D58-FD96-4DD5-A8D9-02A5F1D781D3}.Debug|x64.ActiveCfg = Debug|x64
17 | {0F151D58-FD96-4DD5-A8D9-02A5F1D781D3}.Debug|x64.Build.0 = Debug|x64
18 | {0F151D58-FD96-4DD5-A8D9-02A5F1D781D3}.Debug|x86.ActiveCfg = Debug|Win32
19 | {0F151D58-FD96-4DD5-A8D9-02A5F1D781D3}.Debug|x86.Build.0 = Debug|Win32
20 | {0F151D58-FD96-4DD5-A8D9-02A5F1D781D3}.Release|x64.ActiveCfg = Release|x64
21 | {0F151D58-FD96-4DD5-A8D9-02A5F1D781D3}.Release|x64.Build.0 = Release|x64
22 | {0F151D58-FD96-4DD5-A8D9-02A5F1D781D3}.Release|x86.ActiveCfg = Release|Win32
23 | {0F151D58-FD96-4DD5-A8D9-02A5F1D781D3}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {DC9BECDF-5FED-4662-8359-DB1007FB6FB2}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/enet/win32.h:
--------------------------------------------------------------------------------
1 | /**
2 | @file win32.h
3 | @brief ENet Win32 header
4 | */
5 | #ifndef __ENET_WIN32_H__
6 | #define __ENET_WIN32_H__
7 |
8 | #ifdef _MSC_VER
9 | #ifdef ENET_BUILDING_LIB
10 | #pragma warning (disable: 4267) // size_t to int conversion
11 | #pragma warning (disable: 4244) // 64bit to 32bit int
12 | #pragma warning (disable: 4018) // signed/unsigned mismatch
13 | #pragma warning (disable: 4146) // unary minus operator applied to unsigned type
14 | #endif
15 | #endif
16 |
17 | #include
18 | #include
19 |
20 | typedef SOCKET ENetSocket;
21 |
22 | #define ENET_SOCKET_NULL INVALID_SOCKET
23 |
24 | #define ENET_HOST_TO_NET_16(value) (htons (value))
25 | #define ENET_HOST_TO_NET_32(value) (htonl (value))
26 |
27 | #define ENET_NET_TO_HOST_16(value) (ntohs (value))
28 | #define ENET_NET_TO_HOST_32(value) (ntohl (value))
29 |
30 | typedef struct
31 | {
32 | size_t dataLength;
33 | void * data;
34 | } ENetBuffer;
35 |
36 | #define ENET_CALLBACK __cdecl
37 |
38 | #ifdef ENET_DLL
39 | #ifdef ENET_BUILDING_LIB
40 | #define ENET_API __declspec( dllexport )
41 | #else
42 | #define ENET_API __declspec( dllimport )
43 | #endif /* ENET_BUILDING_LIB */
44 | #else /* !ENET_DLL */
45 | #define ENET_API extern
46 | #endif /* ENET_DLL */
47 |
48 | typedef fd_set ENetSocketSet;
49 |
50 | #define ENET_SOCKETSET_EMPTY(sockset) FD_ZERO (& (sockset))
51 | #define ENET_SOCKETSET_ADD(sockset, socket) FD_SET (socket, & (sockset))
52 | #define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLR (socket, & (sockset))
53 | #define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET (socket, & (sockset))
54 |
55 | #endif /* __ENET_WIN32_H__ */
56 |
57 |
58 |
--------------------------------------------------------------------------------
/enet server test.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 | Header Files
35 |
36 |
37 |
38 |
39 | Source Files
40 |
41 |
42 | Source Files
43 |
44 |
45 |
--------------------------------------------------------------------------------
/bcrypt.h:
--------------------------------------------------------------------------------
1 | #ifndef BCRYPT_H_
2 | #define BCRYPT_H_
3 | /*
4 | * bcrypt wrapper library
5 | *
6 | * Written in 2011, 2013, 2014, 2015 by Ricardo Garcia
7 | *
8 | * To the extent possible under law, the author(s) have dedicated all copyright
9 | * and related and neighboring rights to this software to the public domain
10 | * worldwide. This software is distributed without any warranty.
11 | *
12 | * You should have received a copy of the CC0 Public Domain Dedication along
13 | * with this software. If not, see
14 | * .
15 | */
16 |
17 | #define BCRYPT_HASHSIZE (64)
18 |
19 | #ifdef __cplusplus
20 | extern "C" {
21 | #endif
22 |
23 | /*
24 | * This function expects a work factor between 4 and 31 and a char array to
25 | * store the resulting generated salt. The char array should typically have
26 | * BCRYPT_HASHSIZE bytes at least. If the provided work factor is not in the
27 | * previous range, it will default to 12.
28 | *
29 | * The return value is zero if the salt could be correctly generated and
30 | * nonzero otherwise.
31 | *
32 | */
33 | int bcrypt_gensalt(int workfactor, char salt[BCRYPT_HASHSIZE]);
34 |
35 | /*
36 | * This function expects a password to be hashed, a salt to hash the password
37 | * with and a char array to leave the result. Both the salt and the hash
38 | * parameters should have room for BCRYPT_HASHSIZE characters at least.
39 | *
40 | * It can also be used to verify a hashed password. In that case, provide the
41 | * expected hash in the salt parameter and verify the output hash is the same
42 | * as the input hash. However, to avoid timing attacks, it's better to use
43 | * bcrypt_checkpw when verifying a password.
44 | *
45 | * The return value is zero if the password could be hashed and nonzero
46 | * otherwise.
47 | */
48 | int bcrypt_hashpw(const char *passwd, const char salt[BCRYPT_HASHSIZE],
49 | char hash[BCRYPT_HASHSIZE]);
50 |
51 | /*
52 | * This function expects a password and a hash to verify the password against.
53 | * The internal implementation is tuned to avoid timing attacks.
54 | *
55 | * The return value will be -1 in case of errors, zero if the provided password
56 | * matches the given hash and greater than zero if no errors are found and the
57 | * passwords don't match.
58 | *
59 | */
60 | int bcrypt_checkpw(const char *passwd, const char hash[BCRYPT_HASHSIZE]);
61 |
62 | /*
63 | * Brief Example
64 | * -------------
65 | *
66 | * Hashing a password:
67 | *
68 | * char salt[BCRYPT_HASHSIZE];
69 | * char hash[BCRYPT_HASHSIZE];
70 | * int ret;
71 | *
72 | * ret = bcrypt_gensalt(12, salt);
73 | * assert(ret == 0);
74 | * ret = bcrypt_hashpw("thepassword", salt, hash);
75 | * assert(ret == 0);
76 | *
77 | *
78 | * Verifying a password:
79 | *
80 | * int ret;
81 | *
82 | * ret = bcrypt_checkpw("thepassword", "expectedhash");
83 | * assert(ret != -1);
84 | *
85 | * if (ret == 0) {
86 | * printf("The password matches\n");
87 | * } else {
88 | * printf("The password does NOT match\n");
89 | * }
90 | *
91 | */
92 |
93 | #ifdef __cplusplus
94 | }
95 | #endif
96 |
97 | #endif
98 |
--------------------------------------------------------------------------------
/bcrypt.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * bcrypt wrapper library
3 | *
4 | * Written in 2011, 2013, 2014, 2015 by Ricardo Garcia
5 | *
6 | * To the extent possible under law, the author(s) have dedicated all copyright
7 | * and related and neighboring rights to this software to the public domain
8 | * worldwide. This software is distributed without any warranty.
9 | *
10 | * You should have received a copy of the CC0 Public Domain Dedication along
11 | * with this software. If not, see
12 | * .
13 | */
14 | #include
15 | #include
16 | #include
17 | #include
18 | //#include
19 | #ifndef _UNISTD_H
20 | #define _UNISTD_H 1
21 |
22 | /* This is intended as a drop-in replacement for unistd.h on Windows.
23 | * Please add functionality as neeeded.
24 | * https://stackoverflow.com/a/826027/1202830
25 | */
26 |
27 | #include
28 | #include
29 | //#include /* getopt at: https://gist.github.com/ashelly/7776712 */
30 | #include /* for getpid() and the exec..() family */
31 | #include /* for _getcwd() and _chdir() */
32 |
33 | #define srandom srand
34 | #define random rand
35 |
36 | /* Values for the second argument to access.
37 | These may be OR'd together. */
38 | #define R_OK 4 /* Test for read permission. */
39 | #define W_OK 2 /* Test for write permission. */
40 | //#define X_OK 1 /* execute permission - unsupported in windows*/
41 | #define F_OK 0 /* Test for existence. */
42 |
43 | #define access _access
44 | #define dup2 _dup2
45 | #define execve _execve
46 | #define ftruncate _chsize
47 | #define unlink _unlink
48 | #define fileno _fileno
49 | #define getcwd _getcwd
50 | #define chdir _chdir
51 | #define isatty _isatty
52 | #define lseek _lseek
53 | /* read, write, and close are NOT being #defined here, because while there are file handle specific versions for Windows, they probably don't work for sockets. You need to look at your app and consider whether to call e.g. closesocket(). */
54 |
55 | #ifdef _WIN64
56 | #define ssize_t __int64
57 | #else
58 | #define ssize_t long
59 | #endif
60 |
61 | #define STDIN_FILENO 0
62 | #define STDOUT_FILENO 1
63 | #define STDERR_FILENO 2
64 | /* should be in some equivalent to */
65 | //typedef __int8 int8_t;
66 | typedef __int16 int16_t;
67 | typedef __int32 int32_t;
68 | typedef __int64 int64_t;
69 | typedef unsigned __int8 uint8_t;
70 | typedef unsigned __int16 uint16_t;
71 | typedef unsigned __int32 uint32_t;
72 | typedef unsigned __int64 uint64_t;
73 |
74 | #endif /* unistd.h */
75 |
76 | #include
77 |
78 | #include "bcrypt.h"
79 | #include "crypt_blowfish/ow-crypt.h"
80 |
81 | #define RANDBYTES (16)
82 |
83 | /*
84 | * This is a best effort implementation. Nothing prevents a compiler from
85 | * optimizing this function and making it vulnerable to timing attacks, but
86 | * this method is commonly used in crypto libraries like NaCl.
87 | *
88 | * Return value is zero if both strings are equal and nonzero otherwise.
89 | */
90 | static int timing_safe_strcmp(const char *str1, const char *str2)
91 | {
92 | const unsigned char *u1;
93 | const unsigned char *u2;
94 | int ret;
95 | int i;
96 |
97 | int len1 = strlen(str1);
98 | int len2 = strlen(str2);
99 |
100 | /* In our context both strings should always have the same length
101 | * because they will be hashed passwords. */
102 | if (len1 != len2)
103 | return 1;
104 |
105 | /* Force unsigned for bitwise operations. */
106 | u1 = (const unsigned char *)str1;
107 | u2 = (const unsigned char *)str2;
108 |
109 | ret = 0;
110 | for (i = 0; i < len1; ++i)
111 | ret |= (u1[i] ^ u2[i]);
112 |
113 | return ret;
114 | }
115 |
116 | int bcrypt_gensalt(int factor, char salt[BCRYPT_HASHSIZE])
117 | {
118 | int fd;
119 | char input[RANDBYTES];
120 | int workf;
121 | char *aux;
122 |
123 | for (int i = 0; i < RANDBYTES; i++)
124 | {
125 | input[i] = rand();
126 | }
127 |
128 | /* Generate salt. */
129 | workf = (factor < 4 || factor > 31)?12:factor;
130 | aux = crypt_gensalt_rn("$2a$", workf, input, RANDBYTES,
131 | salt, BCRYPT_HASHSIZE);
132 | return (aux == NULL)?5:0;
133 | }
134 |
135 | int bcrypt_hashpw(const char *passwd, const char salt[BCRYPT_HASHSIZE], char hash[BCRYPT_HASHSIZE])
136 | {
137 | char *aux;
138 | aux = crypt_rn(passwd, salt, hash, BCRYPT_HASHSIZE);
139 | return (aux == NULL)?1:0;
140 | }
141 |
142 | int bcrypt_checkpw(const char *passwd, const char hash[BCRYPT_HASHSIZE])
143 | {
144 | int ret;
145 | char outhash[BCRYPT_HASHSIZE];
146 |
147 | ret = bcrypt_hashpw(passwd, hash, outhash);
148 | if (ret != 0)
149 | return -1;
150 |
151 | return timing_safe_strcmp(hash, outhash);
152 | }
153 |
154 | #ifdef TEST_BCRYPT
155 | #include
156 | #include
157 | #include
158 | #include
159 |
160 | int main(void)
161 | {
162 | clock_t before;
163 | clock_t after;
164 | char salt[BCRYPT_HASHSIZE];
165 | char hash[BCRYPT_HASHSIZE];
166 | int ret;
167 |
168 | const char pass[] = "hi,mom";
169 | const char hash1[] = "$2a$10$VEVmGHy4F4XQMJ3eOZJAUeb.MedU0W10pTPCuf53eHdKJPiSE8sMK";
170 | const char hash2[] = "$2a$10$3F0BVk5t8/aoS.3ddaB3l.fxg5qvafQ9NybxcpXLzMeAt.nVWn.NO";
171 |
172 | ret = bcrypt_gensalt(12, salt);
173 | assert(ret == 0);
174 | printf("Generated salt: %s\n", salt);
175 | before = clock();
176 | ret = bcrypt_hashpw("testtesttest", salt, hash);
177 | assert(ret == 0);
178 | after = clock();
179 | printf("Hashed password: %s\n", hash);
180 | printf("Time taken: %f seconds\n",
181 | (double)(after - before) / CLOCKS_PER_SEC);
182 |
183 | ret = bcrypt_hashpw(pass, hash1, hash);
184 | assert(ret == 0);
185 | printf("First hash check: %s\n", (strcmp(hash1, hash) == 0)?"OK":"FAIL");
186 | ret = bcrypt_hashpw(pass, hash2, hash);
187 | assert(ret == 0);
188 | printf("Second hash check: %s\n", (strcmp(hash2, hash) == 0)?"OK":"FAIL");
189 |
190 | before = clock();
191 | ret = (bcrypt_checkpw(pass, hash1) == 0);
192 | after = clock();
193 | printf("First hash check with bcrypt_checkpw: %s\n", ret?"OK":"FAIL");
194 | printf("Time taken: %f seconds\n",
195 | (double)(after - before) / CLOCKS_PER_SEC);
196 |
197 | before = clock();
198 | ret = (bcrypt_checkpw(pass, hash2) == 0);
199 | after = clock();
200 | printf("Second hash check with bcrypt_checkpw: %s\n", ret?"OK":"FAIL");
201 | printf("Time taken: %f seconds\n",
202 | (double)(after - before) / CLOCKS_PER_SEC);
203 |
204 | return 0;
205 | }
206 | #endif
207 |
--------------------------------------------------------------------------------
/enet/protocol.h:
--------------------------------------------------------------------------------
1 | /**
2 | @file protocol.h
3 | @brief ENet protocol
4 | */
5 | #ifndef __ENET_PROTOCOL_H__
6 | #define __ENET_PROTOCOL_H__
7 |
8 | #include "enet/types.h"
9 |
10 | enum
11 | {
12 | ENET_PROTOCOL_MINIMUM_MTU = 576,
13 | ENET_PROTOCOL_MAXIMUM_MTU = 4096,
14 | ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS = 32,
15 | ENET_PROTOCOL_MINIMUM_WINDOW_SIZE = 4096,
16 | ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE = 65536,
17 | ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 1,
18 | ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255,
19 | ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xFFF,
20 | ENET_PROTOCOL_MAXIMUM_FRAGMENT_COUNT = 1024 * 1024
21 | };
22 |
23 | typedef enum _ENetProtocolCommand
24 | {
25 | ENET_PROTOCOL_COMMAND_NONE = 0,
26 | ENET_PROTOCOL_COMMAND_ACKNOWLEDGE = 1,
27 | ENET_PROTOCOL_COMMAND_CONNECT = 2,
28 | ENET_PROTOCOL_COMMAND_VERIFY_CONNECT = 3,
29 | ENET_PROTOCOL_COMMAND_DISCONNECT = 4,
30 | ENET_PROTOCOL_COMMAND_PING = 5,
31 | ENET_PROTOCOL_COMMAND_SEND_RELIABLE = 6,
32 | ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE = 7,
33 | ENET_PROTOCOL_COMMAND_SEND_FRAGMENT = 8,
34 | ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED = 9,
35 | ENET_PROTOCOL_COMMAND_BANDWIDTH_LIMIT = 10,
36 | ENET_PROTOCOL_COMMAND_THROTTLE_CONFIGURE = 11,
37 | ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE_FRAGMENT = 12,
38 | ENET_PROTOCOL_COMMAND_COUNT = 13,
39 |
40 | ENET_PROTOCOL_COMMAND_MASK = 0x0F
41 | } ENetProtocolCommand;
42 |
43 | typedef enum _ENetProtocolFlag
44 | {
45 | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE = (1 << 7),
46 | ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED = (1 << 6),
47 |
48 | ENET_PROTOCOL_HEADER_FLAG_COMPRESSED = (1 << 14),
49 | ENET_PROTOCOL_HEADER_FLAG_SENT_TIME = (1 << 15),
50 | ENET_PROTOCOL_HEADER_FLAG_MASK = ENET_PROTOCOL_HEADER_FLAG_COMPRESSED | ENET_PROTOCOL_HEADER_FLAG_SENT_TIME,
51 |
52 | ENET_PROTOCOL_HEADER_SESSION_MASK = (3 << 12),
53 | ENET_PROTOCOL_HEADER_SESSION_SHIFT = 12
54 | } ENetProtocolFlag;
55 |
56 | #ifdef _MSC_VER
57 | #pragma pack(push, 1)
58 | #define ENET_PACKED
59 | #elif defined(__GNUC__) || defined(__clang__)
60 | #define ENET_PACKED __attribute__ ((packed))
61 | #else
62 | #define ENET_PACKED
63 | #endif
64 |
65 | typedef struct _ENetProtocolHeader
66 | {
67 | enet_uint16 peerID;
68 | enet_uint16 sentTime;
69 | } ENET_PACKED ENetProtocolHeader;
70 |
71 | typedef struct _ENetProtocolCommandHeader
72 | {
73 | enet_uint8 command;
74 | enet_uint8 channelID;
75 | enet_uint16 reliableSequenceNumber;
76 | } ENET_PACKED ENetProtocolCommandHeader;
77 |
78 | typedef struct _ENetProtocolAcknowledge
79 | {
80 | ENetProtocolCommandHeader header;
81 | enet_uint16 receivedReliableSequenceNumber;
82 | enet_uint16 receivedSentTime;
83 | } ENET_PACKED ENetProtocolAcknowledge;
84 |
85 | typedef struct _ENetProtocolConnect
86 | {
87 | ENetProtocolCommandHeader header;
88 | enet_uint16 outgoingPeerID;
89 | enet_uint8 incomingSessionID;
90 | enet_uint8 outgoingSessionID;
91 | enet_uint32 mtu;
92 | enet_uint32 windowSize;
93 | enet_uint32 channelCount;
94 | enet_uint32 incomingBandwidth;
95 | enet_uint32 outgoingBandwidth;
96 | enet_uint32 packetThrottleInterval;
97 | enet_uint32 packetThrottleAcceleration;
98 | enet_uint32 packetThrottleDeceleration;
99 | enet_uint32 connectID;
100 | enet_uint32 data;
101 | } ENET_PACKED ENetProtocolConnect;
102 |
103 | typedef struct _ENetProtocolVerifyConnect
104 | {
105 | ENetProtocolCommandHeader header;
106 | enet_uint16 outgoingPeerID;
107 | enet_uint8 incomingSessionID;
108 | enet_uint8 outgoingSessionID;
109 | enet_uint32 mtu;
110 | enet_uint32 windowSize;
111 | enet_uint32 channelCount;
112 | enet_uint32 incomingBandwidth;
113 | enet_uint32 outgoingBandwidth;
114 | enet_uint32 packetThrottleInterval;
115 | enet_uint32 packetThrottleAcceleration;
116 | enet_uint32 packetThrottleDeceleration;
117 | enet_uint32 connectID;
118 | } ENET_PACKED ENetProtocolVerifyConnect;
119 |
120 | typedef struct _ENetProtocolBandwidthLimit
121 | {
122 | ENetProtocolCommandHeader header;
123 | enet_uint32 incomingBandwidth;
124 | enet_uint32 outgoingBandwidth;
125 | } ENET_PACKED ENetProtocolBandwidthLimit;
126 |
127 | typedef struct _ENetProtocolThrottleConfigure
128 | {
129 | ENetProtocolCommandHeader header;
130 | enet_uint32 packetThrottleInterval;
131 | enet_uint32 packetThrottleAcceleration;
132 | enet_uint32 packetThrottleDeceleration;
133 | } ENET_PACKED ENetProtocolThrottleConfigure;
134 |
135 | typedef struct _ENetProtocolDisconnect
136 | {
137 | ENetProtocolCommandHeader header;
138 | enet_uint32 data;
139 | } ENET_PACKED ENetProtocolDisconnect;
140 |
141 | typedef struct _ENetProtocolPing
142 | {
143 | ENetProtocolCommandHeader header;
144 | } ENET_PACKED ENetProtocolPing;
145 |
146 | typedef struct _ENetProtocolSendReliable
147 | {
148 | ENetProtocolCommandHeader header;
149 | enet_uint16 dataLength;
150 | } ENET_PACKED ENetProtocolSendReliable;
151 |
152 | typedef struct _ENetProtocolSendUnreliable
153 | {
154 | ENetProtocolCommandHeader header;
155 | enet_uint16 unreliableSequenceNumber;
156 | enet_uint16 dataLength;
157 | } ENET_PACKED ENetProtocolSendUnreliable;
158 |
159 | typedef struct _ENetProtocolSendUnsequenced
160 | {
161 | ENetProtocolCommandHeader header;
162 | enet_uint16 unsequencedGroup;
163 | enet_uint16 dataLength;
164 | } ENET_PACKED ENetProtocolSendUnsequenced;
165 |
166 | typedef struct _ENetProtocolSendFragment
167 | {
168 | ENetProtocolCommandHeader header;
169 | enet_uint16 startSequenceNumber;
170 | enet_uint16 dataLength;
171 | enet_uint32 fragmentCount;
172 | enet_uint32 fragmentNumber;
173 | enet_uint32 totalLength;
174 | enet_uint32 fragmentOffset;
175 | } ENET_PACKED ENetProtocolSendFragment;
176 |
177 | typedef union _ENetProtocol
178 | {
179 | ENetProtocolCommandHeader header;
180 | ENetProtocolAcknowledge acknowledge;
181 | ENetProtocolConnect connect;
182 | ENetProtocolVerifyConnect verifyConnect;
183 | ENetProtocolDisconnect disconnect;
184 | ENetProtocolPing ping;
185 | ENetProtocolSendReliable sendReliable;
186 | ENetProtocolSendUnreliable sendUnreliable;
187 | ENetProtocolSendUnsequenced sendUnsequenced;
188 | ENetProtocolSendFragment sendFragment;
189 | ENetProtocolBandwidthLimit bandwidthLimit;
190 | ENetProtocolThrottleConfigure throttleConfigure;
191 | } ENET_PACKED ENetProtocol;
192 |
193 | #ifdef _MSC_VER
194 | #pragma pack(pop)
195 | #endif
196 |
197 | #endif /* __ENET_PROTOCOL_H__ */
198 |
199 |
--------------------------------------------------------------------------------
/HTTP/Program.cs:
--------------------------------------------------------------------------------
1 | /*GTPS-HTTP-CS
2 | A HTTP Server made with C#, based on Growbrew Proxy HTTP Server.
3 | */
4 | using System;
5 | using System.Diagnostics;
6 | using System.IO;
7 | using System.Linq;
8 | using System.Net;
9 | using System.Text;
10 | using System.Threading;
11 | namespace HTTP
12 | {
13 | internal class Program
14 | {
15 | private static HttpListener listener = new HttpListener();
16 | private static Random random = new Random();
17 |
18 | public static string RandomString(int length) => new string(Enumerable.Repeat("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", length).Select((Func)(s => s[Program.random.Next(s.Length)])).ToArray());
19 |
20 | private static bool ProgramIsRunning(string FullPath)
21 | {
22 | string directoryName = Path.GetDirectoryName(FullPath);
23 | string lower = Path.GetFileNameWithoutExtension(FullPath).ToLower();
24 | bool flag = false;
25 | foreach (Process process in Process.GetProcessesByName(lower))
26 | {
27 | if (process.MainModule.FileName.StartsWith(directoryName, StringComparison.InvariantCultureIgnoreCase))
28 | {
29 | flag = true;
30 | break;
31 | }
32 | }
33 | return flag;
34 | }
35 |
36 | public static void ExecuteCommand(string command)
37 | {
38 | Process proc = new System.Diagnostics.Process();
39 | proc.StartInfo.FileName = "/bin/bash";
40 | proc.StartInfo.Arguments = "-c \" " + command + " \"";
41 | proc.StartInfo.UseShellExecute = false;
42 | proc.StartInfo.RedirectStandardOutput = true;
43 | proc.Start();
44 |
45 | while (!proc.StandardOutput.EndOfStream)
46 | {
47 | Console.WriteLine(proc.StandardOutput.ReadLine());
48 | }
49 | }
50 | public const string guidFWPolicy2 = "{E2B3C97F-6AE1-41AC-817A-F6F92166D7DD}";
51 | public const string guidRWRule = "{2C5BC43E-3369-4C33-AB0C-BE9469677AF4}";
52 |
53 |
54 | public static void HTTPHandler()
55 | {
56 | string str1 = DateTimeOffset.UtcNow.ToString();
57 | while (Program.listener.IsListening)
58 | {
59 | try
60 | {
61 | string empty = string.Empty;
62 | HttpListenerContext context = Program.listener.GetContext();
63 | HttpListenerRequest request = context.Request;
64 | HttpListenerResponse response = context.Response;
65 | string str2 = request.RemoteEndPoint.ToString().Split(':')[0];
66 | string host = request.Url.Host;
67 | string str3 = request.Url.ToString();
68 | string str4 = request.Url.Port.ToString();
69 | Console.WriteLine("[" + str1 + "] [IP]: " + str2);
70 | Console.WriteLine("[" + str1 + "] [URL]: " + str3);
71 | if (str3.Contains("/favicon.ico"))
72 | {
73 | }
74 | else if (host == "growtopia2.com" && request.HttpMethod == "POST" || host == "growtopia1.com" && request.HttpMethod == "POST" || host == "gttc.sytes.net" && request.HttpMethod == "POST" || host == "rtsoft.com" && request.HttpMethod == "POST" || host == "hamumu.com" && request.HttpMethod == "POST")
75 | {
76 | if (str3.Contains("growtopia/server_data.php"))
77 | {
78 | byte[] bytes = Encoding.UTF8.GetBytes(System.IO.File.ReadAllText("server_data.php"));
79 | response.ContentLength64 = (long)bytes.Length;
80 | Stream outputStream = response.OutputStream;
81 | outputStream.Write(bytes, 0, bytes.Length);
82 | outputStream.Close();
83 | response.Close();
84 | }
85 | }
86 | else
87 | {
88 | Console.WriteLine("[" + str1 + "] [Blocked IP ADDRESS]: " + str2);
89 | ProcessStartInfo procStartInfo = new ProcessStartInfo("/bin/bash", "-c \"iptables -A INPUT -s " +str2 + " -j DROP\"");
90 | procStartInfo.RedirectStandardOutput = true;
91 | procStartInfo.UseShellExecute = false;
92 | procStartInfo.CreateNoWindow = true;
93 |
94 | System.Diagnostics.Process proc = new System.Diagnostics.Process();
95 | proc.StartInfo = procStartInfo;
96 | proc.Start();
97 | Thread.Sleep(250);
98 | }
99 | response.Close();
100 | }
101 | catch (Exception ex)
102 | {
103 | Console.WriteLine("[" + str1 + "] [ERROR]: " + ex.Message + " ");
104 | Thread.Sleep(1000);
105 | }
106 | }
107 | }
108 |
109 | public static void StartHTTP(string[] prefixes)
110 | {
111 | string str = DateTimeOffset.UtcNow.ToString();
112 | Console.WriteLine("[" + str + "] [INFO]: Setting up HTTP Server...");
113 | if (!HttpListener.IsSupported)
114 | {
115 | Console.WriteLine("[" + str + "] [ERROR]: Windows XP SP2 or Server 2003 is required to use the HttpListener class.");
116 | }
117 | else
118 | {
119 | if (prefixes == null || prefixes.Length == 0)
120 | throw new ArgumentException(nameof(prefixes));
121 | foreach (string prefix in prefixes)
122 | Program.listener.Prefixes.Add(prefix);
123 | Program.listener.Start();
124 | if (Program.listener.IsListening)
125 | Console.WriteLine("[" + str + "] [INFO]: Listening!");
126 | else
127 | Console.WriteLine("[" + str + "] [ERROR]: Could not listen to port 80, an error occured!");
128 | new Thread(new ThreadStart(Program.HTTPHandler)).Start();
129 | Console.WriteLine("[" + str + "] [INFO]: HTTP Server is running.");
130 | }
131 | }
132 |
133 | private static void Main(string[] args) => Program.StartHTTP(new string[1]
134 | {
135 | "http://*:80/"
136 | });
137 | }
138 | }
--------------------------------------------------------------------------------
/GTAPI.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************************
2 | First Growtopia Private Server made with ENet.
3 | Copyright (C) 2018 Growtopia Noobs
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License as published
6 | by the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
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 Affero General Public License for more details.
12 | You should have received a copy of the GNU Affero General Public License
13 | along with this program. If not, see .
14 | **********************************************************************************/
15 |
16 | #pragma region Includes
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #pragma warning(disable:4996)
30 | #ifndef _UNISTD_H
31 | #define _UNISTD_H 1
32 | #include
33 | #include
34 | #include
35 | #include
36 | #define srandom srand
37 | #define random rand
38 | #define R_OK 4
39 | #define W_OK 2
40 | #define F_OK 0
41 | #define access _access
42 | #define dup2 _dup2
43 | #define execve _execve
44 | #define ftruncate _chsize
45 | #define unlink _unlink
46 | #define fileno _fileno
47 | #define getcwd _getcwd
48 | #define chdir _chdir
49 | #define isatty _isatty
50 | #define lseek _lseek
51 | #ifdef _WIN64
52 | #define ssize_t __int64
53 | #else
54 | #define ssize_t long
55 | #endif
56 | #define STDIN_FILENO 0
57 | #define STDOUT_FILENO 1
58 | #define STDERR_FILENO 2
59 | typedef __int16 int16_t;
60 | typedef __int32 int32_t;
61 | typedef __int64 int64_t;
62 | typedef unsigned __int8 uint8_t;
63 | typedef unsigned __int16 uint16_t;
64 | typedef unsigned __int32 uint32_t;
65 | typedef unsigned __int64 uint64_t;
66 |
67 | #endif _UNISTD_H
68 |
69 |
70 | using namespace std;
71 |
72 | #pragma endregion
73 | /*
74 | =* Growtopia Dialog Stuff *=
75 | =* For examples, check https://github.com/GrowtopiaNoobs/GrowtopiaServer *=
76 | */
77 |
78 | enum LabelStyles {
79 | LABEL_BIG,
80 | LABEL_SMALL
81 | };
82 |
83 | enum SpacerTypes
84 | {
85 | SPACER_BIG,
86 | SPACER_SMALL
87 | };
88 |
89 | enum CheckboxTypes
90 | {
91 | CHECKBOX_SELECTED,
92 | CHECKBOX_NOT_SELECTED
93 | };
94 | #pragma region Dialog stuff
95 | /*
96 | Dialog api starts.
97 | */
98 |
99 |
100 | class GTDialog
101 | {
102 | public:
103 | string dialogstr = "";
104 | void addSpacer(SpacerTypes type);
105 | void addLabelWithIcon(string text, int tileid, LabelStyles type);
106 | void addButton(string buttonname, string buttontext);
107 | void addCheckbox(string checkboxname, string string, CheckboxTypes type);
108 | void addTextBox(string str);
109 | void addSmallText(string str);
110 | void addInputBox(string name, string text, string cont, int size);
111 | void addQuickExit();
112 | void endDialog(string name, string accept, string nvm);
113 | void addCustom(string name);
114 | string finishDialog();
115 |
116 | operator string() {
117 | return this->dialogstr;
118 | }
119 | };
120 |
121 |
122 | void GTDialog::addSpacer(SpacerTypes type) {
123 | switch (type)
124 | {
125 | case SPACER_BIG:
126 | this->dialogstr.append("add_spacer|big|\n");
127 | break;
128 | case SPACER_SMALL:
129 | this->dialogstr.append("add_spacer|small|\n");
130 | break;
131 | default:
132 | break;
133 | }
134 | }
135 |
136 | void GTDialog::addLabelWithIcon(string text, int tileid, LabelStyles type) {
137 | switch (type)
138 | {
139 | case LABEL_BIG:
140 | this->dialogstr.append("add_label_with_icon|big|" + text + "|left|" + to_string(tileid) + "|\n");
141 | break;
142 | case LABEL_SMALL:
143 | this->dialogstr.append("add_label_with_icon|small|" + text + "|left|" + to_string(tileid) + "|\n");
144 | break;
145 | default:
146 | break;
147 | }
148 | }
149 |
150 | void GTDialog::addButton(string buttonname, string buttontext) {
151 | this->dialogstr.append("add_button|" + buttonname + "|" + buttontext + "|noflags|0|0|\n");
152 | }
153 |
154 | void GTDialog::addCheckbox(string checkboxname, string string, CheckboxTypes type) {
155 | switch (type)
156 | {
157 | case CHECKBOX_SELECTED:
158 | this->dialogstr.append("add_checkbox|" + checkboxname + "|" + string + "|1|\n");
159 | break;
160 | case CHECKBOX_NOT_SELECTED:
161 | this->dialogstr.append("add_checkbox|" + checkboxname + "|" + string + "|0|\n");
162 | break;
163 | default:
164 | break;
165 | }
166 | }
167 |
168 | void GTDialog::addTextBox(string str) {
169 | this->dialogstr.append("add_textbox|" + str + "|left|\n");
170 | }
171 |
172 | void GTDialog::addSmallText(string str) {
173 | this->dialogstr.append("add_smalltext|" + str + "|\n");
174 | }
175 |
176 | void GTDialog::addInputBox(string name, string text, string cont, int size) {
177 | this->dialogstr.append("add_text_input|" + name + "|" + text + "|" + cont + "|" + to_string(size) + "|\n");
178 | }
179 |
180 | void GTDialog::addQuickExit() {
181 | this->dialogstr.append("add_quick_exit|\n");
182 | }
183 |
184 | void GTDialog::endDialog(string name, string accept, string nvm) {
185 | this->dialogstr.append("end_dialog|" + name + "|" + nvm + "|" + accept + "|\n");
186 | }
187 |
188 | void GTDialog::addCustom(string name) {
189 | this->dialogstr.append(name + "\n");
190 | }
191 |
192 | string GTDialog::finishDialog() {
193 | return this->dialogstr;
194 | }
195 | #pragma endregion
196 |
197 | #pragma region Items.Dat
198 |
199 | /*
200 | Taken from Gamedeveloper magazine's InnerProduct (Sean Barrett 2005-03-15)
201 |
202 | Created by Seth Robinson on 3/6/09.
203 | (c) RTSoft. All rights reserved.
204 | */
205 |
206 | /*
207 | Get the file size. It's for binary.
208 | */
209 | std::ifstream::pos_type filesize(string filename)
210 | {
211 | std::ifstream in(filename, std::ifstream::ate | std::ifstream::binary);
212 | return in.tellg();
213 | }
214 |
215 | /*
216 | Hash the file.
217 | */
218 | uint32_t HashString(unsigned char* str, int len)
219 | {
220 | if (!str) return 0;
221 |
222 | unsigned char* n = (unsigned char*)str;
223 | uint32_t acc = 0x55555555;
224 |
225 | if (len == 0)
226 | {
227 | while (*n)
228 | acc = (acc >> 27) + (acc << 5) + *n++;
229 | }
230 | else
231 | {
232 | for (int i = 0; i < len; i++)
233 | {
234 | acc = (acc >> 27) + (acc << 5) + *n++;
235 | }
236 | }
237 | return acc;
238 |
239 | }
240 |
241 | /*
242 | GetHash from ProtonSDK.
243 | */
244 | unsigned char* getA(string fileName, int* pSizeOut, bool bAddBasePath, bool bAutoDecompress)
245 | {
246 | unsigned char* pData = NULL;
247 | FILE* fp = fopen(fileName.c_str(), "rb");
248 | if (!fp)
249 | {
250 | cout << "File not found" << endl;
251 | if (!fp) return NULL;
252 | }
253 |
254 | fseek(fp, 0, SEEK_END);
255 | *pSizeOut = ftell(fp);
256 | fseek(fp, 0, SEEK_SET);
257 |
258 | pData = (unsigned char*)new unsigned char[((*pSizeOut) + 1)];
259 | if (!pData)
260 | {
261 | printf("Out of memory opening %s?", fileName.c_str());
262 | return 0;
263 | }
264 | pData[*pSizeOut] = 0;
265 | fread(pData, *pSizeOut, 1, fp);
266 | fclose(fp);
267 |
268 | return pData;
269 | }
270 |
271 | int GetHashOf(string path) {
272 | uint8_t* pData;
273 | int size = 0;
274 | size = filesize(path);
275 | pData = getA((string)path, &size, false, false);
276 | return HashString((unsigned char*)pData, size);
277 | }
278 | #pragma endregion
279 |
--------------------------------------------------------------------------------
/server.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "enet/enet.h"
3 |
4 | #pragma warning(disable : 4996)
5 | using namespace std;
6 | using namespace std::chrono;
7 | using json = nlohmann::json;
8 | #define BlastProperties_Null 0
9 | #define BlastProperties_RandomDeco1 1
10 | #define BlastProperties_RandomDeco2 2
11 | #define BlastProperties_WaterLevelD2 4
12 | #define STR16(x, y) (*(uint16_t*)(&(x)[(y)]))
13 | #define STRINT(x, y) (*(int*)(&(x)[(y)]))
14 | #pragma region dialogs
15 | string heatwave;
16 | long long int last_ = 0;
17 | #pragma endregion dialogs
18 | int coredatasize = 0;
19 | int configPort = 17096;
20 | bool usemars = false;
21 | vector threads;
22 | bool usedthermoblast = false;
23 | string newslist = "set_default_color|`o\n\nadd_label_with_icon|big|`wThe Growtopia Gazette``|left|5016|\n\nadd_spacer|small|\nadd_label_with_icon|small|`4WARNING:`` `5Worlds (and accounts)`` might be deleted at any time if database issues appear (once per day or week).|left|4|\nadd_label_with_icon|small|`4WARNING:`` `5Accounts`` are in beta, bugs may appear and they will be probably deleted often, because of new account updates, which will cause database incompatibility.|left|4|\nadd_spacer|small|\n\nadd_url_button||``Watch: `1Watch a video about GT Private Server``|NOFLAGS|https://www.youtube.com/watch?v=_3avlDDYBBY|Open link?|0|0|\nadd_url_button||``Channel: `1Watch Growtopia Noobs' channel``|NOFLAGS|https://www.youtube.com/channel/UCLXtuoBlrXFDRtFU8vPy35g|Open link?|0|0|\nadd_url_button||``Items: `1Item database by Nenkai``|NOFLAGS|https://raw.githubusercontent.com/Nenkai/GrowtopiaItemDatabase/master/GrowtopiaItemDatabase/CoreData.txt|Open link?|0|0|\nadd_url_button||``Discord: `1GT Private Server Discord``|NOFLAGS|https://discord.gg/8WUTs4v|Open the link?|0|0|\nadd_quick_exit|\n\nend_dialog|gazette|Close||";
24 | string configCDN = "0098/CDNContent46/cache/";
25 | string player1 = "";
26 | int daily_item1 = 0, daily_item2 = 0, _amount_for_daily = 20;
27 | int gemevent = 0;
28 | string player2 = "";
29 | bool started = false;
30 | string ipban = "";
31 | ENetHost* server;
32 | string chat_links = "";
33 | string login_links = "";
34 | vectorcreatorname;
35 | int cId = 1;
36 | string worldas_ = "";
37 | int resultnbr1 = 0, resultnbr2 = 0, hasil = 0, prize = 0;
38 | string toUpperCase(std::string& s)
39 | {
40 | for (char& c : s)
41 | c = toupper(c);
42 | return s;
43 | }
44 | struct point {
45 | int x;
46 | int y;
47 | };
48 | BYTE* itemsDat = 0;
49 | int itemsDatSize = 0;
50 | int itemdathash;
51 |
52 | BYTE* itemsDatNormal = 0;
53 | int itemsDatSizeNormal = 0;
54 | int itemdathashNormal;
55 | void decodeName(char* src, int len, int itemID, char* dest) {
56 | const char key[] = "PBG892FXX982ABC*";
57 | for (int i = 0; i < len; i++) {
58 | dest[i] = src[i] ^ key[(i + itemID) % 16];
59 | }
60 | }
61 | string toLowerCase(std::string& s)
62 | {
63 | try {
64 | for (char& c : s)
65 | c = tolower(c);
66 | return s;
67 | } catch (std::exception& e) {
68 | std::cout << e.what() << std::endl;
69 | } catch (const std::out_of_range& e) {
70 | std::cout << e.what() << std::endl;
71 | }
72 | }
73 | const std::string currentDateTime() {
74 | const int MAXLEN = 80;
75 | char s[MAXLEN];
76 | time_t t = time(0);
77 | strftime(s, MAXLEN, "%m/%d/%Y", localtime(&t));
78 | return s;
79 | }
80 |
81 | string GetPlayerCountServer()
82 | {
83 | auto count = 0;
84 | for (auto currentPeer = server->peers; currentPeer < &server->peers[server->peerCount]; ++currentPeer) {
85 | if (currentPeer->state != ENET_PEER_STATE_CONNECTED || currentPeer->data == NULL) continue;
86 | count++;
87 | }
88 | return to_string(count);
89 | }
90 |
91 | struct itemDataStruct {
92 | string name;
93 | string texturefile;
94 | string audiofile;
95 | int id;
96 | uint8_t editableType;
97 | uint8_t category;
98 | uint8_t type;
99 | uint8_t solid;
100 | uint16_t rarity;
101 | uint32_t color1;
102 | uint32_t color2;
103 | uint8_t textureX;
104 | uint8_t textureY;
105 | uint8_t textureType;
106 | uint8_t hardness;
107 | uint16_t audioVol;
108 | uint32_t texturehash;
109 | uint32_t audiohash;
110 | uint8_t seedBase;
111 | uint8_t seedOverlay;
112 | uint8_t treeBase;
113 | uint8_t treeOverlay;
114 | int punchEffect = 0;
115 | };
116 |
117 | enum editableType {
118 | consumable = 20
119 | };
120 |
121 | enum itemType {
122 | clothing = 20,
123 | background = 18,
124 | sheet_music = 28,
125 | lock = 3
126 | };
127 | struct BlockVisual {
128 | int packetType;
129 | int characterState;
130 | int punchX;
131 | int punchY;
132 | int charStat;
133 | int blockid;
134 | int visual;
135 | int signs;
136 | int backgroundid;
137 | int displayblock;
138 | int time;
139 | int netID;
140 | //int bpm;
141 | };
142 |
143 | struct TileExtra {
144 | int packetType;
145 | int characterState;
146 | float objectSpeedX;
147 | int punchX;
148 | int punchY;
149 | int charStat;
150 | int blockid;
151 | int visual;
152 | int signs;
153 | int backgroundid;
154 | int displayblock;
155 | int time;
156 | int netID;
157 | int weatherspeed;
158 | int bpm;
159 | //int unused1;
160 | //int unused2;
161 | //int unused3;
162 | //int bpm;
163 | };
164 |
165 | string join(const vector v, const char delimeter) {
166 | string str;
167 | for (auto p = v.begin(); p != v.end(); ++p) {
168 | str += *p;
169 | if (p != (v.end() - 1))
170 | str += delimeter;
171 | }
172 | return str;
173 | }
174 | void replaceAll(std::string& source, const std::string& from, const std::string& to) {
175 | try {
176 | std::string newString;
177 | newString.reserve(source.length());
178 | std::string::size_type lastPos = 0;
179 | std::string::size_type findPos;
180 | while (std::string::npos != (findPos = source.find(from, lastPos))) {
181 | newString.append(source, lastPos, findPos - lastPos);
182 | newString += to;
183 | lastPos = findPos + from.length();
184 | }
185 | newString += source.substr(lastPos);
186 | source.swap(newString);
187 | }
188 | catch (const std::out_of_range& p) {
189 | std::cerr << p.what() << std::endl;
190 | }
191 | catch (const std::exception& p) {
192 | std::cerr << p.what() << std::endl;
193 | }
194 | }
195 | std::string replace1(std::string str, const std::string& from, const std::string& to) {
196 | try {
197 | size_t start_pos = 0;
198 | while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
199 | str.replace(start_pos, from.length(), to);
200 | start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
201 | }
202 | } catch (const std::out_of_range& p) {
203 | std::cerr << p.what() << std::endl;
204 | } catch (const std::exception& p) {
205 | std::cerr << p.what() << std::endl;
206 | }
207 | return str;
208 | }
209 | string BanDays(int time) {
210 | string x;
211 | int day = time / (24 * 3600);
212 | x.append(to_string(day));
213 | //n = n % (24 * 3600);
214 | return x;
215 | }
216 |
217 | string BanHours(int time) {
218 | string x;
219 | time = time % (24 * 3600);
220 | int hour = time / 3600;
221 | x.append(to_string(hour));
222 | //n = n % (24 * 3600);
223 | return x;
224 | }
225 | string BanSecs(int n) {
226 | string x;
227 | n %= 60;
228 | int seconds = n;
229 | x.append(to_string(seconds));
230 | //n = n % (24 * 3600);
231 | return x;
232 | }
233 | string BanMinutes(int n) {
234 | string x;
235 | n %= 3600;
236 | int minutes = n / 60;
237 | x.append(to_string(minutes));
238 | //n = n % (24 * 3600);
239 | return x;
240 | }
241 | string discord = "https://discord.gg/NWpngCe";
242 | long long GetCurrentTimeInternal() {
243 | return (duration_cast(system_clock::now().time_since_epoch())).count();
244 | }
245 | long long GetCurrentTimeInternalSeconds() {
246 | return (duration_cast(system_clock::now().time_since_epoch())).count();
247 | }
248 |
249 | int calcBanDuration(const long long banDuration) {
250 | int duration = 0;
251 | duration = banDuration - GetCurrentTimeInternalSeconds();
252 | if (duration <= 0) return 0;
253 | else return duration;
254 | }
255 |
256 | int CoreDataItems = 0;
257 | int userIDcount = 0;
258 |
259 | string filterName2(string password) {
260 |
261 | string filteredpass = "";
262 | for (int i = 0; i < password.length(); i++) {
263 | string ch = password.substr(i, 1); // always take 1 character, and move next. EXAMPLE: we got password 12345, it will take first 1 and check, then 2 and check, and 3 and check, 4 and check, 5 and ccheck. it will scan ALL characters if bad symbols etc. because i is always getting a higher number cuz we said i++
264 | if (ch != "a" && ch != "A" && ch != "b" && ch != "B" && ch != "c" && ch != "C" && ch != "d" && ch != "D" && ch != "e" && ch != "E"
265 | && ch != "f" && ch != "F" && ch != "g" && ch != "G" && ch != "h" && ch != "H" && ch != "i" && ch != "I" && ch != "j" && ch != "J"
266 | && ch != "k" && ch != "K" && ch != "l" && ch != "L" && ch != "m" && ch != "M" && ch != "n" && ch != "N" && ch != "o" && ch != "O" &&
267 | ch != "p" && ch != "P" && ch != "q" && ch != "Q" && ch != "r" && ch != "R" && ch != "s" && ch != "S" && ch != "t" && ch != "T" && ch != "u" && ch != "U"
268 | && ch != "v" && ch != "V" && ch != "w" && ch != "W" && ch != "x" && ch != "X" && ch != "y" && ch != "Y" && ch != "z" && ch != "Z" && ch != "0" && ch != "1" && ch != "2"
269 | && ch != "3" && ch != "4" && ch != "5" && ch != "6" && ch != "7" && ch != "8" && ch != "9" && ch != "!" && ch != "." && ch != "@") {
270 |
271 |
272 | }
273 | else
274 | {
275 | filteredpass = filteredpass + ch;
276 | }
277 | }
278 | return filteredpass;
279 | }
280 |
281 | bool serverIsFrozen = false;
--------------------------------------------------------------------------------
/gamepacket.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "enet/enet.h"
3 | #include "server.h"
4 | using namespace std;
5 |
6 | char* GetTextPointerFromPacket(ENetPacket* packet)
7 | {
8 | char zero = 0;
9 | memcpy(packet->data + packet->dataLength - 1, &zero, 1);
10 | return (char*)(packet->data + 4);
11 | }
12 |
13 | BYTE* GetStructPointerFromTankPacket(ENetPacket* packet)
14 | {
15 | const unsigned int packetLenght = packet->dataLength;
16 | BYTE* result = nullptr;
17 | if (packetLenght >= 0x3C)
18 | {
19 | BYTE* packetData = packet->data;
20 | result = packetData + 4;
21 | if (*static_cast(packetData + 16) & 8)
22 | {
23 | if (packetLenght < *reinterpret_cast(packetData + 56) + 60)
24 | {
25 | result = nullptr;
26 | }
27 | }
28 | else
29 | {
30 | int zero = 0;
31 | memcpy(packetData + 56, &zero, 4);
32 | }
33 | }
34 | return result;
35 | }
36 | int GetMessageTypeFromPacket(ENetPacket* packet) {
37 | int result = 0;
38 | if (packet->dataLength > 3u) {
39 | result = *(packet->data);
40 | }
41 | return result;
42 | }
43 |
44 | vector explode(const string& delimiter, const string& str)
45 | {
46 | vector arr;
47 | const int strleng = str.length();
48 | const int delleng = delimiter.length();
49 | if (delleng == 0)
50 | return arr;
51 | int i = 0;
52 | int k = 0;
53 | while (i < strleng)
54 | {
55 | int j = 0;
56 | while (i + j < strleng && j < delleng && str.at(i + j) == delimiter.at(j))
57 | j++;
58 | if (j == delleng)
59 | {
60 | arr.push_back(str.substr(k, i - k));
61 | i += delleng;
62 | k = i;
63 | }
64 | else
65 | {
66 | i++;
67 | }
68 | }
69 | arr.push_back(str.substr(k, i - k));
70 | return arr;
71 | }
72 |
73 |
74 | void sendData(ENetPeer* peer, int num, char* data, const int len)
75 | {
76 | const auto packet = enet_packet_create(nullptr, len + 5, ENET_PACKET_FLAG_RELIABLE);
77 | memcpy(packet->data, &num, 4);
78 | if (data != nullptr) {
79 | memcpy(packet->data + 2, data, len);
80 | }
81 | char zero = 0;
82 | memcpy(packet->data + 2 + len, &zero, 1);
83 | enet_peer_send(peer, 0, packet);
84 | }
85 |
86 | int getPacketId(char* data)
87 | {
88 | return *data;
89 | }
90 |
91 | char* getPacketData(char* data)
92 | {
93 | return data + 4;
94 | }
95 |
96 |
97 | int ch2n(char x)
98 | {
99 | switch (x)
100 | {
101 | case '0':
102 | return 0;
103 | case '1':
104 | return 1;
105 | case '2':
106 | return 2;
107 | case '3':
108 | return 3;
109 | case '4':
110 | return 4;
111 | case '5':
112 | return 5;
113 | case '6':
114 | return 6;
115 | case '7':
116 | return 7;
117 | case '8':
118 | return 8;
119 | case '9':
120 | return 9;
121 | case 'A':
122 | return 10;
123 | case 'B':
124 | return 11;
125 | case 'C':
126 | return 12;
127 | case 'D':
128 | return 13;
129 | case 'E':
130 | return 14;
131 | case 'F':
132 | return 15;
133 | default:
134 | break;
135 | }
136 | }
137 | struct gamepacket_t
138 | {
139 | private:
140 | int index = 0;
141 | int len = 0;
142 | byte* packet_data = new byte[61];
143 |
144 | public:
145 | gamepacket_t(int delay = 0, int NetID = -1) {
146 |
147 | len = 61;
148 | int MessageType = 0x4;
149 | int PacketType = 0x1;
150 | int CharState = 0x8;
151 |
152 | memset(packet_data, 0, 61);
153 | memcpy(packet_data, &MessageType, 4);
154 | memcpy(packet_data + 4, &PacketType, 4);
155 | memcpy(packet_data + 8, &NetID, 4);
156 | memcpy(packet_data + 16, &CharState, 4);
157 | memcpy(packet_data + 24, &delay, 4);
158 | };
159 | ~gamepacket_t() {
160 | delete[] packet_data;
161 | }
162 |
163 | void Insert(string a) {
164 | byte* data = new byte[len + 2 + a.length() + 4];
165 | memcpy(data, packet_data, len);
166 | delete[] packet_data;
167 | packet_data = data;
168 | data[len] = index;
169 | data[len + 1] = 0x2;
170 | int str_len = a.length();
171 | memcpy(data + len + 2, &str_len, 4);
172 | memcpy(data + len + 6, a.data(), str_len);
173 | len = len + 2 + a.length() + 4;
174 | index++;
175 | packet_data[60] = (byte)index;
176 | }
177 | void Insert(int a) {
178 | byte* data = new byte[len + 2 + 4];
179 | memcpy(data, packet_data, len);
180 | delete[] packet_data;
181 | packet_data = data;
182 | data[len] = index;
183 | data[len + 1] = 0x9;
184 | memcpy(data + len + 2, &a, 4);
185 | len = len + 2 + 4;
186 | index++;
187 | packet_data[60] = (byte)index;
188 | }
189 | void Insert(unsigned int a) {
190 | byte* data = new byte[len + 2 + 4];
191 | memcpy(data, packet_data, len);
192 | delete[] packet_data;
193 | packet_data = data;
194 | data[len] = index;
195 | data[len + 1] = 0x5;
196 | memcpy(data + len + 2, &a, 4);
197 | len = len + 2 + 4;
198 | index++;
199 | packet_data[60] = (byte)index;
200 | }
201 | void Insert(float a) {
202 | byte* data = new byte[len + 2 + 4];
203 | memcpy(data, packet_data, len);
204 | delete[] packet_data;
205 | packet_data = data;
206 | data[len] = index;
207 | data[len + 1] = 0x1;
208 | memcpy(data + len + 2, &a, 4);
209 | len = len + 2 + 4;
210 | index++;
211 | packet_data[60] = (byte)index;
212 | }
213 | void Insert(float a, float b) {
214 | byte* data = new byte[len + 2 + 8];
215 | memcpy(data, packet_data, len);
216 | delete[] packet_data;
217 | packet_data = data;
218 | data[len] = index;
219 | data[len + 1] = 0x3;
220 | memcpy(data + len + 2, &a, 4);
221 | memcpy(data + len + 6, &b, 4);
222 | len = len + 2 + 8;
223 | index++;
224 | packet_data[60] = (byte)index;
225 | }
226 | void Insert(float a, float b, float c) {
227 | byte* data = new byte[len + 2 + 12];
228 | memcpy(data, packet_data, len);
229 | delete[] packet_data;
230 | packet_data = data;
231 | data[len] = index;
232 | data[len + 1] = 0x4;
233 | memcpy(data + len + 2, &a, 4);
234 | memcpy(data + len + 6, &b, 4);
235 | memcpy(data + len + 10, &c, 4);
236 | len = len + 2 + 12;
237 | index++;
238 | packet_data[60] = (byte)index;
239 | }
240 | void CreatePacket(ENetPeer* peer) {
241 | ENetPacket* packet = enet_packet_create(packet_data, len, 1);
242 | enet_peer_send(peer, 0, packet);
243 | }
244 | };
245 | struct GamePacket
246 | {
247 | BYTE* data;
248 | int len;
249 | int indexes;
250 | };
251 |
252 | GamePacket appendFloat(GamePacket p, float val)
253 | {
254 | //p.data[56] += 1;
255 | BYTE* n = new BYTE[p.len + 2 + 4];
256 | memcpy(n, p.data, p.len);
257 | delete[] p.data;
258 | p.data = n;
259 | n[p.len] = p.indexes;
260 | n[p.len + 1] = 1;
261 | memcpy(n + p.len + 2, &val, 4);
262 | p.len = p.len + 2 + 4;
263 | p.indexes++;
264 | return p;
265 | }
266 |
267 | GamePacket appendFloat(GamePacket p, float val, float val2)
268 | {
269 | //p.data[56] += 1;
270 | BYTE* n = new BYTE[p.len + 2 + 8];
271 | memcpy(n, p.data, p.len);
272 | delete[] p.data;
273 | p.data = n;
274 | n[p.len] = p.indexes;
275 | n[p.len + 1] = 3;
276 | memcpy(n + p.len + 2, &val, 4);
277 | memcpy(n + p.len + 6, &val2, 4);
278 | p.len = p.len + 2 + 8;
279 | p.indexes++;
280 | return p;
281 | }
282 |
283 | GamePacket appendFloat(GamePacket p, float val, float val2, float val3)
284 | {
285 | //p.data[56] += 1;
286 | BYTE* n = new BYTE[p.len + 2 + 12];
287 | memcpy(n, p.data, p.len);
288 | delete[] p.data;
289 | p.data = n;
290 | n[p.len] = p.indexes;
291 | n[p.len + 1] = 4;
292 | memcpy(n + p.len + 2, &val, 4);
293 | memcpy(n + p.len + 6, &val2, 4);
294 | memcpy(n + p.len + 10, &val3, 4);
295 | p.len = p.len + 2 + 12;
296 | p.indexes++;
297 | return p;
298 | }
299 |
300 | GamePacket appendInt(GamePacket p, int val)
301 | {
302 | //p.data[56] += 1;
303 | BYTE* n = new BYTE[p.len + 2 + 4];
304 | memcpy(n, p.data, p.len);
305 | delete[] p.data;
306 | p.data = n;
307 | n[p.len] = p.indexes;
308 | n[p.len + 1] = 9;
309 | memcpy(n + p.len + 2, &val, 4);
310 | p.len = p.len + 2 + 4;
311 | p.indexes++;
312 | return p;
313 | }
314 |
315 | GamePacket appendIntx(GamePacket p, int val)
316 | {
317 | //p.data[56] += 1;
318 | BYTE* n = new BYTE[p.len + 2 + 4];
319 | memcpy(n, p.data, p.len);
320 | delete[] p.data;
321 | p.data = n;
322 | n[p.len] = p.indexes;
323 | n[p.len + 1] = 5;
324 | memcpy(n + p.len + 2, &val, 4);
325 | p.len = p.len + 2 + 4;
326 | p.indexes++;
327 | return p;
328 | }
329 |
330 | GamePacket appendString(GamePacket p, string str)
331 | {
332 | //p.data[56] += 1;
333 | BYTE* n = new BYTE[p.len + 2 + str.length() + 4];
334 | memcpy(n, p.data, p.len);
335 | delete[] p.data;
336 | p.data = n;
337 | n[p.len] = p.indexes;
338 | n[p.len + 1] = 2;
339 | int sLen = str.length();
340 | memcpy(n + p.len + 2, &sLen, 4);
341 | memcpy(n + p.len + 6, str.c_str(), sLen);
342 | p.len = p.len + 2 + str.length() + 4;
343 | p.indexes++;
344 | return p;
345 | }
346 |
347 | GamePacket createPacket()
348 | {
349 | BYTE* data = new BYTE[61];
350 | try {
351 | string asdf = "0400000001000000FFFFFFFF00000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
352 | for (int i = 0; i < asdf.length(); i += 2)
353 | {
354 | char x = ch2n(asdf.at(i));
355 | x = x << 4;
356 | x += ch2n(asdf[i + 1]);
357 | memcpy(data + (i / 2), &x, 1);
358 | if (asdf.length() > 61 * 2) throw 0;
359 | }
360 | }
361 | catch (std::exception& e) {
362 | std::cout << e.what() << std::endl;
363 | }
364 | catch (const std::out_of_range& e) {
365 | std::cout << e.what() << std::endl;
366 | }
367 | GamePacket packet{};
368 | packet.data = data;
369 | packet.len = 61;
370 | packet.indexes = 0;
371 | return packet;
372 | }
373 |
374 | GamePacket packetEnd(GamePacket p)
375 | {
376 | BYTE* n = new BYTE[p.len + 1];
377 | memcpy(n, p.data, p.len);
378 | delete[] p.data;
379 | p.data = n;
380 | char zero = 0;
381 | memcpy(p.data + p.len, &zero, 1);
382 | p.len += 1;
383 | //*(int*)(p.data + 52) = p.len;
384 | *(int*)(p.data + 56) = p.indexes;//p.len-60;//p.indexes;
385 | *(BYTE*)(p.data + 60) = p.indexes;
386 | //*(p.data + 57) = p.indexes;
387 | return p;
388 | }
389 |
390 | void SendGamePacket(ENetPeer* peer, GamePacket* p)
391 | {
392 | ENetPacket* packet1 = enet_packet_create(p->data,
393 | p->len,
394 | ENET_PACKET_FLAG_RELIABLE);
395 | enet_peer_send(peer, 0, packet1);
396 | delete p->data;
397 | }
--------------------------------------------------------------------------------
/enet server test.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Debug
10 | x64
11 |
12 |
13 | Release
14 | Win32
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | {0F151D58-FD96-4DD5-A8D9-02A5F1D781D3}
23 | Win32Proj
24 | enetservertest
25 | server
26 |
27 |
28 |
29 | Application
30 | true
31 | v142
32 | Unicode
33 |
34 |
35 | Application
36 | true
37 | v142
38 | Unicode
39 |
40 |
41 | Application
42 | false
43 | v142
44 | true
45 | Unicode
46 |
47 |
48 | Application
49 | false
50 | v142
51 | true
52 | Unicode
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | true
72 | $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);C:\Users\AMD\Documents\Visual Studio 2013\Projects\enet server test\enet server test\enet;
73 | $(VC_IncludePath);$(WindowsSDK_IncludePath);C:\Users\AMD\Documents\Visual Studio 2013\Projects\enet server test\enet server test\enet;
74 | $(VC_ReferencesPath_x86);C:\Users\AMD\Documents\Visual Studio 2013\Projects\enet server test\enet server test\enet;
75 |
76 |
77 | true
78 | $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);C:\Users\AMD\Documents\Visual Studio 2013\Projects\enet server test\enet server test\enet;
79 | $(VC_IncludePath);$(WindowsSDK_IncludePath);C:\Users\AMD\Documents\Visual Studio 2013\Projects\enet server test\enet server test\enet;
80 | $(VC_ReferencesPath_x86);C:\Users\AMD\Documents\Visual Studio 2013\Projects\enet server test\enet server test\enet;
81 |
82 |
83 | false
84 |
85 |
86 | false
87 |
88 |
89 |
90 | Use
91 | Level3
92 | Disabled
93 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
94 | true
95 |
96 |
97 | Console
98 | true
99 | enet.lib;ws2_32.lib;winmm.lib;%(AdditionalDependencies)
100 |
101 |
102 |
103 |
104 | Use
105 | Level3
106 | Disabled
107 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
108 | true
109 |
110 |
111 | Console
112 | true
113 | enet.lib;ws2_32.lib;winmm.lib;%(AdditionalDependencies)
114 |
115 |
116 |
117 |
118 | Level3
119 | Use
120 | MaxSpeed
121 | true
122 | true
123 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
124 | true
125 | Speed
126 |
127 |
128 | Console
129 | true
130 | true
131 | true
132 | enet.lib;ws2_32.lib;winmm.lib;%(AdditionalDependencies)
133 | false
134 | true
135 | false
136 |
137 |
138 |
139 |
140 | Level3
141 | Use
142 | MaxSpeed
143 | true
144 | true
145 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
146 | true
147 |
148 |
149 | Console
150 | true
151 | true
152 | true
153 | enet.lib;ws2_32.lib;winmm.lib;%(AdditionalDependencies)
154 | false
155 | true
156 | false
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 | Create
174 | Create
175 | Create
176 | Create
177 |
178 |
179 |
180 |
181 |
182 |
--------------------------------------------------------------------------------
/enet/enet.h:
--------------------------------------------------------------------------------
1 | /**
2 | @file enet.h
3 | @brief ENet public header file
4 | */
5 | #ifndef __ENET_ENET_H__
6 | #define __ENET_ENET_H__
7 |
8 | #ifdef __cplusplus
9 | extern "C"
10 | {
11 | #endif
12 |
13 | #include
14 |
15 | #ifdef _WIN32
16 | #include "enet/win32.h"
17 | #else
18 | #include "enet/unix.h"
19 | #endif
20 |
21 | #include "enet/types.h"
22 | #include "enet/protocol.h"
23 | #include "enet/list.h"
24 | #include "enet/callbacks.h"
25 |
26 | #define ENET_VERSION_MAJOR 1
27 | #define ENET_VERSION_MINOR 3
28 | #define ENET_VERSION_PATCH 13
29 | #define ENET_VERSION_CREATE(major, minor, patch) (((major)<<16) | ((minor)<<8) | (patch))
30 | #define ENET_VERSION_GET_MAJOR(version) (((version)>>16)&0xFF)
31 | #define ENET_VERSION_GET_MINOR(version) (((version)>>8)&0xFF)
32 | #define ENET_VERSION_GET_PATCH(version) ((version)&0xFF)
33 | #define ENET_VERSION ENET_VERSION_CREATE(ENET_VERSION_MAJOR, ENET_VERSION_MINOR, ENET_VERSION_PATCH)
34 |
35 | typedef enet_uint32 ENetVersion;
36 |
37 | struct _ENetHost;
38 | struct _ENetEvent;
39 | struct _ENetPacket;
40 |
41 | typedef enum _ENetSocketType
42 | {
43 | ENET_SOCKET_TYPE_STREAM = 1,
44 | ENET_SOCKET_TYPE_DATAGRAM = 2
45 | } ENetSocketType;
46 |
47 | typedef enum _ENetSocketWait
48 | {
49 | ENET_SOCKET_WAIT_NONE = 0,
50 | ENET_SOCKET_WAIT_SEND = (1 << 0),
51 | ENET_SOCKET_WAIT_RECEIVE = (1 << 1),
52 | ENET_SOCKET_WAIT_INTERRUPT = (1 << 2)
53 | } ENetSocketWait;
54 |
55 | typedef enum _ENetSocketOption
56 | {
57 | ENET_SOCKOPT_NONBLOCK = 1,
58 | ENET_SOCKOPT_BROADCAST = 2,
59 | ENET_SOCKOPT_RCVBUF = 3,
60 | ENET_SOCKOPT_SNDBUF = 4,
61 | ENET_SOCKOPT_REUSEADDR = 5,
62 | ENET_SOCKOPT_RCVTIMEO = 6,
63 | ENET_SOCKOPT_SNDTIMEO = 7,
64 | ENET_SOCKOPT_ERROR = 8,
65 | ENET_SOCKOPT_NODELAY = 9
66 | } ENetSocketOption;
67 |
68 | typedef enum _ENetSocketShutdown
69 | {
70 | ENET_SOCKET_SHUTDOWN_READ = 0,
71 | ENET_SOCKET_SHUTDOWN_WRITE = 1,
72 | ENET_SOCKET_SHUTDOWN_READ_WRITE = 2
73 | } ENetSocketShutdown;
74 |
75 | #define ENET_HOST_ANY 0
76 | #define ENET_HOST_BROADCAST 0xFFFFFFFFU
77 | #define ENET_PORT_ANY 0
78 |
79 | /**
80 | * Portable internet address structure.
81 | *
82 | * The host must be specified in network byte-order, and the port must be in host
83 | * byte-order. The constant ENET_HOST_ANY may be used to specify the default
84 | * server host. The constant ENET_HOST_BROADCAST may be used to specify the
85 | * broadcast address (255.255.255.255). This makes sense for enet_host_connect,
86 | * but not for enet_host_create. Once a server responds to a broadcast, the
87 | * address is updated from ENET_HOST_BROADCAST to the server's actual IP address.
88 | */
89 | typedef struct _ENetAddress
90 | {
91 | enet_uint32 host;
92 | enet_uint16 port;
93 | } ENetAddress;
94 |
95 | /**
96 | * Packet flag bit constants.
97 | *
98 | * The host must be specified in network byte-order, and the port must be in
99 | * host byte-order. The constant ENET_HOST_ANY may be used to specify the
100 | * default server host.
101 |
102 | @sa ENetPacket
103 | */
104 | typedef enum _ENetPacketFlag
105 | {
106 | /** packet must be received by the target peer and resend attempts should be
107 | * made until the packet is delivered */
108 | ENET_PACKET_FLAG_RELIABLE = (1 << 0),
109 | /** packet will not be sequenced with other packets
110 | * not supported for reliable packets
111 | */
112 | ENET_PACKET_FLAG_UNSEQUENCED = (1 << 1),
113 | /** packet will not allocate data, and user must supply it instead */
114 | ENET_PACKET_FLAG_NO_ALLOCATE = (1 << 2),
115 | /** packet will be fragmented using unreliable (instead of reliable) sends
116 | * if it exceeds the MTU */
117 | ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT = (1 << 3),
118 |
119 | /** whether the packet has been sent from all queues it has been entered into */
120 | ENET_PACKET_FLAG_SENT = (1<<8)
121 | } ENetPacketFlag;
122 |
123 | typedef void (ENET_CALLBACK * ENetPacketFreeCallback) (struct _ENetPacket *);
124 |
125 | /**
126 | * ENet packet structure.
127 | *
128 | * An ENet data packet that may be sent to or received from a peer. The shown
129 | * fields should only be read and never modified. The data field contains the
130 | * allocated data for the packet. The dataLength fields specifies the length
131 | * of the allocated data. The flags field is either 0 (specifying no flags),
132 | * or a bitwise-or of any combination of the following flags:
133 | *
134 | * ENET_PACKET_FLAG_RELIABLE - packet must be received by the target peer
135 | * and resend attempts should be made until the packet is delivered
136 | *
137 | * ENET_PACKET_FLAG_UNSEQUENCED - packet will not be sequenced with other packets
138 | * (not supported for reliable packets)
139 | *
140 | * ENET_PACKET_FLAG_NO_ALLOCATE - packet will not allocate data, and user must supply it instead
141 |
142 | @sa ENetPacketFlag
143 | */
144 | typedef struct _ENetPacket
145 | {
146 | size_t referenceCount; /**< internal use only */
147 | enet_uint32 flags; /**< bitwise-or of ENetPacketFlag constants */
148 | enet_uint8 * data; /**< allocated data for packet */
149 | size_t dataLength; /**< length of data */
150 | ENetPacketFreeCallback freeCallback; /**< function to be called when the packet is no longer in use */
151 | void * userData; /**< application private data, may be freely modified */
152 | } ENetPacket;
153 |
154 | typedef struct _ENetAcknowledgement
155 | {
156 | ENetListNode acknowledgementList;
157 | enet_uint32 sentTime;
158 | ENetProtocol command;
159 | } ENetAcknowledgement;
160 |
161 | typedef struct _ENetOutgoingCommand
162 | {
163 | ENetListNode outgoingCommandList;
164 | enet_uint16 reliableSequenceNumber;
165 | enet_uint16 unreliableSequenceNumber;
166 | enet_uint32 sentTime;
167 | enet_uint32 roundTripTimeout;
168 | enet_uint32 roundTripTimeoutLimit;
169 | enet_uint32 fragmentOffset;
170 | enet_uint16 fragmentLength;
171 | enet_uint16 sendAttempts;
172 | ENetProtocol command;
173 | ENetPacket * packet;
174 | } ENetOutgoingCommand;
175 |
176 | typedef struct _ENetIncomingCommand
177 | {
178 | ENetListNode incomingCommandList;
179 | enet_uint16 reliableSequenceNumber;
180 | enet_uint16 unreliableSequenceNumber;
181 | ENetProtocol command;
182 | enet_uint32 fragmentCount;
183 | enet_uint32 fragmentsRemaining;
184 | enet_uint32 * fragments;
185 | ENetPacket * packet;
186 | } ENetIncomingCommand;
187 |
188 | typedef enum _ENetPeerState
189 | {
190 | ENET_PEER_STATE_DISCONNECTED = 0,
191 | ENET_PEER_STATE_CONNECTING = 1,
192 | ENET_PEER_STATE_ACKNOWLEDGING_CONNECT = 2,
193 | ENET_PEER_STATE_CONNECTION_PENDING = 3,
194 | ENET_PEER_STATE_CONNECTION_SUCCEEDED = 4,
195 | ENET_PEER_STATE_CONNECTED = 5,
196 | ENET_PEER_STATE_DISCONNECT_LATER = 6,
197 | ENET_PEER_STATE_DISCONNECTING = 7,
198 | ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT = 8,
199 | ENET_PEER_STATE_ZOMBIE = 9
200 | } ENetPeerState;
201 |
202 | #ifndef ENET_BUFFER_MAXIMUM
203 | #define ENET_BUFFER_MAXIMUM (1 + 2 * ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS)
204 | #endif
205 |
206 | enum
207 | {
208 | ENET_HOST_RECEIVE_BUFFER_SIZE = 256 * 1024,
209 | ENET_HOST_SEND_BUFFER_SIZE = 256 * 1024,
210 | ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL = 1000,
211 | ENET_HOST_DEFAULT_MTU = 1400,
212 | ENET_HOST_DEFAULT_MAXIMUM_PACKET_SIZE = 32 * 1024 * 1024,
213 | ENET_HOST_DEFAULT_MAXIMUM_WAITING_DATA = 32 * 1024 * 1024,
214 |
215 | ENET_PEER_DEFAULT_ROUND_TRIP_TIME = 500,
216 | ENET_PEER_DEFAULT_PACKET_THROTTLE = 32,
217 | ENET_PEER_PACKET_THROTTLE_SCALE = 32,
218 | ENET_PEER_PACKET_THROTTLE_COUNTER = 7,
219 | ENET_PEER_PACKET_THROTTLE_ACCELERATION = 2,
220 | ENET_PEER_PACKET_THROTTLE_DECELERATION = 2,
221 | ENET_PEER_PACKET_THROTTLE_INTERVAL = 5000,
222 | ENET_PEER_PACKET_LOSS_SCALE = (1 << 16),
223 | ENET_PEER_PACKET_LOSS_INTERVAL = 10000,
224 | ENET_PEER_WINDOW_SIZE_SCALE = 64 * 1024,
225 | ENET_PEER_TIMEOUT_LIMIT = 32,
226 | ENET_PEER_TIMEOUT_MINIMUM = 5000,
227 | ENET_PEER_TIMEOUT_MAXIMUM = 30000,
228 | ENET_PEER_PING_INTERVAL = 500,
229 | ENET_PEER_UNSEQUENCED_WINDOWS = 64,
230 | ENET_PEER_UNSEQUENCED_WINDOW_SIZE = 1024,
231 | ENET_PEER_FREE_UNSEQUENCED_WINDOWS = 32,
232 | ENET_PEER_RELIABLE_WINDOWS = 16,
233 | ENET_PEER_RELIABLE_WINDOW_SIZE = 0x1000,
234 | ENET_PEER_FREE_RELIABLE_WINDOWS = 8
235 | };
236 |
237 | typedef struct _ENetChannel
238 | {
239 | enet_uint16 outgoingReliableSequenceNumber;
240 | enet_uint16 outgoingUnreliableSequenceNumber;
241 | enet_uint16 usedReliableWindows;
242 | enet_uint16 reliableWindows [ENET_PEER_RELIABLE_WINDOWS];
243 | enet_uint16 incomingReliableSequenceNumber;
244 | enet_uint16 incomingUnreliableSequenceNumber;
245 | ENetList incomingReliableCommands;
246 | ENetList incomingUnreliableCommands;
247 | } ENetChannel;
248 |
249 | /**
250 | * An ENet peer which data packets may be sent or received from.
251 | *
252 | * No fields should be modified unless otherwise specified.
253 | */
254 | typedef struct _ENetPeer
255 | {
256 | ENetListNode dispatchList;
257 | struct _ENetHost * host;
258 | enet_uint16 outgoingPeerID;
259 | enet_uint16 incomingPeerID;
260 | enet_uint32 connectID;
261 | enet_uint8 outgoingSessionID;
262 | enet_uint8 incomingSessionID;
263 | ENetAddress address; /**< Internet address of the peer */
264 | void * data; /**< Application private data, may be freely modified */
265 | ENetPeerState state;
266 | ENetChannel * channels;
267 | size_t channelCount; /**< Number of channels allocated for communication with peer */
268 | enet_uint32 incomingBandwidth; /**< Downstream bandwidth of the client in bytes/second */
269 | enet_uint32 outgoingBandwidth; /**< Upstream bandwidth of the client in bytes/second */
270 | enet_uint32 incomingBandwidthThrottleEpoch;
271 | enet_uint32 outgoingBandwidthThrottleEpoch;
272 | enet_uint32 incomingDataTotal;
273 | enet_uint32 outgoingDataTotal;
274 | enet_uint32 lastSendTime;
275 | enet_uint32 lastReceiveTime;
276 | enet_uint32 nextTimeout;
277 | enet_uint32 earliestTimeout;
278 | enet_uint32 packetLossEpoch;
279 | enet_uint32 packetsSent;
280 | enet_uint32 packetsLost;
281 | enet_uint32 packetLoss; /**< mean packet loss of reliable packets as a ratio with respect to the constant ENET_PEER_PACKET_LOSS_SCALE */
282 | enet_uint32 packetLossVariance;
283 | enet_uint32 packetThrottle;
284 | enet_uint32 packetThrottleLimit;
285 | enet_uint32 packetThrottleCounter;
286 | enet_uint32 packetThrottleEpoch;
287 | enet_uint32 packetThrottleAcceleration;
288 | enet_uint32 packetThrottleDeceleration;
289 | enet_uint32 packetThrottleInterval;
290 | enet_uint32 pingInterval;
291 | enet_uint32 timeoutLimit;
292 | enet_uint32 timeoutMinimum;
293 | enet_uint32 timeoutMaximum;
294 | enet_uint32 lastRoundTripTime;
295 | enet_uint32 lowestRoundTripTime;
296 | enet_uint32 lastRoundTripTimeVariance;
297 | enet_uint32 highestRoundTripTimeVariance;
298 | enet_uint32 roundTripTime; /**< mean round trip time (RTT), in milliseconds, between sending a reliable packet and receiving its acknowledgement */
299 | enet_uint32 roundTripTimeVariance;
300 | enet_uint32 mtu;
301 | enet_uint32 windowSize;
302 | enet_uint32 reliableDataInTransit;
303 | enet_uint16 outgoingReliableSequenceNumber;
304 | ENetList acknowledgements;
305 | ENetList sentReliableCommands;
306 | ENetList sentUnreliableCommands;
307 | ENetList outgoingReliableCommands;
308 | ENetList outgoingUnreliableCommands;
309 | ENetList dispatchedCommands;
310 | int needsDispatch;
311 | enet_uint16 incomingUnsequencedGroup;
312 | enet_uint16 outgoingUnsequencedGroup;
313 | enet_uint32 unsequencedWindow [ENET_PEER_UNSEQUENCED_WINDOW_SIZE / 32];
314 | enet_uint32 eventData;
315 | size_t totalWaitingData;
316 | } ENetPeer;
317 |
318 | /** An ENet packet compressor for compressing UDP packets before socket sends or receives.
319 | */
320 | typedef struct _ENetCompressor
321 | {
322 | /** Context data for the compressor. Must be non-NULL. */
323 | void * context;
324 | /** Compresses from inBuffers[0:inBufferCount-1], containing inLimit bytes, to outData, outputting at most outLimit bytes. Should return 0 on failure. */
325 | size_t (ENET_CALLBACK * compress) (void * context, const ENetBuffer * inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 * outData, size_t outLimit);
326 | /** Decompresses from inData, containing inLimit bytes, to outData, outputting at most outLimit bytes. Should return 0 on failure. */
327 | size_t (ENET_CALLBACK * decompress) (void * context, const enet_uint8 * inData, size_t inLimit, enet_uint8 * outData, size_t outLimit);
328 | /** Destroys the context when compression is disabled or the host is destroyed. May be NULL. */
329 | void (ENET_CALLBACK * destroy) (void * context);
330 | } ENetCompressor;
331 |
332 | /** Callback that computes the checksum of the data held in buffers[0:bufferCount-1] */
333 | typedef enet_uint32 (ENET_CALLBACK * ENetChecksumCallback) (const ENetBuffer * buffers, size_t bufferCount);
334 |
335 | /** Callback for intercepting received raw UDP packets. Should return 1 to intercept, 0 to ignore, or -1 to propagate an error. */
336 | typedef int (ENET_CALLBACK * ENetInterceptCallback) (struct _ENetHost * host, struct _ENetEvent * event);
337 |
338 | /** An ENet host for communicating with peers.
339 | *
340 | * No fields should be modified unless otherwise stated.
341 |
342 | @sa enet_host_create()
343 | @sa enet_host_destroy()
344 | @sa enet_host_connect()
345 | @sa enet_host_service()
346 | @sa enet_host_flush()
347 | @sa enet_host_broadcast()
348 | @sa enet_host_compress()
349 | @sa enet_host_compress_with_range_coder()
350 | @sa enet_host_channel_limit()
351 | @sa enet_host_bandwidth_limit()
352 | @sa enet_host_bandwidth_throttle()
353 | */
354 | typedef struct _ENetHost
355 | {
356 | ENetSocket socket;
357 | ENetAddress address; /**< Internet address of the host */
358 | enet_uint32 incomingBandwidth; /**< downstream bandwidth of the host */
359 | enet_uint32 outgoingBandwidth; /**< upstream bandwidth of the host */
360 | enet_uint32 bandwidthThrottleEpoch;
361 | enet_uint32 mtu;
362 | enet_uint32 randomSeed;
363 | int recalculateBandwidthLimits;
364 | ENetPeer * peers; /**< array of peers allocated for this host */
365 | size_t peerCount; /**< number of peers allocated for this host */
366 | size_t channelLimit; /**< maximum number of channels allowed for connected peers */
367 | enet_uint32 serviceTime;
368 | ENetList dispatchQueue;
369 | int continueSending;
370 | size_t packetSize;
371 | enet_uint16 headerFlags;
372 | ENetProtocol commands [ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS];
373 | size_t commandCount;
374 | ENetBuffer buffers [ENET_BUFFER_MAXIMUM];
375 | size_t bufferCount;
376 | ENetChecksumCallback checksum; /**< callback the user can set to enable packet checksums for this host */
377 | ENetCompressor compressor;
378 | enet_uint8 packetData [2][ENET_PROTOCOL_MAXIMUM_MTU];
379 | ENetAddress receivedAddress;
380 | enet_uint8 * receivedData;
381 | size_t receivedDataLength;
382 | enet_uint32 totalSentData; /**< total data sent, user should reset to 0 as needed to prevent overflow */
383 | enet_uint32 totalSentPackets; /**< total UDP packets sent, user should reset to 0 as needed to prevent overflow */
384 | enet_uint32 totalReceivedData; /**< total data received, user should reset to 0 as needed to prevent overflow */
385 | enet_uint32 totalReceivedPackets; /**< total UDP packets received, user should reset to 0 as needed to prevent overflow */
386 | ENetInterceptCallback intercept; /**< callback the user can set to intercept received raw UDP packets */
387 | size_t connectedPeers;
388 | size_t bandwidthLimitedPeers;
389 | size_t duplicatePeers; /**< optional number of allowed peers from duplicate IPs, defaults to ENET_PROTOCOL_MAXIMUM_PEER_ID */
390 | size_t maximumPacketSize; /**< the maximum allowable packet size that may be sent or received on a peer */
391 | size_t maximumWaitingData; /**< the maximum aggregate amount of buffer space a peer may use waiting for packets to be delivered */
392 | } ENetHost;
393 |
394 | /**
395 | * An ENet event type, as specified in @ref ENetEvent.
396 | */
397 | typedef enum _ENetEventType
398 | {
399 | /** no event occurred within the specified time limit */
400 | ENET_EVENT_TYPE_NONE = 0,
401 |
402 | /** a connection request initiated by enet_host_connect has completed.
403 | * The peer field contains the peer which successfully connected.
404 | */
405 | ENET_EVENT_TYPE_CONNECT = 1,
406 |
407 | /** a peer has disconnected. This event is generated on a successful
408 | * completion of a disconnect initiated by enet_pper_disconnect, if
409 | * a peer has timed out, or if a connection request intialized by
410 | * enet_host_connect has timed out. The peer field contains the peer
411 | * which disconnected. The data field contains user supplied data
412 | * describing the disconnection, or 0, if none is available.
413 | */
414 | ENET_EVENT_TYPE_DISCONNECT = 2,
415 |
416 | /** a packet has been received from a peer. The peer field specifies the
417 | * peer which sent the packet. The channelID field specifies the channel
418 | * number upon which the packet was received. The packet field contains
419 | * the packet that was received; this packet must be destroyed with
420 | * enet_packet_destroy after use.
421 | */
422 | ENET_EVENT_TYPE_RECEIVE = 3
423 | } ENetEventType;
424 |
425 | /**
426 | * An ENet event as returned by enet_host_service().
427 |
428 | @sa enet_host_service
429 | */
430 | typedef struct _ENetEvent
431 | {
432 | ENetEventType type; /**< type of the event */
433 | ENetPeer * peer; /**< peer that generated a connect, disconnect or receive event */
434 | enet_uint8 channelID; /**< channel on the peer that generated the event, if appropriate */
435 | enet_uint32 data; /**< data associated with the event, if appropriate */
436 | ENetPacket * packet; /**< packet associated with the event, if appropriate */
437 | } ENetEvent;
438 |
439 | /** @defgroup global ENet global functions
440 | @{
441 | */
442 |
443 | /**
444 | Initializes ENet globally. Must be called prior to using any functions in
445 | ENet.
446 | @returns 0 on success, < 0 on failure
447 | */
448 | ENET_API int enet_initialize (void);
449 |
450 | /**
451 | Initializes ENet globally and supplies user-overridden callbacks. Must be called prior to using any functions in ENet. Do not use enet_initialize() if you use this variant. Make sure the ENetCallbacks structure is zeroed out so that any additional callbacks added in future versions will be properly ignored.
452 |
453 | @param version the constant ENET_VERSION should be supplied so ENet knows which version of ENetCallbacks struct to use
454 | @param inits user-overridden callbacks where any NULL callbacks will use ENet's defaults
455 | @returns 0 on success, < 0 on failure
456 | */
457 | ENET_API int enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits);
458 |
459 | /**
460 | Shuts down ENet globally. Should be called when a program that has
461 | initialized ENet exits.
462 | */
463 | ENET_API void enet_deinitialize (void);
464 |
465 | /**
466 | Gives the linked version of the ENet library.
467 | @returns the version number
468 | */
469 | ENET_API ENetVersion enet_linked_version (void);
470 |
471 | /** @} */
472 |
473 | /** @defgroup private ENet private implementation functions */
474 |
475 | /**
476 | Returns the wall-time in milliseconds. Its initial value is unspecified
477 | unless otherwise set.
478 | */
479 | ENET_API enet_uint32 enet_time_get (void);
480 | /**
481 | Sets the current wall-time in milliseconds.
482 | */
483 | ENET_API void enet_time_set (enet_uint32);
484 |
485 | /** @defgroup socket ENet socket functions
486 | @{
487 | */
488 | ENET_API ENetSocket enet_socket_create (ENetSocketType);
489 | ENET_API int enet_socket_bind (ENetSocket, const ENetAddress *);
490 | ENET_API int enet_socket_get_address (ENetSocket, ENetAddress *);
491 | ENET_API int enet_socket_listen (ENetSocket, int);
492 | ENET_API ENetSocket enet_socket_accept (ENetSocket, ENetAddress *);
493 | ENET_API int enet_socket_connect (ENetSocket, const ENetAddress *);
494 | ENET_API int enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t);
495 | ENET_API int enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t);
496 | ENET_API int enet_socket_wait (ENetSocket, enet_uint32 *, enet_uint32);
497 | ENET_API int enet_socket_set_option (ENetSocket, ENetSocketOption, int);
498 | ENET_API int enet_socket_get_option (ENetSocket, ENetSocketOption, int *);
499 | ENET_API int enet_socket_shutdown (ENetSocket, ENetSocketShutdown);
500 | ENET_API void enet_socket_destroy (ENetSocket);
501 | ENET_API int enet_socketset_select (ENetSocket, ENetSocketSet *, ENetSocketSet *, enet_uint32);
502 |
503 | /** @} */
504 |
505 | /** @defgroup Address ENet address functions
506 | @{
507 | */
508 | /** Attempts to resolve the host named by the parameter hostName and sets
509 | the host field in the address parameter if successful.
510 | @param address destination to store resolved address
511 | @param hostName host name to lookup
512 | @retval 0 on success
513 | @retval < 0 on failure
514 | @returns the address of the given hostName in address on success
515 | */
516 | ENET_API int enet_address_set_host (ENetAddress * address, const char * hostName);
517 |
518 | /** Gives the printable form of the IP address specified in the address parameter.
519 | @param address address printed
520 | @param hostName destination for name, must not be NULL
521 | @param nameLength maximum length of hostName.
522 | @returns the null-terminated name of the host in hostName on success
523 | @retval 0 on success
524 | @retval < 0 on failure
525 | */
526 | ENET_API int enet_address_get_host_ip (const ENetAddress * address, char * hostName, size_t nameLength);
527 |
528 | /** Attempts to do a reverse lookup of the host field in the address parameter.
529 | @param address address used for reverse lookup
530 | @param hostName destination for name, must not be NULL
531 | @param nameLength maximum length of hostName.
532 | @returns the null-terminated name of the host in hostName on success
533 | @retval 0 on success
534 | @retval < 0 on failure
535 | */
536 | ENET_API int enet_address_get_host (const ENetAddress * address, char * hostName, size_t nameLength);
537 |
538 | /** @} */
539 |
540 | ENET_API ENetPacket * enet_packet_create (const void *, size_t, enet_uint32);
541 | ENET_API void enet_packet_destroy (ENetPacket *);
542 | ENET_API int enet_packet_resize (ENetPacket *, size_t);
543 | ENET_API enet_uint32 enet_crc32 (const ENetBuffer *, size_t);
544 |
545 | ENET_API ENetHost * enet_host_create (const ENetAddress *, size_t, size_t, enet_uint32, enet_uint32);
546 | ENET_API void enet_host_destroy (ENetHost *);
547 | ENET_API ENetPeer * enet_host_connect (ENetHost *, const ENetAddress *, size_t, enet_uint32);
548 | ENET_API int enet_host_check_events (ENetHost *, ENetEvent *);
549 | ENET_API int enet_host_service (ENetHost *, ENetEvent *, enet_uint32);
550 | ENET_API void enet_host_flush (ENetHost *);
551 | ENET_API void enet_host_broadcast (ENetHost *, enet_uint8, ENetPacket *);
552 | ENET_API void enet_host_compress (ENetHost *, const ENetCompressor *);
553 | ENET_API int enet_host_compress_with_range_coder (ENetHost * host);
554 | ENET_API void enet_host_channel_limit (ENetHost *, size_t);
555 | ENET_API void enet_host_bandwidth_limit (ENetHost *, enet_uint32, enet_uint32);
556 | extern void enet_host_bandwidth_throttle (ENetHost *);
557 | extern enet_uint32 enet_host_random_seed (void);
558 |
559 | ENET_API int enet_peer_send (ENetPeer *, enet_uint8, ENetPacket *);
560 | ENET_API ENetPacket * enet_peer_receive (ENetPeer *, enet_uint8 * channelID);
561 | ENET_API void enet_peer_ping (ENetPeer *);
562 | ENET_API void enet_peer_ping_interval (ENetPeer *, enet_uint32);
563 | ENET_API void enet_peer_timeout (ENetPeer *, enet_uint32, enet_uint32, enet_uint32);
564 | ENET_API void enet_peer_reset (ENetPeer *);
565 | ENET_API void enet_peer_disconnect (ENetPeer *, enet_uint32);
566 | ENET_API void enet_peer_disconnect_now (ENetPeer *, enet_uint32);
567 | ENET_API void enet_peer_disconnect_later (ENetPeer *, enet_uint32);
568 | ENET_API void enet_peer_throttle_configure (ENetPeer *, enet_uint32, enet_uint32, enet_uint32);
569 | extern int enet_peer_throttle (ENetPeer *, enet_uint32);
570 | extern void enet_peer_reset_queues (ENetPeer *);
571 | extern void enet_peer_setup_outgoing_command (ENetPeer *, ENetOutgoingCommand *);
572 | extern ENetOutgoingCommand * enet_peer_queue_outgoing_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32, enet_uint16);
573 | extern ENetIncomingCommand * enet_peer_queue_incoming_command (ENetPeer *, const ENetProtocol *, const void *, size_t, enet_uint32, enet_uint32);
574 | extern ENetAcknowledgement * enet_peer_queue_acknowledgement (ENetPeer *, const ENetProtocol *, enet_uint16);
575 | extern void enet_peer_dispatch_incoming_unreliable_commands (ENetPeer *, ENetChannel *);
576 | extern void enet_peer_dispatch_incoming_reliable_commands (ENetPeer *, ENetChannel *);
577 | extern void enet_peer_on_connect (ENetPeer *);
578 | extern void enet_peer_on_disconnect (ENetPeer *);
579 |
580 | ENET_API void * enet_range_coder_create (void);
581 | ENET_API void enet_range_coder_destroy (void *);
582 | ENET_API size_t enet_range_coder_compress (void *, const ENetBuffer *, size_t, size_t, enet_uint8 *, size_t);
583 | ENET_API size_t enet_range_coder_decompress (void *, const enet_uint8 *, size_t, enet_uint8 *, size_t);
584 |
585 | extern size_t enet_protocol_command_size (enet_uint8);
586 |
587 | #ifdef __cplusplus
588 | }
589 | #endif
590 |
591 | #endif /* __ENET_ENET_H__ */
592 |
593 |
--------------------------------------------------------------------------------
/player.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "enet/enet.h"
3 | #include "gamepacket.h"
4 | #include "server.h"
5 |
6 | #define cloth0 cloth_hair
7 | #define cloth1 cloth_shirt
8 | #define cloth2 cloth_pants
9 | #define cloth3 cloth_feet
10 | #define cloth4 cloth_face
11 | #define cloth5 cloth_hand
12 | #define cloth6 cloth_back
13 | #define cloth7 cloth_mask
14 | #define cloth8 cloth_necklace
15 | #define cloth9 cloth_ances
16 | struct InventoryItem {
17 | short itemID;
18 | byte itemCount;
19 | };
20 | struct PlayerInventory {
21 | vector items;
22 | int inventorySize = 20;
23 | };
24 |
25 | struct Note {
26 | string who = "";
27 | string time = "";
28 | string reason = "";
29 | };
30 | struct PlayerNotes {
31 | vector notes;
32 |
33 | };
34 |
35 | struct TradeItem
36 | {
37 | int id;
38 | int count;
39 | };
40 |
41 | struct PlayerInfo {
42 | string mac = "", rid = "", gid = "";
43 | int play_time = 0;
44 | int wrong_onto_something = 0;
45 | bool registerverify = false;
46 | int kipaskiek_turi_kainoti = 0;
47 | int buy_dd = 0;
48 | int play_x = 0;
49 | int play_y = 0;
50 | /*HELLO*/
51 | long long int lastPPS = 0;
52 | int pps = 0;
53 | /*HM*/
54 | bool blueName = false;
55 | bool lName = false;
56 | bool tutorial = false;
57 | bool isIn = false;
58 | int transform = 0;
59 | int lastPunchForeground = 0;
60 | int lastPunchBackground = 0;
61 | bool disconnect_ = false;
62 | int billboardid = 0;
63 | int suckerid = 0;
64 | string suckername = "";
65 | int laststorebuyprice = 0;
66 | long long int saco = 0;
67 | int laststorebuyid = 0;
68 | int laststorebuycount = 0;
69 | long long int last_afk = 0;
70 | int billboardtab = 0;
71 | string lastfriend = "";
72 | int billboardprice = 0;
73 | int billboardperwhat = 0;
74 | int pure_state = 0;
75 | bool playing = false;
76 | int netID;
77 | int chatwarn = 0;
78 | string pin = "";
79 | int warncheck2 = 0;
80 | bool isHidde = false;
81 | long long int lastSpin = 0;
82 | bool haveGrowId = false;
83 | int lasttrashitem;
84 | int warncheat = 0;
85 | int laststoresellworldlocks = 0;
86 | int laststoreselldiamondlocks = 0;
87 | int laststoresellid = 0;
88 | int laststoresellcount = 0;
89 | string lastvendbuycount = "";
90 | bool haveSubscription = false;
91 | long long int lastpackettype = 0;
92 | long long int lastTRADE = 0;
93 | int warnforcheat = 0;
94 |
95 | /*FRIEND SYSTEM*/
96 | bool lastLC = false;
97 | bool showloc = true;
98 | string lastFrnName = "";
99 | string lastFrn = "";
100 | string lastFrnWorld = "";
101 | vectorfriendinfo;
102 | /*LOL*/
103 |
104 | string lastInfoname = "";
105 | string lastgm = "";
106 | string lastgmname = "";
107 | string lastgmworld = "";
108 | int noclipas_ = 0;
109 | string guildlast = "";
110 | bool isinvited = false;
111 | int guildBg = 0;
112 | int guildFg = 0;
113 | int petlevel = 0;
114 | string guildStatement = "";
115 | string guildLeader = "";
116 | vector guildmatelist;
117 | vectorguildMembers;
118 | vectorguildGE;
119 | vectorguildGC;
120 | int guildlevel = 0;
121 | int guildexp = 0;
122 | string createGuildName = "";
123 | string createGuildStatement = "";
124 | string createGuildFlagBg = "";
125 | string createGuildFlagFg = "";
126 | string LastState = "";
127 | string guild = "";
128 | bool joinguild = false;
129 |
130 |
131 | string tankIDName = "";
132 | string tankIDPass = "";
133 | string requestedName = "";
134 | string rawName = "";
135 | string lastMsgerWorld = "";
136 | vectorworldsowned;
137 | string displayName = "";
138 | string country = "";
139 | int adminLevel = 0;
140 | string currentWorld = "EXIT";
141 | long long int lastPackets = 0;
142 | int warn = 0;
143 | bool radio = true;
144 | int xptime = 0;
145 | int x;
146 | int xpboost = 0;
147 | int y;
148 | int x1;
149 | int lastUserID = 0;
150 | int wrenchedBlockLocation = -1;
151 | int puncheffect;
152 | int y1;
153 | string lastuser;
154 | bool isRotatedLeft = false;
155 | string charIP = "";
156 | bool isUpdating = false;
157 | string lastdialog = "";
158 | bool joinClothesUpdated = false;
159 | bool muted = false;
160 | unsigned int gems = 0;
161 | int userID = 0;
162 | bool hasLogon = false;
163 |
164 | bool isInvitedGuild = false;
165 | bool taped = false;
166 | bool isFishing = false;
167 | string registerIP;
168 | string ipAddress;
169 | int number1 = rand() % 10;
170 | int number2 = rand() % 100;
171 | bool validated = false;
172 | string backupName = "";
173 | int cloth_hair = 0; // 0
174 | int cloth_shirt = 0; // 1
175 | int cloth_pants = 0; // 2
176 | int cloth_feet = 0; // 3
177 | int cloth_face = 0; // 4
178 | int cloth_hand = 0; // 5
179 | bool didAlready = false;
180 | int cloth_back = 0; // 6
181 | int cloth_mask = 0; // 7
182 | int cloth_necklace = 0; // 8
183 | int cloth_ances = 0;
184 | int xp = 0;
185 | int level = 0x1;
186 | string platformID;
187 | int updateReq;
188 | bool canWalkInBlocks = false; // 1
189 | bool canDoubleJump = false; // 2
190 | bool isInvisible = false; // 4
191 | bool noHands = false; // 8
192 |
193 | int lavaLevel = 0;
194 | bool noEyes = false; // 16
195 | bool noBody = false; // 32
196 | bool devilHorns = false; // 64
197 | bool goldenHalo = false; // 128
198 | bool isFrozen = false; // 2048
199 | bool isCursed = false; // 4096
200 | bool isDuctaped = false; // 8192
201 | bool haveCigar = false; // 16384
202 | bool isShining = false; // 32768
203 | bool isZombie = false; // 65536
204 | bool isHitByLava = false; // 131072
205 | bool haveHauntedShadows = false; // 262144
206 | bool haveGeigerRadiation = false; // 524288
207 | bool haveReflector = false; // 1048576
208 | bool isEgged = false; // 2097152
209 | bool havePineappleFloag = false; // 4194304
210 | bool haveFlyingPineapple = false; // 8388608
211 | bool haveSuperSupporterName = false; // 16777216
212 | bool haveSupperPineapple = false; // 33554432
213 |
214 | int lqueststep = 0;
215 | int lquestprogress = 0;
216 | int ltype = 0;
217 |
218 | long long int lastBREAK = 0;
219 |
220 |
221 | bool isInFinalTradeDialog = false;
222 | //Blueberry
223 | ///////////////////////////////
224 | bool blueBerry = false;
225 | int usedBerry = 0;
226 | int lastBerry = 0;
227 | ///////////////////////////////
228 | bool isBot = false;
229 |
230 | string banName = "";
231 |
232 | bool loadedInventory = false;
233 |
234 | int geigerTimeModifier = 4;
235 | int geigerIdleScore = 0;
236 |
237 | //Coffee
238 | ///////////////////////////////
239 | bool Caffeine = false;
240 | int usedCoffee = 0;
241 | int leftCoffee = 0;
242 | ///////////////////////////////
243 | bool acceptedFinalDialog = false;
244 | int infiniteZoomEnabled = 0;
245 |
246 | int infiniteJumpsEnabled = 0;
247 | bool isTrading = false;
248 | bool isWaitingForTrade = false;
249 | int isWaitingForTradeWithUserID = 0;
250 | vector tradeItems;
251 | bool isAcceptingTrade = false;
252 | int isTradingWithUserID = 0;
253 |
254 | int lastTradeNetID = 0;
255 | int lastTradeItem = 0;
256 | string lastTradeName = "";
257 |
258 | int buygkto = 0;
259 |
260 | string currentTradeItems = "";
261 | int bandate = 0;
262 | int firesOutput = 0;
263 | bool isNicked = false;
264 | int lastPunchY = 0;
265 | int respawnX = 0;
266 | int respawnY = 0;
267 | int mstate = 0;
268 | int smstate = 0;
269 | int insInvis = 0;
270 | int lastPunchX = 0;
271 | int lastdropitemcount = 0;
272 | int lastdropitem = 0;
273 | long long int lastJoinReq = 0;
274 | bool ignorePackets = false;
275 | string lastMsger = "";
276 | string lastMsgWorld = "";
277 | string lastMsgerTrue = "";
278 | int bantime = 0;
279 | int ban = 0;
280 | string lastsbworld = "";
281 | int respawnPos = -1;
282 | //bool respawnPos
283 | int skinColor = 0x8295C3FF; //normal SKin color like gt!
284 | int droppeditemcount = 0;
285 | PlayerInventory inventory;
286 |
287 | PlayerNotes notes;
288 |
289 | int magplantitemid = 0;
290 |
291 | int magplantx = -1;
292 | int magplanty = -1;
293 | bool useGeiger = false;
294 | long long int lastChat = 0;
295 | long long int lastSB = 0;
296 | long long int lastGeigerTime = 0;
297 | long long int weatherPunch = 0;
298 | string ItemsOption = "cape=147,56,143:collar=147,56,143:cape2=137,30,43:collar2=137,30,43:delay=5";
299 | };
300 | int GetQuantityOfItem(ENetPeer* peer, const int fItemId) {
301 | auto quantity = 0;
302 | try {
303 | for (auto i = 0; i < ((PlayerInfo*)(peer->data))->inventory.items.size(); i++) {
304 | if (((PlayerInfo*)(peer->data))->inventory.items.at(i).itemID == fItemId) {
305 | quantity = ((PlayerInfo*)(peer->data))->inventory.items.at(i).itemCount;
306 | break;
307 | }
308 | }
309 | }
310 | catch (const std::out_of_range& e) {
311 | std::cout << e.what() << std::endl;
312 | }
313 | return quantity;
314 | }
315 | string GetItemCount(ENetPeer* peer, int itemid) {
316 | auto KiekTuri = 0;
317 | try {
318 | for (int i = 0; i < ((PlayerInfo*)(peer->data))->inventory.items.size(); i++) {
319 | if (((PlayerInfo*)(peer->data))->inventory.items.at(i).itemID == itemid && ((PlayerInfo*)(peer->data))->inventory.items.at(i).itemCount >= 1) {
320 | KiekTuri = ((PlayerInfo*)(peer->data))->inventory.items.at(i).itemCount;
321 | break;
322 | }
323 | }
324 | }
325 | catch (const std::out_of_range& e) {
326 | std::cout << e.what() << std::endl;
327 | }
328 | if (KiekTuri != 0) return to_string(KiekTuri);
329 | else return "";
330 | }
331 | bool isPickaxe(ENetPeer* peer) {
332 | if (((PlayerInfo*)(peer->data))->cloth_hand == 2754 || ((PlayerInfo*)(peer->data))->cloth_hand == 7830 || ((PlayerInfo*)(peer->data))->cloth_hand == 930 || ((PlayerInfo*)(peer->data))->cloth_hand == 1874 || ((PlayerInfo*)(peer->data))->cloth_hand == 6368 || ((PlayerInfo*)(peer->data))->cloth_hand == 2572 || ((PlayerInfo*)(peer->data))->cloth_hand == 1484 || ((PlayerInfo*)(peer->data))->cloth_hand == 734 || ((PlayerInfo*)(peer->data))->cloth_hand == 98 || ((PlayerInfo*)(peer->data))->cloth_hand == 1438 || ((PlayerInfo*)(peer->data))->cloth_hand == 4956 || ((PlayerInfo*)(peer->data))->cloth_hand == 1708) {
333 | return true;
334 | }
335 | else {
336 | return false;
337 | }
338 | }
339 |
340 | bool isGFLAGS(int tile) {
341 | if (tile == 5830 || tile == 5832 || tile == 5834 || tile == 5836 || tile == 5838 || tile == 5840 || tile == 5842 || tile == 5844 || tile == 5846 || tile == 5848 || tile == 5850 || tile == 5852 || tile == 5854 || tile == 5856 || tile == 5858 || tile == 5860 || tile == 5862 || tile == 5864 || tile == 5866 || tile == 5868 || tile == 5870 || tile == 5872 || tile == 5874 || tile == 5876 || tile == 5878 || tile == 5880 || tile == 5882 || tile == 5884 || tile == 5886 || tile == 5888 || tile == 5890 || tile == 5892 || tile == 5894 || tile == 5896 || tile == 5898 || tile == 5900 || tile == 5902 || tile == 5904 || tile == 5906 || tile == 5908 || tile == 5910 || tile == 5912 || tile == 5914 || tile == 5916 || tile == 5918 || tile == 5920 || tile == 5922 || tile == 5924 || tile == 5926 || tile == 5928 || tile == 5930 || tile == 5932) return true;
342 | else return false;
343 | }
344 | int getInventoryItem(ENetPeer* peer, int item)
345 | {
346 | int count = 0;
347 | try {
348 | for (int i = 0; i < ((PlayerInfo*)(peer->data))->inventory.items.size(); i++) {
349 | if (((PlayerInfo*)(peer->data))->inventory.items.at(i).itemID == item) {
350 | count = (unsigned int)((PlayerInfo*)(peer->data))->inventory.items.at(i).itemCount;
351 | break;
352 | }
353 | }
354 | } catch (const std::out_of_range& e) {
355 | std::cout << e.what() << std::endl;
356 | }
357 | return count;
358 | }
359 | bool CheckItemExists(ENetPeer* peer, const int fItemId)
360 | {
361 | bool isExists = false;
362 | try {
363 | for (auto i = 0; i < ((PlayerInfo*)(peer->data))->inventory.items.size(); i++) {
364 | if (((PlayerInfo*)(peer->data))->inventory.items.at(i).itemID == fItemId) {
365 | isExists = true;
366 | break;
367 | }
368 | }
369 | } catch (const std::out_of_range& e) {
370 | std::cout << e.what() << std::endl;
371 | }
372 | return isExists;
373 | }
374 | bool CheckItemMaxed(ENetPeer* peer, const int fItemId, int fQuantityAdd)
375 | {
376 | auto isMaxed = false;
377 | try {
378 | for (auto i = 0; i < ((PlayerInfo*)(peer->data))->inventory.items.size(); i++) {
379 | if (((PlayerInfo*)(peer->data))->inventory.items.at(i).itemID == fItemId && ((PlayerInfo*)(peer->data))->inventory.items.at(i).itemCount + fQuantityAdd > 200) {
380 | isMaxed = true;
381 | break;
382 | }
383 | }
384 | }
385 | catch (const std::out_of_range& e) {
386 | std::cout << e.what() << std::endl;
387 | }
388 | return isMaxed;
389 | }
390 |
391 | string OutputBanTime(int n) {
392 | string x;
393 | const auto day = n / (24 * 3600);
394 | if (day != 0) x.append(to_string(day) + " Days ");
395 | n = n % (24 * 3600);
396 | const auto hour = n / 3600;
397 | if (hour != 0) x.append(to_string(hour) + " Hours ");
398 | n %= 3600;
399 | const auto minutes = n / 60;
400 | if (minutes != 0) x.append(to_string(minutes) + " Minutes ");
401 | n %= 60;
402 | const auto seconds = n;
403 | if (seconds != 0) x.append(to_string(seconds) + " Seconds");
404 | return x;
405 | }
406 |
407 |
408 | enum ClothTypes {
409 | HAIR,
410 | SHIRT,
411 | PANTS,
412 | FEET,
413 | FACE,
414 | HAND,
415 | BACK,
416 | MASK,
417 | NECKLACE,
418 | ANCES,
419 | //NONE
420 | };
421 | enum BlockTypes {
422 | COMPONENT,
423 | RANDOM_BLOCK,
424 | Painting_Easel,
425 | DEADLY,
426 | ANIM_FOREGROUND,
427 | DONATION,
428 | DISPLAY_SHELF,
429 | TREASURE,
430 | DISPLAY,
431 | Kranken,
432 | PORTAL,
433 | TRAMPOLINE,
434 | PLATFORM,
435 | SUCKER,
436 | GROUND_BLOCK,
437 | VENDING,
438 | SFX_FOREGROUND,
439 | FOREGROUND,
440 | BACKGROUND,
441 | SEED,
442 | PAIN_BLOCK,
443 | BEDROCK,
444 | MAIN_DOOR,
445 | SIGN,
446 | DOOR,
447 | MAILBOX,
448 | CLOTHING,
449 | FIST,
450 | CONSUMABLE,
451 | CHECKPOINT,
452 | GATEWAY,
453 | LOCK,
454 | WEATHER,
455 | MAGIC_EGG,
456 | FACTION,
457 | GEMS,
458 | JAMMER,
459 | BULLETIN_BOARD,
460 | Mannequin,
461 | TOGGLE_FOREGROUND,
462 | SWITCH_BLOCK,
463 | CHEST,
464 | UNKNOWN
465 | };
466 | #define Property_Zero 0
467 | #define Property_NoSeed 1
468 | #define Property_Dropless 2
469 | #define Property_Beta 4
470 | #define Property_Mod 8
471 | #define Property_Untradable 16
472 | #define Property_Wrenchable 32
473 | #define Property_MultiFacing 64
474 | #define Property_Permanent 128
475 | #define Property_AutoPickup 256
476 | #define Property_WorldLock 512
477 | #define Property_NoSelf 1024
478 | #define Property_RandomGrow 2048
479 | #define Property_Public 4096
480 |
481 |
482 | bool IsValidAction(string action)
483 | {
484 | if (action == "/smile" ||
485 | action == "/cry" ||
486 | action == "/laugh" ||
487 | action == "/lol" ||
488 | action == "/mad" ||
489 | action == "/wave" ||
490 | action == "/dance" ||
491 | action == "/dance2" ||
492 | action == "/love" ||
493 | action == "/kiss" ||
494 | action == "/sleep" ||
495 | action == "/yes" ||
496 | action == "/no" ||
497 | action == "/wink" ||
498 | action == "/troll" ||
499 | action == "/cheer" ||
500 | action == "/sad" ||
501 | action == "/fp" ||
502 | action == "/facepalm" ||
503 | action == "/omg" ||
504 | action == "/shrug" ||
505 | action == "/idk" ||
506 | action == "/furious" ||
507 | action == "/rolleyes" ||
508 | action == "/eyeroll" ||
509 | action == "/foldarms" ||
510 | action == "/fold" ||
511 | action == "/stubborn" ||
512 | action == "/fa" ||
513 | action == "/dab" ||
514 | action == "/sassy")
515 | return true;
516 | return false;
517 | }
518 |
519 |
520 |
521 | struct DroppedItem { // TODO
522 | int id;
523 | int uid;
524 | int count;
525 | float x;
526 | float y;
527 | };
528 | struct ItemDefinition {
529 | int id;
530 | int properties;
531 | unsigned char editableType;
532 | unsigned char itemCategory;
533 | unsigned char actionType = 0;
534 | unsigned char hitSoundType = 0;
535 |
536 | std::string name;
537 |
538 | std::string texture = "";
539 | int textureHash = 0;
540 | unsigned char itemKind = 0;
541 | int val1;
542 | unsigned char textureX = 0;
543 | unsigned char textureY = 0;
544 | unsigned char spreadType = 0;
545 | unsigned char isStripeyWallpaper = 0;
546 | unsigned char collisionType = 0;
547 |
548 | unsigned char breakHits = 0;
549 |
550 | int dropChance = 0;
551 | unsigned char clothingType = 0;
552 | BlockTypes blockType;
553 | int growTime;
554 | ClothTypes clothType;
555 | int16_t rarity = 0;
556 | unsigned char maxAmount = 0;
557 | std::string extraFile = "";
558 | int extraFileHash = 0;
559 | int audioVolume = 0;
560 | std::string petName = "";
561 | std::string petPrefix = "";
562 | std::string petSuffix = "";
563 | std::string petAbility = "";
564 | unsigned char seedBase = 0;
565 | unsigned char seedOverlay = 0;
566 | unsigned char treeBase = 0;
567 | unsigned char treeLeaves = 0;
568 | int seedColor = 0;
569 | int seedOverlayColor = 0;
570 | bool isMultiFace = false;
571 | short val2;
572 | short isRayman = 0;
573 | std::string extraOptions = "";
574 | std::string texture2 = "";
575 | std::string extraOptions2 = "";
576 | std::string punchOptions = "";
577 | std::string description = "Nothing to see.";
578 | };
579 | vector ItemCategoryToProperties(unsigned char bcateg, unsigned char btype) {
580 | std::vector list;
581 | if ((btype & 0x40) > 0)
582 | {
583 | list.push_back("NoShadow");
584 | }
585 | if ((btype & 0x20) > 0)
586 | {
587 | list.push_back("NoSelf");
588 | }
589 | if ((btype & 2) > 0)
590 | {
591 | list.push_back("Wrenchable");
592 | }
593 | if ((btype & 8) > 0)
594 | {
595 | list.push_back("Dropless");
596 | }
597 | if ((btype & 0x10) > 0)
598 | {
599 | list.push_back("NoSeed");
600 | }
601 | if ((btype & 4) > 0)
602 | {
603 | list.push_back("Permanent");
604 | }
605 | if ((btype & 1) > 0)
606 | {
607 | list.push_back("MultiFacing");
608 | }
609 | if ((btype & 0x80) > 0)
610 | {
611 | list.push_back("WorldLock");
612 | }
613 | if ((bcateg & 0x80) > 0)
614 | {
615 | list.push_back("Untradable");
616 | }
617 | if ((bcateg & 0x20) > 0)
618 | {
619 | list.push_back("Foreground");
620 | }
621 | if ((bcateg & 0x10) > 0)
622 | {
623 | list.push_back("Public");
624 | }
625 | if ((bcateg & 1) > 0)
626 | {
627 | list.push_back("Beta");
628 | }
629 | if ((bcateg & 4) > 0)
630 | {
631 | list.push_back("Mod");
632 | }
633 | if ((bcateg & 8) > 0)
634 | {
635 | list.push_back("RandomGrow");
636 | }
637 | if ((bcateg & 0x40) > 0)
638 | {
639 | list.push_back("Holiday");
640 | }
641 | if ((bcateg & 2) > 0)
642 | {
643 | list.push_back("AutoPickup");
644 | }
645 | return list;
646 | }
647 | struct Doorxd {
648 |
649 | string linksToWorld = "";
650 | string doorId = "";
651 | int x;
652 | int y;
653 | bool locked;
654 | };
655 | vector itemDefs;
656 | int getState(PlayerInfo* info) {
657 | int val = 0;
658 | val |= info->canWalkInBlocks << 0;
659 | val |= info->canDoubleJump << 1;
660 | val |= info->isInvisible << 2;
661 | val |= info->noHands << 3;
662 | val |= info->noEyes << 4;
663 | val |= info->noBody << 5;
664 | val |= info->devilHorns << 6;
665 | val |= info->goldenHalo << 7;
666 | val |= info->isFrozen << 11;
667 | val |= info->isCursed << 12;
668 | val |= info->isDuctaped << 13;
669 | val |= info->haveCigar << 14;
670 | val |= info->isShining << 15;
671 | val |= info->isZombie << 16;
672 | val |= info->isHitByLava << 17;
673 | val |= info->haveHauntedShadows << 18;
674 | val |= info->haveGeigerRadiation << 19;
675 | val |= info->haveReflector << 20;
676 | val |= info->isEgged << 21;
677 | val |= info->havePineappleFloag << 22;
678 | val |= info->haveFlyingPineapple << 23;
679 | val |= info->haveSuperSupporterName << 24;
680 | val |= info->haveSupperPineapple << 25;
681 | return val;
682 | }
683 |
684 | string EntranceTiles(int visual, uint32_t owner) {
685 | string data;
686 | data.resize(4 + 2 + 4 + 4 + 4 + 8);
687 | data[2] = 0x01;
688 | data[4] = 3;
689 | data[5] = visual;
690 | STRINT(data, 6) = owner;
691 | return data;
692 | }
693 | string EntranceTilesLocked(int visual, uint32_t owner) {
694 | string data;
695 | data.resize(4 + 2 + 4 + 4 + 4 + 8);
696 | data[2] = 0x01;
697 | data[5] = visual;
698 | STRINT(data, 6) = owner;
699 | return data;
700 | }
701 | void setupVIP(BYTE* raw) {
702 | raw[0] = 0x5;
703 | raw[1] = 0x0;
704 | raw[2] = 0x0;
705 | raw[3] = 0x0;
706 | raw[4] = 0x0;
707 | raw[5] = 0x0;
708 | raw[6] = 0x0;
709 | raw[7] = 0x0;
710 | raw[8] = 0x0;
711 | raw[9] = 0x8000000;
712 | raw[10] = 0x80000;
713 | raw[11] = 0x800;
714 | raw[12] = 0x8;
715 | raw[13] = 0x0;
716 | raw[14] = 0x0; //0
717 | raw[15] = 0x0; //0
718 | raw[16] = 0x0; //0
719 | raw[17] = 0x0; //0
720 | raw[18] = 0x0; //0
721 | raw[19] = 0x0; //0
722 | raw[20] = 0x0; //0
723 | raw[21] = 0x0; //0
724 | raw[22] = 0x0; //0
725 | raw[23] = 0x0; //0
726 | raw[24] = 0x0; //0
727 | raw[25] = 0x0; //0
728 | raw[26] = 0x0; //0
729 | raw[27] = 0x0; //0
730 | raw[28] = 0x0; //0
731 | raw[29] = 0x0; //0
732 | raw[30] = 0x0; //0
733 | raw[31] = 0x0; //0
734 | raw[32] = 0x0; //0
735 | raw[33] = 0x0; //0
736 | raw[34] = 0x0; //0
737 | raw[35] = 0x0; //0
738 | raw[36] = 0x0; //0
739 | raw[37] = 0x0; //0
740 | raw[38] = 0x0; //0
741 | raw[39] = 0x0; //0
742 | raw[40] = 0x0; //0
743 | raw[41] = 0x41000000; //1090519040
744 | raw[42] = 0x410000; //4259840
745 | raw[43] = 0x4100; //16640
746 | raw[44] = 0x41; //65
747 | raw[45] = 0x17000000; //385875968
748 | raw[46] = 0x170000; //1507328
749 | raw[47] = 0x1700; //5888
750 | raw[48] = 0x17; //23
751 | raw[49] = 0x12000000; //301989888
752 | raw[50] = 0x120000; //1179648
753 | raw[51] = 0x1200; //4608
754 | raw[52] = 0x12; //18
755 | raw[53] = -0x2a000000; //-704643072
756 | raw[54] = 0xed60000; //248905728
757 | raw[55] = 0xed600; //972288
758 | raw[56] = 0xed6; //3798
759 | raw[57] = 0xe; //14
760 | raw[58] = 0x0; //0
761 | raw[59] = 0x19000000; //419430400
762 | raw[60] = 0x190000; //1638400
763 | raw[61] = 0x2c001900; //738203904
764 | raw[62] = 0x2c0019; //2883609
765 | raw[63] = -0x52ffd400; //-1392497664
766 | raw[64] = -0x2052ffd4; //-542310356
767 | raw[65] = -0x48205300; //-1210077952
768 | raw[66] = 0x2b7dfad; //45604781
769 | raw[67] = 0x2b7df; //178143
770 | raw[68] = 0x2b7; //695
771 | raw[69] = 0x2; //2
772 | raw[70] = 0x0; //0
773 | raw[71] = 0x0; //0
774 | raw[72] = 0x0; //0
775 | raw[73] = 0x58000000; //1476395008
776 | raw[74] = 0x580000; //5767168
777 | raw[75] = 0x5800;
778 | raw[76] = 0x58;
779 | raw[77] = 0x23000000;
780 | raw[78] = 0x230000;
781 | }
782 | void ADBlocker_Setup(BYTE* raw) {
783 | raw[0] = 5, raw[1] = 0, raw[2] = 0, raw[3] = 0, raw[4] = 0, raw[5] = 0, raw[6] = 0, raw[7] = 0, raw[8] = 0, raw[9] = 0, raw[10] = 0, raw[11] = 2048, raw[12] = 8, raw[13] = 0, raw[14] = 0, raw[15] = 0, raw[16] = 0, raw[17] = 0, raw[18] = 0, raw[19] = 0, raw[20] = 0, raw[21] = 0, raw[22] = 0, raw[23] = 0, raw[24] = 0, raw[25] = 0, raw[26] = 0, raw[27] = 0, raw[28] = 0, raw[29] = 0, raw[30] = 0, raw[31] = 0, raw[32] = 0, raw[33] = 0, raw[34] = 0, raw[35] = 0, raw[36] = 0, raw[37] = 0, raw[38] = 0, raw[39] = 0, raw[40] = 0, raw[41] = 0, raw[42] = 0, raw[43] = 256, raw[44] = 1, raw[45] = 0, raw[46] = 0, raw[47] = 15104, raw[48] = 59, raw[49] = 0, raw[50] = 0, raw[51] = 7680, raw[52] = 30, raw[53] = 0, raw[54] = 0, raw[55] = 45056, raw[56] = 3760, raw[57] = 3598, raw[58] = 14, raw[59] = 0, raw[60] = 0, raw[61] = 256, raw[62] = 1, raw[63] = 10752, raw[64] = 42, raw[65] = 256, raw[66] = 1, raw[67] = 0, raw[68] = 0, raw[69] = 0, raw[70] = 0, raw[71] = 0, raw[72] = 0, raw[73] = 0, raw[74] = 0, raw[75] = 0, raw[76] = 0, raw[77] = 0, raw[78] = 0, raw[79] = 0, raw[80] = 0, raw[81] = 65280, raw[82] = 65535, raw[83] = 65535, raw[84] = 65535, raw[85] = 6399, raw[86] = 64792, raw[87] = 65021, raw[88] = 65021, raw[89] = 65021, raw[90] = 56829;
784 | }
785 | void ADBlocker(ENetPeer* peer) {
786 | const auto plength = 90;
787 | const auto raw = new BYTE[plength];
788 | memset(raw, 0, plength);
789 | ADBlocker_Setup(raw);
790 | ENetPacket* p = enet_packet_create(0, plength + 4, ENET_PACKET_FLAG_RELIABLE);
791 | const auto four = 4;
792 | memcpy(p->data, &four, sizeof(int));
793 | memcpy((char*)p->data + 4, raw, plength);
794 | enet_peer_send(peer, 0, p);
795 | delete[] raw;
796 | }
797 | void VIP_Door(ENetPeer* peer, const int x, const int y, const int fg, const int bg, const int owner) {
798 | const auto plength = 79;
799 | const auto raw = new BYTE[plength];
800 | memset(raw, 0, plength);
801 | setupVIP(raw);
802 | memcpy(raw + 44, &x, sizeof(int));
803 | memcpy(raw + 48, &y, sizeof(int));
804 | memcpy(raw + 56, &fg, sizeof(short));
805 | memcpy(raw + 58, &bg, sizeof(short));
806 | memcpy(raw + 66, &owner, sizeof(int));
807 | ENetPacket* p = enet_packet_create(0, plength + 4, ENET_PACKET_FLAG_RELIABLE);
808 | const auto four = 4;
809 | memcpy(p->data, &four, sizeof(int));
810 | memcpy((char*)p->data + 4, raw, plength);
811 | enet_peer_send(peer, 0, p);
812 | delete[] raw;
813 | }
814 |
815 | struct WorldItem {
816 | int rate_of_fire = 10, projectile_speed = 100;
817 | int flags = 0x00000000;
818 | uint16_t foreground = 0;
819 | uint16_t background = 0;
820 | string destWorld = "";
821 | string destId = "";
822 | string currId = "";
823 | string blockstate = "";
824 | bool spliced = false;
825 | bool silenced = false;
826 | int growtime = 0;
827 | int fruitcount = 0;
828 | bool entrance_open = false;
829 | int breakLevel = 0;
830 | long long int breakTime = 0;
831 | bool rm = false;
832 | bool water = false;
833 | bool opened = false;
834 | bool fire = false;
835 | bool glue = false;
836 | bool red = false;
837 | bool green = false;
838 | bool blue = false;
839 | bool activated = false;
840 | string worldinput = "";
841 | /*vending*/
842 | bool destroy = false;
843 | int vdraw = 0;
844 | int breakstate = 0;
845 | int breakbotstate = 0;
846 | string sign = "";
847 | string doorid = "";
848 | bool flipped = false;
849 | bool activeWeather = false;
850 | int intdata = 0;
851 | int yellowGems = 0;
852 | int blueGems = 0;
853 | string hmonitor_owner = "";
854 | int redGems = 0;
855 | int greenGems = 0;
856 | int purpleGems = 0;
857 | bool dropCollectBlocked = false;
858 |
859 |
860 |
861 | };
862 |
863 | struct gameupdatepacket_t {
864 | uint8_t m_type;
865 | uint8_t m_netid;
866 | uint8_t m_jump_amount;
867 | uint8_t m_count;
868 | int32_t m_player_flags;
869 | int32_t m_item;
870 | int32_t m_packet_flags;
871 | float m_struct_flags;
872 | int32_t m_int_data;
873 | float m_vec_x;
874 | float m_vec_y;
875 | float m_vec2_x;
876 | float m_vec2_y;
877 | float m_particle_time;
878 | uint32_t m_state1;
879 | uint32_t m_state2;
880 | uint32_t m_data_size;
881 | uint32_t m_data;
882 | };
883 | typedef struct gametankpacket_t {
884 | int32_t m_type;
885 | char m_data;
886 | } gametextpacket_t;
887 | struct BlockData {
888 | int packetType;
889 | int x;
890 | int y;
891 | int fg;
892 | int bg;
893 | int charState;
894 | int plength;
895 | int visual;
896 | int visual2;
897 |
898 | };
899 | BYTE* makeData(BlockData bdata) {
900 | BYTE* data = new BYTE[bdata.plength];
901 | memset(data, 0, bdata.plength);
902 | memcpy(data + 0, &bdata.packetType, 2);
903 | memcpy(data + 12, &bdata.charState, 2);
904 | memcpy(data + 44, &bdata.x, 4);
905 | memcpy(data + 48, &bdata.y, 4);
906 | memcpy(data + 56, &bdata.fg, 2);
907 | memcpy(data + 58, &bdata.bg, 2);
908 | memcpy(data + 60, &bdata.visual, 4);
909 | memcpy(data + 64, &bdata.visual2, 4);
910 | return data;
911 | }
912 | struct WorldAdministration {
913 | int userID = 0;
914 | int bannedAt = 0;
915 | };
916 |
917 | BYTE* packStuffVisual(TileExtra* dataStruct, int options, int gravity)
918 | {
919 | BYTE* data = new BYTE[102];
920 | for (auto i = 0; i < 102; i++)
921 | {
922 | data[i] = 0;
923 | }
924 | memcpy(data, &dataStruct->packetType, 4);
925 | memcpy(data + 8, &dataStruct->netID, 4);
926 | memcpy(data + 12, &dataStruct->characterState, 4);
927 | memcpy(data + 44, &dataStruct->punchX, 4);
928 | memcpy(data + 48, &dataStruct->punchY, 4);
929 | memcpy(data + 52, &dataStruct->charStat, 4);
930 | memcpy(data + 56, &dataStruct->blockid, 2);
931 | memcpy(data + 58, &dataStruct->backgroundid, 2);
932 | memcpy(data + 60, &dataStruct->visual, 4);
933 | memcpy(data + 64, &dataStruct->displayblock, 4);
934 | memcpy(data + 68, &gravity, 4);
935 | memcpy(data + 70, &options, 4);
936 | return data;
937 | }
938 | struct WorldInfo {
939 | long long int last_SAVE = 0;
940 | bool allowDropTakeAll = true;
941 | bool isEvent = true;
942 | bool WorldSaved = false;
943 | int geiger_locX = 64;
944 | int geiger_locY = 64;
945 | int bpm = 100;
946 | vector viplist;
947 | int width = 100;
948 | int invisible_music = 0;
949 | int droppedCount = 0;
950 | vector door;
951 | int height = 60;
952 | string name = "TEST";
953 | vector accessworld;
954 | vector wbans;
955 |
956 | bool enablecolleciton = false;
957 | int magX = 0;
958 | int magY = 0;
959 |
960 | bool silence = false;
961 | bool rainbows = false;
962 | vector items{};
963 | string ownerDisplayName = "";
964 | int magplantGems = 0;
965 |
966 | string owner = "";
967 | string itemsdropped = "";
968 | vector droppedItems;
969 | bool isPublic = false;
970 | int ownerID = 0;
971 | int weather = 0;
972 | bool isPineappleGuard = false;
973 | bool isCasino = false;
974 | bool isNuked = false;
975 |
976 | bool allowNoclip = true;
977 | bool item_changed = false;
978 | int stuff_gravity = 50;
979 | bool stuff_spin = false;
980 | bool stuff_invert = false;
981 | int stuffID = 2;
982 | int bgID = 14;
983 | int hw_red = 255;
984 | int hw_green = 128;
985 | int hw_blue = 64;
986 | };
987 |
988 | enum LabelStyles
989 | {
990 |
991 | LABEL_BIG,
992 | LABEL_SMALL
993 | };
994 |
995 | enum SpacerTypes
996 | {
997 | SPACER_BIG,
998 | SPACER_SMALL
999 | };
1000 |
1001 | enum CheckboxTypes
1002 | {
1003 | CHECKBOX_SELECTED,
1004 | CHECKBOX_NOT_SELECTED
1005 | };
1006 | /*string RgbToHex(int rNum, int gNum, int bNum)
1007 | {
1008 | string result;
1009 |
1010 | char r[255];
1011 | sprintf_s(r, "%.2X", rNum);
1012 | result.append(r);
1013 |
1014 | char g[255];
1015 | sprintf_s(g, "%.2X", gNum);
1016 | result.append(g);
1017 |
1018 | char b[255];
1019 | sprintf_s(b, "%.2X", bNum);
1020 | result.append(b);
1021 |
1022 | return result;
1023 | }*/
1024 | unsigned long RgbToHex(int r, int g, int b)
1025 | {
1026 | return ((b & 0xff) << 24) + ((g & 0xff) << 16) + ((r & 0xff) << 8) + (255 & 0xff);
1027 | }
1028 | void RiftOptions(ENetPeer* peer) {
1029 | string opt = ((PlayerInfo*)(peer->data))->ItemsOption;
1030 | vector ex = explode(":", opt);
1031 |
1032 | string capecolor = explode("=", ex[0])[1];
1033 | string collarcolor = explode("=", ex[1])[1];
1034 | string capecolor2 = explode("=", ex[2])[1];
1035 | string collarcolor2 = explode("=", ex[3])[1];
1036 | int delay = stoi(explode("=", ex[4])[1]);
1037 | //style 1
1038 | //get cpae color rgb
1039 | string rc = explode(",", capecolor)[0];
1040 | string gc = explode(",", capecolor)[1];
1041 | string bc = explode(",", capecolor)[2];
1042 | //get collar color
1043 | string cr = explode(",", collarcolor)[0];
1044 | string cg = explode(",", collarcolor)[1];
1045 | string cb = explode(",", collarcolor)[2];
1046 | //style 2
1047 | //get cpae color rgb
1048 | string rc2 = explode(",", capecolor2)[0];
1049 | string gc2 = explode(",", capecolor2)[1];
1050 | string bc2 = explode(",", capecolor2)[2];
1051 | //get collar color
1052 | string cr2 = explode(",", collarcolor2)[0];
1053 | string cg2 = explode(",", collarcolor2)[1];
1054 | string cb2 = explode(",", collarcolor2)[2];
1055 |
1056 | string dialog = "add_label_with_icon|big|`w" + itemDefs[10424].name + "|left|10424|\nadd_label|big|`oCape Style 1|left|\nadd_label|small|`oCape Color:|left|\nadd_text_input|rc|`oRed:|" + rc + "|3|\nadd_text_input|rg|`oGreen:|" + gc + "|3|\nadd_text_input|rb|`oBlue:|" + bc + "|3|\nadd_spacer|small|\nadd_label|small|`oCape Collar Color:|left|\nadd_text_input|cr|`oRed:|" + cr + "|3|\nadd_text_input|cg|`oGreen:|" + cg + "|3|\nadd_text_input|cb|`oBlue:|" + cb + "|3|\nadd_spacer|small|\nadd_label|big|`oCape Style 2|left|\nadd_label|small|`oCape Color:|left|\nadd_text_input|rc2|`oRed:|" + cr2 + "|3|\nadd_text_input|rg2|`oGreen:|" + gc2 + "|3|\nadd_text_input|rb2|`oBlue:|" + bc2 + "|3|\nadd_spacer|small|\nadd_label|small|`oCape Collar Color:|left|\nadd_text_input|cr2|`oRed:|" + cr2 + "|3|\nadd_text_input|cg2|`oGreen:|" + cg2 + "|3|\nadd_text_input|cb2|`oBlue:|" + cb2 + "|3|\nadd_spacer|small|\nadd_text_input|mmmmkmmkkk|`oTime Dilation Cycle Time|" + std::to_string(delay) + "|6|\nadd_spacer|small|\nadd_button|restore|`oRestore to default|noflags|0|0|\nend_dialog|updaterift|`wCancel|`wUpdate|";
1057 | GamePacket p = packetEnd(appendString(appendString(createPacket(), "OnDialogRequest"), dialog));
1058 | ENetPacket* packet = enet_packet_create(p.data,
1059 | p.len,
1060 | ENET_PACKET_FLAG_RELIABLE);
1061 | enet_peer_send(peer, 0, packet);
1062 | delete p.data;
1063 | }
1064 | bool isHerez(ENetPeer* peer, ENetPeer* peer2)
1065 | {
1066 | return ((PlayerInfo*)(peer->data))->currentWorld == ((PlayerInfo*)(peer2->data))->currentWorld;
1067 | }
1068 | class GTDialog
1069 | {
1070 | public:
1071 | string dialogstr = "";
1072 | void appendStart();
1073 | void addSpacer(SpacerTypes type);
1074 | void addLabelWithIcon(string text, int tileid, LabelStyles type);
1075 | void addLabelWithIconButton(string text, int tileid, string buttontext);
1076 | void addButton(string buttonname, string buttontext);
1077 | void addPicker(string pickername, string pickertext, string headText);
1078 | void addCheckbox(string checkboxname, string string, CheckboxTypes type);
1079 | void addTextBox(string str);
1080 | void addSmallText(string str);
1081 | void addItemWithCustomText(string itemID, string textUnderButton, string buttonName);
1082 | void addStaticBlueFrame(string itemID, string textUnderFrame, string buttonName, bool isEndLine);
1083 | void addInputBox(string name, string text, string cont, int size);
1084 | void addStaticBlueFrameWithIdCountText(string itemID, string count, string textUnderFrame, string buttonName, bool isEndLine);
1085 | void addQuickExit();
1086 | void addNewLineAfterFrame();
1087 | void endDialog(string name, string accept, string nvm);
1088 | void addCustom(string name);
1089 | string finishDialog() const;
1090 |
1091 | explicit operator string() const
1092 | {
1093 | return this->dialogstr;
1094 | }
1095 | };
1096 |
1097 | inline void GTDialog::addSpacer(const SpacerTypes type)
1098 | {
1099 | switch (type)
1100 | {
1101 | case SPACER_BIG:
1102 | this->dialogstr.append("add_spacer|big|\n");
1103 | break;
1104 | case SPACER_SMALL:
1105 | this->dialogstr.append("add_spacer|small|\n");
1106 | break;
1107 | default:
1108 | break;
1109 | }
1110 | }
1111 |
1112 | inline void GTDialog::addItemWithCustomText(const string itemID, const string textUnderButton, const string buttonName)
1113 | {
1114 | this->dialogstr.append("\nadd_button_with_icon|" + buttonName + "|" + textUnderButton + "|staticBlueFrame|" + itemID + "|");
1115 | }
1116 |
1117 | inline void GTDialog::addNewLineAfterFrame()
1118 | {
1119 | this->dialogstr.append("\nadd_button_with_icon||END_LIST|noflags|0|0|");
1120 | }
1121 |
1122 | inline void GTDialog::addPicker(const string pickername, const string pickertext, const string headText)
1123 | {
1124 | this->dialogstr.append("\nadd_item_picker|" + pickername + "|" + pickertext + "|" + headText + "|");
1125 | }
1126 |
1127 | inline void GTDialog::addStaticBlueFrame(const string itemID, const string textUnderFrame, const string buttonName, const bool isEndLine)
1128 | {
1129 | if (isEndLine == false)
1130 | {
1131 | this->dialogstr.append("\nadd_button_with_icon|" + buttonName + "||staticBlueFrame|" + itemID + "|" + textUnderFrame + "|");
1132 | }
1133 | else
1134 | {
1135 | this->dialogstr.append("\nadd_button_with_icon||END_LIST|noflags|0|0|\nadd_button_with_icon|" + buttonName + "||staticBlueFrame|" + itemID + "|" + textUnderFrame + "|");
1136 | }
1137 | }
1138 |
1139 | inline void GTDialog::addStaticBlueFrameWithIdCountText(const string itemID, string count, const string textUnderFrame, const string buttonName, const bool isEndLine)
1140 | {
1141 | if (isEndLine == false)
1142 | {
1143 | this->dialogstr.append("\nadd_button_with_icon|" + buttonName + "|" + textUnderFrame + "|frame|" + itemID + "|" + count + "|");
1144 | }
1145 | else
1146 | {
1147 | this->dialogstr.append("\nadd_button_with_icon||END_LIST|noflags|0|0|\nadd_button_with_icon|" + buttonName + "|" + textUnderFrame + "|frame|" + itemID + "|" + count + "|");
1148 | }
1149 | }
1150 |
1151 | inline void GTDialog::addLabelWithIcon(const string text, const int tileid, const LabelStyles type)
1152 | {
1153 | switch (type)
1154 | {
1155 | case LABEL_BIG:
1156 | this->dialogstr.append("add_label_with_icon|big|" + text + "|left|" + to_string(tileid) + "|\n");
1157 | break;
1158 | case LABEL_SMALL:
1159 | this->dialogstr.append("add_label_with_icon|small|" + text + "|left|" + to_string(tileid) + "|\n");
1160 | break;
1161 | default:
1162 | break;
1163 | }
1164 | }
1165 |
1166 | inline void GTDialog::addLabelWithIconButton(const string text, const int tileid, const string buttontext)
1167 | {
1168 | this->dialogstr.append("add_label_with_icon_button|mid|" + text + "|left|" + to_string(tileid) + "|" + buttontext + "|\n");
1169 | }
1170 |
1171 | inline void GTDialog::addButton(const string buttonname, const string buttontext)
1172 | {
1173 | this->dialogstr.append("add_button|" + buttonname + "|" + buttontext + "|noflags|0|0|\n");
1174 | }
1175 |
1176 | inline void GTDialog::addCheckbox(const string checkboxname, const string string, const CheckboxTypes type)
1177 | {
1178 | switch (type)
1179 | {
1180 | case CHECKBOX_SELECTED:
1181 | this->dialogstr.append("add_checkbox|" + checkboxname + "|" + string + "|1|\n");
1182 | break;
1183 | case CHECKBOX_NOT_SELECTED:
1184 | this->dialogstr.append("add_checkbox|" + checkboxname + "|" + string + "|0|\n");
1185 | break;
1186 | default:
1187 | break;
1188 | }
1189 | }
1190 |
1191 | inline void GTDialog::appendStart()
1192 | {
1193 | this->dialogstr.append("text_scaling_string|Dirttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt|\nset_default_color|\n");
1194 | }
1195 |
1196 | inline void GTDialog::addTextBox(const string str)
1197 | {
1198 | this->dialogstr.append("add_textbox|" + str + "|left|\n");
1199 | }
1200 |
1201 | inline void GTDialog::addSmallText(const string str)
1202 | {
1203 | this->dialogstr.append("add_smalltext|" + str + "|\n");
1204 | }
1205 |
1206 | inline void GTDialog::addInputBox(const string name, const string text, const string cont, const int size)
1207 | {
1208 | this->dialogstr.append("add_text_input|" + name + "|" + text + "|" + cont + "|" + to_string(size) + "|\n");
1209 | }
1210 |
1211 | inline void GTDialog::addQuickExit()
1212 | {
1213 | this->dialogstr.append("add_quick_exit|\n");
1214 | }
1215 |
1216 | inline void GTDialog::endDialog(const string name, const string accept, const string nvm)
1217 | {
1218 | this->dialogstr.append("end_dialog|" + name + "|" + nvm + "|" + accept + "|\n");
1219 | }
1220 |
1221 | inline void GTDialog::addCustom(const string name)
1222 | {
1223 | this->dialogstr.append(name + "\n");
1224 | }
1225 |
1226 | inline string GTDialog::finishDialog() const
1227 | {
1228 | return this->dialogstr;
1229 | }
1230 | namespace Player {
1231 | static void OnCountdownStart(ENetPeer* peer, int netID, int time, int score) {
1232 | gamepacket_t p(0, netID);
1233 | if (score == -1) {
1234 | p.Insert("OnCountdownStart"), p.Insert(time);
1235 | }
1236 | else
1237 | {
1238 | p.Insert("OnCountdownStart"), p.Insert(time), p.Insert(time);
1239 | }
1240 | p.CreatePacket(peer);
1241 | }
1242 | static void OnConsoleMessage(ENetPeer* peer, string message) {
1243 | gamepacket_t p;
1244 | p.Insert("OnConsoleMessage"), p.Insert(message);
1245 | p.CreatePacket(peer);
1246 | }
1247 | static void OnConsoleMessageWithTime(ENetPeer* peer, string message, int ms) {
1248 | gamepacket_t p(ms);
1249 | p.Insert("OnConsoleMessage"), p.Insert(message);
1250 | p.CreatePacket(peer);
1251 | }
1252 | static void OnKilled(ENetPeer* peer, int netID) {
1253 | gamepacket_t p(0, netID);
1254 | p.Insert("OnKilled");
1255 | p.CreatePacket(peer);
1256 | }
1257 | static void OnSetPos(ENetPeer* peer, int netID, int x, int y, int ms) {
1258 | gamepacket_t p(0, netID);
1259 | p.Insert("OnSetPos"), p.Insert(x, y);
1260 | p.CreatePacket(peer);
1261 | }
1262 |
1263 | static void OnSetFreezeState(ENetPeer* peer, int state, int netID) {
1264 | gamepacket_t p(0, netID);
1265 | p.Insert("OnSetFreezeState"), p.Insert(state);
1266 | p.CreatePacket(peer);
1267 | }
1268 | static void OnFailedToEnterWorld(ENetPeer* peer) {
1269 | gamepacket_t p;
1270 | p.Insert("OnFailedToEnterWorld"), p.Insert(1);
1271 | p.CreatePacket(peer);
1272 | }
1273 |
1274 | static void OnZoomCamera(ENetPeer* peer, float value1, int value2) {
1275 | gamepacket_t p;
1276 | p.Insert("OnZoomCamera"), p.Insert(value1), p.Insert(value2);
1277 | p.CreatePacket(peer);
1278 | }
1279 |
1280 | static void OnAddNotification(ENetPeer* peer, string text, string audiosound, string interfaceimage)
1281 | {
1282 | gamepacket_t p;
1283 | p.Insert("OnAddNotification"), p.Insert(interfaceimage), p.Insert(text), p.Insert(audiosound), p.Insert(0);
1284 | p.CreatePacket(peer);
1285 | }
1286 |
1287 | static void SmoothZoom(ENetPeer* peer) {
1288 | gamepacket_t p;
1289 | p.Insert("OnZoomCamera"), p.Insert(10000.0f), p.Insert(1000);
1290 | p.CreatePacket(peer);
1291 | }
1292 | static void SetRespawnPos(ENetPeer* peer, int posX, int posY, int netID) {
1293 | gamepacket_t p(0, netID);
1294 | p.Insert("SetRespawnPos"), p.Insert(posX + posY); // (world->width * posY)
1295 | p.CreatePacket(peer);
1296 | }
1297 |
1298 | static void OnTradeStatus(ENetPeer* peer, int netID, string statustext, string items, string locked)
1299 | {
1300 | //"add_slot|20|3locked|0reset_locks|1accepted|1"
1301 | gamepacket_t p;
1302 | p.Insert("OnTradeStatus"), p.Insert(netID), p.Insert(items), p.Insert(statustext), p.Insert(locked);
1303 | p.CreatePacket(peer);
1304 | }
1305 | static void OnChangeSkin(ENetPeer* peer, int skinColor, int netID) {
1306 | gamepacket_t p(0, netID);
1307 | p.Insert("OnChangeSkin"), p.Insert(skinColor);
1308 | p.CreatePacket(peer);
1309 | }
1310 | static void OnSpawn(ENetPeer* peer, int netID, int userID, int posX, int posY, string name, string country, int invis, int modstate, int supermodstate)
1311 | {
1312 | gamepacket_t p;
1313 | p.Insert("OnSpawn"), p.Insert("spawn|avatar\nnetID|" + std::to_string(netID) + "\nuserID|" + std::to_string(userID) + "\ncolrect|0|0|20|30\nposXY|" + std::to_string(posX) + "|" + std::to_string(posY) + "\nname|``" + name + "``\ncountry|" + country + "\ninvis|" + to_string(invis) + "\nmstate|" + to_string(modstate) + "\nsmstate|" + to_string(supermodstate) + "\ntype|local\n");
1314 | p.CreatePacket(peer);
1315 | }
1316 |
1317 |
1318 | static void OnStartTrade(ENetPeer* peer, string displayName, int netID)
1319 | {
1320 | gamepacket_t p;
1321 | p.Insert("OnStartTrade"), p.Insert(displayName), p.Insert(netID);
1322 | p.CreatePacket(peer);
1323 | }
1324 |
1325 | static void OnForceTradeEnd(ENetPeer* peer)
1326 | {
1327 | gamepacket_t p;
1328 | p.Insert("OnForceTradeEnd");
1329 | p.CreatePacket(peer);
1330 | }
1331 |
1332 | static void OnNameChanged(ENetPeer* peer, int netID, string name)
1333 | {
1334 | gamepacket_t p(0, netID);
1335 | p.Insert("OnNameChanged"), p.Insert("`0`0" + name);
1336 | ENetPeer* currentPeer;
1337 | for (currentPeer = server->peers;
1338 | currentPeer < &server->peers[server->peerCount];
1339 | ++currentPeer)
1340 | {
1341 | if (currentPeer->state != ENET_PEER_STATE_CONNECTED || currentPeer->data == NULL) continue;
1342 | if (isHerez(peer, currentPeer)) {
1343 | p.CreatePacket(currentPeer);
1344 | }
1345 | }
1346 | }
1347 | static void OnTextOverlay(ENetPeer* peer, string text) {
1348 | gamepacket_t p;
1349 | p.Insert("OnTextOverlay");
1350 | p.Insert(text);
1351 | p.CreatePacket(peer);
1352 | }
1353 |
1354 | static void OnSetBux(ENetPeer* peer, int gems, int accountstate)
1355 | {
1356 | gamepacket_t p;
1357 | p.Insert("OnSetBux");
1358 | p.Insert(gems), p.Insert(accountstate);
1359 | p.CreatePacket(peer);
1360 | }
1361 |
1362 | static void OnDialogRequest(ENetPeer* peer, string message) {
1363 | gamepacket_t p;
1364 | p.Insert("OnDialogRequest");
1365 | p.Insert(message);
1366 | p.CreatePacket(peer);
1367 | }
1368 | static void OnSendToServer(ENetPeer* peer, int userID, int token, string ip, int port, string doorId, int lmode)
1369 | {
1370 | gamepacket_t p;
1371 | p.Insert("OnSendToServer"), p.Insert(port), p.Insert(token), p.Insert(userID), p.Insert(ip + "|" + doorId), p.Insert(lmode);
1372 | p.CreatePacket(peer);
1373 | }
1374 |
1375 | static void OnParticleEffect(ENetPeer* peer, int effect, float x, float y, int delay) {
1376 | gamepacket_t p(delay);
1377 | p.Insert("OnParticleEffect"), p.Insert(effect), p.Insert(x, y);
1378 | p.CreatePacket(peer);
1379 | }
1380 |
1381 | static void OnConsoleMessageAll(string message) {
1382 | gamepacket_t p;
1383 | p.Insert("OnConsoleMessage"), p.Insert(message);
1384 | ENetPeer* currentPeer;
1385 | for (currentPeer = server->peers;
1386 | currentPeer < &server->peers[server->peerCount];
1387 | ++currentPeer)
1388 | {
1389 | if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
1390 | continue;
1391 | p.CreatePacket(currentPeer);
1392 | }
1393 | }
1394 |
1395 | static void PlayAudio(ENetPeer* peer, string audioFile, int delayMS)
1396 | {
1397 | string text = "action|play_sfx\nfile|" + audioFile + "\ndelayMS|" + to_string(delayMS) + "\n";
1398 | BYTE* data = new BYTE[5 + text.length()];
1399 | BYTE zero = 0;
1400 | int type = 3;
1401 | memcpy(data, &type, 4);
1402 | memcpy(data + 4, text.c_str(), text.length());
1403 | memcpy(data + 4 + text.length(), &zero, 1);
1404 | ENetPacket* packet = enet_packet_create(data,
1405 | 5 + text.length(),
1406 | ENET_PACKET_FLAG_RELIABLE);
1407 |
1408 | enet_peer_send(peer, 0, packet);
1409 | delete[] data;
1410 | }
1411 | static void OnTalkBubble(ENetPeer* peer, int netID, string message, bool stay) {
1412 | if (message.length() == 0 || message.length() > 100) return;
1413 | gamepacket_t p;
1414 | p.Insert("OnTalkBubble"), p.Insert(netID), p.Insert(message), p.Insert(0), p.Insert(stay ? 1 : 0);
1415 | p.CreatePacket(peer);
1416 | }
1417 |
1418 | static void OnPlayPositioned(ENetPeer* peer, string audiofile, int netID, bool broadcastInWorld, ENetPacket* pk) // packet only externally used when broadcasting / sending to multiple players to reduce memory leaks / cpu usage cuz we dont want to loop creating the packet for each player that would be insanely stupid.
1419 | {
1420 | if (broadcastInWorld) {
1421 | ENetPeer* currentPeer;
1422 |
1423 | for (currentPeer = server->peers;
1424 | currentPeer < &server->peers[server->peerCount];
1425 | ++currentPeer)
1426 | {
1427 | if (currentPeer->state != ENET_PEER_STATE_CONNECTED)
1428 | continue;
1429 | if (isHerez(peer, currentPeer)) {
1430 | enet_peer_send(currentPeer, 0, pk);
1431 | }
1432 | }
1433 | }
1434 | else
1435 | {
1436 | gamepacket_t p(0, netID);
1437 | p.Insert("OnPlayPositioned"), p.Insert(audiofile);
1438 | p.CreatePacket(peer);
1439 | }
1440 | }
1441 |
1442 | };
1443 | void SendWebhook(string message, string type) {
1444 | gamepacket_t p;
1445 | p.Insert("OnConsoleMessage"), p.Insert("`e[`wM`e] `o" + message);
1446 | for (ENetPeer* currentPeer = server->peers;
1447 | currentPeer < &server->peers[server->peerCount];
1448 | ++currentPeer) {
1449 | if (currentPeer->state != ENET_PEER_STATE_CONNECTED || currentPeer->data == NULL) continue;
1450 | if (!((PlayerInfo*)(currentPeer->data))->radio)
1451 | continue;
1452 | if (((PlayerInfo*)(currentPeer->data))->adminLevel >= 1) {
1453 | p.CreatePacket(currentPeer);
1454 | }
1455 | }
1456 | }
1457 | bool world_exist(string name) {
1458 | return experimental::filesystem::exists("worlds/" + name + ".json");
1459 | }
1460 | int GetPriceForInventory(int currentInv) {
1461 | return 10 * currentInv;
1462 | }
1463 | int GetMaxExpForNextLevel(int level) {
1464 | return 150 * level;
1465 | }
1466 |
1467 |
--------------------------------------------------------------------------------