docs(reference): import Dune: Awakening server-manager references
All checks were successful
CI / backend-types (push) Successful in 10s
CI / frontend-build (push) Successful in 15s
CI / agent-tests (push) Successful in 39s
CI / integration (push) Successful in 22s

Phase 2 references for the host-agent Dune adapter, moved out of volatile /tmp
into docs/reference-repos/ (per Commander). Three upstream projects, .git +
node_modules + compiled binaries stripped (16MB source). Nested AI-instruction
files (.claude/, CLAUDE.md) removed so they don't pollute Corrosion sessions.

- icehunter/    dune-admin (Go+React) — 4 control planes; SETUP_DOCKER.md is the
                closest analog to our agent's Dune docker control plane (compose
                lifecycle, docker logs, RabbitMQ-via-exec, dune Postgres schema)
- adainrivers/  Rust/Tauri desktop — SSH+k8s BattleGroup control, maintenance
                daemon, in-game admin console (Rust idiom reference)
- the4rchangel/ Node web UI replacing battlegroup.bat — matches the Commander's
                Hyper-V self-host path + game-config schema

See docs/reference-repos/README.md for the full index + how we use each.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Vantz Stockwell
2026-06-11 21:08:05 -04:00
parent 0715492ddf
commit 651a35d4be
1334 changed files with 238971 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
-- dune_exchange_add_sell_order(in_exchange_id bigint, in_access_point_id bigint, in_owner_id bigint, in_max_orders_per_player integer, in_expiration_time bigint, in_item_id bigint, in_count bigint, in_category_mask integer, in_category_depth smallint, in_durability_cur real, in_durability_max real, in_item_price bigint, in_wear_normalized_item_price bigint, in_quality_level bigint, in_solari_cost bigint) -> dune.duneexchangeaddsellorderresult
-- oid: 58241 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.dune_exchange_add_sell_order(in_exchange_id bigint, in_access_point_id bigint, in_owner_id bigint, in_max_orders_per_player integer, in_expiration_time bigint, in_item_id bigint, in_count bigint, in_category_mask integer, in_category_depth smallint, in_durability_cur real, in_durability_max real, in_item_price bigint, in_wear_normalized_item_price bigint, in_quality_level bigint, in_solari_cost bigint)
RETURNS dune.duneexchangeaddsellorderresult
LANGUAGE plpgsql
AS $function$
DECLARE
exchange_inventory_id BIGINT;
user_id BIGINT;
new_item_id BIGINT;
item_template_id TEXT;
result DuneExchangeAddSellOrderResult;
fls_id TEXT;
BEGIN
result.order_id = 0;
SELECT INTO result.order_slots_used get_dune_exchange_used_order_slots(in_owner_id);
IF result.order_slots_used >= in_max_orders_per_player THEN
RETURN result;
END IF;
PERFORM * from dune_exchange_orders where item_id = in_item_id;
IF FOUND THEN
-- Debug logging
SELECT acc."user"
INTO fls_id
FROM accounts acc
JOIN player_state ps on ps.account_id = acc.id
WHERE ps.player_controller_id = in_owner_id
LIMIT 1;
PERFORM log_cheating(fls_id, 'exchange_order_dupe');
RAISE WARNING 'Trying to dupe exchange sell orders FLS: %', fls_id;
RETURN result;
END IF;
SELECT INTO user_id dune_exchange_get_user_id(in_owner_id);
SELECT INTO exchange_inventory_id get_exchange_inventory_id(in_exchange_id);
IF exchange_inventory_id IS NULL THEN
RETURN result;
END IF;
UPDATE dune_exchange_users SET solari_balance = solari_balance - in_solari_cost WHERE id = user_id AND solari_balance >= in_solari_cost;
IF NOT FOUND THEN
RETURN result;
END IF;
SELECT INTO STRICT item_template_id template_id FROM items WHERE id = in_item_id FOR UPDATE;
INSERT INTO dune_exchange_orders(exchange_id, access_point_id, owner_id, expiration_time, template_id, durability_cur, durability_max, category_mask, category_depth, item_price, quality_level)
VALUES(in_exchange_id, in_access_point_id, in_owner_id, in_expiration_time, item_template_id, in_durability_cur, in_durability_max, in_category_mask, in_category_depth, in_item_price, in_quality_level)
RETURNING id INTO result.order_id;
INSERT INTO dune_exchange_sell_orders(order_id, initial_stack_size, wear_normalized_price) VALUES(result.order_id, in_count, in_wear_normalized_item_price);
SELECT INTO new_item_id move_inventory_item(in_item_id, exchange_inventory_id, result.order_id, in_count);
IF new_item_id IS NULL THEN
RAISE EXCEPTION 'Failed to move inventory item %', in_item_id;
END IF;
UPDATE dune_exchange_orders SET item_id = new_item_id WHERE id = result.order_id;
result.order_slots_used = result.order_slots_used + 1;
RETURN result;
END $function$

