PDA

View Full Version : cMaNGOS TBC ban announcer lua



Zalvia
10-06-2016, 06:49 PM
I am looking for an LUA Mute,Kick,Ban announcer

slp13at420
10-06-2016, 07:24 PM
cant you set announcements for those in the config file?
I know kicked announcement has a config.

but your thread lack the info/details .
what do you want announced?
who did the action?
the action was for who?
why the action?

what do you want it to announce other than just `x got y'd by z.`

Zalvia
10-07-2016, 06:24 AM
Name is kicked by GM Name.Reason:
Name is muted by GM Katharis for time.Reason:
Name is banned by GM Name for time/Permanently.Reason:

Something like that. Never seen this thing in the config

slp13at420
10-07-2016, 12:14 PM
Now I have never worked with Mangos, CMangos, MangosZero or any Mangos version except TrinityCore (a spawn from of Mangos).
For TrinityCore under Custom Server Settings you can find announce for Kick,Ban, and Mute:



#
# ShowKickInWorld
# Description: Determines whether a message is broadcasted to the entire server when a
# player gets kicked.
# Default: 0 - (Disabled)
# 1 - (Enabled)

ShowKickInWorld = 0

# ShowMuteInWorld
# Description: Determines whether a message is broadcasted to the entire server when a
# player gets muted.
# Default: 0 - (Disabled)
# 1 - (Enabled)

ShowMuteInWorld = 0

#
# ShowBanInWorld
# Description: Determines whether a message is broadcasted to the entire server when a
# player gets banned.
# Default: 0 - (Disabled)
# 1 - (Enabled)

ShowBanInWorld = 0



let me check out the API .
I didn't find any events for OnPlayerBanned, OnPlayerKicked, OnPlayerMuted. but I did get to thinking you could mod your core to do it possibly.

in TrinityCore I would look at : \src\server\scripts\Commands\
cs_ban.cpp
cs_misc.cpp

Zalvia
10-07-2016, 05:55 PM
No there isnt this thing in config and no idea how to mod

slp13at420
10-09-2016, 08:57 PM
again let me state that I have never worked with CMangos or Mangos of any type.

I did do some poking around in the project files and did find :

\src\game\WorldSession.cpp :



/// Kick a player out of the World
void WorldSession::KickPlayer()
{
if (m_Socket)
m_Socket->CloseSocket();
}

\src\game\World.cpp :



/// Ban an account or ban an IP address, duration_secs if it is positive used, otherwise permban
BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, uint32 duration_secs, std::string reason, const std::string& author)
{
LoginDatabase.escape_string(nameOrIP);
LoginDatabase.escape_string(reason);
std::string safe_author = author;
LoginDatabase.escape_string(safe_author);

QueryResult* resultAccounts = nullptr; // used for kicking

///- Update the database with ban information
switch (mode)
{
case BAN_IP:
// No SQL injection as strings are escaped
resultAccounts = LoginDatabase.PQuery("SELECT id FROM account WHERE last_ip = '%s'", nameOrIP.c_str());
LoginDatabase.PExecute("INSERT INTO ip_banned VALUES ('%s',UNIX_TIMESTAMP(),UNIX_TIMESTAMP()+%u,'%s','% s')", nameOrIP.c_str(), duration_secs, safe_author.c_str(), reason.c_str());
break;
case BAN_ACCOUNT:
// No SQL injection as string is escaped
resultAccounts = LoginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'", nameOrIP.c_str());
break;
case BAN_CHARACTER:
// No SQL injection as string is escaped
resultAccounts = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'", nameOrIP.c_str());
break;
default:
return BAN_SYNTAX_ERROR;
}

if (!resultAccounts)
{
if (mode == BAN_IP)
return BAN_SUCCESS; // ip correctly banned but nobody affected (yet)
else
return BAN_NOTFOUND; // Nobody to ban
}

///- Disconnect all affected players (for IP it can be several)
do
{
Field* fieldsAccount = resultAccounts->Fetch();
uint32 account = fieldsAccount->GetUInt32();

if (mode != BAN_IP)
{
// No SQL injection as strings are escaped
LoginDatabase.PExecute("INSERT INTO account_banned VALUES ('%u', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()+%u, '%s', '%s', '1')",
account, duration_secs, safe_author.c_str(), reason.c_str());
}

if (WorldSession* sess = FindSession(account))
if (std::string(sess->GetPlayerName()) != author)
sess->KickPlayer();
}
while (resultAccounts->NextRow());

delete resultAccounts;
return BAN_SUCCESS;
}



You could add a couple lines to do a World Announcement in these 2 functions:


/// Sends a server message to the specified or all players
void World::SendServerMessage(ServerMessageType type, const char* text /*=""*/, Player* player /*= nullptr*/)

Zalvia
10-13-2016, 05:01 PM
Can u tell me what exactly i should do. I am new in core development

slp13at420
10-15-2016, 01:09 AM
I have never messed with CMangos nor do I have an7y knowledge of how-to setup,compile,build a CMangos server for testing.

but at first glance I would attempt something like this:



/// Ban an account or ban an IP address, duration_secs if it is positive used, otherwise permban
BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, uint32 duration_secs, std::string reason, const std::string& author)
{
LoginDatabase.escape_string(nameOrIP);
LoginDatabase.escape_string(reason);
std::string safe_author = author;
LoginDatabase.escape_string(safe_author);

QueryResult* resultAccounts = nullptr; // used for kicking

///- Update the database with ban information
switch (mode)
{
case BAN_IP:
// No SQL injection as strings are escaped
resultAccounts = LoginDatabase.PQuery("SELECT id FROM account WHERE last_ip = '%s'", nameOrIP.c_str());
LoginDatabase.PExecute("INSERT INTO ip_banned VALUES ('%s',UNIX_TIMESTAMP(),UNIX_TIMESTAMP()+%u,'%s','% s')", nameOrIP.c_str(), duration_secs, safe_author.c_str(), reason.c_str());
World::SendServerMessage(1, "IP:" + nameOrIP + " was banned by " + author + " due to: " + reason, nullptr);
break;
case BAN_ACCOUNT:
// No SQL injection as string is escaped
resultAccounts = LoginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'", nameOrIP.c_str());
World::SendServerMessage(1, "ACCT:" + nameOrIP + " was banned by " + author + " due to: " + reason, nullptr);
break;
case BAN_CHARACTER:
// No SQL injection as string is escaped
resultAccounts = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'", nameOrIP.c_str());
World::SendServerMessage(1, nameOrIP + " was banned by " + author + " due to: " + reason, nullptr);
break;
default:
return BAN_SYNTAX_ERROR;
}

if (!resultAccounts)
{
if (mode == BAN_IP)
return BAN_SUCCESS; // ip correctly banned but nobody affected (yet)
else
return BAN_NOTFOUND; // Nobody to ban
}

///- Disconnect all affected players (for IP it can be several)
do
{
Field* fieldsAccount = resultAccounts->Fetch();
uint32 account = fieldsAccount->GetUInt32();

if (mode != BAN_IP)
{
// No SQL injection as strings are escaped
LoginDatabase.PExecute("INSERT INTO account_banned VALUES ('%u', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()+%u, '%s', '%s', '1')",
account, duration_secs, safe_author.c_str(), reason.c_str());
}

if (WorldSession* sess = FindSession(account))
if (std::string(sess->GetPlayerName()) != author)
sess->KickPlayer();
} while (resultAccounts->NextRow());

delete resultAccounts;
return BAN_SUCCESS;
}


but this is where someone with some cmangos exp steps in ;P