mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-02-05 02:00:45 +03:00
Merge remote-tracking branch 'origin23/master' into masterFP
This commit is contained in:
commit
22e963250e
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -21,5 +21,6 @@ namespace Steamworks.Data
|
|||||||
|
|
||||||
public ConnectionState State => state;
|
public ConnectionState State => state;
|
||||||
public SteamId SteamId => identity.steamID;
|
public SteamId SteamId => identity.steamID;
|
||||||
|
public int EndReason => endReason;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -278,11 +278,11 @@ namespace Steamworks.Ugc
|
|||||||
while ( true )
|
while ( true )
|
||||||
{
|
{
|
||||||
if ( ct.IsCancellationRequested )
|
if ( ct.IsCancellationRequested )
|
||||||
return false;
|
break;
|
||||||
|
|
||||||
progress?.Invoke( DownloadAmount );
|
progress?.Invoke( DownloadAmount );
|
||||||
|
|
||||||
if ( !IsDownloading )
|
if ( !IsDownloading && State.HasFlag( ItemState.Installed ) )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
await Task.Delay( milisecondsUpdateDelay );
|
await Task.Delay( milisecondsUpdateDelay );
|
||||||
|
@ -15,12 +15,39 @@ namespace Steamworks
|
|||||||
// private static readonly byte A2S_PLAYER = 0x55;
|
// private static readonly byte A2S_PLAYER = 0x55;
|
||||||
private static readonly byte A2S_RULES = 0x56;
|
private static readonly byte A2S_RULES = 0x56;
|
||||||
|
|
||||||
internal static async Task<Dictionary<string, string>> GetRules( ServerInfo server )
|
private static readonly Dictionary<IPEndPoint, Task<Dictionary<string, string>>> PendingQueries =
|
||||||
{
|
new Dictionary<IPEndPoint, Task<Dictionary<string, string>>>();
|
||||||
try
|
|
||||||
|
internal static Task<Dictionary<string, string>> GetRules( ServerInfo server )
|
||||||
{
|
{
|
||||||
var endpoint = new IPEndPoint(server.Address, server.QueryPort);
|
var endpoint = new IPEndPoint(server.Address, server.QueryPort);
|
||||||
|
|
||||||
|
lock (PendingQueries)
|
||||||
|
{
|
||||||
|
if (PendingQueries.TryGetValue(endpoint, out var pending))
|
||||||
|
return pending;
|
||||||
|
|
||||||
|
var task = GetRulesImpl(endpoint, server)
|
||||||
|
.ContinueWith(t =>
|
||||||
|
{
|
||||||
|
lock (PendingQueries)
|
||||||
|
{
|
||||||
|
PendingQueries.Remove(endpoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
return t;
|
||||||
|
})
|
||||||
|
.Unwrap();
|
||||||
|
|
||||||
|
PendingQueries.Add(endpoint, task);
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task<Dictionary<string, string>> GetRulesImpl( IPEndPoint endpoint, ServerInfo server )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
using (var client = new UdpClient())
|
using (var client = new UdpClient())
|
||||||
{
|
{
|
||||||
client.Client.SendTimeout = 3000;
|
client.Client.SendTimeout = 3000;
|
||||||
@ -32,7 +59,7 @@ namespace Steamworks
|
|||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine( e.Message );
|
//Console.Error.WriteLine( e.Message );
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,14 +81,14 @@ namespace Steamworks
|
|||||||
var numRules = br.ReadUInt16();
|
var numRules = br.ReadUInt16();
|
||||||
for ( int index = 0; index < numRules; index++ )
|
for ( int index = 0; index < numRules; index++ )
|
||||||
{
|
{
|
||||||
rules.Add( br.ReadNullTerminatedUTF8String( readBuffer ), br.ReadNullTerminatedUTF8String( readBuffer ) );
|
rules.Add( br.ReadNullTerminatedUTF8String(), br.ReadNullTerminatedUTF8String() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rules;
|
return rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
static byte[] readBuffer = new byte[1024 * 8];
|
|
||||||
|
|
||||||
static async Task<byte[]> Receive( UdpClient client )
|
static async Task<byte[]> Receive( UdpClient client )
|
||||||
{
|
{
|
||||||
@ -120,10 +147,10 @@ namespace Steamworks
|
|||||||
return challengeData;
|
return challengeData;
|
||||||
}
|
}
|
||||||
|
|
||||||
static byte[] sendBuffer = new byte[1024];
|
|
||||||
|
|
||||||
static async Task Send( UdpClient client, byte[] message )
|
static async Task Send( UdpClient client, byte[] message )
|
||||||
{
|
{
|
||||||
|
var sendBuffer = new byte[message.Length + 4];
|
||||||
|
|
||||||
sendBuffer[0] = 0xFF;
|
sendBuffer[0] = 0xFF;
|
||||||
sendBuffer[1] = 0xFF;
|
sendBuffer[1] = 0xFF;
|
||||||
sendBuffer[2] = 0xFF;
|
sendBuffer[2] = 0xFF;
|
||||||
|
@ -80,20 +80,22 @@ namespace Steamworks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ReadNullTerminatedUTF8String( this BinaryReader br, byte[] buffer = null )
|
static byte[] readBuffer = new byte[1024 * 8];
|
||||||
{
|
|
||||||
if ( buffer == null )
|
|
||||||
buffer = new byte[1024];
|
|
||||||
|
|
||||||
|
public static string ReadNullTerminatedUTF8String( this BinaryReader br )
|
||||||
|
{
|
||||||
|
lock ( readBuffer )
|
||||||
|
{
|
||||||
byte chr;
|
byte chr;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while ( (chr = br.ReadByte()) != 0 && i < buffer.Length )
|
while ( (chr = br.ReadByte()) != 0 && i < readBuffer.Length )
|
||||||
{
|
{
|
||||||
buffer[i] = chr;
|
readBuffer[i] = chr;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Encoding.UTF8.GetString( buffer, 0, i );
|
return Encoding.UTF8.GetString( readBuffer, 0, i );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user