private async Task HandleMessage(InfoControllerEvent info, ClientManager <MyPlayer> manager) { if (info.Event is NotificatorControllerEvent) { manager.GetClient(info.Sender).Entity = EntityType.Watcher; await manager.GetClient(info.Sender).SendAsync(new InitialMessage()); ConfigurationMessage message = new ConfigurationMessage(); message.AddBinding(1, typeof(NotificatorControllerEvent)); await manager.GetClient(info.Sender).SendAsync(message); return; } if (info.Event is TextBoxControllerEvent textBox) { manager.GetClient(info.Sender).Name = textBox.Text; manager.GetClient(info.Sender).Entity = EntityType.Player; return; } if (info.Event is ButtonControllerEvent button) { var send = MakeMessage(info, manager); foreach (var client in manager.Players) { if (client.Value.Entity == EntityType.Watcher) { await manager.SendAsync(client.Key, send); } } } }
protected override async Task OnInitializedAsync() { try { await _user.ConnectAsync(new Uri(@"ws://localhost:5001/ws")); } catch (Exception) { return; } await _user.SendAsync(new InitialMessage()); ConfigurationMessage msg = new ConfigurationMessage(); msg.AddBinding(1, typeof(NotificatorControllerEvent)); await _user.SendAsync(msg); await _user.SendAsync(new NotificatorControllerEvent("notifcator", "non", 1)); while (_user.IsConnected) { HandleMessage(await _user.ReceiveAsync()); } }
private async Task OnNameChose(TextBoxControllerEvent @event) { isNameChose = true; StateHasChanged(); while (!_user.IsConnected) { await Task.Delay(1000); } await _user.SendAsync(@event); ConfigurationMessage msg = new ConfigurationMessage(); msg.AddBinding(1, typeof(ButtonControllerEvent)); msg.AddBinding(2, typeof(ButtonControllerEvent)); msg.AddBinding(3, typeof(ButtonControllerEvent)); await _user.SendAsync(msg); }
protected override async Task OnInitializedAsync() { try { await _user.ConnectAsync(new Uri(@"ws://localhost:5001/ws")); } catch (Exception) { return; } await _user.SendAsync(new InitialMessage()); ConfigurationMessage msg = new ConfigurationMessage(); msg.AddBinding(1, typeof(TextBoxControllerEvent)); await _user.SendAsync(msg); }