Example #1
0
        protected override void OnConnect(Event e)
        {
            Peer peer = e.Peer;
            uint id   = peer.ID + 1;           // Increase by 1 so ID of 0 remains free for host

            if (peer.IsSet)
            {
                NetworkLogger.Log($"Client [{id}] connected", LogCategory.Connections);

                var client = new FlareClientShell(peer)
                {
                    Id = id
                };
                ClientManager?.AddClient(client);

                // Send the client its ID manually
                PayloadHandler.AddCallback <ClientAssigned>(PushClientConnected);
                SendMessage(new IdAssignment {
                    id = id
                }, 0, peers: client.Peer);
            }
            else
            {
                NetworkLogger.Log("Unset peer connected. How?", LogCategory.Connections, LogLevel.Error);
            }
        }
Example #2
0
        /// <summary>
        /// Get all connected clients as an array.
        /// </summary>
        /// <returns>Connected clients as an array</returns>
        internal FlareClientShell[] GetAllClients()
        {
            var clients = new FlareClientShell[connectedClients.Count];

            connectedClients.Values.CopyTo(clients, 0);

            return(clients);
        }
Example #3
0
        /// <summary>
        /// Add a client to the client manager.
        /// </summary>
        /// <param name="client"></param>
        internal void AddClient(FlareClientShell client)
        {
            uint id = client.Id;

            // Add client to the connect clients dictionary
            if (!connectedClients.ContainsKey(id))
            {
                connectedClients.Add(id, client);
            }
            else
            {
                NetworkLogger.Log($"Unable to add already existing peer with ID [{id}] to ClientManager!", LogCategory.Connections, LogLevel.Error);
            }
        }
Example #4
0
 /// <summary>
 /// Get a client by ID.
 /// </summary>
 /// <param name="clientId">The ID of the client</param>
 /// <returns></returns>
 internal bool TryGetClient(uint clientId, out FlareClientShell client)
 {
     return(connectedClients.TryGetValue(clientId, out client));
 }