Noclip - how it works

So the base gamemode has this

[ServerCommand( "noclip", Help = "Turns on noclip mode, which makes you non solid and lets you fly around" )]
public static void NoclipCommand()
{
    if ( ConsoleSystem.Caller == null ) return;

    (Current as Game)?.DoPlayerNoclip( ConsoleSystem.Caller );
}

which calls this on the gamemode class

public virtual void DoPlayerNoclip( Player player )
{
	// TODO - check can use cheats

	if ( player is BasePlayer basePlayer )
    {
		if ( basePlayer.DevController is NoclipController )
		{
			Log.Info( "Noclip Mode Off" );
			basePlayer.DevController = null;
		}
		else
		{
			Log.Info( "Noclip Mode On" );
			basePlayer.DevController = new NoclipController();
		}
	}
}

On the player the DevController is always used if it’s set, it has priority over the default controller.

public override PlayerController GetActiveController()
{
	if ( DevController != null ) return DevController;

	return Controller;
}

This means it’s possible to add other development movement types. I can’t actually think of any others that would be useful, but the door is opened by this anyway

20 Likes

is that how custom con commands are going to made?

[ServerCommand( "command", Help = "info" )]
public static void commandMethod() {
    //command stuff
}

Yeah - it needs a review, but right now yeah.

4 Likes

how is that gonna work for commands with args? like “myCommandVar 5”

Like this

[ServerCommand( "myCommandVar", Help = "info" )]
public static void commandMethod( int val ) {
    //command stuff
}
5 Likes

anything built in for permissions?

You can see // TODO - check can use cheats which is where garry plans to implement checks to see if somebody should be allowed to noclip or not.

IMO it would be cleaner it there was an additional attribute for basic permission checks.

For example

[ServerCommand( "myCommandVar", Help = "info" )]
[RequiresRole("AllowNoclip")]
public static void commandMethod( int val ) {
    //command stuff
}

Alternatively a way to implement your own command handler (with the ability to just extend the default one so you don’t have to reinvent the wheel) to allow you to implement it yourself, and whatever else you might need (similar to nancyfx/asp.net core/etc).

6 Likes

That’s a good idea

9 Likes

I wouldn’t name it role but permission instead. Roles would be collections of permissions.

[ServerCommand( "myCommandVar", Help = "info" )]
[RequiresPermission("AllowNoclip")]
public static void commandMethod( int val ) {
    //command stuff
}

admin role would include AllowNoClip permission

12 Likes

That would be amazing if combined with the ability to create custom permissions. For a while I’ve been scratching my head over how admins might be handled.

1 Like

Now this. This. I like.