-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrustsocket.h
More file actions
99 lines (96 loc) · 2.48 KB
/
rustsocket.h
File metadata and controls
99 lines (96 loc) · 2.48 KB
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
#pragma once
#include <iostream>
#include <fstream>
#include "easywsclient.hpp"
#include "rustplus.pb.h"
#include <map>
#ifdef _WIN32
#pragma comment( lib, "ws2_32" )
#include <WinSock2.h>
#include <assert.h>
#endif
#ifdef __WIN32__
# include <winsock2.h>
#else
# include <sys/types.h>
#endif
using namespace easywsclient;
using namespace rustplus;
//std::vector<char> buffer;
std::string trim(const std::string& str, const std::string& whitespace = " \t");
struct Time
{
int hours, minutes;
};
enum MessageFlags
{
MsgLocal = 0x01,
MsgChat = 0x02,
MsgBoth = 0x03,
MsgIncludeTime = 0x04
};
struct Events
{
int cCrate = 0;
int cCargo = 0;
int cExplosion = 0;
int cChinook = 0;
int cPatrol = 0;
std::vector<AppMarker> v_crates;
AppMarker i_cargo;
bool operator==(const Events& other)
{
return cCrate == other.cCrate && cCargo == other.cCargo && cExplosion == other.cExplosion && cChinook == other.cChinook && cPatrol == other.cPatrol;
}
bool operator!=(const Events& other)
{
return cCrate != other.cCrate || cCargo != other.cCargo || cExplosion != other.cExplosion || cChinook != other.cChinook || cPatrol != other.cPatrol;
}
bool empty()
{
return !cCrate && !cCargo && !cExplosion && !cChinook && !cPatrol && v_crates.empty() && !i_cargo.ByteSizeLong();
}
};
enum NStatus
{
NReady,
NWaiting
};
enum NMessageType
{
NMarkers,
NTeamChat,
NTeamInfo
};
bool DifferentChats(const AppTeamChat& OLD, const AppTeamChat& NEW);
std::pair<int, int> FormatCoord(int x, int y, int map_size);
void SaveMap(const AppMap& map, const char* filename);
Time FormatTime(float fTime);
Time FormatTime(AppTime time);
float Distance(float x1, float y1, float x2, float y2);
bool VectorContains(std::vector<AppMarker>& vec, AppMarker element);
class RustSocket
{
public:
WebSocket::pointer ws = nullptr;
RustSocket(const char* ip, const char* port, uint64_t steamid, int32_t token);
void SendTeamChatMessage(const char* message);
AppInfo GetInfo();
AppMap GetMap();
AppMapMarkers GetMarkers();
AppTeamChat GetTeamChat();
Events GetEvents(AppMapMarkers markers);
AppTime GetTime();
AppTeamInfo GetTeamInfo();
void PromoteToTeamLeader(uint64_t steamid);
AppRequest initProto();
void Message(const std::string& msg, int flags);
AppCameraInfo Subscribe(const char* camid);
void SetSubscription();
void CheckSubscription();
private:
std::string url = "ws://";
uint32_t iSeq;
uint64_t iSteamID;
int32_t iPlayerToken;
};