mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-22 22:13:35 +02:00
Code cleanup
This commit is contained in:
parent
322c5faf63
commit
eaca128c99
@ -133,14 +133,14 @@ CServerHandler::~CServerHandler()
|
||||
}
|
||||
|
||||
CServerHandler::CServerHandler()
|
||||
: state(EClientState::NONE)
|
||||
, networkHandler(INetworkHandler::createHandler())
|
||||
, applier(std::make_unique<CApplier<CBaseForLobbyApply>>())
|
||||
: applier(std::make_unique<CApplier<CBaseForLobbyApply>>())
|
||||
, lobbyClient(std::make_unique<GlobalLobbyClient>())
|
||||
, client(nullptr)
|
||||
, loadMode(ELoadMode::NONE)
|
||||
, screenType(ESelectionScreen::unknown)
|
||||
, networkHandler(INetworkHandler::createHandler())
|
||||
, state(EClientState::NONE)
|
||||
, campaignStateToSend(nullptr)
|
||||
, screenType(ESelectionScreen::unknown)
|
||||
, loadMode(ELoadMode::NONE)
|
||||
, client(nullptr)
|
||||
, campaignServerRestartLock(false)
|
||||
{
|
||||
uuid = boost::uuids::to_string(boost::uuids::random_generator()());
|
||||
|
@ -69,7 +69,7 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientConnected(LobbyClientCon
|
||||
GH.windows().popWindows(1);
|
||||
}
|
||||
|
||||
GH.windows().createAndPushWindow<CLobbyScreen>(static_cast<ESelectionScreen>(handler.screenType));
|
||||
GH.windows().createAndPushWindow<CLobbyScreen>(handler.screenType);
|
||||
}
|
||||
handler.state = EClientState::LOBBY;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ void NetworkServer::start(uint16_t port)
|
||||
|
||||
void NetworkServer::startAsyncAccept()
|
||||
{
|
||||
std::shared_ptr<NetworkSocket> upcomingConnection = std::make_shared<NetworkSocket>(*io);
|
||||
auto upcomingConnection = std::make_shared<NetworkSocket>(*io);
|
||||
acceptor->async_accept(*upcomingConnection, std::bind(&NetworkServer::connectionAccepted, this, upcomingConnection, _1));
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
static const auto accountCookieLifetime = std::chrono::hours(24 * 7);
|
||||
|
||||
bool LobbyServer::isAccountNameValid(const std::string & accountName)
|
||||
bool LobbyServer::isAccountNameValid(const std::string & accountName) const
|
||||
{
|
||||
if(accountName.size() < 4)
|
||||
return false;
|
||||
@ -40,7 +40,7 @@ std::string LobbyServer::sanitizeChatMessage(const std::string & inputString) co
|
||||
return inputString;
|
||||
}
|
||||
|
||||
NetworkConnectionPtr LobbyServer::findAccount(const std::string & accountID)
|
||||
NetworkConnectionPtr LobbyServer::findAccount(const std::string & accountID) const
|
||||
{
|
||||
for(const auto & account : activeAccounts)
|
||||
if(account.second.accountID == accountID)
|
||||
@ -49,7 +49,7 @@ NetworkConnectionPtr LobbyServer::findAccount(const std::string & accountID)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NetworkConnectionPtr LobbyServer::findGameRoom(const std::string & gameRoomID)
|
||||
NetworkConnectionPtr LobbyServer::findGameRoom(const std::string & gameRoomID) const
|
||||
{
|
||||
for(const auto & account : activeGameRooms)
|
||||
if(account.second.roomID == gameRoomID)
|
||||
@ -187,7 +187,7 @@ void LobbyServer::sendJoinRoomSuccess(const NetworkConnectionPtr & target, const
|
||||
sendMessage(target, reply);
|
||||
}
|
||||
|
||||
void LobbyServer::sendChatMessage(const NetworkConnectionPtr & target, const std::string & roomMode, const std::string & roomName, const std::string & accountID, std::string & displayName, const std::string & messageText)
|
||||
void LobbyServer::sendChatMessage(const NetworkConnectionPtr & target, const std::string & roomMode, const std::string & roomName, const std::string & accountID, const std::string & displayName, const std::string & messageText)
|
||||
{
|
||||
JsonNode reply;
|
||||
reply["type"].String() = "chatMessage";
|
||||
@ -301,8 +301,8 @@ void LobbyServer::receiveSendChatMessage(const NetworkConnectionPtr & connection
|
||||
|
||||
database->insertChatMessage(accountID, "global", "english", messageText);
|
||||
|
||||
for(const auto & connection : activeAccounts)
|
||||
sendChatMessage(connection.first, "global", "english", accountID, displayName, messageText);
|
||||
for(const auto & otherConnection : activeAccounts)
|
||||
sendChatMessage(otherConnection.first, "global", "english", accountID, displayName, messageText);
|
||||
}
|
||||
|
||||
void LobbyServer::receiveClientRegister(const NetworkConnectionPtr & connection, const JsonNode & json)
|
||||
@ -548,7 +548,7 @@ void LobbyServer::receiveDeclineInvite(const NetworkConnectionPtr & connection,
|
||||
LobbyServer::~LobbyServer() = default;
|
||||
|
||||
LobbyServer::LobbyServer(const boost::filesystem::path & databasePath)
|
||||
: database(new LobbyDatabase(databasePath))
|
||||
: database(std::make_unique<LobbyDatabase>(databasePath))
|
||||
, networkHandler(INetworkHandler::createHandler())
|
||||
, networkServer(networkHandler->createServerTCP(*this))
|
||||
{
|
||||
|
@ -56,10 +56,10 @@ class LobbyServer : public INetworkServerListener
|
||||
std::unique_ptr<INetworkServer> networkServer;
|
||||
|
||||
std::string sanitizeChatMessage(const std::string & inputString) const;
|
||||
bool isAccountNameValid(const std::string & accountName);
|
||||
bool isAccountNameValid(const std::string & accountName) const;
|
||||
|
||||
NetworkConnectionPtr findAccount(const std::string & accountID);
|
||||
NetworkConnectionPtr findGameRoom(const std::string & gameRoomID);
|
||||
NetworkConnectionPtr findAccount(const std::string & accountID) const;
|
||||
NetworkConnectionPtr findGameRoom(const std::string & gameRoomID) const;
|
||||
|
||||
void onNewConnection(const NetworkConnectionPtr & connection) override;
|
||||
void onDisconnected(const NetworkConnectionPtr & connection) override;
|
||||
@ -70,7 +70,7 @@ class LobbyServer : public INetworkServerListener
|
||||
void broadcastActiveAccounts();
|
||||
void broadcastActiveGameRooms();
|
||||
|
||||
void sendChatMessage(const NetworkConnectionPtr & target, const std::string & roomMode, const std::string & roomName, const std::string & accountID, std::string & displayName, const std::string & messageText);
|
||||
void sendChatMessage(const NetworkConnectionPtr & target, const std::string & roomMode, const std::string & roomName, const std::string & accountID, const std::string & displayName, const std::string & messageText);
|
||||
void sendAccountCreated(const NetworkConnectionPtr & target, const std::string & accountID, const std::string & accountCookie);
|
||||
void sendLoginFailed(const NetworkConnectionPtr & target, const std::string & reason);
|
||||
void sendLoginSuccess(const NetworkConnectionPtr & target, const std::string & accountCookie, const std::string & displayName);
|
||||
|
@ -32,8 +32,7 @@ SQLiteStatement::SQLiteStatement(SQLiteInstance & instance, sqlite3_stmt * state
|
||||
|
||||
SQLiteStatement::~SQLiteStatement()
|
||||
{
|
||||
int result = sqlite3_finalize(m_statement);
|
||||
checkSQLiteError(m_instance.m_connection, result);
|
||||
sqlite3_finalize(m_statement);
|
||||
}
|
||||
|
||||
bool SQLiteStatement::execute()
|
||||
@ -179,8 +178,7 @@ SQLiteInstance::SQLiteInstance(sqlite3 * connection)
|
||||
|
||||
SQLiteInstance::~SQLiteInstance()
|
||||
{
|
||||
int result = sqlite3_close(m_connection);
|
||||
checkSQLiteError(m_connection, result);
|
||||
sqlite3_close(m_connection);
|
||||
}
|
||||
|
||||
SQLiteStatementPtr SQLiteInstance::prepare(const std::string & sql_text)
|
||||
|
@ -117,7 +117,11 @@ public:
|
||||
};
|
||||
|
||||
CVCMIServer::CVCMIServer(boost::program_options::variables_map & opts)
|
||||
: state(EServerState::LOBBY), cmdLineOptions(opts), currentClientId(1), currentPlayerId(1), restartGameplay(false)
|
||||
: restartGameplay(false)
|
||||
, state(EServerState::LOBBY)
|
||||
, currentClientId(1)
|
||||
, currentPlayerId(1)
|
||||
, cmdLineOptions(opts)
|
||||
{
|
||||
uuid = boost::uuids::to_string(boost::uuids::random_generator()());
|
||||
logNetwork->trace("CVCMIServer created! UUID: %s", uuid);
|
||||
@ -401,7 +405,7 @@ bool CVCMIServer::passHost(int toConnectionId)
|
||||
return false;
|
||||
}
|
||||
|
||||
void CVCMIServer::clientConnected(std::shared_ptr<CConnection> c, std::vector<std::string> & names, std::string uuid, EStartMode mode)
|
||||
void CVCMIServer::clientConnected(std::shared_ptr<CConnection> c, std::vector<std::string> & names, const std::string & uuid, EStartMode mode)
|
||||
{
|
||||
if(state != EServerState::LOBBY)
|
||||
throw std::runtime_error("CVCMIServer::clientConnected called while game is not accepting clients!");
|
||||
|
@ -105,7 +105,7 @@ public:
|
||||
void setPlayerConnectedId(PlayerSettings & pset, ui8 player) const;
|
||||
void updateStartInfoOnMapChange(std::shared_ptr<CMapInfo> mapInfo, std::shared_ptr<CMapGenOptions> mapGenOpt = {});
|
||||
|
||||
void clientConnected(std::shared_ptr<CConnection> c, std::vector<std::string> & names, std::string uuid, EStartMode mode);
|
||||
void clientConnected(std::shared_ptr<CConnection> c, std::vector<std::string> & names, const std::string & uuid, EStartMode mode);
|
||||
void clientDisconnected(std::shared_ptr<CConnection> c);
|
||||
void reconnectPlayer(int connId);
|
||||
|
||||
|
@ -24,8 +24,8 @@
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
std::string SERVER_NAME_AFFIX = "server";
|
||||
std::string SERVER_NAME = GameConstants::VCMI_VERSION + std::string(" (") + SERVER_NAME_AFFIX + ')';
|
||||
const std::string SERVER_NAME_AFFIX = "server";
|
||||
const std::string SERVER_NAME = GameConstants::VCMI_VERSION + std::string(" (") + SERVER_NAME_AFFIX + ')';
|
||||
|
||||
static void handleCommandOptions(int argc, const char * argv[], boost::program_options::variables_map & options)
|
||||
{
|
||||
@ -110,7 +110,7 @@ int main(int argc, const char * argv[])
|
||||
logConfig.configure();
|
||||
|
||||
loadDLLClasses();
|
||||
srand((ui32)time(nullptr));
|
||||
std::srand(static_cast<uint32_t>(time(nullptr)));
|
||||
|
||||
{
|
||||
CVCMIServer server(opts);
|
||||
|
@ -142,7 +142,7 @@ public:
|
||||
si.mapname = "anything";//does not matter, map service mocked
|
||||
si.difficulty = 0;
|
||||
si.mapfileChecksum = 0;
|
||||
si.mode = StartInfo::NEW_GAME;
|
||||
si.mode = EStartMode::NEW_GAME;
|
||||
si.seedToBeUsed = 42;
|
||||
|
||||
std::unique_ptr<CMapHeader> header = mapService.loadMapHeader(ResourcePath(si.mapname));
|
||||
|
Loading…
Reference in New Issue
Block a user