Disable 'hacks setting' screen (as it is pointless to show anyways) when server sends hax/ophax in motd.

This commit is contained in:
UnknownShadow200 2015-12-15 10:05:17 +11:00
parent 3e6e270044
commit d7e3e9d200
8 changed files with 76 additions and 38 deletions

View File

@ -16,7 +16,7 @@ namespace ClassicalSharp {
for( int i = widgets.Length - 1; i >= 0; i-- ) {
Widget widget = widgets[i];
if( widget != null && widget.Bounds.Contains( mouseX, mouseY ) ) {
if( widget.OnClick != null )
if( widget.OnClick != null && !widget.Disabled )
widget.OnClick( game, widget );
return true;
}

View File

@ -18,6 +18,7 @@ namespace ClassicalSharp {
public override void Init() {
base.Init();
game.Events.HackPermissionsChanged += CheckHacksAllowed;
buttons = new ButtonWidget[] {
// Column 1
Make( -140, -150, "Options", Anchor.Centre,
@ -51,6 +52,17 @@ namespace ClassicalSharp {
MakeBack( true, titleFont,
(g, w) => g.SetNewScreen( null ) ),
};
CheckHacksAllowed( null, null );
}
void CheckHacksAllowed( object sender, EventArgs e ) {
for( int i = 0; i < buttons.Length; i++ )
buttons[i].Disabled = false;
if( !game.LocalPlayer.CanAnyHacks ) {
buttons[2].Disabled = true; // hack permissions
buttons[3].Disabled = true; // env settings
buttons[8].Disabled = true; // select texture pack
}
}
ButtonWidget Make( int x, int y, string text, Anchor vDocking, Action<Game, Widget> onClick ) {
@ -68,5 +80,10 @@ namespace ClassicalSharp {
game.SetNewScreen( null );
return true;
}
public override void Dispose() {
base.Dispose();
game.Events.HackPermissionsChanged -= CheckHacksAllowed;
}
}
}

View File

@ -35,11 +35,12 @@ namespace ClassicalSharp {
Height = defaultHeight;
}
static TextureRec shadowRec = new TextureRec( 0, 66/256f, 200/256f, 20/256f );
static TextureRec selectedRec = new TextureRec( 0, 86/256f, 200/256f, 20/256f );
static Texture shadowTex = new Texture( 0, 0, 0, 0, 0, shadowRec );
static Texture selectedTex = new Texture( 0, 0, 0, 0, 0, selectedRec );
static Texture shadowTex = new Texture( 0, 0, 0, 0, 0,
new TextureRec( 0, 66/256f, 200/256f, 20/256f ) );
static Texture selectedTex = new Texture( 0, 0, 0, 0, 0,
new TextureRec( 0, 86/256f, 200/256f, 20/256f ) );
static Texture disdabledTex = new Texture( 0, 0, 0, 0, 0,
new TextureRec( 0, 46/256f, 200/256f, 20/256f ) );
public string Text;
public void SetText( string text ) {
graphicsApi.DeleteTexture( ref texture );
@ -57,15 +58,17 @@ namespace ClassicalSharp {
}
public override void Render( double delta ) {
if( texture.IsValid ) {
Texture backTex = Active ? selectedTex : shadowTex;
backTex.ID = game.GuiTexId;
backTex.X1 = X; backTex.Y1 = Y;
backTex.Width = Width; backTex.Height = Height;
backTex.Render( graphicsApi );
FastColour col = Active ? FastColour.White : new FastColour( 200, 200, 200 );
texture.Render( graphicsApi, col );
}
if( !texture.IsValid )
return;
Texture backTex = Active ? selectedTex : shadowTex;
if( Disabled ) backTex = disdabledTex;
backTex.ID = game.GuiTexId;
backTex.X1 = X; backTex.Y1 = Y;
backTex.Width = Width; backTex.Height = Height;
backTex.Render( graphicsApi );
FastColour col = Active ? FastColour.White : new FastColour( 200, 200, 200 );
if( Disabled ) col = new FastColour( 150, 150, 150 );
texture.Render( graphicsApi, col );
}
public override void Dispose() {
@ -73,12 +76,9 @@ namespace ClassicalSharp {
}
public override void MoveTo( int newX, int newY ) {
int deltaX = newX - X;
int deltaY = newY - Y;
texture.X1 += deltaX;
texture.Y1 += deltaY;
X = newX;
Y = newY;
int deltaX = newX - X, deltaY = newY - Y;
texture.X1 += deltaX; texture.Y1 += deltaY;
X = newX; Y = newY;
}
public Func<Game, string> GetValue;

View File

@ -14,6 +14,9 @@ namespace ClassicalSharp {
/// <summary> Whether this widget is currently being moused over. </summary>
public bool Active;
/// <summary> Whether this widget is prevented from being interacted with. </summary>
public bool Disabled;
/// <summary> Invoked when this widget is clicked on. Can be left null. </summary>
public Action<Game, Widget> OnClick;

View File

@ -63,9 +63,8 @@ namespace ClassicalSharp.Commands {
}
public override void Execute( CommandReader reader ) {
foreach( string line in game.Graphics.ApiInfo ) {
foreach( string line in game.Graphics.ApiInfo )
game.Chat.Add( "&a" + line );
}
}
}

View File

@ -8,16 +8,30 @@ namespace ClassicalSharp {
public class LocalPlayer : Player {
/// <summary> Position the player's position is set to when the 'respawn' key binding is pressed. </summary>
public Vector3 SpawnPoint;
/// <summary> The distance (in blocks) that players are allowed to
/// reach to and interact/modify blocks in. </summary>
public float ReachDistance = 5f;
/// <summary> The speed that the player move at, relative to normal speed,
/// when the 'speeding' key binding is held down. </summary>
public float SpeedMultiplier = 10;
public byte UserType;
/// <summary> Whether blocks that the player places that intersect themselves
/// should cause the player to be pushed back in the opposite direction of the placed block. </summary>
public bool PushbackPlacing;
/// <summary> Whether the player has allowed hacks usage as an option.
/// Note that all 'can use X' set by the server override this. </summary>
public bool HacksEnabled = true;
/// <summary> Whether the player is allowed to use any type of hacks. </summary>
public bool CanAnyHacks = true;
/// <summary> Whether the player is allowed to use the types of cameras that use third person. </summary>
public bool CanUseThirdPersonCamera = true;
@ -27,7 +41,7 @@ namespace ClassicalSharp {
/// <summary> Whether the player is allowed to fly in the world. </summary>
public bool CanFly = true;
/// <summary> Whether the player is allowed to teleport to their respawn point. </summary>
/// <summary> Whether the player is allowed to teleport to their respawn coordinates. </summary>
public bool CanRespawn = true;
/// <summary> Whether the player is allowed to pass through all blocks. </summary>
@ -171,7 +185,6 @@ namespace ClassicalSharp {
bool pastJumpPoint = liquidFeet && !(liquidBody || liquidHead)
&& (Position.Y % 1 >= 0.4);
Console.WriteLine( pastJumpPoint );
if( !pastJumpPoint ) {
canLiquidJump = true;
Velocity.Y += speeding ? 0.08f : 0.04f;
@ -267,13 +280,10 @@ namespace ClassicalSharp {
/// <remarks> Recognises +/-hax, +/-fly, +/-noclip, +/-speed, +/-respawn, +/-ophax </remarks>
public void ParseHackFlags( string name, string motd ) {
string joined = name + motd;
if( joined.Contains( "-hax" ) ) {
CanFly = CanNoclip = CanRespawn = CanSpeed =
CanPushbackBlocks = CanUseThirdPersonCamera = false;
} else { // By default (this is also the case with WoM), we can use hacks.
CanFly = CanNoclip = CanRespawn = CanSpeed =
CanPushbackBlocks = CanUseThirdPersonCamera = true;
}
SetAllHacks( true );
// By default (this is also the case with WoM), we can use hacks.
if( joined.Contains( "-hax" ) )
SetAllHacks( false );
ParseFlag( b => CanFly = b, joined, "fly" );
ParseFlag( b => CanNoclip = b, joined, "noclip" );
@ -281,17 +291,21 @@ namespace ClassicalSharp {
ParseFlag( b => CanRespawn = b, joined, "respawn" );
if( UserType == 0x64 )
ParseFlag( b => CanFly = CanNoclip = CanRespawn =
CanSpeed = CanPushbackBlocks = b, joined, "ophax" );
ParseFlag( b => SetAllHacks( b ), joined, "ophax" );
CheckHacksConsistency();
game.Events.RaiseHackPermissionmsChanged();
}
void SetAllHacks( bool allowed ) {
CanAnyHacks = CanFly = CanNoclip = CanRespawn = CanSpeed =
CanPushbackBlocks = CanUseThirdPersonCamera = allowed;
}
static void ParseFlag( Action<bool> action, string joined, string flag ) {
if( joined.Contains( "+" + flag ) ) {
if( joined.Contains( "+" + flag ) )
action( true );
} else if( joined.Contains( "-" + flag ) ) {
else if( joined.Contains( "-" + flag ) )
action( false );
}
}
/// <summary> Disables any hacks if their respective CanHackX value is set to false. </summary>

View File

@ -64,7 +64,8 @@ namespace ClassicalSharp {
/// <summary> Raised when the server or a client-side command sends a message. </summary>
public event EventHandler<ChatEventArgs> ChatReceived;
internal void RaiseChatReceived( string text, CpeMessage type ) { chatArgs.Type = type; chatArgs.Text = text; Raise( ChatReceived, chatArgs ); }
internal void RaiseChatReceived( string text, CpeMessage type ) {
chatArgs.Type = type; chatArgs.Text = text; Raise( ChatReceived, chatArgs ); }
/// <summary> Raised when the user changes chat font to arial or back to bitmapped font,
/// also raised when the bitmapped font changes. </summary>
@ -72,6 +73,9 @@ namespace ClassicalSharp {
internal void RaiseChatFontChanged() { Raise( ChatFontChanged ); }
/// <summary> Raised when the hack permissions of the player changes. </summary>
public event EventHandler HackPermissionsChanged;
internal void RaiseHackPermissionmsChanged() { Raise( HackPermissionsChanged ); }
// Cache event instances so we don't create needless new objects.
IdEventArgs idArgs = new IdEventArgs();

View File

@ -368,6 +368,7 @@ namespace ClassicalSharp {
float jumpHeight = reader.ReadInt16() / 32f;
if( jumpHeight < 0 ) jumpHeight = 1.4f;
p.CalculateJumpVelocity( jumpHeight );
game.Events.RaiseHackPermissionmsChanged();
}
void HandleCpeExtAddEntity2() {