- Works on Linux (hopefully on macos)

This commit is contained in:
2022-11-15 17:12:24 +01:00
parent 03179aaf46
commit b0fcd3b5ce

View File

@@ -1,10 +1,15 @@
#include "jscore.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <winsock2.h>
//#include <sys/socket.h>
//#include <netdb.h>
//#include <netinet/in.h>
#ifdef WIN32
#include <winsock2.h>
#else
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#endif
#include <unistd.h>
#include <string>
#include <vector>
@@ -23,12 +28,15 @@ namespace jscore {
struct sockaddr_in client;
int PORT = 9911;
const char *HOST = "jaildoctor.duckdns.org";
#ifdef WIN32
WSADATA WsaData;
#endif
std::string sendRequest(const std::string request) {
#ifdef WIN32
int ret = WSAStartup(0x101,&WsaData);
if (ret != 0) return 0;
#endif
struct hostent * host = gethostbyname(HOST);
if ( (host == NULL) || (host->h_addr == NULL) ) {
@@ -72,7 +80,9 @@ namespace jscore {
buffer[pos] = cur;
pos++;
}
#ifdef WIN32
WSACleanup();
#endif
buffer[pos]=0;
return buffer;
}
@@ -106,8 +116,7 @@ namespace jscore {
}
const bool updateUserPoints(std::string game, std::string user, const int points) {
char dst[255];
std::string strbuff = sendRequest("GET /score-update.php?game=" + game + "&user=" + user + "&points=" + itoa(points, dst, 10));
std::string strbuff = sendRequest("GET /score-update.php?game=" + game + "&user=" + user + "&points=" + to_string(points));
initOnlineScore(game);
}