small fixes

This commit is contained in:
Anonymous275 2020-05-03 19:03:50 +03:00
parent fa0939b6ed
commit 1b013fb9eb
4 changed files with 12 additions and 16 deletions

View File

@ -38,11 +38,11 @@ std::string Decompress(const std::string&Data)
{
std::string c;
c.resize(Data.size()*5);
z_stream infstream,defstream;
z_stream infstream;
infstream.zalloc = Z_NULL;
infstream.zfree = Z_NULL;
infstream.opaque = Z_NULL;
infstream.avail_in = (uInt)((char*)defstream.next_out - Data.c_str());
infstream.avail_in = (uInt)(Data.c_str());
infstream.next_in = (Bytef *)&Data[0];
infstream.avail_out = (uInt)c.size();
infstream.next_out = (Bytef *)&c[0];

View File

@ -1522,7 +1522,7 @@ static int enet_protocol_dispatch_incoming_commands(ENetHost *host, ENetEvent *e
}
event->packet = enet_peer_receive(peer, &event->channelID);
if (event->packet == NULL) {
if (event->packet == nullptr) {
continue;
}
@ -3583,20 +3583,16 @@ ENetPacket * enet_peer_receive(ENetPeer *peer, enet_uint8 *channelID) {
ENetIncomingCommand *incomingCommand;
ENetPacket *packet;
if (enet_list_empty(&peer->dispatchedCommands)) {
return NULL;
}
incomingCommand = (ENetIncomingCommand *)enet_list_remove(enet_list_begin(&peer->dispatchedCommands));
incomingCommand = (ENetIncomingCommand *) enet_list_remove(enet_list_begin(&peer->dispatchedCommands));
if (channelID != NULL) {
if (channelID != nullptr) {
*channelID = incomingCommand->command.header.channelID;
}
packet = incomingCommand->packet;
--packet->referenceCount;
if (incomingCommand->fragments != NULL) {
if (incomingCommand->fragments != nullptr) {
enet_free(incomingCommand->fragments);
}
@ -3612,7 +3608,7 @@ static void enet_peer_reset_outgoing_commands(ENetList *queue) {
while (!enet_list_empty(queue)) {
outgoingCommand = (ENetOutgoingCommand *) enet_list_remove(enet_list_begin(queue));
if (outgoingCommand->packet != NULL) {
if (outgoingCommand->packet != nullptr) {
--outgoingCommand->packet->referenceCount;
if (outgoingCommand->packet->referenceCount == 0) {

View File

@ -103,7 +103,7 @@ int main(int argc, char* argv[]){
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
std::cout << "Client Connected!" << std::endl;
HTTP_Result = HTTP_REQUEST("https://beamng-mp.com/entitlement?did="+GlobalInfo.at(2),443);
if(HTTP_Result.find("\"MDEV\"") == NPos){
if (HTTP_Result.find("\"MOD\"") == NPos && HTTP_Result.find("\"EA\"") == NPos){

View File

@ -4,7 +4,7 @@
#define ENET_IMPLEMENTATION
#include <condition_variable>
#include "include/enet.h"
#include "include/enet.hpp"
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <iostream>
@ -23,7 +23,7 @@ std::chrono::time_point<std::chrono::steady_clock> PingStart,PingEnd;
extern std::vector<std::string> GlobalInfo;
std::condition_variable RUDPLOCK,TCPLOCK;
std::queue<std::string> RUDPToSend;
std::queue<std::string> RUDPData;
std::queue<std::string> RUDPData; /////QUEUE WAS 196 SLOW?! NEED TO FIX
bool TCPTerminate = false;
bool Terminate = false;
bool CServer = true;
@ -100,7 +100,6 @@ void RUDPClientThread(const std::string& IP, int Port){
if (enet_initialize() != 0) {
std::cout << "An error occurred while initializing!\n";
}
std::mutex Lock;
Client client;
ENetAddress address = {0};
@ -137,6 +136,7 @@ void RUDPClientThread(const std::string& IP, int Port){
}
RUDPToSend.pop();
}
std::mutex Lock;
std::unique_lock<std::mutex> lk(Lock);
std::chrono::high_resolution_clock::time_point tp = std::chrono::high_resolution_clock::now() + std::chrono::nanoseconds (1);
RUDPLOCK.wait_until(lk, tp, [](){return !RUDPToSend.empty();});
@ -152,7 +152,6 @@ void RUDPClientThread(const std::string& IP, int Port){
void TCPRespond(const SOCKET *CS){
SOCKET ClientSocket = *CS;
int iSendResult;
std::mutex Lock;
while(!TCPTerminate){
while (!RUDPData.empty()) {
std::string Data = RUDPData.front() + "\n";
@ -170,6 +169,7 @@ void TCPRespond(const SOCKET *CS){
RUDPData.pop();
}
}
std::mutex Lock;
std::unique_lock<std::mutex> lk(Lock);
std::chrono::high_resolution_clock::time_point tp = std::chrono::high_resolution_clock::now() + std::chrono::milliseconds(1);
TCPLOCK.wait_until(lk, tp, [](){return !RUDPData.empty();});