code wiki / (root) / nx_game_chat.nx

nx_game_chat.nx

buildroot/runtime/nx_game_chat.nx

35073 B808 linesdepth 5pulls 10 transitivereach 0 importersview sourcekind tooltopic game
docsdependenciesstructsconstsfunctions

about

nx_game_chat.nx -- C12 of the comms lane: TURN-BASED MULTIPLAYER + CHAT over the C1 store. Contract symbol gc_room_wire == the /compare/comms C12 watch (milestone M5: comms visible in the games). DONE-RULE (comms.plan): a game opens a room per session and two clients exchange moves and chat through the C1 store; the gate proves order and delivery with the game's own rules as the referee. REFEREE: nx_game_chat_gate. THE DESIGN: THE LOG IS THE GAME. A match is an ordinary nx_chat_store room; moves are TEXT rows with the reserved body prefix mv:<n>; the CURRENT STATE is a DETERMINISTIC REPLAY of the log. The move verb validates against the replayed state before appending, and the replay validates AGAIN on every read -- so a row that slipped in out of turn (a race, or a client that lied) is counted and IGNORED by every reader identically: replay is the referee, the wire is untrusted. Store-and-forward multiplayer follows free: an offline player fetches-since-cursor and the same replay produces the same board on every device (C2 sync moves whole matches between roots). GAME DEFINITIONS ARE DATA (knowledge/comms/games.conf): id, cols, rows, winlen, mode (drop = gravity, connect-four class; place = direct cell, tic-tac-toe class). A new grid game is a conf row. WRITES go through the ONE ruler -- this organ forks the nx_chat_store elf named in the conf, so budgets/refusals/announcements stay with C1; READS are direct plane reads (the same split C2 established). Chat rides the same room (say verb); a chat body may not start with the reserved mv: prefix (refused by name). Tombstones hide CHAT from display but NEVER hide moves: a game's history is its state, so replay ignores del: keys for move rows by design (stated, not accidental). The emitted HTML artifact stamps itself from the LAST ROW's epoch, never the wall clock, so two emits of the same log are byte-identical (deterministic artifacts). license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 5 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_store_seed_lib.nx nx_seg_store.nx nx_tool_run.nx nx_game_chat.nx

imports: nx_syscalls.nxnx_itoa_lib.nxnx_store_seed_lib.nxnx_seg_store.nxnx_tool_run.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main gc_usage gc_w sys_write sys_exit gc_eq gc_room_wire gc_tok_ok gc_w ↻ gc_eq ↻ sts_mm sys_mmap nxa_die sys_write ↻ sys_exit ↻ nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ sts_werr sys_write ↻ sys_exit ↻ gc_game sts_mm ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_munmap sys_close gc_len gc_confs

structs

none

consts

31const GC_EXIT_OK: i64 = 0
32const GC_EXIT_USAGE: i64 = 2
33const GC_EXIT_REFUSED: i64 = 3
34const GC_EXIT_RETRY: i64 = 4
35const GC_EXIT_CORRUPT: i64 = 5
37const GC_NAME_MAX: i64 = 64
38const GC_PFX_CAP: i64 = 256
39const GC_CONF_CAP: i64 = 192
40const GC_BOARD_MAX: i64 = 4096 // conf sanity: cols*rows above this is a conf mistake, refused by name
41const GC_OUT_CAP: i64 = 65536 // fork-capture buffer
42const GC_HTML_CAP: i64 = 262144 // emit buffer
43const GC_NL: i64 = 10
44const GC_PIPE: i64 = 124
45const GC_ST_ONGOING: i64 = 0
46const GC_ST_WIN: i64 = 2
47const GC_ST_DRAW: i64 = 3
48const GC_MODE_DROP: i64 = 1
49const GC_MODE_PLACE: i64 = 2

functions

51func gc_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
52func gc_n(v: i64) -> i64 { nxi_out(v); return 0 }
53func gc_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
54func gc_eq(a: *u8, b: *u8) -> i64
60func gc_tok_ok(s: *u8) -> i64
76func gc_atoi(b: *u8, n: i64) -> i64
called by 2: gc_replaygc_move
88func gc_hexv(c: i64) -> i64
called by 1: gc_hexd
94func gc_hexd(src: *u8, n: i64, dst: *u8) -> i64
called by 1: gc_replay calls 1: gc_hexv
108func gc_confs(confpath: *u8, key: *u8, out: *u8, cap: i64) -> i64
144func gc_game(gconf: *u8, id: *u8, g: *i64) -> i64
209func gc_prefix(chatconf: *u8, room: *u8, out: *u8) -> i64
221func gc_field(p: *u8, l: i64, idx: i64, op: *i64) -> i64
called by 1: gc_replay
237func gc_chat(chatelf: *u8, av: *i64, out: *u8, ol: *i64) -> i64
246func gc_replay(pfx: *u8, gconf: *u8, board: *u8, st: *i64, p1: *u8, p2: *u8, gid: *u8) -> i64
419func gc_replay_err(rr: i64) -> i64
called by 3: gc_movegc_boardgc_emit calls 1: gc_w
430func gc_room_wire(game: *u8, session: *u8, p1: *u8, p2: *u8, gconf: *u8) -> i64
498func gc_move(room: *u8, player: *u8, mv: *u8, gconf: *u8) -> i64
591func gc_say(room: *u8, player: *u8, text: *u8, gconf: *u8) -> i64
623func gc_board_print(board: *u8, st: *i64) -> i64
called by 1: gc_board calls 2: sts_mmsys_write
641func gc_board(room: *u8, gconf: *u8) -> i64
684func gc_emit(room: *u8, outpath: *u8, gconf: *u8) -> i64
765func gc_usage() -> i64
called by 1: main calls 1: gc_w
769func gc_confpick(argc: i64, argv: *i64, idx: i64) -> *u8
called by 1: main
773func main(argc: i64, argv: *i64) -> i64