Compare commits

...

11 commits

Author SHA1 Message Date
fd41af4480 bump v
Some checks reported warnings
.NET / build (push) Has been cancelled
2023-08-29 23:44:13 -04:00
d2d5348958 add Rename() 2023-08-29 23:44:02 -04:00
7bb906a835 bump 2023-08-29 23:34:45 -04:00
37e5f825fd add username property 2023-08-29 23:34:30 -04:00
283a04da63 bump 2023-08-28 20:50:22 -04:00
0907d7b395 just throw the damn exception instead of weird event shit (why did I do that) 2023-08-28 20:50:05 -04:00
fd09840a1c bump version 2023-08-28 16:41:10 -04:00
4de72b38c1 retarget to net6.0 to support ImageSharp 3.x 2023-08-28 16:40:55 -04:00
8de1d73dc8 bump version 2023-08-28 16:10:37 -04:00
d3af774180 Add screen size event 2023-08-28 16:10:15 -04:00
fd9eac27f9 update .gitignore 2023-08-28 16:06:32 -04:00
4 changed files with 35 additions and 14 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ obj/
riderModule.iml
/_ReSharper.Caches/
.idea/
.vs/

View file

@ -1,5 +1,8 @@
#nullable enable
#pragma warning disable CS4014
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using System;
using System.Collections.Generic;
using System.IO;
@ -11,9 +14,6 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using Timer = System.Timers.Timer;
// ReSharper disable FieldCanBeMadeReadOnly.Local
// ReSharper disable ArrangeObjectCreationWhenTypeNotEvident
@ -49,7 +49,7 @@ public class CollabVMClient {
private SemaphoreSlim QEMUMonitorSemaphore;
private TaskCompletionSource<string> QEMUMonitorResult;
// Properties
public Rank Rank { get { return this._rank; } }
public Rank Rank { get { return _rank; } }
public Permissions Permissions { get { return this._perms; } }
public bool Connected { get { return this._connected; } }
public bool ConnectedToVM { get { return this._connectedToVM; } }
@ -58,13 +58,15 @@ public class CollabVMClient {
public VoteUpdateEventArgs CurrentVote { get { return this._currentvote; } }
public TurnUpdateEventArgs CurrentTurn { get { return this._currentturn; } }
public string Node { get { return this.node; } }
public string Username { get { return this.username; } }
// Events
public event EventHandler<ChatMessage> Chat;
public event EventHandler<ChatMessage[]> ChatHistory;
public event EventHandler ConnectedToNode;
public event EventHandler NodeConnectFailed;
public event EventHandler<string> ConnectionFailed;
public event EventHandler<RectEventArgs> Rect;
public event EventHandler<ScreenSizeEventArgs> ScreenSize;
public event EventHandler<string> Renamed;
public event EventHandler<UserRenamedEventArgs> UserRenamed;
public event EventHandler<User> UserJoined;
@ -130,8 +132,8 @@ public class CollabVMClient {
ChatHistory += delegate { };
ConnectedToNode += delegate { };
NodeConnectFailed += delegate { };
ConnectionFailed += delegate { };
Rect += delegate { };
ScreenSize += delegate { };
Renamed += delegate { };
UserRenamed += delegate { };
UserJoined += delegate { };
@ -145,14 +147,13 @@ public class CollabVMClient {
/// <summary>
/// Connect to the CollabVM Server
/// </summary>
public async Task<bool> Connect() {
public async Task Connect() {
try {
await this.socket.ConnectAsync(this.url, CancellationToken.None);
}
catch (WebSocketException e) {
this.ConnectionFailed.Invoke(this, e.Message);
this.Cleanup(false);
return false;
throw e;
}
this._connected = true;
if (this.username != null)
@ -163,7 +164,7 @@ public class CollabVMClient {
this.SendMsg(Guacutils.Encode("connect", this.node));
this.NOPRecieve.Start();
this.WebSocketLoop();
return true;
return;
}
private async void WebSocketLoop() {
@ -262,7 +263,10 @@ public class CollabVMClient {
}
case "size": {
if (msgArr[1] != "0") return;
this.framebuffer = new Image<Rgba32>(int.Parse(msgArr[2]), int.Parse(msgArr[3]));
var width = int.Parse(msgArr[2]);
var height = int.Parse(msgArr[3]);
this.framebuffer = new Image<Rgba32>(width, height);
this.ScreenSize.Invoke(this, new ScreenSizeEventArgs { Width = width, Height = height });
break;
}
case "png": {
@ -817,6 +821,16 @@ public class CollabVMClient {
this.commands.Add(cmd, callback);
}
/// <summary>
/// Change client username
/// </summary>
/// <param name="newname">New username. Null for the server to assign a guest name</param>
public void Rename(string? newname = null)
{
if (newname == null) SendMsg(Guacutils.Encode("rename"));
else SendMsg(Guacutils.Encode("rename", newname));
}
private void ProcessCommand(string username, string cmd) {
// I stole this from stackoverflow
var re = new Regex("(?<=\")[^\"]*(?=\")|[^\" ]+");

View file

@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<Version>2.0.1</Version>
<Version>2.4.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.1" />
</ItemGroup>
</Project>

View file

@ -48,6 +48,12 @@ public class RectEventArgs {
public Image Data { get; set; }
}
public class ScreenSizeEventArgs
{
public int Width { get; set; }
public int Height { get; set; }
}
// this might not be the best place for this IDK
public enum VoteStatus {
Started,