Compare commits
11 commits
ba57733afd
...
fd41af4480
Author | SHA1 | Date | |
---|---|---|---|
fd41af4480 | |||
d2d5348958 | |||
7bb906a835 | |||
37e5f825fd | |||
283a04da63 | |||
0907d7b395 | |||
fd09840a1c | |||
4de72b38c1 | |||
8de1d73dc8 | |||
d3af774180 | |||
fd9eac27f9 |
4 changed files with 35 additions and 14 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ obj/
|
|||
riderModule.iml
|
||||
/_ReSharper.Caches/
|
||||
.idea/
|
||||
.vs/
|
|
@ -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("(?<=\")[^\"]*(?=\")|[^\" ]+");
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue