Rename some API calls

This commit is contained in:
Daniel Butum 2014-08-05 19:12:56 +03:00
parent 62e6a2d733
commit c6c0c6e590
13 changed files with 67 additions and 32 deletions

View File

@ -62,10 +62,12 @@ void GetPeerAddress::asynchronousUpdate()
{
TransportAddress* addr = static_cast<TransportAddress*>(m_callback_object);
result->get("ip", &addr->ip);
if (addr->ip == NetworkManager::getInstance()->getPublicAddress().ip)
result->get("private_port", &addr->port);
else
result->get("port", &addr->port);
Log::debug("GetPeerAddress", "Address gotten successfully.");
}
else

View File

@ -83,6 +83,7 @@ void RequestConnection::asynchronousUpdate()
{
if (!m_request->isDone())
return;
const XMLNode * result = m_request->getXMLData();
std::string rec_success;

View File

@ -193,6 +193,7 @@ void ServerLobbyRoomProtocol::checkIncomingConnectionRequests()
const XMLNode * result = request->getXMLData();
std::string rec_success;
if(result->get("success", &rec_success))
{
if(rec_success == "yes")

View File

@ -42,7 +42,7 @@ void StartServer::asynchronousUpdate()
{
TransportAddress addr = NetworkManager::getInstance()->getPublicAddress();
m_request = new Online::XMLRequest();
PlayerManager::setUserDetails(m_request, "start-server", Online::API::SERVER_PATH);
PlayerManager::setUserDetails(m_request, "start", Online::API::SERVER_PATH);
m_request->addParameter("address", addr.ip);
m_request->addParameter("port", addr.port);

View File

@ -47,7 +47,7 @@ void StopServer::asynchronousUpdate()
{
TransportAddress addr = NetworkManager::getInstance()->getPublicAddress();
m_request = new Online::XMLRequest();
PlayerManager::setUserDetails(m_request, "stop-server", Online::API::SERVER_PATH);
PlayerManager::setUserDetails(m_request, "stop", Online::API::SERVER_PATH);
m_request->addParameter("address", addr.ip);
m_request->addParameter("port", addr.port);

View File

@ -98,7 +98,7 @@ namespace Online
// ------------------------------------------------------------------------
/** Returns true if there was an error downloading the file. */
bool hadDownloadError() const { return m_curl_code!=CURLE_OK; }
bool hadDownloadError() const { return m_curl_code != CURLE_OK; }
// ------------------------------------------------------------------------
/** Returns the curl error message if an error has occurred.

View File

@ -160,6 +160,7 @@ namespace Online
}
}
}
if (login)
{
if(isSuccess())

View File

@ -77,7 +77,7 @@ namespace Online
if(StkTime::getRealTime() - m_last_load_time.getAtomic() > SERVER_REFRESH_INTERVAL)
{
request = new RefreshRequest();
request->setApiURL(API::USER_PATH, "get_server_list");
request->setApiURL(API::SERVER_PATH, "get-all");
if (request_now)
RequestManager::get()->addRequest(request);

View File

@ -139,7 +139,7 @@ void CreateServerScreen::serverCreationRequest()
{
m_server_creation_request = new ServerCreationRequest();
PlayerManager::setUserDetails(m_server_creation_request, "create_server");
PlayerManager::setUserDetails(m_server_creation_request, "create", Online::API::SERVER_PATH);
m_server_creation_request->addParameter("name", name);
m_server_creation_request->addParameter("max_players", max_players);
m_server_creation_request->queue();

View File

@ -38,8 +38,7 @@ using namespace Online;
/** Creates a modal dialog with given percentage of screen width and height
*/
ChangePasswordDialog::ChangePasswordDialog()
: ModalDialog(0.8f,0.7f)
ChangePasswordDialog::ChangePasswordDialog() : ModalDialog(0.8f, 0.7f)
{
m_self_destroy = false;
m_success = false;
@ -49,15 +48,15 @@ ChangePasswordDialog::ChangePasswordDialog()
m_current_password_widget = getWidget<TextBoxWidget>("current_password");
assert(m_current_password_widget != NULL);
m_current_password_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
m_current_password_widget->setPasswordBox(true,L'*');
m_current_password_widget->setPasswordBox(true, L'*');
m_new_password1_widget = getWidget<TextBoxWidget>("new_password1");
assert(m_new_password1_widget != NULL);
m_new_password1_widget->setPasswordBox(true,L'*');
m_new_password1_widget->setPasswordBox(true, L'*');
m_new_password2_widget = getWidget<TextBoxWidget>("new_password2");
assert(m_new_password2_widget != NULL);
m_new_password2_widget->setPasswordBox(true,L'*');
m_new_password2_widget->setPasswordBox(true, L'*');
m_info_widget = getWidget<LabelWidget>("info");
assert(m_info_widget != NULL);
@ -71,7 +70,6 @@ ChangePasswordDialog::ChangePasswordDialog()
} // ChangePasswordDialog
// ----------------------------------------------------------------------------
ChangePasswordDialog::~ChangePasswordDialog()
{
} // ~ChangePasswordDialog
@ -93,6 +91,7 @@ void ChangePasswordDialog::changePassword(const stringw &current_password,
virtual void callback()
{
if (!GUIEngine::ModalDialog::isADialogActive()) return;
ChangePasswordDialog * dialog =
dynamic_cast<ChangePasswordDialog*>(GUIEngine::ModalDialog
::getCurrent());
@ -111,8 +110,9 @@ void ChangePasswordDialog::changePassword(const stringw &current_password,
// ------------------------------------------------------------------------
ChangePasswordRequest * request = new ChangePasswordRequest();
PlayerManager::setUserDetails(request, "change_password");
PlayerManager::setUserDetails(request, "change-password");
request->addParameter("current", current_password);
// The server code expects two passwords (and verifies again that they
// are identical), so send the passwod twice.
request->addParameter("new1", new_password);
@ -126,6 +126,7 @@ void ChangePasswordDialog::submit()
const stringw current_password = m_current_password_widget->getText().trim();
const stringw new_password1 = m_new_password1_widget->getText().trim();
const stringw new_password2 = m_new_password2_widget->getText().trim();
if (current_password.size() < 8 || current_password.size() > 30)
{
sfx_manager->quickSound("anvil");
@ -149,6 +150,7 @@ void ChangePasswordDialog::submit()
{
m_options_widget->setDeactivated();
m_info_widget->setDefaultColor();
// We don't need to use password 2 anymore, it was already confirmed
// that both passwords are identical.
changePassword(current_password, new_password1);
@ -159,42 +161,45 @@ void ChangePasswordDialog::submit()
GUIEngine::EventPropagation
ChangePasswordDialog::processEvent(const std::string& eventSource)
{
if (eventSource == m_options_widget->m_properties[PROP_ID])
{
const std::string& selection =
m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if (selection == m_cancel_widget->m_properties[PROP_ID])
{
m_self_destroy = true;
return GUIEngine::EVENT_BLOCK;
}
else if(selection == m_submit_widget->m_properties[PROP_ID])
{
submit();
return GUIEngine::EVENT_BLOCK;
}
}
return GUIEngine::EVENT_LET;
} // processEvent
// ----------------------------------------------------------------------------
void ChangePasswordDialog::onEnterPressedInternal()
{
const int playerID = PLAYER_ID_GAME_MASTER;
if (GUIEngine::isFocusedForPlayer(m_options_widget, playerID))
return;
if (m_submit_widget->isActivated())
submit();
} // onEnterPressedInternal
// ----------------------------------------------------------------------------
bool ChangePasswordDialog::onEscapePressed()
{
if (m_cancel_widget->isActivated())
m_self_destroy = true;
return false;
} // onEscapePressed
@ -222,12 +227,15 @@ void ChangePasswordDialog::error(const irr::core::stringw & error)
} // error
// -----------------------------------------------------------------------------
void ChangePasswordDialog::onUpdate(float dt)
{
if(!m_options_widget->isActivated())
m_info_widget->setText(StringUtils::loadingDots(_("Validating info")),
false );
{
m_info_widget->setText(
StringUtils::loadingDots(_("Validating info")),
false
);
}
// It's unsafe to delete from inside the event handler so we do it here
if (m_self_destroy)

View File

@ -129,7 +129,7 @@ void RecoveryDialog::processInput()
m_recovery_request = new XMLRequest();
// This function also works when the current user is not logged in
PlayerManager::setUserDetails(m_recovery_request, "recovery");
PlayerManager::setUserDetails(m_recovery_request, "recover");
m_recovery_request->addParameter("username", username);
m_recovery_request->addParameter("email", email );
m_recovery_request->queue();
@ -144,10 +144,13 @@ GUIEngine::EventPropagation
{
std::string selection;
if (eventSource == m_options_widget->m_properties[PROP_ID])
selection =
m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
{
selection = m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
}
else
{
selection = eventSource;
}
if (selection == m_cancel_widget->m_properties[PROP_ID])
{
@ -167,9 +170,9 @@ GUIEngine::EventPropagation
*/
void RecoveryDialog::onEnterPressedInternal()
{
if (GUIEngine::isFocusedForPlayer(m_options_widget, PLAYER_ID_GAME_MASTER))
return;
if (m_submit_widget->isActivated())
processInput();
}
@ -196,15 +199,19 @@ void RecoveryDialog::onUpdate(float dt)
m_info_widget->setText(m_recovery_request->getInfo(), false);
m_options_widget->setActivated();
}
delete m_recovery_request;
m_recovery_request = NULL;
}
else
{
m_info_widget->setText(StringUtils::loadingDots(_("Validating info")),
false);
m_info_widget->setText(
StringUtils::loadingDots(_("Validating info")),
false
);
}
}
// It's unsafe to delete from inside the event handler so we do it here
if (m_self_destroy)
ModalDialog::dismiss();

View File

@ -59,7 +59,6 @@ VoteDialog::VoteDialog(const std::string & addon_id)
m_options_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
m_fetch_vote_request = new XMLRequest();
PlayerManager::setUserDetails(m_fetch_vote_request, "get-addon-vote");
m_fetch_vote_request->addParameter("addonid", addon_id.substr(6));
@ -146,12 +145,15 @@ GUIEngine::EventPropagation VoteDialog::processEvent(const std::string& event)
{
const std::string& selection =
m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if (selection == m_cancel_widget->m_properties[PROP_ID])
{
m_self_destroy = true;
return GUIEngine::EVENT_BLOCK;
}
}
return GUIEngine::EVENT_LET;
} // processEvent
@ -165,16 +167,21 @@ void VoteDialog::updateFetchVote()
if (!m_fetch_vote_request->isDone())
{
// request still pending
m_info_widget->setText(StringUtils::loadingDots(_("Fetching last vote")),
false );
m_info_widget->setText(
StringUtils::loadingDots(_("Fetching last vote")),
false
);
return;
} // !isDone
if (m_fetch_vote_request->isSuccess())
{
m_info_widget->setDefaultColor();
std::string voted("");
m_info_widget->setDefaultColor();
m_fetch_vote_request->getXMLData()->get("voted", &voted);
if (voted == "yes")
{
float rating;

View File

@ -139,25 +139,30 @@ void OnlineUserSearch::parseResult(const XMLNode * input)
{
m_users.clear();
const XMLNode * users_xml = input->getNode("users");
// Try to reserve enough cache space for all found entries.
unsigned int n = ProfileManager::get()
->guaranteeCacheSize(users_xml->getNumNodes());
if (n >= users_xml->getNumNodes())
{
n = users_xml->getNumNodes();
}
else
{
Log::warn("OnlineSearch",
"Too many results found, only %d will be displayed.", n);
}
for (unsigned int i = 0; i < n; i++)
{
OnlineProfile * profile = new OnlineProfile(users_xml->getNode(i));
// The id must be pushed before adding it to the cache, since
// the cache might merge the new data with an existing entry
m_users.push_back(profile->getID());
ProfileManager::get()->addToCache(profile);
}
} // for i = 0 ... number of display users
} // parseResult
// ----------------------------------------------------------------------------
@ -166,17 +171,19 @@ void OnlineUserSearch::parseResult(const XMLNode * input)
void OnlineUserSearch::showList()
{
m_user_list_widget->clear();
for (unsigned int i=0; i < m_users.size(); i++)
for (unsigned int i = 0; i < m_users.size(); i++)
{
std::vector<GUIEngine::ListWidget::ListCell> row;
OnlineProfile * profile = ProfileManager::get()->getProfileByID(m_users[i]);
// This could still happen if something pushed results out of the cache.
if (!profile)
{
Log::warn("OnlineSearch", "User %d not in cache anymore, ignored.",
m_users[i]);
Log::warn("OnlineSearch", "User %d not in cache anymore, ignored.", m_users[i]);
continue;
}
row.push_back(GUIEngine::ListWidget::ListCell(profile->getUserName(),-1,3));
m_user_list_widget->addItem("user", row);
}
@ -267,6 +274,7 @@ void OnlineUserSearch::onUpdate(float dt)
sfx_manager->quickSound( "anvil" );
new MessageDialog(m_search_request->getInfo());
}
delete m_search_request;
m_search_request = NULL;
m_back_widget->setActivated();