{
"id": "300",
"prompt": "One screen that health-checks every bridge the cartridge host exposes: on the first frame latch a host::net::open attempt, a host::http::get of https://example.com/, and a host::mp::auto room join, then each frame render four lamp rows - NET SOCKET from net status, HTTP FETCH from ready() plus the status code once ready, MULTIPLAYER from connected() plus the peer count, IDENTITY from viewer_has_identity() - amber pending, green up, red down, with a SYSTEMS GREEN n OF 4 tally at the bottom.",
"solution_rl": "fn lamp(y: i32, state: i32) {\n let mut col: i32 = 0xaa7700;\n if state == 1 {\n col = 0x22bb44;\n } else if state == 2 {\n col = 0xbb2222;\n }\n host::display::fill_rect(48, y, 24, 24, col);\n}\n\nfn frame(t: i32) {\n host::display::clear(0x0b0d11);\n if host::display::state_get(0) == 0 {\n host::display::state_set(1, host::net::open(\"wss://relay.example.net/lamps\"));\n host::display::state_set(2, host::http::get(\"https://example.com/\", 20));\n host::mp::auto(2);\n host::display::state_set(0, 1);\n }\n host::display::draw_string(140, 30, \"BRIDGE CHECK\", 0xffffff, 3);\n let mut green: i32 = 0;\n\n let nh: i32 = host::display::state_get(1);\n let mut nstate: i32 = 2;\n if nh >= 0 {\n let s: i32 = host::net::status(nh);\n if s == 1 {\n nstate = 1;\n } else if s == 0 {\n nstate = 0;\n }\n }\n lamp(110, nstate);\n host::display::draw_string(96, 116, \"NET SOCKET\", 0x8899aa, 2);\n if nstate == 1 {\n green = green + 1;\n }\n\n let hh: i32 = host::display::state_get(2);\n let mut hstate: i32 = 0;\n if hh < 0 {\n hstate = 2;\n } else {\n let r: i32 = host::http::ready(hh);\n if r == 1 {\n hstate = 1;\n } else if r < 0 {\n hstate = 2;\n }\n }\n lamp(190, hstate);\n host::display::draw_string(96, 196, \"HTTP FETCH\", 0x8899aa, 2);\n if hstate == 1 {\n host::display::draw_number(300, 196, host::http::status(hh), 0x66ddff, 2);\n green = green + 1;\n }\n\n let mut mstate: i32 = 0;\n if host::mp::connected() == 1 {\n mstate = 1;\n }\n lamp(270, mstate);\n host::display::draw_string(96, 276, \"MULTIPLAYER\", 0x8899aa, 2);\n if mstate == 1 {\n host::display::draw_number(300, 276, host::mp::peer_count(), 0x66ddff, 2);\n green = green + 1;\n }\n\n let mut istate: i32 = 2;\n if host::agent::viewer_has_identity() == 1 {\n istate = 1;\n }\n lamp(350, istate);\n host::display::draw_string(96, 356, \"IDENTITY\", 0x8899aa, 2);\n if istate == 1 {\n green = green + 1;\n }\n\n host::display::draw_string(48, 440, \"SYSTEMS GREEN\", 0x556677, 1);\n host::display::draw_number(170, 434, green, 0xffffff, 2);\n host::display::draw_string(200, 440, \"OF 4\", 0x556677, 1);\n host::display::present();\n}\n",
"tags": [
"net",
"http",
"mp",
"agent",
"capstone"
]
}