VeQox
VeQox
Explore posts from servers
CC#
Created by VeQox on 11/19/2023 in #help
✅ using from another csproj
k this worked pog ❤️
10 replies
CC#
Created by VeQox on 11/19/2023 in #help
✅ using from another csproj
and if i dont use vsstudio when
10 replies
CC#
Created by VeQox on 11/19/2023 in #help
✅ using from another csproj
And how would i do that, been searching online but cant find anything on that topic (mightve searched for the wrong things)
10 replies
CC#
Created by VeQox on 11/15/2023 in #help
✅ asp.net background service with database
it (the service) works now thx for the help and recommendations ❤️
13 replies
CC#
Created by VeQox on 11/15/2023 in #help
✅ asp.net background service with database
it says the singleton IHostedService cannot consume scoped service dbcontext
13 replies
CC#
Created by VeQox on 11/15/2023 in #help
✅ asp.net background service with database
sry, with it i mean the dbcontext
13 replies
CC#
Created by VeQox on 8/2/2023 in #help
❔ Raw Websockets, ref alternative in async programming
yeah that should work gonna experiment a lil bit on which solution fits here the best
12 replies
CC#
Created by VeQox on 8/2/2023 in #help
❔ Raw Websockets, ref alternative in async programming
you mean storing a dictionary with <Guid, Room> where i can get the room on every message?
12 replies
CC#
Created by VeQox on 8/2/2023 in #help
❔ Raw Websockets, ref alternative in async programming
Is there an elegant solution for this?
12 replies
CC#
Created by VeQox on 8/2/2023 in #help
❔ Raw Websockets, ref alternative in async programming
What im trying to achieve with these functions is that when a connection receives an a CreateRoomEvent the scoped room in HandleUpgrade should get set. But since ref params dont work with async code this currently doesnt work and the room in HandleUpgrade stays null
12 replies
CC#
Created by VeQox on 8/2/2023 in #help
❔ Raw Websockets, ref alternative in async programming
private void OnJoin(string raw, WebSocketConnection connection, ref Room? room, ref Client? client)
{
var (joinRoomMessage, _) = JsonUtils.Deserialize<JoinRoomMessage>(raw);
if (joinRoomMessage is null) return;

var (name, roomId) = joinRoomMessage;
if(name is null || roomId is null) return;

room = RoomRepository.GetRoom(roomId);
if(room is null) return; // Send error message (no room found)

client = new Client(connection, name);
room.Join(client);
}
private void OnJoin(string raw, WebSocketConnection connection, ref Room? room, ref Client? client)
{
var (joinRoomMessage, _) = JsonUtils.Deserialize<JoinRoomMessage>(raw);
if (joinRoomMessage is null) return;

var (name, roomId) = joinRoomMessage;
if(name is null || roomId is null) return;

room = RoomRepository.GetRoom(roomId);
if(room is null) return; // Send error message (no room found)

client = new Client(connection, name);
room.Join(client);
}
12 replies
CC#
Created by VeQox on 8/2/2023 in #help
❔ Raw Websockets, ref alternative in async programming
private async Task OnMessage(WebSocketClientMessage webSocketClientMessage, string raw, WebSocketConnection connection, Room? room, Client? client)
{
switch (webSocketClientMessage.Event)
{
case WebSocketClientEvent.CreateRoom:
OnCreateRoom(raw, connection, ref room, ref client);
break;

case WebSocketClientEvent.JoinRoom:
OnJoin(raw, connection, ref room, ref client);
break;

case WebSocketClientEvent.StartGame:
case WebSocketClientEvent.DealerAcceptCards:
case WebSocketClientEvent.DealerRejectCards:
case WebSocketClientEvent.PlayerSwapCard:
case WebSocketClientEvent.PlayerSkipTurn:
case WebSocketClientEvent.PlayerLockTurn:
default:
if(room is null) return;
if(client is null) return;

await room.OnMessage(client, webSocketClientMessage, raw);
break;
}
}

