mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-04 00:36:14 +00:00
change __WIN32 to WIN32 (oops)
This commit is contained in:
parent
e9432ac1ca
commit
e986df0579
@ -9,6 +9,9 @@ if (UNIX)
|
|||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -g")
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -g")
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -s")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -s")
|
||||||
elseif (WIN32)
|
elseif (WIN32)
|
||||||
|
# This might cause issues with old windows headers, but it's worth the trouble to keep the code
|
||||||
|
# completely cross platform. For fixes to common issues arising from /permissive- visit:
|
||||||
|
# https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /permissive-")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /permissive-")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
#include <WS2tcpip.h>
|
#include <WS2tcpip.h>
|
||||||
#else
|
#else
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
* Define WIN32 when build target is Win32 API
|
* Define WIN32 when build target is Win32 API
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (defined(_WIN32) || defined(__WIN32__)) && \
|
#if (defined(_WIN32) || defined(WIN32__)) && \
|
||||||
!defined(WIN32) && !defined(__SYMBIAN32__)
|
!defined(WIN32) && !defined(__SYMBIAN32__)
|
||||||
#define WIN32
|
#define WIN32
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
// This header defines unix equivalents of common win32 functions.
|
// This header defines unix equivalents of common win32 functions.
|
||||||
|
|
||||||
#ifndef __WIN32
|
#ifndef WIN32
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -27,4 +27,4 @@ inline void closesocket(int socket) {
|
|||||||
#define __except(x) /**/
|
#define __except(x) /**/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
|
@ -176,7 +176,7 @@
|
|||||||
#if defined(_WINDOWS) && !defined(WINDOWS)
|
#if defined(_WINDOWS) && !defined(WINDOWS)
|
||||||
# define WINDOWS
|
# define WINDOWS
|
||||||
#endif
|
#endif
|
||||||
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
|
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(WIN32__)
|
||||||
# ifndef WIN32
|
# ifndef WIN32
|
||||||
# define WIN32
|
# define WIN32
|
||||||
# endif
|
# endif
|
||||||
|
@ -133,7 +133,7 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
|||||||
#if defined(MACOS) || defined(TARGET_OS_MAC)
|
#if defined(MACOS) || defined(TARGET_OS_MAC)
|
||||||
# define OS_CODE 7
|
# define OS_CODE 7
|
||||||
# ifndef Z_SOLO
|
# ifndef Z_SOLO
|
||||||
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
|
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != WIN32_os
|
||||||
# include <unix.h> /* for fdopen */
|
# include <unix.h> /* for fdopen */
|
||||||
# else
|
# else
|
||||||
# ifndef fdopen
|
# ifndef fdopen
|
||||||
|
@ -3,14 +3,14 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
#include "Lua/LuaSystem.hpp"
|
#include "Lua/LuaSystem.hpp"
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
#else // *nix
|
#else // *nix
|
||||||
typedef unsigned long DWORD, *PDWORD, *LPDWORD;
|
typedef unsigned long DWORD, *PDWORD, *LPDWORD;
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -54,7 +54,7 @@ void ConsoleOut(const std::string& msg){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __WIN32
|
#ifndef WIN32
|
||||||
static int _getch()
|
static int _getch()
|
||||||
{
|
{
|
||||||
char buf = 0;
|
char buf = 0;
|
||||||
@ -77,10 +77,10 @@ static int _getch()
|
|||||||
// no echo printf("%c\n", buf);
|
// no echo printf("%c\n", buf);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
|
|
||||||
void SetupConsole(){
|
void SetupConsole(){
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
DWORD outMode = 0;
|
DWORD outMode = 0;
|
||||||
HANDLE stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
|
HANDLE stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
if (stdoutHandle == INVALID_HANDLE_VALUE){
|
if (stdoutHandle == INVALID_HANDLE_VALUE){
|
||||||
@ -101,7 +101,7 @@ void SetupConsole(){
|
|||||||
exit(GetLastError());
|
exit(GetLastError());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] void ReadCin(){
|
[[noreturn]] void ReadCin(){
|
||||||
|
@ -85,7 +85,7 @@ int Dec(int value,int d,int n){
|
|||||||
return log_power(value, d, n);
|
return log_power(value, d, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
int Handle(EXCEPTION_POINTERS *ep,char* Origin){
|
int Handle(EXCEPTION_POINTERS *ep,char* Origin){
|
||||||
assert(false);
|
assert(false);
|
||||||
std::stringstream R;
|
std::stringstream R;
|
||||||
@ -98,7 +98,7 @@ int Handle(EXCEPTION_POINTERS *ep,char* Origin){
|
|||||||
#else
|
#else
|
||||||
// stub
|
// stub
|
||||||
int Handle(EXCEPTION_POINTERS *, char*) { return 1; }
|
int Handle(EXCEPTION_POINTERS *, char*) { return 1; }
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
|
|
||||||
std::string RSA_E(const std::string& Data, RSA*k){
|
std::string RSA_E(const std::string& Data, RSA*k){
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
|
@ -143,7 +143,7 @@ void SafeExecution(Lua* lua,const std::string& FuncName){
|
|||||||
lua_getglobal(luaState, FuncName.c_str());
|
lua_getglobal(luaState, FuncName.c_str());
|
||||||
if(lua_isfunction(luaState, -1)) {
|
if(lua_isfunction(luaState, -1)) {
|
||||||
char* Origin = ThreadOrigin(lua);
|
char* Origin = ThreadOrigin(lua);
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
__try{
|
__try{
|
||||||
int R = lua_pcall(luaState, 0, 0, 0);
|
int R = lua_pcall(luaState, 0, 0, 0);
|
||||||
CheckLua(luaState, R);
|
CheckLua(luaState, R);
|
||||||
@ -151,7 +151,7 @@ void SafeExecution(Lua* lua,const std::string& FuncName){
|
|||||||
#else // unix
|
#else // unix
|
||||||
int R = lua_pcall(luaState, 0, 0, 0);
|
int R = lua_pcall(luaState, 0, 0, 0);
|
||||||
CheckLua(luaState, R);
|
CheckLua(luaState, R);
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
delete [] Origin;
|
delete [] Origin;
|
||||||
}
|
}
|
||||||
ClearStack(luaState);
|
ClearStack(luaState);
|
||||||
@ -515,18 +515,18 @@ int CallFunction(Lua*lua,const std::string& FuncName,LuaArg* Arg){
|
|||||||
}
|
}
|
||||||
int R = 0;
|
int R = 0;
|
||||||
char* Origin = lua->GetOrigin();
|
char* Origin = lua->GetOrigin();
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
__try{
|
__try{
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
R = lua_pcall(luaState, Size, 1, 0);
|
R = lua_pcall(luaState, Size, 1, 0);
|
||||||
if (CheckLua(luaState, R)){
|
if (CheckLua(luaState, R)){
|
||||||
if (lua_isnumber(luaState, -1)) {
|
if (lua_isnumber(luaState, -1)) {
|
||||||
return int(lua_tointeger(luaState, -1));
|
return int(lua_tointeger(luaState, -1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
}__except(Handle(GetExceptionInformation(),Origin)){}
|
}__except(Handle(GetExceptionInformation(),Origin)){}
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
delete [] Origin;
|
delete [] Origin;
|
||||||
}
|
}
|
||||||
ClearStack(luaState);
|
ClearStack(luaState);
|
||||||
|
@ -158,20 +158,20 @@ void Identify(SOCKET TCPSock){
|
|||||||
// reason MSVC defines __try and __except and libg++ defines
|
// reason MSVC defines __try and __except and libg++ defines
|
||||||
// __try and __catch so its all a big mess if we leave this in or undefine
|
// __try and __catch so its all a big mess if we leave this in or undefine
|
||||||
// the macros
|
// the macros
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
__try{
|
__try{
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
Identification(TCPSock,S,Skey);
|
Identification(TCPSock,S,Skey);
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
}__except(1){
|
}__except(1){
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
|
|
||||||
if(TCPSock != -1){
|
if(TCPSock != -1){
|
||||||
closesocket(TCPSock);
|
closesocket(TCPSock);
|
||||||
}
|
}
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
}
|
}
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
|
|
||||||
delete Skey;
|
delete Skey;
|
||||||
delete S;
|
delete S;
|
||||||
@ -179,7 +179,7 @@ void Identify(SOCKET TCPSock){
|
|||||||
|
|
||||||
void TCPServerMain(){
|
void TCPServerMain(){
|
||||||
DebugPrintTID();
|
DebugPrintTID();
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
if (WSAStartup(514, &wsaData)){
|
if (WSAStartup(514, &wsaData)){
|
||||||
error(Sec("Can't start Winsock!"));
|
error(Sec("Can't start Winsock!"));
|
||||||
@ -249,5 +249,5 @@ void TCPServerMain(){
|
|||||||
}while(client);
|
}while(client);
|
||||||
|
|
||||||
closesocket(client);
|
closesocket(client);
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
}
|
}
|
||||||
|
@ -124,13 +124,13 @@ void SyncClient(Client*c){
|
|||||||
}
|
}
|
||||||
void ParseVeh(Client*c, const std::string& Packet){
|
void ParseVeh(Client*c, const std::string& Packet){
|
||||||
Assert(c);
|
Assert(c);
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
__try{
|
__try{
|
||||||
VehicleParser(c,Packet);
|
VehicleParser(c,Packet);
|
||||||
}__except(Handle(GetExceptionInformation(),Sec("Vehicle Handler"))){}
|
}__except(Handle(GetExceptionInformation(),Sec("Vehicle Handler"))){}
|
||||||
#else // unix
|
#else // unix
|
||||||
VehicleParser(c,Packet);
|
VehicleParser(c,Packet);
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleEvent(Client*c ,const std::string&Data){
|
void HandleEvent(Client*c ,const std::string&Data){
|
||||||
@ -204,11 +204,11 @@ void GlobalParser(Client*c, const std::string& Pack){
|
|||||||
|
|
||||||
void GParser(Client*c, const std::string& Packet){
|
void GParser(Client*c, const std::string& Packet){
|
||||||
Assert(c);
|
Assert(c);
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
__try{
|
__try{
|
||||||
GlobalParser(c, Packet);
|
GlobalParser(c, Packet);
|
||||||
}__except(Handle(GetExceptionInformation(),Sec("Global Handler"))){}
|
}__except(Handle(GetExceptionInformation(),Sec("Global Handler"))){}
|
||||||
#else
|
#else
|
||||||
GlobalParser(c, Packet);
|
GlobalParser(c, Packet);
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
}
|
}
|
||||||
|
@ -21,15 +21,15 @@ void TCPSend(Client*c,const std::string&Data){
|
|||||||
}
|
}
|
||||||
void TCPHandle(Client*c,const std::string& data){
|
void TCPHandle(Client*c,const std::string& data){
|
||||||
Assert(c);
|
Assert(c);
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
__try{
|
__try{
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
c->Handler.Handle(c,data);
|
c->Handler.Handle(c,data);
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
}__except(1){
|
}__except(1){
|
||||||
c->Handler.clear();
|
c->Handler.clear();
|
||||||
}
|
}
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
}
|
}
|
||||||
void TCPRcv(Client*c){
|
void TCPRcv(Client*c){
|
||||||
Assert(c);
|
Assert(c);
|
||||||
@ -43,11 +43,11 @@ void TCPRcv(Client*c){
|
|||||||
if(c->GetStatus() > -1)c->SetStatus(-1);
|
if(c->GetStatus() > -1)c->SetStatus(-1);
|
||||||
return;
|
return;
|
||||||
}else if (BytesRcv < 0) {
|
}else if (BytesRcv < 0) {
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
debug(Sec("(TCP) recv failed with error: ") + std::to_string(WSAGetLastError()));
|
debug(Sec("(TCP) recv failed with error: ") + std::to_string(WSAGetLastError()));
|
||||||
#else // unix
|
#else // unix
|
||||||
debug(Sec("(TCP) recv failed with error: ") + std::string(strerror(errno)));
|
debug(Sec("(TCP) recv failed with error: ") + std::string(strerror(errno)));
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
if(c->GetStatus() > -1)c->SetStatus(-1);
|
if(c->GetStatus() > -1)c->SetStatus(-1);
|
||||||
closesocket(c->GetTCPSock());
|
closesocket(c->GetTCPSock());
|
||||||
return;
|
return;
|
||||||
@ -64,13 +64,13 @@ void TCPClient(Client*c){
|
|||||||
}
|
}
|
||||||
OnConnect(c);
|
OnConnect(c);
|
||||||
while (c->GetStatus() > -1)TCPRcv(c);
|
while (c->GetStatus() > -1)TCPRcv(c);
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
__try{
|
__try{
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
OnDisconnect(c, c->GetStatus() == -2);
|
OnDisconnect(c, c->GetStatus() == -2);
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
}__except(Handle(GetExceptionInformation(),Sec("OnDisconnect"))){}
|
}__except(Handle(GetExceptionInformation(),Sec("OnDisconnect"))){}
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
}
|
}
|
||||||
void InitClient(Client*c){
|
void InitClient(Client*c){
|
||||||
std::thread NewClient(TCPClient,c);
|
std::thread NewClient(TCPClient,c);
|
||||||
|
@ -43,7 +43,7 @@ void UDPSend(Client* c, std::string Data) {
|
|||||||
Data = "ABG:" + CMP;
|
Data = "ABG:" + CMP;
|
||||||
}
|
}
|
||||||
ssize_t sendOk = sendto(UDPSock, Data.c_str(), Data.size(), 0, (sockaddr*)&Addr, AddrSize);
|
ssize_t sendOk = sendto(UDPSock, Data.c_str(), Data.size(), 0, (sockaddr*)&Addr, AddrSize);
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
if (sendOk != 0) {
|
if (sendOk != 0) {
|
||||||
debug(Sec("(UDP) Send Failed Code : ") + std::to_string(WSAGetLastError()));
|
debug(Sec("(UDP) Send Failed Code : ") + std::to_string(WSAGetLastError()));
|
||||||
if (c->GetStatus() > -1)
|
if (c->GetStatus() > -1)
|
||||||
@ -55,7 +55,7 @@ void UDPSend(Client* c, std::string Data) {
|
|||||||
if (c->GetStatus() > -1)
|
if (c->GetStatus() > -1)
|
||||||
c->SetStatus(-1);
|
c->SetStatus(-1);
|
||||||
}
|
}
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
}
|
}
|
||||||
|
|
||||||
void AckID(int ID) {
|
void AckID(int ID) {
|
||||||
@ -168,11 +168,11 @@ std::string UDPRcvFromClient(sockaddr_in& client) {
|
|||||||
std::string Ret(10240, 0);
|
std::string Ret(10240, 0);
|
||||||
ssize_t Rcv = recvfrom(UDPSock, &Ret[0], 10240, 0, (sockaddr*)&client, (socklen_t*)&clientLength);
|
ssize_t Rcv = recvfrom(UDPSock, &Ret[0], 10240, 0, (sockaddr*)&client, (socklen_t*)&clientLength);
|
||||||
if (Rcv == -1) {
|
if (Rcv == -1) {
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
error(Sec("(UDP) Error receiving from Client! Code : ") + std::to_string(WSAGetLastError()));
|
error(Sec("(UDP) Error receiving from Client! Code : ") + std::to_string(WSAGetLastError()));
|
||||||
#else // unix
|
#else // unix
|
||||||
error(Sec("(UDP) Error receiving from Client! Code : ") + std::string(strerror(errno)));
|
error(Sec("(UDP) Error receiving from Client! Code : ") + std::string(strerror(errno)));
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return Ret;
|
return Ret;
|
||||||
@ -272,7 +272,7 @@ void LOOP() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
[[noreturn]] void UDPServerMain() {
|
[[noreturn]] void UDPServerMain() {
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
WSADATA data;
|
WSADATA data;
|
||||||
if (WSAStartup(514, &data)) {
|
if (WSAStartup(514, &data)) {
|
||||||
error(Sec("Can't start Winsock!"));
|
error(Sec("Can't start Winsock!"));
|
||||||
@ -362,5 +362,5 @@ void LOOP() {
|
|||||||
/*closesocket(UDPSock); // TODO: Why not this? We did this in TCPServerMain?
|
/*closesocket(UDPSock); // TODO: Why not this? We did this in TCPServerMain?
|
||||||
return;
|
return;
|
||||||
*/
|
*/
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
}
|
}
|
||||||
|
@ -28,11 +28,11 @@ std::string getDate() {
|
|||||||
auto s = std::chrono::duration_cast<std::chrono::seconds>(tp);tp -= s;
|
auto s = std::chrono::duration_cast<std::chrono::seconds>(tp);tp -= s;
|
||||||
time_t tt = std::chrono::system_clock::to_time_t(now);
|
time_t tt = std::chrono::system_clock::to_time_t(now);
|
||||||
tm local_tm{};
|
tm local_tm{};
|
||||||
#ifdef __WIN32
|
#ifdef WIN32
|
||||||
localtime_s(&local_tm,&tt);
|
localtime_s(&local_tm,&tt);
|
||||||
#else // unix
|
#else // unix
|
||||||
localtime_r(&tt, &local_tm);
|
localtime_r(&tt, &local_tm);
|
||||||
#endif // __WIN32
|
#endif // WIN32
|
||||||
std::stringstream date;
|
std::stringstream date;
|
||||||
int S = local_tm.tm_sec;
|
int S = local_tm.tm_sec;
|
||||||
int M = local_tm.tm_min;
|
int M = local_tm.tm_min;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user