forked from JaiMaaSheeravali/Roosh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
206 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <string> | ||
void print_instructions(std::string p); | ||
void print_no_access_to_level(); | ||
|
||
bool check_password(int level); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#pragma once | ||
|
||
int roosh_exec_tutorial(char **args, int num_args); | ||
int roosh_tutorial(); | ||
int create_tutorial_folder(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <iostream> | ||
#include <cstring> | ||
#include <fstream> | ||
using namespace std; | ||
|
||
const char *passwd_list[] = { | ||
|
||
"XfwQrTY8drdyR8CDdpcgBSYq", | ||
"B7GXVdmXZGDgBXjUrP2aKhnc", | ||
"j7uvv2CwUFSujANxHnM2dM4L", | ||
"wdJPxNNK66cUGra6JJjbCLRe", | ||
"8X8jevLsYwWpZkhvDHXUWu5Q", | ||
"fcyHejqsN4LUgqVD9SACZLzh", | ||
"Y99Ch3hbZy8QhDm639BCxayF", | ||
"Q9n59xHrrTmyRcWc6Ag8m8d9", | ||
"JtfU4VftpqH3wbB6cVdjdLqr", | ||
"NZAbCFvQuSrPmDgrQHRCj2GZ"}; | ||
|
||
string curr_pass; | ||
int curr_level = 1; | ||
bool unlocked[10]; | ||
|
||
void print_instructions(string p) | ||
{ | ||
string line; | ||
ifstream myfile(p); | ||
if (myfile.is_open()) | ||
{ | ||
while (getline(myfile, line)) | ||
{ | ||
cout << line << '\n'; | ||
} | ||
myfile.close(); | ||
} | ||
else | ||
cout << "Unable to open file.\nPlease try again."; | ||
} | ||
|
||
void print_no_access_to_level() | ||
{ | ||
cout << "Oops! you need to solve all previous levels to unlock this level. Currently you can attempt level " << curr_level << " .\n"; | ||
} | ||
|
||
bool check_password(int level) | ||
{ | ||
cout << "enter password\n"; | ||
cin >> curr_pass; | ||
if (curr_pass == passwd_list[level - 1]) | ||
{ | ||
cout << "Success!!\n"; | ||
unlocked[level] = 1; | ||
curr_level++; | ||
} | ||
else | ||
cout << "wrong password!!\n"; | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
#include <sstream> | ||
#include <cstring> | ||
#include <unistd.h> | ||
#include <pwd.h> | ||
#include "../include/parse.hpp" | ||
#include "../include/launch.hpp" | ||
#include "../include/levels.hpp" | ||
#include "../include/tutorial.hpp" | ||
|
||
using namespace std; | ||
|
||
string home_dir; | ||
extern bool unlocked[10]; | ||
extern int level; | ||
int roosh_tutorial(); | ||
|
||
int create_tutorial_folder() | ||
{ | ||
char *home; | ||
struct passwd *pw = getpwuid(getuid()); | ||
home = strdup(pw->pw_dir); | ||
home_dir = home; | ||
roosh_launch("cp -r tutorial " + home_dir); | ||
return 0; | ||
} | ||
|
||
int roosh_exec_tutorial(char **args, int num_args) | ||
{ | ||
//number of arguments can be => | ||
// 1 i.e. tutorial | ||
// 3 i.e. tutorial level <1-10> | ||
// 4 i.e. tutorial level <1-10> password | ||
|
||
//tutorial cmd | ||
if (num_args == 1) | ||
{ | ||
|
||
return roosh_tutorial(); | ||
} | ||
|
||
// case of 3 or 4 arguments | ||
else if ((num_args == 3 || num_args == 4) && (strcmp(args[1], "level") == 0)) | ||
{ | ||
if (num_args == 4) | ||
{ //error if fourth arg is not password | ||
if ((strcmp(args[3], "password") != 0)) | ||
{ | ||
cerr << "no such command exists\n"; | ||
return 1; | ||
} | ||
} | ||
|
||
//parse the level value to int | ||
int level; | ||
stringstream ss; | ||
ss << args[2]; | ||
ss >> level; | ||
|
||
//level must be b/w 1-10 | ||
if (level > 0 && level <= 10 && (strlen(args[2]) == level / 10 + 1)) | ||
{ | ||
|
||
if (num_args == 3) | ||
{ | ||
//display corresponding instructins | ||
string path = (home_dir + "/tutorial/lvl_instrns/level" + args[2] + ".txt"); | ||
print_instructions(path); | ||
|
||
//navigate to corresponding directory | ||
path = (home_dir + "/tutorial/tutorial_levels/level" + args[2]); | ||
chdir(path.c_str()); | ||
} | ||
|
||
else | ||
{ // for level 1 just check the password entered | ||
if (level == 1) | ||
{ | ||
check_password(level); | ||
return 1; | ||
} | ||
//else first check whether the level is unlocked or not | ||
else if (unlocked[level - 1]) | ||
{ | ||
check_password(level); | ||
return 1; | ||
} | ||
|
||
else | ||
{ | ||
print_no_access_to_level(); | ||
} | ||
} | ||
return 1; | ||
} | ||
|
||
else | ||
{ | ||
//display error if level is not an integer bw 1 nd 10 | ||
cerr << "Please enter a level between 1 to 10.\n"; | ||
return 1; | ||
} | ||
} | ||
|
||
else | ||
{ | ||
cerr << "no such command exists\n"; | ||
return 1; | ||
} | ||
} | ||
|
||
int roosh_tutorial() | ||
{ | ||
cout << "My tutorial :)\n"; | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Commands you may need to solve the level | ||
ls cd cat |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Commands you may need to solve the level | ||
ls cd cat | ||
|
||
Hint: ever heard about hidden files?? |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
XfwQrTY8drdyR8CDdpcgBSYq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The password is B7GXVdmXZGDgBXjUrP2aKhnc |