learning-c/dvorakmsdos.c

102 lines
No EOL
4 KiB
C

#include "dvorakmsdos.h"
#include <stdio.h>
#include <string.h>
#ifdef _WIN32
#include <conio.h>
#define GETCH() _getch()
#else
#include <termios.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#define GETCH() getch()
char getch();
#endif
void loginmenu(int USER, int PASS) {
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
// we now use w.ws_col as width and w.ws_row as height
int repeat = 0;
for (int height=w.ws_row; height>1; height--) {
for (int width=w.ws_col; width>0; width--) {
if ((w.ws_col/2+11 >= width && width >= w.ws_col/2-11) && (w.ws_row/2+3 >= height && height >= w.ws_row/2-2)) {
if ((w.ws_row/2+3 == height) && repeat == 0) {
printf("Welcome To DvorakMSDOS!");
repeat++;
} else if ((w.ws_row/2+2 == height) && repeat == 1) {
if (USER == 1) {
printf("Username: admin ");
} else {
printf("Username: ");
}
repeat++;
} else if ((w.ws_row/2+1 == height) && repeat == 2) {
if (PASS == 1) {
printf("Password: **** █████████████████████████████████████████████████████████████████████");
} else {
printf("Password: █████████████████████████████████████████████████████████████████████");
}
repeat++;
}
} else {
printf("█");
}
}
}
}
void msmain() {
int level = 0;
int userfail = 0;
#ifndef _WIN32
while (1) {
char GETCH();
switch (level) {
case 0:
loginmenu(0, 0);
if (userfail == 0) {
printf("Enter your username: ");
} else {
printf("Wrong username, Try again: ");
}
fflush(stdout); // this forces the buffer to print NOW, fixing the "bug" in which it prints out everything AFTER the next line (scanf)
char username[13];
scanf(" %12[^\n]", username);
while (getchar() != '\n') {}
if (strcmp(username, "admin") != 0) {
userfail = 1;
} else {
userfail = 0;
system("clear");
level++;
}
break;
case 1:
loginmenu(1, 0);
if (userfail == 0) {
printf("Enter your password: ");
} else {
printf("Wrong password, Try again: ");
}
fflush(stdout); // this forces the buffer to print NOW, fixing the "bug" in which it prints out everything AFTER the next line (scanf)
char password[13];
scanf(" %12[^\n]", password);
while (getchar() != '\n') {}
if (strcmp(password, "1234") != 0) {
userfail = 1;
} else {
int userfail = 0;
system("clear");
level++;
}
break;
case 2:
printf("you did it");
}
}
#else
printf("fuck you for using windows get out of here and run this on an unix system") // ofcourse this is temporary
return;
#endif
}