Merge fix

This commit is contained in:
KimLS
2019-09-17 20:56:22 -07:00
231 changed files with 18003 additions and 13896 deletions
+18 -18
View File
@@ -47,8 +47,8 @@ ChatChannel::ChatChannel(std::string inName, std::string inOwner, std::string in
Moderated = false;
Log(Logs::Detail, Logs::UCS_Server, "New ChatChannel created: Name: [%s], Owner: [%s], Password: [%s], MinStatus: %i",
Name.c_str(), Owner.c_str(), Password.c_str(), MinimumStatus);
LogInfo("New ChatChannel created: Name: [[{}]], Owner: [[{}]], Password: [[{}]], MinStatus: [{}]",
Name.c_str(), Owner.c_str(), Password.c_str(), MinimumStatus);
}
@@ -154,7 +154,7 @@ void ChatChannelList::SendAllChannels(Client *c) {
void ChatChannelList::RemoveChannel(ChatChannel *Channel) {
Log(Logs::Detail, Logs::UCS_Server, "RemoveChannel(%s)", Channel->GetName().c_str());
LogInfo("RemoveChannel([{}])", Channel->GetName().c_str());
LinkedListIterator<ChatChannel*> iterator(ChatChannels);
@@ -175,7 +175,7 @@ void ChatChannelList::RemoveChannel(ChatChannel *Channel) {
void ChatChannelList::RemoveAllChannels() {
Log(Logs::Detail, Logs::UCS_Server, "RemoveAllChannels");
LogInfo("RemoveAllChannels");
LinkedListIterator<ChatChannel*> iterator(ChatChannels);
@@ -233,7 +233,7 @@ void ChatChannel::AddClient(Client *c) {
if(IsClientInChannel(c)) {
Log(Logs::Detail, Logs::UCS_Server, "Client %s already in channel %s", c->GetName().c_str(), GetName().c_str());
LogInfo("Client [{}] already in channel [{}]", c->GetName().c_str(), GetName().c_str());
return;
}
@@ -242,7 +242,7 @@ void ChatChannel::AddClient(Client *c) {
int AccountStatus = c->GetAccountStatus();
Log(Logs::Detail, Logs::UCS_Server, "Adding %s to channel %s", c->GetName().c_str(), Name.c_str());
LogInfo("Adding [{}] to channel [{}]", c->GetName().c_str(), Name.c_str());
LinkedListIterator<Client*> iterator(ClientsInChannel);
@@ -267,7 +267,7 @@ bool ChatChannel::RemoveClient(Client *c) {
if(!c) return false;
Log(Logs::Detail, Logs::UCS_Server, "RemoveClient %s from channel %s", c->GetName().c_str(), GetName().c_str());
LogInfo("RemoveClient [{}] from channel [{}]", c->GetName().c_str(), GetName().c_str());
bool HideMe = c->GetHideMe();
@@ -304,7 +304,7 @@ bool ChatChannel::RemoveClient(Client *c) {
if((Password.length() == 0) || (RuleI(Channels, DeleteTimer) == 0))
return false;
Log(Logs::Detail, Logs::UCS_Server, "Starting delete timer for empty password protected channel %s", Name.c_str());
LogInfo("Starting delete timer for empty password protected channel [{}]", Name.c_str());
DeleteTimer.Start(RuleI(Channels, DeleteTimer) * 60000);
}
@@ -402,8 +402,8 @@ void ChatChannel::SendMessageToChannel(std::string Message, Client* Sender) {
if(ChannelClient)
{
Log(Logs::Detail, Logs::UCS_Server, "Sending message to %s from %s",
ChannelClient->GetName().c_str(), Sender->GetName().c_str());
LogInfo("Sending message to [{}] from [{}]",
ChannelClient->GetName().c_str(), Sender->GetName().c_str());
if (cv_messages[static_cast<uint32>(ChannelClient->GetClientVersion())].length() == 0) {
switch (ChannelClient->GetClientVersion()) {
@@ -505,7 +505,7 @@ ChatChannel *ChatChannelList::AddClientToChannel(std::string ChannelName, Client
return nullptr;
}
Log(Logs::Detail, Logs::UCS_Server, "AddClient to channel [%s] with password [%s]", NormalisedName.c_str(), Password.c_str());
LogInfo("AddClient to channel [[{}]] with password [[{}]]", NormalisedName.c_str(), Password.c_str());
ChatChannel *RequiredChannel = FindChannel(NormalisedName);
@@ -581,7 +581,7 @@ void ChatChannelList::Process() {
if(CurrentChannel && CurrentChannel->ReadyToDelete()) {
Log(Logs::Detail, Logs::UCS_Server, "Empty temporary password protected channel %s being destroyed.",
LogInfo("Empty temporary password protected channel [{}] being destroyed",
CurrentChannel->GetName().c_str());
RemoveChannel(CurrentChannel);
@@ -597,7 +597,7 @@ void ChatChannel::AddInvitee(const std::string &Invitee)
if (!IsInvitee(Invitee)) {
Invitees.push_back(Invitee);
Log(Logs::Detail, Logs::UCS_Server, "Added %s as invitee to channel %s", Invitee.c_str(), Name.c_str());
LogInfo("Added [{}] as invitee to channel [{}]", Invitee.c_str(), Name.c_str());
}
}
@@ -608,7 +608,7 @@ void ChatChannel::RemoveInvitee(std::string Invitee)
if(it != std::end(Invitees)) {
Invitees.erase(it);
Log(Logs::Detail, Logs::UCS_Server, "Removed %s as invitee to channel %s", Invitee.c_str(), Name.c_str());
LogInfo("Removed [{}] as invitee to channel [{}]", Invitee.c_str(), Name.c_str());
}
}
@@ -622,7 +622,7 @@ void ChatChannel::AddModerator(const std::string &Moderator)
if (!IsModerator(Moderator)) {
Moderators.push_back(Moderator);
Log(Logs::Detail, Logs::UCS_Server, "Added %s as moderator to channel %s", Moderator.c_str(), Name.c_str());
LogInfo("Added [{}] as moderator to channel [{}]", Moderator.c_str(), Name.c_str());
}
}
@@ -633,7 +633,7 @@ void ChatChannel::RemoveModerator(const std::string &Moderator)
if (it != std::end(Moderators)) {
Moderators.erase(it);
Log(Logs::Detail, Logs::UCS_Server, "Removed %s as moderator to channel %s", Moderator.c_str(), Name.c_str());
LogInfo("Removed [{}] as moderator to channel [{}]", Moderator.c_str(), Name.c_str());
}
}
@@ -647,7 +647,7 @@ void ChatChannel::AddVoice(const std::string &inVoiced)
if (!HasVoice(inVoiced)) {
Voiced.push_back(inVoiced);
Log(Logs::Detail, Logs::UCS_Server, "Added %s as voiced to channel %s", inVoiced.c_str(), Name.c_str());
LogInfo("Added [{}] as voiced to channel [{}]", inVoiced.c_str(), Name.c_str());
}
}
@@ -658,7 +658,7 @@ void ChatChannel::RemoveVoice(const std::string &inVoiced)
if (it != std::end(Voiced)) {
Voiced.erase(it);
Log(Logs::Detail, Logs::UCS_Server, "Removed %s as voiced to channel %s", inVoiced.c_str(), Name.c_str());
LogInfo("Removed [{}] as voiced to channel [{}]", inVoiced.c_str(), Name.c_str());
}
}
+43 -47
View File
@@ -20,7 +20,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "../common/global_define.h"
#include "../common/string_util.h"
#include "../common/eqemu_logsys.h"
#include "../common/eqemu_logsys_fmt.h"
#include "../common/misc_functions.h"
#include "ucsconfig.h"
@@ -236,7 +235,7 @@ std::vector<std::string> ParseRecipients(std::string RecipientString) {
static void ProcessMailTo(Client *c, std::string MailMessage) {
Log(Logs::Detail, Logs::UCS_Server, "MAILTO: From %s, %s", c->MailBoxName().c_str(), MailMessage.c_str());
LogInfo("MAILTO: From [{}], [{}]", c->MailBoxName().c_str(), MailMessage.c_str());
std::vector<std::string> Recipients;
@@ -305,7 +304,7 @@ static void ProcessMailTo(Client *c, std::string MailMessage) {
if (!database.SendMail(Recipient, c->MailBoxName(), Subject, Body, RecipientsString)) {
Log(Logs::Detail, Logs::UCS_Server, "Failed in SendMail(%s, %s, %s, %s)", Recipient.c_str(),
LogInfo("Failed in SendMail([{}], [{}], [{}], [{}])", Recipient.c_str(),
c->MailBoxName().c_str(), Subject.c_str(), RecipientsString.c_str());
int PacketLength = 10 + Recipient.length() + Subject.length();
@@ -398,7 +397,7 @@ static void ProcessSetMessageStatus(std::string SetMessageCommand) {
static void ProcessCommandBuddy(Client *c, std::string Buddy) {
Log(Logs::Detail, Logs::UCS_Server, "Received buddy command with parameters %s", Buddy.c_str());
LogInfo("Received buddy command with parameters [{}]", Buddy.c_str());
c->GeneralChannelMessage("Buddy list modified");
uint8 SubAction = 1;
@@ -427,7 +426,7 @@ static void ProcessCommandBuddy(Client *c, std::string Buddy) {
static void ProcessCommandIgnore(Client *c, std::string Ignoree) {
Log(Logs::Detail, Logs::UCS_Server, "Received ignore command with parameters %s", Ignoree.c_str());
LogInfo("Received ignore command with parameters [{}]", Ignoree.c_str());
c->GeneralChannelMessage("Ignore list modified");
uint8 SubAction = 0;
@@ -483,12 +482,12 @@ Clientlist::Clientlist(int ChatPort) {
const ucsconfig *Config = ucsconfig::get();
Log(Logs::General, Logs::UCS_Server, "Loading '%s'", Config->MailOpCodesFile.c_str());
LogInfo("Loading [{}]", Config->MailOpCodesFile.c_str());
if (!ChatOpMgr->LoadOpcodes(Config->MailOpCodesFile.c_str()))
exit(1);
chatsf->OnNewConnection([this](std::shared_ptr<EQ::Net::EQStream> stream) {
LogF(Logs::General, Logs::Login_Server, "New Client UDP connection from {0}:{1}", stream->GetRemoteIP(), stream->GetRemotePort());
LogF(Logs::General, Logs::Loginserver, "New Client UDP connection from {0}:{1}", stream->GetRemoteIP(), stream->GetRemotePort());
stream->SetOpcodeManager(&ChatOpMgr);
auto c = new Client(stream);
@@ -568,13 +567,13 @@ void Clientlist::CheckForStaleConnections(Client *c) {
if (((*Iterator) != c) && ((c->GetName() == (*Iterator)->GetName())
&& (c->GetConnectionType() == (*Iterator)->GetConnectionType()))) {
Log(Logs::Detail, Logs::UCS_Server, "Removing old connection for %s", c->GetName().c_str());
LogInfo("Removing old connection for [{}]", c->GetName().c_str());
struct in_addr in;
in.s_addr = (*Iterator)->ClientStream->GetRemoteIP();
Log(Logs::Detail, Logs::UCS_Server, "Client connection from %s:%d closed.", inet_ntoa(in),
LogInfo("Client connection from [{}]:[{}] closed", inet_ntoa(in),
ntohs((*Iterator)->ClientStream->GetRemotePort()));
safe_delete((*Iterator));
@@ -593,7 +592,7 @@ void Clientlist::Process()
struct in_addr in;
in.s_addr = (*it)->ClientStream->GetRemoteIP();
Log(Logs::Detail, Logs::UCS_Server, "Client connection from %s:%d closed.", inet_ntoa(in),
LogInfo("Client connection from [{}]:[{}] closed", inet_ntoa(in),
ntohs((*it)->ClientStream->GetRemotePort()));
safe_delete((*it));
@@ -619,8 +618,7 @@ void Clientlist::Process()
VARSTRUCT_DECODE_STRING(MailBox, PacketBuffer);
if (strlen(PacketBuffer) != 9) {
Log(Logs::Detail, Logs::UCS_Server,
"Mail key is the wrong size. Version of world incompatible with UCS.");
LogInfo("Mail key is the wrong size. Version of world incompatible with UCS.");
KeyValid = false;
break;
}
@@ -641,12 +639,11 @@ void Clientlist::Process()
else
CharacterName = MailBoxString.substr(LastPeriod + 1);
Log(Logs::Detail, Logs::UCS_Server, "Received login for user %s with key %s",
LogInfo("Received login for user [{}] with key [{}]",
MailBox, Key);
if (!database.VerifyMailKey(CharacterName, (*it)->ClientStream->GetRemoteIP(), Key)) {
Log(Logs::Detail, Logs::UCS_Server,
"Chat Key for %s does not match, closing connection.", MailBox);
LogError("Chat Key for [{}] does not match, closing connection.", MailBox);
KeyValid = false;
break;
}
@@ -671,7 +668,7 @@ void Clientlist::Process()
}
default: {
Log(Logs::Detail, Logs::UCS_Server, "Unhandled chat opcode %8X", opcode);
LogInfo("Unhandled chat opcode {:#04x}", opcode);
break;
}
}
@@ -681,10 +678,9 @@ void Clientlist::Process()
struct in_addr in;
in.s_addr = (*it)->ClientStream->GetRemoteIP();
Log(Logs::Detail, Logs::UCS_Server,
"Force disconnecting client: %s:%d, KeyValid=%i, GetForceDisconnect()=%i",
inet_ntoa(in), ntohs((*it)->ClientStream->GetRemotePort()), KeyValid,
(*it)->GetForceDisconnect());
LogInfo("Force disconnecting client: [{}]:[{}], KeyValid=[{}], GetForceDisconnect()=[{}]",
inet_ntoa(in), ntohs((*it)->ClientStream->GetRemotePort()), KeyValid,
(*it)->GetForceDisconnect());
(*it)->ClientStream->Close();
@@ -824,7 +820,7 @@ void Clientlist::ProcessOPMailCommand(Client *c, std::string CommandString)
break;
case CommandSetMessageStatus:
Log(Logs::Detail, Logs::UCS_Server, "Set Message Status, Params: %s", Parameters.c_str());
LogInfo("Set Message Status, Params: [{}]", Parameters.c_str());
ProcessSetMessageStatus(Parameters);
break;
@@ -849,7 +845,7 @@ void Clientlist::ProcessOPMailCommand(Client *c, std::string CommandString)
default:
c->SendHelp();
Log(Logs::Detail, Logs::UCS_Server, "Unhandled OP_Mail command: %s", CommandString.c_str());
LogInfo("Unhandled OP_Mail command: [{}]", CommandString.c_str());
}
}
@@ -860,7 +856,7 @@ void Clientlist::CloseAllConnections() {
for (Iterator = ClientChatConnections.begin(); Iterator != ClientChatConnections.end(); ++Iterator) {
Log(Logs::Detail, Logs::UCS_Server, "Removing client %s", (*Iterator)->GetName().c_str());
LogInfo("Removing client [{}]", (*Iterator)->GetName().c_str());
(*Iterator)->CloseConnection();
}
@@ -869,7 +865,7 @@ void Clientlist::CloseAllConnections() {
void Client::AddCharacter(int CharID, const char *CharacterName, int Level) {
if (!CharacterName) return;
Log(Logs::Detail, Logs::UCS_Server, "Adding character %s with ID %i for %s", CharacterName, CharID, GetName().c_str());
LogInfo("Adding character [{}] with ID [{}] for [{}]", CharacterName, CharID, GetName().c_str());
CharacterEntry NewCharacter;
NewCharacter.CharID = CharID;
NewCharacter.Name = CharacterName;
@@ -934,7 +930,7 @@ void Client::AddToChannelList(ChatChannel *JoinedChannel) {
for (int i = 0; i < MAX_JOINED_CHANNELS; i++)
if (JoinedChannels[i] == nullptr) {
JoinedChannels[i] = JoinedChannel;
Log(Logs::Detail, Logs::UCS_Server, "Added Channel %s to slot %i for %s", JoinedChannel->GetName().c_str(), i + 1, GetName().c_str());
LogInfo("Added Channel [{}] to slot [{}] for [{}]", JoinedChannel->GetName().c_str(), i + 1, GetName().c_str());
return;
}
}
@@ -975,7 +971,7 @@ void Client::JoinChannels(std::string ChannelNameList) {
}
}
Log(Logs::Detail, Logs::UCS_Server, "Client: %s joining channels %s", GetName().c_str(), ChannelNameList.c_str());
LogInfo("Client: [{}] joining channels [{}]", GetName().c_str(), ChannelNameList.c_str());
int NumberOfChannels = ChannelCount();
@@ -1074,7 +1070,7 @@ void Client::JoinChannels(std::string ChannelNameList) {
void Client::LeaveChannels(std::string ChannelNameList) {
Log(Logs::Detail, Logs::UCS_Server, "Client: %s leaving channels %s", GetName().c_str(), ChannelNameList.c_str());
LogInfo("Client: [{}] leaving channels [{}]", GetName().c_str(), ChannelNameList.c_str());
std::string::size_type CurrentPos = 0;
@@ -1250,7 +1246,7 @@ void Client::SendChannelMessage(std::string Message)
std::string ChannelName = Message.substr(1, MessageStart - 1);
Log(Logs::Detail, Logs::UCS_Server, "%s tells %s, [%s]", GetName().c_str(), ChannelName.c_str(), Message.substr(MessageStart + 1).c_str());
LogInfo("[{}] tells [{}], [[{}]]", GetName().c_str(), ChannelName.c_str(), Message.substr(MessageStart + 1).c_str());
ChatChannel *RequiredChannel = ChannelList->FindChannel(ChannelName);
@@ -1393,7 +1389,7 @@ void Client::SendChannelMessageByNumber(std::string Message) {
}
}
Log(Logs::Detail, Logs::UCS_Server, "%s tells %s, [%s]", GetName().c_str(), RequiredChannel->GetName().c_str(),
LogInfo("[{}] tells [{}], [[{}]]", GetName().c_str(), RequiredChannel->GetName().c_str(),
Message.substr(MessageStart + 1).c_str());
if (RuleB(Chat, EnableAntiSpam))
@@ -1601,7 +1597,7 @@ void Client::SetChannelPassword(std::string ChannelPassword) {
else
Message = "Password change on channel " + ChannelName;
Log(Logs::Detail, Logs::UCS_Server, "Set password of channel [%s] to [%s] by %s", ChannelName.c_str(), Password.c_str(), GetName().c_str());
LogInfo("Set password of channel [[{}]] to [[{}]] by [{}]", ChannelName.c_str(), Password.c_str(), GetName().c_str());
ChatChannel *RequiredChannel = ChannelList->FindChannel(ChannelName);
@@ -1656,7 +1652,7 @@ void Client::SetChannelOwner(std::string CommandString) {
if ((ChannelName.length() > 0) && isdigit(ChannelName[0]))
ChannelName = ChannelSlotName(atoi(ChannelName.c_str()));
Log(Logs::Detail, Logs::UCS_Server, "Set owner of channel [%s] to [%s]", ChannelName.c_str(), NewOwner.c_str());
LogInfo("Set owner of channel [[{}]] to [[{}]]", ChannelName.c_str(), NewOwner.c_str());
ChatChannel *RequiredChannel = ChannelList->FindChannel(ChannelName);
@@ -1744,7 +1740,7 @@ void Client::ChannelInvite(std::string CommandString) {
if ((ChannelName.length() > 0) && isdigit(ChannelName[0]))
ChannelName = ChannelSlotName(atoi(ChannelName.c_str()));
Log(Logs::Detail, Logs::UCS_Server, "[%s] invites [%s] to channel [%s]", GetName().c_str(), Invitee.c_str(), ChannelName.c_str());
LogInfo("[[{}]] invites [[{}]] to channel [[{}]]", GetName().c_str(), Invitee.c_str(), ChannelName.c_str());
Client *RequiredClient = g_Clientlist->FindCharacter(Invitee);
@@ -1872,7 +1868,7 @@ void Client::ChannelGrantModerator(std::string CommandString) {
if ((ChannelName.length() > 0) && isdigit(ChannelName[0]))
ChannelName = ChannelSlotName(atoi(ChannelName.c_str()));
Log(Logs::Detail, Logs::UCS_Server, "[%s] gives [%s] moderator rights to channel [%s]", GetName().c_str(), Moderator.c_str(), ChannelName.c_str());
LogInfo("[[{}]] gives [[{}]] moderator rights to channel [[{}]]", GetName().c_str(), Moderator.c_str(), ChannelName.c_str());
Client *RequiredClient = g_Clientlist->FindCharacter(Moderator);
@@ -1953,7 +1949,7 @@ void Client::ChannelGrantVoice(std::string CommandString) {
if ((ChannelName.length() > 0) && isdigit(ChannelName[0]))
ChannelName = ChannelSlotName(atoi(ChannelName.c_str()));
Log(Logs::Detail, Logs::UCS_Server, "[%s] gives [%s] voice to channel [%s]", GetName().c_str(), Voicee.c_str(), ChannelName.c_str());
LogInfo("[[{}]] gives [[{}]] voice to channel [[{}]]", GetName().c_str(), Voicee.c_str(), ChannelName.c_str());
Client *RequiredClient = g_Clientlist->FindCharacter(Voicee);
@@ -2041,7 +2037,7 @@ void Client::ChannelKick(std::string CommandString) {
if ((ChannelName.length() > 0) && isdigit(ChannelName[0]))
ChannelName = ChannelSlotName(atoi(ChannelName.c_str()));
Log(Logs::Detail, Logs::UCS_Server, "[%s] kicks [%s] from channel [%s]", GetName().c_str(), Kickee.c_str(), ChannelName.c_str());
LogInfo("[[{}]] kicks [[{}]] from channel [[{}]]", GetName().c_str(), Kickee.c_str(), ChannelName.c_str());
Client *RequiredClient = g_Clientlist->FindCharacter(Kickee);
@@ -2151,28 +2147,28 @@ void Client::SetConnectionType(char c) {
{
TypeOfConnection = ConnectionTypeChat;
ClientVersion_ = EQEmu::versions::ClientVersion::Titanium;
Log(Logs::Detail, Logs::UCS_Server, "Connection type is Chat (Titanium)");
LogInfo("Connection type is Chat (Titanium)");
break;
}
case EQEmu::versions::ucsTitaniumMail:
{
TypeOfConnection = ConnectionTypeMail;
ClientVersion_ = EQEmu::versions::ClientVersion::Titanium;
Log(Logs::Detail, Logs::UCS_Server, "Connection type is Mail (Titanium)");
LogInfo("Connection type is Mail (Titanium)");
break;
}
case EQEmu::versions::ucsSoFCombined:
{
TypeOfConnection = ConnectionTypeCombined;
ClientVersion_ = EQEmu::versions::ClientVersion::SoF;
Log(Logs::Detail, Logs::UCS_Server, "Connection type is Combined (SoF)");
LogInfo("Connection type is Combined (SoF)");
break;
}
case EQEmu::versions::ucsSoDCombined:
{
TypeOfConnection = ConnectionTypeCombined;
ClientVersion_ = EQEmu::versions::ClientVersion::SoD;
Log(Logs::Detail, Logs::UCS_Server, "Connection type is Combined (SoD)");
LogInfo("Connection type is Combined (SoD)");
break;
}
case EQEmu::versions::ucsUFCombined:
@@ -2180,7 +2176,7 @@ void Client::SetConnectionType(char c) {
TypeOfConnection = ConnectionTypeCombined;
ClientVersion_ = EQEmu::versions::ClientVersion::UF;
UnderfootOrLater = true;
Log(Logs::Detail, Logs::UCS_Server, "Connection type is Combined (Underfoot)");
LogInfo("Connection type is Combined (Underfoot)");
break;
}
case EQEmu::versions::ucsRoFCombined:
@@ -2188,7 +2184,7 @@ void Client::SetConnectionType(char c) {
TypeOfConnection = ConnectionTypeCombined;
ClientVersion_ = EQEmu::versions::ClientVersion::RoF;
UnderfootOrLater = true;
Log(Logs::Detail, Logs::UCS_Server, "Connection type is Combined (RoF)");
LogInfo("Connection type is Combined (RoF)");
break;
}
case EQEmu::versions::ucsRoF2Combined:
@@ -2196,14 +2192,14 @@ void Client::SetConnectionType(char c) {
TypeOfConnection = ConnectionTypeCombined;
ClientVersion_ = EQEmu::versions::ClientVersion::RoF2;
UnderfootOrLater = true;
Log(Logs::Detail, Logs::UCS_Server, "Connection type is Combined (RoF2)");
LogInfo("Connection type is Combined (RoF2)");
break;
}
default:
{
TypeOfConnection = ConnectionTypeUnknown;
ClientVersion_ = EQEmu::versions::ClientVersion::Unknown;
Log(Logs::Detail, Logs::UCS_Server, "Connection type is unknown.");
LogInfo("Connection type is unknown");
}
}
}
@@ -2280,12 +2276,12 @@ void Client::SendNotification(int MailBoxNumber, std::string Subject, std::strin
void Client::ChangeMailBox(int NewMailBox)
{
Log(Logs::Detail, Logs::UCS_Server, "%s Change to mailbox %i", MailBoxName().c_str(), NewMailBox);
LogInfo("[{}] Change to mailbox [{}]", MailBoxName().c_str(), NewMailBox);
SetMailBox(NewMailBox);
auto id = std::to_string(NewMailBox);
Log(Logs::Detail, Logs::UCS_Server, "New mailbox is %s", MailBoxName().c_str());
LogInfo("New mailbox is [{}]", MailBoxName().c_str());
auto outapp = new EQApplicationPacket(OP_MailboxChange, id.length() + 1);
@@ -2354,13 +2350,13 @@ std::string Client::MailBoxName() {
if ((Characters.empty()) || (CurrentMailBox > (Characters.size() - 1)))
{
Log(Logs::Detail, Logs::UCS_Server, "MailBoxName() called with CurrentMailBox set to %i and Characters.size() is %i",
LogInfo("MailBoxName() called with CurrentMailBox set to [{}] and Characters.size() is [{}]",
CurrentMailBox, Characters.size());
return "";
}
Log(Logs::Detail, Logs::UCS_Server, "MailBoxName() called with CurrentMailBox set to %i and Characters.size() is %i",
LogInfo("MailBoxName() called with CurrentMailBox set to [{}] and Characters.size() is [{}]",
CurrentMailBox, Characters.size());
return Characters[CurrentMailBox].Name;
+359 -222
View File
@@ -38,8 +38,10 @@
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#else
#include "../common/unix.h"
#include <netinet/in.h>
#endif
#include "database.h"
@@ -48,12 +50,12 @@
#include "../common/string_util.h"
#include "chatchannel.h"
extern Clientlist *g_Clientlist;
extern Clientlist *g_Clientlist;
extern std::string GetMailPrefix();
extern ChatChannelList *ChannelList;
extern uint32 MailMessagesSent;
extern uint32 MailMessagesSent;
Database::Database ()
Database::Database()
{
DBInitVars();
}
@@ -62,37 +64,36 @@ Database::Database ()
Establish a connection to a mysql database with the supplied parameters
*/
Database::Database(const char* host, const char* user, const char* passwd, const char* database, uint32 port)
Database::Database(const char *host, const char *user, const char *passwd, const char *database, uint32 port)
{
DBInitVars();
Connect(host, user, passwd, database, port);
}
bool Database::Connect(const char* host, const char* user, const char* passwd, const char* database, uint32 port)
bool Database::Connect(const char *host, const char *user, const char *passwd, const char *database, uint32 port)
{
uint32 errnum= 0;
char errbuf[MYSQL_ERRMSG_SIZE];
if (!Open(host, user, passwd, database, port, &errnum, errbuf))
{
Log(Logs::General, Logs::Error, "Failed to connect to database: Error: %s", errbuf);
uint32 errnum = 0;
char errbuf[MYSQL_ERRMSG_SIZE];
if (!Open(host, user, passwd, database, port, &errnum, errbuf)) {
LogError("Failed to connect to database: Error: {}", errbuf);
HandleMysqlError(errnum);
return false;
}
else
{
Log(Logs::General, Logs::Status, "Using database '%s' at %s:%d",database,host,port);
else {
LogInfo("Using database [{}] at [{}]:[{}]", database, host, port);
return true;
}
}
void Database::DBInitVars() {
void Database::DBInitVars()
{
}
void Database::HandleMysqlError(uint32 errnum) {
void Database::HandleMysqlError(uint32 errnum)
{
}
/*
@@ -103,22 +104,27 @@ Database::~Database()
{
}
void Database::GetAccountStatus(Client *client) {
void Database::GetAccountStatus(Client *client)
{
std::string query = StringFormat(
"SELECT `status`, `hideme`, `karma`, `revoked` FROM `account` WHERE `id` = '%i' LIMIT 1",
client->GetAccountID()
);
auto results = QueryDatabase(query);
if (!results.Success()) {
LogInfo(
"Unable to get account status for character [{}], error [{}]",
client->GetName().c_str(),
results.ErrorMessage().c_str()
);
std::string query = StringFormat("SELECT `status`, `hideme`, `karma`, `revoked` "
"FROM `account` WHERE `id` = '%i' LIMIT 1",
client->GetAccountID());
auto results = QueryDatabase(query);
if (!results.Success()) {
Log(Logs::Detail, Logs::UCS_Server, "Unable to get account status for character %s, error %s", client->GetName().c_str(), results.ErrorMessage().c_str());
return;
}
Log(Logs::Detail, Logs::UCS_Server, "GetAccountStatus Query: %s", query.c_str());
if(results.RowCount() != 1)
{
Log(Logs::Detail, Logs::UCS_Server, "Error in GetAccountStatus");
if (results.RowCount() != 1) {
LogInfo("Error in GetAccountStatus");
return;
}
@@ -127,29 +133,34 @@ void Database::GetAccountStatus(Client *client) {
client->SetAccountStatus(atoi(row[0]));
client->SetHideMe(atoi(row[1]) != 0);
client->SetKarma(atoi(row[2]));
client->SetRevoked((atoi(row[3])==1?true:false));
Log(Logs::Detail, Logs::UCS_Server, "Set account status to %i, hideme to %i and karma to %i for %s", client->GetAccountStatus(), client->GetHideMe(), client->GetKarma(), client->GetName().c_str());
client->SetRevoked((atoi(row[3]) == 1 ? true : false));
LogDebug(
"Set account status to [{}], hideme to [{}] and karma to [{}] for [{}]",
client->GetAccountStatus(),
client->GetHideMe(),
client->GetKarma(),
client->GetName().c_str()
);
}
int Database::FindAccount(const char *characterName, Client *client) {
Log(Logs::Detail, Logs::UCS_Server, "FindAccount for character %s", characterName);
int Database::FindAccount(const char *characterName, Client *client)
{
LogInfo("FindAccount for character [{}]", characterName);
client->ClearCharacters();
std::string query = StringFormat("SELECT `id`, `account_id`, `level` "
"FROM `character_data` WHERE `name` = '%s' LIMIT 1",
characterName);
auto results = QueryDatabase(query);
std::string query = StringFormat(
"SELECT `id`, `account_id`, `level` FROM `character_data` WHERE `name` = '%s' LIMIT 1",
characterName
);
auto results = QueryDatabase(query);
if (!results.Success()) {
Log(Logs::Detail, Logs::UCS_Server, "FindAccount query failed: %s", query.c_str());
return -1;
}
if (results.RowCount() != 1) {
Log(Logs::Detail, Logs::UCS_Server, "Bad result from query");
return -1;
}
@@ -158,14 +169,18 @@ int Database::FindAccount(const char *characterName, Client *client) {
int accountID = atoi(row[1]);
Log(Logs::Detail, Logs::UCS_Server, "Account ID for %s is %i", characterName, accountID);
LogInfo("Account ID for [{}] is [{}]", characterName, accountID);
query = StringFormat("SELECT `id`, `name`, `level` FROM `character_data` "
"WHERE `account_id` = %i AND `name` != '%s'",
accountID, characterName);
results = QueryDatabase(query);
if (!results.Success())
query = StringFormat(
"SELECT `id`, `name`, `level` FROM `character_data` "
"WHERE `account_id` = %i AND `name` != '%s'",
accountID, characterName
);
results = QueryDatabase(query);
if (!results.Success()) {
return accountID;
}
for (auto row = results.begin(); row != results.end(); ++row)
client->AddCharacter(atoi(row[0]), row[1], atoi(row[2]));
@@ -173,13 +188,17 @@ int Database::FindAccount(const char *characterName, Client *client) {
return accountID;
}
bool Database::VerifyMailKey(std::string characterName, int IPAddress, std::string MailKey) {
bool Database::VerifyMailKey(std::string characterName, int IPAddress, std::string MailKey)
{
std::string query = StringFormat("SELECT `mailkey` FROM `character_data` WHERE `name`='%s' LIMIT 1",
characterName.c_str());
auto results = QueryDatabase(query);
std::string query = StringFormat(
"SELECT `mailkey` FROM `character_data` WHERE `name`='%s' LIMIT 1",
characterName.c_str()
);
auto results = QueryDatabase(query);
if (!results.Success()) {
Log(Logs::Detail, Logs::UCS_Server, "Error retrieving mailkey from database: %s", results.ErrorMessage().c_str());
LogInfo("Error retrieving mailkey from database: [{}]", results.ErrorMessage().c_str());
return false;
}
@@ -190,21 +209,26 @@ bool Database::VerifyMailKey(std::string characterName, int IPAddress, std::stri
//
char combinedKey[17];
if(RuleB(Chat, EnableMailKeyIPVerification) == true)
if (RuleB(Chat, EnableMailKeyIPVerification) == true) {
sprintf(combinedKey, "%08X%s", IPAddress, MailKey.c_str());
else
}
else {
sprintf(combinedKey, "%s", MailKey.c_str());
}
Log(Logs::Detail, Logs::UCS_Server, "DB key is [%s], Client key is [%s]", (row[0] ? row[0] : ""), combinedKey);
LogInfo("DB key is [[{}]], Client key is [[{}]]", (row[0] ? row[0] : ""), combinedKey);
return !strcmp(row[0], combinedKey);
}
int Database::FindCharacter(const char *characterName)
{
char *safeCharName = RemoveApostrophes(characterName);
std::string query = StringFormat("SELECT `id` FROM `character_data` WHERE `name`='%s' LIMIT 1", safeCharName);
auto results = QueryDatabase(query);
char *safeCharName = RemoveApostrophes(characterName);
std::string query = StringFormat(
"SELECT `id` FROM `character_data` WHERE `name`='%s' LIMIT 1",
safeCharName
);
auto results = QueryDatabase(query);
if (!results.Success()) {
safe_delete_array(safeCharName);
return -1;
@@ -213,8 +237,7 @@ int Database::FindCharacter(const char *characterName)
safe_delete_array(safeCharName);
if (results.RowCount() != 1) {
Log(Logs::Detail, Logs::UCS_Server, "Bad result from FindCharacter query for character %s",
characterName);
LogInfo("Bad result from FindCharacter query for character [{}]", characterName);
return -1;
}
@@ -225,16 +248,18 @@ int Database::FindCharacter(const char *characterName)
return characterID;
}
bool Database::GetVariable(const char* varname, char* varvalue, uint16 varvalue_len) {
bool Database::GetVariable(const char *varname, char *varvalue, uint16 varvalue_len)
{
std::string query = StringFormat("SELECT `value` FROM `variables` WHERE `varname` = '%s'", varname);
auto results = QueryDatabase(query);
std::string query = StringFormat("SELECT `value` FROM `variables` WHERE `varname` = '%s'", varname);
auto results = QueryDatabase(query);
if (!results.Success()) {
return false;
}
if (results.RowCount() != 1)
if (results.RowCount() != 1) {
return false;
}
auto row = results.begin();
@@ -243,19 +268,20 @@ bool Database::GetVariable(const char* varname, char* varvalue, uint16 varvalue_
return true;
}
bool Database::LoadChatChannels() {
bool Database::LoadChatChannels()
{
Log(Logs::Detail, Logs::UCS_Server, "Loading chat channels from the database.");
LogInfo("Loading chat channels from the database");
const std::string query = "SELECT `name`, `owner`, `password`, `minstatus` FROM `chatchannels`";
auto results = QueryDatabase(query);
const std::string query = "SELECT `name`, `owner`, `password`, `minstatus` FROM `chatchannels`";
auto results = QueryDatabase(query);
if (!results.Success()) {
return false;
}
for (auto row = results.begin();row != results.end(); ++row) {
std::string channelName = row[0];
std::string channelOwner = row[1];
for (auto row = results.begin(); row != results.end(); ++row) {
std::string channelName = row[0];
std::string channelOwner = row[1];
std::string channelPassword = row[2];
ChannelList->CreateChannel(channelName, channelOwner, channelPassword, true, atoi(row[3]));
@@ -264,40 +290,50 @@ bool Database::LoadChatChannels() {
return true;
}
void Database::SetChannelPassword(std::string channelName, std::string password) {
void Database::SetChannelPassword(std::string channelName, std::string password)
{
LogInfo("Database::SetChannelPassword([{}], [{}])", channelName.c_str(), password.c_str());
Log(Logs::Detail, Logs::UCS_Server, "Database::SetChannelPassword(%s, %s)", channelName.c_str(), password.c_str());
std::string query = StringFormat("UPDATE `chatchannels` SET `password` = '%s' WHERE `name` = '%s'",
password.c_str(), channelName.c_str());
QueryDatabase(query);
std::string query = StringFormat(
"UPDATE `chatchannels` SET `password` = '%s' WHERE `name` = '%s'",
password.c_str(), channelName.c_str());
QueryDatabase(query);
}
void Database::SetChannelOwner(std::string channelName, std::string owner) {
void Database::SetChannelOwner(std::string channelName, std::string owner)
{
LogInfo("Database::SetChannelOwner([{}], [{}])", channelName.c_str(), owner.c_str());
Log(Logs::Detail, Logs::UCS_Server, "Database::SetChannelOwner(%s, %s)", channelName.c_str(), owner.c_str());
std::string query = StringFormat(
"UPDATE `chatchannels` SET `owner` = '%s' WHERE `name` = '%s'",
owner.c_str(),
channelName.c_str()
);
std::string query = StringFormat("UPDATE `chatchannels` SET `owner` = '%s' WHERE `name` = '%s'",
owner.c_str(), channelName.c_str());
QueryDatabase(query);
QueryDatabase(query);
}
void Database::SendHeaders(Client *client) {
void Database::SendHeaders(Client *client)
{
int unknownField2 = 25015275;
int unknownField3 = 1;
int characterID = FindCharacter(client->MailBoxName().c_str());
int characterID = FindCharacter(client->MailBoxName().c_str());
Log(Logs::Detail, Logs::UCS_Server, "Sendheaders for %s, CharID is %i", client->MailBoxName().c_str(), characterID);
LogInfo("Sendheaders for [{}], CharID is [{}]", client->MailBoxName().c_str(), characterID);
if(characterID <= 0)
if (characterID <= 0) {
return;
}
std::string query = StringFormat("SELECT `msgid`,`timestamp`, `from`, `subject`, `status` "
"FROM `mail` WHERE `charid`=%i", characterID);
auto results = QueryDatabase(query);
if (!results.Success())
std::string query = StringFormat(
"SELECT `msgid`,`timestamp`, `from`, `subject`, `status` "
"FROM `mail` WHERE `charid`=%i", characterID
);
auto results = QueryDatabase(query);
if (!results.Success()) {
return;
}
char buffer[100];
@@ -317,7 +353,7 @@ void Database::SendHeaders(Client *client) {
auto outapp = new EQApplicationPacket(OP_MailHeaderCount, headerCountPacketLength);
char *packetBuffer = (char *)outapp->pBuffer;
char *packetBuffer = (char *) outapp->pBuffer;
VARSTRUCT_ENCODE_INTSTRING(packetBuffer, client->GetMailBoxNumber());
VARSTRUCT_ENCODE_INTSTRING(packetBuffer, unknownField2);
@@ -329,8 +365,8 @@ void Database::SendHeaders(Client *client) {
safe_delete(outapp);
int rowIndex = 0;
for(auto row = results.begin(); row != results.end(); ++row, ++rowIndex) {
int rowIndex = 0;
for (auto row = results.begin(); row != results.end(); ++row, ++rowIndex) {
int headerPacketLength = 0;
sprintf(buffer, "%i", client->GetMailBoxNumber());
@@ -348,7 +384,7 @@ void Database::SendHeaders(Client *client) {
outapp = new EQApplicationPacket(OP_MailHeader, headerPacketLength);
packetBuffer = (char *)outapp->pBuffer;
packetBuffer = (char *) outapp->pBuffer;
VARSTRUCT_ENCODE_INTSTRING(packetBuffer, client->GetMailBoxNumber());
VARSTRUCT_ENCODE_INTSTRING(packetBuffer, unknownField2);
@@ -369,39 +405,48 @@ void Database::SendHeaders(Client *client) {
}
void Database::SendBody(Client *client, int messageNumber) {
void Database::SendBody(Client *client, int messageNumber)
{
int characterID = FindCharacter(client->MailBoxName().c_str());
Log(Logs::Detail, Logs::UCS_Server, "SendBody: MsgID %i, to %s, CharID is %i", messageNumber, client->MailBoxName().c_str(), characterID);
LogInfo("SendBody: MsgID [{}], to [{}], CharID is [{}]", messageNumber, client->MailBoxName().c_str(), characterID);
if(characterID <= 0)
if (characterID <= 0) {
return;
}
std::string query = StringFormat("SELECT `msgid`, `body`, `to` FROM `mail` "
"WHERE `charid`=%i AND `msgid`=%i", characterID, messageNumber);
auto results = QueryDatabase(query);
if (!results.Success())
std::string query = StringFormat(
"SELECT `msgid`, `body`, `to` FROM `mail` "
"WHERE `charid`=%i AND `msgid`=%i",
characterID,
messageNumber
);
auto results = QueryDatabase(query);
if (!results.Success()) {
return;
}
if (results.RowCount() != 1)
if (results.RowCount() != 1) {
return;
}
auto row = results.begin();
Log(Logs::Detail, Logs::UCS_Server, "Message: %i body (%i bytes)", messageNumber, strlen(row[1]));
LogInfo("Message: [{}] body ([{}] bytes)", messageNumber, strlen(row[1]));
int packetLength = 12 + strlen(row[0]) + strlen(row[1]) + strlen(row[2]);
auto outapp = new EQApplicationPacket(OP_MailSendBody, packetLength);
char *packetBuffer = (char *)outapp->pBuffer;
char *packetBuffer = (char *) outapp->pBuffer;
VARSTRUCT_ENCODE_INTSTRING(packetBuffer, client->GetMailBoxNumber());
VARSTRUCT_ENCODE_STRING(packetBuffer,row[0]);
VARSTRUCT_ENCODE_STRING(packetBuffer,row[1]);
VARSTRUCT_ENCODE_STRING(packetBuffer,"1");
VARSTRUCT_ENCODE_STRING(packetBuffer, row[0]);
VARSTRUCT_ENCODE_STRING(packetBuffer, row[1]);
VARSTRUCT_ENCODE_STRING(packetBuffer, "1");
VARSTRUCT_ENCODE_TYPE(uint8, packetBuffer, 0);
VARSTRUCT_ENCODE_TYPE(uint8, packetBuffer, 0x0a);
VARSTRUCT_ENCODE_STRING(packetBuffer, "TO:");
@@ -410,62 +455,75 @@ void Database::SendBody(Client *client, int messageNumber) {
packetBuffer--; // Overwrite the null terminator
VARSTRUCT_ENCODE_TYPE(uint8, packetBuffer, 0x0a);
client->QueuePacket(outapp);
safe_delete(outapp);
}
bool Database::SendMail(std::string recipient, std::string from, std::string subject, std::string body, std::string recipientsString) {
bool Database::SendMail(
std::string recipient,
std::string from,
std::string subject,
std::string body,
std::string recipientsString
)
{
int characterID;
int characterID;
std::string characterName;
auto lastPeriod = recipient.find_last_of(".");
if(lastPeriod == std::string::npos)
if (lastPeriod == std::string::npos) {
characterName = recipient;
else
characterName = recipient.substr(lastPeriod+1);
}
else {
characterName = recipient.substr(lastPeriod + 1);
}
characterName[0] = toupper(characterName[0]);
for(unsigned int i = 1; i < characterName.length(); i++)
for (unsigned int i = 1; i < characterName.length(); i++)
characterName[i] = tolower(characterName[i]);
characterID = FindCharacter(characterName.c_str());
Log(Logs::Detail, Logs::UCS_Server, "SendMail: CharacterID for recipient %s is %i", characterName.c_str(), characterID);
LogInfo("SendMail: CharacterID for recipient [{}] is [{}]", characterName.c_str(), characterID);
if(characterID <= 0)
return false;
if (characterID <= 0) {
return false;
}
auto escSubject = new char[subject.length() * 2 + 1];
auto escBody = new char[body.length() * 2 + 1];
auto escBody = new char[body.length() * 2 + 1];
DoEscapeString(escSubject, subject.c_str(), subject.length());
DoEscapeString(escBody, body.c_str(), body.length());
int now = time(nullptr); // time returns a 64 bit int on Windows at least, which vsnprintf doesn't like.
std::string query = StringFormat("INSERT INTO `mail` "
"(`charid`, `timestamp`, `from`, `subject`, `body`, `to`, `status`) "
"VALUES ('%i', %i, '%s', '%s', '%s', '%s', %i)",
characterID, now, from.c_str(), escSubject, escBody,
recipientsString.c_str(), 1);
safe_delete_array(escSubject);
safe_delete_array(escBody);
auto results = QueryDatabase(query);
if(!results.Success()) {
std::string query = StringFormat(
"INSERT INTO `mail` (`charid`, `timestamp`, `from`, `subject`, `body`, `to`, `status`) VALUES ('%i', %i, '%s', '%s', '%s', '%s', %i)",
characterID,
now,
from.c_str(),
escSubject,
escBody,
recipientsString.c_str(),
1
);
safe_delete_array(escSubject);
safe_delete_array(escBody);
auto results = QueryDatabase(query);
if (!results.Success()) {
return false;
}
Log(Logs::Detail, Logs::UCS_Server, "MessageID %i generated, from %s, to %s", results.LastInsertedID(), from.c_str(), recipient.c_str());
LogInfo("MessageID [{}] generated, from [{}], to [{}]", results.LastInsertedID(), from.c_str(), recipient.c_str());
Client *client = g_Clientlist->IsCharacterOnline(characterName);
if(client) {
if (client) {
std::string FQN = GetMailPrefix() + from;
client->SendNotification(client->GetMailBoxNumber(characterName), subject, FQN, results.LastInsertedID());
}
@@ -475,91 +533,127 @@ bool Database::SendMail(std::string recipient, std::string from, std::string sub
return true;
}
void Database::SetMessageStatus(int messageNumber, int status) {
void Database::SetMessageStatus(int messageNumber, int status)
{
Log(Logs::Detail, Logs::UCS_Server, "SetMessageStatus %i %i", messageNumber, status);
LogInfo("SetMessageStatus [{}] [{}]", messageNumber, status);
if(status == 0) {
std::string query = StringFormat("DELETE FROM `mail` WHERE `msgid` = %i", messageNumber);
auto results = QueryDatabase(query);
return;
}
if (status == 0) {
std::string query = StringFormat("DELETE FROM `mail` WHERE `msgid` = %i", messageNumber);
auto results = QueryDatabase(query);
return;
}
std::string query = StringFormat("UPDATE `mail` SET `status` = %i WHERE `msgid`=%i", status, messageNumber);
QueryDatabase(query);
std::string query = StringFormat("UPDATE `mail` SET `status` = %i WHERE `msgid`=%i", status, messageNumber);
QueryDatabase(query);
}
void Database::ExpireMail() {
void Database::ExpireMail()
{
Log(Logs::Detail, Logs::UCS_Server, "Expiring mail...");
LogInfo("Expiring mail");
std::string query = "SELECT COUNT(*) FROM `mail`";
auto results = QueryDatabase(query);
if (!results.Success()) {
std::string query = "SELECT COUNT(*) FROM `mail`";
auto results = QueryDatabase(query);
if (!results.Success()) {
return;
}
auto row = results.begin();
Log(Logs::Detail, Logs::UCS_Server, "There are %s messages in the database.", row[0]);
LogInfo("There are [{}] messages in the database", row[0]);
// Expire Trash
if(RuleI(Mail, ExpireTrash) >= 0) {
query = StringFormat("DELETE FROM `mail` WHERE `status`=4 AND `timestamp` < %i",
time(nullptr) - RuleI(Mail, ExpireTrash));
results = QueryDatabase(query);
if(results.Success())
Log(Logs::Detail, Logs::UCS_Server, "Expired %i trash messages.", results.RowsAffected());
/**
* Expire trash
*/
if (RuleI(Mail, ExpireTrash) >= 0) {
query = StringFormat(
"DELETE FROM `mail` WHERE `status`=4 AND `timestamp` < %i",
time(nullptr) - RuleI(Mail, ExpireTrash));
results = QueryDatabase(query);
if (results.Success()) {
LogInfo("Expired [{}] trash messages", results.RowsAffected());
}
}
// Expire Read
if(RuleI(Mail, ExpireRead) >= 0) {
query = StringFormat("DELETE FROM `mail` WHERE `status` = 3 AND `timestamp` < %i",
time(nullptr) - RuleI(Mail, ExpireRead));
results = QueryDatabase(query);
if(results.Success())
Log(Logs::Detail, Logs::UCS_Server, "Expired %i read messages.", results.RowsAffected());
/**
* Expire read
*/
if (RuleI(Mail, ExpireRead) >= 0) {
query = StringFormat(
"DELETE FROM `mail` WHERE `status` = 3 AND `timestamp` < %i",
time(nullptr) - RuleI(Mail, ExpireRead)
);
results = QueryDatabase(query);
if (results.Success())
LogInfo("Expired [{}] read messages", results.RowsAffected());
}
// Expire Unread
if(RuleI(Mail, ExpireUnread) >= 0) {
query = StringFormat("DELETE FROM `mail` WHERE `status`=1 AND `timestamp` < %i",
time(nullptr) - RuleI(Mail, ExpireUnread));
results = QueryDatabase(query);
if(results.Success())
Log(Logs::Detail, Logs::UCS_Server, "Expired %i unread messages.", results.RowsAffected());
/**
* Expire unread
*/
if (RuleI(Mail, ExpireUnread) >= 0) {
query = StringFormat(
"DELETE FROM `mail` WHERE `status`=1 AND `timestamp` < %i",
time(nullptr) - RuleI(Mail, ExpireUnread)
);
results = QueryDatabase(query);
if (results.Success()) {
LogInfo("Expired [{}] unread messages", results.RowsAffected());
}
}
}
void Database::AddFriendOrIgnore(int charID, int type, std::string name) {
void Database::AddFriendOrIgnore(int charID, int type, std::string name)
{
std::string query = StringFormat(
"INSERT INTO `friends` (`charid`, `type`, `name`) "
"VALUES('%i', %i, '%s')",
charID,
type,
CapitaliseName(name).c_str()
);
std::string query = StringFormat("INSERT INTO `friends` (`charid`, `type`, `name`) "
"VALUES('%i', %i, '%s')",
charID, type, CapitaliseName(name).c_str());
auto results = QueryDatabase(query);
if(results.Success())
Log(Logs::Detail, Logs::UCS_Server, "Wrote Friend/Ignore entry for charid %i, type %i, name %s to database.", charID, type, name.c_str());
auto results = QueryDatabase(query);
}
void Database::RemoveFriendOrIgnore(int charID, int type, std::string name) {
std::string query = StringFormat("DELETE FROM `friends` WHERE `charid` = %i "
"AND `type` = %i AND `name` = '%s'",
charID, type, CapitaliseName(name).c_str());
auto results = QueryDatabase(query);
if (!results.Success()) {
Log(Logs::Detail, Logs::UCS_Server, "Error removing friend/ignore, query was %s", query.c_str());
}
else {
Log(Logs::Detail, Logs::UCS_Server, "Removed Friend/Ignore entry for charid %i, type %i, name %s from database.", charID, type, name.c_str());
if (results.Success()) {
LogInfo(
"Wrote Friend/Ignore entry for charid [{}], type [{}], name [{}] to database",
charID,
type,
name.c_str()
);
}
}
void Database::GetFriendsAndIgnore(int charID, std::vector<std::string> &friends, std::vector<std::string> &ignorees) {
void Database::RemoveFriendOrIgnore(int charID, int type, std::string name)
{
std::string query = StringFormat(
"DELETE FROM `friends` WHERE `charid` = %i AND `type` = %i AND `name` = '%s'",
charID,
type,
CapitaliseName(name).c_str()
);
std::string query = StringFormat("select `type`, `name` FROM `friends` WHERE `charid`=%i", charID);
auto results = QueryDatabase(query);
auto results = QueryDatabase(query);
if (results.Success()) {
LogInfo(
"Removed Friend/Ignore entry for charid [{}], type [{}], name [{}] from database",
charID,
type,
name.c_str()
);
}
}
void Database::GetFriendsAndIgnore(int charID, std::vector<std::string> &friends, std::vector<std::string> &ignorees)
{
std::string query = StringFormat("select `type`, `name` FROM `friends` WHERE `charid`=%i", charID);
auto results = QueryDatabase(query);
if (!results.Success()) {
return;
}
@@ -568,57 +662,100 @@ void Database::GetFriendsAndIgnore(int charID, std::vector<std::string> &friends
for (auto row = results.begin(); row != results.end(); ++row) {
std::string name = row[1];
if(atoi(row[0]) == 0)
{
if (atoi(row[0]) == 0) {
ignorees.push_back(name);
Log(Logs::Detail, Logs::UCS_Server, "Added Ignoree from DB %s", name.c_str());
LogInfo("Added Ignoree from DB [{}]", name.c_str());
continue;
}
friends.push_back(name);
Log(Logs::Detail, Logs::UCS_Server, "Added Friend from DB %s", name.c_str());
friends.push_back(name);
LogInfo("Added Friend from DB [{}]", name.c_str());
}
}
void Database::LoadLogSettings(EQEmuLogSys::LogSettings* log_settings){
void Database::LoadLogSettings(EQEmuLogSys::LogSettings *log_settings)
{
std::string query =
"SELECT "
"log_category_id, "
"log_category_description, "
"log_to_console, "
"log_to_file, "
"log_to_gmsay "
"FROM "
"logsys_categories "
"ORDER BY log_category_id";
auto results = QueryDatabase(query);
"SELECT "
"log_category_id, "
"log_category_description, "
"log_to_console, "
"log_to_file, "
"log_to_gmsay "
"FROM "
"logsys_categories "
"ORDER BY log_category_id";
int log_category = 0;
LogSys.file_logs_enabled = false;
auto results = QueryDatabase(query);
int log_category_id = 0;
int *categories_in_database = new int[1000];
for (auto row = results.begin(); row != results.end(); ++row) {
log_category = atoi(row[0]);
log_settings[log_category].log_to_console = atoi(row[2]);
log_settings[log_category].log_to_file = atoi(row[3]);
log_settings[log_category].log_to_gmsay = atoi(row[4]);
log_category_id = atoi(row[0]);
if (log_category_id <= Logs::None || log_category_id >= Logs::MaxCategoryID) {
continue;
}
/* Determine if any output method is enabled for the category
and set it to 1 so it can used to check if category is enabled */
const bool log_to_console = log_settings[log_category].log_to_console > 0;
const bool log_to_file = log_settings[log_category].log_to_file > 0;
const bool log_to_gmsay = log_settings[log_category].log_to_gmsay > 0;
log_settings[log_category_id].log_to_console = static_cast<uint8>(atoi(row[2]));
log_settings[log_category_id].log_to_file = static_cast<uint8>(atoi(row[3]));
log_settings[log_category_id].log_to_gmsay = static_cast<uint8>(atoi(row[4]));
/**
* Determine if any output method is enabled for the category
* and set it to 1 so it can used to check if category is enabled
*/
const bool log_to_console = log_settings[log_category_id].log_to_console > 0;
const bool log_to_file = log_settings[log_category_id].log_to_file > 0;
const bool log_to_gmsay = log_settings[log_category_id].log_to_gmsay > 0;
const bool is_category_enabled = log_to_console || log_to_file || log_to_gmsay;
if (is_category_enabled)
log_settings[log_category].is_category_enabled = 1;
if (is_category_enabled) {
log_settings[log_category_id].is_category_enabled = 1;
}
/*
This determines whether or not the process needs to actually file log anything.
If we go through this whole loop and nothing is set to any debug level, there is no point to create a file or keep anything open
*/
if (log_settings[log_category].log_to_file > 0){
/**
* This determines whether or not the process needs to actually file log anything.
* If we go through this whole loop and nothing is set to any debug level, there is no point to create a file or keep anything open
*/
if (log_settings[log_category_id].log_to_file > 0) {
LogSys.file_logs_enabled = true;
}
categories_in_database[log_category_id] = 1;
}
/**
* Auto inject categories that don't exist in the database...
*/
for (int log_index = Logs::AA; log_index != Logs::MaxCategoryID; log_index++) {
if (categories_in_database[log_index] != 1) {
LogInfo(
"New Log Category [{0}] doesn't exist... Automatically adding to [logsys_categories] table...",
Logs::LogCategoryName[log_index]
);
auto inject_query = fmt::format(
"INSERT INTO logsys_categories "
"(log_category_id, "
"log_category_description, "
"log_to_console, "
"log_to_file, "
"log_to_gmsay) "
"VALUES "
"({0}, '{1}', {2}, {3}, {4})",
log_index,
EscapeString(Logs::LogCategoryName[log_index]),
std::to_string(log_settings[log_index].log_to_console),
std::to_string(log_settings[log_index].log_to_file),
std::to_string(log_settings[log_index].log_to_gmsay)
);
QueryDatabase(inject_query);
}
}
delete[] categories_in_database;
}
+12 -12
View File
@@ -73,10 +73,10 @@ int main() {
Timer InterserverTimer(INTERSERVER_TIMER); // does auto-reconnect
Log(Logs::General, Logs::UCS_Server, "Starting EQEmu Universal Chat Server.");
LogInfo("Starting EQEmu Universal Chat Server");
if (!ucsconfig::LoadConfig()) {
Log(Logs::General, Logs::UCS_Server, "Loading server configuration failed.");
LogInfo("Loading server configuration failed");
return 1;
}
@@ -84,7 +84,7 @@ int main() {
WorldShortName = Config->ShortName;
Log(Logs::General, Logs::UCS_Server, "Connecting to MySQL...");
LogInfo("Connecting to MySQL");
if (!database.Connect(
Config->DatabaseHost.c_str(),
@@ -92,7 +92,7 @@ int main() {
Config->DatabasePassword.c_str(),
Config->DatabaseDB.c_str(),
Config->DatabasePort)) {
Log(Logs::General, Logs::UCS_Server, "Cannot continue without a database connection.");
LogInfo("Cannot continue without a database connection");
return 1;
}
@@ -104,26 +104,26 @@ int main() {
// ucs has no 'reload rules' handler
if (database.GetVariable("RuleSet", tmp, sizeof(tmp)-1)) {
Log(Logs::General, Logs::UCS_Server, "Loading rule set '%s'", tmp);
LogInfo("Loading rule set [{}]", tmp);
if(!RuleManager::Instance()->LoadRules(&database, tmp, false)) {
Log(Logs::General, Logs::UCS_Server, "Failed to load ruleset '%s', falling back to defaults.", tmp);
LogInfo("Failed to load ruleset [{}], falling back to defaults", tmp);
}
} else {
if(!RuleManager::Instance()->LoadRules(&database, "default", false)) {
Log(Logs::General, Logs::UCS_Server, "No rule set configured, using default rules");
LogInfo("No rule set configured, using default rules");
} else {
Log(Logs::General, Logs::UCS_Server, "Loaded default rule set 'default'", tmp);
LogInfo("Loaded default rule set 'default'", tmp);
}
}
EQEmu::InitializeDynamicLookups();
Log(Logs::General, Logs::UCS_Server, "Initialized dynamic dictionary entries");
LogInfo("Initialized dynamic dictionary entries");
database.ExpireMail();
if(Config->ChatPort != Config->MailPort)
{
Log(Logs::General, Logs::UCS_Server, "MailPort and CharPort must be the same in eqemu_config.xml for UCS.");
LogInfo("MailPort and CharPort must be the same in eqemu_config.json for UCS");
exit(1);
}
@@ -134,11 +134,11 @@ int main() {
database.LoadChatChannels();
if (signal(SIGINT, CatchSignal) == SIG_ERR) {
Log(Logs::General, Logs::UCS_Server, "Could not set signal handler");
LogInfo("Could not set signal handler");
return 1;
}
if (signal(SIGTERM, CatchSignal) == SIG_ERR) {
Log(Logs::General, Logs::UCS_Server, "Could not set signal handler");
LogInfo("Could not set signal handler");
return 1;
}
+3 -3
View File
@@ -61,7 +61,7 @@ void WorldServer::ProcessMessage(uint16 opcode, EQ::Net::Packet &p)
ServerPacket tpack(opcode, p);
ServerPacket *pack = &tpack;
Log(Logs::Detail, Logs::UCS_Server, "Received Opcode: %4X", opcode);
LogInfo("Received Opcode: {:#04x}", opcode);
switch (opcode)
{
@@ -82,7 +82,7 @@ void WorldServer::ProcessMessage(uint16 opcode, EQ::Net::Packet &p)
std::string Message = Buffer;
Log(Logs::Detail, Logs::UCS_Server, "Player: %s, Sent Message: %s", From, Message.c_str());
LogInfo("Player: [{}], Sent Message: [{}]", From, Message.c_str());
Client *c = g_Clientlist->FindCharacter(From);
@@ -93,7 +93,7 @@ void WorldServer::ProcessMessage(uint16 opcode, EQ::Net::Packet &p)
if (!c)
{
Log(Logs::Detail, Logs::UCS_Server, "Client not found.");
LogInfo("Client not found");
break;
}