diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/main.ha | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/server/main.ha b/server/main.ha index 71bb71b..cf8e720 100644 --- a/server/main.ha +++ b/server/main.ha @@ -17,6 +17,7 @@ use unix::poll; use drawing; use drawing::{pos,CHUNKSIZE}; use packet_reader; +use packet_reader::{VERSION}; def PORT: u16 = 41460; @@ -130,7 +131,6 @@ fn loop(state: *server_state, timeout: time::duration) void = { for (let pollfd_idx = 1z: size; pollfd_idx < len(pollfds); pollfd_idx += 1) { const conn_idx = pollfd_idx - 1; if (state.connections[conn_idx].should_delete) continue; - fmt::printfln("checking conn {} with pollfd {}",conn_idx, pollfd_idx)!; if (0 != pollfds[conn_idx+1].revents & poll::event::POLLIN) { read_from_connection(state, conn_idx); }; @@ -153,7 +153,10 @@ fn perform_deletions(state: *server_state) void = { }; fn greet_connection(state: *server_state, conn_idx: size) -(void|io::error) = void; +(void|io::error) = { + const conn = state.connections[conn_idx]; + io::write(conn.sock, [VERSION])?; +}; @@ -195,8 +198,8 @@ fn handle_packet( match (packet) { case let op: packet_reader::packet_drawop => const opc = op as drawing::op_circle; - fmt::printfln("#{}: drawop ({:+6},{:+6}) r{}", - conn_idx,opc.pos.0,opc.pos.1, opc.radius)!; + // fmt::printfln("#{}: drawop ({:+6},{:+6}) r{}", + // conn_idx,opc.pos.0,opc.pos.1, opc.radius)!; drawing::perform(state.pictures, opc); for (let other_idx = 0z; other_idx < len(state.connections); @@ -205,7 +208,7 @@ fn handle_packet( if (other_idx == conn_idx) continue; const other_conn = &state.connections[other_idx]; if (other_conn.should_delete) continue; - fmt::printfln("\t -> #{}",other_idx)!; + // fmt::printfln("\t -> #{}",other_idx)!; match (packet_reader::send(other_conn.sock, packet)) { case void => yield; case let e: io::error => @@ -215,8 +218,8 @@ fn handle_packet( }; }; case let pos: packet_reader::packet_position => - fmt::printfln("pos of #{} is now {},{}", - conn_idx, pos.0, pos.1)!; + // fmt::printfln("pos of #{} is now {},{}", + // conn_idx, pos.0, pos.1)!; state.connections[conn_idx].pos = pos; case let world_pos: packet_reader::packet_reqchunk => // xxx it is probably easy to ddos the server by sending lots of these @@ -268,12 +271,15 @@ fn unload_distant_chunks(state: *server_state) void = { const chunk_in_y = floor_div(conn.pos.1, CHUNKSIZE)*CHUNKSIZE; // pic_chunk_pos - player_chunk_pos must be either 0 or 512 or 1024 // can't be less than 0 or more than 1024 + // + // -CHUNKSIZE because i suspect this still unloads chunks when + // it should't, somehow for (let i = 0z; i < n_pics; i += 1) { const pic = &state.pictures[i]; const dcx = pic.world_pos.0 - chunk_in_x; const dcy = pic.world_pos.1 - chunk_in_y; - if (0 <= dcx && dcx <= 2*CHUNKSIZE && 0 <= dcy && dcy <= 2*CHUNKSIZE) + if (-CHUNKSIZE <= dcx && dcx <= 2*CHUNKSIZE && -CHUNKSIZE <= dcy && dcy <= 2*CHUNKSIZE) should_unload[i] = false; }; }; |