View File

@@ -0,0 +1,23 @@
-- dune_exchange_cancel_order(in_order_id bigint, in_purge_time bigint, in_completion_type integer) -> void
-- oid: 58242 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.dune_exchange_cancel_order(in_order_id bigint, in_purge_time bigint, in_completion_type integer)
RETURNS void
LANGUAGE plpgsql
AS $function$
DECLARE
BEGIN
DELETE FROM dune_exchange_sell_orders WHERE order_id = in_order_id;
IF NOT FOUND THEN
RETURN;
END IF;
WITH item_stack_size AS
(SELECT item.stack_size
FROM dune_exchange_orders ord
JOIN items item ON ord.item_id = item.id
WHERE ord.id = in_order_id)
INSERT INTO dune_exchange_fulfilled_orders(order_id, completion_type, stack_size, original_order_id) VALUES(in_order_id, in_completion_type, (SELECT * FROM item_stack_size), in_order_id);
UPDATE dune_exchange_orders SET expiration_time = in_purge_time, revision = revision + 1 WHERE id = in_order_id;
END $function$

View File

@@ -0,0 +1,46 @@
-- dune_exchange_expire_orders(in_exchange_id bigint, in_current_time bigint, in_purge_time bigint, in_expired_completion_type integer) -> SETOF dune.exchangeexpiredorder
-- oid: 58243 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.dune_exchange_expire_orders(in_exchange_id bigint, in_current_time bigint, in_purge_time bigint, in_expired_completion_type integer)
RETURNS SETOF dune.exchangeexpiredorder
LANGUAGE plpgsql
AS $function$
DECLARE
cur_order RECORD;
order_is_npc_order BOOLEAN;
BEGIN
FOR cur_order IN
SELECT
ord.id AS order_id,
ord.owner_id AS owner_id,
ord.is_npc_order AS is_npc_order,
item.stack_size AS stack_size,
ord.item_price AS item_price,
ord.quality_level AS quality_level
FROM dune_exchange_orders ord
JOIN dune_exchange_sell_orders sord ON (ord.id = sord.order_id)
JOIN items item ON (ord.item_id = item.id)
WHERE ord.exchange_id = in_exchange_id AND ord.expiration_time IS NOT NULL AND in_current_time >= ord.expiration_time
FOR UPDATE
LOOP
IF NOT cur_order.is_npc_order THEN
-- Make an item_storage record for the order item.
DELETE FROM dune_exchange_sell_orders WHERE order_id = cur_order.order_id;
INSERT INTO dune_exchange_fulfilled_orders(order_id, completion_type, stack_size, original_order_id) VALUES(cur_order.order_id, in_expired_completion_type, cur_order.stack_size, cur_order.order_id);
UPDATE dune_exchange_orders SET revision = revision + 1, expiration_time = in_purge_time WHERE id = cur_order.order_id;
RETURN NEXT (
cur_order.order_id,
cur_order.owner_id,
in_expired_completion_type,
cur_order.stack_size,
cur_order.item_price,
cur_order.order_id,
cur_order.quality_level);
ELSE
-- Delete the order. Will cascade into the items table.
DELETE FROM dune_exchange_orders WHERE id = order_id;
END IF;
END LOOP;
END $function$

View File

