Jump to content

Ban / Unban System with Reason


Recommended Posts

M2 Download Center

Download Here ( Internal )

Hello :D

 

first this in Account table

DROP TABLE IF EXISTS `ban_list`;
CREATE TABLE `ban_list` (
  `account` varchar(12) DEFAULT NULL,
  `reason` varchar(64) DEFAULT NULL,
  `source` varchar(12) DEFAULT NULL,
  `date` datetime DEFAULT NULL,
  `action` enum('ban','unban') DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

and lets go :D

open game/cmd.cpp and search for this:

ACMD(do_block_chat);

Add this under that:

ACMD(do_player_ban);
ACMD(do_player_unban);

Search for this still in the game/cmd.cpp:
 

{ "block_chat_list",do_block_chat_list, 0,          POS_DEAD,   GM_PLAYER   },

 
Make a new line and add this under that:

{ "player_unban", do_player_unban, 0, POS_DEAD, GM_IMPLEMENTOR },
{ "player_ban", do_player_ban,    0,        POS_DEAD,    GM_HIGH_WIZARD    },

Search for this event in  game/cmd_gm.cpp:

ACMD(do_block_chat)

Add

this under that:

ACMD (do_player_ban)
{

	if (ch && (ch->GetGMLevel() < GM_HIGH_WIZARD))
	{
		ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("그런 명령어는 없습니다"));
		return;
	}

	char arg1[256];
	argument = one_argument(argument, arg1, sizeof(arg1));

	if (!*arg1)
	{
		if (ch)
			ch->ChatPacket(CHAT_TYPE_INFO, "Usage: player_ban <name> <reason>");

		return;
	}

	const char* name = arg1;
	
	char arg2[256];
	argument = one_argument(argument, arg2, sizeof(arg2));
	if (!*arg2)
	{
		if (ch)
			ch->ChatPacket(CHAT_TYPE_INFO, "Usage: player_ban <name> <reason>");

		return;
	}
	char* reason;

	if(!*arg2)
		reason = (char*) "";
	else
		reason = arg2;

	sys_log(0, "BAN %s", name);

	LPCHARACTER tch = CHARACTER_MANAGER::instance().FindPC(name);

	if (!tch)
	{
		ch->ChatPacket(CHAT_TYPE_INFO, "can not find the target!");
		return;
	}
	
	if (ch)
		ch->ChatPacket(CHAT_TYPE_INFO, "ban requested.");

	if (tch && ch != tch)
	{
		if(tch->GetGMLevel() == GM_IMPLEMENTOR)
		{
			ch->ChatPacket(CHAT_TYPE_INFO, "Can not ban/unban Administrator!");
		} else {
			tch->ban(reason, ch->GetPlayerID());
		}
	}
}

ACMD (do_player_unban)
{
	if (ch && (ch->GetGMLevel() < GM_HIGH_WIZARD))
	{
		ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("그런 명령어는 없습니다"));
		return;
	}

	char arg1[256];
	argument = one_argument(argument, arg1, sizeof(arg1));

	if (!*arg1)
	{
		if (ch)
			ch->ChatPacket(CHAT_TYPE_INFO, "Usage: player_unban <name>");

		return;
	}

	char* name = arg1;

	sys_log(0, "UNBAN %s", name);
	
	ch->ChatPacket(CHAT_TYPE_INFO, "player_unban requested.");
	
	ch->unban(name);
}

Search for this event in  game/char.cpp

int	CHARACTER::GetSkillPowerByLevel(int level, bool bMob) const
{
	return CTableBySkill::instance().GetSkillPowerByLevelFromType(GetJob(), GetSkillGroup(), MINMAX(0, level, SKILL_MAX_LEVEL), bMob); 
}

and add this

