i might get four goobahs
This commit is contained in:
parent
db39759d42
commit
baa781df4f
6 changed files with 80 additions and 16 deletions
44
protocol
44
protocol
|
@ -3,28 +3,50 @@ PROTOCOL
|
|||
this is almost a carbon copy of every other tcp/ip protocol i write
|
||||
don't care enough to make it fancy
|
||||
|
||||
all numbers are packed unless stated otherwise
|
||||
packed values are msb
|
||||
|
||||
byte n is b.sub n
|
||||
byte n is b.n
|
||||
region n is r.n
|
||||
|
||||
---
|
||||
|
||||
byte the zero: packet id
|
||||
byte the one: region count
|
||||
for 0 <= n < b.sub 1
|
||||
byte the byte after the last byte byte:
|
||||
region length < 128: one byte
|
||||
for 0 <= n < b.1
|
||||
byte the byte after the previous byte byte:
|
||||
region length < 128: one byte
|
||||
region length >= 128: two bytes, highest bit on msb always 1
|
||||
|
||||
byte the bytes after the header octet bytes:
|
||||
byte the bytes after the header octet bytes bytes:
|
||||
raw body data shoved next to each other with no separation
|
||||
|
||||
---
|
||||
|
||||
server -> client
|
||||
|
||||
|
||||
---
|
||||
|
||||
client -> server
|
||||
|
||||
id 0: registration attempt
|
||||
r.0 - username - string
|
||||
r.1 - pin - ushort (max 9999)
|
||||
|
||||
id 1: login attempt
|
||||
r.0 - username - string
|
||||
r.1 - pin - ushort (max 9999)
|
||||
|
||||
id 2: ctx change response
|
||||
r.0 - ack - bool
|
||||
r.1 - ctx id - ushort
|
||||
|
||||
---
|
||||
|
||||
server -> client
|
||||
id 0: registration response
|
||||
r.0 - succeeded - bool
|
||||
r.1 - status - string
|
||||
|
||||
id 1: login response
|
||||
r.0 - succeeded - bool
|
||||
r.1 -> status - string (if r.0 false)
|
||||
-> user id - ushort (if r.0 true)
|
||||
|
||||
id 2: ctx change request
|
||||
r.0 - ctx id - ushort
|
18
src/flimit.c
Normal file
18
src/flimit.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "flimit.h"
|
||||
|
||||
void frame_limit_tick(flimit_t *fld) {
|
||||
time(fld);
|
||||
}
|
||||
|
||||
void frame_limit_wait(flimit_t *fld, unsigned int fps) {
|
||||
double fr = 1.0 / fps, dt, wait;
|
||||
struct timespec swait;
|
||||
|
||||
time_t now = time(NULL);
|
||||
dt = difftime(now, *fld);
|
||||
|
||||
if(dt < fr) {
|
||||
wait = fr - dt;
|
||||
usleep((unsigned int)(wait * 1000000));
|
||||
}
|
||||
}
|
13
src/flimit.h
Normal file
13
src/flimit.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef FLIMIT_H
|
||||
#define FLIMIT_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef time_t flimit_t;
|
||||
|
||||
void frame_limit_tick(flimit_t*);
|
||||
void frame_limit_wait(flimit_t*, unsigned int);
|
||||
|
||||
#endif
|
|
@ -1,12 +1,20 @@
|
|||
#include "server.h"
|
||||
|
||||
void server() {
|
||||
void server() {
|
||||
server_context_start();
|
||||
|
||||
socket_t *sock = sock_server_init("6770");
|
||||
sock_start(sock);
|
||||
|
||||
sock_set_timeout_us(sock, 0, 100);
|
||||
sock_set_nonblocking(sock);
|
||||
|
||||
flimit_t vsync;
|
||||
for(;;) {
|
||||
frame_limit_tick(&vsync);
|
||||
|
||||
|
||||
|
||||
frame_limit_wait(&vsync, 1000);
|
||||
}
|
||||
|
||||
printf("awaiting connection...\r\n");
|
||||
socket_t *conn = sock_accept(sock);
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
#include <stdio.h>
|
||||
#include "sock.h"
|
||||
#include "queue.h"
|
||||
#include "flimit.h"
|
||||
|
||||
#define MAX_CONNS 100
|
||||
|
||||
void server();
|
||||
|
||||
|
|
|
@ -5,14 +5,14 @@ static socket_t* sock_init() {
|
|||
}
|
||||
|
||||
socket_t* sock_client_init(char *addr, char *port) {
|
||||
socket_t* sock = sock_init();
|
||||
socket_t *sock = sock_init();
|
||||
sock->type = SOCK_TYPE_CLIENT;
|
||||
sock->port = port;
|
||||
sock->addr = addr;
|
||||
}
|
||||
|
||||
socket_t* sock_server_init(char *port) {
|
||||
socket_t* sock = sock_init();
|
||||
socket_t *sock = sock_init();
|
||||
sock->type = SOCK_TYPE_SERVER;
|
||||
sock->port = port;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue