|
@@ -79,11 +79,17 @@ void render_sleep(void) {
|
|
|
if (render_overlimit)
|
|
|
return;
|
|
|
|
|
|
- if (current_render.speed) {
|
|
|
- ms_sleep(current_render.speed * 100);
|
|
|
+ if (current_render.speed) { // * 100 still too slow.
|
|
|
+ ms_sleep(current_render.speed * 10);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void write_color(int fd, int color) {
|
|
|
+ char buffer[10];
|
|
|
+ sprintf(buffer, "\x1b[%dm", color);
|
|
|
+ write(fd, buffer, strlen(buffer));
|
|
|
+}
|
|
|
+
|
|
|
const char * process_trigger(int fd, const char * cp) {
|
|
|
char ch;
|
|
|
int i, x, y;
|
|
@@ -104,7 +110,7 @@ const char * process_trigger(int fd, const char * cp) {
|
|
|
};
|
|
|
|
|
|
if ((i > 0) && (i < 80)) {
|
|
|
-#ifdef LOGGING
|
|
|
+#ifdef BUGGER
|
|
|
fprintf(fp, "DEL %02d\n", i);
|
|
|
#endif
|
|
|
for (x = 0; x < i; x++ ) {
|
|
@@ -124,6 +130,7 @@ const char * process_trigger(int fd, const char * cp) {
|
|
|
i += (*cp) - '0';
|
|
|
cp++;
|
|
|
};
|
|
|
+ write_color(fd, i);
|
|
|
break;
|
|
|
|
|
|
case 'G':
|
|
@@ -156,7 +163,7 @@ const char * process_trigger(int fd, const char * cp) {
|
|
|
cp++;
|
|
|
};
|
|
|
if ( ( i > 0 ) && ( i < 10) ) {
|
|
|
-#ifdef LOGGING
|
|
|
+#ifdef BUGGER
|
|
|
fprintf(fp, "RENDER %d\n", i);
|
|
|
#endif
|
|
|
|
|
@@ -172,7 +179,7 @@ const char * process_trigger(int fd, const char * cp) {
|
|
|
cp++;
|
|
|
};
|
|
|
if ( ( i > 0 ) && ( i < 10) ) {
|
|
|
-#ifdef LOGGING
|
|
|
+#ifdef BUGGER
|
|
|
fprintf(fp, "SPEED %d\n", i);
|
|
|
#endif
|
|
|
|
|
@@ -188,7 +195,7 @@ const char * process_trigger(int fd, const char * cp) {
|
|
|
cp++;
|
|
|
};
|
|
|
if ( ( i > 0 ) && ( i < 10) ) {
|
|
|
-#ifdef LOGGING
|
|
|
+#ifdef BUGGER
|
|
|
fprintf(fp, "PAWS %d\n", i);
|
|
|
#endif
|
|
|
// sleep(i);
|
|
@@ -205,15 +212,37 @@ const char * process_trigger(int fd, const char * cp) {
|
|
|
|
|
|
void render_effect(int fd, char ch) {
|
|
|
int effect = current_render.effect;
|
|
|
-
|
|
|
- render_sleep();
|
|
|
- int x = write(fd, &ch, 1);
|
|
|
-
|
|
|
- return;
|
|
|
+ int l;
|
|
|
+ char space = ' ';
|
|
|
+ char bs = '\b';
|
|
|
|
|
|
switch (effect) {
|
|
|
+ case 1:
|
|
|
+ // CHAR + SPC + BS
|
|
|
+ render_sleep();
|
|
|
+ write(fd, &ch, 1);
|
|
|
+ render_sleep(); // Maybe extra sleep here?
|
|
|
+ write(fd, &space, 1);
|
|
|
+ render_sleep();
|
|
|
+ write(fd, &bs, 1);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ // CHAR + 8 spaces + 8 BS
|
|
|
+ render_sleep();
|
|
|
+ write(fd, &ch, 1);
|
|
|
+ for(l = 0; l < 8; l++) {
|
|
|
+ render_sleep();
|
|
|
+ write(fd, &space, 1);
|
|
|
+ }
|
|
|
+ for(l = 0; l < 8; l++) {
|
|
|
+ render_sleep();
|
|
|
+ write(fd, &bs, 1);
|
|
|
+ }
|
|
|
+ break;
|
|
|
case 0:
|
|
|
default:
|
|
|
+ // NORMAL
|
|
|
+ render_sleep();
|
|
|
write(fd, &ch, 1);
|
|
|
break;
|
|
|
}
|
|
@@ -228,7 +257,7 @@ void render( int fd, const char * string_out ) {
|
|
|
|
|
|
reset_render();
|
|
|
|
|
|
-#ifdef LOGGING
|
|
|
+#ifdef BUGGER
|
|
|
fprintf(fp, "render(%d, %s)\n", fd, string_out);
|
|
|
fflush(fp);
|
|
|
#endif
|
|
@@ -245,7 +274,7 @@ void render( int fd, const char * string_out ) {
|
|
|
current_render.speed = 0;
|
|
|
};
|
|
|
|
|
|
-#ifdef LOGGING
|
|
|
+#ifdef BUGGER
|
|
|
fprintf(fp, "re(%c)\n", *cp);
|
|
|
fflush(fp);
|
|
|
#endif
|
|
@@ -254,7 +283,7 @@ void render( int fd, const char * string_out ) {
|
|
|
cp++;
|
|
|
};
|
|
|
|
|
|
-#ifdef LOGGING
|
|
|
+#ifdef BUGGER
|
|
|
fprintf(fp, "at trigger: (%s)\n", cp);
|
|
|
fflush(fp);
|
|
|
#endif
|
|
@@ -264,7 +293,7 @@ void render( int fd, const char * string_out ) {
|
|
|
// Ok, we're pointing at the trigger -- do something.
|
|
|
cp = process_trigger(fd, cp);
|
|
|
|
|
|
-#ifdef LOGGING
|
|
|
+#ifdef BUGGER
|
|
|
fprintf(fp, "after trigger: (%s)\n", cp);
|
|
|
fflush(fp);
|
|
|
#endif
|
|
@@ -273,6 +302,11 @@ void render( int fd, const char * string_out ) {
|
|
|
|
|
|
// We still might be under a rendering effect.
|
|
|
while (*cp != 0) {
|
|
|
+ elapsed = time(NULL)-start;
|
|
|
+ if (elapsed > SLEEP_LIMIT) {
|
|
|
+ render_overlimit = 1;
|
|
|
+ current_render.speed = 0;
|
|
|
+ };
|
|
|
// write(fd, cp, 1);
|
|
|
render_effect(fd, *cp);
|
|
|
cp++;
|
|
@@ -284,6 +318,10 @@ void harry_event(int fd) {
|
|
|
char buffer[100];
|
|
|
int r = random() % 5;
|
|
|
|
|
|
+ // This is no where near finished, BUT!
|
|
|
+ // TO FIX: Remember the last phrase used,
|
|
|
+ // and don't repeat (the last two)!
|
|
|
+
|
|
|
const char * phrases[] =
|
|
|
{
|
|
|
"Hahaha",
|
|
@@ -294,16 +332,9 @@ void harry_event(int fd) {
|
|
|
};
|
|
|
const char * cp;
|
|
|
|
|
|
-#ifdef LOGGING
|
|
|
- fprintf(fp, "harry_event(%d)\n", fd);
|
|
|
- fflush(fp);
|
|
|
-#endif
|
|
|
-
|
|
|
cp = phrases[r];
|
|
|
|
|
|
sprintf(buffer, "^S2%s^P2^D%02d", cp, (int)strlen(cp));
|
|
|
- // write(fd, ) is working just fine here!
|
|
|
- // write(fd, buffer, strlen(buffer));
|
|
|
|
|
|
#ifdef LOGGING
|
|
|
fprintf(fp, "harry_event: render(%d, \"%s\")\n", fd, buffer);
|
|
@@ -326,6 +357,10 @@ void pcopy(char * pstring, char * str) {
|
|
|
str[len] = 0;
|
|
|
}
|
|
|
|
|
|
+/*
|
|
|
+This only works for those few idiots that use SSH,
|
|
|
+the Mystic broken SSH!
|
|
|
+ */
|
|
|
int locate_user(const char *alias) {
|
|
|
FILE * user;
|
|
|
char buffer[0x600];
|
|
@@ -394,8 +429,7 @@ int main(int argc, char * argv[])
|
|
|
// Telnet: -ML0 -ST0
|
|
|
|
|
|
|
|
|
- //
|
|
|
-
|
|
|
+ // Locate username (if given) in the command line
|
|
|
// -U<username>
|
|
|
for (int x = 0; x < argc; x++) {
|
|
|
if (strncmp("-U", argv[x], 2) == 0) {
|
|
@@ -414,7 +448,7 @@ int main(int argc, char * argv[])
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
- // With IGNBRK I don't think I need this anymore.
|
|
|
+ // With IGNBRK I don't think I need this anymore. (Nope!)
|
|
|
// signal(SIGINT, SIG_IGN);
|
|
|
|
|
|
pid = forkpty(&master, NULL, NULL, NULL);
|
|
@@ -434,8 +468,6 @@ int main(int argc, char * argv[])
|
|
|
args[x] = argv[x];
|
|
|
};
|
|
|
args[x] = NULL;
|
|
|
- // char *args[] = { "vim", "test.txt", NULL }; // argv; //{ NULL };
|
|
|
-
|
|
|
// run Mystic, run!
|
|
|
execvp( TARGET, args);
|
|
|
}
|
|
@@ -492,7 +524,7 @@ int main(int argc, char * argv[])
|
|
|
if ( select(master+1, &read_fd, &write_fd, &except_fd, &timeout) == 0 ) {
|
|
|
// This means timeout!
|
|
|
harry_event(STDOUT_FILENO);
|
|
|
-#ifdef LOGGING
|
|
|
+#ifdef BUGGER
|
|
|
fprintf(fp, "%s : TICK\n", it_is_now());
|
|
|
fprintf(fp, "STDOUT is %d\n", STDOUT_FILENO);
|
|
|
#endif
|
|
@@ -540,6 +572,7 @@ int main(int argc, char * argv[])
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // Restore terminal
|
|
|
tcsetattr(1, TCSAFLUSH, &orig1);
|
|
|
#ifdef LOGGING
|
|
|
fclose(fp);
|