Partial rewrite, missing:
Some checks failed
Build Mau & Deploy Mau / build (push) Failing after 1m15s
Build Mau & Deploy Mau / deploy (push) Has been skipped

- Correctly parsing incoming messages
- Sending the gamestate after relevant actions
This commit is contained in:
DTieman
2024-05-04 19:55:11 +02:00
parent 0c2cb8272d
commit 694bc6147a
20 changed files with 612 additions and 294 deletions

View File

@@ -1,17 +1,30 @@
using System.Net.WebSockets;
using System.Text;
namespace MauMau_Server.Websockets;
public class ConnectionInstance
{
public string Name { get; set; }
public string ConnectionId { get; set; }
public string Id { get; set; }
public WebSocket Socket { get; set; }
public ConnectionInstance(string name, string connectionId, WebSocket socket)
public ConnectionInstance(string name, string id, WebSocket socket)
{
Name = name;
ConnectionId = connectionId;
Id = id;
Socket = socket;
}
/**
* <summary>
* Sends a message to the client. This method is asynchronous and formats the message to be ready to be sent.
* </summary>
*/
public void SendMessageAsync(string message)
{
var bytes = Encoding.Default.GetBytes(message);
var arraySegment = new ArraySegment<byte>(bytes);
Socket.SendAsync(arraySegment, WebSocketMessageType.Text, true, CancellationToken.None);
}
}