aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-04-15 17:13:08 +0100
committerubq323 <ubq323@ubq323.website>2024-04-15 17:13:08 +0100
commite19852c958838688481422ed3ddd953d2dcd4309 (patch)
tree3c23260f8f3ca3d32284214d68b49af405e109ac /client
parent1f8e6e98b924ee4661be2e7b75cf09a6a8bb7cd3 (diff)
version check
Diffstat (limited to 'client')
-rw-r--r--client/main.ha21
1 files changed, 17 insertions, 4 deletions
diff --git a/client/main.ha b/client/main.ha
index 04e6854..4c70892 100644
--- a/client/main.ha
+++ b/client/main.ha
@@ -1,13 +1,16 @@
use fmt;
use sdl2;
use math;
+use io;
use net;
use net::dial;
+use unix::poll;
+
use drawing;
use drawing::{pos,CHUNKSIZE};
use client::paintui;
-use unix::poll;
use packet_reader;
+use packet_reader::{VERSION};
def NCHUNKS = 16;
@@ -19,7 +22,7 @@ export fn main() void = {
sdl2::SDL_Init(sdl2::SDL_INIT_VIDEO)!;
defer sdl2::SDL_Quit();
- const win = sdl2::SDL_CreateWindow("hi", sdl2::SDL_WINDOWPOS_UNDEFINED, sdl2::SDL_WINDOWPOS_UNDEFINED, 640, 480, sdl2::SDL_WindowFlags::NONE)!;
+ const win = sdl2::SDL_CreateWindow("garden", sdl2::SDL_WINDOWPOS_UNDEFINED, sdl2::SDL_WINDOWPOS_UNDEFINED, 640, 480, sdl2::SDL_WindowFlags::NONE)!;
defer sdl2::SDL_DestroyWindow(win);
const wsurf = sdl2::SDL_GetWindowSurface(win)!;
@@ -42,11 +45,21 @@ export fn main() void = {
};
// connect to server
- const conn = match(dial::dial("tcp","localhost","41460")) {
+ const conn = match(dial::dial("tcp","ubq323.website","41460")) {
case let c: net::socket => yield c;
case let err: net::error =>
fmt::fatal("couldn't connect to server:",net::strerror(err));
};
+
+ let byte = [0u8];
+ match (io::read(conn, byte)) {
+ case let e: io::error =>
+ fmt::fatal("error with server handshake",io::strerror(e));
+ case => if (byte[0] != VERSION)
+ fmt::fatalf("invalid version: got {}, expecting {}",
+ byte[0], VERSION);
+ };
+
const pollfd: [1]poll::pollfd = [ poll::pollfd {
fd = conn, events=poll::event::POLLIN, revents = 0
@@ -150,7 +163,7 @@ export fn main() void = {
};
- drawing::clear_picture(&win_pic, 0xff0000);
+ drawing::clear_picture(&win_pic, 0xdddddd);
for (let i = 0z; i < len(pictures); i += 1) {
const psurf = picture_surfaces[i];