@@ -0,0 +1,142 @@
-- dune_exchange_fulfill_sell_order(in_exchange_id bigint, in_max_orders_per_player integer, in_purchased_completion_type integer, in_sold_completion_type integer, in_instigator_id bigint, in_order_id bigint, in_order_revision bigint, in_dst_inventory_id bigint, in_dst_index bigint, in_count bigint, in_solaris_fee bigint, in_purge_time bigint) -> dune.duneexchangefulfillsellorderresult
-- oid: 58244 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.dune_exchange_fulfill_sell_order(in_exchange_id bigint, in_max_orders_per_player integer, in_purchased_completion_type integer, in_sold_completion_type integer, in_instigator_id bigint, in_order_id bigint, in_order_revision bigint, in_dst_inventory_id bigint, in_dst_index bigint, in_count bigint, in_solaris_fee bigint, in_purge_time bigint)
RETURNS dune.duneexchangefulfillsellorderresult
LANGUAGE plpgsql
AS $function$
DECLARE
exchange_inventory_id BIGINT;
order_access_point_id BIGINT;
seller_actor_id BIGINT;
seller_user_id BIGINT;
buyer_user_id BIGINT;
user_solari_balance BIGINT;
per_item_price BIGINT;
total_cost BIGINT;
order_revision BIGINT;
order_item_id BIGINT;
order_is_npc_order BOOLEAN;
order_category_mask INT;
order_category_depth SMALLINT;
item_template_id TEXT;
item_durability_cur REAL;
item_durability_max REAL;
storage_order_id BIGINT;
log_order_id BIGINT;
result DuneExchangeFulfillSellOrderResult;
BEGIN
result.item_id = 0;
SELECT INTO result.order_slots_used get_dune_exchange_used_order_slots(in_instigator_id);
IF result.order_slots_used >= in_max_orders_per_player THEN
RETURN result;
END IF;
SELECT INTO exchange_inventory_id get_exchange_inventory_id(in_exchange_id);
SELECT INTO buyer_user_id dune_exchange_get_user_id(in_instigator_id);
BEGIN
SELECT INTO STRICT user_solari_balance solari_balance FROM dune_exchange_users WHERE id = buyer_user_id FOR UPDATE;
SELECT INTO STRICT
order_revision,
order_access_point_id,
order_item_id,
item_template_id,
item_durability_cur,
item_durability_max,
seller_actor_id,
order_category_mask,
order_category_depth,
order_is_npc_order,
per_item_price
ord.revision,
ord.access_point_id,
ord.item_id,
ord.template_id,
ord.durability_cur,
ord.durability_max,
ord.owner_id,
ord.category_mask,
ord.category_depth,
ord.is_npc_order,
ord.item_price
FROM
dune_exchange_orders ord
JOIN dune_exchange_sell_orders sord ON (ord.id = sord.order_id)
WHERE
id = in_order_id AND revision = in_order_revision
FOR UPDATE;
EXCEPTION
WHEN NO_DATA_FOUND THEN RETURN result;
END;
IF order_revision != in_order_revision THEN
RETURN result;
END IF;
IF NOT order_is_npc_order THEN
SELECT INTO seller_user_id dune_exchange_get_user_id(seller_actor_id);
END IF;
total_cost = per_item_price * in_count + in_solaris_fee;
IF total_cost > user_solari_balance THEN
RETURN result;
END IF;
IF in_dst_inventory_id IS NULL THEN
-- Item is to be transferred to exchange storage rather than an external inventory. Make a record for it.
INSERT INTO dune_exchange_orders(exchange_id, access_point_id, owner_id, template_id, expiration_time, durability_cur, durability_max, item_price, category_mask, category_depth)
VALUES(in_exchange_id, order_access_point_id, in_instigator_id, item_template_id, in_purge_time, item_durability_cur, item_durability_max, per_item_price, order_category_mask, order_category_depth)
RETURNING id INTO storage_order_id;
INSERT INTO dune_exchange_fulfilled_orders(order_id, completion_type, stack_size, original_order_id)
VALUES(storage_order_id, in_purchased_completion_type, in_count, in_order_id);
in_dst_inventory_id = exchange_inventory_id;
in_dst_index = storage_order_id;
END IF;
UPDATE dune_exchange_orders SET item_id = NULL WHERE id = in_order_id;
SELECT INTO result.item_id move_inventory_item(order_item_id, in_dst_inventory_id, in_dst_index, in_count);
IF result.item_id IS NULL THEN
IF storage_order_id IS NOT NULL THEN
DELETE FROM dune_exchange_orders WHERE id = storage_order_id;
END IF;
RETURN result;
END IF;
-- Create an entry for the fulfilled orders log.
SELECT INTO log_order_id order_id FROM dune_exchange_fulfilled_orders where source_order_id = in_order_id FOR SHARE;
IF log_order_id IS NOT NULL THEN
UPDATE dune_exchange_orders SET expiration_time = in_purge_time, revision = revision + 1 WHERE id = log_order_id;
UPDATE dune_exchange_fulfilled_orders SET stack_size = stack_size + in_count WHERE order_id = log_order_id;
ELSE
INSERT INTO dune_exchange_orders(exchange_id, access_point_id, owner_id, template_id, expiration_time, durability_cur, durability_max, item_price, category_mask, category_depth)
VALUES(in_exchange_id, order_access_point_id, seller_actor_id, item_template_id, in_purge_time, item_durability_cur, item_durability_max, per_item_price, order_category_mask, order_category_depth) RETURNING id INTO log_order_id;
INSERT INTO dune_exchange_fulfilled_orders(order_id, source_order_id, completion_type, stack_size, original_order_id)
VALUES(log_order_id, in_order_id, in_sold_completion_type, in_count, in_order_id);
END IF;
UPDATE dune_exchange_users SET solari_balance = solari_balance - total_cost WHERE id = buyer_user_id;
-- If the new ID is equal to the old ID the item/stack was moved rather than split and the order is now empty
IF result.item_id = order_item_id THEN
DELETE FROM dune_exchange_orders WHERE id = in_order_id;
ELSE
UPDATE dune_exchange_orders SET item_id = order_item_id, revision = revision + 1 WHERE id = in_order_id; -- Item was split. Restore reference to remaining items.
END IF;
-- If the item was transferred to exchange storage rather than an external inventory, update the record with the item ID.
IF storage_order_id IS NOT NULL THEN
UPDATE dune_exchange_orders SET item_id = result.item_id WHERE id = storage_order_id;
END IF;
result.order_slots_used = result.order_slots_used + 1;
RETURN result;
END $function$

