Jump to content

1 Screenshot

  • 2k
  • 50
  • 49.31 kB
 Share

About Image Manager

Image Manager is a sleek and powerful tool for developers, offering a lightweight alternative to ImageLibrary.
Its unique handling and plugin-specific callbacks make it exceptionally easy to use.

Console Command:

imagemanager.reset // can only be ran from server console/terminal I don't allow use client side.



Features:

Error Handling:
Outputs special debug info for devs when something fails.
It's able to self repair when the server sv.files have been deleted but a wipe hasn't occurred or vice versa.
Stores images with unique identifiers to ensure reliable retrieval/removal.
If unity request fails retries with www instead.

Optimized Request Management:

Utilizes batch processing to handle image caching requests efficiently.

Auto Remove Data that isn't used past x Days: Default = 30, 0 = disabled.

Sets batch limits on Images: Default = 30 & Avatars can do 100 at a time per request using steam API key.

Keeps Previous Wipe Data thus reducing the need to redo everything each wipe.

Groups requests into batches to optimize resource use and reduce overhead.

Manages large volumes of connections without sacrificing performance.

Handles high volumes of image caching requests during server wipes or mass player reconnections.

Processes and caches avatar images quickly with coroutine-based execution.

Manages concurrent requests from multiple plugins simultaneously without conflicts or slowdowns.

Maintains responsiveness and efficiency in dynamic server environments.

Plugin Communication:
In addition to its core functionality, the system includes special logic to facilitate communication between plugins.
Each plugin calling the image caching system is notified when its batch of requests is ready or finished, allowing it to proceed with its logic without waiting for all requests to complete.
This feature enhances the flexibility and usability of the system, ensuring smooth integration with various plugins and workflows.

Plugin Communication Example For Images:

        // Plugin Calls!? Whaaa.. :P This works with all Adding hook calls in this plugin.

        // Example plugin: GUIShop
        [PluginReference] private Plugin ImageManager;
        private List<string> _pluginImages = new List<string>();
        private Dictionary<string, string> _guishopImages = new Dictionary<string, string>();

        private void OnServerInitialized()
        {
            // This will add the images to the filesystem list for the callback
            if (ImageManager != null && ImageManager.IsLoaded)
                ImageManager?.Call("AddImages", _pluginImages, FileStorage.Type.jpg, "GUIShop");
        }

        // why do we need this!? OnPluginLoaded for reload situations, or when plugin wasn't loaded yet.
        private void OnPluginLoaded(Plugin name)
        {
            if (ImageManager != null && name.Name == ImageManager.Name & ImageManager.IsLoaded)
            {
                Puts("ImageManager has been detected and GUIShop Images are now being Processed");
                // This will add the images to the filesystem list for the callback
                ImageManager?.Call("AddImages", _pluginImages, FileStorage.Type.jpg, "GUIShop");
            }
        }

        // this would be your custom call-back ( Why use this!? Because it can actually be faster so you can continue your code logic quicker )
        void ImageManagerGUIShop(Dictionary<string, string> images)
        {
            _guishopImages = images;
            // this returns the sent URL as the KEY with the image as the value.
        }

        // now down in your GUI / UI you can do this ( same for avatars except the key is ulong )
        public void Pic(ref CuiElementContainer container, string parent, string name, string anchorMin, string anchorMax, string url)
        {
            CuiRawImageComponent rawImage = new CuiRawImageComponent();

            rawImage.Png = _guishopImages[url];

            container.Add(new CuiElement
            {
                Parent = parent,
                Name = name,
                Components =
                {
                    rawImage,
                    new CuiRectTransformComponent
                    {
                        AnchorMin = anchorMin,
                        AnchorMax = anchorMax
                    }
                }
            });
        }


Plugin Communication Example for Avatars / Image Combo:

private HashSet<string> _storeImages = new HashSet<string>();
private Dictionary<string, string> _storedImages = new Dictionary<string, string>();
private Dictionary<string, string> _storedAvatars = new Dictionary<string, string>();

