Exemple #1
0
bool CMenuLogin::start(CGameCore *gameCore)
{
	_gameCore = gameCore;

	_gameCore->getAllManagers(_dispGrafico, _dispAudio, _gerEventos, _gerCena, _gerVideo, _gerHud, _gameConfig);

	_gameCore->playMusic(pathBackgroundSound[MM_LOGIN]);

	_myID = _nextID = MN_LOGIN;

	_menuFlag[HUDUPDATED] = false;

	_loadingStage = LS_PERSONAGENS;


	std::string line;
	size_t separ_pos;

	ifstream serverFile (pathServerSetup);
	
	if (serverFile.is_open())
	{
		//while (!serverFile.eof() )
		//{
			getline (serverFile, line);
		//}
		serverFile.close();

		separ_pos = line.find_first_of(":");
		
		_gameCore->SERVERHOST = line.substr(0, separ_pos);
		_gameCore->SERVERPORT = atoi( (line.substr(separ_pos+1, line.size())).c_str() );		
		/*
		cout << "\n" << _gameCore->SERVERHOST << endl;
		cout << "\n" << _gameCore->SERVERPORT << endl;
		system("pause");*/
	}
	else
	{
		cout << "\nFalha ao abrir o arquivo servidor.txt" << endl;
		system("pause");
	}

	return true;
}
Exemple #2
0
bool Game::connect(sf::TcpSocket* socket)
{
    this->socket = socket;
    localEntityID = -1;

    std::vector<std::string> signUpCreds, loginCreds, serverCreds;
    std::ifstream signUpFile("signup.txt");
    std::ifstream loginFile("login.txt");
    std::ifstream serverFile("server.txt");
    bool clientSignUp = signUpFile;

    if(signUpFile.is_open() && clientSignUp)
    {
        std::string line;
        while(std::getline(signUpFile, line))
        {
            signUpCreds.push_back(line);
        }
        signUpFile.close();
    }

    if(loginFile.is_open() && !clientSignUp)
    {
        std::string line;
        while(std::getline(loginFile, line))
        {
            loginCreds.push_back(line);
        }
        loginFile.close();
    }

    if(serverFile.is_open())
    {
        std::string line;
        while(std::getline(serverFile, line))
        {
            serverCreds.push_back(line);
        }
        serverFile.close();
    }

    serverIP = serverCreds[0];

    if(socket->connect(serverIP, 9756, sf::seconds(10)) != sf::Socket::Done)
        return false;

    if(clientSignUp)
    {
        SignUpPacket signUp;
        signUp.username = signUpCreds[0];
        signUp.password = signUpCreds[1];
        signUp.email = signUpCreds[2];

        sf::Packet out;
        out << signUp;
        socket->send(out);
    }
    else
    {
        LoginPacket login;
        login.username = loginCreds[0];
        login.password = loginCreds[1];

        sf::Packet out;
        out << login;
        socket->send(out);
    }

    connected = true;
    hbt.start();
    return true;
}