Approval System

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)
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();
* 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:
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:
People can change really fast. How someone is now isn't always how they'll be 6 months from now. I see nothing wrong with this release. It's actually a great idea. Good job TS.

Yea, but you can't say that everyone is like that. If you know a person for months, and you just know he is good person I don't think he will change. And it's not that hard to find out that somebody is abusing their powers.
 
Yea, but you can't say that everyone is like that. If you know a person for months, and you just know he is good person I don't think he will change. And it's not that hard to find out that somebody is abusing their powers.

Better safe than sorry :) Players hate to have rollbacks, and if a GM goes rogue, at least this will hinder it and possibly prevent one.
 
Good start, but you shouldn't be hiring people that you can't trust to begin with.

It's just a precaution.

---------- Post added at 08:00 AM ---------- Previous post was at 07:58 AM ----------

You shouldnt read/write to the database every time.

What do you mean? =D

Reason for creating this: I created a server for friends to play. I give them GM power, they spam summon mob and causes lag to the server. So we decided to make this system.
 
Last edited:
Lol, you do?
I bet a lot.. wait, I've seen a few players above the age of 18 playing GMS/private servers. But that was 2 years ago.

Not to get off topic but yeah I'm 21 and own my own server (not under the name of my friends anymore *yay me*) And the only people who apply for GM or who actually come to the game and play aren't even 17-18 yet. Most of them still have bed times.

So yeah this system will help out a lot and stop GMs from spamming commands or whatever.(i'm guessing this is what it's for :huh:) 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...
 
Not to get off topic but yeah I'm 21 and own my own server (not under the name of my friends anymore *yay me*) And the only people who apply for GM or who actually come to the game and play aren't even 17-18 yet. Most of them still have bed times.

So yeah this system will help out a lot and stop GMs from spamming commands or whatever.(i'm guessing this is what it's for :huh:) 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...

I don't think they know how to DDoS. =D. It isn't easy and it's illegal.
 
It's just a precaution.

---------- Post added at 08:00 AM ---------- Previous post was at 07:58 AM ----------



What do you mean? =D

Reason for creating this: I created a server for friends to play. I give them GM power, they spam summon mob and causes lag to the server. So we decided to make this system.

Instead of using the database to store and read the values for the characters clearance, store it in variables and only use the database when the character is not there. It would be easier if you were to just modify maplecharacter instead of making another class. This just seems to be more then it needs to be.
 
Not to get off topic but yeah I'm 21 and own my own server (not under the name of my friends anymore *yay me*) And the only people who apply for GM or who actually come to the game and play aren't even 17-18 yet. Most of them still have bed times.

So yeah this system will help out a lot and stop GMs from spamming commands or whatever.(i'm guessing this is what it's for :huh:) 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...

Then why continuing a Maple server?
(After this post, I'll stop being offtopic in this thread.. It's the last one.)
 
Back