medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit d6eaf557777baac7f4da9f9865f530fa8eea0869
parent f7a4321d9a9ce0735a32ff6a88fcabc4618822e1
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Tue Dec 27 19:26:22 +0200

Commit the code that actually connects to the server

Diffstat:
hm.cc | 29+++++++++++++++++++++++++++++
1 file changed, 29 insertions(+), 0 deletions(-)
diff --git a/hm.cc b/hm.cc @@ -140,6 +140,35 @@ extern "C" GAME_INIT( game_init ) { ); skybox_init( &game->skybox ); + + sock = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); + if( sock == -1 ) { + FATAL( "socket" ); + } + if( !set_nonblocking( sock ) ) { + FATAL( "set_nonblocking" ); + } + + struct sockaddr_storage addrs = { }; + if( !dns_first( "localhost", &addrs ) ) { + FATAL( "dns_first" ); + } + + memcpy( &addr, &addrs, sizeof( addr ) ); + if( addr.sin_family == AF_INET6 ) printf( "ipv6\n" ); + addr.sin_port = htons( 13337 ); + + char write_buf[ 1400 ]; + WriteStream ws( write_buf ); + v3 pos( 1, 2, 3 ); + + write_u64( &ws, -1 ); + write( &ws, pos ); + + int ok = sendto( sock, ws.start, ws.len(), 0, ( sockaddr * ) &addr, sizeof( addr ) ); + if( ok == -1 ) { + FATAL( "sendto" ); + } } static m4 camera_to_view( v3 position, v3 angles ) {