Esempio n. 1
0
        /// <summary>
        /// Sends a failed <see cref="LoginResponsePacket"/> with the given reason and message.
        /// </summary>
        /// <param name="connectionId">Connection ID</param>
        /// <param name="failureReason">Failure reason</param>
        /// <param name="failureMessage">Failure message</param>
        private void sendFailedLoginResponsePacket(string connectionId, LoginFailureReason failureReason, string failureMessage)
        {
            RaiseLogEntry(new LogEventArgs(string.Format("Sending failed LoginResponsePacket to connection {0}", connectionId), LogLevel.DEBUG));

            // Create and pack a response
            LoginResponsePacket response = new LoginResponsePacket
            {
                Success        = false,
                FailureReason  = failureReason,
                FailureMessage = failureMessage
            };
            Any packedResponse = ProtobufPacketHelper.Pack(response);

            // Send it on its way
            if (!netServer.TrySend(connectionId, MODULE_NAME, packedResponse.ToByteArray()))
            {
                RaiseLogEntry(new LogEventArgs("Failed to send LoginResponsePacket to connection " + connectionId, LogLevel.ERROR));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Sends a successful <see cref="LoginResponsePacket"/> with the given UUID and display name.
        /// </summary>
        /// <param name="connectionId">Connection ID</param>
        /// <param name="uuid">User's UUID</param>
        /// <param name="displayName">User's display name</param>
        private void sendSuccessfulLoginResponsePacket(string connectionId, string uuid, string displayName)
        {
            RaiseLogEntry(new LogEventArgs(string.Format("Sending successful LoginResponsePacket to connection {0}", connectionId), LogLevel.DEBUG));

            // Create and pack a response
            LoginResponsePacket response = new LoginResponsePacket
            {
                Success     = true,
                Uuid        = uuid,
                DisplayName = displayName
            };
            Any packedResponse = ProtobufPacketHelper.Pack(response);

            // Send it on its way
            if (!netServer.TrySend(connectionId, MODULE_NAME, packedResponse.ToByteArray()))
            {
                RaiseLogEntry(new LogEventArgs("Failed to send LoginResponsePacket to connection " + connectionId, LogLevel.ERROR));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Handles incoming <see cref="LoginResponsePacket"/>s.
        /// </summary>
        /// <param name="connectionId">Original connection ID</param>
        /// <param name="packet">Incoming <see cref="LoginResponsePacket"/></param>
        private void loginResponsePacketHandler(string connectionId, LoginResponsePacket packet)
        {
            if (packet.Success)
            {
                // Set module states
                LoggedIn = true;
                Uuid     = packet.Uuid;

                // Raise login success event
                OnLoginSuccess?.Invoke(this, new LoginEventArgs());
            }
            else
            {
                // Set module states
                LoggedIn = false;
                Uuid     = null;

                // Raise login failure event
                OnLoginFailure?.Invoke(this, new LoginEventArgs(packet.FailureReason, packet.FailureMessage));
            }
        }