View File

@@ -0,0 +1,16 @@
-- dune_exchange_get_user_id(in_owner_id bigint) -> bigint
-- oid: 58247 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.dune_exchange_get_user_id(in_owner_id bigint)
RETURNS bigint
LANGUAGE plpgsql
AS $function$
DECLARE
new_user_id BIGINT;
user_id BIGINT;
BEGIN
INSERT INTO dune_exchange_users(owner_id) VALUES(in_owner_id) ON CONFLICT DO NOTHING RETURNING id INTO new_user_id;
SELECT INTO user_id COALESCE(new_user_id, id) FROM dune_exchange_users WHERE owner_id = in_owner_id;
return user_id;
END $function$

View File

@@ -0,0 +1,37 @@
-- dune_exchange_purge_completed_orders(in_exchange_id bigint, in_current_time bigint) -> SETOF dune.exchangeexpiredorder
-- oid: 58249 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.dune_exchange_purge_completed_orders(in_exchange_id bigint, in_current_time bigint)
RETURNS SETOF dune.exchangeexpiredorder
LANGUAGE plpgsql
AS $function$
DECLARE
cur_order RECORD;
order_is_npc_order BOOLEAN;
BEGIN
FOR cur_order IN
SELECT
ord.id AS order_id,
ord.owner_id AS owner_id,
ord.is_npc_order AS is_npc_order,
sord.stack_size AS stack_size,
ord.item_price AS item_price,
sord.completion_type AS completion_type,
sord.original_order_id AS original_order_id,
ord.quality_level AS quality_level
FROM dune_exchange_orders ord
JOIN dune_exchange_fulfilled_orders sord ON (ord.id = sord.order_id)
WHERE ord.exchange_id = in_exchange_id AND ord.expiration_time IS NOT NULL AND in_current_time >= ord.expiration_time
FOR UPDATE
LOOP
DELETE FROM dune_exchange_orders WHERE id = cur_order.order_id;
RETURN NEXT (
cur_order.order_id,
cur_order.owner_id,
cur_order.completion_type,
cur_order.stack_size,
cur_order.item_price,
cur_order.original_order_id,
cur_order.quality_level);
END LOOP;
END $function$

View File

@@ -0,0 +1,16 @@
-- dune_exchange_query_storage_item(in_order_id bigint) -> TABLE(completion_type integer, id bigint, revision bigint, expiration_time bigint, access_point_id bigint, ap_name text, owner_id bigint, item_id bigint, template_id text, stack_size bigint, item_price bigint, quality_level bigint, durability_cur real, durability_max real, dynamic_stats jsonb)
-- oid: 58250 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.dune_exchange_query_storage_item(in_order_id bigint)
RETURNS TABLE(completion_type integer, id bigint, revision bigint, expiration_time bigint, access_point_id bigint, ap_name text, owner_id bigint, item_id bigint, template_id text, stack_size bigint, item_price bigint, quality_level bigint, durability_cur real, durability_max real, dynamic_stats jsonb)
LANGUAGE plpgsql
AS $function$
BEGIN
RETURN QUERY
SELECT sord.completion_type, ord.id, ord.revision, ord.expiration_time, ord.access_point_id, ap.name, ord.owner_id, ord.item_id, ord.template_id, sord.stack_size, ord.item_price, ord.quality_level, ord.durability_cur, ord.durability_max, item.stats
FROM dune_exchange_orders ord
JOIN dune_exchange_fulfilled_orders sord ON (ord.id = sord.order_id)
JOIN dune_exchange_accesspoints ap ON (ord.access_point_id = ap.id)
LEFT JOIN items item ON ord.item_id = item.id
WHERE ord.id = in_order_id;
END; $function$

View File

