Esempio n. 1
0
 public bool Add(INetworkingClient client)
 {
     lock (entities)
     {
         return(entities.TryAdd(client.Token, client));
     }
 }
Esempio n. 2
0
 public bool TryGet(string token, out INetworkingClient client)
 {
     lock (entities)
     {
         return(entities.TryGetValue(token, out client));
     }
 }
        /// <summary>
        /// Checks which keys have changed for the input data snapshot to stay in sync
        /// </summary>
        /// <param name="networkingClient">The networking client to compare, we need the client not the snapshot to keep reference for possible overflow</param>
        /// <returns>the changed keys, returns null when no changes</returns>
        public IEnumerable <string> CompareWithClient(INetworkingClient networkingClient)
        {
            if (Snapshots == null)
            {
                return(null);                   // entity snapshot never updated, nothing to do
            }
            lastClients.Add(networkingClient);
            IEnumerable <string> changedKeys;
            var clientDataSnapshot = networkingClient.Snapshot;

            if (clientDataSnapshot.TryGetSnapshotForEntity(entityId, out var entitySnapshotFromClient)
                ) // client visited entity before
            {
                changedKeys = Compare(entitySnapshotFromClient);
                entitySnapshotFromClient.Snapshots.Clear();
                foreach (var(key, value) in Snapshots)
                {
                    entitySnapshotFromClient.Snapshots[key] = value;
                }
            }
            else // client never visited entity before
            {
                changedKeys = Snapshots.Keys.ToArray();
                clientDataSnapshot.SetSnapshotForEntity(entityId,
                                                        new DataSnapshot(new ConcurrentDictionary <string, ulong>(Snapshots)));
            }

            return(changedKeys);
        }
Esempio n. 4
0
        public void UpdateClientPositionOverride(INetworkingClient networkingClient, Vector3?position)
        {
            ServerEvent serverEvent;

            if (position != null)
            {
                var clientPositionOverrideChangeEvent = new ClientPositionOverrideChangeEvent
                {
                    PositionX = position.Value.X, PositionY = position.Value.Y, PositionZ = position.Value.Z
                };
                serverEvent = new ServerEvent {
                    ClientPositionOverrideChange = clientPositionOverrideChangeEvent
                };
            }
            else
            {
                var clientPositionStopOverrideChangeEvent = new ClientPositionStopOverrideChangeEvent();
                serverEvent = new ServerEvent
                {
                    ClientPositionStopOverrideChange = clientPositionStopOverrideChangeEvent
                };
            }

            var bytes = serverEvent.ToByteArray();

            lock (networkingClient)
            {
                if (networkingClient.Exists)
                {
                    networkingClient.WebSocket?.SendAsync(bytes, true);
                }
            }
        }
Esempio n. 5
0
 public DataBlockManager(INetworkingClient client)
 {
     Client            = client;
     BlockEventManager = new BlockEventManager(Client);
     BlockEventManager.RegisterEvents();
     SendBlockQueue = new ConcurrentQueue <IBlockEvent>();
     Task.Factory.StartNew(() => Update());
 }
 public void Process(INetworkingClient client)//currently only support server clients and not regular clients
 {
     if (NewBlock)
     {
         client.BlockManager.NewBlock(BlockEventId, BlockLength);
     }
     else
     {
         client.BlockManager.AddBlock(Block);
     }
 }
 public Task <bool> Verify(INetworkingClientPool networkingClientPool, ManagedWebSocket webSocket, string token,
                           out INetworkingClient client)
 {
     if (!networkingClientPool.TryGet(token, out client))
     {
         return(Task.FromResult(false));
     }
     //TODO: check if already has websocket ect. client.WebSocket
     webSocket.Extra[ClientExtra] = client;
     return(Task.FromResult(true));
 }
Esempio n. 8
0
        public void UpdateClientDimension(INetworkingClient networkingClient, int dimension)
        {
            var clientDimensionChangeEvent = new ClientDimensionChangeEvent {
                Dimension = dimension
            };
            var serverEvent = new ServerEvent {
                ClientDimensionChange = clientDimensionChangeEvent
            };
            var bytes = serverEvent.ToByteArray();

            networkingClient.WebSocket.SendAsync(bytes, true);
        }
