From 7425c1b6c1efb598b18a038e5d0b2e8a38507d70 Mon Sep 17 00:00:00 2001 From: Fernando Cortez Date: Tue, 20 Apr 2021 11:36:34 -0400 Subject: [PATCH 1/4] sanitized text in input/IP & port fields on input change callback --- Assets/BossRoom/Prefabs/UI/PopupPanel.prefab | 201 ++++++++---------- .../BossRoom/Scripts/Client/UI/PopupPanel.cs | 41 ++++ 2 files changed, 128 insertions(+), 114 deletions(-) diff --git a/Assets/BossRoom/Prefabs/UI/PopupPanel.prefab b/Assets/BossRoom/Prefabs/UI/PopupPanel.prefab index c16a5e7aa..19d983413 100644 --- a/Assets/BossRoom/Prefabs/UI/PopupPanel.prefab +++ b/Assets/BossRoom/Prefabs/UI/PopupPanel.prefab @@ -733,7 +733,19 @@ MonoBehaviour: m_Calls: [] m_OnValueChanged: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 2699227445768669173} + m_TargetAssemblyTypeName: BossRoom.Visual.PopupPanel, BossRoom.Client + m_MethodName: SanitizePortText + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 m_CaretColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} m_CustomCaretColor: 0 m_SelectionColor: {r: 0.65882355, g: 0.80784315, b: 1, a: 0.7529412} @@ -810,8 +822,7 @@ MonoBehaviour: m_text: Main Text m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 9641ce046d2227445b9684161a165f68, type: 2} - m_sharedMaterial: {fileID: -4106257185398102161, guid: 9641ce046d2227445b9684161a165f68, - type: 2} + m_sharedMaterial: {fileID: -4106257185398102161, guid: 9641ce046d2227445b9684161a165f68, type: 2} m_fontSharedMaterials: [] m_fontMaterial: {fileID: 0} m_fontMaterials: [] @@ -945,8 +956,7 @@ MonoBehaviour: m_text: Title Text m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2} - m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e, - type: 2} + m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2} m_fontSharedMaterials: [] m_fontMaterial: {fileID: 0} m_fontMaterials: [] @@ -970,7 +980,7 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 18 + m_fontSize: 31.25 m_fontSizeBase: 32 m_fontWeight: 400 m_enableAutoSizing: 1 @@ -1306,8 +1316,7 @@ MonoBehaviour: m_text: Sub Text m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 9641ce046d2227445b9684161a165f68, type: 2} - m_sharedMaterial: {fileID: -4106257185398102161, guid: 9641ce046d2227445b9684161a165f68, - type: 2} + m_sharedMaterial: {fileID: -4106257185398102161, guid: 9641ce046d2227445b9684161a165f68, type: 2} m_fontSharedMaterials: [] m_fontMaterial: {fileID: 0} m_fontMaterials: [] @@ -2072,7 +2081,19 @@ MonoBehaviour: m_Calls: [] m_OnValueChanged: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 2699227445768669173} + m_TargetAssemblyTypeName: BossRoom.Visual.PopupPanel, BossRoom.Client + m_MethodName: SanitizeInputText + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 m_CaretColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} m_CustomCaretColor: 0 m_SelectionColor: {r: 0.65882355, g: 0.80784315, b: 1, a: 0.7529412} @@ -2616,8 +2637,7 @@ MonoBehaviour: m_text: OK m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2} - m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e, - type: 2} + m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2} m_fontSharedMaterials: [] m_fontMaterial: {fileID: 0} m_fontMaterials: [] @@ -2641,7 +2661,7 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 28.45 + m_fontSize: 35.15 m_fontSizeBase: 32 m_fontWeight: 400 m_enableAutoSizing: 1 @@ -2690,255 +2710,208 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 6702871171647363811} m_Modifications: - - target: {fileID: 442359802337233140, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 442359802337233140, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchorMax.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 442359802337233140, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 442359802337233140, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchorMin.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 442359802337233140, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 442359802337233140, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchoredPosition.x value: 0 objectReference: {fileID: 0} - - target: {fileID: 442359802337233140, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 442359802337233140, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchoredPosition.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_Pivot.x value: 0.5 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_Pivot.y value: 0.5 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_RootOrder value: 7 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchorMax.x value: 0.92985773 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchorMax.y value: 0.3086479 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchorMin.x value: 0.06835955 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchorMin.y value: 0.13082394 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_SizeDelta.x value: -98.7999 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_SizeDelta.y value: -50 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_LocalPosition.x value: 0 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_LocalPosition.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_LocalPosition.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_LocalRotation.w value: 1 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_LocalRotation.x value: -0 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_LocalRotation.y value: -0 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_LocalRotation.z value: -0 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchoredPosition.x value: 22.850464 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchoredPosition.y value: 68.2 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_LocalEulerAnglesHint.x value: 0 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_LocalEulerAnglesHint.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 1531301342784867179, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1531301342784867179, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchorMax.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 1531301342784867179, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1531301342784867179, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchorMin.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 1531301342784867179, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1531301342784867179, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchoredPosition.x value: 0 objectReference: {fileID: 0} - - target: {fileID: 1531301342784867179, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 1531301342784867179, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchoredPosition.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 2174966933596881657, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 2174966933596881657, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_FontData.m_MaxSize value: 40 objectReference: {fileID: 0} - - target: {fileID: 7636978241429846730, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 7636978241429846730, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchorMax.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 7636978241429846730, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 7636978241429846730, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchorMin.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 7636978241429846730, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 7636978241429846730, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchoredPosition.x value: 0 objectReference: {fileID: 0} - - target: {fileID: 7636978241429846730, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 7636978241429846730, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchoredPosition.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 7912206577138345114, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 7912206577138345114, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchorMax.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 7912206577138345114, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 7912206577138345114, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchorMin.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 7912206577138345114, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 7912206577138345114, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchoredPosition.x value: 0 objectReference: {fileID: 0} - - target: {fileID: 7912206577138345114, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 7912206577138345114, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchoredPosition.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 8210325049482289980, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 8210325049482289980, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_CurrentName value: objectReference: {fileID: 8470479361425810124} - - target: {fileID: 8403980163329380773, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 8403980163329380773, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchorMax.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 8403980163329380773, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 8403980163329380773, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchorMin.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 8403980163329380773, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 8403980163329380773, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchoredPosition.x value: 0 objectReference: {fileID: 0} - - target: {fileID: 8403980163329380773, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 8403980163329380773, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_AnchoredPosition.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 8728003287376236913, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + - target: {fileID: 8728003287376236913, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} propertyPath: m_Name value: NameDisplay objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} ---- !u!114 &8470479361425810124 stripped +--- !u!224 &3521129445966426109 stripped +RectTransform: + m_CorrespondingSourceObject: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} + m_PrefabInstance: {fileID: 2533628164130561547} + m_PrefabAsset: {fileID: 0} +--- !u!114 &5969994396107504951 stripped MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 6243239769371671751, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + m_CorrespondingSourceObject: {fileID: 8210325049482289980, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} m_PrefabInstance: {fileID: 2533628164130561547} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Script: {fileID: 11500000, guid: 55aeec10c1bda27448c176abb6615c0f, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!224 &3521129445966426109 stripped -RectTransform: - m_CorrespondingSourceObject: {fileID: 1438005041722192374, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} - m_PrefabInstance: {fileID: 2533628164130561547} - m_PrefabAsset: {fileID: 0} ---- !u!114 &5969994396107504951 stripped +--- !u!114 &8470479361425810124 stripped MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 8210325049482289980, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, - type: 3} + m_CorrespondingSourceObject: {fileID: 6243239769371671751, guid: c3f6a30a7d785ef41a47b0cfd0c8b26d, type: 3} m_PrefabInstance: {fileID: 2533628164130561547} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 55aeec10c1bda27448c176abb6615c0f, type: 3} + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} m_Name: m_EditorClassIdentifier: diff --git a/Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs b/Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs index d3da238c6..37cd1adec 100644 --- a/Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs +++ b/Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs @@ -59,6 +59,8 @@ public class PopupPanel : MonoBehaviour private const string k_DefaultConfirmText = "OK"; + static readonly char[] k_InputFieldIncludeChars = new[] { '.' }; + /// /// Setup this panel to be a panel view to have the player enter the game, complete with the ability for the player to /// cancel their input and requests. @@ -122,6 +124,45 @@ private void OnConfirmClick() m_ConfirmFunction.Invoke(m_InputField.text, portNum, m_NameDisplay.GetCurrentName(), (OnlineMode)m_OnlineModeDropdown.value); } + /// + /// Sanitize user port InputField box allowing only alphanumerics, plus any matching chars, if provided. + /// + /// string to sanitize. + /// Array of chars to include. + /// Sanitized text string. + static string Sanitize(string dirtyString, char[] includeChars = null) + { + var result = new StringBuilder(dirtyString.Length); + foreach (char c in dirtyString) + { + if (char.IsLetterOrDigit(c) || + (includeChars != null && Array.Exists(includeChars, excludeChar => excludeChar == c))) + { + result.Append(c); + } + } + + return result.ToString(); + } + + /// + /// Added to the InputField component's OnValueChanged callback for the Room/IP UI text. + /// + public void SanitizeInputText() + { + var inputFieldText = Sanitize(m_InputField.text, k_InputFieldIncludeChars); + m_InputField.text = inputFieldText; + } + + /// + /// Added to the InputField component's OnValueChanged callback for the Port UI text. + /// + public void SanitizePortText() + { + var inputFieldText = Sanitize(m_PortInputField.text); + m_PortInputField.text = inputFieldText; + } + /// /// Called when the user clicks on the cancel button when in a mode where the player is expecting to input something. /// Primary responsibility for this method is to reset the UI state. From fd5a35fac0637bd18f5a66224cb5919020528916 Mon Sep 17 00:00:00 2001 From: Fernando Cortez Date: Wed, 21 Apr 2021 16:52:32 -0400 Subject: [PATCH 2/4] adding underscore to allowed chars to input field --- Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs b/Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs index 37cd1adec..149a93a42 100644 --- a/Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs +++ b/Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs @@ -59,7 +59,7 @@ public class PopupPanel : MonoBehaviour private const string k_DefaultConfirmText = "OK"; - static readonly char[] k_InputFieldIncludeChars = new[] { '.' }; + static readonly char[] k_InputFieldIncludeChars = new[] { '.', '_' }; /// /// Setup this panel to be a panel view to have the player enter the game, complete with the ability for the player to From 8f5bafb86365bcde94b9c999583ec8af6486dfb4 Mon Sep 17 00:00:00 2001 From: Fernando Cortez Date: Fri, 23 Apr 2021 11:34:57 -0400 Subject: [PATCH 3/4] renaming variable --- Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs b/Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs index 149a93a42..13ddba261 100644 --- a/Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs +++ b/Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs @@ -136,7 +136,7 @@ static string Sanitize(string dirtyString, char[] includeChars = null) foreach (char c in dirtyString) { if (char.IsLetterOrDigit(c) || - (includeChars != null && Array.Exists(includeChars, excludeChar => excludeChar == c))) + (includeChars != null && Array.Exists(includeChars, includeChar => includeChar == c))) { result.Append(c); } From f36e2fee9ad7e1991d4e098393e753952f09472c Mon Sep 17 00:00:00 2001 From: Fernando Cortez Date: Fri, 30 Apr 2021 10:12:45 -0400 Subject: [PATCH 4/4] re-adding oninputchange callbacks on prefab --- Assets/BossRoom/Prefabs/UI/PopupPanel.prefab | 32 +++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/Assets/BossRoom/Prefabs/UI/PopupPanel.prefab b/Assets/BossRoom/Prefabs/UI/PopupPanel.prefab index 20dc6316c..9f7ec8952 100644 --- a/Assets/BossRoom/Prefabs/UI/PopupPanel.prefab +++ b/Assets/BossRoom/Prefabs/UI/PopupPanel.prefab @@ -733,7 +733,19 @@ MonoBehaviour: m_Calls: [] m_OnValueChanged: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 2699227445768669173} + m_TargetAssemblyTypeName: BossRoom.Visual.PopupPanel, BossRoom.Client + m_MethodName: SanitizePortText + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 m_CaretColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} m_CustomCaretColor: 0 m_SelectionColor: {r: 0.65882355, g: 0.80784315, b: 1, a: 0.7529412} @@ -968,7 +980,7 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 21.55 + m_fontSize: 18 m_fontSizeBase: 32 m_fontWeight: 400 m_enableAutoSizing: 1 @@ -2069,7 +2081,19 @@ MonoBehaviour: m_Calls: [] m_OnValueChanged: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 2699227445768669173} + m_TargetAssemblyTypeName: BossRoom.Visual.PopupPanel, BossRoom.Client + m_MethodName: SanitizeInputText + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 m_CaretColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} m_CustomCaretColor: 0 m_SelectionColor: {r: 0.65882355, g: 0.80784315, b: 1, a: 0.7529412} @@ -2637,7 +2661,7 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 30.35 + m_fontSize: 35.05 m_fontSizeBase: 32 m_fontWeight: 400 m_enableAutoSizing: 1