@@ -0,0 +1,16 @@
-- dune_exchange_query_storage_items(in_exchange_id bigint, in_owner_id bigint) -> TABLE(completion_type integer, id bigint, revision bigint, expiration_time bigint, access_point_id bigint, ap_name text, owner_id bigint, item_id bigint, template_id text, stack_size bigint, item_price bigint, quality_level bigint, durability_cur real, durability_max real, dynamic_stats jsonb)
-- oid: 58251 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.dune_exchange_query_storage_items(in_exchange_id bigint, in_owner_id bigint)
RETURNS TABLE(completion_type integer, id bigint, revision bigint, expiration_time bigint, access_point_id bigint, ap_name text, owner_id bigint, item_id bigint, template_id text, stack_size bigint, item_price bigint, quality_level bigint, durability_cur real, durability_max real, dynamic_stats jsonb)
LANGUAGE plpgsql
AS $function$
BEGIN
RETURN QUERY
SELECT sord.completion_type, ord.id, ord.revision, ord.expiration_time, ord.access_point_id, ap.name, ord.owner_id, ord.item_id, ord.template_id, sord.stack_size, ord.item_price, ord.quality_level, ord.durability_cur, ord.durability_max, item.stats
FROM dune_exchange_orders ord
JOIN dune_exchange_fulfilled_orders sord ON (ord.id = sord.order_id)
JOIN dune_exchange_accesspoints ap ON (ord.access_point_id = ap.id)
LEFT JOIN items item ON ord.item_id = item.id
WHERE ord.exchange_id = in_exchange_id AND ord.owner_id = in_owner_id;
END; $function$

View File

@@ -0,0 +1,41 @@
-- dune_exchange_relist_order(in_order_id bigint, in_expiration_time bigint, in_item_price bigint, in_wear_normalized_item_price bigint, in_solari_cost bigint) -> bigint
-- oid: 58252 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.dune_exchange_relist_order(in_order_id bigint, in_expiration_time bigint, in_item_price bigint, in_wear_normalized_item_price bigint, in_solari_cost bigint)
RETURNS bigint
LANGUAGE plpgsql
AS $function$
DECLARE
user_id BIGINT;
initial_stack_size BIGINT;
BEGIN
WITH order_owner_id AS
(SELECT ord.owner_id
FROM dune_exchange_orders ord
JOIN dune_exchange_fulfilled_orders ford ON (ord.id = ford.order_id)
WHERE id = in_order_id AND item_id IS NOT NULL)
SELECT INTO user_id dune_exchange_get_user_id((SELECT * FROM order_owner_id));
UPDATE dune_exchange_users SET solari_balance = solari_balance - in_solari_cost WHERE id = user_id AND solari_balance >= in_solari_cost;
IF NOT FOUND THEN
RETURN 0;
END IF;
DELETE FROM dune_exchange_fulfilled_orders WHERE order_id = in_order_id;
IF NOT FOUND THEN
RAISE EXCEPTION 'Order % is not a fulfilled order', in_order_id;
END IF;
WITH item_stack_size AS
(SELECT item.stack_size
FROM dune_exchange_orders ord
JOIN items item ON ord.item_id = item.id
WHERE ord.id = in_order_id)
INSERT INTO dune_exchange_sell_orders(order_id, initial_stack_size, wear_normalized_price) VALUES(in_order_id, (SELECT * FROM item_stack_size), in_wear_normalized_item_price) RETURNING dune_exchange_sell_orders.initial_stack_size INTO initial_stack_size;
UPDATE dune_exchange_orders SET item_price = in_item_price, expiration_time = in_expiration_time WHERE id = in_order_id;
RETURN initial_stack_size;
END $function$

View File

