This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
NetworkWrapper.h
121 lines (87 loc) · 3.31 KB
/
NetworkWrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <iostream>
#include <sstream>
#include <tuple>
#include "MTAStuff/sdk/SharedUtil.h"
#include "MTAStuff/core/CDynamicLibrary.h"
#include "MTAStuff/sdk/SharedUtil.h"
#include "MTAStuff/sdk/net/Packets.h"
#include "MTAStuff/sdk/net/bitstream.h"
#include "MTAStuff/sdk/net/CNetServer.h"
#include <Python.h>
#include "Packets/PlayerJoinDataPacket.h"
#include "Utils.h"
#ifndef WIN32
#define __stdcall
#endif
struct Packet
{
NetServerPlayerID player;
unsigned char ucPacketID;
NetBitStreamInterface* pBitStream;
unsigned char ucPriority;
unsigned char ucReliability;
Packet(NetServerPlayerID socket, unsigned char packetId, NetBitStreamInterface* bitStream, unsigned char priority, unsigned char reliability)
: player(socket), ucPacketID(packetId), pBitStream(bitStream), ucPriority(priority), ucReliability(reliability) {}
};
struct SerialExtraAndVersion
{
std::string serial;
std::string extra;
std::string version;
SerialExtraAndVersion(std::string serial, std::string extra, std::string version)
: serial(serial), extra(extra), version(version) {}
};
struct PlayerAddress
{
std::string strIP = "";
unsigned short usPort = 0;
};
class MTANetworkWrapper
{
private:
unsigned short usID;
static uint16_t nextId;
static std::map<uint16_t, MTANetworkWrapper*> netWrappers;
static std::map<NetServerPlayerID, MTANetworkWrapper*> netWrappersPerSocket;
bool m_QueuedPacket = false;
CDynamicLibrary m_NetworkLibLoader;
unsigned int m_uiPacketIndex;
unsigned int m_uiPacket = 0;
unsigned long m_ulPlayerListAddress = 0;
PyObject* m_pPacketData = nullptr;
CNetServer* m_pNetwork;
std::map<ulong, NetServerPlayerID> m_Players;
bool m_bRunning;
std::thread m_MainThread;
std::thread m_PulseThread;
std::thread m_PacketHandlerThread;
std::queue<Packet> m_Packets;
std::mutex mutex;
void PulseLoop();
void MainLoop();
public:
MTANetworkWrapper();
bool Setup(const char* szServerIdPath, const char* szNetLibPath, const char* szIP, unsigned short usPort, unsigned int uiPlayerCount,
const char* szServerName, unsigned long* pulMtaVersionType, PyObject* pFunction);
void Start();
PyObject* GetLastPackets();
void Send(unsigned long ulAddress, unsigned char ucPacketId, unsigned short usBitStreamVersion, const char* szData, unsigned long ulDataSize, unsigned char ucPriority, unsigned char ucReliability);
bool IsValidSocket(unsigned long ulAddress);
PlayerAddress GetPlayerAddress(unsigned long ulAddress);
void SetClientBitStreamVersion(unsigned long ulAddress, unsigned short usVersion);
void SetAntiCheatChecks(const char* szDisableComboACMap, const char* szDisableACMap, const char* szEnableSDMap, int iEnableClientChecks, bool bHideAC, const char* szImgMods);
void GetAntiCheatInfo(unsigned long ulAddress);
SerialExtraAndVersion GetClientData(unsigned long ulAddress);
void GetModPackets(unsigned long ulAddress);
const char* GetNetRoute();
const char* GetPingStatus();
SBandwidthStatistics GetBandwidthStatistics();
SPacketStat GetPacketStats();
void Stop();
void Destroy();
ushort GetId();
bool StaticPacketHandler(unsigned char ucPacketID, const NetServerPlayerID& player, NetBitStreamInterface* pBitStream, SNetExtraInfo* pNetExtraInfo);
bool IsValidSocket(NetServerPlayerID id);
static MTANetworkWrapper* GetNetWrapper(int iId);
static MTANetworkWrapper* GetNetWrapper(NetServerPlayerID id);
};