mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-22 03:18:22 +00:00
Remove unused and unmaintained sources
This commit is contained in:
-375
@@ -1,375 +0,0 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2016 EQEMu Development Team (http://eqemulator.net)
|
||||
|
||||
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; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||
are required to give you total support for your newly bought product;
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifdef EMBPERL
|
||||
|
||||
#include "../common/global_define.h"
|
||||
#include "eqw.h"
|
||||
#include "eqw_parser.h"
|
||||
#include "world_config.h"
|
||||
#include "../common/races.h"
|
||||
#include "../common/classes.h"
|
||||
#include "../common/misc.h"
|
||||
#include "../common/strings.h"
|
||||
#include "zoneserver.h"
|
||||
#include "zonelist.h"
|
||||
#include "clientlist.h"
|
||||
#include "cliententry.h"
|
||||
#include "login_server.h"
|
||||
#include "login_server_list.h"
|
||||
#include "worlddb.h"
|
||||
#include "client.h"
|
||||
#include "launcher_list.h"
|
||||
#include "launcher_link.h"
|
||||
#include "wguild_mgr.h"
|
||||
#include "../common/emu_constants.h"
|
||||
|
||||
#ifdef seed
|
||||
#undef seed
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
extern uint32 numzones;
|
||||
extern LauncherList launcher_list;
|
||||
extern volatile bool RunLoops;
|
||||
|
||||
EQW EQW::s_EQW;
|
||||
|
||||
//IO Capture routine
|
||||
XS(XS_EQWIO_PRINT); /* prototype to pass -Wmissing-prototypes */
|
||||
XS(XS_EQWIO_PRINT)
|
||||
{
|
||||
dXSARGS;
|
||||
if (items < 2)
|
||||
return;
|
||||
|
||||
int r;
|
||||
for(r = 1; r < items; r++) {
|
||||
char *str = SvPV_nolen(ST(r));
|
||||
EQW::Singleton()->AppendOutput(str);
|
||||
}
|
||||
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
EQW::EQW() {
|
||||
}
|
||||
|
||||
void EQW::AppendOutput(const char *str) {
|
||||
m_outputBuffer += str;
|
||||
// Log.LogDebugType(Logs::Detail, Logs::World_Server, "Append %d chars, yeilding result of length %d", strlen(str), m_outputBuffer.length());
|
||||
}
|
||||
|
||||
const std::string &EQW::GetOutput() const {
|
||||
// Log.LogDebugType(Logs::Detail, Logs::World_Server, "Getting, length %d", m_outputBuffer.length());
|
||||
return(m_outputBuffer);
|
||||
}
|
||||
|
||||
void EQW::LockWorld() {
|
||||
WorldConfig::LockWorld();
|
||||
if (LoginServerList::Instance()->Connected()) {
|
||||
LoginServerList::Instance()->SendStatus();
|
||||
}
|
||||
}
|
||||
|
||||
void EQW::UnlockWorld() {
|
||||
WorldConfig::UnlockWorld();
|
||||
if (LoginServerList::Instance()->Connected()) {
|
||||
LoginServerList::Instance()->SendStatus();
|
||||
}
|
||||
}
|
||||
|
||||
Const_char *EQW::GetConfig(Const_char *var_name) {
|
||||
m_returnBuffer = WorldConfig::get()->GetByName(var_name);
|
||||
return(m_returnBuffer.c_str());
|
||||
}
|
||||
|
||||
bool EQW::LSConnected() {
|
||||
return(LoginServerList::Instance()->Connected());
|
||||
}
|
||||
|
||||
int EQW::CountZones() {
|
||||
return(ZSList::Instance()->GetZoneCount());
|
||||
}
|
||||
|
||||
//returns an array of zone_refs (opaque)
|
||||
std::vector<std::string> EQW::ListBootedZones() {
|
||||
std::vector<std::string> res;
|
||||
|
||||
std::vector<uint32> zones;
|
||||
ZSList::Instance()->GetZoneIDList(zones);
|
||||
|
||||
std::vector<uint32>::iterator cur, end;
|
||||
cur = zones.begin();
|
||||
end = zones.end();
|
||||
for(; cur != end; ++cur) {
|
||||
res.push_back(itoa(*cur));
|
||||
}
|
||||
|
||||
return(res);
|
||||
}
|
||||
|
||||
std::map<std::string,std::string> EQW::GetZoneDetails(Const_char *zone_ref) {
|
||||
std::map<std::string,std::string> res;
|
||||
|
||||
ZoneServer *zs = ZSList::Instance()->FindByID(Strings::ToInt(zone_ref));
|
||||
if(zs == nullptr) {
|
||||
res["error"] = "Invalid zone.";
|
||||
return(res);
|
||||
}
|
||||
|
||||
res["type"] = zs->IsStaticZone()?"static":"dynamic";
|
||||
res["zone_id"] = itoa(zs->GetZoneID());
|
||||
res["launch_name"] = zs->GetLaunchName();
|
||||
res["launched_name"] = zs->GetLaunchedName();
|
||||
res["short_name"] = zs->GetZoneName();
|
||||
res["long_name"] = zs->GetZoneLongName();
|
||||
res["port"] = itoa(zs->GetCPort());
|
||||
res["player_count"] = itoa(zs->NumPlayers());
|
||||
|
||||
//this isnt gunna work for dynamic zones...
|
||||
res["launcher"] = "";
|
||||
if(zs->GetZoneID() != 0) {
|
||||
LauncherLink *ll = launcher_list.FindByZone(zs->GetLaunchName());
|
||||
if(ll != nullptr)
|
||||
res["launcher"] = ll->GetName();
|
||||
}
|
||||
|
||||
return(res);
|
||||
}
|
||||
|
||||
int EQW::CountPlayers() {
|
||||
return(ClientList::Instance()->GetClientCount());
|
||||
}
|
||||
|
||||
//returns an array of character names in the zone (empty=all zones)
|
||||
std::vector<std::string> EQW::ListPlayers(Const_char *zone_name) {
|
||||
std::vector<std::string> res;
|
||||
|
||||
std::vector<ClientListEntry *> list;
|
||||
ClientList::Instance()->GetClients(zone_name, list);
|
||||
|
||||
std::vector<ClientListEntry *>::iterator cur, end;
|
||||
cur = list.begin();
|
||||
end = list.end();
|
||||
for(; cur != end; ++cur) {
|
||||
res.push_back((*cur)->name());
|
||||
}
|
||||
return(res);
|
||||
}
|
||||
|
||||
std::map<std::string,std::string> EQW::GetPlayerDetails(Const_char *char_name) {
|
||||
std::map<std::string,std::string> res;
|
||||
|
||||
ClientListEntry *cle = ClientList::Instance()->FindCharacter(char_name);
|
||||
if(cle == nullptr) {
|
||||
res["error"] = "1";
|
||||
return(res);
|
||||
}
|
||||
|
||||
res["character"] = cle->name();
|
||||
res["account"] = cle->AccountName();
|
||||
res["account_id"] = itoa(cle->AccountID());
|
||||
res["location_short"] = cle->zone()?ZoneName(cle->zone()):"No Zone";
|
||||
res["location_long"] = res["location_short"];
|
||||
res["location_id"] = itoa(cle->zone());
|
||||
res["ip"] = long2ip(cle->GetIP());
|
||||
res["level"] = itoa(cle->level());
|
||||
res["race"] = GetRaceIDName(cle->race());
|
||||
res["race_id"] = itoa(cle->race());
|
||||
res["class"] = GetClassIDName(cle->class_());
|
||||
res["class_id"] = itoa(cle->class_());
|
||||
res["guild_id"] = itoa(cle->GuildID());
|
||||
res["guild"] = guild_mgr.GetGuildName(cle->GuildID());
|
||||
res["status"] = itoa(cle->Admin());
|
||||
// res["patch"] = cle->DescribePatch();
|
||||
|
||||
return(res);
|
||||
}
|
||||
|
||||
int EQW::CountLaunchers(bool active_only) {
|
||||
if(active_only)
|
||||
return(launcher_list.GetLauncherCount());
|
||||
|
||||
std::vector<std::string> it(EQW::ListLaunchers());
|
||||
return(it.size());
|
||||
}
|
||||
/*
|
||||
vector<string> EQW::ListActiveLaunchers() {
|
||||
vector<string> launchers;
|
||||
launcher_list.GetLauncherNameList(launchers);
|
||||
return(launchers);
|
||||
}*/
|
||||
|
||||
std::vector<std::string> EQW::ListLaunchers() {
|
||||
// vector<string> list;
|
||||
// database.GetLauncherList(list);
|
||||
std::vector<std::string> launchers;
|
||||
launcher_list.GetLauncherNameList(launchers);
|
||||
return(launchers);
|
||||
|
||||
/* if(list.empty()) {
|
||||
return(launchers);
|
||||
} else if(launchers.empty()) {
|
||||
return(list);
|
||||
}
|
||||
|
||||
//union the two lists.
|
||||
vector<string>::iterator curo, endo, curi, endi;
|
||||
curo = list.begin();
|
||||
endo = list.end();
|
||||
for(; curo != endo; curo++) {
|
||||
bool found = false;
|
||||
curi = launchers.begin();
|
||||
endi = launchers.end();
|
||||
for(; curi != endi; curi++) {
|
||||
if(*curo == *curi) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(found)
|
||||
break;
|
||||
launchers.push_back(*curo);
|
||||
}
|
||||
return(launchers);*/
|
||||
}
|
||||
|
||||
EQLConfig * EQW::GetLauncher(Const_char *launcher_name) {
|
||||
return(launcher_list.GetConfig(launcher_name));
|
||||
}
|
||||
|
||||
void EQW::CreateLauncher(Const_char *launcher_name, int dynamic_count) {
|
||||
launcher_list.CreateLauncher(launcher_name, dynamic_count);
|
||||
}
|
||||
|
||||
uint32 EQW::CreateGuild(const char* name, uint32 leader_char_id) {
|
||||
uint32 id = guild_mgr.CreateGuild(name, leader_char_id);
|
||||
if(id != GUILD_NONE)
|
||||
ClientList::Instance()->UpdateClientGuild(leader_char_id, id);
|
||||
return(id);
|
||||
}
|
||||
|
||||
bool EQW::DeleteGuild(uint32 guild_id) {
|
||||
return(guild_mgr.DeleteGuild(guild_id));
|
||||
}
|
||||
|
||||
bool EQW::RenameGuild(uint32 guild_id, const char* name) {
|
||||
return(guild_mgr.RenameGuild(guild_id, name));
|
||||
}
|
||||
|
||||
bool EQW::SetGuildMOTD(uint32 guild_id, const char* motd, const char *setter) {
|
||||
return(guild_mgr.SetGuildMOTD(guild_id, motd, setter));
|
||||
}
|
||||
|
||||
bool EQW::SetGuildLeader(uint32 guild_id, uint32 leader_char_id) {
|
||||
return(guild_mgr.SetGuildLeader(guild_id, leader_char_id));
|
||||
}
|
||||
|
||||
bool EQW::SetGuild(uint32 charid, uint32 guild_id, uint8 rank) {
|
||||
ClientList::Instance()->UpdateClientGuild(charid, guild_id);
|
||||
return(guild_mgr.SetGuild(charid, guild_id, rank));
|
||||
}
|
||||
|
||||
bool EQW::SetGuildRank(uint32 charid, uint8 rank) {
|
||||
return(guild_mgr.SetGuildRank(charid, rank));
|
||||
}
|
||||
|
||||
bool EQW::SetBankerFlag(uint32 charid, bool is_banker) {
|
||||
return(guild_mgr.SetBankerFlag(charid, is_banker));
|
||||
}
|
||||
|
||||
bool EQW::SetTributeFlag(uint32 charid, bool enabled) {
|
||||
return(guild_mgr.SetTributeFlag(charid, enabled));
|
||||
}
|
||||
|
||||
bool EQW::SetPublicNote(uint32 charid, const char *note) {
|
||||
return(guild_mgr.SetPublicNote(charid, note));
|
||||
}
|
||||
|
||||
int EQW::CountBugs() {
|
||||
std::string query = "SELECT count(*) FROM bugs where status = 0";
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success())
|
||||
return 0;
|
||||
|
||||
if (results.RowCount() == 0)
|
||||
return 0;
|
||||
|
||||
auto row = results.begin();
|
||||
return Strings::ToInt(row[0]);
|
||||
}
|
||||
|
||||
std::vector<std::string> EQW::ListBugs(uint32 offset) {
|
||||
std::vector<std::string> res;
|
||||
std::string query = StringFormat("SELECT id FROM bugs WHERE status = 0 limit %d, 30", offset);
|
||||
auto results = database.QueryDatabase(query);
|
||||
|
||||
if (!results.Success())
|
||||
return res;
|
||||
|
||||
for (auto row = results.begin();row != results.end(); ++row)
|
||||
res.push_back(row[0]);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
std::map<std::string,std::string> EQW::GetBugDetails(Const_char *id) {
|
||||
std::map<std::string,std::string> res;
|
||||
std::string query = StringFormat("SELECT name, zone, x, y, z, target, bug FROM bugs WHERE id = %s", id);
|
||||
auto results = database.QueryDatabase(query);
|
||||
|
||||
if (!results.Success())
|
||||
return res;
|
||||
|
||||
for(auto row = results.begin(); row != results.end(); ++row) {
|
||||
res["name"] = row[0];
|
||||
res["zone"] = row[1];
|
||||
res["x"] = row[2];
|
||||
res["y"] = row[3];
|
||||
res["z"] = row[4];
|
||||
res["target"] = row[5];
|
||||
res["bug"] = row[6];
|
||||
res["id"] = id;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void EQW::ResolveBug(const char *id) {
|
||||
std::vector<std::string> res;
|
||||
std::string query = StringFormat("UPDATE bugs SET status=1 WHERE id=%s", id);
|
||||
database.QueryDatabase(query);
|
||||
}
|
||||
|
||||
void EQW::SendMessage(uint32 type, const char *msg) {
|
||||
ZSList::Instance()->SendEmoteMessage(
|
||||
0,
|
||||
0,
|
||||
AccountStatus::Player,
|
||||
type,
|
||||
msg
|
||||
);
|
||||
}
|
||||
|
||||
void EQW::WorldShutDown(uint32 time, uint32 interval) {
|
||||
ZSList::Instance()->WorldShutDown(time, interval);
|
||||
}
|
||||
|
||||
#endif //EMBPERL
|
||||
|
||||
-93
@@ -1,93 +0,0 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net)
|
||||
|
||||
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; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||
are required to give you total support for your newly bought product;
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef EQW_H_
|
||||
#define EQW_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "../common/types.h"
|
||||
|
||||
class EQLConfig;
|
||||
|
||||
//this is the main object exported to perl.
|
||||
class EQW {
|
||||
EQW();
|
||||
public:
|
||||
static EQW *Singleton() { return(&s_EQW); }
|
||||
|
||||
void AppendOutput(const char *str);
|
||||
const std::string &GetOutput() const;
|
||||
void ClearOutput() { m_outputBuffer = ""; }
|
||||
|
||||
//BEGIN PERL EXPORT
|
||||
//NOTE: you must have a space after the * of a return value
|
||||
Const_char * GetConfig(Const_char *var_name);
|
||||
void LockWorld();
|
||||
void UnlockWorld();
|
||||
|
||||
bool LSConnected();
|
||||
|
||||
int CountZones();
|
||||
std::vector<std::string> ListBootedZones(); //returns an array of zone_refs (opaque)
|
||||
std::map<std::string,std::string> GetZoneDetails(Const_char *zone_ref); //returns a hash ref of details
|
||||
|
||||
int CountPlayers();
|
||||
std::vector<std::string> ListPlayers(Const_char *zone_name = ""); //returns an array of player refs (opaque)
|
||||
std::map<std::string,std::string> GetPlayerDetails(Const_char *player_ref); //returns a hash ref of details
|
||||
|
||||
int CountLaunchers(bool active_only);
|
||||
// vector<string> ListActiveLaunchers(); //returns an array of launcher names
|
||||
std::vector<std::string> ListLaunchers(); //returns an array of launcher names
|
||||
EQLConfig * GetLauncher(Const_char *launcher_name); //returns the EQLConfig object for the specified launcher.
|
||||
void CreateLauncher(Const_char *launcher_name, int dynamic_count);
|
||||
// EQLConfig * FindLauncher(Const_char *zone_ref);
|
||||
|
||||
//Guild routines, mostly wrappers around guild_mgr
|
||||
uint32 CreateGuild(const char* name, uint32 leader_char_id);
|
||||
bool DeleteGuild(uint32 guild_id);
|
||||
bool RenameGuild(uint32 guild_id, const char* name);
|
||||
bool SetGuildMOTD(uint32 guild_id, const char* motd, const char *setter);
|
||||
bool SetGuildLeader(uint32 guild_id, uint32 leader_char_id);
|
||||
bool SetGuild(uint32 charid, uint32 guild_id, uint8 rank);
|
||||
bool SetGuildRank(uint32 charid, uint8 rank);
|
||||
bool SetBankerFlag(uint32 charid, bool is_banker);
|
||||
bool SetTributeFlag(uint32 charid, bool enabled);
|
||||
bool SetPublicNote(uint32 charid, const char *note);
|
||||
|
||||
//bugs
|
||||
int CountBugs();
|
||||
std::vector<std::string> ListBugs(uint32 offset); //returns an array of zone_refs (opaque)
|
||||
std::map<std::string,std::string> GetBugDetails(const char *id);
|
||||
void ResolveBug(const char *id);
|
||||
|
||||
void SendMessage(uint32 type, const char *msg);
|
||||
void WorldShutDown(uint32 time, uint32 interval);
|
||||
//END PERL EXPORT
|
||||
|
||||
protected:
|
||||
std::string m_outputBuffer;
|
||||
std::string m_returnBuffer;
|
||||
|
||||
bool m_worldLocked;
|
||||
|
||||
private:
|
||||
static EQW s_EQW;
|
||||
};
|
||||
|
||||
#endif /*EQW_H_*/
|
||||
@@ -1,335 +0,0 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net)
|
||||
|
||||
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; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||
are required to give you total support for your newly bought product;
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "../common/global_define.h"
|
||||
#include "eqw_http_handler.h"
|
||||
#include "../common/SocketLib/Base64.h"
|
||||
#include "eqw_parser.h"
|
||||
#include "eqw.h"
|
||||
#include "http_request.h"
|
||||
|
||||
#include "worlddb.h"
|
||||
#include "console.h"
|
||||
|
||||
Mime EQWHTTPHandler::s_mime;
|
||||
#ifdef EMBPERL
|
||||
EQWParser *EQWHTTPHandler::s_parser = nullptr;
|
||||
#endif
|
||||
const int EQWHTTPHandler::READ_BUFFER_LEN = 1024; //for page IO, was a static const member, but VC6 got mad.
|
||||
|
||||
EQWHTTPHandler::EQWHTTPHandler(uint32 ID, SOCKET in_socket, uint32 irIP, uint16 irPort)
|
||||
: HttpdSocket(ID,in_socket,irIP,irPort),
|
||||
m_closeOnFinish(false)
|
||||
{
|
||||
}
|
||||
|
||||
EQWHTTPHandler::~EQWHTTPHandler() {
|
||||
|
||||
}
|
||||
|
||||
#ifdef EMBPERL
|
||||
EQWParser *EQWHTTPHandler::GetParser() {
|
||||
if(s_parser == nullptr) {
|
||||
EQW::Singleton()->ClearOutput();
|
||||
s_parser = new EQWParser();
|
||||
const std::string &res = EQW::Singleton()->GetOutput();
|
||||
if(!res.empty()) {
|
||||
printf("EQWParser Init output:\n%s\n\n", res.c_str());
|
||||
EQW::Singleton()->ClearOutput();
|
||||
}
|
||||
}
|
||||
return(s_parser);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*void EQWHTTPHandler::OnWrite() {
|
||||
HttpdSocket::OnWrite();
|
||||
if(m_closeOnFinish && GetOutputLength() == 0) {
|
||||
// printf("CLOSING\n");
|
||||
Close();
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
void EQWHTTPHandler::Exec() {
|
||||
m_sentHeaders = false;
|
||||
m_responseCode = "200";
|
||||
// printf("Request: %s, %s, %s, %s.\n", GetMethod().c_str(), GetUrl().c_str(), GetUri().c_str(), GetQueryString().c_str());
|
||||
|
||||
SetHttpVersion("HTTP/1.0");
|
||||
AddResponseHeader("Connection", "close");
|
||||
|
||||
if(GetUri().find("..") != std::string::npos) {
|
||||
SendResponse("403", "Forbidden");
|
||||
printf("%s is forbidden.\n", GetUri().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if(!CheckAuth()) {
|
||||
AddResponseHeader("Content-type", "text/plain");
|
||||
AddResponseHeader("WWW-Authenticate", "Basic realm=\"EQEmulator\"");
|
||||
SendResponse("401", "Authorization Required");
|
||||
SendString("Gotta Authenticate.");
|
||||
} else {
|
||||
std::string::size_type start = GetUri().find_first_not_of('/');
|
||||
std::string page;
|
||||
if(start != std::string::npos)
|
||||
page = GetUri().substr(start);
|
||||
else
|
||||
page = "index.html";
|
||||
SendPage(page);
|
||||
}
|
||||
/* if (!Detach()) {
|
||||
printf("Unable to detach...\n");
|
||||
}
|
||||
if(GetOutputLength() > 0) {
|
||||
//we cannot close yet
|
||||
m_closeOnFinish = true;
|
||||
} else {
|
||||
Close();
|
||||
}*/
|
||||
Free(); //the "app" side (us) is done with this connection too...
|
||||
Disconnect();
|
||||
}
|
||||
|
||||
void EQWHTTPHandler::OnHeader(const std::string& key,const std::string& value) {
|
||||
HttpdSocket::OnHeader(key, value);
|
||||
|
||||
if (!strcasecmp(key.c_str(),"Authorization")) {
|
||||
if(strncasecmp(value.c_str(), "Basic ", 6)) {
|
||||
printf("Invalid auth type. Expected Basic: %s\n", value.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
std::string dec;
|
||||
Base64::decode(value.c_str() + 6, dec);
|
||||
|
||||
std::string::size_type cpos;
|
||||
cpos = dec.find_first_of(':');
|
||||
if(cpos == std::string::npos) {
|
||||
printf("Invalid auth string: %s\n", dec.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
m_username = dec.substr(0, cpos);
|
||||
m_password = dec.substr(cpos+1);
|
||||
}
|
||||
}
|
||||
|
||||
//we should prolly cache login info here... if we load a fresh page, we could be checking
|
||||
//their auth dozens of times rather quickly...
|
||||
bool EQWHTTPHandler::CheckAuth() const {
|
||||
if(m_username.length() < 1)
|
||||
return(false);
|
||||
|
||||
int16 status = 0;
|
||||
uint32 acctid = database.CheckLogin(m_username.c_str(), m_password.c_str(), &status);
|
||||
if(acctid == 0) {
|
||||
LogInfo("Login autentication failed for [{}] with [{}]", m_username.c_str(), m_password.c_str());
|
||||
return(false);
|
||||
}
|
||||
if(status < httpLoginStatus) {
|
||||
LogInfo("Login of [{}] failed: status too low", m_username.c_str());
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void EQWHTTPHandler::SendPage(const std::string &file) {
|
||||
|
||||
std::string path = "templates/";
|
||||
path += file;
|
||||
|
||||
FILE *f = fopen(path.c_str(), "rb");
|
||||
if(f == nullptr) {
|
||||
SendResponse("404", "Not Found");
|
||||
SendString("Not found.");
|
||||
printf("%s not found.\n", file.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
std::string type = s_mime.GetMimeFromFilename(file);
|
||||
AddResponseHeader("Content-type", type);
|
||||
|
||||
bool process = false;
|
||||
#ifdef EMBPERL
|
||||
if(type == "text/html")
|
||||
process = true;
|
||||
else {
|
||||
//not processing, send headers right away
|
||||
#endif
|
||||
SendResponse("200", "OK");
|
||||
#ifdef EMBPERL
|
||||
}
|
||||
#endif
|
||||
|
||||
auto buffer = new char[READ_BUFFER_LEN + 1];
|
||||
size_t len;
|
||||
std::string to_process;
|
||||
while((len = fread(buffer, 1, READ_BUFFER_LEN, f)) > 0) {
|
||||
buffer[len] = '\0';
|
||||
if(process)
|
||||
to_process += buffer;
|
||||
else
|
||||
SendBuf(buffer, len);
|
||||
}
|
||||
delete[] buffer;
|
||||
fclose(f);
|
||||
#ifdef EMBPERL
|
||||
if(process) {
|
||||
//convert the base form into a useful perl exportable form
|
||||
HTTPRequest req(this, GetHttpForm());
|
||||
GetParser()->SetHTTPRequest("testing", &req);
|
||||
|
||||
//parse out the page and potentially pass some stuff on to perl.
|
||||
ProcessAndSend(to_process);
|
||||
|
||||
//clear out the form, just in case (since it gets destroyed next)
|
||||
GetParser()->SetHTTPRequest("testing", nullptr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool EQWHTTPHandler::LoadMimeTypes(const char *filename) {
|
||||
return(s_mime.LoadMimeFile(filename));
|
||||
}
|
||||
|
||||
#ifdef EMBPERL
|
||||
void EQWHTTPHandler::ProcessAndSend(const std::string &str) {
|
||||
std::string::size_type len = str.length();
|
||||
std::string::size_type start = 0;
|
||||
std::string::size_type pos, end;
|
||||
|
||||
while((pos = str.find("<?", start)) != std::string::npos) {
|
||||
//send all the crap leading up to the script block
|
||||
if(pos != start) {
|
||||
ProcessText(str.c_str() + start, pos-start);
|
||||
}
|
||||
|
||||
//look for the end of this script block...
|
||||
end = str.find("?>", pos+2);
|
||||
if(end == std::string::npos) {
|
||||
//terminal ?> not found... should issue a warning or something...
|
||||
std::string scriptBody = str.substr(pos+2);
|
||||
ProcessScript(scriptBody);
|
||||
start = len;
|
||||
break;
|
||||
} else {
|
||||
//script only consumes some of this buffer...
|
||||
std::string scriptBody = str.substr(pos+2, end-pos-2);
|
||||
ProcessScript(scriptBody);
|
||||
start = end + 2;
|
||||
}
|
||||
}
|
||||
|
||||
//send whatever is left over
|
||||
if(start != len)
|
||||
ProcessText(str.c_str() + start, len-start);
|
||||
}
|
||||
|
||||
void EQWHTTPHandler::ProcessScript(const std::string &script_body) {
|
||||
const char *script = script_body.c_str();
|
||||
if(strcmp("perl", script) == 0)
|
||||
script += 4; //allow <?perl
|
||||
|
||||
// printf("Script: ''''%s''''\n\n", script_body.c_str());
|
||||
|
||||
GetParser()->EQW_eval("testing", script_body.c_str());
|
||||
const std::string &res = EQW::Singleton()->GetOutput();
|
||||
if(!res.empty()) {
|
||||
ProcessText(res.c_str(), res.length());
|
||||
EQW::Singleton()->ClearOutput();
|
||||
}
|
||||
}
|
||||
|
||||
void EQWHTTPHandler::ProcessText(const char *txt, int len) {
|
||||
if(!m_sentHeaders) {
|
||||
SendResponse(m_responseCode, "OK");
|
||||
m_sentHeaders = true;
|
||||
}
|
||||
SendBuf(txt, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
EQWHTTPServer::EQWHTTPServer()
|
||||
: m_port(0)
|
||||
{
|
||||
}
|
||||
|
||||
void EQWHTTPServer::CreateNewConnection(uint32 ID, SOCKET in_socket, uint32 irIP, uint16 irPort) {
|
||||
auto conn = new EQWHTTPHandler(ID, in_socket, irIP, irPort);
|
||||
AddConnection(conn);
|
||||
}
|
||||
|
||||
void EQWHTTPServer::Stop() {
|
||||
LogInfo("Requesting that HTTP Service stop");
|
||||
m_running = false;
|
||||
Close();
|
||||
}
|
||||
|
||||
bool EQWHTTPServer::Start(uint16 port, const char *mime_file) {
|
||||
if(m_running) {
|
||||
LogInfo("HTTP Service is already running on port [{}]", m_port);
|
||||
return(false);
|
||||
}
|
||||
|
||||
//load up our nice mime types
|
||||
if(!EQWHTTPHandler::LoadMimeTypes(mime_file)) {
|
||||
LogInfo("Failed to load mime types from [{}]", mime_file);
|
||||
return(false);
|
||||
} else {
|
||||
LogInfo("Loaded mime types from [{}]", mime_file);
|
||||
}
|
||||
|
||||
//fire up the server thread
|
||||
char errbuf[TCPServer_ErrorBufferSize];
|
||||
if(!Open(port, errbuf)) {
|
||||
LogInfo("Unable to bind to port [{}] for HTTP service: [{}]", port, errbuf);
|
||||
return(false);
|
||||
}
|
||||
|
||||
m_running = true;
|
||||
m_port = port;
|
||||
|
||||
/*
|
||||
|
||||
#ifdef _WINDOWS
|
||||
_beginthread(ThreadProc, 0, this);
|
||||
#else
|
||||
pthread_create(&m_thread, nullptr, ThreadProc, this);
|
||||
#endif*/
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
/*
|
||||
void EQWHTTPServer::Run() {
|
||||
Log.LogDebugType(Logs::Detail, Logs::World_Server, "HTTP Processing thread started on port %d", m_port);
|
||||
do {
|
||||
#warning DELETE THIS IF YOU DONT USE IT
|
||||
Sleep(10);
|
||||
} while(m_running);
|
||||
Log.LogDebugType(Logs::Detail, Logs::World_Server, "HTTP Processing thread terminating on port %d", m_port);
|
||||
}
|
||||
|
||||
ThreadReturnType EQWHTTPServer::ThreadProc(void *data) {
|
||||
((EQWHTTPServer *) data)->Run();
|
||||
THREAD_RETURN(nullptr);
|
||||
}*/
|
||||
|
||||
@@ -1,348 +0,0 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net)
|
||||
|
||||
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; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||
are required to give you total support for your newly bought product;
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
//a lot of this is copied from embperl.cpp, but I didnt feel like factoring the common stuff out
|
||||
|
||||
#ifdef EMBPERL
|
||||
|
||||
#include "../common/global_define.h"
|
||||
#include "eqw_parser.h"
|
||||
#include "eqw.h"
|
||||
#include "../common/eqdb.h"
|
||||
|
||||
#include "worlddb.h"
|
||||
|
||||
#ifndef GvCV_set
|
||||
#define GvCV_set(gv,cv) (GvCV(gv) = (cv))
|
||||
#endif
|
||||
|
||||
XS(XS_EQWIO_PRINT);
|
||||
|
||||
//so embedded scripts can use xs extensions (ala 'use socket;')
|
||||
EXTERN_C void boot_DynaLoader(pTHX_ CV* cv);
|
||||
EXTERN_C XS(boot_EQW);
|
||||
EXTERN_C XS(boot_EQDB);
|
||||
EXTERN_C XS(boot_EQDBRes);
|
||||
EXTERN_C XS(boot_HTTPRequest);
|
||||
EXTERN_C XS(boot_EQLConfig);
|
||||
|
||||
EXTERN_C void xs_init(pTHX)
|
||||
{
|
||||
char file[256];
|
||||
strncpy(file, __FILE__, 256);
|
||||
file[255] = '\0';
|
||||
|
||||
char buf[128]; //shouldent have any function names longer than this.
|
||||
|
||||
//add the strcpy stuff to get rid of const warnings....
|
||||
|
||||
newXS(strcpy(buf, "DynaLoader::boot_DynaLoader"), boot_DynaLoader, file);
|
||||
newXS(strcpy(buf, "EQW::boot_EQW"), boot_EQW, file);
|
||||
newXS(strcpy(buf, "EQDB::boot_EQDB"), boot_EQDB, file);
|
||||
newXS(strcpy(buf, "EQDBRes::boot_EQDBRes"), boot_EQDBRes, file);
|
||||
newXS(strcpy(buf, "HTTPRequest::boot_HTTPRequest"), boot_HTTPRequest, file);
|
||||
newXS(strcpy(buf, "EQLConfig::boot_EQLConfig"), boot_EQLConfig, file);
|
||||
newXS(strcpy(buf, "EQWIO::PRINT"), XS_EQWIO_PRINT, file);
|
||||
}
|
||||
|
||||
EQWParser::EQWParser() {
|
||||
//setup perl...
|
||||
my_perl = perl_alloc();
|
||||
_empty_sv = newSV(0);
|
||||
if (!my_perl) {
|
||||
LogInfo("Error: perl_alloc failed!");
|
||||
}
|
||||
else {
|
||||
DoInit();
|
||||
}
|
||||
}
|
||||
|
||||
void EQWParser::DoInit() {
|
||||
const char *argv_eqemu[] = { "",
|
||||
"-w", "-W",
|
||||
"-e", "0;", nullptr };
|
||||
|
||||
int argc = 5;
|
||||
|
||||
char **argv = (char **)argv_eqemu;
|
||||
char **env = { nullptr };
|
||||
|
||||
PL_perl_destruct_level = 1;
|
||||
|
||||
perl_construct(my_perl);
|
||||
|
||||
PERL_SYS_INIT3(&argc, &argv, &env);
|
||||
|
||||
perl_parse(my_perl, xs_init, argc, argv, env);
|
||||
|
||||
perl_run(my_perl);
|
||||
|
||||
//a little routine we use a lot.
|
||||
eval_pv("sub my_eval {eval $_[0];}", TRUE); //dies on error
|
||||
|
||||
//ruin the perl exit and command:
|
||||
eval_pv("sub my_exit {}",TRUE);
|
||||
eval_pv("sub my_sleep {}",TRUE);
|
||||
if(gv_stashpv("CORE::GLOBAL", FALSE)) {
|
||||
GV *exitgp = gv_fetchpv("CORE::GLOBAL::exit", TRUE, SVt_PVCV);
|
||||
GvCV_set(exitgp, perl_get_cv("my_exit", TRUE)); //dies on error
|
||||
GvIMPORTED_CV_on(exitgp);
|
||||
GV *sleepgp = gv_fetchpv("CORE::GLOBAL::sleep", TRUE, SVt_PVCV);
|
||||
GvCV_set(sleepgp, perl_get_cv("my_sleep", TRUE)); //dies on error
|
||||
GvIMPORTED_CV_on(sleepgp);
|
||||
}
|
||||
|
||||
//setup eval_file
|
||||
eval_pv(
|
||||
"our %Cache;"
|
||||
"use Symbol qw(delete_package);"
|
||||
"sub eval_file {"
|
||||
"my($package, $filename) = @_;"
|
||||
"$filename=~s/\'//g;"
|
||||
"if(! -r $filename) { print \"Unable to read perl file '$filename'\\n\"; return; }"
|
||||
"my $mtime = -M $filename;"
|
||||
"if(defined $Cache{$package}{mtime}&&$Cache{$package}{mtime} <= $mtime && !($package eq 'plugin')){"
|
||||
" return;"
|
||||
"} else {"
|
||||
//we 'my' $filename,$mtime,$package,$sub to prevent them from changing our state up here.
|
||||
" eval(\"package $package; my(\\$filename,\\$mtime,\\$package,\\$sub); \\$isloaded = 1; require '$filename'; \");"
|
||||
"}"
|
||||
"}"
|
||||
,FALSE);
|
||||
|
||||
//make a tie-able class to capture IO and get it where it needs to go
|
||||
eval_pv(
|
||||
"package EQWIO; "
|
||||
// "&boot_EQEmuIO;"
|
||||
"sub TIEHANDLE { my $me = bless {}, $_[0]; $me->PRINT('Creating '.$me); return($me); } "
|
||||
"sub WRITE { } "
|
||||
"sub PRINTF { my $me = shift; my $fmt = shift; $me->PRINT(sprintf($fmt, @_)); } "
|
||||
"sub CLOSE { my $me = shift; $me->PRINT('Closing '.$me); } "
|
||||
"sub DESTROY { my $me = shift; $me->PRINT('Destroying '.$me); } "
|
||||
//this ties us for all packages
|
||||
"package MAIN;"
|
||||
" if(tied *STDOUT) { untie(*STDOUT); }"
|
||||
" if(tied *STDERR) { untie(*STDERR); }"
|
||||
" tie *STDOUT, 'EQWIO';"
|
||||
" tie *STDERR, 'EQWIO';"
|
||||
,FALSE);
|
||||
|
||||
eval_pv(
|
||||
"package world; "
|
||||
,FALSE
|
||||
);
|
||||
|
||||
//make sure the EQW pointer is set up in this package
|
||||
EQW *curc = EQW::Singleton();
|
||||
SV *l = get_sv("world::EQW", true);
|
||||
if(curc != nullptr) {
|
||||
sv_setref_pv(l, "EQW", curc);
|
||||
} else {
|
||||
//clear out the value, mainly to get rid of blessedness
|
||||
sv_setsv(l, _empty_sv);
|
||||
}
|
||||
|
||||
//make sure the EQDB pointer is set up in this package
|
||||
EQDB::SetMySQL(database.getMySQL());
|
||||
EQDB *curc_db = EQDB::Singleton();
|
||||
SV *l_db = get_sv("world::EQDB", true);
|
||||
if(curc_db != nullptr) {
|
||||
sv_setref_pv(l_db, "EQDB", curc_db);
|
||||
} else {
|
||||
//clear out the value, mainly to get rid of blessedness
|
||||
sv_setsv(l_db, _empty_sv);
|
||||
}
|
||||
|
||||
//load up EQW
|
||||
eval_pv(
|
||||
"package EQW;"
|
||||
"&boot_EQW;" //load our EQW XS
|
||||
"package EQDB;"
|
||||
"&boot_EQDB;" //load our EQW XS
|
||||
"package EQDBRes;"
|
||||
"&boot_EQDBRes;" //load our EQW XS
|
||||
"package HTTPRequest;"
|
||||
"&boot_HTTPRequest;" //load our HTTPRequest XS
|
||||
"package EQLConfig;"
|
||||
"&boot_EQLConfig;" //load our EQLConfig XS
|
||||
, FALSE );
|
||||
|
||||
|
||||
#ifdef EMBPERL_PLUGIN
|
||||
LogInfo("Loading worldui perl plugins");
|
||||
std::string err;
|
||||
if(!eval_file("world", "worldui.pl", err)) {
|
||||
LogInfo("Warning - world.pl: [{}]", err.c_str());
|
||||
}
|
||||
|
||||
eval_pv(
|
||||
"package world; "
|
||||
"if(opendir(D,'worldui')) { "
|
||||
" my @d = readdir(D);"
|
||||
" closedir(D);"
|
||||
" foreach(@d){ "
|
||||
" next unless(/\\.pl$); "
|
||||
" require 'templates/'.$_;"
|
||||
" }"
|
||||
"}"
|
||||
,FALSE);
|
||||
#endif //EMBPERL_PLUGIN
|
||||
}
|
||||
|
||||
EQWParser::~EQWParser() {
|
||||
//removed to try to stop perl from exploding on reload, we'll see
|
||||
/* eval_pv(
|
||||
"package quest;"
|
||||
" untie *STDOUT;"
|
||||
" untie *STDERR;"
|
||||
,FALSE);
|
||||
*/
|
||||
perl_free(my_perl);
|
||||
}
|
||||
|
||||
bool EQWParser::eval_file(const char * packagename, const char * filename, std::string &error)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
args.push_back(packagename);
|
||||
args.push_back(filename);
|
||||
return(dosub("eval_file", args, error));
|
||||
}
|
||||
|
||||
bool EQWParser::dosub(const char * subname, const std::vector<std::string> &args, std::string &error, int mode) {
|
||||
bool err = false;
|
||||
dSP; // initialize stack pointer
|
||||
ENTER; // everything created after here
|
||||
SAVETMPS; // ...is a temporary variable
|
||||
PUSHMARK(SP); // remember the stack pointer
|
||||
if(!args.empty())
|
||||
{
|
||||
for (auto i = args.begin(); i != args.end(); ++i) { /* push the arguments onto the perl stack */
|
||||
XPUSHs(sv_2mortal(newSVpv(i->c_str(), i->length())));
|
||||
}
|
||||
}
|
||||
PUTBACK; // make local stack pointer global
|
||||
call_pv(subname, mode); /*eval our code*/
|
||||
SPAGAIN; // refresh stack pointer
|
||||
if(SvTRUE(ERRSV)) {
|
||||
err = true;
|
||||
}
|
||||
FREETMPS; // free temp values
|
||||
LEAVE; // ...and the XPUSHed "mortal" args.
|
||||
|
||||
if(err) {
|
||||
error = "Perl runtime error: ";
|
||||
error += SvPVX(ERRSV);
|
||||
return(false);
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool EQWParser::eval(const char * code, std::string &error) {
|
||||
std::vector<std::string> arg;
|
||||
arg.push_back(code);
|
||||
return(dosub("my_eval", arg, error, G_SCALAR|G_DISCARD|G_EVAL|G_KEEPERR));
|
||||
}
|
||||
|
||||
void EQWParser::EQW_eval(const char *pkg, const char *code) {
|
||||
char namebuf[64];
|
||||
|
||||
snprintf(namebuf, 64, "package %s;", pkg);
|
||||
eval_pv(namebuf, FALSE);
|
||||
|
||||
//make sure the EQW pointer is set up
|
||||
EQW *curc = EQW::Singleton();
|
||||
snprintf(namebuf, 64, "EQW");
|
||||
// snprintf(namebuf, 64, "%s::EQW", pkg);
|
||||
SV *l = get_sv(namebuf, true);
|
||||
if(curc != nullptr) {
|
||||
sv_setref_pv(l, "EQW", curc);
|
||||
} else {
|
||||
//clear out the value, mainly to get rid of blessedness
|
||||
sv_setsv(l, _empty_sv);
|
||||
}
|
||||
//make sure the EQDB pointer is set up
|
||||
EQDB *curc_db = EQDB::Singleton();
|
||||
snprintf(namebuf, 64, "EQDB");
|
||||
// snprintf(namebuf, 64, "%s::EQW", pkg);
|
||||
SV *l_db = get_sv(namebuf, true);
|
||||
if(curc_db != nullptr) {
|
||||
sv_setref_pv(l_db, "EQDB", curc_db);
|
||||
} else {
|
||||
//clear out the value, mainly to get rid of blessedness
|
||||
sv_setsv(l_db, _empty_sv);
|
||||
}
|
||||
|
||||
std::string err;
|
||||
if(!eval(code, err)) {
|
||||
EQW::Singleton()->AppendOutput(err.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void EQWParser::SetHTTPRequest(const char *pkg, HTTPRequest *it) {
|
||||
char namebuf[64];
|
||||
|
||||
snprintf(namebuf, 64, "package %s;", pkg);
|
||||
eval_pv(namebuf, FALSE);
|
||||
|
||||
snprintf(namebuf, 64, "request");
|
||||
// snprintf(namebuf, 64, "%s::EQW", pkg);
|
||||
SV *l = get_sv(namebuf, true);
|
||||
if(it != nullptr) {
|
||||
sv_setref_pv(l, "HTTPRequest", it);
|
||||
} else {
|
||||
//clear out the value, mainly to get rid of blessedness
|
||||
sv_setsv(l, _empty_sv);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
$editors = array();
|
||||
$editors["merchant"] = new MerchantEditor();
|
||||
#... for other editors
|
||||
|
||||
if(defined($editors[$editor])) {
|
||||
$edit = $editors[$editor];
|
||||
$edit->dispatch($action);
|
||||
}
|
||||
|
||||
class MerchantEditor extends BaseEditor {
|
||||
MerchantEditor() {
|
||||
$this->RegisterAction(0, "get_merchantlist", "merchant/merchant.tmpl.php", "no");
|
||||
$this->RegisterAction(1, "get_merchantlist", "merchant/merchant.edit.tmpl.php", "no");
|
||||
}
|
||||
}
|
||||
|
||||
function dispatch() {
|
||||
my $dispatcher = $this->_dispatchers[$action];
|
||||
$body = new Template($dispatcher["template"]);
|
||||
my $proc = $dispatcher["proc"];
|
||||
$vars = $this->$proc();
|
||||
if($dispatcher["guestmode"] == "no") {
|
||||
check_authorization();
|
||||
}
|
||||
if ($vars) {
|
||||
foreach ($vars as $key=>$value) {
|
||||
$body->set($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
#endif //EMBPERL
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net)
|
||||
|
||||
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; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||
are required to give you total support for your newly bought product;
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "../common/global_define.h"
|
||||
#include "http_request.h"
|
||||
#include "eqw_http_handler.h"
|
||||
#include "../common/eqdb.h"
|
||||
#include "../common/SocketLib/HttpdForm.h"
|
||||
#include <cstdlib>
|
||||
|
||||
HTTPRequest::HTTPRequest(EQWHTTPHandler *h, HttpdForm *form)
|
||||
: m_handler(h)
|
||||
{
|
||||
std::string name, value;
|
||||
if(form->getfirst(name, value)) {
|
||||
m_values[name] = value;
|
||||
while(form->getnext(name, value))
|
||||
m_values[name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
const char *HTTPRequest::getEscaped(const char *name, const char *default_value) const {
|
||||
return(EQDB::Singleton()->escape_string(get(name, default_value)));
|
||||
}
|
||||
|
||||
const char *HTTPRequest::get(const char *name, const char *default_value) const {
|
||||
std::map<std::string, std::string>::const_iterator res;
|
||||
res = m_values.find(name);
|
||||
if(res == m_values.end())
|
||||
return(default_value);
|
||||
return(res->second.c_str());
|
||||
}
|
||||
|
||||
std::map<std::string,std::string> HTTPRequest::get_all() const {
|
||||
return m_values;
|
||||
}
|
||||
|
||||
int HTTPRequest::getInt(const char *name, int default_value) const {
|
||||
std::map<std::string, std::string>::const_iterator res;
|
||||
res = m_values.find(name);
|
||||
if(res == m_values.end())
|
||||
return(default_value);
|
||||
return(Strings::ToInt(res->second.c_str()));
|
||||
}
|
||||
|
||||
float HTTPRequest::getFloat(const char *name, float default_value) const {
|
||||
std::map<std::string, std::string>::const_iterator res;
|
||||
res = m_values.find(name);
|
||||
if(res == m_values.end())
|
||||
return(default_value);
|
||||
return(Strings::ToFloat(res->second.c_str()));
|
||||
}
|
||||
|
||||
void HTTPRequest::header(Const_char *name, Const_char *value) {
|
||||
m_handler->AddResponseHeader(name, value);
|
||||
}
|
||||
|
||||
void HTTPRequest::SetResponseCode(Const_char *code) {
|
||||
m_handler->SetResponseCode(code);
|
||||
}
|
||||
|
||||
void HTTPRequest::redirect(Const_char *URL) {
|
||||
header("Location", URL);
|
||||
SetResponseCode("302");
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net)
|
||||
|
||||
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; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||
are required to give you total support for your newly bought product;
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef HTTPREQUEST_H_
|
||||
#define HTTPREQUEST_H_
|
||||
|
||||
#include "../common/types.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
//this object acts as a friendlier interface to the HttpdForm object (perl exportable)
|
||||
//which does more effecient lookups
|
||||
|
||||
|
||||
class HttpdForm;
|
||||
class EQWHTTPHandler;
|
||||
|
||||
class HTTPRequest {
|
||||
public:
|
||||
HTTPRequest(EQWHTTPHandler *h, HttpdForm *form);
|
||||
|
||||
//BEGIN PERL EXPORT
|
||||
|
||||
Const_char * get(Const_char *name, Const_char *default_value = "") const;
|
||||
int getInt(Const_char *name, int default_value = 0) const;
|
||||
float getFloat(Const_char *name, float default_value = 0.0) const;
|
||||
|
||||
//returns a database-safe string
|
||||
Const_char * getEscaped(Const_char *name, Const_char *default_value = "") const;
|
||||
|
||||
std::map<std::string,std::string> get_all() const;
|
||||
|
||||
void redirect(Const_char *URL);
|
||||
void SetResponseCode(Const_char *code);
|
||||
void header(Const_char *name, Const_char *value);
|
||||
//END PERL EXPORT
|
||||
|
||||
protected:
|
||||
EQWHTTPHandler *const m_handler;
|
||||
std::map<std::string, std::string> m_values;
|
||||
};
|
||||
|
||||
#endif /*HTTPREQUEST_H_*/
|
||||
|
||||
Reference in New Issue
Block a user