public async Task ArmaUpdateMarkersPosition(ArmaMessage message) { var state = GetState(ConnectionKind.Arma); if (state == null) { _logger.LogWarning($"No state for ArmaUpdateMarkersPosition"); return; } var msg = new UpdateMarkersMessagePosition() { Timestamp = message.Timestamp, Makers = new List <MarkerPosition>() }; foreach (var entry in message.Args) { var data = ArmaSerializer.ParseMixedArray(entry); var id = (string)data[0]; var pos = ((object[])data[1]).Cast <double?>().ToArray(); var dir = (double)data[2]; msg.Makers.Add(new MarkerPosition() { Id = id, X = pos[0] ?? 0, Y = pos[1] ?? 0, Heading = dir }); } var lastUpdate = state.LastUpdateMarkers; if (lastUpdate != null) { foreach (var marker in lastUpdate.Makers) { var updated = msg.Makers.FirstOrDefault(m => m.Id == marker.Id); if (updated != null) { marker.X = updated.X; marker.Y = updated.Y; marker.Heading = updated.Heading; } } } try { await Clients.Group(state.WebChannelName).SendAsync("UpdateMarkersPosition", msg); } catch (Exception e) { _logger.LogWarning(e, "UpdateMarkersPosition failed"); } }
public async Task ArmaUpdateMarkers(ArmaMessage message) { //Console.WriteLine("ArmaUpdateMarkers " + string.Join(", ", message.Args)); var state = GetState(ConnectionKind.Arma); if (state == null) { _logger.LogWarning($"No state for ArmaUpdateMarkers"); return; } var msg = new UpdateMarkersMessage() { Timestamp = message.Timestamp, Makers = new List <Marker>() }; foreach (var entry in message.Args) { var data = ArmaSerializer.ParseMixedArray(entry); var kind = (string)data[0]; var id = (string)data[1]; var iconA = (string)data[2]; var iconB = (string)data[3]; var text = (string)data[4]; var textDetail = (string)data[5]; var pos = ((object[])data[6]).Cast <double?>().ToArray(); var dir = (double)data[7]; var vehicle = data.Length > 8 ? (string)data[8] : null; msg.Makers.Add(new Marker() { Kind = kind, Id = id, X = pos[0] ?? 0, Y = pos[1] ?? 0, Heading = dir, Symbol = GetMilSymbol(iconA, iconB), Name = text, Vehicle = vehicle }); } msg.Makers.Sort((a, b) => a.Name.CompareTo(b.Name)); state.LastUpdateMarkers = msg; try { await Clients.Group(state.WebChannelName).SendAsync("UpdateMarkers", state.LastUpdateMarkers); } catch (Exception e) { _logger.LogWarning(e, "UpdateMarkers failed"); } }
public void ArmaEndMission(ArmaMessage message) { var state = GetState(ConnectionKind.Arma); if (state == null) { _logger.LogWarning($"No state for ArmaEndMission"); return; } Console.WriteLine("ArmaEndMission " + string.Join(", ", message.Args)); state.LastSetPosition = null; state.LastMission = null; }
public async Task ArmaUpdateMessages(ArmaMessage message) { //Console.WriteLine("ArmaUpdateMarkers " + string.Join(", ", message.Args)); var state = GetState(ConnectionKind.Arma); if (state == null) { _logger.LogWarning($"No state for ArmaUpdateMarkers"); return; } var msg = new UpdateMessagesMessage() { Timestamp = message.Timestamp, Messages = new List <Message>() }; foreach (var entry in message.Args) { var data = ArmaSerializer.ParseMixedArray(entry); var title = (string)data[0]; var body = (string)data[1]; var msgState = (int)((double?)data[2]); var id = (string)data[3]; msg.Messages.Add(new Message() { Id = id, Title = title, State = msgState, Body = body }); } state.LastUpdateMessages = msg; try { await Clients.Group(state.WebChannelName).SendAsync("UpdateMessages", state.LastUpdateMessages); } catch (Exception e) { _logger.LogWarning(e, "UpdateMessages failed"); } }
public async Task ArmaDevices(ArmaMessage message) { var state = GetState(ConnectionKind.Arma); if (state == null) { _logger.LogWarning($"No state for ArmaDevices"); return; } Console.WriteLine("ArmaDevices " + string.Join(", ", message.Args)); var deviceLevel = int.Parse(message.Args[0], CultureInfo.InvariantCulture); var useMils = bool.Parse(message.Args[1]); state.LastDevices = new DevicesMessage() { Level = deviceLevel, UseMils = useMils }; await Clients.Group(state.WebChannelName).SendAsync("Devices", state.LastDevices); }
public async Task ArmaUpdatePosition(ArmaMessage message) { if (message.Timestamp < DateTime.UtcNow.AddMinutes(-1)) { _logger.LogTrace("Too old, skip"); return; // Too old ! } var state = GetState(ConnectionKind.Arma); if (state == null) { _logger.LogWarning($"No state for ArmaUpdatePosition"); return; } var x = ArmaSerializer.ParseDouble(message.Args[0]) ?? 0d; var y = ArmaSerializer.ParseDouble(message.Args[1]) ?? 0d; var z = ArmaSerializer.ParseDouble(message.Args[2]) ?? 0d; var dir = ArmaSerializer.ParseDouble(message.Args[3]) ?? 0d; var date = ArmaSerializer.ParseIntegerArray(message.Args[4]); var grp = ArmaSerializer.ParseString(message.Args[5]); var vehicle = message.Args.Length > 6 ? ArmaSerializer.ParseString(message.Args[6]) : null; state.LastSetPosition = new SetPositionMessage() { X = x, Y = y, Altitude = z, Heading = dir, Date = ToDateTime(date), Timestamp = message.Timestamp, Group = grp, Vehicle = vehicle }; await Clients.Group(state.WebChannelName).SendAsync("SetPosition", state.LastSetPosition); }
public async Task ArmaStartMission(ArmaMessage message) { var state = GetState(ConnectionKind.Arma); if (state == null) { Console.WriteLine($"No state for ArmaStartMission"); return; } var worldName = ArmaSerializer.ParseString(message.Args[0]); var size = ArmaSerializer.ParseDouble(message.Args[1]) ?? 0d; var date = ArmaSerializer.ParseIntegerArray(message.Args[2]); state.LastMission = new MissionMessage() { WorldName = worldName, Size = size, Date = ToDateTime(date), Timestamp = message.Timestamp }; await Clients.Group(state.WebChannelName).SendAsync("Mission", state.LastMission); }
public async Task ArmaUpdateMapMarkers(ArmaMessage message) { var state = GetState(ConnectionKind.Arma); if (state == null) { _logger.LogWarning($"No state for ArmaUpdateMapMarkers"); return; } var msg = new UpdateMapMarkersMessage() { Simples = new List <SimpleMapMarker>(), Icons = new List <IconMapMarker>(), Polylines = new List <PolylineMapMarker>() }; var simple = ArmaSerializer.ParseMixedArray(message.Args[0]); foreach (object[] simpleMarker in simple) { var shape = (string)simpleMarker[3]; if (string.Equals(shape, "ICON", StringComparison.OrdinalIgnoreCase)) { Arma3MarkerType type; if (Enum.TryParse((string)simpleMarker[2], true, out type)) { msg.Icons.Add(new IconMapMarker() { Name = ShorterName((string)simpleMarker[0]), Pos = ((object[])simpleMarker[1]).Cast <double>().Take(2).Select(p => Math.Round(p, 1)).ToArray(), Icon = ToIcon(type, (string)simpleMarker[7]), Size = ((object[])simpleMarker[4]).Cast <double>().ToArray(), Dir = (double)simpleMarker[5], Label = (string)simpleMarker[8], Alpha = (double)simpleMarker[9] }); } } else { msg.Simples.Add(new SimpleMapMarker() { Name = ShorterName((string)simpleMarker[0]), Pos = ((object[])simpleMarker[1]).Cast <double>().Take(2).Select(p => Math.Round(p, 1)).ToArray(), Shape = shape.ToLowerInvariant(), Size = ((object[])simpleMarker[4]).Cast <double>().ToArray(), Dir = (double)simpleMarker[5], Brush = (string)simpleMarker[6], Color = ToHtmlColor((string)simpleMarker[7]), Alpha = (double)simpleMarker[9] }); } } var poly = ArmaSerializer.ParseMixedArray(message.Args[1]); foreach (object[] polyMarker in poly) { msg.Polylines.Add(new PolylineMapMarker() { Name = ShorterName((string)polyMarker[0]), Points = ((object[])polyMarker[1]).Cast <double>().Select(p => Math.Round(p, 1)).ToArray(), Brush = (string)polyMarker[2], Color = ToHtmlColor((string)polyMarker[3]), Alpha = (double)polyMarker[4] }); } state.LastUpdateMapMarkers = msg; try { await Clients.Group(state.WebChannelName).SendAsync("UpdateMapMarkers", state.LastUpdateMapMarkers); } catch (Exception e) { _logger.LogWarning(e, "UpdateMapMarkers failed"); } }