From b1bad8d1448d9dc8d312db59ea8620433b9fa9eb Mon Sep 17 00:00:00 2001 From: lotodore Date: Wed, 18 Mar 2009 15:01:43 +0000 Subject: [PATCH] Preparing client use of external avatar servers. --- src/net/clientcontext.h | 5 +++++ src/net/clientthread.h | 1 + src/net/common/clientstate.cpp | 9 +++++++++ src/net/common/clientthread.cpp | 6 +++++- src/session.cpp | 4 ++++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/net/clientcontext.h b/src/net/clientcontext.h index 328e66e8..27ff6e62 100644 --- a/src/net/clientcontext.h +++ b/src/net/clientcontext.h @@ -63,6 +63,10 @@ public: {return m_serverPort;} void SetServerPort(unsigned serverPort) {m_serverPort = serverPort;} + const std::string &GetAvatarServerAddr() const + {return m_avatarServerAddr;} + void SetAvatarServerAddr(const std::string &avatarServerAddr) + {m_avatarServerAddr = avatarServerAddr;} const std::string &GetPassword() const {return m_password;} void SetPassword(const std::string &password) @@ -102,6 +106,7 @@ private: std::string m_serverListUrl; bool m_useServerList; unsigned m_serverPort; + std::string m_avatarServerAddr; std::string m_password; sockaddr_storage m_clientSockaddr; std::string m_playerName; diff --git a/src/net/clientthread.h b/src/net/clientthread.h index f83cc8ca..f1d436d3 100644 --- a/src/net/clientthread.h +++ b/src/net/clientthread.h @@ -54,6 +54,7 @@ public: unsigned serverPort, bool ipv6, bool sctp, + const std::string &avatarServerAddress, const std::string &pwd, const std::string &playerName, const std::string &avatarFile, diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 94eb7cf0..414b9b74 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -459,6 +459,9 @@ ClientStateReadingServerList::Process(ClientThread &client) addrNode = firstServer->FirstChild("IPv4Address"); const TiXmlNode *portNode = firstServer->FirstChild("Port"); + // Currently, only IPv4 is supported for avatar servers. + const TiXmlNode *avatarNode = firstServer->FirstChild("AvatarServerIPv4Address"); + if (!addrNode || !addrNode->ToElement() || !portNode || !portNode->ToElement()) throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_XML, 0); @@ -467,6 +470,12 @@ ClientStateReadingServerList::Process(ClientThread &client) int tmpPort = 0; portNode->ToElement()->QueryIntAttribute("value", &tmpPort); context.SetServerPort((unsigned)tmpPort); + + if (avatarNode && avatarNode->ToElement()) // optional + { + context.SetAvatarServerAddr(addrNode->ToElement()->Attribute("value")); + } + retVal = MSG_SOCK_SERVER_LIST_DONE; } else diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index 79b1f559..069207c5 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -56,7 +56,8 @@ void ClientThread::Init( const string &serverAddress, const string &serverListUrl, bool useServerList, unsigned serverPort, bool ipv6, bool sctp, - const string &pwd, const string &playerName, const string &avatarFile, + const string &avatarServerAddress, const string &pwd, + const string &playerName, const string &avatarFile, const string &cacheDir) { if (IsRunning()) @@ -73,6 +74,7 @@ ClientThread::Init( context.SetServerListUrl(serverListUrl); context.SetUseServerList(useServerList); context.SetServerPort(serverPort); + context.SetAvatarServerAddr(avatarServerAddress); context.SetPassword(pwd); context.SetPlayerName(playerName); context.SetAvatarFile(avatarFile); @@ -517,6 +519,8 @@ ClientThread::RetrieveAvatarIfNeeded(unsigned id, const PlayerInfo &info) if (info.hasAvatar && !info.avatar.IsZero() && !GetAvatarManager().HasAvatar(info.avatar)) { m_avatarHasRequestedList.push_back(id); // Never remove from this list. Only request once. + + // TODO: download from avatar server if applicable. boost::shared_ptr retrieveAvatar(new NetPacketRetrieveAvatar); NetPacketRetrieveAvatar::Data retrieveAvatarData; retrieveAvatarData.requestId = id; diff --git a/src/session.cpp b/src/session.cpp index 3fcf0998..4f7aff83 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -174,6 +174,7 @@ void Session::startInternetClient() } myNetClient = new ClientThread(*myGui, *myAvatarManager); + bool useAvatarServer = myConfig->readConfigInt("UseAvatarServer") != 0; myNetClient->Init( myConfig->readConfigString("InternetServerAddress"), myConfig->readConfigString("InternetServerListAddress"), @@ -181,6 +182,7 @@ void Session::startInternetClient() myConfig->readConfigInt("InternetServerPort"), myConfig->readConfigInt("InternetServerUseIpv6") == 1, myConfig->readConfigInt("InternetServerUseSctp") == 1, + useAvatarServer ? myConfig->readConfigString("AvatarServerAddress") : "", myConfig->readConfigString("InternetServerPassword"), myConfig->readConfigString("MyName"), myConfig->readConfigString("MyAvatar"), @@ -205,6 +207,7 @@ void Session::startNetworkClient(const string &serverAddress, unsigned serverPor serverPort, ipv6, sctp, + "", // no avatar server pwd, myConfig->readConfigString("MyName"), myConfig->readConfigString("MyAvatar"), @@ -232,6 +235,7 @@ void Session::startNetworkClientForLocalServer(const GameData &gameData) myConfig->readConfigInt("ServerPort"), useIpv6, myConfig->readConfigInt("ServerUseSctp") == 1, + "", // no avatar server myConfig->readConfigString("ServerPassword"), myConfig->readConfigString("MyName"), myConfig->readConfigString("MyAvatar"),