Fix clickable chat not properly checking input for invalid characters on non-FullCP437 servers. (Thanks WhatIDoHere)

This commit is contained in:
UnknownShadow200 2016-01-05 13:33:31 +11:00
parent 8b72de5e79
commit edd321762e
4 changed files with 21 additions and 15 deletions

View file

@ -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 {

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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.