2010-07-29 22:01:38 +05:30
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2010 Alistair Riddoch
|
|
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
2013-07-26 20:14:33 +02:00
|
|
|
#ifndef SERVER_POSSESSION_AUTHENTICATOR_H
|
|
|
|
|
#define SERVER_POSSESSION_AUTHENTICATOR_H
|
2010-07-29 22:01:38 +05:30
|
|
|
|
|
|
|
|
#include <string>
|
2013-08-09 16:25:04 +02:00
|
|
|
#include <unordered_map>
|
|
|
|
|
#include <boost/optional.hpp>
|
2010-07-29 22:01:38 +05:30
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
class LocatedEntity;
|
2013-07-26 20:14:33 +02:00
|
|
|
class PendingPossession;
|
2010-11-26 11:18:06 +00:00
|
|
|
|
2010-08-15 03:56:33 +05:30
|
|
|
/// \brief Map of teleported entity IDs and their PendingState objects
|
2013-08-09 16:25:04 +02:00
|
|
|
typedef std::unordered_map<std::string, PendingPossession *> PendingPossessionsMap;
|
2010-08-05 03:02:57 +05:30
|
|
|
|
2013-07-26 20:14:33 +02:00
|
|
|
/// \brief A class that stores and authenticates possession requests
|
|
|
|
|
class PossessionAuthenticator
|
2010-07-29 22:01:38 +05:30
|
|
|
{
|
2013-02-08 23:38:32 +00:00
|
|
|
private:
|
2010-08-15 03:56:33 +05:30
|
|
|
/// \brief An instance pointer for singleton behaviour
|
2013-07-26 20:14:33 +02:00
|
|
|
static PossessionAuthenticator * m_instance;
|
2010-08-15 03:56:33 +05:30
|
|
|
/// \brief Map of teleport requests
|
2013-07-26 20:14:33 +02:00
|
|
|
PendingPossessionsMap m_possessions;
|
2010-07-29 22:01:38 +05:30
|
|
|
|
2013-07-26 20:14:33 +02:00
|
|
|
void removePossession(PendingPossessionsMap::iterator I);
|
2013-02-08 23:38:32 +00:00
|
|
|
|
|
|
|
|
public:
|
2010-07-29 22:01:38 +05:30
|
|
|
|
|
|
|
|
static void init() {
|
|
|
|
|
if(m_instance == 0) {
|
2013-07-26 20:14:33 +02:00
|
|
|
m_instance = new PossessionAuthenticator();
|
2010-07-29 22:01:38 +05:30
|
|
|
}
|
|
|
|
|
}
|
2013-07-26 20:14:33 +02:00
|
|
|
static PossessionAuthenticator * instance() {
|
2010-07-29 22:01:38 +05:30
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
static void del() {
|
|
|
|
|
if (m_instance != 0) {
|
|
|
|
|
delete m_instance;
|
|
|
|
|
m_instance = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-08 23:13:46 +00:00
|
|
|
bool isPending(const std::string &) const;
|
2010-07-29 22:01:38 +05:30
|
|
|
|
2013-07-26 20:14:33 +02:00
|
|
|
int addPossession(const std::string &, const std::string &);
|
2010-07-29 22:01:38 +05:30
|
|
|
|
2013-07-26 20:14:33 +02:00
|
|
|
int removePossession(const std::string &);
|
2010-08-05 03:02:57 +05:30
|
|
|
|
2013-08-09 16:25:04 +02:00
|
|
|
boost::optional<std::string> getPossessionKey(const std::string& entity_id);
|
|
|
|
|
|
2013-07-26 20:14:33 +02:00
|
|
|
LocatedEntity * authenticatePossession(const std::string &,
|
2013-02-09 00:29:03 +00:00
|
|
|
const std::string &);
|
2012-12-26 00:34:31 +00:00
|
|
|
|
|
|
|
|
friend class TeleportAuthenticatortest;
|
2010-07-29 22:01:38 +05:30
|
|
|
};
|
|
|
|
|
|
2013-07-26 20:14:33 +02:00
|
|
|
#endif // SERVER_POSSESSION_AUTHENTICATOR_H
|