mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-08-18 01:06:51 +00:00
Merge pull request #24 from SamZahreddine/v3
[Fixed] Check port if valid
This commit is contained in:
commit
2e3b62c15c
@ -4,6 +4,7 @@
|
||||
///
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include "Compressor.h"
|
||||
#include "Server.h"
|
||||
#include "Launcher.h"
|
||||
@ -45,12 +46,16 @@ void Server::TCPClientMain() {
|
||||
if (status != 0) {
|
||||
UStatus = "Connection Failed!";
|
||||
LOG(ERROR) << "Connect failed! Error code: " << GetSocketApiError();
|
||||
Close();
|
||||
Terminate.store(true);
|
||||
return;
|
||||
}
|
||||
|
||||
char Code = 'C';
|
||||
if (send(TCPSocket, &Code, 1, 0) != 1) {
|
||||
Terminate.store(true);
|
||||
return;
|
||||
}
|
||||
LOG(INFO) << "Connected!";
|
||||
char Code = 'C';
|
||||
send(TCPSocket, &Code, 1, 0);
|
||||
SyncResources();
|
||||
while (!Terminate.load()) {
|
||||
ServerParser(TCPRcv());
|
||||
@ -73,7 +78,8 @@ void Server::UDPSend(std::string Data) {
|
||||
Data = "ABG:" + CMP;
|
||||
}
|
||||
std::string Packet = char(ClientID + 1) + std::string(":") + Data;
|
||||
int sendOk = sendto(UDPSocket, Packet.c_str(), int(Packet.size()), 0, (sockaddr*)UDPSockAddress.get(), sizeof(sockaddr_in));
|
||||
int sendOk = sendto(UDPSocket, Packet.c_str(), int(Packet.size()), 0, (sockaddr *) UDPSockAddress.get(),
|
||||
sizeof(sockaddr_in));
|
||||
if (sendOk == SOCKET_ERROR)LOG(ERROR) << "UDP Socket Error Code : " << GetSocketApiError();
|
||||
}
|
||||
|
||||
@ -118,14 +124,17 @@ void Server::Connect(const std::string& Data) {
|
||||
ModList.clear();
|
||||
Terminate.store(false);
|
||||
IP = GetAddress(Data.substr(1, Data.find(':') - 1));
|
||||
if(IP.find('.') == -1){
|
||||
std::string port = Data.substr(Data.find(':') + 1);
|
||||
bool ValidPort = std::all_of(port.begin(), port.end(), ::isdigit);
|
||||
if (IP.find('.') == -1 || !ValidPort) {
|
||||
if (IP == "DNS") UStatus = "Connection Failed! (DNS Lookup Failed)";
|
||||
else if (!ValidPort) UStatus = "Connection Failed! (Invalid Port)";
|
||||
else UStatus = "Connection Failed! (WSA failed to start)";
|
||||
ModList = "-";
|
||||
Terminate.store(true);
|
||||
return;
|
||||
}
|
||||
Port = std::stoi(Data.substr(Data.find(':')+1));
|
||||
Port = std::stoi(port);
|
||||
LauncherInstance->CheckKey();
|
||||
UStatus = "Loading...";
|
||||
Ping = -1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user