private void OnCreateRoom(string raw, WebSocketConnection connection, ref Room? room, ref Client? client)
{
var (createRoomMessage, _) = JsonUtils.Deserialize<CreateRoomMessage>(raw);
if (createRoomMessage is null) return;

var (roomName, capacity, isPublic, name) = createRoomMessage;
if(roomName is null || capacity is null || isPublic is null || name is null) return;

room = RoomRepository.CreateRoom(
roomName,
capacity.Value,
isPublic.Value,
Logger);

client = new Client(connection, name);
client.SendAsync(new CreateRoomResponse(room.Id));
room.Join(client);
}
private async Task OnMessage(WebSocketClientMessage webSocketClientMessage, string raw, WebSocketConnection connection, Room? room, Client? client)
{
switch (webSocketClientMessage.Event)
{
case WebSocketClientEvent.CreateRoom:
OnCreateRoom(raw, connection, ref room, ref client);
break;

case WebSocketClientEvent.JoinRoom:
OnJoin(raw, connection, ref room, ref client);
break;

case WebSocketClientEvent.StartGame:
case WebSocketClientEvent.DealerAcceptCards:
case WebSocketClientEvent.DealerRejectCards:
case WebSocketClientEvent.PlayerSwapCard:
case WebSocketClientEvent.PlayerSkipTurn:
case WebSocketClientEvent.PlayerLockTurn:
default:
if(room is null) return;
if(client is null) return;

await room.OnMessage(client, webSocketClientMessage, raw);
break;
}
}

private void OnCreateRoom(string raw, WebSocketConnection connection, ref Room? room, ref Client? client)
{
var (createRoomMessage, _) = JsonUtils.Deserialize<CreateRoomMessage>(raw);
if (createRoomMessage is null) return;

var (roomName, capacity, isPublic, name) = createRoomMessage;
if(roomName is null || capacity is null || isPublic is null || name is null) return;

room = RoomRepository.CreateRoom(
roomName,
capacity.Value,
isPublic.Value,
Logger);

client = new Client(connection, name);
client.SendAsync(new CreateRoomResponse(room.Id));
room.Join(client);
}
12 replies
CC#
Created by VeQox on 7/23/2023 in #help
❔ ✅ asp.net websockets
well mostly because bc id like to implement things myself (aka shooting myself in the foot), and bc a friend of mine wants to make an alternative server implementation, which would mean my client is incompatable bc its using the typescript sdk to connect to the hub
9 replies
CC#
Created by VeQox on 7/23/2023 in #help
❔ ✅ asp.net websockets
k, i think im just gonna do lists and check the websocket id on every message to know where it should go bc i have 0 knowledge on messaging systems. Gonna keep it in the back of my mind tho.
9 replies
CC#
Created by VeQox on 7/23/2023 in #help
❔ ✅ asp.net websockets
This meaning multiple websocket instances arent a thing in c#?
9 replies
CC#
Created by VeQox on 12/21/2022 in #help
✅ hi im experimenting with websocketsservers and clients.
dont know why this fixes it 🤷‍♂️
7 replies
CC#
Created by VeQox on 12/21/2022 in #help
✅ hi im experimenting with websocketsservers and clients.
WebSocket.ConnectAsync(uri, cancellationTokenSource.Token).Wait(cancellationTokenSource.Token);
7 replies
CC#
Created by VeQox on 12/21/2022 in #help
✅ hi im experimenting with websocketsservers and clients.
fixed it by using this
7 replies
CC#
Created by VeQox on 12/21/2022 in #help
✅ hi im experimenting with websocketsservers and clients.
where uri is new Uri("ws://localhost:8080")
7 replies
CC#
Created by VeQox on 12/21/2022 in #help
✅ hi im experimenting with websocketsservers and clients.
private async Task<bool> Connect(Uri uri)
{
try
{
await WebSocket.ConnectAsync(uri, CancellationToken.None);
}
catch (Exception)
{
return false;
}
return true;
}
private async Task<bool> Connect(Uri uri)
{
try
{
await WebSocket.ConnectAsync(uri, CancellationToken.None);
}
catch (Exception)
{
return false;
}
return true;
}
7 replies