Пример #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);
            }
        }
Пример #2
0
 /// <summary>
 /// Register a method to be invoked when a payload of a certain type is received.
 /// </summary>
 /// <typeparam name="T">The payload type to listen for</typeparam>
 /// <param name="c">The method to call</param>
 public void AddCallback <T>(FlarePayloadCallback <T> c) where T : INetworkPayload => PayloadHandler.AddCallback(c);