fixed server connection

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13340 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hilnius 2013-07-25 01:07:42 +00:00
parent ddc9e8d5ba
commit 1ebfd0ada4
12 changed files with 39 additions and 6 deletions

View File

@ -147,6 +147,7 @@ void ClientLobbyRoomProtocol::newPlayer(Event* event)
if (global_id == Online::CurrentUser::acquire()->getUserID())
{
Online::CurrentUser::release();
Log::error("ClientLobbyRoomProtocol", "The server notified me that i'm a new player in the room (not normal).");
}
else if (m_setup->getProfile(race_id) == NULL || m_setup->getProfile(global_id) == NULL)
@ -218,6 +219,7 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
uint32_t global_id = event->data.gui32(8);
if (global_id == Online::CurrentUser::acquire()->getUserID())
{
Online::CurrentUser::release();
Log::info("ClientLobbyRoomProtocol", "The server accepted the connection.");
// self profile
@ -225,6 +227,7 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
profile->kart_name = "";
profile->race_id = event->data.gui8(1);
profile->user_profile = Online::CurrentUser::acquire();
Online::CurrentUser::release();
m_setup->addPlayer(profile);
// connection token
uint32_t token = event->data.gui32(3);

View File

@ -52,7 +52,9 @@ void GetPeerAddress::asynchronousUpdate()
m_request = new Online::XMLRequest();
m_request->setURL((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
m_request->setParameter("id",Online::CurrentUser::acquire()->getUserID());
Online::CurrentUser::release();
m_request->setParameter("token",Online::CurrentUser::acquire()->getToken());
Online::CurrentUser::release();
m_request->setParameter("peer_id",m_peer_id);
m_request->setParameter("action","get");

View File

@ -48,7 +48,9 @@ void HidePublicAddress::asynchronousUpdate()
m_request = new Online::XMLRequest();
m_request->setURL((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
m_request->setParameter("id",Online::CurrentUser::acquire()->getUserID());
Online::CurrentUser::release();
m_request->setParameter("token",Online::CurrentUser::acquire()->getToken());
Online::CurrentUser::release();
m_request->setParameter("action","unset");
Online::HTTPManager::get()->addRequest(m_request);

View File

@ -50,7 +50,9 @@ void QuickJoinProtocol::asynchronousUpdate()
m_request = new Online::XMLRequest();
m_request->setURL((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
m_request->setParameter("id",Online::CurrentUser::acquire()->getUserID());
Online::CurrentUser::release();
m_request->setParameter("token",Online::CurrentUser::acquire()->getToken());
Online::CurrentUser::release();
m_request->setParameter("action","quick-join");
Online::HTTPManager::get()->addRequest(m_request);

View File

@ -50,7 +50,9 @@ void RequestConnection::asynchronousUpdate()
m_request = new Online::XMLRequest();
m_request->setURL((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
m_request->setParameter("id",Online::CurrentUser::acquire()->getUserID());
Online::CurrentUser::release();
m_request->setParameter("token",Online::CurrentUser::acquire()->getToken());
Online::CurrentUser::release();
m_request->setParameter("server_id",m_server_id);
m_request->setParameter("action","request-connection");

View File

@ -116,7 +116,9 @@ void ServerLobbyRoomProtocol::update()
Online::XMLRequest* request = new Online::XMLRequest();
request->setURL((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
request->setParameter("id",Online::CurrentUser::acquire()->getUserID());
Online::CurrentUser::release();
request->setParameter("token",Online::CurrentUser::acquire()->getToken());
Online::CurrentUser::release();
request->setParameter("address",addr.ip);
request->setParameter("port",addr.port);
request->setParameter("action","poll-connection-requests");

View File

@ -49,7 +49,9 @@ void ShowPublicAddress::asynchronousUpdate()
m_request = new Online::XMLRequest();
m_request->setURL((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
m_request->setParameter("id",Online::CurrentUser::acquire()->getUserID());
Online::CurrentUser::release();
m_request->setParameter("token",Online::CurrentUser::acquire()->getToken());
Online::CurrentUser::release();
m_request->setParameter("address",addr.ip);
m_request->setParameter("port",addr.port);
m_request->setParameter("action","set");

View File

@ -104,6 +104,7 @@ void StartGameProtocol::update()
for (unsigned int i = 0; i < players.size(); i++)
{
bool is_me = (players[i]->user_profile == Online::CurrentUser::acquire());
Online::CurrentUser::release();
if (is_me)
{
NetworkPlayerProfile* profile = players[i];
@ -128,6 +129,7 @@ void StartGameProtocol::update()
for (unsigned int i = 0; i < players.size(); i++)
{
bool is_me = (players[i]->user_profile == Online::CurrentUser::acquire());
Online::CurrentUser::release();
NetworkPlayerProfile* profile = players[i];
RemoteKartInfo rki(profile->race_id, profile->kart_name,
profile->user_profile->getUserName(), profile->race_id, !is_me);

View File

@ -48,7 +48,9 @@ void StartServer::asynchronousUpdate()
m_request = new Online::XMLRequest();
m_request->setURL((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
m_request->setParameter("id",Online::CurrentUser::acquire()->getUserID());
Online::CurrentUser::release();
m_request->setParameter("token",Online::CurrentUser::acquire()->getToken());
Online::CurrentUser::release();
m_request->setParameter("address",addr.ip);
m_request->setParameter("port",addr.port);
m_request->setParameter("max_players",UserConfigParams::m_server_max_players);

View File

@ -48,7 +48,9 @@ void StopServer::asynchronousUpdate()
m_request = new Online::XMLRequest();
m_request->setURL((std::string)UserConfigParams::m_server_multiplayer + "address-management.php");
m_request->setParameter("id",Online::CurrentUser::acquire()->getUserID());
Online::CurrentUser::release();
m_request->setParameter("token",Online::CurrentUser::acquire()->getToken());
Online::CurrentUser::release();
m_request->setParameter("address",addr.ip);
m_request->setParameter("port",addr.port);
m_request->setParameter("action","stop-server");

View File

@ -221,7 +221,6 @@ namespace Online{
request->setParameter("token", m_token);
request->setParameter("id", m_id);
request->setParameter("server_id", server_id);
HTTPManager::get()->addRequest(request);
return request;
}

View File

@ -231,20 +231,33 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const
//FIXME temporary and the request join + join sequence should be placed in one method somewhere
// refresh server list
Online::ServersManager::RefreshRequest* request = ServersManager::acquire()->refreshRequest();
//Online::HTTPManager::get()->synchronousRequest(request);
request->execute();
ServersManager::release();
Online::HTTPManager::get()->synchronousRequest(request);
delete request;
// select first one
Server * server = ServersManager::acquire()->getQuickPlay();
if (Online::CurrentUser::acquire()->requestServerJoin( server->getServerId()))
ServersManager::release();
Online::CurrentUser::ServerJoinRequest* request2 = Online::CurrentUser::acquire()->requestServerJoin( server->getServerId());
Online::CurrentUser::release();
if (request2)
{
StateManager::get()->pushScreen(NetworkingLobby::getInstance());
Online::HTTPManager::get()->synchronousRequest(request2);
if (request2->isSuccess())
{
delete request;
StateManager::get()->pushScreen(NetworkingLobby::getInstance());
ProtocolManager::getInstance()->requestStart(new ConnectToServer(server->getServerId()));
}
else
{
sfx_manager->quickSound( "anvil" );
}
}
else
{
sfx_manager->quickSound( "anvil" );
}
ProtocolManager::getInstance()->requestStart(new ConnectToServer(server->getServerId()));
}
} // eventCallback