mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-24 10:02:08 -05:00
Fix clickable chat not properly checking input for invalid characters on non-FullCP437 servers. (Thanks WhatIDoHere)
This commit is contained in:
parent
8b72de5e79
commit
edd321762e
4 changed files with 21 additions and 15 deletions
|
@ -63,6 +63,15 @@ namespace ClassicalSharp {
|
|||
if( mode == Anchor.BottomOrRight) return axisSize - elemSize - offset;
|
||||
return (axisSize - elemSize) / 2 + offset;
|
||||
}
|
||||
|
||||
protected bool IsValidInputChar( char c ) {
|
||||
if( c >= ' ' && c <= '~' ) return true; // ascii
|
||||
|
||||
bool isCP437 = Utils.ControlCharReplacements.IndexOf( c ) >= 0 ||
|
||||
Utils.ExtendedCharReplacements.IndexOf( c ) >= 0;
|
||||
bool supportsCP437 = game.Network.ServerSupportsFullCP437;
|
||||
return supportsCP437 && isCP437;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Anchor {
|
||||
|
|
|
@ -80,7 +80,7 @@ namespace ClassicalSharp {
|
|||
Font chatFont, chatInputFont, chatUnderlineFont, announcementFont;
|
||||
public override void Init() {
|
||||
int fontSize = (int)(12 * game.GuiChatScale);
|
||||
Utils.Clamp( ref fontSize, 8, 60 );
|
||||
Utils.Clamp( ref fontSize, 8, 60 );
|
||||
chatFont = new Font( "Arial", fontSize );
|
||||
chatInputFont = new Font( "Arial", fontSize, FontStyle.Bold );
|
||||
chatUnderlineFont = new Font( "Arial", fontSize, FontStyle.Underline );
|
||||
|
@ -151,7 +151,7 @@ namespace ClassicalSharp {
|
|||
}
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
public override void Dispose() {
|
||||
if( HandlesAllInput ) {
|
||||
game.chatInInputBuffer = textInput.chatInputText.ToString();
|
||||
if( game.CursorVisible )
|
||||
|
@ -307,6 +307,13 @@ namespace ClassicalSharp {
|
|||
" may have viruses, or things you may not want to open/see."
|
||||
) );
|
||||
} else if( game.ClickableChat ) {
|
||||
for( int i = 0; i < text.Length; i++ ) {
|
||||
if( !IsValidInputChar( text[i] ) ) {
|
||||
Console.WriteLine( i + "," + text[i] );
|
||||
game.Chat.Add( "&eChatline contained characters that can't be sent on this server." );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
textInput.AppendText( text );
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace ClassicalSharp {
|
|||
public sealed partial class TextInputWidget : Widget {
|
||||
|
||||
public override bool HandlesKeyPress( char key ) {
|
||||
if( chatInputText.Length < len && IsValidChar( key ) ) {
|
||||
if( chatInputText.Length < len && IsValidInputChar( key ) && key != '&' ) {
|
||||
if( caretPos == -1 ) {
|
||||
chatInputText.Append( chatInputText.Length, key );
|
||||
} else {
|
||||
|
@ -141,8 +141,8 @@ namespace ClassicalSharp {
|
|||
if( String.IsNullOrEmpty( text ) ) return true;
|
||||
|
||||
for( int i = 0; i < text.Length; i++ ) {
|
||||
if( !IsValidChar( text[i] ) ) {
|
||||
game.Chat.Add( "&eClipboard contained characters that can't be sent." );
|
||||
if( !IsValidInputChar( text[i] ) ) {
|
||||
game.Chat.Add( "&eClipboard contained characters that can't be sent on this server." );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,16 +188,6 @@ namespace ClassicalSharp {
|
|||
altText.Y = altText.texture.Y1;
|
||||
}
|
||||
|
||||
bool IsValidChar( char c ) {
|
||||
if( c == '&' ) return false;
|
||||
if( c >= ' ' && c <= '~' ) return true; // ascii
|
||||
|
||||
bool isCP437 = Utils.ControlCharReplacements.IndexOf( c ) >= 0 ||
|
||||
Utils.ExtendedCharReplacements.IndexOf( c ) >= 0;
|
||||
bool supportsCP437 = game.Network.ServerSupportsFullCP437;
|
||||
return supportsCP437 && isCP437;
|
||||
}
|
||||
|
||||
public void SendTextInBufferAndReset() {
|
||||
SendInBuffer();
|
||||
typingLogPos = game.Chat.InputLog.Count; // Index of newest entry + 1.
|
||||
|
|
Loading…
Add table
Reference in a new issue