@@ -0,0 +1,47 @@
-- dune_exchange_retrieve_storage_item(in_exchange_id bigint, in_order_id bigint, in_dst_inventory_id bigint, in_dst_index bigint, in_count bigint) -> dune.duneexchangeretrievestorageorderresult
-- oid: 58255 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.dune_exchange_retrieve_storage_item(in_exchange_id bigint, in_order_id bigint, in_dst_inventory_id bigint, in_dst_index bigint, in_count bigint)
RETURNS dune.duneexchangeretrievestorageorderresult
LANGUAGE plpgsql
AS $function$
DECLARE
exchange_inventory_id BIGINT;
order_owner_id BIGINT;
order_item_id BIGINT;
result DuneExchangeRetrieveStorageOrderResult;
BEGIN
SELECT INTO exchange_inventory_id get_exchange_inventory_id(in_exchange_id);
IF exchange_inventory_id IS NULL THEN
RETURN NULL;
END IF;
SELECT INTO STRICT order_owner_id, order_item_id owner_id, item_id
FROM dune_exchange_orders
JOIN dune_exchange_fulfilled_orders ON (dune_exchange_orders.id = dune_exchange_fulfilled_orders.order_id)
WHERE id = in_order_id
FOR UPDATE;
UPDATE dune_exchange_orders SET item_id = NULL WHERE id = in_order_id;
SELECT INTO result.item_id move_inventory_item(order_item_id, in_dst_inventory_id, in_dst_index, in_count);
IF result.item_id IS NULL THEN
RAISE EXCEPTION 'Failed to move inventory item % on order %', in_item_id, in_order_id;
END IF;
SELECT INTO result.original_order_id original_order_id FROM dune_exchange_fulfilled_orders WHERE order_id = in_order_id;
-- If the new ID is equal to the old ID the item/stack was moved rather than split and the order is now empty
IF result.item_id = order_item_id THEN
DELETE FROM dune_exchange_orders WHERE id = in_order_id;
ELSE
UPDATE dune_exchange_orders SET item_id = order_item_id WHERE id = in_order_id; -- Item was split. Restore reference to remaining items.
UPDATE dune_exchange_fulfilled_orders SET stack_size = stack_size - in_count WHERE order_id = in_order_id;
END IF;
SELECT INTO result.order_slots_used get_dune_exchange_used_order_slots(order_owner_id);
RETURN result;
END $function$

View File

@@ -0,0 +1,63 @@
-- dune_exchange_update_recurring_sell_order(in_exchange_id bigint, in_expiration_time bigint, in_access_point_id bigint, in_owner_id bigint, in_item_id bigint, in_increment bigint, in_max_count bigint, in_category_mask integer, in_category_depth smallint, in_durability_cur real, in_durability_max real, in_item_price bigint, in_wear_normalized_item_price bigint, in_quality_level bigint) -> bigint
-- oid: 58256 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.dune_exchange_update_recurring_sell_order(in_exchange_id bigint, in_expiration_time bigint, in_access_point_id bigint, in_owner_id bigint, in_item_id bigint, in_increment bigint, in_max_count bigint, in_category_mask integer, in_category_depth smallint, in_durability_cur real, in_durability_max real, in_item_price bigint, in_wear_normalized_item_price bigint, in_quality_level bigint)
RETURNS bigint
LANGUAGE plpgsql
AS $function$
DECLARE
exchange_inventory_id BIGINT;
new_item_id BIGINT;
item_stack_size BIGINT;
new_order_id BIGINT;
item_template_id TEXT;
old_count BIGINT;
new_count BIGINT;
delta_count BIGINT;
BEGIN
LOCK TABLE dune_exchange_orders, items IN ROW EXCLUSIVE MODE;
SELECT INTO exchange_inventory_id get_exchange_inventory_id(in_exchange_id);
IF exchange_inventory_id IS NULL THEN
RETURN 0;
END IF;
SELECT INTO STRICT item_template_id template_id FROM items WHERE id = in_item_id FOR SHARE;
SELECT INTO new_order_id, new_item_id ord.id, ord.item_id
FROM dune_exchange_orders ord
JOIN dune_exchange_sell_orders sord ON (ord.id = sord.order_id)
WHERE ord.is_npc_order = TRUE AND ord.exchange_id = in_exchange_id AND ord.access_point_id = in_access_point_id AND ord.template_id = item_template_id AND ord.item_price = in_item_price AND ord.quality_level = in_quality_level
FOR SHARE;
IF new_order_id IS NULL THEN
INSERT INTO dune_exchange_orders(exchange_id, access_point_id, owner_id, is_npc_order, expiration_time, template_id, durability_cur, durability_max, category_mask, category_depth, item_price, quality_level)
VALUES(in_exchange_id, in_access_point_id, in_owner_id, TRUE, in_expiration_time, item_template_id, in_durability_cur, in_durability_max, in_category_mask, in_category_depth, in_item_price, in_quality_level)
RETURNING id INTO new_order_id;
INSERT INTO dune_exchange_sell_orders(order_id, initial_stack_size, wear_normalized_price) VALUES(new_order_id, new_count, in_wear_normalized_item_price);
SELECT INTO new_item_id move_inventory_item(in_item_id, exchange_inventory_id, new_order_id, in_increment);
IF new_item_id IS NULL THEN
DELETE FROM dune_exchange_orders WHERE id = new_order_id;
RETURN 0;
END IF;
UPDATE dune_exchange_orders SET item_id = new_item_id WHERE id = new_order_id;
RETURN in_increment;
ELSE
UPDATE dune_exchange_orders SET expiration_time = in_expiration_time WHERE id=new_order_id;
SELECT INTO STRICT old_count stack_size FROM items WHERE id = new_item_id FOR SHARE;
new_count = old_count + in_increment;
IF new_count > in_max_count THEN new_count = in_max_count; END IF;
IF new_count != old_count THEN
delta_count = new_count - old_count;
SELECT INTO new_item_id merge_or_move_inventory_item(in_item_id, exchange_inventory_id, new_order_id, delta_count);
RETURN delta_count;
END IF;
RETURN 0;
END IF;
END $function$

