Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] Implement Zone Sidecar #3635

Merged
merged 18 commits into from Oct 24, 2023
Merged

[API] Implement Zone Sidecar #3635

merged 18 commits into from Oct 24, 2023

Conversation

Akkadius
Copy link
Member

This PR implements what I call "zone sidecar". It's purpose is to serve as a local (not exposed to the outside world) web API to answer questions only the zone process can reliably answer. It does not serve player traffic, does not start a port as a zone. It starts a "shell" of a zone and boots up the bare minimum so it can answer simple questions.

Initial Use Cases

Loot simulation of drop rates

To display in an editor to show a user how many times items actually drop out of 100 deaths/drops of an NPC GET /api/v1/loot-simulate

Example Request

This will simulate loot 100x iterations on NPC (Lord Nagafen) using Lord Nagafen's loot table

curl -s http://localhost:9099/api/v1/loot-simulate?loottable_id=4027&npc_id=32040

Response

{
  "data": {
    "iterations": 100,
    "loottable_id": 4027,
    "npc_id": 32040,
    "npc_name": "Lord Nagafen",
    "rolled_items_count": 687,
    "time": 0.003345852
  },
  "lootdrops": [
    {
      "droplimit": 4,
      "drops": [
        {
          "chance": "12.00",
          "item_id": 11621,
          "item_name": "Cloak of Flames",
          "simulate_rolled_count": 34,
          "simulate_rolled_percentage": "34.00",
          "slot": 0
        },
        {
          "chance": "14.00",
          "item_id": 11622,
          "item_name": "Red Dragon Scales",
          "simulate_rolled_count": 36,
          "simulate_rolled_percentage": "36.00",
          "slot": 1
        },
        {
          "chance": "12.00",
          "item_id": 11624,
          "item_name": "Gauntlets of Fiery Might",
          "simulate_rolled_count": 35,
          "simulate_rolled_percentage": "35.00",
          "slot": 2
        },
        {
          "chance": "12.00",
          "item_id": 11625,
          "item_name": "Orb of Tishan",
          "simulate_rolled_count": 22,
          "simulate_rolled_percentage": "22.00",
          "slot": 3
        },
        {
          "chance": "12.00",
          "item_id": 11626,
          "item_name": "Selo`s Drums of the March",
          "simulate_rolled_count": 45,
          "simulate_rolled_percentage": "45.00",
          "slot": 4
        },
        {
          "chance": "13.00",
          "item_id": 11628,
          "item_name": "Blight, Hammer of the Scourge",
          "simulate_rolled_count": 41,
          "simulate_rolled_percentage": "41.00",
          "slot": 5
        },
        {
          "chance": "13.00",
          "item_id": 11629,
          "item_name": "Hierophant`s Crook",
          "simulate_rolled_count": 43,
          "simulate_rolled_percentage": "43.00",
          "slot": 6
        },
        {
          "chance": "13.00",
          "item_id": 11630,
          "item_name": "Gold Plated Koshigatana",
          "simulate_rolled_count": 45,
          "simulate_rolled_percentage": "45.00",
          "slot": 7
        },
        {
          "chance": "14.00",
          "item_id": 11631,
          "item_name": "Prayers of Life",
          "simulate_rolled_count": 42,
          "simulate_rolled_percentage": "42.00",
          "slot": 8
        },
        {
          "chance": "13.00",
          "item_id": 11632,
          "item_name": "Bladestopper",
          "simulate_rolled_count": 36,
          "simulate_rolled_percentage": "36.00",
          "slot": 9
        },
        {
          "chance": "15.00",
          "item_id": 17702,
          "item_name": "Treasure Hunter`s Satchel",
          "simulate_rolled_count": 48,
          "simulate_rolled_percentage": "48.00",
          "slot": 10
        },
        {
          "chance": "15.00",
          "item_id": 19071,
          "item_name": "Torn, Burnt Book",
          "simulate_rolled_count": 60,
          "simulate_rolled_percentage": "60.00",
          "slot": 11
        }
      ],
      "lootdrop_id": 7725,
      "mindrop": 4,
      "multiplier": 1,
      "probability": 100
    },
    {
      "droplimit": 2,
      "drops": [
        {
          "chance": "20.00",
          "item_id": 10036,
          "item_name": "Black Sapphire",
          "simulate_rolled_count": 58,
          "simulate_rolled_percentage": "58.00",
          "slot": 0
        },
        {
          "chance": "20.00",
          "item_id": 10051,
          "item_name": "Ruby Crown",
          "simulate_rolled_count": 52,
          "simulate_rolled_percentage": "52.00",
          "slot": 1
        },
        {
          "chance": "1.00",
          "item_id": 11880,
          "item_name": "Rune of Frost",
          "simulate_rolled_count": 2,
          "simulate_rolled_percentage": "2.00",
          "slot": 2
        },
        {
          "chance": "1.00",
          "item_id": 11881,
          "item_name": "Rune of the Astral",
          "simulate_rolled_count": 4,
          "simulate_rolled_percentage": "4.00",
          "slot": 3
        },
        {
          "chance": "10.00",
          "item_id": 16976,
          "item_name": "Crystallized Sulfur",
          "simulate_rolled_count": 21,
          "simulate_rolled_percentage": "21.00",
          "slot": 4
        },
        {
          "chance": "20.00",
          "item_id": 22503,
          "item_name": "Blue Diamond",
          "simulate_rolled_count": 63,
          "simulate_rolled_percentage": "63.00",
          "slot": 5
        }
      ],
      "lootdrop_id": 7726,
      "mindrop": 2,
      "multiplier": 1,
      "probability": 100
    },
    {
      "droplimit": 1,
      "drops": [
        {
          "chance": "12.00",
          "item_id": 11621,
          "item_name": "Cloak of Flames",
          "simulate_rolled_count": 34,
          "simulate_rolled_percentage": "34.00",
          "slot": 0
        },
        {
          "chance": "14.00",
          "item_id": 11622,
          "item_name": "Red Dragon Scales",
          "simulate_rolled_count": 36,
          "simulate_rolled_percentage": "36.00",
          "slot": 1
        },
        {
          "chance": "12.00",
          "item_id": 11624,
          "item_name": "Gauntlets of Fiery Might",
          "simulate_rolled_count": 35,
          "simulate_rolled_percentage": "35.00",
          "slot": 2
        },
        {
          "chance": "12.00",
          "item_id": 11625,
          "item_name": "Orb of Tishan",
          "simulate_rolled_count": 22,
          "simulate_rolled_percentage": "22.00",
          "slot": 3
        },
        {
          "chance": "12.00",
          "item_id": 11626,
          "item_name": "Selo`s Drums of the March",
          "simulate_rolled_count": 45,
          "simulate_rolled_percentage": "45.00",
          "slot": 4
        },
        {
          "chance": "13.00",
          "item_id": 11628,
          "item_name": "Blight, Hammer of the Scourge",
          "simulate_rolled_count": 41,
          "simulate_rolled_percentage": "41.00",
          "slot": 5
        },
        {
          "chance": "13.00",
          "item_id": 11629,
          "item_name": "Hierophant`s Crook",
          "simulate_rolled_count": 43,
          "simulate_rolled_percentage": "43.00",
          "slot": 6
        },
        {
          "chance": "13.00",
          "item_id": 11630,
          "item_name": "Gold Plated Koshigatana",
          "simulate_rolled_count": 45,
          "simulate_rolled_percentage": "45.00",
          "slot": 7
        },
        {
          "chance": "14.00",
          "item_id": 11631,
          "item_name": "Prayers of Life",
          "simulate_rolled_count": 42,
          "simulate_rolled_percentage": "42.00",
          "slot": 8
        },
        {
          "chance": "13.00",
          "item_id": 11632,
          "item_name": "Bladestopper",
          "simulate_rolled_count": 36,
          "simulate_rolled_percentage": "36.00",
          "slot": 9
        },
        {
          "chance": "15.00",
          "item_id": 17702,
          "item_name": "Treasure Hunter`s Satchel",
          "simulate_rolled_count": 48,
          "simulate_rolled_percentage": "48.00",
          "slot": 10
        },
        {
          "chance": "15.00",
          "item_id": 19071,
          "item_name": "Torn, Burnt Book",
          "simulate_rolled_count": 60,
          "simulate_rolled_percentage": "60.00",
          "slot": 11
        }
      ],
      "lootdrop_id": 175041,
      "mindrop": 0,
      "multiplier": 1,
      "probability": 80
    },
    {
      "droplimit": 1,
      "drops": [
        {
          "chance": "12.00",
          "item_id": 11621,
          "item_name": "Cloak of Flames",
          "simulate_rolled_count": 34,
          "simulate_rolled_percentage": "34.00",
          "slot": 0
        },
        {
          "chance": "14.00",
          "item_id": 11622,
          "item_name": "Red Dragon Scales",
          "simulate_rolled_count": 36,
          "simulate_rolled_percentage": "36.00",
          "slot": 1
        },
        {
          "chance": "12.00",
          "item_id": 11624,
          "item_name": "Gauntlets of Fiery Might",
          "simulate_rolled_count": 35,
          "simulate_rolled_percentage": "35.00",
          "slot": 2
        },
        {
          "chance": "12.00",
          "item_id": 11625,
          "item_name": "Orb of Tishan",
          "simulate_rolled_count": 22,
          "simulate_rolled_percentage": "22.00",
          "slot": 3
        },
        {
          "chance": "12.00",
          "item_id": 11626,
          "item_name": "Selo`s Drums of the March",
          "simulate_rolled_count": 45,
          "simulate_rolled_percentage": "45.00",
          "slot": 4
        },
        {
          "chance": "13.00",
          "item_id": 11628,
          "item_name": "Blight, Hammer of the Scourge",
          "simulate_rolled_count": 41,
          "simulate_rolled_percentage": "41.00",
          "slot": 5
        },
        {
          "chance": "13.00",
          "item_id": 11629,
          "item_name": "Hierophant`s Crook",
          "simulate_rolled_count": 43,
          "simulate_rolled_percentage": "43.00",
          "slot": 6
        },
        {
          "chance": "13.00",
          "item_id": 11630,
          "item_name": "Gold Plated Koshigatana",
          "simulate_rolled_count": 45,
          "simulate_rolled_percentage": "45.00",
          "slot": 7
        },
        {
          "chance": "14.00",
          "item_id": 11631,
          "item_name": "Prayers of Life",
          "simulate_rolled_count": 42,
          "simulate_rolled_percentage": "42.00",
          "slot": 8
        },
        {
          "chance": "13.00",
          "item_id": 11632,
          "item_name": "Bladestopper",
          "simulate_rolled_count": 36,
          "simulate_rolled_percentage": "36.00",
          "slot": 9
        },
        {
          "chance": "15.00",
          "item_id": 17702,
          "item_name": "Treasure Hunter`s Satchel",
          "simulate_rolled_count": 48,
          "simulate_rolled_percentage": "48.00",
          "slot": 10
        },
        {
          "chance": "15.00",
          "item_id": 19071,
          "item_name": "Torn, Burnt Book",
          "simulate_rolled_count": 60,
          "simulate_rolled_percentage": "60.00",
          "slot": 11
        }
      ],
      "lootdrop_id": 175042,
      "mindrop": 0,
      "multiplier": 1,
      "probability": 30
    }
  ]
}

