mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-08-16 00:06:41 +00:00
Auto name request + parser
This commit is contained in:
parent
b227db5def
commit
f286a95d8e
@ -9,6 +9,6 @@ project(BeamMP-Launcher)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
add_executable(BeamMP-Launcher main.cpp proxy.cpp Security.cpp http.cpp Discord.cpp UpdateCheck.cpp CoreNetwork.cpp Resources.cpp ProxyParser.cpp)
|
||||
add_executable(BeamMP-Launcher main.cpp proxy.cpp Security.cpp http.cpp Discord.cpp UpdateCheck.cpp CoreNetwork.cpp Resources.cpp)
|
||||
|
||||
target_link_libraries(BeamMP-Launcher discord-rpc libcurl_a)
|
12
Discord.cpp
12
Discord.cpp
@ -16,7 +16,7 @@ static const char* APPLICATION_ID = "345229890980937739";
|
||||
static int FrustrationLevel = 0;
|
||||
static int64_t StartTime;
|
||||
static int SendPresence = 1;
|
||||
static std::vector<std::string> DiscordInfo;
|
||||
static std::vector<std::string> LocalInfo;
|
||||
|
||||
static void updateDiscordPresence()
|
||||
{
|
||||
@ -51,9 +51,9 @@ static void handleDiscordReady(const DiscordUser* connectedUser)
|
||||
connectedUser->username,
|
||||
connectedUser->discriminator,
|
||||
connectedUser->userId);*/
|
||||
DiscordInfo.emplace_back(connectedUser->username);
|
||||
DiscordInfo.emplace_back(connectedUser->discriminator);
|
||||
DiscordInfo.emplace_back(connectedUser->userId);
|
||||
LocalInfo.emplace_back(connectedUser->username);
|
||||
LocalInfo.emplace_back(connectedUser->discriminator);
|
||||
LocalInfo.emplace_back(connectedUser->userId);
|
||||
}
|
||||
|
||||
static void handleDiscordDisconnected(int errcode, const char* message)
|
||||
@ -129,7 +129,7 @@ static std::vector<std::string> Loop()
|
||||
|
||||
StartTime = time(0);
|
||||
|
||||
while (DiscordInfo.size() < 3) {
|
||||
while (LocalInfo.size() < 3) {
|
||||
//updateDiscordPresence();
|
||||
|
||||
#ifdef DISCORD_DISABLE_IO_THREAD
|
||||
@ -138,7 +138,7 @@ static std::vector<std::string> Loop()
|
||||
Discord_RunCallbacks();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
}
|
||||
return DiscordInfo;
|
||||
return LocalInfo;
|
||||
}
|
||||
|
||||
std::vector<std::string> Discord_Main()
|
||||
|
@ -1,4 +0,0 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 4/16/2020
|
||||
///
|
||||
|
11
main.cpp
11
main.cpp
@ -13,6 +13,7 @@
|
||||
|
||||
std::string HTTP_REQUEST(const std::string&url,int port);
|
||||
std::vector<std::string> Discord_Main();
|
||||
std::vector<std::string> GlobalInfo;
|
||||
std::vector<std::string> Check();
|
||||
std::string getHardwareID();
|
||||
void CheckForUpdates(const std::string& CV);
|
||||
@ -79,7 +80,7 @@ std::string CheckVer(const std::string &path){
|
||||
void SyncResources(const std::string&IP,int Port);
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
std::string ver = "0.38", Path = CheckDir(argv[0],ver),HTTP_Result;
|
||||
std::string ver = "0.40", Path = CheckDir(argv[0],ver),HTTP_Result;
|
||||
CheckForUpdates(ver); //Update Check
|
||||
|
||||
//Security
|
||||
@ -88,10 +89,10 @@ int main(int argc, char* argv[])
|
||||
std::cout << "You own BeamNG on this machine!" << std::endl;
|
||||
std::cout << "Game Ver : " << CheckVer(GamePath) << std::endl;
|
||||
|
||||
|
||||
std::cout << "Name : " << Discord_Main().at(0) << std::endl;
|
||||
std::cout << "Discriminator : " << Discord_Main().at(1) << std::endl;
|
||||
std::cout << "Unique ID : " << Discord_Main().at(2) << std::endl;
|
||||
GlobalInfo = Discord_Main();
|
||||
std::cout << "Name : " << GlobalInfo.at(0) << std::endl;
|
||||
std::cout << "Discriminator : " << GlobalInfo.at(1) << std::endl;
|
||||
std::cout << "Unique ID : " << GlobalInfo.at(2) << std::endl;
|
||||
|
||||
std::cout << "HWID : " << getHardwareID() << std::endl;
|
||||
|
||||
|
30
proxy.cpp
30
proxy.cpp
@ -19,12 +19,12 @@ typedef struct {
|
||||
ENetHost *host;
|
||||
ENetPeer *peer;
|
||||
} Client;
|
||||
|
||||
std::chrono::time_point<std::chrono::steady_clock> PingStart,PingEnd;
|
||||
extern std::vector<std::string> GlobalInfo;
|
||||
std::queue<std::string> RUDPData;
|
||||
std::queue<std::string> RUDPToSend;
|
||||
bool Terminate = false;
|
||||
int ping = 0;
|
||||
std::chrono::time_point<std::chrono::steady_clock> PingStart;
|
||||
void CoreNetworkThread();
|
||||
|
||||
void AutoPing(ENetPeer*peer){
|
||||
@ -34,12 +34,22 @@ void AutoPing(ENetPeer*peer){
|
||||
Sleep(1000);
|
||||
}
|
||||
}
|
||||
void NameRespond(ENetPeer*peer){
|
||||
std::string Packet = "NR" + GlobalInfo.at(0);
|
||||
enet_peer_send(peer, 0, enet_packet_create(Packet.c_str(), Packet.length()+1, ENET_PACKET_FLAG_RELIABLE));
|
||||
}
|
||||
|
||||
void RUDPParser(const std::string& Data){
|
||||
if(Data == "p"){
|
||||
auto PingEnd = std::chrono::high_resolution_clock::now();
|
||||
ping = std::chrono::duration_cast<std::chrono::milliseconds>(PingEnd-PingStart).count();
|
||||
return;
|
||||
void RUDPParser(const std::string& Data,ENetPeer*peer){
|
||||
char Code = Data.at(0),SubCode = 0;
|
||||
if(Data.length() > 1)SubCode = Data.at(1);
|
||||
switch (Code) {
|
||||
case 'p':
|
||||
PingEnd = std::chrono::high_resolution_clock::now();
|
||||
ping = std::chrono::duration_cast<std::chrono::milliseconds>(PingEnd-PingStart).count();
|
||||
return;
|
||||
case 'N':
|
||||
if(SubCode == 'R')NameRespond(peer);
|
||||
return;
|
||||
}
|
||||
std::cout << "Received: " << Data << std::endl;
|
||||
RUDPData.push(Data);
|
||||
@ -56,8 +66,8 @@ void HandleEvent(ENetEvent event,Client client){
|
||||
event.peer->data = (void *)"Connected Server";
|
||||
break;
|
||||
case ENET_EVENT_TYPE_RECEIVE:
|
||||
RUDPParser((char*)event.packet->data);
|
||||
enet_packet_destroy (event.packet);
|
||||
RUDPParser((char*)event.packet->data,event.peer);
|
||||
enet_packet_destroy(event.packet);
|
||||
break;
|
||||
case ENET_EVENT_TYPE_DISCONNECT:
|
||||
printf ("%s disconnected.\n", (char *)event.peer->data);
|
||||
@ -103,7 +113,7 @@ void RUDPClientThread(const std::string& IP, int Port){
|
||||
enet_host_service(client.host, &event, 0);
|
||||
HandleEvent(event,client); //Handles the Events
|
||||
while (!RUDPToSend.empty()){
|
||||
ENetPacket* packet = enet_packet_create (RUDPToSend.front().c_str(),
|
||||
ENetPacket* packet = enet_packet_create(RUDPToSend.front().c_str(),
|
||||
RUDPToSend.front().length()+1,
|
||||
ENET_PACKET_FLAG_RELIABLE);
|
||||
enet_peer_send(client.peer, 0, packet);
|
||||
|
Loading…
x
Reference in New Issue
Block a user