Jump to content
bitmask

[PI] Player Flagging - Make a end to advertising in your server!

Recommended Posts

[CENTER]Hello, some of you who are hosting a live server might find this useful. It took like 2 minutes to write though so you need to add more words to flag censor.

Add this String in your Config.java
[CODE]/**
* The words that player gets flagged.
*/
public static final String[] FLAG_WORDS = {"www.", ".com", ".c0m", ".co.uk", ".net", ".org", ".zzl.org", ".0rg", ".c0 m"};[/CODE]

Add in Client java this:
[CODE]
private PlayerFlag playerFlag = new PlayerFlag(this);[/CODE]

[CODE]public PlayerFlag getPlayerFlag() {
return playerFlag;
}[/CODE]



PlayerFlag.java
[CODE]package server.antimacro;

import server.Configuration;
import server.Connection;
import server.model.players.Client;
import server.model.players.Player;
import server.model.players.PlayerHandler;

public class PlayerFlag {

/**
* The maxinum amount of flags until player will be force banned.
*/
public static final int MAX_FLAGS = 25;
/**
* Represents the flag amount.
*/
private int flags;
/**
* Client instance.
*/
private Client c;
/**
* Constructs the PlayerFlag.
* [MENTION=75098]Para[/MENTION]m c
*
*/
public PlayerFlag(Client c) {
this.c = c;
}

/**
* Processes player flagging.
*/
public void process(String message) {
for (String flagWords : Configuration.FLAG_WORDS)
if (message.toLowerCase().contains(flagWords)) {
c.sendMessage("Your character has received a warning. (Total flags: "+flags+"/"+MAX_FLAGS+")");
flags++;

if (flags == MAX_FLAGS) {
Connection.addNameToBanList(c.playerName);
Connection.addNameToFile(c.playerName);
PlayerHandler.getPlayer(c.playerName).disconnected = true;
c.forceLogout();
flags = 0;
}
return;
}
}

}

[/CODE]

Replace your Chat packet with mine.

[CODE]package server.model.players.packets;

import server.Connection;
import server.model.players.Client;
import server.model.players.PacketType;
import server.util.Misc;

/**
* Chat
**/
public class Chat implements PacketType {

[MENTION=15855]Over[/MENTION]ride
public void processPacket(Client c, int packetType, int packetSize) {
c.setChatTextEffects(c.getInStream().readUnsignedByteS());
c.setChatTextColor(c.getInStream().readUnsignedByteS());
c.setChatTextSize((byte) (c.packetSize - 2));
c.inStream.readBytes_reverseA(c.getChatText(), c.getChatTextSize(), 0);
String message = Misc.textUnpack(c.getChatText(), c.packetSize - 2).toLowerCase();
if (System.currentTimeMillis() < c.muteEnd) {
c.sendMessage("You are muted for breaking a rule.");
return;
} else {
c.muteEnd = 0;
}
ReportHandler.addText(c.playerName, c.getChatText(), packetSize - 2);

if (!Connection.isMuted(c))
{
c.setChatTextUpdateRequired(true);
c.getPlayerFlag().process(message);
}
else
{
c.sendMessage("You are muted for breaking a rule.");
return;
}
}
}
[/CODE]

[B]Media[/B]
[img]http://puu.sh/akmjn/3314089d66.jpg[/img]

Okay now i've advertised 25 times, this is what has happened.
[img]http://puu.sh/akmDB/c9f224a920.jpg[/img]

You can of course change the maxinum flags to more. Next you're probably going to ask how you change it?
-Simple, even cave man can do it.

In PlayerFlags.java you'll find this at top of the file:

[CODE]public static final int MAX_FLAGS = 25;[/CODE]
Change the number to higher or lower to change maxinum flag amount.

EDIT: Update - Force logout method, add this to Client.java
[code]/**
* Sends to the player a forced logout.
*/
public void forceLogout() {
if (this.clan != null) {
this.clan.removeMember(this);
}
outStream.createFrame(109);
if (hasNpc == true)
getSummoning().pickUpClean(this, summonId);
CycleEventHandler.getSingleton().stopEvents(this);
properLogout = true;
ConnectedFrom.addConnectedFrom(this, connectedFrom);
}[/code]

[B][U]Credits to Fuzen Seth[/U][/B][/CENTER] Edited by FUZENSETH
a fix

Share this post


Link to post
Share on other sites
Well written, mind if we add this in the tutorial database on the homepage? You'll get credit.

Share this post


Link to post
Share on other sites
Very very good!
Good Contribution!

Share this post


Link to post
Share on other sites
Amazing work! I like seeing people contribute more ;D.

Share this post


Link to post
Share on other sites
[quote name='StevenAbraham']Well written, mind if we add this in the tutorial database on the homepage? You'll get credit.[/QUOTE]

Sure, feel free to.

Share this post


Link to post
Share on other sites
Nice guide! Love the detail and etc.

Share this post


Link to post
Share on other sites
Really nice guide, thanks for the contribution Fuzen.

Share this post


Link to post
Share on other sites
Thanks all.

24.7.2014 Added a fix; if the message contained before 2+ words it would count them all so this issue has been now fixed if one message contains many flag words it count it still be flag++;

Share this post


Link to post
Share on other sites
EDIT: Fixed it. Thanks Edited by TheDevinM

Share this post


Link to post
Share on other sites
Deserves a bump since this is useful and easy-to-add snippet.

Share this post


Link to post
Share on other sites

×