Skip to content

Commit

Permalink
Cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
ewrogers committed Apr 19, 2015
1 parent 76de368 commit 2d8c1ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 8 additions & 2 deletions Spark/Net/ServerTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,17 @@ public virtual async Task<bool> CheckClientVersionCodeAsync(int versionCode)
// Get the status code from the response
var statusCode = responsePacket.Data[0];

if (statusCode > 0)
if (statusCode == 0x1) // SERVER MESSAGE
{
// Get the server message and raise an exception
var serverMessage = Encoding.ASCII.GetString(responsePacket.Data.Skip(1).ToArray());
throw new Exception(string.Format("The server has rejected client version {0}.", versionCode));
}
else if (statusCode == 0x2) // PATCH REQUEST
{
// Get the required version and raise an exception
var requiredVersion = IntegerExtender.MakeWord(responsePacket.Data[2], responsePacket.Data[1]);
throw new Exception(string.Format("The server requires client version {0} or higher.", requiredVersion));
throw new Exception(string.Format("The server requires client version {0}.", requiredVersion));
}

// Version was accepted by the server
Expand Down
14 changes: 6 additions & 8 deletions Spark/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,21 +359,19 @@ async void TestConnectionToServer(string serverHostname, int serverPort, int ver
{
await serverTester.ConnectToServerAsync(serverIPAddress, serverPort);

if (await serverTester.CheckClientVersionCodeAsync(versionCode))
var isVersionOK = await serverTester.CheckClientVersionCodeAsync(versionCode);
Debug.WriteLine(string.Format("CheckClientVersionOK: {0}", isVersionOK));

if (isVersionOK)
{
// The server has accepted this client version
this.DialogService.ShowOKDialog("Connection Successful",
"The server appears to be up and running.",
string.Format("Connected to {0}:{1} successfully.", serverIPAddress, serverPort));
}
else
{
//string extraInfo;
//// Known required version number?
//if (reqVersionNumber >= 0)
// extraInfo = string.Format("Required Version: {0}. Detected Version: {1}.", reqVersionNumber, versionNumber);
//else
// extraInfo = string.Format("Detected Version: {0}. Please check what versions the server you are connecting to supports.", versionNumber);

// This server has rejected this client version
this.DialogService.ShowOKDialog("Connection Failed",
"The server appears to be running, but requires a different version of the client.",
null);
Expand Down

0 comments on commit 2d8c1ed

Please sign in to comment.