Partial rewrite, missing:
- Correctly parsing incoming messages - Sending the gamestate after relevant actions
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user