using System.Collections.Concurrent; namespace codelanguage; public class ClientService { private readonly ConcurrentDictionary _clients = new(); public ClientState? GetClient(string id) => _clients.TryGetValue(id, out var c) ? c : null; public ClientState Register(string id) { var client = new ClientState { Id = id }; _clients[id] = client; return client; } public void Unregister(string id) => _clients.TryRemove(id, out _); public void SetVar(string clientId, string varName, CraftValue value) { var client = GetClient(clientId); if (client != null) client.Vars[varName] = value; } public CraftValue? GetVar(string clientId, string varName) { var client = GetClient(clientId); if (client != null && client.Vars.TryGetValue(varName, out var v)) return v; return null; } public void Broadcast(string message) { foreach (var client in _clients.Values) { client.OutputQueue.Enqueue(message); } } } public class ClientState { public string Id { get; set; } = ""; public ConcurrentQueue OutputQueue { get; } = new(); public Dictionary Vars { get; set; } = new(); public string? CurrentBrowser { get; set; } public string? Eye { get; set; } public int? ViewSize { get; set; } = 7; public string? Perspective { get; set; } = "mob"; public Dictionary Screen { get; set; } = new(); }