private NotificatorControllerEvent MakeMessage(InfoControllerEvent info, ClientManager <MyPlayer> manager) { if (info.Event is ButtonControllerEvent button) { if (button.SenderID == 1) { return(new NotificatorControllerEvent(manager.GetClient(info.Sender).Name, "Left", 1)); } if (button.SenderID == 2) { return(new NotificatorControllerEvent(manager.GetClient(info.Sender).Name, "Up", 1)); } if (button.SenderID == 3) { return(new NotificatorControllerEvent(manager.GetClient(info.Sender).Name, "Right", 1)); } return(null); } else { return(null); } }
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); } } } }