Exemplo n.º 1
0
        /// <summary>
        /// Handles an incoming handshake request. We should only receive one of these!
        /// </summary>
        protected async Task handleHandshakeRequestMessage(HandshakeRequestMessage message)
        {
            CurrentViewPort        = message.InitialViewport;
            AbsoluteCursorPosition = message.InitialAbsCursorPosition;

            // Tell everyone else about the new client
            ClientStatesMessage newClientNotification = new ClientStatesMessage();

            newClientNotification.ClientStates.Add(GenerateStateSnapshot());
            await manager.Broadcast(this, newClientNotification);

            // Send the new client a response to their handshake request
            HandshakeResponseMessage handshakeResponse = new HandshakeResponseMessage();

            handshakeResponse.Id     = Id;
            handshakeResponse.Colour = Colour;
            handshakeResponse.Name   = Name;
            foreach (Plane plane in manager.NibriServer.PlaneManager.Planes)
            {
                handshakeResponse.Planes.Add(plane.Name);
            }

            await Send(handshakeResponse);

            // Tell the new client about everyone else who's connected
            // FUTURE: If we need to handle a large number of connections, we should generate this message based on the chunks surrounding the client
            await Send(GenerateClientStateUpdate());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles an incoming cursor position message from the client..
        /// </summary>
        /// <param name="message">The message to process.</param>
        protected async Task handleCursorPositionMessage(CursorPositionMessage message)
        {
            AbsoluteCursorPosition = message.AbsCursorPosition;

            // Send the update to the other clients
            // TODO: Buffer these updates and send them about 5 times a second
            // This will improve bandwidth & server resource usage when many clients are connected
            ClientStatesMessage updateMessage = new ClientStatesMessage();

            updateMessage.ClientStates.Add(this.GenerateStateSnapshot());

            await manager.BroadcastPlane(this, updateMessage);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generates an update message that contains information about the locations and states of all connected clients.
        /// Automatically omits information about the current client, and clients on other planes.
        /// </summary>
        /// <returns>The client state update message.</returns>
        protected ClientStatesMessage GenerateClientStateUpdate()
        {
            ClientStatesMessage result = new ClientStatesMessage();

            foreach (NibriClient otherClient in manager.NibriClients)
            {
                // Don't include ourselves in the update message!
                if (otherClient == this)
                {
                    continue;
                }
                // Only include other nibri clients on our plane
                if (otherClient.CurrentPlane != CurrentPlane)
                {
                    continue;
                }

                result.ClientStates.Add(otherClient.GenerateStateSnapshot());
            }
            return(result);
        }