diff --git a/CollabVMSharp/CollabVMClient.cs b/CollabVMSharp/CollabVMClient.cs index 5ea5afa..b54128f 100644 --- a/CollabVMSharp/CollabVMClient.cs +++ b/CollabVMSharp/CollabVMClient.cs @@ -85,6 +85,11 @@ public class CollabVMClient { /// Fired when the VM requires account authentication. The provided string is the authentication server base URL. /// public event EventHandler VMUsesAccountAuth; + + /// + /// Fired when the client encounters a non-fatal error + /// + public event EventHandler Error; /// /// Client for the CollabVM 1.x Server /// @@ -159,6 +164,7 @@ public class CollabVMClient { TurnUpdate += delegate { }; ConnectionClosed += delegate { }; VMUsesAccountAuth += delegate { }; + Error += delegate { }; } /// /// Connect to the CollabVM Server @@ -278,11 +284,22 @@ public class CollabVMClient { } case "list": { List nodes = new(); - for (var i = 1; i < msgArr.Length; i += 3) { + for (var i = 1; i < msgArr.Length; i += 3) + { + byte[] thumbnail; + try + { + thumbnail = Convert.FromBase64String(msgArr[i + 2]); + } + catch (FormatException ex) + { + Error.Invoke(this, "Server sent an invalid thumbnail."); + return; + } nodes.Add(new Node { ID = msgArr[i], Name = msgArr[i+1], - Thumbnail = Convert.FromBase64String(msgArr[i+2]) + Thumbnail = thumbnail }); this.GotNodeList.TrySetResult(nodes.ToArray()); } @@ -299,7 +316,16 @@ public class CollabVMClient { } case "png": { if (msgArr[2] != "0") return; - Image rect = Image.Load(Convert.FromBase64String(msgArr[5])); + Image rect; + try + { + rect = Image.Load(Convert.FromBase64String(msgArr[5])); + } + catch (FormatException ex) + { + Error.Invoke(this, "Server sent an invalid screen rect"); + return; + } framebuffer.Mutate(f => f.DrawImage(rect, new Point(int.Parse(msgArr[3]), int.Parse(msgArr[4])), 1)); this.Rect.Invoke(this, new RectEventArgs { X = int.Parse(msgArr[3]),