TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LoginRESTService.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef LoginRESTService_h__
19 #define LoginRESTService_h__
20 
21 #include "Session.h"
22 #include "Define.h"
23 #include "Login.pb.h"
24 #include <boost/asio/io_service.hpp>
25 #include <boost/asio/ip/tcp.hpp>
26 #include <boost/asio/ip/address.hpp>
27 #include <boost/asio/deadline_timer.hpp>
28 #include <atomic>
29 #include <mutex>
30 #include <thread>
31 
32 struct soap;
33 struct soap_plugin;
34 
36 {
37 public:
39 
40  static LoginRESTService& Instance();
41 
42  bool Start(boost::asio::io_service& ioService);
43  void Stop();
44 
45  boost::asio::ip::tcp::endpoint const& GetAddressForClient(boost::asio::ip::address const& address) const;
46 
47  std::unique_ptr<Battlenet::Session::AccountInfo> VerifyLoginTicket(std::string const& id);
48 
49 private:
50  void Run();
51 
52  friend int32 handle_get_plugin(soap* soapClient);
53  int32 HandleGet(soap* soapClient);
54 
55  friend int32 handle_post_plugin(soap* soapClient);
56  int32 HandlePost(soap* soapClient);
57 
58  int32 SendResponse(soap* soapClient, google::protobuf::Message const& response);
59 
60  std::string CalculateShaPassHash(std::string const& name, std::string const& password);
61 
62  void AddLoginTicket(std::string const& id, std::unique_ptr<Battlenet::Session::AccountInfo> accountInfo);
63  void CleanupLoginTickets(boost::system::error_code const& error);
64 
65  struct LoginTicket
66  {
68 
69  std::string Id;
70  std::unique_ptr<Battlenet::Session::AccountInfo> Account;
71  std::time_t ExpiryTime;
72  };
73 
75  {
76  static char const* const PluginId;
77  static int32 Init(soap* s, soap_plugin*, void*);
78  static void Destroy(soap* s, soap_plugin* p);
79  static int32 ChangeResponse(soap* s, int32 originalResponse, size_t contentLength);
80 
81  int32(*fresponse)(soap* s, int32 status, size_t length);
83  };
84 
86  {
87  static char const* const PluginId;
88  static int32 Init(soap* s, soap_plugin* p, void*);
89  static void Destroy(soap* s, soap_plugin* p);
90  static int32 OnSetHeader(soap* s, char const* key, char const* value);
91 
92  int32(*fposthdr)(soap* s, char const* key, char const* value);
93  char const* ContentType;
94  };
95 
96  std::thread _thread;
97  std::atomic<bool> _stopped;
99  std::string _bindIP;
101  boost::asio::ip::tcp::endpoint _externalAddress;
102  boost::asio::ip::tcp::endpoint _localAddress;
103  std::mutex _loginTicketMutex;
104  std::unordered_map<std::string, LoginTicket> _validLoginTickets;
105  boost::asio::deadline_timer* _loginTicketCleanupTimer;
106 };
107 
108 #define sLoginService LoginRESTService::Instance()
109 
110 #endif // LoginRESTService_h__
void Stop()
Definition: LoginRESTService.cpp:108
static int32 ChangeResponse(soap *s, int32 originalResponse, size_t contentLength)
Definition: LoginRESTService.cpp:411
int32(* fresponse)(soap *s, int32 status, size_t length)
Definition: LoginRESTService.h:81
void CleanupLoginTickets(boost::system::error_code const &error)
Definition: LoginRESTService.cpp:344
boost::asio::ip::tcp::endpoint _localAddress
Definition: LoginRESTService.h:102
void AddLoginTicket(std::string const &id, std::unique_ptr< Battlenet::Session::AccountInfo > accountInfo)
Definition: LoginRESTService.cpp:337
std::unique_ptr< Battlenet::Session::AccountInfo > Account
Definition: LoginRESTService.h:70
static void Destroy(soap *s, soap_plugin *p)
Definition: LoginRESTService.cpp:433
Definition: LoginRESTService.h:35
Definition: stdsoap2.h:1933
std::mutex _loginTicketMutex
Definition: LoginRESTService.h:103
boost::asio::deadline_timer * _loginTicketCleanupTimer
Definition: LoginRESTService.h:105
char const * ContentType
Definition: LoginRESTService.h:93
std::string Id
Definition: LoginRESTService.h:69
std::thread _thread
Definition: LoginRESTService.h:96
boost::asio::ip::tcp::endpoint const & GetAddressForClient(boost::asio::ip::address const &address) const
Definition: LoginRESTService.cpp:115
#define false
Definition: CascPort.h:18
int32 _port
Definition: LoginRESTService.h:100
static LoginRESTService & Instance()
Definition: LoginRESTService.cpp:383
std::atomic< bool > _stopped
Definition: LoginRESTService.h:97
Definition: message.h:165
static int32 Init(soap *s, soap_plugin *p, void *)
Definition: LoginRESTService.cpp:419
bool Start(boost::asio::io_service &ioService)
Definition: LoginRESTService.cpp:44
std::string _bindIP
Definition: LoginRESTService.h:99
std::unordered_map< std::string, LoginTicket > _validLoginTickets
Definition: LoginRESTService.h:104
friend int32 handle_post_plugin(soap *soapClient)
Definition: LoginRESTService.cpp:39
std::time_t ExpiryTime
Definition: LoginRESTService.h:71
int32 HandlePost(soap *soapClient)
Definition: LoginRESTService.cpp:200
std::unique_ptr< Battlenet::Session::AccountInfo > VerifyLoginTicket(std::string const &id)
Definition: LoginRESTService.cpp:319
Definition: stdsoap2.h:2250
int32_t int32
Definition: Define.h:146
int32 HandleGet(soap *soapClient)
Definition: LoginRESTService.cpp:186
float length(float v)
Definition: vectorMath.h:208
static void Destroy(soap *s, soap_plugin *p)
Definition: LoginRESTService.cpp:404
static char const *const PluginId
Definition: LoginRESTService.h:87
Definition: Login.pb.h:198
int32(* fposthdr)(soap *s, char const *key, char const *value)
Definition: LoginRESTService.h:92
void Run()
Definition: LoginRESTService.cpp:128
Definition: LoginRESTService.h:74
int32 ErrorCode
Definition: LoginRESTService.h:82
std::string CalculateShaPassHash(std::string const &name, std::string const &password)
Definition: LoginRESTService.cpp:304
int32_t int32
Definition: g3dmath.h:167
static int32 OnSetHeader(soap *s, char const *key, char const *value)
Definition: LoginRESTService.cpp:440
boost::asio::ip::tcp::endpoint _externalAddress
Definition: LoginRESTService.h:101
const FieldDescriptor value
Definition: descriptor.h:1522
friend int32 handle_get_plugin(soap *soapClient)
Definition: LoginRESTService.cpp:34
Battlenet::JSON::Login::FormInputs _formInputs
Definition: LoginRESTService.h:98
static char const *const PluginId
Definition: LoginRESTService.h:76
LoginTicket & operator=(LoginTicket &&right)
Definition: LoginRESTService.cpp:366
Definition: LoginRESTService.h:65
int32 SendResponse(soap *soapClient, google::protobuf::Message const &response)
Definition: LoginRESTService.cpp:295
LoginRESTService()
Definition: LoginRESTService.h:38
Definition: LoginRESTService.h:85
static int32 Init(soap *s, soap_plugin *, void *)
Definition: LoginRESTService.cpp:391