View File

@@ -0,0 +1,16 @@
-- get_dune_exchange_accesspoint_id(in_exchange_id bigint, in_name text) -> bigint
-- oid: 58296 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.get_dune_exchange_accesspoint_id(in_exchange_id bigint, in_name text)
RETURNS bigint
LANGUAGE plpgsql
AS $function$
DECLARE
new_ap_id BIGINT;
ap_id BIGINT;
BEGIN
INSERT INTO dune_exchange_accesspoints(exchange_id, name) VALUES(in_exchange_id, in_name) ON CONFLICT DO NOTHING RETURNING id INTO new_ap_id;
SELECT INTO ap_id COALESCE(new_ap_id, id) FROM dune_exchange_accesspoints WHERE exchange_id = in_exchange_id AND name = in_name;
return ap_id;
END $function$

View File

@@ -0,0 +1,15 @@
-- get_dune_exchange_data(in_exchange_id bigint, in_controller_id bigint) -> dune.loadexchangedataresult
-- oid: 58297 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.get_dune_exchange_data(in_exchange_id bigint, in_controller_id bigint)
RETURNS dune.loadexchangedataresult
LANGUAGE plpgsql
AS $function$
DECLARE
result LoadExchangeDataResult;
BEGIN
SELECT INTO result.exchange_name exchange_name FROM dune_exchanges WHERE id=in_exchange_id;
SELECT INTO result.used_order_slots get_dune_exchange_used_order_slots(in_controller_id);
RETURN result;
END $function$

View File

@@ -0,0 +1,15 @@
-- get_dune_exchange_id(in_name text) -> bigint
-- oid: 58298 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.get_dune_exchange_id(in_name text)
RETURNS bigint
LANGUAGE plpgsql
AS $function$
DECLARE
new_exchange_id BIGINT;
exchange_id BIGINT;
BEGIN
INSERT INTO dune_exchanges(exchange_name, inventory_id) VALUES(in_name, NULL) ON CONFLICT DO NOTHING RETURNING id INTO new_exchange_id;
SELECT INTO exchange_id COALESCE(new_exchange_id, id) FROM dune_exchanges WHERE exchange_name = in_name;
RETURN exchange_id;
END $function$

View File

@@ -0,0 +1,14 @@
-- get_dune_exchange_used_order_slots(in_controller_id bigint) -> integer
-- oid: 58299 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.get_dune_exchange_used_order_slots(in_controller_id bigint)
RETURNS integer
LANGUAGE plpgsql
AS $function$
DECLARE
result INT;
BEGIN
SELECT INTO result COUNT(*) FROM dune_exchange_orders where owner_id=in_controller_id AND item_id IS NOT NULL;
RETURN result;
END $function$

View File

@@ -0,0 +1,16 @@
-- get_exchange_inventory_id(in_exchange_id bigint) -> bigint
-- oid: 58300 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.get_exchange_inventory_id(in_exchange_id bigint)
RETURNS bigint
LANGUAGE plpgsql
AS $function$
DECLARE
inv_id BIGINT;
BEGIN
SELECT INTO inv_id id FROM inventories WHERE "exchange_id" = in_exchange_id;
IF inv_id IS NULL THEN
INSERT INTO inventories("id", exchange_id) VALUES(DEFAULT, in_exchange_id) RETURNING id INTO inv_id;
END IF;
RETURN inv_id;
END $function$

View File

@@ -0,0 +1,16 @@
-- get_exchange_orders_by_mask(in_mask integer, in_depth smallint) -> SETOF bigint
-- oid: 58301 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.get_exchange_orders_by_mask(in_mask integer, in_depth smallint)
RETURNS SETOF bigint
LANGUAGE plpgsql
AS $function$
DECLARE
check_mask INT;
check_shift INT;
BEGIN
check_shift := (4 - in_depth) * 8;
check_mask := (in_mask >> check_shift);
RETURN query SELECT id FROM dune_exchange_orders WHERE category_depth >= in_depth AND (category_mask >> check_shift) = check_mask FOR SHARE;
END
$function$

View File

