Añadida la opción para pasar por parametro el servidor y puerto online
This commit is contained in:
@@ -19,4 +19,5 @@ input1=1
|
|||||||
## ONLINE OPTIONS
|
## ONLINE OPTIONS
|
||||||
enabled=false
|
enabled=false
|
||||||
server=
|
server=
|
||||||
|
port=
|
||||||
jailerID=
|
jailerID=
|
||||||
|
|||||||
@@ -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");
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ struct online_t
|
|||||||
{
|
{
|
||||||
bool enabled; // Indica si se quiere usar el modo online o no
|
bool enabled; // Indica si se quiere usar el modo online o no
|
||||||
std::string server; // Servidor para los servicios online
|
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 gameID; // Identificador del juego para los servicios online
|
||||||
std::string jailerID; // Identificador del jugador para los servicios online
|
std::string jailerID; // Identificador del jugador para los servicios online
|
||||||
int score; // Puntuación almacenada online
|
int score; // Puntuación almacenada online
|
||||||
|
|||||||
@@ -454,6 +454,7 @@ bool Director::saveConfigFile()
|
|||||||
file << "\n## ONLINE OPTIONS\n";
|
file << "\n## ONLINE OPTIONS\n";
|
||||||
file << "enabled=" + boolToString(options->online.enabled) + "\n";
|
file << "enabled=" + boolToString(options->online.enabled) + "\n";
|
||||||
file << "server=" + options->online.server + "\n";
|
file << "server=" + options->online.server + "\n";
|
||||||
|
file << "port=" + std::to_string(options->online.port) + "\n";
|
||||||
file << "jailerID=" + options->online.jailerID + "\n";
|
file << "jailerID=" + options->online.jailerID + "\n";
|
||||||
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
@@ -542,6 +543,9 @@ void Director::initOnline()
|
|||||||
else
|
else
|
||||||
{ // Jailer ID iniciado
|
{ // Jailer ID iniciado
|
||||||
|
|
||||||
|
// Establece el servidor y el puerto
|
||||||
|
jscore::init(options->online.server, options->online.port);
|
||||||
|
|
||||||
// Obtiene la información online
|
// Obtiene la información online
|
||||||
if (jscore::initOnlineScore(options->online.gameID))
|
if (jscore::initOnlineScore(options->online.gameID))
|
||||||
{
|
{
|
||||||
@@ -680,6 +684,11 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
|
|||||||
options->online.server = value;
|
options->online.server = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (var == "port")
|
||||||
|
{
|
||||||
|
options->online.port = std::stoi(value);
|
||||||
|
}
|
||||||
|
|
||||||
else if (var == "jailerID")
|
else if (var == "jailerID")
|
||||||
{
|
{
|
||||||
options->online.jailerID = value;
|
options->online.jailerID = value;
|
||||||
|
|||||||
Reference in New Issue
Block a user