- Joined
- Dec 31, 2008
- Messages
- 319
- Reaction score
- 65
A simple system made to prevent your SGM to abuse their authority by spamming command that will cause your server. This is a piece of random noob coding. Hope you all dun flame.
PlayerAuth.java(have to make .java yourself)
Admin.java(You should know where to add it)
Add this under you commanddefinition for Admin.java
PlayerLoggedinHandler.java(*)
* Made for the purpose of de-authorizing if you forget to de-authorize the person yourself. It will de-authorize the player
when the person log in.
How to execute the script:
EDIT: I will be adding the SQL script to be added into your database soon.
EDIT2: SQL SCRIPT ADDED :
Credit:
rubbercow AKA ApplePied in RZ.
LameKids AKA hecari in RZ.
NOTE: DO NOT FLAME IF THERE ARE EXPLOIT OR SO, BECAUSE WE ARE NOT PROFESSIONAL CODER. WE ARE JUST CODING FOR THE SAKE OF LEARNING.
PlayerAuth.java(have to make .java yourself)
PHP:
package net.sf.odinms.tools.custom;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import net.sf.odinms.client.MapleCharacter;
import net.sf.odinms.database.DatabaseConnection;
/*
* PlayerAuth class: authorisation system for player commands
* CREDITS:
* AUTHOR: rubbercow
* CONCEPT: LameKids
* DESC: This system is meant to help insulate the server against spamming by
* implementing a system where a player is checked for clearance before allowing
* a potentially spammable function, without reducing server usability.
* NOTES:
* - For security reasons, there is no way to set a player's authlevel to
* <adminLevel> in-game. This will have to be done manually through the
* SQL database.
*
* - For security reasons, players are not allowed to modify the
* authorisation level of a player with clearance level 3. This will have
* to be done manually through the SQL database.
*
*/
public class PlayerAuth {
private static int adminLevel = 7; // Level that is considered server admin (able to auth others)
private static int minAuthLvl = 1; // Minimum configurable level that is considered authorised
private static int tmpAuthLvl = 1; // Level that indicates tempoary authorisation
private static int maxAuthLvl = 2; // Maximum configurable level that is considered authorised
private static int nonAuthLvl = 0; // Level that is considered to be not authorised
public static void authorisePlayer(MapleCharacter target, int auth) {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps;
if (auth > --minAuthLvl && auth < ++maxAuthLvl && auth != adminLevel) { // Authorisation levels range from 1 - 3, where only 3 is able to set authorisation (Server Admin)
try {
ps = con.prepareStatement("UPDATE characters SET clearance = ? WHERE id = ?");
ps.setInt(1, auth);
ps.setInt(2, target.getId());
ps.execute();
} catch (SQLException e) {
System.out.println("\r\nERROR: Error while attempting to authorise "+target.getName()+".\r\nDUMP:\r\n"+e);
}
}
}
public static void deauthorisePlayer(MapleCharacter target) {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps;
try {
ps = con.prepareStatement("UPDATE characters SET clearance = ? WHERE id = ?");
ps.setInt(1, nonAuthLvl);
ps.setInt(2, target.getId());
ps.execute();
} catch (SQLException e) {
System.out.println("\r\nERROR: Error while attempting to deauthorise "+target.getName()+".\r\nDUMP:\r\n"+e);
}
}
public static int authLevel(MapleCharacter target) {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps;
int auth = -1;
try {
ps = con.prepareStatement("SELECT clearance FROM characters WHERE id = ?");
ps.setInt(1, target.getId());
ResultSet rs = ps.executeQuery();
if (rs.next()) {
auth = rs.getInt("clearance");
}
rs.close();
ps.close();
} catch (SQLException e) {
System.out.println("\r\nERROR: Error while attempting to get authorisation level of "+target.getName()+".\r\nDUMP:\r\n"+e);
}
if (auth == -1) {
System.out.println("\r\nERROR: Error while attempting to get authorisation level of "+target.getName()+".");
return 0;
} else {
return auth;
}
}
public static boolean isAuthorised(MapleCharacter target) {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps;
int auth = -1;
boolean isAuth = false;
try {
ps = con.prepareStatement("SELECT clearance FROM characters WHERE id = ?");
ps.setInt(1, target.getId());
ResultSet rs = ps.executeQuery();
if (rs.next()) {
auth = rs.getInt("clearance");
}
rs.close();
ps.close();
} catch (SQLException e) {
System.out.println("\r\nERROR: Error while attempting to get authorisation level of "+target.getName()+".\r\nDUMP:\r\n"+e);
}
if (auth == -1) {
System.out.println("\r\nERROR: Error while attempting to get authorisation level of "+target.getName()+".");
return false;
} else {
isAuth = auth > 0 ? true : false;
return isAuth;
}
}
public static boolean canSetAuth(MapleCharacter target) {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps;
int auth = -1;
boolean isAuth = false;
try {
ps = con.prepareStatement("SELECT clearance FROM characters WHERE id = ?");
ps.setInt(1, target.getId());
ResultSet rs = ps.executeQuery();
if (rs.next()) {
auth = rs.getInt("clearance");
}
rs.close();
ps.close();
} catch (SQLException e) {
System.out.println("\r\nERROR: Error while attempting to get authorisation level of "+target.getName()+".\r\nDUMP:\r\n"+e);
}
if (auth == -1) {
System.out.println("\r\nERROR: Error while attempting to get authorisation level of "+target.getName()+".");
return false;
} else {
isAuth = auth == adminLevel ? true : false;
return isAuth;
}
}
public static void loginCheck(MapleCharacter target) {
boolean doAuthReset = true;
int authLevel = PlayerAuth.authLevel(target);
doAuthReset = authLevel == tmpAuthLvl ? true : false; // IF AUTHLVL == 1, SET AUTHLVL 0; IF AUTHLVL == 2+ || 0, DO NOTHING
if (doAuthReset) {
PlayerAuth.deauthorisePlayer(target);
}
}
}
Admin.java(You should know where to add it)
PHP:
} else if (splitted[0].equals("!authorise")) {
MapleCharacter target = c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]);
if (target != null) {
if (PlayerAuth.canSetAuth(player)) {
PlayerAuth.authorisePlayer(target, 1);
} else {
mc.dropMessage("You have insufficent privilages.");
}
} else {
mc.dropMessage("Player was not found.");
}
} else if (splitted[0].equals("!powerauth")) {
MapleCharacter target = c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]);
if (target != null) {
if (PlayerAuth.canSetAuth(player)) {
PlayerAuth.authorisePlayer(target, 2);
} else {
mc.dropMessage("You have insufficent privilages.");
}
} else {
mc.dropMessage("Player was not found.");
}
} else if (splitted[0].equals("!deauthorise")) {
MapleCharacter target = c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]);
if (target != null) {
if (PlayerAuth.canSetAuth(player)) {
PlayerAuth.deauthorisePlayer(target);
} else {
mc.dropMessage("You have insufficent privilages.");
}
} else {
mc.dropMessage("Player was not found.");
}
} else if (splitted[0].equals("!checkauth")) {
MapleCharacter target = c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]);
if (target != null) {
if (PlayerAuth.isAuthorised(player)) {
boolean auth = PlayerAuth.isAuthorised(target);
String ret = auth ? "currently authorised" : "not authorised";
mc.dropMessage(target.getName()+" is "+ret+".");
} else {
mc.dropMessage("You have insufficent privilages.");
}
} else {
mc.dropMessage("Player was not found.");
}
}
}
Add this under you commanddefinition for Admin.java
PHP:
new CommandDefinition("authorise", 4),
new CommandDefinition("powerauth", 4),
new CommandDefinition("deauthorise", 4),
new CommandDefinition("checkauth", 4)
PlayerLoggedinHandler.java(*)
PHP:
if (pendingBuddyRequest != null) {
player.getBuddylist().put(new BuddylistEntry(pendingBuddyRequest.getName(), pendingBuddyRequest.getId(), -1, false));
c.getSession().write(MaplePacketCreator.requestBuddylistAdd(pendingBuddyRequest.getId(), pendingBuddyRequest.getName()));
}
PlayerAuth.loginCheck(player); // Check authorisation status [ADD THIS]
player.checkMessenger();
when the person log in.
How to execute the script:
PHP:
if (!PlayerAuth.isAuthorised(player)) {
mc.dropMessage("You have insufficent privilages.");
return;
}
EDIT: I will be adding the SQL script to be added into your database soon.
EDIT2: SQL SCRIPT ADDED :
PHP:
ALTER TABLE characters ADD COLUMN clearance int(127) not null;
Credit:
rubbercow AKA ApplePied in RZ.
LameKids AKA hecari in RZ.
NOTE: DO NOT FLAME IF THERE ARE EXPLOIT OR SO, BECAUSE WE ARE NOT PROFESSIONAL CODER. WE ARE JUST CODING FOR THE SAKE OF LEARNING.
Last edited:
) Cause you can tell a 13 yr old to stop and they'll just keep going out of spite. Then you ban them, they cry, try to DDoS the server, and it really just becomes a hassle...
