aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
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],
+ })?;
+ };
+
+};