private void OnServerInitialized()
{
  ImageManager?.Call("AddImages", _storeImages.ToList(), FileStorage.Type.jpg, "GUIShop");
}

private void OnPluginLoaded(Plugin name)
{
  if (ImageManager != null && name.Name == ImageManager.Name)
  {
      Puts("ImageManager has been detected and Images are now being Processed");
      ImageManager?.Call("AddImages", _storeImages.ToList(), FileStorage.Type.jpg, "GUIShop"); // plugin name "GUIShop"
  }
}

// your special made hook to listen for on your image request.
private void ImageManagerRustID(Dictionary<string, string> received)
{
// you can filter which ones you want when you get the list back. example.
    foreach (var image in received)
    {
        if (_storeImages.Contains(image.Key))
        {
            _storedImages[image.Key] = image.Value;
            _storeImages.Remove(image.Key);
            if (_storeImages.Count == 0)
                break;
        }
    }
}

// called when new avatars get cached so you can update as needed.
void ImageManagerPlayerConnected(Dictionary<string, string> avatars) => _storedAvatars = avatars;

// use for your gui example
CuiRawImageComponent rawImage = new CuiRawImageComponent();
rawImage.Png = _storedAvatars[id]; //or call each time if you prefer.. (string)ImageManager?.Call("GetAvatar", id);
// or image rawImage.Png = _storedImages[key]
container.Add(new CuiElement
{
    Parent = parent,
    Name = name,
    Components =
    {
        rawImage,
        new CuiRectTransformComponent
        {
            AnchorMin = anchorMin,
            AnchorMax = anchorMax
        }
    }
});



API Hooks:
 

        // Avatars

        // Called when the plugin has initially loaded / compiled & finished/ready for use.
        void ImageManagerLoadedAvatars(Dictionary<string, string> avatars)

        // Triggered when new players connect with no stored pic yet. ( Is only called once finished storing in the event of multiple or mass player connections their Queued )
        void ImageManagerPlayerConnected(Dictionary<string, string> avatars)

        // Triggered by 3rd party plugins doing stuff + PlayerConnected.
        void ImageManagerAdded(Dictionary<string, string> avatars)

        // called when avatars have been removed & returns the new full avatar list available.
        void ImageManagerRemoved(Dictionary<string, string> avatars)

        // Images

        // Called when the plugin has initially loaded / compiled & finished/ready for use.
        void ImageManagerLoadedImages(Dictionary<string, string> images)

        // Triggered by 3rd party plugins doing stuff.
        void ImageManagerAdded(Dictionary<string, string> images)

        // called when avatars have been removed & returns the new full avatar list available.
        void ImageManagerRemoved(Dictionary<string, string> images)

 

API Calls:

 

These are API CALLS which means you call them..

ImageManager?.Call("AddImages", _pluginImages, FileStorage.Type.jpg, "GUIShop"); // Example

// new hook use this to specify individual image storage types.
AddImages(Dictionary<string, FileStorage.Type> images, string plugin)

// hook changed.
AddImages(List<string> images, FileStorage.Type format, string plugin)

// hook changed. Use this to specify 1 storage type for all images to save as.
AddImage(string image, FileStorage.Type format, string plugin)

GetImage(string image) // returns string
GetImages(List<string> images) // returns Dictionary<string, string>

RemoveImage(string image)
RemoveImages(List<string> images)


AddAvatar(ulong player, string url, string plugin) // url is optional if you want to provide custom image for player.
AddAvatar(string player, string url, string plugin) // url is optional if you want to provide custom image for player.
AddAvatars(Dictionary<string, string> players, string plugin) // url is optional if you want to provide custom image for player.

GetAvatar(string player) // returns string
GetAvatars(List<string> players) // returns Dictionary<string, string>

RemoveAvatar(string player)
RemoveAvatars(List<string> players)


TODO:

Add MYSQL Support to have 1 database available instead of each server instance.
Add Discord support for Error Responses.

  • Love 1

User Feedback

1.2m

Downloads

Total number of downloads.

6k

Customers

Total customers served.

87.3k

Files Sold

Total number of files sold.

1.7m

Payments Processed

Total payments processed.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.