There are also plans to answer BestZ for use of placement on a 2D map editor.

Booting Sidecar

Booting is done from the brand new Zone CLI.

CLI ./bin/zone sidecar:serve-http --port=9000(optional) --key=authkey(optional)

eqemu@b51353f10adc:~/server$ ./bin/zone sidecar:serve-http
  Zone |    Info    | LoadLogDatabaseSettings Loaded [72] log categories 
  Zone |    Info    | StartFileLogs Starting File Log [logs/zone/zone_318624.log] 
  Zone |    Info    | CheckVersionsUpToDate ---------------------------------------------------------------------- 
  Zone |    Info    | CheckVersionsUpToDate   Server | database [9237] binary [9237] up to date 
  Zone |    Info    | CheckVersionsUpToDate   Config | [server.auto_database_updates] [true] 
  Zone |    Info    | CheckVersionsUpToDate ---------------------------------------------------------------------- 
  Zone |    Info    | main CURRENT_VERSION [22.28.0-dev] 
  Zone |    Info    | MapOpcodes Mapped [602] client opcode handlers 
  Zone |    Info    | LoadVariables Loaded [6] variable(s) 
  Zone |    Info    | LoadZones Loaded [604] zones 
  Zone |    Info    | LoadItems Loaded [117,934] items via shared memory 
  Zone |    Info    | LoadNPCFactionLists Loading [shared/faction] 
  Zone |    Info    | LoadNPCFactionLists Loaded faction lists via shared memory 
  Zone |    Info    | LoadFactionAssociation Loaded faction associations via shared memory 
  Zone |    Info    | LoadLoot Loaded loot tables via shared memory 
  Zone |    Info    | LoadSkillCaps Loading [shared/skill_caps] 
  Zone |    Info    | LoadSkillCaps Loaded skill caps via shared memory 
  Zone |    Info    | LoadSpells Loading [shared/spells] 
  Zone |    Info    | LoadSpells Loaded [40,722] spells via shared memory 
  Zone |    Info    | LoadBaseData Loaded base data via shared memory 
  Zone |    Info    | LoadGuilds Loaded [0] Guilds 
  Zone |    Info    | LoadFactionData Loaded [2,105] faction(s) 
  Zone |    Info    | LoadFactionData Loaded [610] faction base(s) 
  Zone |    Info    | LoadFactionData Loaded [8,802] faction modifier(s) 
  Zone |    Info    | LoadTitles Loaded [197] titles 
  Zone |    Info    | LoadTributes Loaded [52] tributes 
  Zone |    Info    | LoadTributes Loaded [225] tribute levels 
  Zone |    Info    | GetDecayTimes Loaded [0] decay timers 
  Zone |    Info    | load_database_entries Loaded [0] profanity entries 
  Zone |    Info    | main Loaded [154] commands loaded 
  Zone |    Info    | LoadRules Loaded [715] rules(s) in rule_set [default] id [1] 
  Zone |    Info    | SetExpansionContext Current expansion is [9] (Dragons of Norrath) 
  Zone |    Info    | ReloadContentFlags Loaded content flag [peq_halloween] [Disabled] 
  Zone |    Info    | LoadScaleData Loaded [270] global scaling data entries 
  Zone |    Info    | LoadPerlEventExportSettings Loaded [84] Perl Event Export Settings 
  Zone |    Info    | main Loading quests 
  Zone |    Info    | MapOpcodes Mapped [602] client opcode handlers 
