aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-04-13 01:46:53 +0100
committerubq323 <ubq323@ubq323.website>2024-04-13 01:46:53 +0100
commit0fc5f56e6287541901dc956115f44e9bad93279d (patch)
tree8202b8edeb5ffe8761256665fa7fd96817afedd2 /server
parentbf03e2a0d86a4b5202a72aa66da5dc0e2c0b412b (diff)
server sends chunk data to client!!! code quality is declining steadily
Diffstat (limited to 'server')
-rw-r--r--server/main.ha18
1 files changed, 17 insertions, 1 deletions
diff --git a/server/main.ha b/server/main.ha
index 9f21932..ae7d9eb 100644
--- a/server/main.ha
+++ b/server/main.ha
@@ -41,7 +41,13 @@ export fn main() void = {
for (const p &.. pictures) drawing::clear_picture(p, 0xffffff);
- const listener = tcp::listen(ip::ANY_V4, PORT)!;
+ const listener = match(tcp::listen(ip::ANY_V4, PORT)) {
+ case let err: net::error =>
+ fmt::fatalf(net::strerror(err));
+ case let sock: net::socket =>
+ yield sock;
+ };
+
loop(listener, pictures);
};
@@ -111,6 +117,7 @@ fn loop(listener: net::socket, pictures: []drawing::picture) void = {
});
append(packet_readers, packet_reader::new());
fmt::printfln("there are now {},{} conns.",len(pollfds),len(packet_readers))!;
+ send_world(new_conn, pictures)!;
};
for (let connidx = 1z; connidx < len(pollfds); connidx += 1) {
if (0 != pollfds[connidx].revents & poll::event::POLLIN) {
@@ -153,3 +160,12 @@ fn handle_packet(pictures: []drawing::picture, pollfds: []poll::pollfd, packet:
};
};
+fn send_world(conn: io::file, pictures: []drawing::picture) (void | io::error) = {
+ for (const pic &.. pictures) {
+ packet_reader::send(conn, packet_reader::packet_sendchunk {
+ world_pos = pic.world_pos,
+ chunk_data = pic.d[..pic.w*pic.h],
+ })?;
+ };
+
+};