|
@@ -144,6 +144,14 @@ ServerStatus::ServerStatus(Framework::Text name,
|
|
|
|
|
|
|
|
ServerStatus::~ServerStatus()
|
|
ServerStatus::~ServerStatus()
|
|
|
{
|
|
{
|
|
|
|
|
+ requestIdLock.lockRead();
|
|
|
|
|
+ while (currentRequestIds.getEntryCount())
|
|
|
|
|
+ {
|
|
|
|
|
+ requestIdLock.unlockRead();
|
|
|
|
|
+ Sleep(100); // wait until running requets are completed
|
|
|
|
|
+ requestIdLock.lockRead();
|
|
|
|
|
+ }
|
|
|
|
|
+ requestIdLock.unlockRead();
|
|
|
secrets->release();
|
|
secrets->release();
|
|
|
removeButton->release();
|
|
removeButton->release();
|
|
|
join->release();
|
|
join->release();
|
|
@@ -153,64 +161,87 @@ void ServerStatus::updatePlayerName(Framework::Text playerName)
|
|
|
{
|
|
{
|
|
|
status = "";
|
|
status = "";
|
|
|
this->playerName = playerName;
|
|
this->playerName = playerName;
|
|
|
- ServerStatus* tmp = dynamic_cast<ServerStatus*>(getThis());
|
|
|
|
|
requestIdLock.lockWrite();
|
|
requestIdLock.lockWrite();
|
|
|
int id = ++requestId;
|
|
int id = ++requestId;
|
|
|
requestIdLock.unlockWrite();
|
|
requestIdLock.unlockWrite();
|
|
|
- new AsynchronCall([tmp, id]() {
|
|
|
|
|
|
|
+ bool* ready = new bool;
|
|
|
|
|
+ *ready = 0;
|
|
|
|
|
+ AsynchronCall* request = new AsynchronCall([this, id, ready]() {
|
|
|
FactoryClient* client = new FactoryClient();
|
|
FactoryClient* client = new FactoryClient();
|
|
|
- if (!client->connect(tmp->getIp(), tmp->getSSLPort()))
|
|
|
|
|
|
|
+ if (!client->connect(getIp(), getSSLPort()))
|
|
|
{
|
|
{
|
|
|
- tmp->requestIdLock.lockRead();
|
|
|
|
|
- if (tmp->requestId == id)
|
|
|
|
|
|
|
+ requestIdLock.lockRead();
|
|
|
|
|
+ if (requestId == id)
|
|
|
{
|
|
{
|
|
|
- tmp->status = "The Server is currently not reachable";
|
|
|
|
|
- tmp->statusId = 404;
|
|
|
|
|
- tmp->ping = -1;
|
|
|
|
|
- tmp->rend = 1;
|
|
|
|
|
|
|
+ status = "The Server is currently not reachable";
|
|
|
|
|
+ statusId = 404;
|
|
|
|
|
+ ping = -1;
|
|
|
|
|
+ rend = 1;
|
|
|
}
|
|
}
|
|
|
- tmp->requestIdLock.unlockRead();
|
|
|
|
|
|
|
+ requestIdLock.unlockRead();
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- tmp->requestIdLock.lockRead();
|
|
|
|
|
- if (tmp->requestId == id)
|
|
|
|
|
|
|
+ requestIdLock.lockRead();
|
|
|
|
|
+ if (requestId == id)
|
|
|
{
|
|
{
|
|
|
Text secret = "";
|
|
Text secret = "";
|
|
|
- if (tmp->secrets->has(tmp->playerName))
|
|
|
|
|
- secret = tmp->secrets->get(tmp->playerName);
|
|
|
|
|
- tmp->requestIdLock.unlockRead();
|
|
|
|
|
|
|
+ if (secrets->has(this->playerName))
|
|
|
|
|
+ secret = secrets->get(this->playerName);
|
|
|
|
|
+ requestIdLock.unlockRead();
|
|
|
int ping = client->ping();
|
|
int ping = client->ping();
|
|
|
- int statusId = client->status(tmp->playerName, secret);
|
|
|
|
|
|
|
+ int statusId = client->status(this->playerName, secret);
|
|
|
if (statusId == 403)
|
|
if (statusId == 403)
|
|
|
{
|
|
{
|
|
|
- int secondStatus = client->status(tmp->playerName, "");
|
|
|
|
|
|
|
+ int secondStatus = client->status(this->playerName, "");
|
|
|
if (secondStatus == 200) statusId = 203;
|
|
if (secondStatus == 200) statusId = 203;
|
|
|
}
|
|
}
|
|
|
if (secret.isEqual("") && statusId == 200)
|
|
if (secret.isEqual("") && statusId == 200)
|
|
|
{
|
|
{
|
|
|
statusId = 203;
|
|
statusId = 203;
|
|
|
}
|
|
}
|
|
|
- tmp->requestIdLock.lockRead();
|
|
|
|
|
- if (tmp->requestId == id)
|
|
|
|
|
|
|
+ requestIdLock.lockRead();
|
|
|
|
|
+ if (requestId == id)
|
|
|
{
|
|
{
|
|
|
- tmp->writeLock().lock();
|
|
|
|
|
- tmp->ping = ping;
|
|
|
|
|
- tmp->statusId = statusId;
|
|
|
|
|
- if (tmp->statusId == 200)
|
|
|
|
|
- tmp->status = "The Server is reachable";
|
|
|
|
|
- if (statusId == 203) tmp->status = "Create a new player";
|
|
|
|
|
- if (tmp->statusId == 403)
|
|
|
|
|
- tmp->status = "The name is already in use";
|
|
|
|
|
- tmp->rend = 1;
|
|
|
|
|
- tmp->writeLock().unlock();
|
|
|
|
|
|
|
+ writeLock().lock();
|
|
|
|
|
+ this->ping = ping;
|
|
|
|
|
+ this->statusId = statusId;
|
|
|
|
|
+ if (statusId == 200) status = "The Server is reachable";
|
|
|
|
|
+ if (statusId == 203) status = "Create a new player";
|
|
|
|
|
+ if (statusId == 403) status = "The name is already in use";
|
|
|
|
|
+ rend = 1;
|
|
|
|
|
+ writeLock().unlock();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- tmp->requestIdLock.unlockRead();
|
|
|
|
|
|
|
+ requestIdLock.unlockRead();
|
|
|
}
|
|
}
|
|
|
client->release();
|
|
client->release();
|
|
|
- tmp->release();
|
|
|
|
|
|
|
+ while (!*ready)
|
|
|
|
|
+ {
|
|
|
|
|
+ Sleep(100);
|
|
|
|
|
+ }
|
|
|
|
|
+ delete ready;
|
|
|
|
|
+ requestIdLock.lockWrite();
|
|
|
|
|
+ auto idIterator = currentRequestIds.begin();
|
|
|
|
|
+ auto requestIterator = currentRequests.begin();
|
|
|
|
|
+ while (idIterator && requestIterator)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (*idIterator == id)
|
|
|
|
|
+ {
|
|
|
|
|
+ requestIterator.remove();
|
|
|
|
|
+ idIterator.remove();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ ++idIterator;
|
|
|
|
|
+ ++requestIterator;
|
|
|
|
|
+ }
|
|
|
|
|
+ requestIdLock.unlockWrite();
|
|
|
});
|
|
});
|
|
|
|
|
+ requestIdLock.lockWrite();
|
|
|
|
|
+ currentRequestIds.add(id);
|
|
|
|
|
+ currentRequests.add(request);
|
|
|
|
|
+ *ready = 1;
|
|
|
|
|
+ requestIdLock.unlockWrite();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void ServerStatus::doMouseEvent(Framework::MouseEvent& me, bool userRet)
|
|
void ServerStatus::doMouseEvent(Framework::MouseEvent& me, bool userRet)
|
|
@@ -238,7 +269,7 @@ void ServerStatus::render(Framework::Image& rObj)
|
|
|
tr.renderText(5, 5, name, rObj, 0xFFFFFFFF);
|
|
tr.renderText(5, 5, name, rObj, 0xFFFFFFFF);
|
|
|
tr.renderText(
|
|
tr.renderText(
|
|
|
5, 25, ip + ":" + sslPort + " (" + port + ")", rObj, 0xFF808080);
|
|
5, 25, ip + ":" + sslPort + " (" + port + ")", rObj, 0xFF808080);
|
|
|
- if (requestId && requestId != 404)
|
|
|
|
|
|
|
+ if (requestId && statusId != 404)
|
|
|
{
|
|
{
|
|
|
int tbr = tr.getTextWidth(Text("ping: ") + ping);
|
|
int tbr = tr.getTextWidth(Text("ping: ") + ping);
|
|
|
if (ping >= 0)
|
|
if (ping >= 0)
|