From 1042cb27864c832913612e1beff6ad2d53c04847 Mon Sep 17 00:00:00 2001 From: WT Michael Date: Tue, 2 Jan 2024 07:27:13 +0000 Subject: [PATCH] kinda works - trying to figure out if I can do dynamic timing or not --- .gitignore | 2 +- endlessh.c | 35 ++++++++++++++++++++++++++++++++--- stillalive.h | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 stillalive.h diff --git a/.gitignore b/.gitignore index 6753b35..47973dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ endlessh - +.vscode diff --git a/endlessh.c b/endlessh.c index b14de73..f935706 100644 --- a/endlessh.c +++ b/endlessh.c @@ -26,7 +26,9 @@ #include #include -#define ENDLESSH_VERSION 1.1 +#include "stillalive.h" + +#define ENDLESSH_VERSION 1.2 #define DEFAULT_PORT 2222 #define DEFAULT_DELAY 10000 /* milliseconds */ @@ -120,6 +122,7 @@ struct client { struct client *next; int port; int fd; + int index; }; static struct client * @@ -134,6 +137,7 @@ client_new(int fd, long long send_next) c->next = 0; c->fd = fd; c->port = 0; + c->index=0; /* Set the smallest possible recieve buffer. This reduces local * resource usage and slows down the remote end. @@ -606,9 +610,30 @@ static struct client * sendline(struct client *client, int max_line_length, unsigned long *rng) { char line[256]; - int len = randline(line, max_line_length, rng); - for (;;) { + //int len = randline(line, max_line_length, rng); + for (int c = 0;c < LYRIC_COUNT+CREDIT_COUNT;c++) { + long long nextdelay=LYRIC_TIMES[client->index%LYRIC_COUNT]; + /*logmsg(log_debug, "epochms_1=%d", epochms()); + logmsg(log_debug, "send_next_1=%d", client->send_next); + logmsg(log_debug, "adding %d ms", nextdelay*1000); + client->send_next=epochms()-(nextdelay*1000); + logmsg(log_debug, "epochms_2=%d", epochms()); + logmsg(log_debug, "send_next_2=%d", client->send_next);*/ + char *wordline; + if (client->index >= LYRIC_COUNT && client->index < LYRIC_COUNT+CREDIT_COUNT) { + logmsg(log_debug,"index=%d LYRIC_COUNT=%d effective_index=%d", client->index, LYRIC_COUNT, client->index%LYRIC_COUNT); + wordline=CREDIT_LINES[client->index%LYRIC_COUNT]; + } else if (client->index >= LYRIC_COUNT+CREDIT_COUNT) { + logmsg(log_debug,"index=%d LYRIC_COUNT+CREDIT_COUNT=%d effective_index=%d", client->index, LYRIC_COUNT+CREDIT_COUNT, client->index%(LYRIC_COUNT+CREDIT_COUNT)); + wordline=APERTURE_LINES[client->index%(LYRIC_COUNT+CREDIT_COUNT)]; + } else wordline=LYRIC_LINES[client->index]; + int len = strlen(wordline)+2; + for (int n = 0; n < len-2; n++) line[n]=wordline[n]; + line[len-2] = 13; + line[len-1] = 10; + logmsg(log_debug, "line='%s' len='%d'", wordline, len-2); ssize_t out = write(client->fd, line, len); + client->index = client->index+1; logmsg(log_debug, "write(%d) = %d", client->fd, (int)out); if (out == -1) { if (errno == EINTR) { @@ -622,6 +647,10 @@ sendline(struct client *client, int max_line_length, unsigned long *rng) } else { client->bytes_sent += out; statistics.bytes_sent += out; + if (client->index == (LYRIC_COUNT+CREDIT_COUNT+APERTURE_COUNT)) { + client_destroy(client); + return 0; + } return client; } } diff --git a/stillalive.h b/stillalive.h new file mode 100644 index 0000000..84f0067 --- /dev/null +++ b/stillalive.h @@ -0,0 +1,37 @@ +/* + * The +*/ + +#define LYRIC_COUNT 57 +#define CREDIT_COUNT 7 +#define APERTURE_COUNT 23 + +static char* LYRIC_LINES[LYRIC_COUNT]={"This was a triumph.","Im making a note here:","huge success.","Its hard to overstate","My satisfaction.","Aperture Science.","We do what we must","Because we can.","For the good of all of us.","Except the ones who are dead.","But theres no sense crying","Over every mistake.","You just keep on trying","Till you run out of cake.","And the Science gets done.","And you make a neat gun.","For the people who are","Still alive.","Im not even angry.","Im being so sincere right now.","Even though you broke my heart.","And killed me.","And tore me to pieces.","And threw every piece into a fire.","As they burned it hurt because","I was so happy for you!","Now these points of data","Make a beautiful line.","And were out of beta.","Were releasing on time.","So Im GLaD. I got burned.","Think of all the things we learned","For the people who are","Still alive.","Go ahead and leave me.","I think I prefer to stay inside.","Maybe youll find someone else","To help you.","Maybe Black Mesa...","THAT WAS A JOKE, HA HA, FAT CHANCE.","Anyway this cake is great","Its so delicious and moist","Look at me still talking","when theres science to do","When I look out there","It makes me GLaD Im not you.","Ive experiments to run","There is research to be done","On the people who are","Still alive.","And believe me I am still alive","Im doing science and Im still alive","I feel FANTASTIC and Im still alive","While youre dying Ill be still alive","And when youre dead I will be still alive","Still alive","Still alive."}; +static int LYRIC_TIMES[LYRIC_COUNT]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + +static char* CREDIT_LINES[CREDIT_COUNT]={"...","...","Still Alive by Jonathon Coulton", "EndleSSH by skeeto", "\"Still Alive\" fork by WTMike24","...","..."}; + +static char* APERTURE_LINES[APERTURE_COUNT]={ +" .,-:;//;:=,", +" . :H@@@MM@M#H/ ,+%;,", +" ,/X+ +M@@M@MM%/ %HMMM@X/,", +" -+@MM; %M@@MH+ XMMMM@MMMM@+-", +" ;@M@@M/ XM@X;. +XXXXXHHH@M@M#@/.", +" %MM@@MH @%= _,_.,_.._.", +" #@@@MX. -%HX#$%%%:;", +" =- @M@M$ .;@MMMM@MM:", +" X@\\ @MM/ +MM@@@M$", +",@M@H: @: X#@@@@-", +",@@@MMX /H @M@M=", +".H@@@@M@+ %MM+ %#$.", +" /MMMM@MMH/. XM@MH ;", +" #%+%%XHH@$= , .H@@@@MX", +" ..__.,,__._,. -%H ,@@@@@MX,", +" .%MM@@@HHHXX&#$%+ .:#MMX =M@@MM%.", +" =XMMM@MM@MM#H; +HMM@M+ /MMMX=", +" =%@M@M#@$ &@MM@@@M; %M%=", +" ,:+$+- H#MMMMMMM@/ =,", +" ++%%%%+/:-.", +"...", +"...", +"Goodbye!"}; \ No newline at end of file