mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
uuid check
This commit is contained in:
parent
83f4a5b561
commit
930f03e812
@ -120,11 +120,6 @@ CServerHandler::CServerHandler()
|
||||
uuid = boost::uuids::to_string(boost::uuids::random_generator()());
|
||||
applier = std::make_shared<CApplier<CBaseForLobbyApply>>();
|
||||
registerTypesLobbyPacks(*applier);
|
||||
|
||||
if(settings["remoteSession"].Bool())
|
||||
{
|
||||
uuid = settings["uuid"].String();
|
||||
}
|
||||
}
|
||||
|
||||
void CServerHandler::resetStateForLobby(const StartInfo::EMode mode, const std::vector<std::string> * names)
|
||||
@ -669,6 +664,7 @@ void CServerHandler::restoreLastSession()
|
||||
{
|
||||
auto loadSession = [this]()
|
||||
{
|
||||
uuid = settings["server"]["uuid"].String();
|
||||
for(auto & name : settings["server"]["names"].Vector())
|
||||
myNames.push_back(name.String());
|
||||
resetStateForLobby(StartInfo::LOAD_GAME, &myNames);
|
||||
|
@ -308,20 +308,6 @@ void CVCMIServer::connectionAccepted(const boost::system::error_code & ec)
|
||||
|
||||
try
|
||||
{
|
||||
/*if(state == EServerState::GAMEPLAY && !hangingConnections.empty())
|
||||
{
|
||||
logNetwork->info("Reconnection player");
|
||||
(*hangingConnections.begin())->socket = upcomingConnection;
|
||||
upcomingConnection.reset();
|
||||
//immediately start game
|
||||
//std::unique_ptr<LobbyStartGame> startGameForReconnectedPlayer(new LobbyStartGame);
|
||||
//startGameForReconnectedPlayer->initializedStartInfo = si;
|
||||
//startGameForReconnectedPlayer->initializedGameState = gh->gs;
|
||||
//startGameForReconnectedPlayer->clientId = (*hangingConnections.begin())->connectionID;
|
||||
//announcePack(std::move(startGameForReconnectedPlayer));
|
||||
|
||||
(*hangingConnections.begin())->handler = std::make_shared<boost::thread>(&CVCMIServer::threadHandleClient, this, *hangingConnections.begin());
|
||||
}*/
|
||||
if(state == EServerState::LOBBY || !hangingConnections.empty())
|
||||
{
|
||||
logNetwork->info("We got a new connection! :)");
|
||||
@ -329,26 +315,6 @@ void CVCMIServer::connectionAccepted(const boost::system::error_code & ec)
|
||||
upcomingConnection.reset();
|
||||
connections.insert(c);
|
||||
c->handler = std::make_shared<boost::thread>(&CVCMIServer::threadHandleClient, this, c);
|
||||
|
||||
if(!hangingConnections.empty() && gh)
|
||||
{
|
||||
//TODO: check client uuid
|
||||
logNetwork->info("Reconnection player");
|
||||
c->connectionID = (*hangingConnections.begin())->connectionID;
|
||||
for(auto & playerConnection : gh->connections)
|
||||
{
|
||||
for(auto & existingConnection : playerConnection.second)
|
||||
{
|
||||
if(existingConnection == *hangingConnections.begin())
|
||||
{
|
||||
playerConnection.second.erase(existingConnection);
|
||||
playerConnection.second.insert(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//hangingConnections.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(std::exception & e)
|
||||
|
@ -34,11 +34,58 @@ void CLobbyPackToServer::applyOnServerAfterAnnounce(CVCMIServer * srv)
|
||||
|
||||
bool LobbyClientConnected::checkClientPermissions(CVCMIServer * srv) const
|
||||
{
|
||||
return true;
|
||||
if(srv->gh)
|
||||
{
|
||||
for(auto & connection : srv->hangingConnections)
|
||||
{
|
||||
if(connection->uuid == uuid)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(srv->state == EServerState::LOBBY)
|
||||
return true;
|
||||
|
||||
//disconnect immediately and ignore this client
|
||||
srv->connections.erase(c);
|
||||
if(c && c->isOpen())
|
||||
{
|
||||
c->close();
|
||||
c->connected = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LobbyClientConnected::applyOnServer(CVCMIServer * srv)
|
||||
{
|
||||
if(srv->gh)
|
||||
{
|
||||
for(auto & connection : srv->hangingConnections)
|
||||
{
|
||||
if(connection->uuid == uuid)
|
||||
{
|
||||
logNetwork->info("Reconnection player");
|
||||
c->connectionID = connection->connectionID;
|
||||
for(auto & playerConnection : srv->gh->connections)
|
||||
{
|
||||
for(auto & existingConnection : playerConnection.second)
|
||||
{
|
||||
if(existingConnection == connection)
|
||||
{
|
||||
playerConnection.second.erase(existingConnection);
|
||||
playerConnection.second.insert(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
srv->hangingConnections.erase(connection);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
srv->clientConnected(c, names, uuid, mode);
|
||||
// Server need to pass some data to newly connected client
|
||||
clientId = c->connectionID;
|
||||
@ -55,7 +102,6 @@ void LobbyClientConnected::applyOnServerAfterAnnounce(CVCMIServer * srv)
|
||||
srv->updateAndPropagateLobbyState();
|
||||
if(srv->state == EServerState::GAMEPLAY)
|
||||
{
|
||||
|
||||
//immediately start game
|
||||
std::unique_ptr<LobbyStartGame> startGameForReconnectedPlayer(new LobbyStartGame);
|
||||
startGameForReconnectedPlayer->initializedStartInfo = srv->si;
|
||||
@ -92,7 +138,7 @@ bool LobbyClientDisconnected::applyOnServer(CVCMIServer * srv)
|
||||
|
||||
void LobbyClientDisconnected::applyOnServerAfterAnnounce(CVCMIServer * srv)
|
||||
{
|
||||
if(c->isOpen())
|
||||
if(c && c->isOpen())
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lock(*c->mutexWrite);
|
||||
c->close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user