Skip to content

Commit

Permalink
Merge branch 'hotfix-0.9.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
norrisng committed Mar 26, 2020
2 parents 1239c64 + 61396b2 commit c3a2f3e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
9 changes: 6 additions & 3 deletions FcomClient/FcomClient.Serialization/ApiManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ApiManager
/// <summary>
/// User agent string to use.
/// </summary>
private readonly string CLIENT_VERSION = "FcomClient/0.8.0";
private readonly string CLIENT_VERSION = "FcomClient/0.9.1";

/// <summary>
/// Server address, read from the file server_location.txt
Expand Down Expand Up @@ -160,9 +160,12 @@ public void ForwardMessage(FsdObject.FsdMessage pm)
var content = response.Content;

if (response.IsSuccessful)
Console.WriteLine("Success!");
{
}
else
Console.WriteLine("Fail!");
{
throw new FcomApiException(String.Format("[Message forwarding error] {0}", response.Content));
}

}
}
Expand Down
24 changes: 24 additions & 0 deletions FcomClient/FcomClient.Serialization/FcomApiException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FcomClient.Serialization
{
class FcomApiException : Exception
{
public FcomApiException()
{
}

public FcomApiException(string message) : base(message)
{
}

public FcomApiException(string message, Exception inner) : base(message, inner)
{
}

}
}
17 changes: 14 additions & 3 deletions FcomClient/FcomClient.UI/FcomClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,14 @@ static void OnIncomingFsdPacket(object sender, CaptureEventArgs e)
logger.Log(String.Format("<{0}>", pkt.PacketString));
logger.Log(loggingString);

am.ForwardMessage(pm);
try
{
am.ForwardMessage(pm);
}
catch (FcomApiException ex)
{
logger.Log(ex.Message);
}

// Do not forward messages sent over the frequency, that aren't addressed to the user
//if (pm.Message.StartsWith(callsign))
Expand All @@ -296,8 +303,12 @@ static private bool IsForwardMessage(FsdMessage msg)
string.Equals(msg.Recipient, "data", StringComparison.OrdinalIgnoreCase)
;

// private/frequency messages not addressed to the user...
bool isAddressedToUser = msg.Message.StartsWith(callsign, StringComparison.OrdinalIgnoreCase) ||
// on-frequency and private messages addressed to the user...

// (NOTE: using string.StartsWith() results in partial matches (e.g. UAL1/UAL123), so use regex instead)
// Regex: ^{callsign}( |,).*
Regex frequencyMessagePattern = new Regex("^" + callsign + @"( |,).*", RegexOptions.IgnoreCase);
bool isAddressedToUser = frequencyMessagePattern.IsMatch(msg.Message) ||
string.Equals(msg.Recipient, callsign, StringComparison.OrdinalIgnoreCase);

// self-addressed messages:
Expand Down
1 change: 1 addition & 0 deletions FcomClient/FcomClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<Compile Include="FcomClient.Serialization\ApiObjects\ForwardedMessage.cs" />
<Compile Include="FcomClient.Serialization\ApiObjects\MessageForwardRequest.cs" />
<Compile Include="FcomClient.Serialization\ApiObjects\ServerRegistration.cs" />
<Compile Include="FcomClient.Serialization\FcomApiException.cs" />
<Compile Include="FcomClient.Serialization\MessageForwarder.cs" />
<Compile Include="FcomClient.UI\FcomClient.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
2 changes: 1 addition & 1 deletion FcomClient/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("0.9")]
[assembly: AssemblyFileVersion("0.9.0")]
[assembly: AssemblyFileVersion("0.9.1")]

0 comments on commit c3a2f3e

Please sign in to comment.