Skip to content

How to setup different ranks to by pass a command?

Devwarlt edited this page Feb 27, 2017 · 1 revision

[Tutorial] Setting up different ranks to by-pass a command.

Language used:

  • C#.

Software used:

Microsoft Visual Studio Community:

  • Windows: download link here.

Game Source used:

Realm of the Mad God 27.3.2 Server:

  • Download link here.

Adding public variables to compare on another file.

1) Navigate on your server solution and go to "wServer > Program.cs";

2) At "Program.cs" bellow scope of static class add these public variables for reference:

...

namespace wServer

{

internal static class Program
{
    public const int server_Owner          = 7;
    public const int server_Co_Owner       = 6;
    public const int server_Admin          = 5;
    public const int server_Dev            = 4;
    public const int server_Yt             = 3;
    public const int server_Vip            = 2;
    public const int server_Player         = 1;
    public const int server_Null           = 0;
    public static readonly List<int> server_Ranks = new List<int> {
        server_Null, server_Player, server_Vip,
        server_Yt, server_Dev, server_Admin,
        server_Co_Owner, server_Owner
    };
    ...

3) At region scope import this library, System.Collections.Generic:

...

using System.Collections.Generic;

namespace wServer

{

internal static class Program
{
    public const int server_Owner          = 7;
    public const int server_Co_Owner       = 6;
    public const int server_Admin          = 5;
    public const int server_Dev            = 4;
    public const int server_Yt             = 3;
    public const int server_Vip            = 2;
    public const int server_Player         = 1;
    public const int server_Null           = 0;
    public static readonly List<int> server_Ranks = new List<int> {
        server_Null, server_Player, server_Vip,
        server_Yt, server_Dev, server_Admin,
        server_Co_Owner, server_Owner
    };
    ...

4) Navigate on your server solution and go to "wServer > realm > commands> WorldCommand.cs";

5) At "WorldCommand.cs" bellow scope of static class add these internal functions:

...

namespace wServer.realm.commands

{

//Unique command to do different actions for each rank.
internal class Firstcommand : Command
{
    public Firstcommand() : base("firstcommand") { }
    protected override bool Process(Player player, RealmTime time, string[] args)
    {
        int PlayerRank = player.Client.Account.Rank;
        switch(PlayerRank)
        {
            case Program.server_Owner:
                player.SendInfo("I'm an owner.");
                return true;
            case Program.server_Co_Owner:
                player.SendInfo("I'm a co-owner.");
                return true;
            case Program.server_Admin:
                player.SendInfo("I'm an administrator.");
                return true;
            case Program.server_Dev:
                player.SendInfo("I'm a developer.");
                return true;
            case Program.server_Yt:
                player.SendInfo("I'm a youtuber.");
                return true;
            case Program.server_Vip:
                player.SendInfo("I'm a very important person.");
                return true;
            case Program.server_Player:
                player.SendInfo("I'm a player.");
                return true;
            case Program.server_Null:
                player.SendInfo("I don't rank rank.");
                return true;
            default:
                player.SendError("An error occured, contact administrator.");
                return true;
        }
    }
}
//Unique command to by-pass rank greater than specific rank
//You could adapt it to by-pass greater-equal than, lesser-equal than or whatever
internal class SecondCommand : Command
{
    public SecondCommand() : base("secondcommand") { }
    protected override bool Process(Player player, RealmTime time, string[] args)
    {
        int PlayerRank = player.Client.Account.Rank;
        if (PlayerRank > Program.server_Player)
        {
            player.SendInfo("Rank lesser than 'player' cannot use this command.");
            return true;
        } else
        {
            player.SendHelp("You don't have enough rights to use this command.");
            return true;
        }
    }
}
//Unique command to by-pass rank into between specific array values
internal class ThirdCommand : Command
{
    public ThirdCommand() : base("thirdcommand") { }
    protected override bool Process(Player player, RealmTime time, string[] args)
    {
        int PlayerRank = player.Client.Account.Rank;
        if ((Program.server_Ranks.Contains(PlayerRank))
            && (PlayerRank > Program.server_Ranks[Program.server_Player - 1])
            && (PlayerRank <= Program.server_Ranks[Program.server_Admin -1]))
        {
            player.SendInfo(@"Rank lesser than 'player' and greater than 'admin'
                cannot use this command.");
            return true;
        } else
        {
            player.SendHelp("You don't have enough rights to use this command.");
            return true;
        }
    }
}

...


Understanding by-pass and usages.

Many alternative RotMG projects aim to have their own ranking differentiation mechanism and thus limit commands that only specific members will have access to. However, it's necessary to program this mechanism manually. As mentioned earlier, this by-pass system limits some ranks in having access to some commands or even a single command performing several different functions depending on the user rank.

The examples shown above are 3 options to perform a by-pass per user rank, however you can adapt them the way you want. Functions such as foreach and switch can be used to customize a better by-pass verification mechanism too.

Credits:

  • @Devwarlt (GitHub) for tutorial;
  • @Fabian (GitHub) for Server source.

Clone this wiki locally