Skip to content

Commit

Permalink
Improvements in how servers are shown.
Browse files Browse the repository at this point in the history
  • Loading branch information
BigETI committed Dec 15, 2018
1 parent 584a0d3 commit 5ff5809
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 61 deletions.
Binary file modified .vs/SAMPLauncherNET/v15/.suo
Binary file not shown.
4 changes: 2 additions & 2 deletions SAMPLauncherNET/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.6.5")]
[assembly: AssemblyFileVersion("1.0.6.5")]
[assembly: AssemblyVersion("1.0.6.6")]
[assembly: AssemblyFileVersion("1.0.6.6")]
4 changes: 2 additions & 2 deletions SAMPLauncherNET/SAMPLauncherNET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Source\SAMPLauncherNET\Core\APIDataContract.cs" />
<Compile Include="Source\SAMPLauncherNET\Core\SAMPAPIServer.cs" />
<Compile Include="Source\SAMPLauncherNET\Core\SAMPAPIServerDataContract.cs" />
<Compile Include="Source\SAMPLauncherNET\Core\SAMPServersAPIServer.cs" />
<Compile Include="Source\SAMPLauncherNET\Core\SAMPServersAPIServerDataContract.cs" />
<Compile Include="Source\SAMPLauncherNET\Core\ChatlogFormatter.cs" />
<Compile Include="Source\SAMPLauncherNET\Core\DeveloperToolsConfigDataContract.cs" />
<Compile Include="Source\SAMPLauncherNET\Core\EChatlogFormatType.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public string RCONPassword
/// <param name="rconPassword">RCON password</param>
public FavouriteServer(string ipAddressAndPortString, string cachedHostname, string cachedGamemode, string serverPassword, string rconPassword) : base(ipAddressAndPortString, false)
{
//requestsRequired[ERequestType.Information] = false;
if (cachedHostname != null)
{
if (cachedHostname.Trim().Length > 0)
Expand All @@ -71,7 +70,6 @@ public FavouriteServer(string ipAddressAndPortString, string cachedHostname, str
/// <param name="fdc">Favorite data contract</param>
public FavouriteServer(FavouriteDataContract fdc) : base(fdc.Host, false)
{
//requestsRequired[ERequestType.Information] = false;
if (fdc.Hostname.Trim().Length > 0)
{
hostname = fdc.Hostname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
namespace SAMPLauncherNET
{
/// <summary>
/// Backend restful API server class
/// SA:MP servers API server class
/// </summary>
public class SAMPAPIServer : Server
public class SAMPServersAPIServer : Server
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="serverData">Server data</param>
public SAMPAPIServer(SAMPAPIServerDataContract serverData) : base(serverData.Host, false)
public SAMPServersAPIServer(SAMPServersAPIServerDataContract serverData) : base(serverData.Host, false)
{
requestsRequired.Lock(ERequestResponseType.Information);
if (serverData.Hostname.Trim().Length > 0)
{
hostname = serverData.Hostname;
Expand All @@ -24,7 +23,8 @@ public SAMPAPIServer(SAMPAPIServerDataContract serverData) : base(serverData.Hos
maxPlayers = serverData.MaxPlayers;
hasPassword = serverData.HasPassword;
language = serverData.Language;
//FetchDataAsync(ERequestType.Ping);
FetchDataAsync(ERequestResponseType.Ping);
FetchDataAsync(ERequestResponseType.Information);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
namespace SAMPLauncherNET
{
/// <summary>
/// SA:MP API server data contract class
/// SA:MP servers API server data contract class
/// </summary>
[DataContract]
public class SAMPAPIServerDataContract
public class SAMPServersAPIServerDataContract
{
/// <summary>
/// Host
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,30 +201,6 @@ public int CompareTo(SAMPVersionDataContract other)
if (ret == 0)
{
ret = string.Compare(other.name, name, StringComparison.InvariantCulture);
/*if (ret == 0)
{
ret = string.Compare(other.internetTabURI, internetTabURI, StringComparison.InvariantCulture);
if (ret == 0)
{
ret = string.Compare(other.hostedTabURI, hostedTabURI, StringComparison.InvariantCulture);
if (ret == 0)
{
ret = string.Compare(other.userAgent, userAgent, StringComparison.InvariantCulture);
if (ret == 0)
{
ret = string.Compare(other.zipURI, zipURI, StringComparison.InvariantCulture);
if (ret == 0)
{
ret = string.Compare(other.installationURI, installationURI, StringComparison.InvariantCulture);
if (ret == 0)
{
ret = string.Compare(other.sampDLLSHA512, sampDLLSHA512, StringComparison.InvariantCulture);
}
}
}
}
}
}*/
}
}
return ret;
Expand Down
22 changes: 5 additions & 17 deletions SAMPLauncherNET/Source/SAMPLauncherNET/Core/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,33 +632,21 @@ private void SendQueryAsync(ERequestResponseType requestType)
threads[index].Start();
}

/// <summary>
/// Send query when required
/// </summary>
/// <param name="requestType">Request type</param>
/// <returns>Success</returns>
private bool SendQueryWhenRequired(ERequestResponseType requestType)
{
bool ret = true;
if (requestsRequired[requestType])
{
ret = SendQuery(requestType);
}
return ret;
}

/// <summary>
/// Send query when expired
/// </summary>
/// <param name="requestType">Request type</param>
/// <param name="milliseconds">Milliseconds</param>
public void SendQueryWhenExpired(ERequestResponseType requestType, uint milliseconds)
/// <returns>"true" if attempted sending query, othewrwise "false"</returns>
public bool SendQueryWhenExpiredAsync(ERequestResponseType requestType, uint milliseconds)
{
uint t = (uint)(DateTime.Now.Subtract(requestsRequired.GetLastRequestTime(requestType)).TotalMilliseconds);
if (t >= milliseconds)
bool ret = (t >= milliseconds);
if (ret)
{
SendQueryAsync(requestType);
}
return ret;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ServerListConnector : ITranslatable
/// <summary>
/// Server list JSON serializer
/// </summary>
private static DataContractJsonSerializer serverListJSONSerializer = new DataContractJsonSerializer(typeof(SAMPAPIServerDataContract[]));
private static DataContractJsonSerializer serverListJSONSerializer = new DataContractJsonSerializer(typeof(SAMPServersAPIServerDataContract[]));

/// <summary>
/// Favourites list JSON serializer
Expand Down Expand Up @@ -199,14 +199,15 @@ public Dictionary<string, Server> ServerListIO
wc.Headers.Set(HttpRequestHeader.ContentType, APIHTTPContentType);
wc.Headers.Set(HttpRequestHeader.Accept, APIHTTPAccept);
wc.Headers.Set(HttpRequestHeader.UserAgent, /* User agent of Firefox */ "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0" /*SAMPProvider.UserAgent*/);
//wc.Headers.Set(HttpRequestHeader.UserAgent, SAMPProvider.UserAgent);
using (MemoryStream stream = new MemoryStream(wc.DownloadData(Endpoint)))
{
SAMPAPIServerDataContract[] servers = serverListJSONSerializer.ReadObject(stream) as SAMPAPIServerDataContract[];
SAMPServersAPIServerDataContract[] servers = serverListJSONSerializer.ReadObject(stream) as SAMPServersAPIServerDataContract[];
if (servers != null)
{
foreach (SAMPAPIServerDataContract sdc in servers)
foreach (SAMPServersAPIServerDataContract sdc in servers)
{
SAMPAPIServer server = new SAMPAPIServer(sdc);
SAMPServersAPIServer server = new SAMPServersAPIServer(sdc);
if (server.IsValid)
{
if (!(ret.ContainsKey(server.IPPortString)))
Expand Down
33 changes: 33 additions & 0 deletions SAMPLauncherNET/Source/SAMPLauncherNET/Core/ServerListEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public class ServerListEntry : IComparable, IComparable<ServerListEntry>, IDispo
/// </summary>
private readonly int serverListIndex;

/// <summary>
/// Tries
/// </summary>
private uint tries;

/// <summary>
/// Server
/// </summary>
Expand All @@ -30,6 +35,11 @@ public class ServerListEntry : IComparable, IComparable<ServerListEntry>, IDispo
/// </summary>
public int ServerListIndex { get => serverListIndex; }

/// <summary>
/// Tries
/// </summary>
public uint Tries { get => tries; }

/// <summary>
/// Constructor
/// </summary>
Expand All @@ -41,6 +51,29 @@ public ServerListEntry(Server server, int serverListIndex)
this.serverListIndex = serverListIndex;
}

/// <summary>
/// Try send query
/// </summary>
public void TrySendQuery()
{
if (server != null)
{
bool tried = false;
if (server.SendQueryWhenExpiredAsync(ERequestResponseType.Ping, 5000U))
{
tried = true;
}
if (server.SendQueryWhenExpiredAsync(ERequestResponseType.Information, 5000U))
{
tried = true;
}
if (tried)
{
++tries;
}
}
}

/// <summary>
/// Compare to
/// </summary>
Expand Down
19 changes: 16 additions & 3 deletions SAMPLauncherNET/Source/SAMPLauncherNET/UI/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,12 @@ public MainForm()
while (keepRunning)
{
List<ServerListEntry> server_list_entries = new List<ServerListEntry>();
List<ServerListEntry> remove_server_list_entries = new List<ServerListEntry>();
lock (loadServers)
{
foreach (ServerListEntry server_list_entry in loadServers)
{
if ((server_list_entry.Server is FavouriteServer) || (server_list_entry.Server is SAMPAPIServer))
if (server_list_entry.Server is FavouriteServer)
{
server_list_entries.Add(server_list_entry);
}
Expand All @@ -276,21 +277,33 @@ public MainForm()
}
else
{
server_list_entry.Server.SendQueryWhenExpired(ERequestResponseType.Ping, 5000U);
server_list_entry.Server.SendQueryWhenExpired(ERequestResponseType.Information, 5000U);
if (server_list_entry.Tries > 2U)
{
remove_server_list_entries.Add(server_list_entry);
}
else
{
server_list_entry.TrySendQuery();
}
}
}
}
foreach (ServerListEntry server_list_entry in server_list_entries)
{
loadServers.Remove(server_list_entry);
}
foreach (ServerListEntry server_list_entry in remove_server_list_entries)
{
loadServers.Remove(server_list_entry);
server_list_entry.Dispose();
}
}
lock (loadedServers)
{
loadedServers.AddRange(server_list_entries);
}
server_list_entries.Clear();
remove_server_list_entries.Clear();
Thread.Sleep(50);
}
});
Expand Down
Binary file modified SAMPLauncherNET/obj/Debug/DesignTimeResolveAssemblyReferences.cache
Binary file not shown.

0 comments on commit 5ff5809

Please sign in to comment.