enable the usage of shortened relay messages
This commit is contained in:
parent
0a531801c4
commit
253f60f3d5
1 changed files with 100 additions and 5 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SecondBotEvents.Config
|
namespace SecondBotEvents.Config
|
||||||
|
|
@ -13,6 +14,7 @@ namespace SecondBotEvents.Config
|
||||||
filename = "relay";
|
filename = "relay";
|
||||||
settings.Add("count");
|
settings.Add("count");
|
||||||
settings.Add("HideStatusOutput");
|
settings.Add("HideStatusOutput");
|
||||||
|
settings.Add("UseShortEncoder");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetRelayCount()
|
public int GetRelayCount()
|
||||||
|
|
@ -20,31 +22,124 @@ namespace SecondBotEvents.Config
|
||||||
return ReadSettingAsInt("count", 0);
|
return ReadSettingAsInt("count", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool GetUseShortEncoder()
|
||||||
|
{
|
||||||
|
return ReadSettingAsBool("UseShortEncoder", false);
|
||||||
|
}
|
||||||
|
|
||||||
public bool GetRelayEnabled(int relayID)
|
public bool GetRelayEnabled(int relayID)
|
||||||
|
{
|
||||||
|
if (GetUseShortEncoder() == false)
|
||||||
{
|
{
|
||||||
return ReadSettingAsBool(relayID.ToString() + "_enabled", false);
|
return ReadSettingAsBool(relayID.ToString() + "_enabled", false);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public string RelaySourceType(int relayID)
|
public string RelaySourceType(int relayID)
|
||||||
|
{
|
||||||
|
if (GetUseShortEncoder() == false)
|
||||||
{
|
{
|
||||||
return ReadSettingAsString(relayID.ToString() + "_source_type", "none");
|
return ReadSettingAsString(relayID.ToString() + "_source_type", "none");
|
||||||
}
|
}
|
||||||
|
Dictionary<string,string> settings = GetShortEncodedOptions(relayID);
|
||||||
|
if (settings.ContainsKey("sType") == false)
|
||||||
|
{
|
||||||
|
return "none";
|
||||||
|
}
|
||||||
|
return settings["sType"];
|
||||||
|
}
|
||||||
|
|
||||||
public string RelaySourceOption(int relayID)
|
public string RelaySourceOption(int relayID)
|
||||||
|
{
|
||||||
|
if (GetUseShortEncoder() == false)
|
||||||
{
|
{
|
||||||
return ReadSettingAsString(relayID.ToString() + "_source_option", "");
|
return ReadSettingAsString(relayID.ToString() + "_source_option", "");
|
||||||
}
|
}
|
||||||
|
Dictionary<string, string> settings = GetShortEncodedOptions(relayID);
|
||||||
|
if (settings.ContainsKey("sFilter") == false)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return settings["sFilter"];
|
||||||
|
}
|
||||||
|
|
||||||
public string RelayTargetType(int relayID)
|
public string RelayTargetType(int relayID)
|
||||||
|
{
|
||||||
|
if (GetUseShortEncoder() == false)
|
||||||
{
|
{
|
||||||
return ReadSettingAsString(relayID.ToString() + "_target_type", "none");
|
return ReadSettingAsString(relayID.ToString() + "_target_type", "none");
|
||||||
}
|
}
|
||||||
|
Dictionary<string, string> settings = GetShortEncodedOptions(relayID);
|
||||||
|
if (settings.ContainsKey("tType") == false)
|
||||||
|
{
|
||||||
|
return "none";
|
||||||
|
}
|
||||||
|
return settings["tType"];
|
||||||
|
}
|
||||||
|
|
||||||
public string RelayTargetOption(int relayID)
|
public string RelayTargetOption(int relayID)
|
||||||
|
{
|
||||||
|
if (GetUseShortEncoder() == false)
|
||||||
{
|
{
|
||||||
return ReadSettingAsString(relayID.ToString() + "_target_option", "");
|
return ReadSettingAsString(relayID.ToString() + "_target_option", "");
|
||||||
}
|
}
|
||||||
|
Dictionary<string, string> settings = GetShortEncodedOptions(relayID);
|
||||||
|
if (settings.ContainsKey("tConfig") == false)
|
||||||
|
{
|
||||||
|
return "none";
|
||||||
|
}
|
||||||
|
return settings["tConfig"];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Dictionary<string,string> GetShortEncodedOptions(int relayID)
|
||||||
|
{
|
||||||
|
if(UnpackedConfigs.ContainsKey(relayID) == true)
|
||||||
|
{
|
||||||
|
return UnpackedConfigs[relayID];
|
||||||
|
}
|
||||||
|
// config not unpacked from string lets unpack it
|
||||||
|
string config = ReadSettingAsString(relayID.ToString() + "_RelayConfig", "");
|
||||||
|
UnpackedConfigs.Add(relayID, new Dictionary<string, string>());
|
||||||
|
if (config == "")
|
||||||
|
{
|
||||||
|
return UnpackedConfigs[relayID];
|
||||||
|
}
|
||||||
|
string[] bits = config.Split("{}", StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
Dictionary<string,string> data = new Dictionary<string,string>();
|
||||||
|
foreach(string A in bits)
|
||||||
|
{
|
||||||
|
string[] B = A.Split("::", StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (B.Count() == 2)
|
||||||
|
{
|
||||||
|
if (data.ContainsKey(B[0]) == false)
|
||||||
|
{
|
||||||
|
data.Add(B[0], B[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(data.Count() != 4)
|
||||||
|
{
|
||||||
|
return UnpackedConfigs[relayID];
|
||||||
|
}
|
||||||
|
List<string> checks = new List<string>() { "sType", "sFilter", "tType", "tConfig" };
|
||||||
|
bool allfound = true;
|
||||||
|
foreach (string A in checks)
|
||||||
|
{
|
||||||
|
if (data.ContainsKey(A) == false)
|
||||||
|
{
|
||||||
|
allfound = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(allfound == true)
|
||||||
|
{
|
||||||
|
UnpackedConfigs[relayID] = data;
|
||||||
|
}
|
||||||
|
return UnpackedConfigs[relayID];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Dictionary<int, Dictionary<string, string>> UnpackedConfigs = new Dictionary<int, Dictionary<string, string>>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue