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); } } }
private void OnAvatarNameCheckRequestMessageReceived(AvatarNameCheckRequestMessage message) { string name = message.GetName(); if (name == null) { return; } name = StringUtil.RemoveMultipleSpaces(name.Trim()); if (name.Length < 2) { AvatarNameCheckResponseMessage avatarNameCheckResponseMessage = new AvatarNameCheckResponseMessage(); avatarNameCheckResponseMessage.SetName(message.GetName()); avatarNameCheckResponseMessage.SetInvalid(true); avatarNameCheckResponseMessage.SetErrorCode(AvatarNameCheckResponseMessage.ErrorCode.NAME_TOO_SHORT); this.m_session.SendPiranhaMessage(avatarNameCheckResponseMessage, 1); return; } if (name.Length > 16) { AvatarNameCheckResponseMessage avatarNameCheckResponseMessage = new AvatarNameCheckResponseMessage(); avatarNameCheckResponseMessage.SetName(message.GetName()); avatarNameCheckResponseMessage.SetInvalid(true); avatarNameCheckResponseMessage.SetErrorCode(AvatarNameCheckResponseMessage.ErrorCode.NAME_TOO_LONG); this.m_session.SendPiranhaMessage(avatarNameCheckResponseMessage, 1); return; } if (WordCensorUtil.IsValidMessage(name)) { LogicClientAvatar logicClientAvatar = this.m_session.GameAvatar.LogicClientAvatar; if (logicClientAvatar.GetNameChangeState() >= 1) { AvatarNameCheckResponseMessage avatarNameCheckResponseMessage = new AvatarNameCheckResponseMessage(); avatarNameCheckResponseMessage.SetName(message.GetName()); avatarNameCheckResponseMessage.SetInvalid(true); avatarNameCheckResponseMessage.SetErrorCode(AvatarNameCheckResponseMessage.ErrorCode.NAME_ALREADY_CHANGED); this.m_session.SendPiranhaMessage(avatarNameCheckResponseMessage, 1); return; } if (logicClientAvatar.GetNameChangeState() == 0 && logicClientAvatar.GetTownHallLevel() < LogicDataTables.GetGlobals().GetEnableNameChangeTownHallLevel()) { AvatarNameCheckResponseMessage avatarNameCheckResponseMessage = new AvatarNameCheckResponseMessage(); avatarNameCheckResponseMessage.SetName(message.GetName()); avatarNameCheckResponseMessage.SetInvalid(true); avatarNameCheckResponseMessage.SetErrorCode(AvatarNameCheckResponseMessage.ErrorCode.NAME_TH_LEVEL_TOO_LOW); this.m_session.SendPiranhaMessage(avatarNameCheckResponseMessage, 1); } else { AvatarNameCheckResponseMessage avatarNameCheckResponseMessage = new AvatarNameCheckResponseMessage(); avatarNameCheckResponseMessage.SetName(message.GetName()); this.m_session.SendPiranhaMessage(avatarNameCheckResponseMessage, 1); } } else { AvatarNameCheckResponseMessage avatarNameCheckResponseMessage = new AvatarNameCheckResponseMessage(); avatarNameCheckResponseMessage.SetName(message.GetName()); avatarNameCheckResponseMessage.SetInvalid(true); avatarNameCheckResponseMessage.SetErrorCode(AvatarNameCheckResponseMessage.ErrorCode.INVALID_NAME); this.m_session.SendPiranhaMessage(avatarNameCheckResponseMessage, 1); } }