ulvis.paste.net

Paste Search Dynamic
Recent pastes
CameraPurchaseEvent.cs
  1. using CameraAPI;
  2. using Plus.Communication.Packets.Outgoing.Inventory.Furni;
  3. using Plus.Communication.Packets.Outgoing.Inventory.Purse;
  4. using Plus.Communication.Packets.Outgoing.Rooms.Camera;
  5. using Plus.Communication.Packets.Outgoing.Rooms.Notifications;
  6. using Plus.Database.Interfaces;
  7. using Plus.HabboHotel.GameClients;
  8. using Plus.HabboHotel.Items;
  9. using Plus.Utilities;
  10. using System;
  11.  
  12. namespace Plus.Communication.Packets.Incoming.Rooms.Camera
  13. {
  14.     class CameraPurchaseEvent : IPacketEvent
  15.     {
  16.         public void Parse(GameClient Session, ClientPacket Packet)
  17.         {
  18.             String photoUrl = PlusEnvironment.GetGame().GetCameraManager().GetPhotoForHabbo(Session.GetHabbo());
  19.             if (String.IsNullOrEmpty(photoUrl))
  20.                 return;
  21.  
  22.             if (Session.GetHabbo().Duckets < 1)
  23.             {
  24.                 Session.SendPacket(new RoomNotificationComposer("camera", "errors", "${catalog.alert.notenough.activitypoints.description.0}"));
  25.                 return;
  26.             }
  27.  
  28.             string roomId = photoUrl.Split('-')[0];
  29.             string timestamp = photoUrl.Split('-')[1];
  30.  
  31.             int posterId = 777954881;
  32.             Int32.TryParse(CameraUtils.Value("camera.poster.id"), out posterId);
  33.  
  34.             if (!PlusEnvironment.GetGame().GetItemManager().GetItem(posterId, out ItemData Item))
  35.                 return;
  36.             if (Item == null)
  37.                 return;
  38.  
  39.             int photoId;
  40.             using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  41.             {
  42.                 dbClient.SetQuery("INSERT INTO `camera_photos` (creator_id, creator_name, file_name, reports, deleted, ip_address, created_at) VALUES (@uid,@name,@fileName,@reports,@deleted,@ip_address,@created_at)");
  43.                 dbClient.AddParameter("uid", Session.GetHabbo().Id);
  44.                 dbClient.AddParameter("name", Session.GetHabbo().Username);
  45.                 dbClient.AddParameter("fileName", photoUrl);
  46.                 dbClient.AddParameter("reports", 0);
  47.                 dbClient.AddParameter("deleted", "0");
  48.                 dbClient.AddParameter("ip_address", Session.GetConnection().GetIp());
  49.                 dbClient.AddParameter("created_at", timestamp);
  50.                 photoId = Convert.ToInt32(dbClient.InsertQuery());
  51.             }
  52.  
  53.             Item photoPoster = ItemFactory.CreateSingleItemNullable(Item, Session.GetHabbo(), "{\"w\":\"" + StringCharFilter.EscapeJSONString(photoUrl) + "\", \"n\":\"" + StringCharFilter.EscapeJSONString(Session.GetHabbo().Username) + "\", \"s\":\"" + Session.GetHabbo().Id + "\", \"u\":\"" + photoId + "\", \"t\":\"" + timestamp + "\"}", "");
  54.  
  55.             if (photoPoster != null)
  56.             {
  57.                 Session.GetHabbo().GetInventoryComponent().TryAddItem(photoPoster);
  58.  
  59.                 Session.SendPacket(new FurniListAddComposer(photoPoster));
  60.                 Session.SendPacket(new FurniListUpdateComposer());
  61.                 Session.SendPacket(new FurniListNotificationComposer(photoPoster.Id, 1));
  62.                 Session.GetHabbo().Duckets--;
  63.                 Session.SendPacket(new HabboActivityPointNotificationComposer(Session.GetHabbo().Duckets, -1));
  64.  
  65.                 PlusEnvironment.GetGame().GetAchievementManager().ProgressAchievement(Session, "ACH_CameraPhotoCount", 1);
  66.             }
  67.  
  68.             Session.SendPacket(new CameraPurchaseSuccesfullComposer());
  69.  
  70.             Session.GetHabbo().GetInventoryComponent().UpdateItems(false);
  71.  
  72.            
  73.         }
  74.     }
  75. }
Parsed in 0.009 seconds