// SPDX-License-Identifier: AGPL-3.0-only
/**
* Digital Voice Modem - DVMConsole
* AGPLv3 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* @package DVM / DVM Console
* @license AGPLv3 License (https://opensource.org/licenses/AGPL-3.0)
*
* Copyright (C) 2024-2025 Caleb, K4PHP
*
*/
using System.Security.Policy;
namespace DVMConsole
{
///
/// Codeplug object used project wide
///
public class Codeplug
{
public List Systems { get; set; }
public List Zones { get; set; }
///
///
///
public class System
{
public string Name { get; set; }
public string Address { get; set; }
public uint PeerId { get; set; }
public int Port { get; set; }
public string Rid { get; set; }
public string AuthKey { get; set; }
public string AliasPath { get; set; } = "./alias.yml";
public List RidAlias { get; set; } = null;
public override string ToString()
{
return Name;
}
}
///
///
///
public class Zone
{
public string Name { get; set; }
public List Channels { get; set; }
}
///
///
///
public class Channel
{
public string Name { get; set; }
public string System { get; set; }
public string Tgid { get; set; }
public string EncryptionKey { get; set; }
public string AlgoId { get; set; } = "0x80";
public string KeyId { get; set; }
public ushort GetKeyId()
{
return Convert.ToUInt16(KeyId, 16);
}
public byte GetAlgoId()
{
return Convert.ToByte(AlgoId, 16);
}
public byte[] GetEncryptionKey()
{
if (EncryptionKey == null)
return [];
return EncryptionKey
.Split(',')
.Select(s => Convert.ToByte(s.Trim(), 16))
.ToArray();
}
}
///
/// Helper to return a system by looking up a
///
///
///
public System GetSystemForChannel(Channel channel)
{
return Systems.FirstOrDefault(s => s.Name == channel.System);
}
///
/// Helper to return a system by looking up a channel name
///
///
///
public System GetSystemForChannel(string channelName)
{
foreach (var zone in Zones)
{
var channel = zone.Channels.FirstOrDefault(c => c.Name == channelName);
if (channel != null)
{
return Systems.FirstOrDefault(s => s.Name == channel.System);
}
}
return null;
}
///
/// Helper to return a by channel name
///
///
///
public Channel GetChannelByName(string channelName)
{
foreach (var zone in Zones)
{
var channel = zone.Channels.FirstOrDefault(c => c.Name == channelName);
if (channel != null)
{
return channel;
}
}
return null;
}
}
}