Merge pull request #206 from Raicuparta/alek/net-changes-stuff

some stuff
This commit is contained in:
Mister_Nebula 2020-09-07 19:02:14 +01:00 committed by GitHub
commit 66a7c7a915
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 20 deletions

View File

@ -2,7 +2,6 @@
using QSB.Messaging;
using QSB.TransformSync;
using QSB.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Networking;
@ -42,11 +41,7 @@ namespace QSB
public static bool PlayerExists(uint id)
{
if (id == uint.MaxValue)
{
return false;
}
return PlayerList.Any(x => x.PlayerId == id);
return id != uint.MaxValue && PlayerList.Any(x => x.PlayerId == id);
}
public static void HandleFullStateMessage(PlayerStateMessage message)
@ -102,20 +97,8 @@ namespace QSB
public static List<uint> GetPlayerNetIds(PlayerInfo player)
{
var ints = Enumerable.Range((int)player.PlayerId, PlayerSyncObjects.DistinctBy(x => x.AttachedNetId).Count(x => x.Player.PlayerId == player.PlayerId)).Select(x => (uint)x).ToList();
return ints;
}
private static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
var seenKeys = new HashSet<TKey>();
foreach (var element in source)
{
if (seenKeys.Add(keySelector(element)))
{
yield return element;
}
}
var count = PlayerSyncObjects.DistinctBy(x => x.AttachedNetId).Count(x => x.Player.PlayerId == player.PlayerId);
return Enumerable.Range((int)player.PlayerId, count).Select(x => (uint)x).ToList();
}
}
}

View File

@ -164,6 +164,7 @@
<Compile Include="TransformSync\QSBSectorManager.cs" />
<Compile Include="TransformSync\TransformSync.cs" />
<Compile Include="Utility\GOExtensions.cs" />
<Compile Include="Utility\ListExtensions.cs" />
<Compile Include="WorldSync\BoolWorldObjectMessage.cs" />
<Compile Include="WorldSync\WorldObjectMessage.cs" />
<Compile Include="Tools\QSBFlashlight.cs" />

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
namespace QSB.Utility
{
public static class ListExtensions
{
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
var seenKeys = new HashSet<TKey>();
foreach (var element in source)
{
if (seenKeys.Add(keySelector(element)))
{
yield return element;
}
}
}
}
}