void CHARACTER::ban(char* reason2, unsigned int myid2)
{
	DWORD myself = GetAID();
	char * query = (char*) malloc(sizeof(*query));
	snprintf(query, 1024, "UPDATE account.account SET status='BLOCK' WHERE id='%u'", myself);
	SQLMsg * msg = DBManager::instance().DirectQuery(query);
	if(!msg) {
		sys_err("cmd_ban: MySQL Query failed!");
	}
	free(query);

	char * query2 = (char*) malloc(sizeof(*query2));
	snprintf(query2, 1024, "INSERT INTO account.ban_list (account, reason, source, date, action) VALUES('%u', '%s', '%u', NOW(), 'ban')", myself, reason2, myid2);
	//const char * query2 = "INSERT INTO account.ban_list (account, reason, source) VALUES('%d', '%d', '%s')", GetAID(), myid2, reason2;
	SQLMsg * msg2 = DBManager::instance().DirectQuery(query2);
	if(!msg2) {
		sys_err("cmd_ban: MySQL Query2 failed!");
	}
	free(query2);
	M2_DELETE(query);
	M2_DELETE(query2);
	M2_DELETE(msg);
	M2_DELETE(msg2);
	char * resulttxt = (char*) malloc(sizeof(*query2));
	snprintf(resulttxt, 1024, "%s %s", LC_TEXT("You were banned! Reason:"), reason2);
	ChatPacket(CHAT_TYPE_INFO, resulttxt);
	GetDesc()->DelayedDisconnect(3);
	M2_DELETE(resulttxt);
}

void CHARACTER::unban(char* name)
{
	char * query = (char*) malloc(sizeof(*query));
	snprintf(query, 1024, "UPDATE account.account INNER JOIN player.player ON player.account_id=account.id SET status='OK' WHERE player.name='%s'", name);
	//snprintf(query, 1024, "UPDATE account.account SET status='OK' WHERE id='%u'", GetAID());
	SQLMsg * msg = DBManager::instance().DirectQuery(query);
	if(!msg) {
		sys_err("cmd_unban: MySQL Query failed!");
	}
	free(query);
	
	char * query2 = (char*) malloc(sizeof(*query));
	snprintf(query2, 1024, "INSERT INTO account.ban_list (account, reason, source, date, action) VALUES(0, '%s', '%u', NOW(), 'unban')", name, GetPlayerID());
	//snprintf(query, 1024, "UPDATE account.account SET status='OK' WHERE id='%u'", GetAID());
	SQLMsg * msg2 = DBManager::instance().DirectQuery(query2);
	if(!msg2) {
		sys_err("cmd_unban: MySQL Query failed!");
	}
	free(query2);
	M2_DELETE(query2);
	M2_DELETE(msg2);
	M2_DELETE(query);
	M2_DELETE(msg);
}

and now open game/char.h

 

search this

void			StartAffectEvent();

and add this

void			ban(char* reason2, unsigned int myid2);
void			unban(char* name);

Kind Regards,

 

Despero

  • Love 4
Link to comment

I can't see actual functions :)

ch-unban(name);
tch->ban(reason, ch->GetPlayerID());
// GM이 아니거나 block_chat_privilege가 없는 사람은 명령어 사용 불가

I don't know what i say for this :)

 

Thanks anyway.

 

Kind Regards

Ken ~ TA

Edited by Ken
  • Love 1

Do not be sorry, be better.

Link to comment

It works 100 %

 

Can you tell me one thing please? How can gcc know these functions if it's not declared in char.h & char.cpp ?

 

#first error

 

unban & ban are not declared in char.h & char.cpp

 

Kind Regards

Ken ~ TA

Edited by Ken
  • Love 1

Do not be sorry, be better.

Link to comment

 

It works 100 %

 

Can you tell me one thing please? How can gcc know these functions if it's not declared in char.h & char.cpp ?

 

#first error

 

unban & ban are not declared in char.h & char.cpp

 

Kind Regards

Ken ~ TA

 

 

I have edit the topic

Link to comment
  • 3 weeks later...
  • 2 weeks later...
  • 5 months later...
  • 1 month later...
  • 5 months later...
  • VIP
On 10/10/2015 at 3:05 PM, Draeth said:

The Server shutdown if you write like this:

/Player_ban NICK REASON OTHERSTUFFTHATYOUWROTE

/Player_unban NICK OTHERSTUFFTHATYOUWR

 

in my home_server this working 5* and no problems

 

but in my main server, core crash. Why???

Link to comment
  • 3 months later...
  • 4 years later...

How do I get the system to change give / player_ban Name, Reason, and time?

 

 

Error compile: 
cmd_gm.cpp:4388:7: error: redefinition of 'do_player_ban'
ACMD (do_player_ban)
      ^
cmd_gm.cpp:2758:7: note: previous definition is here
ACMD (do_player_ban)
      ^
cmd_gm.cpp:4450:7: error: redefinition of 'do_player_unban'
ACMD (do_player_unban)
      ^
cmd_gm.cpp:2820:7: note: previous definition is here
ACMD (do_player_unban)
      ^
2 errors generated.
gmake: *** [Makefile:76: debug/cmd_gm.o] Error 1

Edited by tarata12
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.