.{math, log, string, random, buffer, memory} := @use("../../stn/src/lib.hb"); .{Surface, new_surface} := @use("../../render/src/lib.hb"); .{Window, WindowProps, WindowData, MessageHeader, BUFFER, message, receive_message, send_message, await_message} := @use("./lib.hb") WindowServer := struct { window_count: uint, id: uint, // ! replace this with an actual collection when we get an allocator windows: ^WindowData, } // ! in the future this should be safely handled server := @as(WindowServer, idk) start := fn(): void { windows := memory.alloc(WindowData, 10) server = .(0, buffer.create(BUFFER), windows) log.debug("server: started server\0") } // ! this function will be rewritten to several functions that allow the server mainloop to handle these itself handle_connections := fn(): bool { recv := receive_message(MessageHeader, server.id) if recv == null { return true } if recv.kind == message.syn { buffer_id := buffer.create_without_name() send_message(MessageHeader, .(message.ack, buffer_id), server.id) log.debug("server: sent ack\0") resp := await_message(WindowProps, buffer_id) log.debug("server: received props\0") data := WindowData.(resp, buffer_id) send_message(WindowData, data, buffer_id) log.debug("server: sent window data\0"); *(server.windows + server.window_count) = data server.window_count += 1 } else if recv.kind == message.shutdown { log.warn("server: shutdown handled without validation\n\r this is temporary behaviour\0") return false } return true }