Skip to content

Commit 28479f9

Browse files
Improve dimension update for networking entity
1 parent f61521a commit 28479f9

File tree

6 files changed

+41
-9
lines changed

6 files changed

+41
-9
lines changed

api/AltV.Net.NetworkingEntity/ClientEntityStreamingHandler.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ namespace AltV.Net.NetworkingEntity
1717
public class ClientEntityStreamingHandler : IStreamingHandler
1818
{
1919
private readonly INetworkingClientPool networkingClientPool;
20-
20+
2121
private readonly IAuthenticationProvider authenticationProvider;
2222

2323
public event Action<INetworkingEntity, INetworkingClient> EntityStreamInHandler;
2424

2525
public event Action<INetworkingEntity, INetworkingClient> EntityStreamOutHandler;
2626

27-
public ClientEntityStreamingHandler(INetworkingClientPool networkingClientPool, IAuthenticationProvider authenticationProvider)
27+
public ClientEntityStreamingHandler(INetworkingClientPool networkingClientPool,
28+
IAuthenticationProvider authenticationProvider)
2829
{
2930
this.networkingClientPool = networkingClientPool;
3031
this.authenticationProvider = authenticationProvider;
@@ -43,12 +44,15 @@ public void OnMessage(ManagedWebSocket managedWebSocket, WebSocketReceiveResult
4344
{
4445
var token = authEvent.Token;
4546
if (token == null) return;
46-
var verified = await authenticationProvider.Verify(networkingClientPool, managedWebSocket, token, out var client);
47+
var verified = await authenticationProvider.Verify(networkingClientPool, managedWebSocket, token,
48+
out var client);
4749
if (!verified)
4850
{
4951
return;
5052
}
5153

54+
client.OnConnect();
55+
5256
var sendEvent = new ServerEvent();
5357
var currSendEvent = new EntitySendEvent();
5458
lock (AltNetworking.Module.EntityPool.Entities)

api/AltV.Net.NetworkingEntity/Elements/Entities/INetworkingClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ public interface INetworkingClient
1313
ManagedWebSocket WebSocket { get; set; }
1414

1515
int Dimension { get; set; }
16+
17+
void OnConnect();
1618
}
1719
}

api/AltV.Net.NetworkingEntity/Elements/Entities/INetworkingEntity.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public interface INetworkingEntity
4141
/// </summary>
4242
StreamingType StreamingType { get; }
4343

44+
/// <summary>
45+
/// The main entity streamer, not in use currently
46+
/// </summary>
47+
INetworkingClient MainStreamer { get; }
48+
4449

4550
/// <summary>
4651
/// This method is required to call to change entity data after creation to update data snapshot

api/AltV.Net.NetworkingEntity/Elements/Entities/NetworkingClient.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,21 @@ public class NetworkingClient : INetworkingClient, IInternalNetworkingClient
1919

2020
public int Dimension
2121
{
22-
get => dimension;
22+
get
23+
{
24+
lock (this)
25+
{
26+
return dimension;
27+
}
28+
}
2329
set
2430
{
25-
if (dimension == value) return;
26-
entityStreamer.UpdateClientDimension(this, value);
27-
dimension = value;
31+
lock (this)
32+
{
33+
if (dimension == value) return;
34+
entityStreamer.UpdateClientDimension(this, value);
35+
dimension = value;
36+
}
2837
}
2938
}
3039

@@ -34,5 +43,16 @@ public NetworkingClient(string token, IEntityStreamer entityStreamer)
3443
Exists = true;
3544
this.entityStreamer = entityStreamer;
3645
}
46+
47+
public void OnConnect()
48+
{
49+
lock (this)
50+
{
51+
if (dimension != 0)
52+
{
53+
entityStreamer.UpdateClientDimension(this, dimension);
54+
}
55+
}
56+
}
3757
}
3858
}

api/AltV.Net.NetworkingEntity/Elements/Entities/NetworkingEntity.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ public class NetworkingEntity : INetworkingEntity, IInternalNetworkingEntity
1010
private readonly IEntityStreamer entityStreamer;
1111

1212
public EntityDataSnapshot Snapshot { get; }
13-
13+
14+
public INetworkingClient MainStreamer { get; }
1415

1516
public StreamingType StreamingType { get; }
1617

api/AltV.Net/FunctionParser/FunctionTypeInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal class FunctionTypeInfo
4040
public FunctionTypeInfo(Type type)
4141
{
4242
IsList = type.BaseType == FunctionTypes.Array;
43-
IsDict = type.Name.StartsWith("Dictionary");
43+
IsDict = type.Name.StartsWith("Dictionary") || type.Name.StartsWith("IDictionary");
4444
if (IsDict)
4545
{
4646
GenericArguments = type.GetGenericArguments();

0 commit comments

Comments
 (0)