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