ZoneSi |    Info    | BootWebserver Booting zone sidecar API 
ZoneSi |    Info    | BootWebserver Loading loot tables 
ZoneSi |    Info    | LoadLoot Loaded loot tables via shared memory 
ZoneSi |    Info    | Bootup Booting [qrg] [(3:0)] 
ZoneSi |    Info    | LoadZoneCFG Successfully loaded zone headers for zone [qrg] long_name [The Surefall Glade] version [0] instance_id [0] 
ZoneSi |    Info    | LoadMapFile Attempting to load Map File [maps/base/qrg.map] 
ZoneSi |    Info    | Load Loading V2 Map File [maps/base/qrg.map] 
ZoneSi |    Info    | Load Loaded V2 Map File [maps/base/qrg.map] 
ZoneSi |    Info    | LoadWaterMapfile Loaded Water Map [V1] file [maps/water/qrg.wtr] 
ZoneSi |    Info    | Load Loaded Navmesh [V2] file [/home/eqemu/server/maps/nav/qrg.nav] 
ZoneSi |    Info    | LoadSpawnConditions Loaded [0] spawn_conditions 
ZoneSi |    Info    | LoadSpawnConditions Loaded [0] spawn_events 
ZoneSi |    Info    | LoadStaticZonePoints Loaded [2] zone_points 
ZoneSi |    Info    | LoadSpawnGroups Loaded [51] spawn group(s) 
ZoneSi |    Info    | LoadSpawnGroups Loaded [60] spawn entries 
ZoneSi |    Info    | PopulateZoneSpawnList Loaded [7] respawn timer(s) 
ZoneSi |    Info    | PopulateZoneSpawnList Loaded [66] spawn2 entries 
ZoneSi |    Info    | LoadCharacterCorpses Loaded [0] player corpse(s) 
ZoneSi |    Info    | LoadTraps Loaded [0] trap(s) 
ZoneSi |    Info    | Init Loading adventure flavor text 
ZoneSi |    Info    | LoadAdventureFlavor Loaded [5] adventure text entries 
ZoneSi |    Info    | LoadGroundSpawns Loaded [0] ground spawns 
ZoneSi |    Info    | LoadZoneObjects Loaded [2] world objects 
ZoneSi |    Info    | LoadZoneBlockedSpells Loaded [0] blocked spells(s) 
ZoneSi |    Info    | LoadVeteranRewards Loaded [0] veteran reward(s) 
ZoneSi |    Info    | LoadAlternateCurrencies Loaded [34] alternate currencies 
ZoneSi |    Info    | LoadNPCEmotes Loaded [2,647] npc emotes 
ZoneSi |    Info    | LoadAlternateAdvancementAbilities Loaded [1,567] Alternate Advancement Abilities 
ZoneSi |    Info    | LoadAlternateAdvancementAbilities Loaded [6,652] Alternate Advancement Ability Ranks 
ZoneSi |    Info    | LoadAlternateAdvancementAbilities Loaded [9,849] Alternate Advancement Ability Rank Effects 
ZoneSi |    Info    | LoadAlternateAdvancementAbilities Loaded [2,525] Alternate Advancement Ability Rank Prereqs 
ZoneSi |    Info    | LoadGlobalLoot Loaded [1] global loot entries 
ZoneSi |    Info    | GetMerchantDataForZoneLoad Loaded [224] merchant lists 
ZoneSi |    Info    | LoadTempMerchantData Loaded [0] temporary merchant entries 
ZoneSi |    Info    | CacheAllFromDatabase Loaded [0] dynamic zone(s) 
ZoneSi |    Info    | CacheAllFromDatabase Loaded [0] expedition(s) 
ZoneSi |    Info    | Init Loading timezone data 
ZoneSi |    Info    | Init Zone booted successfully zone_id [3] time_offset [0] 
ZoneSi |    Info    | LoadGrids Loaded [18] grids and [1,819] grid_entries 
ZoneSi |    Info    | LoadTickItems Loaded [0] item_tick entries 
ZoneSi |    Info    | LoadScaleData Loaded [270] global scaling data entries 
ZoneSi |    Info    | Bootup Zone server [qrg] listening on port [0] -- [qrg] (The Surefall Glade) inst_id [0]
ZoneSi |    Info    | Bootup Zone bootup type [Dynamic] short_name [qrg] zone_id [3] instance_id [0] -- [qrg] (The Surefall Glade) inst_id [0]
ZoneSi |    Info    | GetTimeSync Requesting world time -- [qrg] (The Surefall Glade) inst_id [0]
ZoneSi |    Info    | StartShutdownTimer Reset to [1 Hour] (Loaded from [zone table]) from original remaining time [5 Seconds] duration [5 Seconds] zone [PID (318624) The Surefall Glade (3)] -- [qrg] (The Surefall Glade) inst_id [0]
ZoneSi |    Info    | StartFileLogs Starting File Log [logs/zone/qrg_version_0_inst_id_0_port_0_318624.log] -- [qrg] (The Surefall Glade) inst_id [0]
ZoneSi |    Info    | StopShutdownTimer Stopping zone shutdown timer -- [qrg] (The Surefall Glade) inst_id [0]
ZoneSi |    Info    | BootWebserver Webserver API now listening on port [9099] -- [qrg] (The Surefall Glade) inst_id [0]

