Añadida la opción para pasar por parametro el servidor y puerto online

This commit is contained in:
2022-11-16 13:58:09 +01:00
parent 5380ea6bc5
commit 7b00dc0303
5 changed files with 20 additions and 2 deletions

View File

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

View File

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

View File

@@ -88,6 +88,7 @@ struct online_t
{
bool enabled; // Indica si se quiere usar el modo online o no
std::string server; // Servidor para los servicios online
int port; // Puerto del servidor
std::string gameID; // Identificador del juego para los servicios online
std::string jailerID; // Identificador del jugador para los servicios online
int score; // Puntuación almacenada online