eqemu-server/loginserver/loginserver_webserver.h
Chris Miles d87db648c3
[Loginserver] Code Cleanup and Tweaks (#1653)
* if for whatever reason the world server is not sending an address, use the local address it sends

* Log when world is sending loginserver info

* Force legacy mode when login host is login.eqemulator.net to avoid misconfigurations at least until things change

* Add human IP translation to log messages

* Sanitize world server name

* Code cleanup and renaming member variables

* More cleanup

* Remove this->

* Validation constants

* Key worldserver lookups by both longname and shortname both

* Update allowed character list

* Fix short_name API response field; add world_id to response

* Shorten receiver verbosity

* Remove unnecessary member variables from database and rename database to m_database

* Adjust MAX_SERVER_VERSION_LENGTH

* Fix indents
2021-10-30 19:09:42 -05:00

39 lines
1.1 KiB
C++

#ifndef EQEMU_LOGINSERVER_WEBSERVER_H
#define EQEMU_LOGINSERVER_WEBSERVER_H
#include "../common/http/httplib.h"
#include "../common/json/json.h"
#include "../common/types.h"
namespace LoginserverWebserver {
class TokenManager {
public:
TokenManager() = default;
struct token_data {
std::string token;
bool can_read;
bool can_write;
std::string user_agent;
std::string remote_address;
};
std::map<std::string, token_data> loaded_api_tokens{};
void LoadApiTokens();
static bool TokenExists(const std::string &token);
token_data GetToken(const std::string &token);
static token_data CheckApiAuthorizationHeaders(const httplib::Request &request);
static bool AuthCanRead(const httplib::Request &request, httplib::Response &res);
static bool AuthCanWrite(const httplib::Request &request, httplib::Response &res);
};
void RegisterRoutes(httplib::Server &api);
void SendResponse(const Json::Value &payload, httplib::Response &res);
static Json::Value ParseRequestBody(const httplib::Request &request);
};
#endif //EQEMU_LOGINSERVER_WEBSERVER_H