- Afegida la funció "init(host, port)" per a donar la opció de pasar per paràmetre el servidor que ara JDes ho te hard coded.

This commit is contained in:
2022-11-16 13:38:01 +01:00
parent a31b069cb0
commit 4666615535
2 changed files with 10 additions and 3 deletions

View File

@@ -3,7 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#else #else
#include <sys/socket.h> #include <sys/socket.h>
@@ -26,8 +26,9 @@ namespace jscore {
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0) #define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
int sock; int sock;
struct sockaddr_in client; struct sockaddr_in client;
int PORT = 9911; int PORT = 9911;
const char *HOST = "jaildoctor.duckdns.org"; string HOST = "jaildoctor.duckdns.org";
#ifdef WIN32 #ifdef WIN32
WSADATA WsaData; WSADATA WsaData;
@@ -36,6 +37,11 @@ namespace jscore {
bool jscore_error = false; bool jscore_error = false;
string error_message; string error_message;
void init(std::string host, const int port) {
PORT = port;
HOST = host;
}
void setErrorMessage(string message) { void setErrorMessage(string message) {
jscore_error = true; jscore_error = true;
error_message = message; error_message = message;
@@ -46,7 +52,7 @@ namespace jscore {
int ret = WSAStartup(0x101,&WsaData); int ret = WSAStartup(0x101,&WsaData);
if (ret != 0) return 0; if (ret != 0) return 0;
#endif #endif
struct hostent * host = gethostbyname(HOST); struct hostent * host = gethostbyname(HOST.c_str());
if ( (host == NULL) || (host->h_addr == NULL) ) { if ( (host == NULL) || (host->h_addr == NULL) ) {
setErrorMessage("Error retrieving DNS information.\n"); setErrorMessage("Error retrieving DNS information.\n");

View File

@@ -2,6 +2,7 @@
#include <string> #include <string>
namespace jscore { namespace jscore {
void init(std::string host, const int port);
const bool initOnlineScore(std::string game); const bool initOnlineScore(std::string game);
const int getNumUsers(); const int getNumUsers();
std::string getUserName(const int index); std::string getUserName(const int index);