No longer use the server list md5, it caused only trouble, and the serverlist .z file is small enough to be downloaded each time (#95).
This commit is contained in:
@@ -734,18 +734,6 @@ void startWindowImpl::networkError(int errorID, int /*osErrorID*/)
|
|||||||
QMessageBox::Close);
|
QMessageBox::Close);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ERR_SOCK_OPEN_MD5_FAILED: {
|
|
||||||
QMessageBox::warning(this, tr("Network Error"),
|
|
||||||
tr("Could not open the server list MD5 file.\nPlease make sure that the server list URL is correct."),
|
|
||||||
QMessageBox::Close);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ERR_SOCK_INVALID_SERVERLIST_MD5: {
|
|
||||||
QMessageBox::warning(this, tr("Network Error"),
|
|
||||||
tr("Synchronization of the PokerTH internet server list has failed.\nPlease make sure that the server list URL is correct."),
|
|
||||||
QMessageBox::Close);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ERR_SOCK_INVALID_SERVERLIST_XML: {
|
case ERR_SOCK_INVALID_SERVERLIST_XML: {
|
||||||
QMessageBox::warning(this, tr("Network Error"),
|
QMessageBox::warning(this, tr("Network Error"),
|
||||||
tr("The PokerTH internet server list contains invalid data.\nIf you use a custom server list, please make sure its format is correct."),
|
tr("The PokerTH internet server list contains invalid data.\nIf you use a custom server list, please make sure its format is correct."),
|
||||||
|
|||||||
@@ -107,34 +107,6 @@ protected:
|
|||||||
ClientStateStartServerListDownload();
|
ClientStateStartServerListDownload();
|
||||||
};
|
};
|
||||||
|
|
||||||
// State: Synchronizing server list.
|
|
||||||
class ClientStateSynchronizingServerList : public ClientState
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// Access the state singleton.
|
|
||||||
static ClientStateSynchronizingServerList &Instance();
|
|
||||||
virtual ~ClientStateSynchronizingServerList();
|
|
||||||
|
|
||||||
virtual void Enter(boost::shared_ptr<ClientThread> client);
|
|
||||||
virtual void Exit(boost::shared_ptr<ClientThread> client);
|
|
||||||
|
|
||||||
virtual void HandlePacket(boost::shared_ptr<ClientThread> /*client*/, boost::shared_ptr<NetPacket> /*tmpPacket*/) {}
|
|
||||||
|
|
||||||
void SetDownloadHelper(boost::shared_ptr<DownloadHelper> helper);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
// Protected constructor - this is a singleton.
|
|
||||||
ClientStateSynchronizingServerList();
|
|
||||||
|
|
||||||
// Poll for the completion of the download.
|
|
||||||
void TimerLoop(const boost::system::error_code& ec, boost::shared_ptr<ClientThread> client);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
boost::shared_ptr<DownloadHelper> m_downloadHelper;
|
|
||||||
};
|
|
||||||
|
|
||||||
// State: Downloading the server list.
|
// State: Downloading the server list.
|
||||||
class ClientStateDownloadingServerList : public ClientState
|
class ClientStateDownloadingServerList : public ClientState
|
||||||
{
|
{
|
||||||
|
|||||||
+10
-103
@@ -178,24 +178,20 @@ ClientStateStartServerListDownload::Enter(boost::shared_ptr<ClientThread> client
|
|||||||
string serverListUrl(context.GetServerListUrl());
|
string serverListUrl(context.GetServerListUrl());
|
||||||
// Retrieve the file name from the URL.
|
// Retrieve the file name from the URL.
|
||||||
size_t pos = serverListUrl.find_last_of('/');
|
size_t pos = serverListUrl.find_last_of('/');
|
||||||
if (serverListUrl.empty() || pos == string::npos || ++pos >= serverListUrl.length()) {
|
if (context.GetCacheDir().empty() || serverListUrl.empty() || pos == string::npos || ++pos >= serverListUrl.length()) {
|
||||||
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_URL, 0);
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_URL, 0);
|
||||||
}
|
}
|
||||||
tmpServerListPath /= serverListUrl.substr(pos);
|
tmpServerListPath /= serverListUrl.substr(pos);
|
||||||
if (exists(tmpServerListPath)) {
|
if (exists(tmpServerListPath)) {
|
||||||
// Download and compare md5.
|
// Always download the current server list.
|
||||||
tmpServerListPath = tmpServerListPath.directory_string() + ".md5";
|
// If a previous file exists, delete it.
|
||||||
boost::shared_ptr<DownloadHelper> downloader(new DownloadHelper);
|
remove(tmpServerListPath);
|
||||||
downloader->Init(serverListUrl + ".md5", tmpServerListPath.directory_string());
|
|
||||||
ClientStateSynchronizingServerList::Instance().SetDownloadHelper(downloader);
|
|
||||||
client->SetState(ClientStateSynchronizingServerList::Instance());
|
|
||||||
} else {
|
|
||||||
// Download server list.
|
|
||||||
boost::shared_ptr<DownloadHelper> downloader(new DownloadHelper);
|
|
||||||
downloader->Init(serverListUrl, tmpServerListPath.directory_string());
|
|
||||||
ClientStateDownloadingServerList::Instance().SetDownloadHelper(downloader);
|
|
||||||
client->SetState(ClientStateDownloadingServerList::Instance());
|
|
||||||
}
|
}
|
||||||
|
// Download server list.
|
||||||
|
boost::shared_ptr<DownloadHelper> downloader(new DownloadHelper);
|
||||||
|
downloader->Init(serverListUrl, tmpServerListPath.directory_string());
|
||||||
|
ClientStateDownloadingServerList::Instance().SetDownloadHelper(downloader);
|
||||||
|
client->SetState(ClientStateDownloadingServerList::Instance());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -206,95 +202,6 @@ ClientStateStartServerListDownload::Exit(boost::shared_ptr<ClientThread> /*clien
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
ClientStateSynchronizingServerList &
|
|
||||||
ClientStateSynchronizingServerList::Instance()
|
|
||||||
{
|
|
||||||
static ClientStateSynchronizingServerList state;
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClientStateSynchronizingServerList::ClientStateSynchronizingServerList()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ClientStateSynchronizingServerList::~ClientStateSynchronizingServerList()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ClientStateSynchronizingServerList::Enter(boost::shared_ptr<ClientThread> client)
|
|
||||||
{
|
|
||||||
client->GetStateTimer().expires_from_now(
|
|
||||||
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
|
||||||
client->GetStateTimer().async_wait(
|
|
||||||
boost::bind(
|
|
||||||
&ClientStateSynchronizingServerList::TimerLoop, this, boost::asio::placeholders::error, client));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ClientStateSynchronizingServerList::Exit(boost::shared_ptr<ClientThread> client)
|
|
||||||
{
|
|
||||||
client->GetStateTimer().cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ClientStateSynchronizingServerList::SetDownloadHelper(boost::shared_ptr<DownloadHelper> helper)
|
|
||||||
{
|
|
||||||
m_downloadHelper = helper;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ClientStateSynchronizingServerList::TimerLoop(const boost::system::error_code& ec, boost::shared_ptr<ClientThread> client)
|
|
||||||
{
|
|
||||||
if (!ec && &client->GetState() == this) {
|
|
||||||
if (m_downloadHelper->Process()) {
|
|
||||||
m_downloadHelper.reset();
|
|
||||||
ClientContext &context = client->GetContext();
|
|
||||||
path md5ServerListPath(context.GetCacheDir());
|
|
||||||
|
|
||||||
// No more checking needed as this was done before.
|
|
||||||
md5ServerListPath /= context.GetServerListUrl().substr(context.GetServerListUrl().find_last_of('/') + 1) + ".md5";
|
|
||||||
path serverListPath = change_extension(md5ServerListPath, "");
|
|
||||||
// Compare the md5 sums.
|
|
||||||
string tmpMd5;
|
|
||||||
{
|
|
||||||
ifstream inFile(md5ServerListPath.directory_string().c_str(), ios_base::in);
|
|
||||||
if (inFile.fail())
|
|
||||||
throw ClientException(__FILE__, __LINE__, ERR_SOCK_OPEN_MD5_FAILED, 0);
|
|
||||||
inFile >> tmpMd5;
|
|
||||||
}
|
|
||||||
MD5Buf downloadedMd5;
|
|
||||||
if (!downloadedMd5.FromString(tmpMd5))
|
|
||||||
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_MD5, 0);
|
|
||||||
MD5Buf currentMd5;
|
|
||||||
if (!CryptHelper::MD5Sum(serverListPath.directory_string(), currentMd5))
|
|
||||||
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_MD5, 0);
|
|
||||||
if (downloadedMd5 == currentMd5) {
|
|
||||||
// Server list is still current.
|
|
||||||
client->SetState(ClientStateReadingServerList::Instance());
|
|
||||||
} else {
|
|
||||||
// Download new server list.
|
|
||||||
// Paranoia check before removing the file, we do not want to delete wrong files.
|
|
||||||
path tmpPath(serverListPath);
|
|
||||||
if (path(context.GetCacheDir()) == tmpPath.remove_leaf()) {
|
|
||||||
remove(serverListPath);
|
|
||||||
client->SetState(ClientStateStartServerListDownload::Instance());
|
|
||||||
} else
|
|
||||||
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_URL, 0);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Download still in process. Delay.
|
|
||||||
client->GetStateTimer().expires_from_now(
|
|
||||||
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
|
||||||
client->GetStateTimer().async_wait(
|
|
||||||
boost::bind(
|
|
||||||
&ClientStateSynchronizingServerList::TimerLoop, this, boost::asio::placeholders::error, client));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ClientStateDownloadingServerList &
|
ClientStateDownloadingServerList &
|
||||||
ClientStateDownloadingServerList::Instance()
|
ClientStateDownloadingServerList::Instance()
|
||||||
{
|
{
|
||||||
@@ -379,7 +286,7 @@ ClientStateReadingServerList::Enter(boost::shared_ptr<ClientThread> client)
|
|||||||
// Unzip the file using zlib.
|
// Unzip the file using zlib.
|
||||||
try {
|
try {
|
||||||
ifstream inFile(zippedServerListPath.directory_string().c_str(), ios_base::in | ios_base::binary);
|
ifstream inFile(zippedServerListPath.directory_string().c_str(), ios_base::in | ios_base::binary);
|
||||||
ofstream outFile(xmlServerListPath.directory_string().c_str(), ios_base::out);
|
ofstream outFile(xmlServerListPath.directory_string().c_str(), ios_base::out | ios_base::trunc);
|
||||||
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
|
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
|
||||||
in.push(boost::iostreams::zlib_decompressor());
|
in.push(boost::iostreams::zlib_decompressor());
|
||||||
in.push(inFile);
|
in.push(inFile);
|
||||||
|
|||||||
@@ -41,15 +41,13 @@
|
|||||||
#define ERR_SOCK_INVALID_STATE 19
|
#define ERR_SOCK_INVALID_STATE 19
|
||||||
#define ERR_SOCK_INVALID_TYPE 20
|
#define ERR_SOCK_INVALID_TYPE 20
|
||||||
#define ERR_SOCK_INVALID_SERVERLIST_URL 21
|
#define ERR_SOCK_INVALID_SERVERLIST_URL 21
|
||||||
#define ERR_SOCK_OPEN_MD5_FAILED 22
|
#define ERR_SOCK_INVALID_SERVERLIST_XML 22
|
||||||
#define ERR_SOCK_INVALID_SERVERLIST_MD5 23
|
#define ERR_SOCK_UNZIP_FAILED 23
|
||||||
#define ERR_SOCK_INVALID_SERVERLIST_XML 24
|
#define ERR_SOCK_TRANSFER_INIT_FAILED 24
|
||||||
#define ERR_SOCK_UNZIP_FAILED 25
|
#define ERR_SOCK_TRANSFER_OPEN_FAILED 25
|
||||||
#define ERR_SOCK_TRANSFER_INIT_FAILED 26
|
#define ERR_SOCK_TRANSFER_INVALID_URL 26
|
||||||
#define ERR_SOCK_TRANSFER_OPEN_FAILED 27
|
#define ERR_SOCK_TRANSFER_SELECT_FAILED 27
|
||||||
#define ERR_SOCK_TRANSFER_INVALID_URL 28
|
#define ERR_SOCK_TRANSFER_FAILED 28
|
||||||
#define ERR_SOCK_TRANSFER_SELECT_FAILED 29
|
|
||||||
#define ERR_SOCK_TRANSFER_FAILED 30
|
|
||||||
// The following errors are game errors.
|
// The following errors are game errors.
|
||||||
#define ERR_NET_VERSION_NOT_SUPPORTED 101
|
#define ERR_NET_VERSION_NOT_SUPPORTED 101
|
||||||
#define ERR_NET_SERVER_MAINTENANCE 102
|
#define ERR_NET_SERVER_MAINTENANCE 102
|
||||||
|
|||||||
Reference in New Issue
Block a user