Esempio n. 9
0
        public bool Remove(string token, out INetworkingClient client)
        {
            idProvider.Free(token);
            lock (entities)
            {
                if (!entities.Remove(token, out client))
                {
                    return(false);
                }
            }

            if (client is IInternalNetworkingClient internalNetworkingClient)
            {
                lock (internalNetworkingClient)
                {
                    internalNetworkingClient.Exists = false;
                }
            }

            return(true);
        }
        public Task <bool> Verify(INetworkingClientPool networkingClientPool, ManagedWebSocket managedWebSocket,
                                  string token, out INetworkingClient client)
        {
            if (networkingClientPool.TryGet(token, out client))
            {
                //managedWebSocket.Extra.TryAdd("client", client);

                /*if (client.WebSocket != managedWebSocket)
                 * {
                 *  webSocket.CloseWebSocket(client.WebSocket);
                 * }
                 *
                 * client.WebSocket = managedWebSocket;*/
                //return Task.FromResult(true);
                networkingClientPool.Remove(client);
                //TODO: maybe try to reuse clients later when client can send if it was a reconnect or new connection in auth event
            }

            client           = AltNetworking.CreateClient(token);
            client.WebSocket = managedWebSocket; //TODO: maybe do that automatically, but we would lost freedom
            managedWebSocket.Extra.TryAdd("client", client);
            return(Task.FromResult(true));
        }
Esempio n. 11
0
 public void Transmit(INetworkingClient client)
 {
     client.BlockManager.QueueBlockEvent(this);
 }
Esempio n. 12
0
 public void Process(INetworkingClient client)
 {
 }
 public RemoteEventManager(INetworkingClient client)
 {
     Client       = client;
     RemoteEvents = new List <RemoteEvent>();
 }
 public UserClient(INetworkingClient client)
 {
     this.client = client;
 }
Esempio n. 15
0
 public void Process(INetworkingClient client)//currently only support server clients and not regular clients
 {
 }
 internal static void SetNetworkingClient(this IPlayer player, INetworkingClient client)
 {
     player.SetData(ClientKey, client);
 }
Esempio n. 17
0
 public ConversationClient(INetworkingClient client)
 {
     this.client = client;
 }
 public bool VerifyPosition(INetworkingClient client, INetworkingEntity entity, bool inRange)
 {
     return(true);
 }
Esempio n. 19
0
 public void Transmit(INetworkingClient client)
 {
     throw new NotImplementedException();
 }
 public GameEventManager(INetworkingClient client)
 {
     Client = client;
 }
 public bool VerifyPosition(INetworkingClient client, INetworkingEntity entity, bool inRange)
 {
     // Can be extended when more trustful position checking is needed
     return(true);
 }
 public static bool TryGetNetworkingClient(this IPlayer player, out INetworkingClient client)
 {
     return(player.GetData(ClientKey, out client));
 }
 public void Transmit(INetworkingClient client)
 {
     client.SendEvent(this);
 }
 public void Process(INetworkingClient client)
 {
     client.SetAuthenticated(true);
 }
 public void Process(INetworkingClient client)
 {
     client.RemoteEventManager.TriggerEvent(EventId, FunctionId);
 }
Esempio n. 26
0
 public void Transmit(INetworkingClient client)//currently only support server clients and not regular clients
 {
 }
Esempio n. 27
0
 public void Process(INetworkingClient client)
 {
     throw new NotImplementedException();
 }
Esempio n. 28
0
 public BlockEventManager(INetworkingClient client)
 {
     Client      = client;
     BlockEvents = new Dictionary <BlockEventId, Type>();
 }
 public MessageClient(INetworkingClient client)
 {
     this.client = client;
 }
Esempio n. 30
0
 public void Remove(INetworkingClient client) => Remove(client.Token);