@@ -0,0 +1,23 @@
-- get_exchange_sell_orders(in_id bigint, in_exchange_id bigint, in_min_item_price bigint, in_max_item_price bigint, in_template_id text, in_mask integer, in_depth smallint) -> TABLE(id bigint, revision bigint, expiration_time bigint, access_point_id bigint, ap_name text, owner_id bigint, template_id text, stack_size bigint, initial_stack_size bigint, item_price bigint, quality_level bigint, durability_cur real, durability_max real, dynamic_stats jsonb)
-- oid: 58302 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.get_exchange_sell_orders(in_id bigint, in_exchange_id bigint, in_min_item_price bigint, in_max_item_price bigint, in_template_id text, in_mask integer, in_depth smallint)
RETURNS TABLE(id bigint, revision bigint, expiration_time bigint, access_point_id bigint, ap_name text, owner_id bigint, template_id text, stack_size bigint, initial_stack_size bigint, item_price bigint, quality_level bigint, durability_cur real, durability_max real, dynamic_stats jsonb)
LANGUAGE plpgsql
AS $function$
DECLARE
BEGIN
RETURN query
SELECT ord.id, ord.revision, ord.expiration_time, ord.access_point_id, ap.name, ord.owner_id, item.template_id, item.stack_size, sord.initial_stack_size, ord.item_price, ord.quality_level, ord.durability_cur, ord.durability_max, item.stats
FROM dune_exchange_orders ord
JOIN dune_exchange_sell_orders sord ON (ord.id = sord.order_id)
JOIN items item ON (ord.item_id = item.id)
JOIN dune_exchange_accesspoints ap ON (ord.access_point_id = ap.id)
WHERE (in_id IS NOT NULL AND ord.id = in_id) OR
(in_id IS NULL AND ord.exchange_id = in_exchange_id AND ord.item_price >= in_min_item_price AND (in_max_item_price <= 0 OR ord.item_price <= in_max_item_price) AND
((in_template_id IS NOT NULL AND ord.template_id = in_template_id) OR
(in_template_id IS NULL AND ord.id IN (SELECT * FROM get_exchange_orders_by_mask(in_mask, in_depth))))
)
FOR SHARE;
END
$function$

View File

@@ -0,0 +1,19 @@
-- get_exchange_sell_orders_by_owner(in_exchange_id bigint, in_owner_id bigint) -> TABLE(id bigint, revision bigint, expiration_time bigint, access_point_id bigint, ap_name text, owner_id bigint, template_id text, stack_size bigint, initial_stack_size bigint, item_price bigint, quality_level bigint, durability_cur real, durability_max real, dynamic_stats jsonb)
-- oid: 58304 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.get_exchange_sell_orders_by_owner(in_exchange_id bigint, in_owner_id bigint)
RETURNS TABLE(id bigint, revision bigint, expiration_time bigint, access_point_id bigint, ap_name text, owner_id bigint, template_id text, stack_size bigint, initial_stack_size bigint, item_price bigint, quality_level bigint, durability_cur real, durability_max real, dynamic_stats jsonb)
LANGUAGE plpgsql
AS $function$
DECLARE
BEGIN
RETURN query
SELECT ord.id, ord.revision, ord.expiration_time, ord.access_point_id, ap.name, ord.owner_id, item.template_id, item.stack_size, sord.initial_stack_size, ord.item_price, ord.quality_level, ord.durability_cur, ord.durability_max, item.stats
FROM dune_exchange_orders ord
JOIN dune_exchange_sell_orders sord ON (ord.id = sord.order_id)
JOIN items item ON (ord.item_id = item.id)
JOIN dune_exchange_accesspoints ap ON (ord.access_point_id = ap.id)
WHERE ord.owner_id = in_owner_id
FOR SHARE;
END
$function$

View File

@@ -0,0 +1,20 @@
-- try_update_exchange_categories_hash(in_new_hash integer) -> TABLE(item_template_id text, mask integer, depth smallint)
-- oid: 58613 kind: FUNCTION category: exchange
CREATE OR REPLACE FUNCTION dune.try_update_exchange_categories_hash(in_new_hash integer)
RETURNS TABLE(item_template_id text, mask integer, depth smallint)
LANGUAGE plpgsql
AS $function$
DECLARE
BEGIN
IF NOT EXISTS (SELECT * FROM dune_exchange_categories_hash) FOR UPDATE THEN
INSERT INTO dune_exchange_categories_hash(id, hash) VALUES(1, in_new_hash);
RETURN;
END IF;
IF NOT in_new_hash IN (SELECT hash FROM dune_exchange_categories_hash FOR SHARE) THEN
UPDATE dune_exchange_categories_hash SET hash = in_new_hash WHERE dune_exchange_categories_hash.id = 1;
RETURN QUERY SELECT DISTINCT template_id, category_mask, category_depth FROM dune_exchange_orders;
END IF;
RETURN;
END
$function$