summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/account-server/accountclient.cpp20
-rw-r--r--src/account-server/accountclient.h46
-rw-r--r--src/account-server/accounthandler.cpp4
3 files changed, 32 insertions, 38 deletions
diff --git a/src/account-server/accountclient.cpp b/src/account-server/accountclient.cpp
index 814f2aba..dd55be7a 100644
--- a/src/account-server/accountclient.cpp
+++ b/src/account-server/accountclient.cpp
@@ -22,24 +22,6 @@
AccountClient::AccountClient(ENetPeer *peer):
NetComputer(peer),
- status(CLIENT_LOGIN),
- mAccount(nullptr)
+ status(CLIENT_LOGIN)
{
}
-
-AccountClient::~AccountClient()
-{
- unsetAccount();
-}
-
-void AccountClient::setAccount(Account *acc)
-{
- unsetAccount();
- mAccount = acc;
-}
-
-void AccountClient::unsetAccount()
-{
- delete mAccount;
- mAccount = nullptr;
-}
diff --git a/src/account-server/accountclient.h b/src/account-server/accountclient.h
index dd2e1366..7812f1e9 100644
--- a/src/account-server/accountclient.h
+++ b/src/account-server/accountclient.h
@@ -26,6 +26,8 @@
#include "account-server/account.h"
#include "net/netcomputer.h"
+#include <memory>
+
class AccountHandler;
enum AccountClientStatus
@@ -42,29 +44,39 @@ class AccountClient : public NetComputer
{
public:
AccountClient(ENetPeer *peer);
- ~AccountClient();
- /**
- * Set the account associated with the connection
- */
void setAccount(Account *acc);
-
- /**
- * Unset the account associated with the connection
- */
void unsetAccount();
-
- /**
- * Get account associated with the connection.
- */
- Account *getAccount() const
- { return mAccount; }
+ Account *getAccount() const;
AccountClientStatus status;
private:
- /** Account associated with connection */
- Account *mAccount;
+ std::unique_ptr<Account> mAccount;
};
-#endif
+/**
+ * Set the account associated with the connection.
+ */
+inline void AccountClient::setAccount(Account *acc)
+{
+ mAccount.reset(acc);
+}
+
+/**
+ * Unset the account associated with the connection.
+ */
+inline void AccountClient::unsetAccount()
+{
+ mAccount.reset();
+}
+
+/**
+ * Get account associated with the connection.
+ */
+inline Account *AccountClient::getAccount() const
+{
+ return mAccount.get();
+}
+
+#endif // ACCOUNTCLIENT_H
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp
index a9905f7f..2656d210 100644
--- a/src/account-server/accounthandler.cpp
+++ b/src/account-server/accounthandler.cpp
@@ -242,7 +242,7 @@ void AccountClientHandler::deinitialize()
{
accountHandler->stopListen();
delete accountHandler;
- accountHandler = 0;
+ accountHandler = nullptr;
}
void AccountClientHandler::process()
@@ -381,7 +381,7 @@ void AccountHandler::handleLoginMessage(AccountClient &client, MessageIn &msg)
}
// Check if the account exists
- Account *acc = 0;
+ Account *acc = nullptr;
for (Account *account : mPendingAccounts)
if (account->getName() == username)
acc = account;