Ejemplo n.º 1
0
        /// <summary>
        ///     Called when a <see cref="ChangeAvatarNameMessage"/> is received.
        /// </summary>
        internal void ChangeAvatarNameMessageReceived(ChangeAvatarNameMessage message)
        {
            if (message.GetNameSetByUser() && !this._session.AvatarAccount.AvatarEntry.GetNameSetByUser())
            {
                string avatarName = message.RemoveAvatarName();

                if (!string.IsNullOrWhiteSpace(avatarName))
                {
                    if (avatarName.Length <= 12)
                    {
                        avatarName = ServiceAvatar.Regex.Replace(avatarName, " ");

                        if (avatarName.Length >= 2)
                        {
                            AllowServerCommandMessage    allowServerCommandMessage = new AllowServerCommandMessage();
                            LogicChangeAvatarNameCommand serverCommand             = new LogicChangeAvatarNameCommand();

                            serverCommand.SetAvatarName(avatarName);
                            serverCommand.SetAvatarNameChangeState(0);
                            allowServerCommandMessage.SetServerCommand(serverCommand);

                            this._session.SendMessage(NetUtils.SERVICE_NODE_TYPE_ZONE_CONTAINER, allowServerCommandMessage);
                        }
                    }
                }
            }
        }
        private void OnChangeAvatarNameMessageReceived(ChangeAvatarNameMessage message)
        {
            if (message.GetNameSetByUser())
            {
                string name = message.RemoveAvatarName();

                if (name == null)
                {
                    return;
                }

                name = StringUtil.RemoveMultipleSpaces(name.Trim());

                if (name.Length < 2)
                {
                    AvatarNameChangeFailedMessage avatarNameChangeFailedMessage = new AvatarNameChangeFailedMessage();
                    avatarNameChangeFailedMessage.SetErrorCode(AvatarNameChangeFailedMessage.ErrorCode.TOO_SHORT);
                    this.m_session.SendPiranhaMessage(avatarNameChangeFailedMessage, 1);
                    return;
                }

                if (name.Length > 16)
                {
                    AvatarNameChangeFailedMessage avatarNameChangeFailedMessage = new AvatarNameChangeFailedMessage();
                    avatarNameChangeFailedMessage.SetErrorCode(AvatarNameChangeFailedMessage.ErrorCode.TOO_LONG);
                    this.m_session.SendPiranhaMessage(avatarNameChangeFailedMessage, 1);
                    return;
                }

                if (WordCensorUtil.IsValidMessage(name))
                {
                    LogicClientAvatar logicClientAvatar = this.m_session.GameAvatar.LogicClientAvatar;

                    if (logicClientAvatar.GetNameChangeState() >= 1)
                    {
                        AvatarNameChangeFailedMessage avatarNameChangeFailedMessage = new AvatarNameChangeFailedMessage();
                        avatarNameChangeFailedMessage.SetErrorCode(AvatarNameChangeFailedMessage.ErrorCode.ALREADY_CHANGED);
                        this.m_session.SendPiranhaMessage(avatarNameChangeFailedMessage, 1);
                        return;
                    }

                    if (logicClientAvatar.GetNameChangeState() == 0 && logicClientAvatar.GetTownHallLevel() < LogicDataTables.GetGlobals().GetEnableNameChangeTownHallLevel())
                    {
                        AvatarNameChangeFailedMessage avatarNameChangeFailedMessage = new AvatarNameChangeFailedMessage();
                        avatarNameChangeFailedMessage.SetErrorCode(AvatarNameChangeFailedMessage.ErrorCode.TH_LEVEL_TOO_LOW);
                        this.m_session.SendPiranhaMessage(avatarNameChangeFailedMessage, 1);
                        return;
                    }

                    LogicChangeAvatarNameCommand serverCommand = new LogicChangeAvatarNameCommand();

                    serverCommand.SetAvatarName(name);
                    serverCommand.SetAvatarNameChangeState(logicClientAvatar.GetNameChangeState() + 1);

                    this.m_session.GameAvatar.LogicClientAvatar.SetName(name);
                    this.m_session.GameAvatar.LogicClientAvatar.SetNameChangeState(logicClientAvatar.GetNameChangeState() + 1);
                    this.m_session.GameAvatar.AddServerCommand(serverCommand);
                }
                else
                {
                    AvatarNameChangeFailedMessage avatarNameChangeFailedMessage = new AvatarNameChangeFailedMessage();
                    avatarNameChangeFailedMessage.SetErrorCode(AvatarNameChangeFailedMessage.ErrorCode.BAD_WORD);
                    this.m_session.SendPiranhaMessage(avatarNameChangeFailedMessage, 1);
                }
            }
        }