docs(reference): import Dune: Awakening server-manager references
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:
@@ -0,0 +1,46 @@
|
||||
-- adjust_player_virtual_currency_balance(in_controller_id bigint, in_currency_id smallint, in_delta bigint) -> bigint
|
||||
-- oid: 58129 kind: FUNCTION category: currency
|
||||
|
||||
CREATE OR REPLACE FUNCTION dune.adjust_player_virtual_currency_balance(in_controller_id bigint, in_currency_id smallint, in_delta bigint)
|
||||
RETURNS bigint
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
DECLARE
|
||||
current_balance BIGINT;
|
||||
current_delta BIGINT;
|
||||
new_delta BIGINT;
|
||||
fls_id TEXT;
|
||||
function_oid oid;
|
||||
BEGIN
|
||||
SELECT INTO current_balance balance from player_virtual_currency_balances WHERE player_controller_id = in_controller_id AND currency_id = in_currency_id;
|
||||
INSERT INTO player_virtual_currency_balances("player_controller_id", "currency_id", "balance")
|
||||
VALUES (in_controller_id, in_currency_id, in_delta)
|
||||
ON CONFLICT (player_controller_id, currency_id) DO UPDATE SET balance = (player_virtual_currency_balances.balance + in_delta)
|
||||
RETURNING balance INTO current_balance;
|
||||
|
||||
IF in_currency_id = get_solaris_id() THEN
|
||||
GET DIAGNOSTICS function_oid = PG_ROUTINE_OID;
|
||||
PERFORM log_event_solaris(function_oid, 'update_solaris', in_controller_id, current_balance, in_delta);
|
||||
END IF;
|
||||
|
||||
current_delta = 0;
|
||||
IF current_balance < 0 THEN
|
||||
SELECT acc."user"
|
||||
INTO fls_id
|
||||
FROM accounts acc
|
||||
JOIN player_state ps on ps.account_id = acc.id
|
||||
WHERE ps.account_id = in_player_id
|
||||
LIMIT 1;
|
||||
|
||||
PERFORM log_cheating(COALESCE(fls_id, in_player_id::text), 'negative_solaris');
|
||||
|
||||
INSERT INTO player_virtual_currency_balances("player_controller_id", "currency_id", "balance")
|
||||
VALUES (in_controller_id, in_currency_id, 0)
|
||||
ON CONFLICT (player_controller_id, currency_id) DO UPDATE SET balance = 0;
|
||||
current_delta = current_balance;
|
||||
END IF;
|
||||
|
||||
new_delta = in_delta + current_delta;
|
||||
RETURN new_delta;
|
||||
END;
|
||||
$function$
|
||||
@@ -0,0 +1,43 @@
|
||||
-- dune_exchange_modify_user_solari_balance(in_controller_id bigint, in_solari_delta bigint) -> void
|
||||
-- oid: 58248 kind: FUNCTION category: currency
|
||||
|
||||
CREATE OR REPLACE FUNCTION dune.dune_exchange_modify_user_solari_balance(in_controller_id bigint, in_solari_delta bigint)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
DECLARE
|
||||
user_id BIGINT;
|
||||
current_balance BIGINT;
|
||||
new_balance BIGINT;
|
||||
delta_balance BIGINT;
|
||||
fls_id TEXT;
|
||||
function_oid oid;
|
||||
BEGIN
|
||||
SELECT INTO user_id dune_exchange_get_user_id(in_controller_id);
|
||||
SELECT INTO current_balance balance from player_virtual_currency_balances WHERE currency_id = get_solaris_id() AND player_controller_id = in_controller_id;
|
||||
|
||||
IF current_balance < 0 THEN
|
||||
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_controller_id
|
||||
LIMIT 1;
|
||||
|
||||
PERFORM log_cheating(COALESCE(fls_id, in_controller_id::text), 'exchange_negative_solaris');
|
||||
UPDATE player_virtual_currency_balances SET balance = 0 WHERE currency_id = get_solaris_id() AND player_controller_id = in_controller_id;
|
||||
current_balance = 0;
|
||||
END IF;
|
||||
|
||||
delta_balance = in_solari_delta;
|
||||
IF current_balance < in_solari_delta THEN
|
||||
delta_balance = current_balance;
|
||||
END IF;
|
||||
|
||||
UPDATE dune_exchange_users SET solari_balance = solari_balance + delta_balance WHERE id = user_id;
|
||||
|
||||
UPDATE player_virtual_currency_balances SET balance = balance - delta_balance WHERE currency_id = get_solaris_id() AND player_controller_id = in_controller_id RETURNING player_virtual_currency_balances.balance INTO new_balance;
|
||||
|
||||
GET DIAGNOSTICS function_oid = PG_ROUTINE_OID;
|
||||
PERFORM log_event_solaris(function_oid, 'update_solaris', in_controller_id, new_balance, delta_balance);
|
||||
END $function$
|
||||
@@ -0,0 +1,27 @@
|
||||
-- dune_exchange_retrieve_solari_balance(in_owner_id bigint) -> bigint
|
||||
-- oid: 58253 kind: FUNCTION category: currency
|
||||
|
||||
CREATE OR REPLACE FUNCTION dune.dune_exchange_retrieve_solari_balance(in_owner_id bigint)
|
||||
RETURNS bigint
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
DECLARE
|
||||
current_balance BIGINT;
|
||||
fls_id TEXT;
|
||||
BEGIN
|
||||
SELECT INTO current_balance solari_balance from dune_exchange_users WHERE owner_id = in_owner_id LIMIT 1;
|
||||
|
||||
IF current_balance < 0 THEN
|
||||
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(COALESCE(fls_id, in_owner_id::text), 'exchange_negative_solaris');
|
||||
|
||||
UPDATE dune_exchange_users SET solari_balance = 0 WHERE owner_id = in_owner_id;
|
||||
END IF;
|
||||
RETURN (SELECT solari_balance FROM dune_exchange_users WHERE owner_id = in_owner_id LIMIT 1);
|
||||
END; $function$
|
||||
@@ -0,0 +1,41 @@
|
||||
-- dune_exchange_retrieve_solaris_from_item(in_controller_id bigint, in_order_id bigint) -> dune.duneexchangeretrievesolarisfromitemresult
|
||||
-- oid: 58254 kind: FUNCTION category: currency
|
||||
|
||||
CREATE OR REPLACE FUNCTION dune.dune_exchange_retrieve_solaris_from_item(in_controller_id bigint, in_order_id bigint)
|
||||
RETURNS dune.duneexchangeretrievesolarisfromitemresult
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
DECLARE
|
||||
result DuneExchangeRetrieveSolarisFromItemResult;
|
||||
new_balance BIGINT;
|
||||
function_oid oid;
|
||||
BEGIN
|
||||
WITH
|
||||
delete_orders_prices AS (
|
||||
DELETE FROM dune_exchange_orders
|
||||
USING dune_exchange_fulfilled_orders
|
||||
WHERE (dune_exchange_orders.id = dune_exchange_fulfilled_orders.order_id)
|
||||
AND id = in_order_id AND (item_id IS NULL OR item_id = 0)
|
||||
RETURNING item_price * dune_exchange_fulfilled_orders.stack_size AS total_price
|
||||
),
|
||||
total_price AS (
|
||||
SELECT SUM(total_price) AS delta FROM delete_orders_prices
|
||||
)
|
||||
UPDATE player_virtual_currency_balances
|
||||
SET balance = balance + total_price.delta
|
||||
FROM total_price
|
||||
WHERE currency_id = get_solaris_id() AND player_controller_id = in_controller_id
|
||||
RETURNING
|
||||
player_virtual_currency_balances.balance,
|
||||
total_price.delta,
|
||||
(SELECT original_order_id FROM dune_exchange_fulfilled_orders WHERE order_id = in_order_id)
|
||||
INTO
|
||||
new_balance,
|
||||
result.total_item_value,
|
||||
result.original_order_id;
|
||||
|
||||
GET DIAGNOSTICS function_oid = PG_ROUTINE_OID;
|
||||
PERFORM log_event_solaris(function_oid, 'update_solaris', in_controller_id, new_balance, result.total_item_value);
|
||||
|
||||
RETURN result;
|
||||
END $function$
|
||||
@@ -0,0 +1,23 @@
|
||||
-- edit_guild_description(in_guild_id bigint, in_guild_desc text) -> void
|
||||
-- oid: 58258 kind: FUNCTION category: currency
|
||||
|
||||
CREATE OR REPLACE FUNCTION dune.edit_guild_description(in_guild_id bigint, in_guild_desc text)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
DECLARE
|
||||
out_guild_description TEXT;
|
||||
BEGIN
|
||||
PERFORM guilds_get_exclusive_operation_lock();
|
||||
|
||||
-- check if guild exists
|
||||
SELECT guild_description INTO out_guild_description FROM guilds WHERE guild_id = in_guild_id;
|
||||
IF NOT FOUND THEN
|
||||
RAISE EXCEPTION 'Trying to add invite to non existing guild %.', in_guild_id;
|
||||
END IF;
|
||||
|
||||
UPDATE guilds SET guild_description = in_guild_desc WHERE guilds.guild_id = in_guild_id;
|
||||
|
||||
PERFORM pg_notify('guild_notify_channel', format('edit_guild_description#{"GuildId" : %s}', in_guild_id));
|
||||
END
|
||||
$function$
|
||||
@@ -0,0 +1,18 @@
|
||||
-- get_player_virtual_currency_balances(in_controller_id bigint) -> TABLE(out_currency_id smallint, out_currency_balance bigint)
|
||||
-- oid: 58345 kind: FUNCTION category: currency
|
||||
|
||||
CREATE OR REPLACE FUNCTION dune.get_player_virtual_currency_balances(in_controller_id bigint)
|
||||
RETURNS TABLE(out_currency_id smallint, out_currency_balance bigint)
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
BEGIN
|
||||
return query (
|
||||
with currencies as (select currency_id, balance from player_virtual_currency_balances where player_controller_id = in_controller_id),
|
||||
bad_currencies as (select * from currencies where balance < 0),
|
||||
target_account_id as (select account_id from player_state where player_controller_id = in_controller_id limit 1),
|
||||
report_cheaters as (select currency_id, flag_player_as_cheater(target_account_id.account_id, 'negative_solaris') from bad_currencies, target_account_id),
|
||||
fix_bad_currencies as (update player_virtual_currency_balances set balance = 0 from report_cheaters where player_controller_id = in_controller_id and player_virtual_currency_balances.currency_id = report_cheaters.currency_id)
|
||||
select currency_id, balance from currencies
|
||||
);
|
||||
END;
|
||||
$function$
|
||||
@@ -0,0 +1,14 @@
|
||||
-- get_solaris_id() -> smallint
|
||||
-- oid: 58351 kind: FUNCTION category: currency
|
||||
|
||||
CREATE OR REPLACE FUNCTION dune.get_solaris_id()
|
||||
RETURNS smallint
|
||||
LANGUAGE plpgsql
|
||||
IMMUTABLE
|
||||
AS $function$
|
||||
DECLARE
|
||||
solaris_id CONSTANT SMALLINT := 0;
|
||||
BEGIN
|
||||
return solaris_id;
|
||||
END
|
||||
$function$
|
||||
@@ -0,0 +1,48 @@
|
||||
-- log_event_solaris(in_function_oid oid, in_message dune.logmessagetype, in_controller_id bigint, in_solaris_balance bigint, in_solaris_delta bigint) -> void
|
||||
-- oid: 58470 kind: FUNCTION category: currency
|
||||
|
||||
CREATE OR REPLACE FUNCTION dune.log_event_solaris(in_function_oid oid, in_message dune.logmessagetype, in_controller_id bigint, in_solaris_balance bigint, in_solaris_delta bigint)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
DECLARE
|
||||
partition_id BIGINT = 0;
|
||||
calling_function_name LogFunctionType;
|
||||
fls_id TEXT;
|
||||
fc_id BYTEA;
|
||||
char_name BYTEA;
|
||||
BEGIN
|
||||
|
||||
partition_id := coalesce(current_setting('dune.partition_id', true)::BIGINT, 0);
|
||||
|
||||
-- map calling function name to LogFunctionType (each calling function must be added to LogFunctionType)
|
||||
SELECT proname::text::LogFunctionType
|
||||
INTO calling_function_name
|
||||
FROM pg_proc
|
||||
WHERE oid = in_function_oid;
|
||||
|
||||
-- get the fls_id for the user performing the acction
|
||||
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_controller_id
|
||||
LIMIT 1;
|
||||
|
||||
INSERT INTO event_log (
|
||||
partition_id,
|
||||
category,
|
||||
function_name,
|
||||
message,
|
||||
event_time,
|
||||
meta
|
||||
) VALUES (
|
||||
partition_id,
|
||||
'solaris',
|
||||
calling_function_name,
|
||||
in_message,
|
||||
now(),
|
||||
json_build_object('fls_id', fls_id, 'event', calling_function_name::text, 'solaris_balance', in_solaris_balance, 'solaris_delta', in_solaris_delta)
|
||||
);
|
||||
END;
|
||||
$function$
|
||||
Reference in New Issue
Block a user