private static bool HandleExchangeRedemption(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData) { switch (Event) { case ItemEventType.Interact: int ItemValue = 0; int.TryParse(Item.Flags, out ItemValue); using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { if (ItemValue != 0) { Session.CharacterInfo.UpdateCreditsBalance(MySqlClient, ItemValue); Session.SendData(CreditsBalanceComposer.Compose(Session.CharacterInfo.CreditsBalance)); } Item.RemovePermanently(MySqlClient); } Instance.TakeItem(Item.Id); Instance.RegenerateRelativeHeightmap(); break; } return(true); }
public static bool TryRedeemVoucher(SqlDatabaseClient MySqlClient, Session Session, string Code) { lock (mSyncRoot) { VoucherValueData ValueData = GetVoucherValue(Code); if (ValueData == null) { return(false); } if (ValueData.ValueCredits > 0) { Session.CharacterInfo.UpdateCreditsBalance(MySqlClient, ValueData.ValueCredits); Session.SendData(CreditsBalanceComposer.Compose(Session.CharacterInfo.CreditsBalance)); } if (ValueData.ValuePixels > 0) { Session.CharacterInfo.UpdateActivityPointsBalance(MySqlClient, ValueData.ValuePixels); Session.SendData(ActivityPointsBalanceComposer.Compose(Session.CharacterInfo.ActivityPointsBalance, ValueData.ValuePixels)); } if (ValueData.ValueFurni.Count > 0) { Dictionary <int, List <uint> > NotifyItems = new Dictionary <int, List <uint> >(); foreach (uint ItemId in ValueData.ValueFurni) { Item Item = ItemFactory.CreateItem(MySqlClient, ItemId, Session.CharacterId, string.Empty, string.Empty, 0, false); if (Item != null) { int NotifyTabId = Item.Definition.Type == ItemType.WallItem ? 2 : 1; Session.InventoryCache.Add(Item); Session.NewItemsCache.MarkNewItem(MySqlClient, NotifyTabId, Item.Id); if (!NotifyItems.ContainsKey(NotifyTabId)) { NotifyItems.Add(NotifyTabId, new List <uint>()); } NotifyItems[NotifyTabId].Add(Item.Id); } } if (NotifyItems.Count > 0) { Session.SendData(InventoryRefreshComposer.Compose()); Session.SendData(InventoryNewItemsComposer.Compose(new Dictionary <int, List <uint> >(NotifyItems))); } } MarkVoucherUsed(Code); return(true); } }
public static void HandlePurchase(SqlDatabaseClient MySqlClient, Session Session, CatalogItem Item, string ItemFlags) { lock (mPurchaseSyncRoot) { string Color = "ffffff"; int TotalCreditCost = Item.CostCredits; int TotalApCost = Item.CostActivityPoints; if (Session.CharacterInfo.CreditsBalance < TotalCreditCost || Session.CharacterInfo.ActivityPointsBalance < TotalApCost) { return; } string[] PetData = null; if (Item.PresetFlags.Length > 0) { ItemFlags = Item.PresetFlags; } else { switch (Item.Definition.Behavior) { case ItemBehavior.Pet: PetData = ItemFlags.Split('\n'); if (PetData.Length != 3) { return; } string Name = PetData[0]; Color = PetData[2]; int Race = 0; int.TryParse(PetData[1], out Race); bool RaceOk = false; List <PetRaceData> Races = PetDataManager.GetRaceDataForType(Item.Definition.BehaviorData); foreach (PetRaceData RaceData in Races) { if (RaceData.Data1 == Race) { RaceOk = true; break; } } /// if (PetName.VerifyPetName(Name) != PetNameError.NameOk || Color.ToLower() != "ffffff" || !RaceOk) if (PetName.VerifyPetName(Name) != PetNameError.NameOk || !RaceOk) // WHY COLOR??? { return; } break; case ItemBehavior.PrizeTrophy: if (ItemFlags.Length > 255) { ItemFlags = ItemFlags.Substring(0, 255); } ItemFlags = Session.CharacterInfo.Username + Convert.ToChar(9) + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + Convert.ToChar(9) + UserInputFilter.FilterString(ItemFlags.Trim(), true); break; default: ItemFlags = string.Empty; break; } } if (TotalCreditCost > 0) { Session.CharacterInfo.UpdateCreditsBalance(MySqlClient, -TotalCreditCost); Session.SendData(CreditsBalanceComposer.Compose(Session.CharacterInfo.CreditsBalance)); } if (TotalApCost > 0) { Session.CharacterInfo.UpdateActivityPointsBalance(MySqlClient, -TotalApCost); Session.SendData(ActivityPointsBalanceComposer.Compose(Session.CharacterInfo.ActivityPointsBalance, -TotalApCost)); } Dictionary <int, List <uint> > NewItems = new Dictionary <int, List <uint> >(); for (int i = 0; i < Item.Amount; i++) { switch (Item.Definition.Type) { default: List <Item> GeneratedGenericItems = new List <Item>(); double ExpireTimestamp = 0; if (Item.Definition.Behavior == ItemBehavior.Rental) { ExpireTimestamp = UnixTimestamp.GetCurrent() + 3600; } GeneratedGenericItems.Add(ItemFactory.CreateItem(MySqlClient, Item.DefinitionId, Session.CharacterId, ItemFlags, ItemFlags, ExpireTimestamp)); switch (Item.Definition.Behavior) { case ItemBehavior.Teleporter: Item LinkedItem = ItemFactory.CreateItem(MySqlClient, Item.DefinitionId, Session.CharacterId, GeneratedGenericItems[0].Id.ToString(), string.Empty, ExpireTimestamp); GeneratedGenericItems[0].Flags = LinkedItem.Id.ToString(); GeneratedGenericItems[0].SynchronizeDatabase(MySqlClient, true); GeneratedGenericItems.Add(LinkedItem); break; } foreach (Item GeneratedItem in GeneratedGenericItems) { Session.InventoryCache.Add(GeneratedItem); int TabId = GeneratedItem.Definition.Type == ItemType.FloorItem ? 1 : 2; if (!NewItems.ContainsKey(TabId)) { NewItems.Add(TabId, new List <uint>()); } NewItems[TabId].Add(GeneratedItem.Id); } break; case ItemType.AvatarEffect: AvatarEffect Effect = null; if (Session.AvatarEffectCache.HasEffect((int)Item.Definition.SpriteId)) { Effect = Session.AvatarEffectCache.GetEffect((int)Item.Definition.SpriteId); if (Effect != null) { Effect.AddToQuantity(); } } else { Effect = AvatarEffectFactory.CreateEffect(MySqlClient, Session.CharacterId, (int)Item.Definition.SpriteId, 3600); Session.AvatarEffectCache.Add(Effect); } if (Effect != null) { Session.SendData(UserEffectAddedComposer.Compose(Effect)); } break; case ItemType.Pet: Pet Pet = PetFactory.CreatePet(MySqlClient, Session.CharacterId, Item.Definition.BehaviorData, PetData[0], int.Parse(PetData[1]), Color.ToLower()); Session.PetInventoryCache.Add(Pet); Session.SendData(InventoryPetAddedComposer.Compose(Pet)); if (!NewItems.ContainsKey(3)) { NewItems.Add(3, new List <uint>()); } NewItems[3].Add(Pet.Id); break; } } Session.SendData(CatalogPurchaseResultComposer.Compose(Item)); Session.SendData(InventoryRefreshComposer.Compose()); foreach (KeyValuePair <int, List <uint> > NewItemData in NewItems) { foreach (uint NewItem in NewItemData.Value) { Session.NewItemsCache.MarkNewItem(MySqlClient, NewItemData.Key, NewItem); } } if (NewItems.Count > 0) { Session.SendData(InventoryNewItemsComposer.Compose(new Dictionary <int, List <uint> >(NewItems))); } } }
private static void OnPurchase(Session Session, ClientMessage Message) { int PageId = Message.PopWiredInt32(); uint ItemId = Message.PopWiredUInt32(); string Data = Message.PopString(); CatalogPage Page = CatalogManager.GetCatalogPage(PageId); if (Page == null || Page.DummyPage || !Page.Visible || (Page.RequiredRight.Length > 0 && !Session.HasRight(Page.RequiredRight))) { return; } using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { switch (Page.Template) { default: CatalogItem Item = Page.GetItem(ItemId); if (Item == null || (Item.ClubRestriction == 1 && !Session.HasRight("club_regular")) || (Item.ClubRestriction == 2 && !Session.HasRight("club_vip"))) { return; } HandlePurchase(MySqlClient, Session, Item, Data); break; case "club_buy": CatalogClubOffer Offer = CatalogManager.GetClubOffer(ItemId); if (Offer == null || (Offer.Price > 0 && Session.CharacterInfo.CreditsBalance < Offer.Price) || (int)Offer.Level < (int)Session.SubscriptionManager.SubscriptionLevel) { return; } string BasicAchievement = "ACH_BasicClub"; string VipAchievement = "ACH_VipClub"; // Extend membership and take credits Session.CharacterInfo.UpdateCreditsBalance(MySqlClient, -Offer.Price); Session.SubscriptionManager.AddOrExtend((int)Offer.Level, Offer.LengthSeconds); // Check if we need to manually award basic/vip badges bool NeedsBasicUnlock = !Session.BadgeCache.ContainsCodeWith(BasicAchievement); bool NeedsVipUnlock = !Session.BadgeCache.ContainsCodeWith(VipAchievement); // Reload the badge cache (reactivating any disabled subscription badges) Session.BadgeCache.ReloadCache(MySqlClient, Session.AchievementCache); // Calculate progress int Progress = (int)Math.Ceiling((double)(Offer.LengthDays / 31)); if (Progress <= 0) { Progress = 1; } // Progress VIP achievement if (Offer.Level >= ClubSubscriptionLevel.VipClub) { NeedsVipUnlock = !AchievementManager.ProgressUserAchievement(MySqlClient, Session, VipAchievement, Progress) && NeedsVipUnlock; } else { NeedsVipUnlock = false; } // Progress basic achievement NeedsBasicUnlock = !AchievementManager.ProgressUserAchievement(MySqlClient, Session, BasicAchievement, Progress) && NeedsBasicUnlock; // Virtually unlock the basic achievement without reward if needed if (NeedsBasicUnlock) { Achievement Achievement = AchievementManager.GetAchievement(BasicAchievement); if (Achievement != null) { UserAchievement UserAchievement = Session.AchievementCache.GetAchievementData( BasicAchievement); if (UserAchievement != null) { Session.SendData(AchievementUnlockedComposer.Compose(Achievement, UserAchievement.Level, 0, 0)); } } } // Virtually unlock the VIP achievement without reward if needed if (NeedsVipUnlock) { Achievement Achievement = AchievementManager.GetAchievement(VipAchievement); if (Achievement != null) { UserAchievement UserAchievement = Session.AchievementCache.GetAchievementData( VipAchievement); if (UserAchievement != null) { Session.SendData(AchievementUnlockedComposer.Compose(Achievement, UserAchievement.Level, 0, 0)); } } } // Disable any VIP badges if they still aren't valid if (Session.SubscriptionManager.SubscriptionLevel < ClubSubscriptionLevel.VipClub) { Session.BadgeCache.DisableSubscriptionBadge(VipAchievement); } // Synchronize equipped badges if the user has unlocked anything if (NeedsVipUnlock || NeedsBasicUnlock) { RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId); if (Instance != null) { Instance.BroadcastMessage(RoomUserBadgesComposer.Compose(Session.CharacterId, Session.BadgeCache.EquippedBadges)); } } // Clear catalog cache for user (in case of changes) CatalogManager.ClearCacheGroup(Session.CharacterId); // Send new data to client Session.SendData(CatalogPurchaseResultComposer.Compose(Offer)); Session.SendData(CreditsBalanceComposer.Compose(Session.CharacterInfo.CreditsBalance)); Session.SendData(FuseRightsListComposer.Compose(Session)); Session.SendData(SubscriptionStatusComposer.Compose(Session.SubscriptionManager, true)); //Session.SendData(ClubGiftReadyComposer.Compose(1)); break; } } }
private static bool HandleFireworks(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode) { int CurrentCharges = 0; int.TryParse(Item.Flags, out CurrentCharges); switch (Event) { case ItemEventType.InstanceLoaded: case ItemEventType.Placed: case ItemEventType.Moved: case ItemEventType.UpdateTick: string DesiredDisplayFlags = "0"; if (CurrentCharges > 0) { DesiredDisplayFlags = "1"; } if (Item.DisplayFlags != DesiredDisplayFlags) { Item.DisplayFlags = DesiredDisplayFlags; Item.BroadcastStateUpdate(Instance); } break; case ItemEventType.Interact: RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId); if (Actor == null) { return(true); } if (Distance.Calculate(Actor.Position.GetVector2(), Item.RoomPosition.GetVector2()) > 1) { Actor.MoveToItemAndInteract(Item, RequestData, Opcode, Item.SquareBehind); return(true); } switch (RequestData) { // Purchase charges case 2: if (Session.CharacterInfo.CreditsBalance < CHARGE_COSTS_CREDITS) { return(true); } if (Session.CharacterInfo.ActivityPointsBalance < CHARGE_COSTS_PIXELS) { return(true); } bool Update = (CurrentCharges <= 0); CurrentCharges += CHARGE_AMOUNT; Item.Flags = CurrentCharges.ToString(); using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { if (CHARGE_COSTS_CREDITS > 0) { Session.CharacterInfo.UpdateCreditsBalance(MySqlClient, -CHARGE_COSTS_CREDITS); Session.SendData(CreditsBalanceComposer.Compose(Session.CharacterInfo.CreditsBalance)); } if (CHARGE_COSTS_PIXELS > 0) { Session.CharacterInfo.UpdateActivityPointsBalance(MySqlClient, -CHARGE_COSTS_PIXELS); Session.SendData(ActivityPointsBalanceComposer.Compose(Session.CharacterInfo.ActivityPointsBalance, -CHARGE_COSTS_PIXELS)); } Item.SynchronizeDatabase(MySqlClient, true); } Session.SendData(FireworksChargeInfoComposer.Compose(Item.Id, CurrentCharges, CHARGE_COSTS_CREDITS, CHARGE_COSTS_PIXELS, CHARGE_AMOUNT)); if (Update) { Item.DisplayFlags = "1"; Item.BroadcastStateUpdate(Instance); } break; case 1: Session.SendData(FireworksChargeInfoComposer.Compose(Item.Id, CurrentCharges, CHARGE_COSTS_CREDITS, CHARGE_COSTS_PIXELS, CHARGE_AMOUNT)); break; default: case 0: if (Item.DisplayFlags == "2") { return(true); } if (CurrentCharges > 0) { Item.DisplayFlags = "2"; Item.BroadcastStateUpdate(Instance); Item.Flags = (--CurrentCharges).ToString(); RoomManager.MarkWriteback(Item, true); Item.RequestUpdate(Item.Definition.BehaviorData); } else { goto case 1; } break; } break; } return(true); }
public static bool HandleCommand(Session Session, string Input) { Input = Input.Substring(1, Input.Length - 1); string[] Bits = Input.Split(' '); RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId); RoomActor Actor = (Instance == null ? null : Instance.GetActorByReferenceId(Session.CharacterId)); Session TargetSession = null; RoomActor TargetActor = null; String TargetName = ""; switch (Bits[0].ToLower()) { #region users #region misc case "commands": { Session.SendData(NotificationMessageComposer.Compose(Localization.GetValue("command.commands.info") + ":\n\n:commands\n:online\n:about\n:pickall")); return(true); } case "online": { List <string> OnlineUsers = SessionManager.ConnectedUserData.Values.ToList(); StringBuilder MessageText = new StringBuilder(Localization.GetValue("command.online", OnlineUsers.Count.ToString()) + "\n"); foreach (string OnlineUser in OnlineUsers) { MessageText.Append('\n'); MessageText.Append("- " + OnlineUser); } Session.SendData(NotificationMessageComposer.Compose(MessageText.ToString())); return(true); } case "about": Session.SendData(UserAlertModernComposer.Compose("Powered by Snowlight", "This hotel is proudly powered by Snowlight,\nedited by flx5. \nCredits to Meth0d.")); return(true); #endregion #region furni case "empty": case "emptyinv": if (Bits.Length > 2) { return(false); } if (!Session.HasRight("hotel_admin") && Bits.Length == 2) { return(false); } Session Targetuser = Session; if (Bits.Length == 2) { uint userid = CharacterResolverCache.GetUidFromName(Bits[1]); Targetuser = SessionManager.GetSessionByCharacterId(userid); } Targetuser.PetInventoryCache.ClearAndDeleteAll(); Targetuser.InventoryCache.ClearAndDeleteAll(); Targetuser.SendData(InventoryRefreshComposer.Compose()); Targetuser.SendData(NotificationMessageComposer.Compose(Localization.GetValue("command.emptyinv.sucess"))); return(true); case "pickall": if (!Instance.CheckUserRights(Session, true)) { Session.SendData(NotificationMessageComposer.Compose(Localization.GetValue("command.pickall.error"))); return(true); } Instance.PickAllToUserInventory(Session); return(true); #endregion #region extra case "moonwalk": if (!Session.CharacterInfo.IsPremium) { return(false); } Actor.WalkingBackwards = !Actor.WalkingBackwards; Actor.Dance(Actor.WalkingBackwards ? 4 : 0); Session.SendData(RoomChatComposer.Compose(Actor.Id, "TEST " + Actor.WalkingBackwards, 0, ChatType.Whisper)); return(true); #region push case "push": if (!Session.CharacterInfo.IsPremium || Bits.Length != 2) { return(false); } TargetName = UserInputFilter.FilterString(Bits[1].Trim()); TargetActor = Instance.GetActorByReferenceId(CharacterResolverCache.GetUidFromName(TargetName)); if (TargetActor == null || TargetActor.IsMoving) { return(false); } if ((TargetActor.Position.X == Actor.Position.X - 1) || (TargetActor.Position.X == Actor.Position.X + 1) || (TargetActor.Position.Y == Actor.Position.Y - 1) || (TargetActor.Position.Y == Actor.Position.Y + 1)) { Vector2 Newposition = null; if (TargetActor.Position.X == Actor.Position.X - 1 && TargetActor.Position.Y == Actor.Position.Y) { Newposition = new Vector2(TargetActor.Position.X - 1, TargetActor.Position.Y); } if (TargetActor.Position.X == Actor.Position.X + 1 && TargetActor.Position.Y == Actor.Position.Y) { Newposition = new Vector2(TargetActor.Position.X + 1, TargetActor.Position.Y); } if (TargetActor.Position.X == Actor.Position.X && TargetActor.Position.Y == Actor.Position.Y + 1) { Newposition = new Vector2(TargetActor.Position.X, TargetActor.Position.Y + 1); } if (TargetActor.Position.X == Actor.Position.X && TargetActor.Position.Y == Actor.Position.Y - 1) { Newposition = new Vector2(TargetActor.Position.X, TargetActor.Position.Y - 1); } if (TargetActor.Position.X == Actor.Position.X + 1 && TargetActor.Position.Y == Actor.Position.Y + 1) { Newposition = new Vector2(TargetActor.Position.X + 1, TargetActor.Position.Y + 1); } if (TargetActor.Position.X == Actor.Position.X - 1 && TargetActor.Position.Y == Actor.Position.Y - 1) { Newposition = new Vector2(TargetActor.Position.X - 1, TargetActor.Position.Y - 1); } if (TargetActor.Position.X == Actor.Position.X - 1 && TargetActor.Position.Y == Actor.Position.Y + 1) { Newposition = new Vector2(TargetActor.Position.X - 1, TargetActor.Position.Y + 1); } if (TargetActor.Position.X == Actor.Position.X + 1 && TargetActor.Position.Y == Actor.Position.Y - 1) { Newposition = new Vector2(TargetActor.Position.X + 1, TargetActor.Position.Y - 1); } if (Newposition == null || !Instance.IsValidPosition(Newposition) || (Instance.Model.DoorPosition.GetVector2().X == Newposition.X && Instance.Model.DoorPosition.GetVector2().Y == Newposition.Y)) { return(false); } TargetActor.MoveTo(Newposition); Actor.Chat("*" + Session.CharacterInfo.Username + " pushes " + Bits[1] + "*"); return(true); } else { Session.SendData(RoomChatComposer.Compose(Actor.Id, Bits[1] + " is not in your area.", 0, ChatType.Whisper)); return(false); } #endregion case "pull": if (!Session.CharacterInfo.IsPremium || Bits.Length != 2) { return(false); } TargetName = UserInputFilter.FilterString(Bits[1].Trim()); TargetActor = Instance.GetActorByReferenceId(CharacterResolverCache.GetUidFromName(TargetName)); if (TargetActor == null || TargetActor.IsMoving) { return(false); } if ((TargetActor.Position.X > Actor.Position.X - 10) && (TargetActor.Position.X < Actor.Position.X + 10) && (TargetActor.Position.Y > Actor.Position.Y - 10) && (TargetActor.Position.Y < Actor.Position.Y + 10) && (Instance.Model.DoorPosition.GetVector2().X == Actor.SquareInFront.X && Instance.Model.DoorPosition.GetVector2().Y == Actor.SquareInFront.Y)) { TargetActor.MoveTo(Actor.SquareInFront); Actor.Chat("*" + Session.CharacterInfo.Username + " pulls " + Bits[1] + "*"); return(true); } Session.SendData(RoomChatComposer.Compose(Actor.Id, Bits[1] + " is not in your area.", 0, ChatType.Whisper)); return(false); #endregion #endregion #region debugging #region items case "update_catalog": { if (!Session.HasRight("hotel_admin")) { return(false); } using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { Snowlight.Game.Catalog.CatalogManager.RefreshCatalogData(MySqlClient); } Session.SendData(NotificationMessageComposer.Compose(Localization.GetValue("command.updatecatalog.success"))); return(true); } case "update_items": { if (!Session.HasRight("hotel_admin")) { return(false); } using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { Snowlight.Game.Items.ItemDefinitionManager.Initialize(MySqlClient); } Session.SendData(NotificationMessageComposer.Compose("Items reloaded")); return(true); } #endregion #region rooms case "unload": if (!Session.HasRight("hotel_admin")) { return(false); } Instance.BroadcastMessage(NotificationMessageComposer.Compose("This room was unloaded!")); Instance.Unload(); return(true); case "t": if (!Session.HasRight("hotel_admin")) { return(false); } Session.SendData(NotificationMessageComposer.Compose("Position: " + Actor.Position.ToString() + ", Rotation: " + Actor.BodyRotation)); return(true); #endregion case "update_rights": if (!Session.HasRight("hotel_admin")) { return(false); } using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { RightsManager.RebuildCache(MySqlClient); } return(true); case "effect": if (!Session.HasRight("hotel_admin")) { return(false); } if (Bits.Length < 1) { Session.SendData(RoomChatComposer.Compose(Actor.Id, "Invalid syntax - :effect <id>", 0, ChatType.Whisper)); return(true); } int effectID; if (int.TryParse(Bits[1], out effectID)) { Actor.ApplyEffect(effectID); Session.CurrentEffect = 0; } else { Session.SendData(RoomChatComposer.Compose(Actor.Id, "Invalid syntax - :effect <id>", 0, ChatType.Whisper)); } return(true); case "clipping": if (!Session.HasRight("hotel_admin")) { return(false); } Actor.OverrideClipping = !Actor.OverrideClipping; Actor.ApplyEffect(Actor.ClippingEnabled ? 0 : 23); Session.CurrentEffect = 0; return(true); #endregion #region moderation #region kick case "superkick": // Kick User out of the Hotel { if (!Session.HasRight("hotel_admin")) { return(false); } if (Bits.Length < 2) { Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.invalidsyntax") + " - :kick <username>", 0, ChatType.Whisper)); return(true); } TargetName = UserInputFilter.FilterString(Bits[1].Trim()); TargetSession = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(TargetName)); if (TargetSession == null || TargetSession.HasRight("moderation_tool") || !TargetSession.InRoom) { Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.targetuser") + " '" + TargetName + "' is offline or cannot be kicked.", 0, ChatType.Whisper)); return(true); } SessionManager.StopSession(TargetSession.Id); using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { ModerationLogs.LogModerationAction(MySqlClient, Session, "Superkicked user from server (chat command)", "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ")."); } return(true); } case "kick": //kick User out of Room { if (!Session.HasRight("moderation_tool")) { return(false); } if (Bits.Length < 2) { Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.invalidsyntax") + " - :kick <username>", 0, ChatType.Whisper)); return(true); } TargetName = UserInputFilter.FilterString(Bits[1].Trim()); TargetSession = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(TargetName)); if (TargetSession == null || TargetSession.HasRight("moderation_tool") || !TargetSession.InRoom) { Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.targetuser") + " '" + TargetName + "' is offline, not in a room, or cannot be kicked.", 0, ChatType.Whisper)); return(true); } RoomManager.RemoveUserFromRoom(TargetSession, true); TargetSession.SendData(NotificationMessageComposer.Compose(Localization.GetValue("command.kick.success"))); using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { ModerationLogs.LogModerationAction(MySqlClient, Session, "Kicked user from room (chat command)", "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ")."); } return(true); } #endregion #region mute case "roomunmute": { if (!Session.HasRight("mute")) { return(false); } if (Instance.RoomMuted) { Instance.RoomMuted = false; Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.roomunmute.success"), 0, ChatType.Whisper)); } else { Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.roomunmute.error"), 0, ChatType.Whisper)); } using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { ModerationLogs.LogModerationAction(MySqlClient, Session, "Unmuted room", "Room '" + Instance.Info.Name + "' (ID " + Instance.RoomId + ")"); } return(true); } case "roommute": { if (!Session.HasRight("mute")) { return(false); } if (!Instance.RoomMuted) { Instance.RoomMuted = true; Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.roommute.success"), 0, ChatType.Whisper)); } else { Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.roommute.error"), 0, ChatType.Whisper)); } using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { ModerationLogs.LogModerationAction(MySqlClient, Session, "Muted room", "Room '" + Instance.Info.Name + "' (ID " + Instance.RoomId + ")"); } return(true); } case "unmute": { if (!Session.HasRight("mute")) { return(false); } if (Bits.Length < 2) { Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.invalidsyntax") + " - :unmute <username>", 0, ChatType.Whisper)); return(true); } TargetName = UserInputFilter.FilterString(Bits[1].Trim()); TargetSession = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(TargetName)); if (TargetSession == null) { Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.targetuser") + " '" + TargetName + "' " + Localization.GetValue("command.cannotproceedcmd3"), 0, ChatType.Whisper)); return(true); } if (!TargetSession.CharacterInfo.IsMuted) { Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.targetuser") + " '" + TargetName + "' " + Localization.GetValue("command.unmute.error"), 0, ChatType.Whisper)); return(true); } using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { TargetSession.CharacterInfo.Unmute(MySqlClient); } TargetSession.SendData(NotificationMessageComposer.Compose(Localization.GetValue("command.unmute.sucess"))); Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.targetuser") + " '" + TargetName + "' " + Localization.GetValue("command.unmute.sucess2"), 0, ChatType.Whisper)); using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { ModerationLogs.LogModerationAction(MySqlClient, Session, "Unmuted user", "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ")."); } return(true); } case "mute": { if (!Session.HasRight("mute")) { return(false); } if (Bits.Length < 2) { Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.invalidsyntax") + " - :mute <username> [length in seconds]", 0, ChatType.Whisper)); return(true); } TargetName = UserInputFilter.FilterString(Bits[1].Trim()); int TimeToMute = 0; if (Bits.Length >= 3) { int.TryParse(Bits[2], out TimeToMute); } if (TimeToMute <= 0) { TimeToMute = 300; } if (TimeToMute > 3600) { Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.mute.error"), 0, ChatType.Whisper)); return(true); } TargetSession = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(TargetName)); if (TargetSession == null || TargetSession.HasRight("mute")) { Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.targetuser") + " '" + TargetName + "' " + Localization.GetValue("command.cannotproceedcmd4"), 0, ChatType.Whisper)); return(true); } using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { TargetSession.CharacterInfo.Mute(MySqlClient, TimeToMute); ModerationLogs.LogModerationAction(MySqlClient, Session, "Muted user", "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ") for " + TimeToMute + " seconds."); } TargetSession.SendData(RoomMutedComposer.Compose(TimeToMute)); Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.mute.sucess.part1") + " '" + TargetName + "' " + Localization.GetValue("command.mute.sucess.part2") + " " + TimeToMute + " seconds.", 0, ChatType.Whisper)); return(true); } #endregion #region credits case "coins": case "credits": using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { if (!Session.HasRight("hotel_admin")) { return(false); } if (Bits.Length < 2) { Session.SendData(RoomChatComposer.Compose(Actor.Id, "Invalid syntax - :" + Bits[0].ToLower() + " <user> <amount>", 0, ChatType.Whisper)); return(false); } int Valor; if (!Int32.TryParse(Bits[2], out Valor)) { Session.SendData(RoomChatComposer.Compose(Actor.Id, "Amount must be numeric!", 0, ChatType.Whisper)); return(false); } TargetName = UserInputFilter.FilterString(Bits[1].Trim()); uint UserID = CharacterResolverCache.GetUidFromName(TargetName); if (UserID == 0) { Session.SendData(RoomChatComposer.Compose(Actor.Id, "User not found!", 0, ChatType.Whisper)); return(false); } Session TargetUser = SessionManager.GetSessionByCharacterId(UserID); if (TargetUser == null) { Session.SendData(RoomChatComposer.Compose(Actor.Id, "User not online!", 0, ChatType.Whisper)); return(false); } TargetUser.CharacterInfo.UpdateCreditsBalance(MySqlClient, (int)Valor); TargetUser.SendData(RoomChatComposer.Compose(TargetUser.Id, "You received " + Valor + " coins!", 0, ChatType.Whisper)); Session.SendData(RoomChatComposer.Compose(Actor.Id, TargetName + " received " + Valor + " coins!", 0, ChatType.Whisper)); TargetUser.SendData(CreditsBalanceComposer.Compose(TargetUser.CharacterInfo.CreditsBalance)); return(true); } #endregion #region messages case "ha": { if (!Session.HasRight("hotel_admin")) { return(false); } string Alert = UserInputFilter.FilterString(MergeInputs(Bits, 1)); SessionManager.BroadcastPacket(UserAlertModernComposer.Compose("Important notice from Hotel Management", Alert)); return(true); } #endregion #endregion } return(false); }
private static void GetBalance(Session Session, ClientMessage Message) { Session.SendData(CreditsBalanceComposer.Compose(Session.CharacterInfo.CreditsBalance)); Session.SendData(ActivityPointsBalanceComposer.Compose(Session.CharacterInfo.ActivityPointsBalance, 0)); }