Amateur? ME?! You are the nab who cannot even create a proper bridge between MMOCore and Olympiad Games.
See the code snippet and LEARN from the professionals!
public abstract class MMOController<T extends MMOConnection<T, RP, SP>, RP extends ReceivablePacket<T, RP, SP>, SP extends SendablePacket<T, RP, SP>> {
// ... lots of code is here
@Inject
private OlympiadGamesService olympiadGamesService;
/**
* An easy way to apply any special limitations on incoming connections. At default it contains
* a flood protection.<br>
* Overriding implementations should call the super method before anything else gets checked.<br>
* <br>
* NOTE: Uses a special way of logging to avoid console flood.
*
* @param sc the inbound connection from a possible client
* @return true if the connection is valid, and should be allowed, no otherwise
*/
protected boolean acceptConnectionFrom(SocketChannel sc) {
if (olympiadGamesService.isLoser((L2PcInstance) sc)) {
_log.warn("Player who lost olympiad games should not be able to connect!");
return false;
}
final String host = sc.socket().getInetAddress().getHostAddress();
final Result isFlooding = _accepts.isFlooding(host, true);
switch (isFlooding) {
case REJECTED: {
_log.warn("Rejected connection from " + host);
return false;
}
case WARNED: {
_log.warn("Connection over warn limit from " + host);
return true;
}
default:
return true;
}
}
/**
* An easy way to apply any special limitations on incoming packets. At default it contains a
* flood protection.<br>
* Overriding implementations should call the super method before anything else gets checked.<br>
* <br>
* NOTE: Uses a special way of logging to avoid console flood.
*
* @param client the associated client
* @param opcode the opcode of the potential packet (for debugging purposes)
* @return true if the client can be allowed to receive a packet, no otherwise
*/
protected boolean canReceivePacketFrom(T client, int opcode) {
if (olympiadGamesService.isLoser(client.getPlayer()) {
_log.warn("Player who lost olympiad games should not be able to receive packets from the server!");
return false;
}
final String key = client.getValidUID();
switch (Result.max(_packets.isFlooding(key, true), _errors.isFlooding(key, false))) {
case REJECTED: {
_log.warn("Rejected packet (0x" + Integer.toHexString(opcode) + ") from " + client);
return false;
}
case WARNED: {
_log.warn("Packet over warn limit (0x" + Integer.toHexString(opcode) + ") from " + client);
return true;
}
default:
return true;
}
}
}