Adding Login/Logout to Audit Log
FILE: src/map/map.cpp
Add to the top of the file at the end of the includes.
Then inside the `map_cleanup` function after the lines:
Code: Select all
PChar->status = STATUS_SHUTDOWN;
PacketParser[0x00D](map_session_data, PChar, 0);
Add the following code:
Code: Select all
int8 packetData[4]{};
WBUFL(packetData, 0) = PChar->id;
std::string bStr = ("* ");
bStr += PChar->GetName();
bStr += " has logged out.";
CHAT_MESSAGE_TYPE messageType = MESSAGE_LOGON;
message::send(MSG_CHAT_SERVMES, 0, 0, new CChatMessagePacket(PChar, messageType, (int8*)bStr.c_str()));
std::string qStr = ("INSERT into audit_chat (speaker,type,message,datetime) VALUES('");
qStr += "AfterHours";
qStr += "','SAY','* ";
qStr += PChar->GetName();
qStr += " has logged out.";
qStr += "',current_timestamp());";
const char * cC = qStr.c_str();
Sql_QueryStr(SqlHandle, cC);
This will handle when a user disconnects without using `/logout`.
FILE: src/map/packet_system.cpp
Now for the /logout function.
Next search for the function `SmallPacket0x0E7` and add the following right before the `return;` line that ends the function:
Code: Select all
int8 packetData[4]{};
WBUFL(packetData, 0) = PChar->id;
std::string bStr = ("* ");
bStr += PChar->GetName();
bStr += " has logged out.";
CHAT_MESSAGE_TYPE messageType = MESSAGE_LOGON;
message::send(MSG_CHAT_SERVMES, 0, 0, new CChatMessagePacket(PChar, messageType, (int8*)bStr.c_str()));
std::string qStr = ("INSERT into audit_chat (speaker,type,message,datetime) VALUES('");
qStr += "AfterHours";
qStr += "','SAY','* ";
qStr += PChar->GetName();
qStr += " has logged out.";
qStr += "',current_timestamp());";
const char * cC = qStr.c_str();
Sql_QueryStr(SqlHandle, cC);
FILE: src/map/lua/luautil.cpp
Search for the `OnGameIn` function and after the line:
Code: Select all
lua_pushboolean(LuaHandle, PChar->GetPlayTime(false) == 0); // first login
Add the following code:
Code: Select all
if (!zoning)
{
std::string qStr = ("INSERT into audit_chat (speaker,type,message,datetime) VALUES('");
qStr += "AfterHours";
qStr += "','SAY','* ";
qStr += PChar->GetName();
qStr += " has logged on.";
qStr += "',current_timestamp());";
const char * cC = qStr.c_str();
Sql_QueryStr(SqlHandle, cC);
}
FILE: src/map/packets/chat_message.h
Near the top of the file there is a `CHAT_MESSAGE_TYPE` enum, add the following line inside the braces:
This last part is my personal preference I use the green linkshell color for the in-game login/logout messages.