web/website/integrations/azuriom/game-bridge-test.php

11 lines
3.2 KiB
PHP

<?php
chdir('/home/dunerealms/apps/azuriom');require 'vendor/autoload.php';$app=require 'bootstrap/app.php';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
use Azuriom\Support\DuneShopGameIdentity as Identity;use Illuminate\Support\Facades\DB;use Azuriom\Models\Server;use Azuriom\Models\User;use Illuminate\Http\Request;
function check($ok,$message){if(!$ok)throw new RuntimeException($message);echo "PASS $message\n";}
$java=['uuid'=>'11111111-1111-4111-8111-111111111111','name'=>'ExamplePlayer'];$bedrock=['uuid'=>'00000000-0000-0000-0009-01f5413c46e7','name'=>'.ExampleBedrock'];
check(Identity::valid(...array_values($java)),'Java identity valid');check(Identity::valid(...array_values($bedrock)),'Bedrock identity valid');check(!Identity::valid($java['uuid'],'bad;name'),'Unsafe name rejected');check(Identity::expand('lp user {uuid} parent add vip',$java)==='lp user '.$java['uuid'].' parent add vip','Verified UUID placeholder');check(Identity::expand('give {player} stone',$bedrock)==='give .ExampleBedrock stone','Bedrock name placeholder');
try{Identity::expand("list\nstop",$java);throw new LogicException('Expected rejection');}catch(RuntimeException $e){check(!($e instanceof LogicException),'Multiline rejected');}
check(!Identity::mayConfigure(['permissions'=>['web.shop.support']]),'Shop support cannot configure console rewards');check(Identity::mayConfigure(['permissions'=>['web.menu.servers','web.servers.console']]),'Console operator can configure rewards');
config(['cache.default'=>'array']);DB::statement('CREATE TEMPORARY TABLE server_commands (id BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,server_id BIGINT UNSIGNED,user_id BIGINT UNSIGNED,need_online BOOLEAN,command TEXT,dune_minecraft_uuid VARCHAR(36),dune_minecraft_name VARCHAR(32),created_at DATETIME,updated_at DATETIME)');$server=Server::where('data->dune-server','lobby')->firstOrFail();$u=new User();$u->id=999999;$u->setAttribute('dune_delivery_uuid',$java['uuid']);$u->setAttribute('dune_delivery_name',$java['name']);$server->bridge()->sendCommands(['give {player} stone'], $u,true);$server->bridge()->sendCommands(['list'],$u,false);
check(DB::table('server_commands')->count()===2,'Native queue receives commands without executing');$fetch=function($players)use($server){$r=Request::create('/api/azlink','POST',[],[],[],['CONTENT_TYPE'=>'application/json'],json_encode(['server-id'=>$server->id,'players'=>$players,'maxPlayers'=>20,'full'=>false]));return (new Azuriom\Http\Controllers\Api\ServerController())->fetch($r)->getData(true);};
$r=$fetch([]);check(count($r['commands'])===1&&DB::table('server_commands')->count()===1,'Offline action drained; online action retained');$r=$fetch([['uuid'=>'22222222-2222-4222-8222-222222222222','name'=>'ExamplePlayer']]);check(DB::table('server_commands')->count()===1,'Same name with wrong UUID cannot receive online reward');$r=$fetch([['uuid'=>$java['uuid'],'name'=>'ExamplePlayer']]);check(DB::table('server_commands')->count()===0&&$r['commands']['ExamplePlayer'][0]==='give ExamplePlayer stone','Matching UUID drains recipient snapshot');$r=$fetch([]);check(!$r['commands'],'Drained action is not returned again');echo "No real payment or console action executed.\n";