mirror of https://github.com/dirtbags/moth.git
Rewrite octopus to not use tokend
This commit is contained in:
parent
b87c1f6f35
commit
c3b94fda84
|
@ -1 +0,0 @@
|
||||||
S゙*郢シ緩ミ7<EFBE90>k<13>
|
|
|
@ -1,2 +0,0 @@
|
||||||
|
|
||||||
Àñõ®¶'çå6Œ™²¤Y=
|
|
|
@ -1 +0,0 @@
|
||||||
偦轎奫^,5嗥贠教
|
|
|
@ -1 +0,0 @@
|
||||||
<EFBFBD><EFBFBD>t322<EFBFBD>/<2F>0<EFBFBD>g<EFBFBD><67>ji
|
|
|
@ -1 +0,0 @@
|
||||||
qð°VA.SF´Ö¨,.}²
|
|
|
@ -1 +0,0 @@
|
||||||
U'0絤騺q<1B>p
|
|
|
@ -1,7 +1,7 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
|
|
||||||
port=8888
|
port=8888
|
||||||
host=10.0.0.8
|
host=${1:-10.0.0.8}
|
||||||
|
|
||||||
blooper=$(tempfile)
|
blooper=$(tempfile)
|
||||||
trap "rm $blooper" 0
|
trap "rm $blooper" 0
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
build: octopus
|
build: octopus
|
||||||
|
|
||||||
octopus: octopus.o token.o
|
octopus: octopus.o
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f octopus *.o
|
rm -f octopus *.o
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include "token.h"
|
|
||||||
|
|
||||||
#define OUTPUT_MAX 1024
|
#define OUTPUT_MAX 1024
|
||||||
#define INPUT_MAX 1024
|
#define INPUT_MAX 1024
|
||||||
|
@ -20,6 +19,9 @@
|
||||||
#define max(a,b) (((a)>(b))?(a):(b))
|
#define max(a,b) (((a)>(b))?(a):(b))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
char token[80];
|
||||||
|
size_t tokenlen;
|
||||||
|
|
||||||
uint8_t const key[] = {0x99, 0x5f, 0xcb, 0xde,
|
uint8_t const key[] = {0x99, 0x5f, 0xcb, 0xde,
|
||||||
0xf9, 0x6d, 0x02, 0xf3,
|
0xf9, 0x6d, 0x02, 0xf3,
|
||||||
0x47, 0x60, 0x0a, 0xe0,
|
0x47, 0x60, 0x0a, 0xe0,
|
||||||
|
@ -47,7 +49,7 @@ char const octopus[] =
|
||||||
);
|
);
|
||||||
|
|
||||||
const char *friends[8] = {
|
const char *friends[8] = {
|
||||||
("Welcome to Olive Octopus's house! Olive lives at 00021270.\n"
|
("Welcome to Olive Octopus's house!\n"
|
||||||
"Help Olive visit all 8 of her friends to receive a prize!\n"
|
"Help Olive visit all 8 of her friends to receive a prize!\n"
|
||||||
"Hurry though, things change quickly in the ocean!\n"
|
"Hurry though, things change quickly in the ocean!\n"
|
||||||
"Next friend: %08o\n"
|
"Next friend: %08o\n"
|
||||||
|
@ -208,17 +210,8 @@ int
|
||||||
rebind(struct in_addr *addr)
|
rebind(struct in_addr *addr)
|
||||||
{
|
{
|
||||||
static int offset = 0;
|
static int offset = 0;
|
||||||
char token[200];
|
|
||||||
size_t tokenlen;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
tokenlen = read_token("octopus",
|
|
||||||
key, sizeof(key),
|
|
||||||
token, sizeof(token));
|
|
||||||
if (-1 == tokenlen) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 1; i < 8; i += 1) {
|
for (i = 1; i < 8; i += 1) {
|
||||||
int ret;
|
int ret;
|
||||||
int last_guy;
|
int last_guy;
|
||||||
|
@ -317,8 +310,6 @@ loop()
|
||||||
FD_SET(bound_ports[i].fd, &rfds);
|
FD_SET(bound_ports[i].fd, &rfds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait forever. There's no need to switch ports if nobody's doing
|
|
||||||
anything. */
|
|
||||||
while (-1 == select(nfds+1, &rfds, NULL, NULL, &timeout)) {
|
while (-1 == select(nfds+1, &rfds, NULL, NULL, &timeout)) {
|
||||||
if (EINTR == errno) {
|
if (EINTR == errno) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -340,11 +331,12 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int i;
|
int i;
|
||||||
time_t last = time(NULL);
|
time_t last_bind = 0;
|
||||||
|
time_t last_token = 0;
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
|
|
||||||
/* The random seed isn't super important here. */
|
/* The random seed isn't super important here. */
|
||||||
srand(last);
|
srand(time(NULL));
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
if (-1 == inet_aton(argv[1], &addr)) {
|
if (-1 == inet_aton(argv[1], &addr)) {
|
||||||
|
@ -365,20 +357,26 @@ main(int argc, char *argv[])
|
||||||
for (i = 1; i < PORTS; i += 1) {
|
for (i = 1; i < PORTS; i += 1) {
|
||||||
bound_ports[i].fd = -1;
|
bound_ports[i].fd = -1;
|
||||||
}
|
}
|
||||||
if (-1 == rebind(&addr)) {
|
|
||||||
perror("initial binding");
|
|
||||||
return EX_IOERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (loop()) {
|
do {
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
|
|
||||||
if (last + 4 < now) {
|
if (last_token + 60 < now) {
|
||||||
last = now;
|
last_token = now;
|
||||||
|
while (NULL == fgets(token, sizeof(token), stdin)) {
|
||||||
|
if (-1 == fseek(stdin, 0, SEEK_SET)) {
|
||||||
|
/* Non-seekable stdin: we're done. */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (tokenlen = 0; token[tokenlen] && (token[tokenlen] != '\n'); tokenlen += 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (last_bind + 4 < now) {
|
||||||
|
last_bind = now;
|
||||||
if (-1 == rebind(&addr)) break;
|
if (-1 == rebind(&addr)) break;
|
||||||
}
|
}
|
||||||
}
|
} while (loop());
|
||||||
|
|
||||||
perror("main loop");
|
return 0;
|
||||||
return EX_IOERR;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
../../../include/token.c
|
|
|
@ -1 +0,0 @@
|
||||||
../../../include/token.h
|
|
|
@ -1 +0,0 @@
|
||||||
octopus
|
|
|
@ -1,2 +0,0 @@
|
||||||
|
|
||||||
Àñõ®¶'çå6Œ™²¤Y=
|
|
|
@ -1,3 +0,0 @@
|
||||||
™_ËÞùmóG`
|
|
||||||
à
|
|
||||||
%M
|
|
Loading…
Reference in New Issue