i might get four goobahs
This commit is contained in:
parent
db39759d42
commit
baa781df4f
6 changed files with 80 additions and 16 deletions
34
protocol
34
protocol
|
@ -3,28 +3,50 @@ PROTOCOL
|
||||||
this is almost a carbon copy of every other tcp/ip protocol i write
|
this is almost a carbon copy of every other tcp/ip protocol i write
|
||||||
don't care enough to make it fancy
|
don't care enough to make it fancy
|
||||||
|
|
||||||
|
all numbers are packed unless stated otherwise
|
||||||
packed values are msb
|
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 zero: packet id
|
||||||
byte the one: region count
|
byte the one: region count
|
||||||
for 0 <= n < b.sub 1
|
for 0 <= n < b.1
|
||||||
byte the byte after the last byte byte:
|
byte the byte after the previous byte byte:
|
||||||
region length < 128: one byte
|
region length < 128: one byte
|
||||||
region length >= 128: two bytes, highest bit on msb always 1
|
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
|
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
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
client -> server
|
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
|
|
@ -2,12 +2,20 @@
|
||||||
|
|
||||||
void server() {
|
void server() {
|
||||||
server_context_start();
|
server_context_start();
|
||||||
|
|
||||||
socket_t *sock = sock_server_init("6770");
|
socket_t *sock = sock_server_init("6770");
|
||||||
sock_start(sock);
|
sock_start(sock);
|
||||||
|
sock_set_nonblocking(sock);
|
||||||
|
|
||||||
sock_set_timeout_us(sock, 0, 100);
|
flimit_t vsync;
|
||||||
|
for(;;) {
|
||||||
|
frame_limit_tick(&vsync);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
frame_limit_wait(&vsync, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
printf("awaiting connection...\r\n");
|
printf("awaiting connection...\r\n");
|
||||||
socket_t *conn = sock_accept(sock);
|
socket_t *conn = sock_accept(sock);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "sock.h"
|
#include "sock.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
#include "flimit.h"
|
||||||
|
|
||||||
|
#define MAX_CONNS 100
|
||||||
|
|
||||||
void server();
|
void server();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue