code wiki / _hdl_build / nx_connect_lds_room.nx
nx_connect_lds_room.nx source
↩ module page · 145 lines · 9244 B
1// nx_connect_lds_room.nx -- CONNECT / LDS vertical: YOUTH GAME + HANGOUT ROOM (safety admission layer).
2// Ask #6: LDS youth worldwide meet, play games and hang out -- SAFELY. This is the safety ADMISSION
3// layer that governs WHO may occupy a youth room together; it COMPOSES the existing substrate rather
4// than duplicating it:
5// * nx_room_relay -> the actual unified room: independent game-state/chat/audio/video channels
6// on one room hash, server-relay (no WebRTC). (proven by nx_game_room_gate)
7// * nx_connect_group -> membership/roles (OWNER/ADMIN/MEMBER), lane safety.
8// * nx_connect_lds_youth-> the two-deep visible-context wall this layer enforces on room occupancy.
9// * the games portal (nx_game_*) -> the peer game played in the room (e.g. tic-tac-toe/connect-four).
10//
11// THE NEW INVARIANT (what neither the relay nor the group had): a youth room is SAFE iff youth and
12// adults coexist ONLY at two-deep (>=2 adults). So a lone adult can never be alone with youth in a
13// game room -- enforced on JOIN and on LEAVE. Peers (youth-youth, adult-adult) are free; no room ever
14// spawns an adult<->youth private DM; no ads to minors.
15//
16// The final check drives a REAL nx_room_relay room: admission-gated posting -> two youth land in the
17// live roster of the game AND chat channels, while the denied lone adult never appears. 8 checks incl.
18// negative controls. 100% sovereign. license_tier: ORIGINAL expect_exit: 0
19import "nx_syscalls.nx"
20import "nx_room_relay.nx"
21const BAND_MAGIC_8000: i64 = 8000
22
23const BAND_MINOR: i64 = 0
24const BAND_ADULT: i64 = 1
25const TWO_DEEP: i64 = 2
26
27func yw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
28func yn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 }
29func yinlist(out: *i64, c: i64, id: i64) -> i64 { var i: i64=0; while i<c { if out[i]==id { return 1 } i=i+1 } return 0 }
30
31// SAFE(y,a): youth and adults coexist only at two-deep (>=2 adults present).
32func room_safe(y: i64, a: i64) -> i64 {
33 if y==0 { return 1 } // adults-only room: fine
34 if a==0 { return 1 } // youth-only room (peers): fine
35 if a>=TWO_DEEP { return 1 } // two-deep: fine
36 return 0 // youth present with exactly one adult: NOT allowed
37}
38// may a `band` peer JOIN the current (y,a) room?
39func room_admit(y: i64, a: i64, band: i64) -> i64 {
40 if band==BAND_MINOR { return room_safe(y+1, a) }
41 return room_safe(y, a+1)
42}
43// may a `band` peer LEAVE without dropping the room below two-deep while youth remain?
44func room_may_leave(y: i64, a: i64, band: i64) -> i64 {
45 if band==BAND_MINOR { return room_safe(y-1, a) }
46 return room_safe(y, a-1)
47}
48// NEG-CONTROL twin: an incumbent room with no age wall (Discord-style) admits anyone.
49func room_admit_incumbent(y: i64, a: i64, band: i64) -> i64 { return 1 }
50
51func ad_allowed(band: i64) -> i64 { if band==BAND_MINOR { return 0 } return 1 }
52// a room never spawns an adult<->youth private 1:1 DM (the youth wall, restated)
53func may_private_dm(a_band: i64, b_band: i64) -> i64 {
54 if a_band==BAND_MINOR { if b_band==BAND_ADULT { return 0 } }
55 if a_band==BAND_ADULT { if b_band==BAND_MINOR { return 0 } }
56 return 1
57}
58
59func ycheck(pass: i64, label: *u8, fails: *i64) -> i64 {
60 yw(" " as *u8); yw(label); yw(": " as *u8)
61 if pass==1 { yw("PASS\n" as *u8) } else { yw("FAIL\n" as *u8); fails[0]=fails[0]+1 }
62 return 0
63}
64
65func main() -> i64 {
66 let fails: *i64 = sys_mmap(16) as *i64
67 fails[0]=0
68
69 // pure admission logic over youth-room occupancy states (y youth, a adults)
70 let y_start: i64 = room_admit(0,0,BAND_MINOR) // youth opens a room
71 let y_gather: i64 = room_admit(1,0,BAND_MINOR) // another youth joins (peers)
72 let lone_adult_in: i64 = room_admit(1,0,BAND_ADULT) // a lone adult tries to enter a youth room -> DENY
73 let a_first: i64 = room_admit(0,0,BAND_ADULT) // adult opens an (adult-only) room
74 let a_second: i64 = room_admit(0,1,BAND_ADULT) // second adult -> two-deep
75 let youth_into_2deep: i64 = room_admit(0,2,BAND_MINOR) // youth joins a two-deep room -> OK
76 let youth_into_1adult: i64 = room_admit(0,1,BAND_MINOR) // youth would be alone w/ one adult -> DENY
77 let leave_breaks: i64 = room_may_leave(1,2,BAND_ADULT) // adult leaving (1y,2a)->(1y,1a) -> DENY
78 let leave_ok_noyouth: i64 = room_may_leave(0,2,BAND_ADULT) // adult leaving adult-only room -> OK
79 let youth_leaves: i64 = room_may_leave(1,2,BAND_MINOR) // youth leaving -> OK
80
81 // ---- LIVE COMPOSITION: drive a REAL nx_room_relay youth room (game channel + chat channel) ----
82 let N: i64 = 8
83 let SBG: i64 = 64
84 let SBC: i64 = 128
85 let g_st: *i64 = sys_mmap((2+5*N)*8) as *i64; let g_ar: *u8 = sys_mmap(N*SBG); rr_init(g_st, N, SBG)
86 let c_st: *i64 = sys_mmap((2+5*N)*8) as *i64; let c_ar: *u8 = sys_mmap(N*SBC); rr_init(c_st, N, SBC)
87 let ROOM: i64 = 0x59555448 // 'YUTH'
88 let NOW: i64 = 1000; let TTL: i64 = BAND_MAGIC_8000
89 let P_Y1: i64 = 1; let P_Y2: i64 = 2; let P_A1: i64 = 3; let P_V: i64 = 9 // P_V = non-posting moderator/viewer
90 let mv: *u8 = sys_mmap(SBG); mv[0]=4 as u8 // a game move (center cell)
91 let msg: *u8 = sys_mmap(SBC); msg[0]=104 as u8; msg[1]=105 as u8 // chat "hi"
92 // admission-GATED posting: a peer only reaches the room's channels if the occupancy invariant admits them
93 if room_admit(0,0,BAND_MINOR)==1 { rr_post(g_st,g_ar,ROOM,P_Y1,NOW,1,mv,1); rr_post(c_st,c_ar,ROOM,P_Y1,NOW,1,msg,2) }
94 if room_admit(1,0,BAND_MINOR)==1 { rr_post(g_st,g_ar,ROOM,P_Y2,NOW,1,mv,1); rr_post(c_st,c_ar,ROOM,P_Y2,NOW,1,msg,2) }
95 if room_admit(2,0,BAND_ADULT)==1 { rr_post(g_st,g_ar,ROOM,P_A1,NOW,1,mv,1); rr_post(c_st,c_ar,ROOM,P_A1,NOW,1,msg,2) } // DENIED -> never posts
96 let outg: *i64 = sys_mmap(N*8) as *i64
97 let outc: *i64 = sys_mmap(N*8) as *i64
98 let rg: i64 = rr_roster(g_st, ROOM, P_V, NOW, TTL, outg)
99 let rc: i64 = rr_roster(c_st, ROOM, P_V, NOW, TTL, outc)
100
101 yw("=== nx_connect_lds_room -- youth game+hangout room (two-deep admission over nx_room_relay) ===\n" as *u8)
102 yw(" youth opens room = " as *u8); yn(y_start); yw(" ; another youth joins = " as *u8); yn(y_gather); yw("\n" as *u8)
103 yw(" LONE adult into youth room = " as *u8); yn(lone_adult_in); yw(" (DENIED) ; youth into two-deep = " as *u8); yn(youth_into_2deep); yw("\n" as *u8)
104 yw(" live relay: game-channel roster = " as *u8); yn(rg); yw(" ; chat-channel roster = " as *u8); yn(rc); yw(" (2 youth; lone adult absent)\n" as *u8)
105 yw("-- gate checks --\n" as *u8)
106
107 // T1: youth can open and gather in a room (peers)
108 var t1: i64=0; if y_start==1 { if y_gather==1 { t1=1 } }
109 ycheck(t1, "T1 youth open + gather (peers meet, play, hang out)" as *u8, fails)
110
111 // T2: CORE WALL -- a lone adult cannot enter a room with youth
112 var t2: i64=0; if lone_adult_in==0 { t2=1 }
113 ycheck(t2, "T2 CORE lone adult DENIED entry to a youth room (never alone with youth)" as *u8, fails)
114
115 // T3: two-deep enables adult presence with youth; a single adult does not
116 var t3: i64=0; if a_first==1 { if a_second==1 { if youth_into_2deep==1 { if youth_into_1adult==0 { t3=1 } } } }
117 ycheck(t3, "T3 two-deep enables adult+youth; single-adult room still bars youth" as *u8, fails)
118
119 // T4: leaving cannot break two-deep while youth remain
120 var t4: i64=0; if leave_breaks==0 { if leave_ok_noyouth==1 { if youth_leaves==1 { t4=1 } } }
121 ycheck(t4, "T4 leave cannot drop below two-deep while youth remain" as *u8, fails)
122
123 // T5: no adult<->youth private DM from a room; youth peers may DM
124 var t5: i64=0; if may_private_dm(BAND_ADULT,BAND_MINOR)==0 { if may_private_dm(BAND_MINOR,BAND_MINOR)==1 { t5=1 } }
125 ycheck(t5, "T5 no adult<->youth private DM; youth peers may (wall preserved)" as *u8, fails)
126
127 // T6: no ads to minors
128 var t6: i64=0; if ad_allowed(BAND_MINOR)==0 { if ad_allowed(BAND_ADULT)==1 { t6=1 } }
129 ycheck(t6, "T6 no ads to minors (free either way)" as *u8, fails)
130
131 // T7: NEG-CONTROL -- an incumbent no-wall room admits exactly the lone adult ours denies
132 var t7: i64=0; if room_admit_incumbent(1,0,BAND_ADULT)==1 { if lone_adult_in==0 { t7=1 } }
133 ycheck(t7, "T7 NEG-CONTROL incumbent no-wall room admits lone adult; ours denies (load-bearing)" as *u8, fails)
134
135 // T8: LIVE COMPOSITION -- admission gates a REAL nx_room_relay room (game + chat); adult absent
136 var t8: i64=0
137 if rg==2 { if rc==2 { if yinlist(outg,rg,P_A1)==0 { if yinlist(outc,rc,P_A1)==0 { t8=1 } } } }
138 ycheck(t8, "T8 LIVE two youth in the real game+chat room roster; denied adult absent (composes nx_room_relay)" as *u8, fails)
139
140 yw(" fails=" as *u8); yn(fails[0]); yw("\n" as *u8)
141 if fails[0]==0 { yw("VERDICT: GREEN (youth game+hangout rooms: two-deep admission enforced on a real relay room; peers free; no ads/DM to minors)\n" as *u8); sys_exit(0) }
142 yw("VERDICT: RED\n" as *u8)
143 sys_exit(1)
144 return 1
145}