Ejemplo n.º 1
0
        public override void FireRead(FrameStream frame, NetworkingPlayer currentPlayer)
        {
            // Check for default messages
            if (frame is Text)
            {
                // This packet is sent if the player did not receive it's network id
                if (frame.GroupId == MessageGroupIds.NETWORK_ID_REQUEST)
                {
                    currentPlayer.InstanceGuid = frame.ToString();

                    OnPlayerGuidAssigned(currentPlayer);

                    // If so, just resend the player id
                    writeBuffer.Clear();
                    writeBuffer.Append(BitConverter.GetBytes(currentPlayer.NetworkId));
                    Send(currentPlayer, new Binary(Time.Timestep, false, writeBuffer, Receivers.Target, MessageGroupIds.NETWORK_ID_REQUEST, false), true);

                    SendBuffer(currentPlayer);
                    return;
                }
            }

            if (frame is ConnectionClose)
            {
                //Send(currentReadingPlayer, new ConnectionClose(Time.Timestep, false, Receivers.Server, MessageGroupIds.DISCONNECT, false), false);

                Disconnect(currentReadingPlayer, true);
                CleanupDisconnections();
                return;
            }

            // Send an event off that a packet has been read
            OnMessageReceived(currentReadingPlayer, frame);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads the frame stream as if it were read on the network
        /// </summary>
        /// <param name="frame">Data extracted from BMSByte packet</param>
        /// <param name="currentPlayer">Client who sent the data</param>
        public override void FireRead(FrameStream frame, NetworkingPlayer currentPlayer)
        {
            // Check for default messages
            if (frame is Text)
            {
                // This packet is sent if the player did not receive it's network id
                if (frame.GroupId == MessageGroupIds.NETWORK_ID_REQUEST)
                {
                    currentPlayer.InstanceGuid = frame.ToString();

                    bool rejected;
                    OnPlayerGuidAssigned(currentPlayer, out rejected);

                    // If the player was rejected during the handling of the playerGuidAssigned event, don't accept them.
                    if (rejected)
                    {
                        return;
                    }

                    // If so, check if there's a user authenticator
                    if (authenticator != null)
                    {
                        authenticator.IssueChallenge(this, currentPlayer, IssueChallenge, AuthUser);
                    }
                    else
                    {
                        AuthUser(currentPlayer);
                    }

                    return;
                }
            }
            else if (frame is Binary)
            {
                if (frame.GroupId == MessageGroupIds.AUTHENTICATION_RESPONSE)
                {
                    // Authenticate user response
                    if (currentPlayer.Authenticated || authenticator == null)
                    {
                        return;
                    }

                    authenticator.VerifyResponse(this, currentPlayer, frame.StreamData, AuthUser, RejectUser);
                    return;
                }
            }

            if (frame is ConnectionClose)
            {
                // TODO:  Check is this return send command required?
                //Send(currentReadingPlayer, new ConnectionClose(Time.Timestep, false, Receivers.Server, MessageGroupIds.DISCONNECT, false), false);
                Disconnect(currentReadingPlayer, true);
                CleanupDisconnections();
                return;
            }

            // Send an event off that a packet has been read
            OnMessageReceived(currentReadingPlayer, frame);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handle network id requests
        /// </summary>
        /// <param name="currentPlayer"></param>
        /// <param name="frame"></param>
        private void HandleNetworkIdRequest(NetworkingPlayer currentPlayer, FrameStream frame)
        {
            currentPlayer.InstanceGuid = frame.ToString();

            // If the player was rejected during the handling of the playerGuidAssigned event, don't accept them.
            if (!TryPlayerGuidAssignment(currentPlayer))
            {
                return;
            }

            // If so, check if there's a user authenticator
            if (authenticator != null)
            {
                authenticator.IssueChallenge(this, currentPlayer, IssueChallenge, AuthUser);
            }
            else
            {
                AuthUser(currentPlayer);
            }
        }
        private void PacketSequenceComplete(BMSByte data, int groupId, byte receivers)
        {
            // Pull the frame from the sent message
            FrameStream frame = Factory.DecodeMessage(data.CompressBytes(), false, groupId, currentReadingPlayer, receivers);

            // Check for default messages
            if (frame is Text)
            {
                // This packet is sent if the player did not receive it's network id
                if (frame.GroupId == MessageGroupIds.NETWORK_ID_REQUEST)
                {
                    currentReadingPlayer.InstanceGuid = frame.ToString();

                    OnPlayerGuidAssigned(currentReadingPlayer);

                    // If so, just resend the player id
                    writeBuffer.Clear();
                    writeBuffer.Append(BitConverter.GetBytes(currentReadingPlayer.NetworkId));
                    Send(currentReadingPlayer, new Binary(Time.Timestep, false, writeBuffer, Receivers.Target, MessageGroupIds.NETWORK_ID_REQUEST, false), true);

                    SendBuffer(currentReadingPlayer);
                    return;
                }
            }

            if (frame is ConnectionClose)
            {
                Send(currentReadingPlayer, new ConnectionClose(Time.Timestep, false, Receivers.Server, MessageGroupIds.DISCONNECT, false), false);

                Disconnect(currentReadingPlayer, false);
                CleanupDisconnections();
                return;
            }

            // Send an event off that a packet has been read
            OnMessageReceived(currentReadingPlayer, frame);
        }