Example Sidecar HTTP Response Logs

ZoneSi |    Info    | LootSimulatorController found npc id [32040] -- [qrg] (The Surefall Glade) inst_id [0]
ZoneSi |    Info    | RequestLogHandler [API] Request [200] [/api/v1/loot-simulate?loottable_id=4027] via [127.0.0.1:45666] -- [qrg] (The Surefall Glade) inst_id [0]
ZoneSi |    Info    | LootSimulatorController found npc id [32040] -- [qrg] (The Surefall Glade) inst_id [0]
ZoneSi |    Info    | RequestLogHandler [API] Request [200] [/api/v1/loot-simulate?loottable_id=4027] via [127.0.0.1:45670] -- [qrg] (The Surefall Glade) inst_id [0]
ZoneSi |    Info    | LootSimulatorController found npc id [32040] -- [qrg] (The Surefall Glade) inst_id [0]
ZoneSi |    Info    | RequestLogHandler [API] Request [200] [/api/v1/loot-simulate?loottable_id=4027] via [127.0.0.1:45676] -- [qrg] (The Surefall Glade) inst_id [0]
ZoneSi |    Info    | LootSimulatorController found npc id [32040] -- [qrg] (The Surefall Glade) inst_id [0]
ZoneSi |    Info    | RequestLogHandler [API] Request [200] [/api/v1/loot-simulate?loottable_id=4027] via [127.0.0.1:57236] -- [qrg] (The Surefall Glade) inst_id [0]

@Akkadius
Copy link
Member Author

Feel free to review, but do not merge quite yet

@Akkadius Akkadius merged commit b027edd into master Oct 24, 2023
2 checks passed
@Akkadius Akkadius deleted the akkadius/zone-sidecar branch October 24, 2023 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants