• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

cMaNGOS TBC ban announcer lua

slp13at420

Mad Scientist
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

Member
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

Mad Scientist
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
 
Last edited:

slp13at420

Mad Scientist
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 :
    • Code:
      [COLOR="#808080"]
      /// Kick a player out of the World
      void WorldSession::KickPlayer()
      {
          if (m_Socket)
              m_Socket->CloseSocket();
      }[/COLOR]
  • \src\game\World.cpp :
    • Code:
      [COLOR="#808080"]
      /// 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;
      } [/COLOR]

You could add a couple lines to do a World Announcement in these 2 functions:
Code:
[COLOR="#808080"]
/// Sends a server message to the specified or all players
void World::SendServerMessage(ServerMessageType type, const char* text /*=""*/, Player* player /*= nullptr*/)
[/COLOR]
 

slp13at420

Mad Scientist
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:
Code:
[COLOR="#808080"]
/// 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());
		[COLOR="#FF0000"]World::SendServerMessage(1, "IP:" + nameOrIP + " was banned by " + author + " due to: " + reason, nullptr);[/COLOR]
		break;
	case BAN_ACCOUNT:
		// No SQL injection as string is escaped
		resultAccounts = LoginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'", nameOrIP.c_str());
		[COLOR="#FF0000"]World::SendServerMessage(1, "ACCT:" + nameOrIP + " was banned by " + author + " due to: " + reason, nullptr);[/COLOR]
		break;
	case BAN_CHARACTER:
		// No SQL injection as string is escaped
		resultAccounts = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'", nameOrIP.c_str());
		[COLOR="#FF0000"]World::SendServerMessage(1, nameOrIP + " was banned by " + author + " due to: " + reason, nullptr);[/COLOR]
		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;
}[/COLOR]

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