Added comments, minor code changes only.
This commit is contained in:
parent
d734d310ab
commit
42b72cc2a8
@ -32,252 +32,258 @@
|
||||
|
||||
using namespace Online;
|
||||
|
||||
namespace Online{
|
||||
namespace Online
|
||||
{
|
||||
|
||||
Profile::RelationInfo::RelationInfo(const irr::core::stringw & date,
|
||||
bool is_online, bool is_pending,
|
||||
bool is_asker)
|
||||
{
|
||||
m_date = date;
|
||||
m_is_online = is_online;
|
||||
m_is_pending = is_pending;
|
||||
m_is_asker = is_asker;
|
||||
} // RelationInfo::RelationInfo
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Profile::RelationInfo::setOnline(bool online)
|
||||
{
|
||||
m_is_online = online;
|
||||
if (m_is_online)
|
||||
m_is_pending = false;
|
||||
}
|
||||
|
||||
Profile::RelationInfo::RelationInfo(const irr::core::stringw & date, bool is_online, bool is_pending, bool is_asker)
|
||||
// ============================================================================
|
||||
/** Constructor for a new profile.
|
||||
*/
|
||||
Profile::Profile(const uint32_t & userid,
|
||||
const irr::core::stringw & username,
|
||||
bool is_current_user)
|
||||
{
|
||||
m_state = S_READY;
|
||||
m_cache_bit = true;
|
||||
m_id = userid;
|
||||
m_is_current_user = is_current_user;
|
||||
m_username = username;
|
||||
m_has_fetched_friends = false;
|
||||
m_has_fetched_achievements = false;
|
||||
m_relation_info = NULL;
|
||||
m_is_friend = false;
|
||||
} // Profile
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
Profile::Profile(const XMLNode * xml, ConstructorType type)
|
||||
{
|
||||
m_relation_info = NULL;
|
||||
m_is_friend = false;
|
||||
if (type == C_RELATION_INFO)
|
||||
{
|
||||
m_date = date;
|
||||
m_is_online = is_online;
|
||||
m_is_pending = is_pending;
|
||||
m_is_asker = is_asker;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
void Profile::RelationInfo::setOnline(bool online)
|
||||
{
|
||||
m_is_online = online;
|
||||
if(m_is_online)
|
||||
m_is_pending = false;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
Profile::Profile( const uint32_t & userid,
|
||||
const irr::core::stringw & username,
|
||||
bool is_current_user)
|
||||
{
|
||||
m_state = S_READY;
|
||||
m_cache_bit = true;
|
||||
m_id = userid;
|
||||
m_is_current_user = is_current_user;
|
||||
m_username = username;
|
||||
m_has_fetched_friends = false;
|
||||
m_has_fetched_achievements = false;
|
||||
m_relation_info = NULL;
|
||||
m_is_friend = false;
|
||||
}
|
||||
|
||||
Profile::Profile(const XMLNode * xml, ConstructorType type)
|
||||
{
|
||||
m_relation_info = NULL;
|
||||
m_is_friend = false;
|
||||
if(type == C_RELATION_INFO){
|
||||
irr::core::stringw date("");
|
||||
xml->get("date", &date);
|
||||
std::string is_pending_string("");
|
||||
xml->get("is_pending", &is_pending_string);
|
||||
bool is_pending = is_pending_string == "yes";
|
||||
bool is_asker(false);
|
||||
bool is_online(false);
|
||||
if(is_pending)
|
||||
{
|
||||
std::string is_asker_string("");
|
||||
xml->get("is_asker", &is_asker_string);
|
||||
is_asker = is_asker_string == "yes";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string is_online_string("");
|
||||
xml->get("online", &is_online_string);
|
||||
is_online = is_online_string == "yes";
|
||||
m_is_friend = true;
|
||||
}
|
||||
m_relation_info = new RelationInfo(date, is_online, is_pending, is_asker);
|
||||
xml = xml->getNode("user");
|
||||
}
|
||||
|
||||
xml->get("id", &m_id);
|
||||
xml->get("user_name", &m_username);
|
||||
m_cache_bit = true;
|
||||
m_has_fetched_friends = false;
|
||||
m_has_fetched_achievements = false;
|
||||
m_is_current_user = (m_id == CurrentUser::get()->getID());
|
||||
m_state = S_READY;
|
||||
}
|
||||
// ============================================================================
|
||||
Profile::~Profile()
|
||||
{
|
||||
delete m_relation_info;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
void Profile::fetchAchievements()
|
||||
{
|
||||
assert(CurrentUser::get()->isRegisteredUser());
|
||||
if(m_has_fetched_achievements || m_is_current_user)
|
||||
return;
|
||||
m_state = S_FETCHING;
|
||||
requestAchievements();
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
void Profile::achievementsCallback(const XMLNode * input)
|
||||
{
|
||||
m_achievements.clear();
|
||||
std::string achieved_string("");
|
||||
if(input->get("achieved", &achieved_string) == 1)
|
||||
irr::core::stringw date("");
|
||||
xml->get("date", &date);
|
||||
std::string is_pending_string("");
|
||||
bool is_pending = false;
|
||||
xml->get("is_pending", &is_pending);
|
||||
bool is_asker = false;
|
||||
bool is_online = false;
|
||||
if (is_pending)
|
||||
{
|
||||
m_achievements = StringUtils::splitToUInt(achieved_string, ' ');
|
||||
xml->get("is_asker", &is_asker);
|
||||
}
|
||||
m_has_fetched_achievements = true;
|
||||
m_state = S_READY;
|
||||
Log::info("test","tit");
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
void Profile::requestAchievements()
|
||||
{
|
||||
assert(CurrentUser::get()->isRegisteredUser() && !m_is_current_user);
|
||||
AchievementsRequest * request = new AchievementsRequest();
|
||||
request->setServerURL("client-user.php");
|
||||
request->addParameter("action","get-achievements");
|
||||
request->addParameter("token", CurrentUser::get()->getToken());
|
||||
request->addParameter("userid", CurrentUser::get()->getID());
|
||||
request->addParameter("visitingid", m_id);
|
||||
RequestManager::get()->addRequest(request);
|
||||
}
|
||||
|
||||
void Profile::AchievementsRequest::callback()
|
||||
{
|
||||
uint32_t user_id(0);
|
||||
getXMLData()->get("visitingid", &user_id);
|
||||
if( ProfileManager::get()->getProfileByID(user_id) != NULL )
|
||||
ProfileManager::get()->getProfileByID(user_id)
|
||||
->achievementsCallback(getXMLData());
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
void Profile::fetchFriends()
|
||||
{
|
||||
assert(CurrentUser::get()->isRegisteredUser());
|
||||
if(m_has_fetched_friends)
|
||||
return;
|
||||
m_state = S_FETCHING;
|
||||
requestFriendsList();
|
||||
}
|
||||
// ============================================================================
|
||||
void Profile::friendsListCallback(const XMLNode * input)
|
||||
{
|
||||
const XMLNode * friends_xml = input->getNode("friends");
|
||||
m_friends.clear();
|
||||
for (unsigned int i = 0; i < friends_xml->getNumNodes(); i++)
|
||||
else
|
||||
{
|
||||
Profile * profile;
|
||||
if(m_is_current_user)
|
||||
{
|
||||
profile = new Profile(friends_xml->getNode(i) , C_RELATION_INFO);
|
||||
ProfileManager::get()->addPersistent(profile);
|
||||
}
|
||||
else
|
||||
{
|
||||
profile = new Profile(friends_xml->getNode(i)->getNode("user"), C_DEFAULT);
|
||||
ProfileManager::get()->addToCache(profile);
|
||||
}
|
||||
m_friends.push_back(profile->getID());
|
||||
xml->get("online", &is_online);
|
||||
m_is_friend = true;
|
||||
}
|
||||
m_has_fetched_friends = true;
|
||||
m_state = S_READY;
|
||||
m_relation_info = new RelationInfo(date, is_online, is_pending,
|
||||
is_asker);
|
||||
xml = xml->getNode("user");
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
xml->get("id", &m_id );
|
||||
xml->get("user_name", &m_username);
|
||||
m_cache_bit = true;
|
||||
m_has_fetched_friends = false;
|
||||
m_has_fetched_achievements = false;
|
||||
m_is_current_user = (m_id == CurrentUser::get()->getID());
|
||||
m_state = S_READY;
|
||||
} // Profile(XMLNode)
|
||||
|
||||
void Profile::requestFriendsList()
|
||||
// ----------------------------------------------------------------------------
|
||||
Profile::~Profile()
|
||||
{
|
||||
delete m_relation_info;
|
||||
} // ~Profile
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Profile::fetchAchievements()
|
||||
{
|
||||
assert(CurrentUser::get()->isRegisteredUser());
|
||||
if (m_has_fetched_achievements || m_is_current_user)
|
||||
return;
|
||||
m_state = S_FETCHING;
|
||||
|
||||
AchievementsRequest * request = new AchievementsRequest();
|
||||
request->setServerURL("client-user.php");
|
||||
request->addParameter("action", "get-achievements");
|
||||
request->addParameter("token", CurrentUser::get()->getToken());
|
||||
request->addParameter("userid", CurrentUser::get()->getID());
|
||||
request->addParameter("visitingid", m_id);
|
||||
RequestManager::get()->addRequest(request);
|
||||
} // fetchAchievements
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Profile::AchievementsRequest::callback()
|
||||
{
|
||||
uint32_t user_id(0);
|
||||
getXMLData()->get("visitingid", &user_id);
|
||||
if (ProfileManager::get()->getProfileByID(user_id) != NULL)
|
||||
ProfileManager::get()->getProfileByID(user_id)
|
||||
->achievementsCallback(getXMLData());
|
||||
} // AchievementsRequest::callback
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Profile::achievementsCallback(const XMLNode * input)
|
||||
{
|
||||
m_achievements.clear();
|
||||
std::string achieved_string("");
|
||||
if (input->get("achieved", &achieved_string) == 1)
|
||||
{
|
||||
assert(CurrentUser::get()->isRegisteredUser());
|
||||
FriendsListRequest * request = new FriendsListRequest();
|
||||
request->setServerURL("client-user.php");
|
||||
request->addParameter("action","get-friends-list");
|
||||
request->addParameter("token", CurrentUser::get()->getToken());
|
||||
request->addParameter("userid", CurrentUser::get()->getID());
|
||||
request->addParameter("visitingid", m_id);
|
||||
RequestManager::get()->addRequest(request);
|
||||
m_achievements = StringUtils::splitToUInt(achieved_string, ' ');
|
||||
}
|
||||
m_has_fetched_achievements = true;
|
||||
m_state = S_READY;
|
||||
Log::info("test", "tit");
|
||||
} // achievementsCallback
|
||||
|
||||
void Profile::FriendsListRequest::callback()
|
||||
// ----------------------------------------------------------------------------
|
||||
void Profile::fetchFriends()
|
||||
{
|
||||
assert(CurrentUser::get()->isRegisteredUser());
|
||||
if (m_has_fetched_friends)
|
||||
return;
|
||||
m_state = S_FETCHING;
|
||||
requestFriendsList();
|
||||
} // fetchFriends
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Profile::friendsListCallback(const XMLNode * input)
|
||||
{
|
||||
const XMLNode * friends_xml = input->getNode("friends");
|
||||
m_friends.clear();
|
||||
for (unsigned int i = 0; i < friends_xml->getNumNodes(); i++)
|
||||
{
|
||||
uint32_t user_id(0);
|
||||
getXMLData()->get("visitingid", &user_id);
|
||||
if( ProfileManager::get()->getProfileByID(user_id) != NULL )
|
||||
ProfileManager::get()->getProfileByID(user_id)
|
||||
->friendsListCallback(getXMLData());
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
void Profile::removeFriend( const uint32_t id)
|
||||
{
|
||||
assert (m_has_fetched_friends);
|
||||
std::vector<uint32_t>::iterator iter;
|
||||
for (iter = m_friends.begin(); iter != m_friends.end();)
|
||||
Profile * profile;
|
||||
if (m_is_current_user)
|
||||
{
|
||||
if (*iter == id)
|
||||
{
|
||||
m_friends.erase(iter++);
|
||||
break;
|
||||
}
|
||||
else
|
||||
++iter;
|
||||
profile = new Profile(friends_xml->getNode(i), C_RELATION_INFO);
|
||||
ProfileManager::get()->addPersistent(profile);
|
||||
}
|
||||
}
|
||||
// ============================================================================
|
||||
|
||||
void Profile::addFriend( const uint32_t id)
|
||||
{
|
||||
assert (m_has_fetched_friends);
|
||||
for(unsigned int i=0; i< m_friends.size(); i++)
|
||||
if(m_friends[i] == id)
|
||||
return;
|
||||
m_friends.push_back(id);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
void Profile::deleteRelationalInfo()
|
||||
{
|
||||
delete m_relation_info;
|
||||
m_relation_info = NULL;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
const std::vector<uint32_t> & Profile::getFriends()
|
||||
{
|
||||
assert (m_has_fetched_friends && m_state == S_READY);
|
||||
return m_friends;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
const std::vector<uint32_t> & Profile::getAchievements()
|
||||
{
|
||||
assert (m_has_fetched_achievements && m_state == S_READY && !m_is_current_user);
|
||||
return m_achievements;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
void Profile::merge(Profile * profile)
|
||||
{
|
||||
assert (profile != NULL);
|
||||
if(!this->m_has_fetched_friends && profile->m_has_fetched_friends)
|
||||
this->m_friends = profile->m_friends;
|
||||
if(!this->m_has_fetched_achievements && profile->m_has_fetched_achievements)
|
||||
this->m_achievements = profile->m_achievements;
|
||||
if(this->m_relation_info == NULL && profile->m_relation_info != NULL)
|
||||
else
|
||||
{
|
||||
this->m_relation_info = profile->m_relation_info;
|
||||
profile->m_relation_info = NULL; //We don't want the destructor of the profile instance to destroy the relation info
|
||||
profile = new Profile(friends_xml->getNode(i)->getNode("user"), C_DEFAULT);
|
||||
ProfileManager::get()->addToCache(profile);
|
||||
}
|
||||
delete profile;
|
||||
m_friends.push_back(profile->getID());
|
||||
}
|
||||
m_has_fetched_friends = true;
|
||||
m_state = S_READY;
|
||||
} // friendsListCallback
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void Profile::requestFriendsList()
|
||||
{
|
||||
assert(CurrentUser::get()->isRegisteredUser());
|
||||
FriendsListRequest * request = new FriendsListRequest();
|
||||
request->setServerURL("client-user.php");
|
||||
request->addParameter("action", "get-friends-list");
|
||||
request->addParameter("token", CurrentUser::get()->getToken());
|
||||
request->addParameter("userid", CurrentUser::get()->getID());
|
||||
request->addParameter("visitingid", m_id);
|
||||
RequestManager::get()->addRequest(request);
|
||||
} // requestFriendsList
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Profile::FriendsListRequest::callback()
|
||||
{
|
||||
uint32_t user_id(0);
|
||||
getXMLData()->get("visitingid", &user_id);
|
||||
if (ProfileManager::get()->getProfileByID(user_id) != NULL)
|
||||
ProfileManager::get()->getProfileByID(user_id)
|
||||
->friendsListCallback(getXMLData());
|
||||
} // FriendsListRequest::callback
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void Profile::removeFriend(const uint32_t id)
|
||||
{
|
||||
assert(m_has_fetched_friends);
|
||||
std::vector<uint32_t>::iterator iter;
|
||||
for (iter = m_friends.begin(); iter != m_friends.end();)
|
||||
{
|
||||
if (*iter == id)
|
||||
{
|
||||
m_friends.erase(iter++);
|
||||
break;
|
||||
}
|
||||
else
|
||||
++iter;
|
||||
}
|
||||
} // removeFriend
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void Profile::addFriend(const uint32_t id)
|
||||
{
|
||||
assert(m_has_fetched_friends);
|
||||
for (unsigned int i = 0; i < m_friends.size(); i++)
|
||||
if (m_friends[i] == id)
|
||||
return;
|
||||
m_friends.push_back(id);
|
||||
} // addFriend
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void Profile::deleteRelationalInfo()
|
||||
{
|
||||
delete m_relation_info;
|
||||
m_relation_info = NULL;
|
||||
} // deleteRelationalInfo
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
const std::vector<uint32_t> & Profile::getFriends()
|
||||
{
|
||||
assert(m_has_fetched_friends && m_state == S_READY);
|
||||
return m_friends;
|
||||
} // getFriends
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
const std::vector<uint32_t> & Profile::getAchievements()
|
||||
{
|
||||
assert(m_has_fetched_achievements && m_state == S_READY && !m_is_current_user);
|
||||
return m_achievements;
|
||||
} // getAchievements
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Merges the information from a given profile with this profile. Any data
|
||||
* that is in the given profile that's not available in this profile will
|
||||
* be copied over, then the given profile will be deleted.
|
||||
*/
|
||||
void Profile::merge(Profile * profile)
|
||||
{
|
||||
assert(profile != NULL);
|
||||
if (!this->m_has_fetched_friends && profile->m_has_fetched_friends)
|
||||
this->m_friends = profile->m_friends;
|
||||
if (!this->m_has_fetched_achievements && profile->m_has_fetched_achievements)
|
||||
this->m_achievements = profile->m_achievements;
|
||||
if (this->m_relation_info == NULL && profile->m_relation_info != NULL)
|
||||
{
|
||||
this->m_relation_info = profile->m_relation_info;
|
||||
// We don't want the destructor of the profile instance to destroy
|
||||
// the relation info
|
||||
profile->m_relation_info = NULL;
|
||||
}
|
||||
delete profile;
|
||||
} // merge
|
||||
|
||||
} // namespace Online
|
||||
|
@ -29,123 +29,142 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Online{
|
||||
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* \brief Class that represents an online profile
|
||||
* \ingroup online
|
||||
*/
|
||||
class Profile
|
||||
namespace Online
|
||||
{
|
||||
/** Class that represents an online profile. It manages the online profile
|
||||
* for any user on this system, but also for users for which information
|
||||
* is requested (e.g. to see the achievements of friends). All those profiles
|
||||
* are managed by the ProfileManager.
|
||||
* \ingroup online
|
||||
*/
|
||||
class Profile
|
||||
{
|
||||
public:
|
||||
enum ConstructorType
|
||||
{
|
||||
public :
|
||||
enum ConstructorType
|
||||
{
|
||||
C_DEFAULT = 1,
|
||||
C_RELATION_INFO
|
||||
};
|
||||
class RelationInfo
|
||||
{
|
||||
private:
|
||||
bool m_is_online;
|
||||
bool m_is_pending;
|
||||
bool m_is_asker;
|
||||
irr::core::stringw m_date;
|
||||
public:
|
||||
RelationInfo(const irr::core::stringw & date, bool is_online, bool is_pending, bool is_asker = false);
|
||||
bool isPending(){return m_is_pending;}
|
||||
bool isAsker(){return m_is_asker;}
|
||||
const irr::core::stringw & getDate() { return m_date; }
|
||||
bool isOnline() const { return m_is_online; }
|
||||
void setOnline(bool online);
|
||||
};
|
||||
class FriendsListRequest : public XMLRequest
|
||||
{
|
||||
virtual void callback ();
|
||||
public:
|
||||
FriendsListRequest() : XMLRequest(0, true) {}
|
||||
};
|
||||
class AchievementsRequest : public XMLRequest
|
||||
{
|
||||
virtual void callback ();
|
||||
public:
|
||||
AchievementsRequest() : XMLRequest(0, true) {}
|
||||
};
|
||||
C_DEFAULT = 1,
|
||||
C_RELATION_INFO
|
||||
};
|
||||
|
||||
typedef std::vector<uint32_t> IDList;
|
||||
private:
|
||||
// ========================================================================
|
||||
class RelationInfo
|
||||
{
|
||||
private:
|
||||
bool m_is_online;
|
||||
bool m_is_pending;
|
||||
bool m_is_asker;
|
||||
irr::core::stringw m_date;
|
||||
public:
|
||||
RelationInfo(const irr::core::stringw & date, bool is_online,
|
||||
bool is_pending, bool is_asker = false);
|
||||
void setOnline(bool online);
|
||||
// --------------------------------------------------------------------
|
||||
bool isPending() const { return m_is_pending; }
|
||||
// --------------------------------------------------------------------
|
||||
bool isAsker() const { return m_is_asker; }
|
||||
// --------------------------------------------------------------------
|
||||
const irr::core::stringw & getDate() const { return m_date; }
|
||||
// --------------------------------------------------------------------
|
||||
bool isOnline() const { return m_is_online; }
|
||||
}; // class RelationInfo
|
||||
// ========================================================================
|
||||
class FriendsListRequest : public XMLRequest
|
||||
{
|
||||
virtual void callback();
|
||||
public:
|
||||
FriendsListRequest() : XMLRequest(0, true) {}
|
||||
}; // class FriendsListRequest
|
||||
|
||||
enum State
|
||||
{
|
||||
S_FETCHING = 1,
|
||||
S_READY
|
||||
};
|
||||
// ========================================================================
|
||||
class AchievementsRequest : public XMLRequest
|
||||
{
|
||||
virtual void callback();
|
||||
public:
|
||||
AchievementsRequest() : XMLRequest(0, true) {}
|
||||
}; // class AchievementsRequest
|
||||
|
||||
State m_state;
|
||||
bool m_is_current_user;
|
||||
uint32_t m_id;
|
||||
irr::core::stringw m_username;
|
||||
/** information about the relation with the current user */
|
||||
RelationInfo * m_relation_info;
|
||||
/** Whether or not the user of this profile, is a friend of the current user */
|
||||
bool m_is_friend;
|
||||
// ========================================================================
|
||||
|
||||
bool m_has_fetched_friends;
|
||||
/**
|
||||
* List of user id's that are friends with the user of this profile.
|
||||
* In case this profile is of the current user, this list also contains any id's of users that still have a friend request pending.
|
||||
* */
|
||||
std::vector<uint32_t> m_friends;
|
||||
typedef std::vector<uint32_t> IDList;
|
||||
private:
|
||||
|
||||
bool m_has_fetched_achievements;
|
||||
std::vector<uint32_t> m_achievements;
|
||||
/** The profile can either be fetching data, or be ready. */
|
||||
enum State
|
||||
{
|
||||
S_FETCHING = 1,
|
||||
S_READY
|
||||
};
|
||||
|
||||
bool m_cache_bit;
|
||||
State m_state;
|
||||
bool m_is_current_user;
|
||||
uint32_t m_id;
|
||||
irr::core::stringw m_username;
|
||||
/** information about the relation with the current user */
|
||||
RelationInfo * m_relation_info;
|
||||
/** Whether or not the user of this profile, is a friend of the current user */
|
||||
bool m_is_friend;
|
||||
|
||||
void requestFriendsList();
|
||||
void friendsListCallback(const XMLNode * input);
|
||||
bool m_has_fetched_friends;
|
||||
|
||||
void requestAchievements();
|
||||
void achievementsCallback(const XMLNode * input);
|
||||
/** List of user id's that are friends with the user of this profile.
|
||||
* In case this profile is of the current user, this list also contains
|
||||
* any id's of users that still have a friend request pending. */
|
||||
std::vector<uint32_t> m_friends;
|
||||
|
||||
public:
|
||||
Profile( const uint32_t & userid,
|
||||
const irr::core::stringw & username,
|
||||
bool is_current_user = false);
|
||||
Profile( const XMLNode * xml,
|
||||
ConstructorType type = C_DEFAULT);
|
||||
~Profile();
|
||||
void fetchFriends();
|
||||
const std::vector<uint32_t> & getFriends();
|
||||
bool hasFetchedFriends() { return m_has_fetched_friends;}
|
||||
bool m_has_fetched_achievements;
|
||||
std::vector<uint32_t> m_achievements;
|
||||
|
||||
void fetchAchievements();
|
||||
const std::vector<uint32_t> & getAchievements();
|
||||
bool hasFetchedAchievements() { return m_has_fetched_achievements;}
|
||||
bool m_cache_bit;
|
||||
|
||||
bool isFetching() const { return m_state == S_FETCHING; }
|
||||
bool isReady() const { return m_state == S_READY; }
|
||||
void requestFriendsList();
|
||||
void friendsListCallback(const XMLNode * input);
|
||||
|
||||
bool isCurrentUser() const { return m_is_current_user; }
|
||||
bool isFriend() const { return m_is_friend; }
|
||||
void setFriend() { m_is_friend = true; }
|
||||
void removeFriend(const uint32_t id);
|
||||
void addFriend(const uint32_t id);
|
||||
void deleteRelationalInfo();
|
||||
RelationInfo * getRelationInfo() { return m_relation_info; }
|
||||
void setRelationInfo(RelationInfo * r){ delete m_relation_info; m_relation_info = r;}
|
||||
void achievementsCallback(const XMLNode * input);
|
||||
|
||||
void setCacheBit(bool cache_bit) { m_cache_bit = cache_bit; }
|
||||
bool getCacheBit() const { return m_cache_bit; }
|
||||
public:
|
||||
Profile(const uint32_t & userid,
|
||||
const irr::core::stringw & username,
|
||||
bool is_current_user = false );
|
||||
Profile(const XMLNode * xml,
|
||||
ConstructorType type = C_DEFAULT);
|
||||
~Profile();
|
||||
void fetchFriends();
|
||||
const std::vector<uint32_t> & getFriends();
|
||||
void fetchAchievements();
|
||||
void removeFriend(const uint32_t id);
|
||||
void addFriend(const uint32_t id);
|
||||
void deleteRelationalInfo();
|
||||
const std::vector<uint32_t> & getAchievements();
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns true if the achievements for this profile have been fetched. */
|
||||
bool hasFetchedAchievements() const { return m_has_fetched_achievements; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns true if the friend list for this profile has been fetched. */
|
||||
bool hasFetchedFriends() const { return m_has_fetched_friends; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** True if the profile is not fetching data atm. */
|
||||
bool isReady() const { return m_state == S_READY; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool isCurrentUser() const { return m_is_current_user; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool isFriend() const { return m_is_friend; }
|
||||
// ------------------------------------------------------------------------
|
||||
void setFriend() { m_is_friend = true; }
|
||||
// ------------------------------------------------------------------------
|
||||
RelationInfo* getRelationInfo() { return m_relation_info; }
|
||||
// ------------------------------------------------------------------------
|
||||
void setRelationInfo(RelationInfo * r){ delete m_relation_info; m_relation_info = r; }
|
||||
|
||||
uint32_t getID() const { return m_id; }
|
||||
const irr::core::stringw & getUserName() const { return m_username; }
|
||||
void setCacheBit(bool cache_bit) { m_cache_bit = cache_bit; }
|
||||
bool getCacheBit() const { return m_cache_bit; }
|
||||
|
||||
void merge(Profile * profile);
|
||||
uint32_t getID() const { return m_id; }
|
||||
const irr::core::stringw & getUserName() const { return m_username; }
|
||||
|
||||
void merge(Profile * profile);
|
||||
|
||||
|
||||
}; // class Profile
|
||||
}; // class Profile
|
||||
|
||||
} // namespace Online
|
||||
|
||||
|
@ -63,13 +63,16 @@ void ProfileManager::iterateCache(Profile * profile)
|
||||
{
|
||||
profile->setCacheBit(true);
|
||||
ProfilesMap::iterator iter;
|
||||
for (iter = m_profiles_cache.begin(); iter != m_profiles_cache.end(); ++iter)
|
||||
for (iter = m_profiles_cache.begin();
|
||||
iter != m_profiles_cache.end(); ++iter)
|
||||
{
|
||||
if (!iter->second->getCacheBit())
|
||||
return;
|
||||
}
|
||||
//All cache bits are one! Set them all to zero except the one currently being visited
|
||||
for (iter = m_profiles_cache.begin(); iter != m_profiles_cache.end(); ++iter)
|
||||
// All cache bits are one! Set them all to zero except the one
|
||||
// currently being visited
|
||||
for (iter = m_profiles_cache.begin();
|
||||
iter != m_profiles_cache.end(); ++iter)
|
||||
{
|
||||
iter->second->setCacheBit(false);
|
||||
}
|
||||
@ -86,7 +89,7 @@ void ProfileManager::iterateCache(Profile * profile)
|
||||
* the RaceResultGUI to leave the race running (for the end animation) while
|
||||
* the results are being shown.
|
||||
*/
|
||||
void ProfileManager::directToCache(Profile * profile)
|
||||
void ProfileManager::directToCache(Profile* profile)
|
||||
{
|
||||
assert(profile != NULL);
|
||||
if (m_profiles_cache.size() == m_max_cache_size)
|
||||
@ -128,8 +131,8 @@ void ProfileManager::addPersistent(Profile * profile)
|
||||
} // addPersistent
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/**
|
||||
* Removes and deletes an entry from the persistent map.
|
||||
/** Removes and deletes an entry from the persistent map.
|
||||
* \param id the id of the profile to be removed.
|
||||
*/
|
||||
void ProfileManager::deleteFromPersistent(const uint32_t id)
|
||||
{
|
||||
@ -139,15 +142,20 @@ void ProfileManager::deleteFromPersistent(const uint32_t id)
|
||||
m_profiles_persistent.erase(id);
|
||||
}
|
||||
else
|
||||
Log::warn("ProfileManager::removePersistent", "Tried to remove profile with id %d from persistent while not present", id);
|
||||
Log::warn("ProfileManager",
|
||||
"Tried to remove profile with id %d from persistent while "
|
||||
"not present", id);
|
||||
} // deleteFromPersistent
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/** Deletes all persistent profiles.
|
||||
*/
|
||||
void ProfileManager::clearPersistent()
|
||||
{
|
||||
ProfilesMap::iterator it;
|
||||
for (it = m_profiles_persistent.begin(); it != m_profiles_persistent.end(); ++it) {
|
||||
for (it = m_profiles_persistent.begin();
|
||||
it != m_profiles_persistent.end(); ++it)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
m_profiles_persistent.clear();
|
||||
@ -163,7 +171,9 @@ void ProfileManager::moveToCache(const uint32_t id)
|
||||
addToCache(profile);
|
||||
}
|
||||
else
|
||||
Log::warn("ProfileManager::moveToCache", "Tried to move profile with id %d from persistent to cache while not present", id);
|
||||
Log::warn("ProfileManager",
|
||||
"Tried to move profile with id %d from persistent to "
|
||||
"cache while not present", id);
|
||||
} // moveToCache
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@ -172,24 +182,24 @@ void ProfileManager::addToCache(Profile * profile)
|
||||
{
|
||||
if (inPersistent(profile->getID()))
|
||||
m_profiles_persistent[profile->getID()]->merge(profile);
|
||||
else if (cacheHit(profile->getID()))
|
||||
else if (isInCache(profile->getID()))
|
||||
m_profiles_cache[profile->getID()]->merge(profile);
|
||||
else
|
||||
directToCache(profile);
|
||||
} // addToCache
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/** True if the profile with the given id is persistent.
|
||||
* \param id The id of the profile to test.
|
||||
*/
|
||||
bool ProfileManager::inPersistent(const uint32_t id)
|
||||
{
|
||||
if (m_profiles_persistent.find(id) != m_profiles_persistent.end())
|
||||
return true;
|
||||
return false;
|
||||
return m_profiles_persistent.find(id) != m_profiles_persistent.end();
|
||||
} // inPersistent
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
bool ProfileManager::cacheHit(const uint32_t id)
|
||||
bool ProfileManager::isInCache(const uint32_t id)
|
||||
{
|
||||
if (m_profiles_cache.find(id) != m_profiles_cache.end())
|
||||
{
|
||||
@ -197,7 +207,7 @@ bool ProfileManager::cacheHit(const uint32_t id)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} // cacheHit
|
||||
} // isInCache
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
void ProfileManager::setVisiting(const uint32_t id)
|
||||
@ -212,7 +222,7 @@ Profile * ProfileManager::getProfileByID(const uint32_t id)
|
||||
|
||||
if (inPersistent(id))
|
||||
return m_profiles_persistent[id];
|
||||
if (cacheHit(id))
|
||||
if (isInCache(id))
|
||||
return m_profiles_cache[id];
|
||||
//FIXME not able to get! Now this should actually fetch the info from the
|
||||
// server, but I haven't come up with a good asynchronous idea yet.
|
||||
|
@ -30,7 +30,12 @@
|
||||
namespace Online
|
||||
{
|
||||
|
||||
/** Class that takes care of online profiles.
|
||||
/** Class that manages all online profiles. Profiles are used for storing
|
||||
* online information from local users, but also to store information about
|
||||
* remote users (e.g. if you want to see the achievements of another user
|
||||
* a Profile for this user is created, the server is then queried for
|
||||
* the information and the result is stored in that profile).
|
||||
* The profile manager has two
|
||||
* \ingroup online.
|
||||
*/
|
||||
class ProfileManager
|
||||
@ -97,7 +102,7 @@ public:
|
||||
void clearPersistent();
|
||||
void moveToCache(const uint32_t id);
|
||||
void setVisiting(const uint32_t id);
|
||||
bool cacheHit(const uint32_t id);
|
||||
bool isInCache(const uint32_t id);
|
||||
bool inPersistent(const uint32_t id);
|
||||
Profile* getProfileByID(const uint32_t id);
|
||||
// ----------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user