@21natzil/

JAMMMMMM (Tunnelbridge#8408)

C++11

No description

fork
loading
Files
  • main.cpp
  • filetree.txt
  • README.txt
  • users\j\Documents\test.txt
  • users\j\Documents\test2.txt
  • users\j\Documents\test3.txt
  • users\j\password
  • users\j\test.bloop
  • users\yo\password

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.3201257615131896","path":"main.cpp","file":{"path":"main.cpp","content":{"asEncoding":{"base64":"Ly8gQWxsIHNjb3JlcyBvdXQgb2YgNQovLyBGaWxlIFN5c3RlbTogNAovLyAgIC0gWW91ciBmaWxlIHN5c3RlbSBkaWQgZXZlcnl0aGluZyByaWdodC4gSXQgd2FzIGVhc2lseSB0cmF2ZXJzYWJsZSwgbWFraW5nIGZpbGVzIGFuZCBkaXJlY3RvcmllcyB3YXMgc2ltcGxlLCBhbmQgeW91IHN0b3BwZWQgcGVvcGxlIGZyb20gZW50ZXJpbmcgb3RoZXIgcGVvcGxlJ3MgZmlsZXMuIEkganVzdCB3aXNoIHlvdSBsZXQgcGVvcGxlIGludG8gaW50ZXJuYWwgZmlsZXMsIGFuZCBwcmV2ZW50ZWQgYWNjZXNzLiAKLy8gQ29kaW5nOiAzCi8vICAgLSBXcml0aW5nIHRvIGZpbGVzIHdhcyBwcmV0dHkgZWFzeSEgSSBqdXN0IHdpc2ggdGhlcmUgd2FzIGEgd2F5IHRvIGVkaXQgb3IgZGVsZXRlIGZpbGVzLiBBbHNvLCB0aGUgbGFuZ3VhZ2UgaXRzZWxmIHdhcyBxdWl0ZSBsaW1pdGVkLiAKLy8gTG9naW46IDMKLy8gICAtIFlvdXIgbG9naW4gd2FzIGZpbmUsIEkgZmVlbCB5b3UgbGlrZSBjb3VsZCBoYXZlIGFuZCBzaG91bGQgaGF2ZSBkb25lIG1vcmUgd2l0aCBpdCBob3dldmVyLgovLyBJbnRlcmZhY2U6IDIKLy8gICAtIFlvdXIgaW50ZXJmYWNlIGxlZnQgbXVjaCB0byBiZSBkZXNpcmV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Y29tbWFuZD09InJ1biIpewogICAgaW50ZXJwcmV0KGFyZ3MpOwogIH1lbHNlIGlmKGNvbW1hbmQ9PSJhcHBlbmQiKXsKICAgIGFwcGVuZF9maWxlKGFyZ3MpOwogIH1lbHNlewogICAgY291dDw8IkNvbW1hbmQgXCIiPDxjb21tYW5kPDwiXCIgbm90IGZvdW5kLlxuIjsKICB9Cn0KCmludCBtYWluKCkgewogIGJ1aWxkX3RyZWUoKTsKICBsb2dpbigpOwogIHN0cmluZyBpbnB1dDsKICBnZXRsaW5lKGNpbixpbnB1dCk7CiAgd2hpbGUob24pewogICAgY291dDw8Y3VycmVudF9kaXI8PCIgPj4+ICI7CiAgICBnZXRsaW5lKGNpbixpbnB1dCk7CiAgICBleGVjdXRlKGlucHV0KTsKICB9CiAgLyppbnQgbFsyXT17MiwzfTsKICBjb3V0PDwoZXZhbHVhdGUoIjIrMyIsbCkpPDxlbmRsOyovCn0="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
// All scores out of 5
// File System: 4
//   - Your file system did everything right. It was easily traversable, making files and directories was simple, and you stopped people from entering other people's files. I just wish you let people into internal files, and prevented access. 
// Coding: 3
//   - Writing to files was pretty easy! I just wish there was a way to edit or delete files. Also, the language itself was quite limited. 
// Login: 3
//   - Your login was fine, I feel you like could have and should have done more with it however.
// Interface: 2
//   - Your interface left much to be desired. Yes, you did indeed have the directory path displayed on the command line which was good, but no colors, and felt squished.
// EOO: 4
//   - I really was able to learn and operate this OS very quickly. Commands were named well, and things weren't finicky. Maybe add some more examples for the commands?
// Docs: 3
//   - The help menu really was quite helpful, however I wish you allowed people to just get help for a specific command, and not have to view all the commands looking for one bit of information.
// Extras: 1
//   - I appreciated that you took the time to impliment a language, +1 for that.
// TOTAL: 20 / 35

#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <ctime>
//I have no idea what I'm doing, but welp, here we go!
using namespace std;

string current_user;
string current_dir;
map<string,vector<string> > file_tree;
bool on=true;

void build_tree(){
  extern map<string,vector<string> > file_tree;
  ifstream tree;
  tree.open("filetree.txt");
  string line;
  string dir;
  while(getline(tree,line)){
    if(line=="#"){
      getline(tree,dir);
      file_tree[dir]=vector<string> (0);
    }else{
      file_tree[dir].push_back(line);
    }
  }
}

void save_tree(){
  ofstream tree;
  tree.open("filetree.txt");
  for(auto i: file_tree){
    tree<<"#\n"<<i.first<<endl;;
    for(auto j: i.second){
      tree<<j<<endl;
    }
  }
}

bool create_account(){
  extern map<string,vector<string> > file_tree;
  extern string current_user,current_dir;
  string username;
  string password;
  string pass_path;
  FILE *working_file;
  cout<<"Enter new username: ";
  cin>>username;
  if(file_tree.count("users\\"+username+"\\")||username=="new"||username==""||username=="shutdown"){
    cout<<"Username taken or invalid.\n";
    return false;
  }
  cout<<"Enter password: ";
  cin>>password;
  pass_path="users\\"+username+"\\password";
  working_file=fopen(pass_path.c_str(),"w");
  fprintf(working_file,"%s",password.c_str());
  fclose(working_file);
  //cout<<pass_path<<endl;
  cout<<"Since we do not value your privacy and security, we store your password in an unencrypted file. You're Welcome!\n";
  current_user=username;
  current_dir="users\\"+username+"\\";
  file_tree["users\\"].push_back(current_dir);
  file_tree[current_dir]={current_dir+"password",current_dir+"Documents\\",current_dir+"Programs\\"};
  file_tree[current_dir+"Documents\\"]=vector<string> (0);
  file_tree[current_dir+"Programs\\"]=vector<string> (0);
  return true;
}

bool authenticate(FILE *user_file,string user){
  //Authentification!
  extern string current_user,current_dir;
  string input;
  char password[50];
  fscanf(user_file,"%s",password);
  for(int i=0; i<3; i++){
    cout<<"Enter your password: ";
    cin>>input;
    if(input==password){
      current_user=user;
      current_dir="users\\"+user+"\\";
      fclose(user_file);
      cout<<"Welcome, "+user+'\n';
      return true;
    }
  }
  cout<<"Quick tip: If you can't remember your password, then just look at your unencrypted password file!\nYou're Welcome!\n";
  fclose(user_file);
  return false;
}

void write_file(string file_name){
  if(file_name.find('\\')!=file_name.npos||file_name.find('/')!=file_name.npos){
    cout<<"File names may not contain either '\\' or '/'.\n";
    return;
  }
  vector<string> contents=file_tree[current_dir];
  auto iter=contents.begin();
  for(iter=contents.begin(); iter!=contents.end(); iter++){
    if(*iter==current_dir+file_name){
      break;
    }
  }
  if(iter==contents.end()){
    file_tree[current_dir].push_back(current_dir+file_name);
  }
	ofstream file;
	file.open(current_dir+file_name);
	string input;
	while(getline(cin,input)){
		if(input=="###"){break;}
		file<<input<<'\n';
	}
	file.close();
}

void append_file(string file_name){
  if(file_name.find('\\')!=file_name.npos||file_name.find('/')!=file_name.npos){
    cout<<"File names may not contain either '\\' or '/'.\n";
    return;
  }
	string input;
  ifstream ifile;
  ifile.open(current_dir+file_name);
  while(getline(ifile,input)){
    cout<<input<<endl;
  }
  ifile.close();
	ofstream ofile;
	ofile.open(current_dir+file_name,ios::app);
	while(getline(cin,input)){
		if(input=="###"){break;}
		ofile<<input<<'\n';
	}
	ofile.close();
}

void view_file(string file_name){
  if(file_name.find('\\')!=file_name.npos||file_name.find('/')!=file_name.npos){
    cout<<"File names may not contain either '\\' or '/'.\n";
    return;
  }
  cout<<"START OF FILE:\n";
	string input;
  ifstream ifile;
  ifile.open(current_dir+file_name);
  while(getline(ifile,input)){
    cout<<input<<endl;
  }
  ifile.close();
  cout<<"END OF FILE\n";
}

/*void delete_file(string file_name){
  if(file_name.find('\\')!=file_name.npos||file_name.find('/')!=file_name.npos){
    cout<<"File names may not contain either '\\' or '/'.\n";
    return;
  }
  vector<string> contents=file_tree[current_dir];
  auto iter=contents.begin();
  for(iter=contents.begin(); iter!=contents.end(); iter++){
    if(*iter==current_dir+file_name){
      file_tree[current_dir].erase(iter);
    }
  }
  if(iter==contents.end()){
    cout<<"File does not exist.\n";
    return;
  }
  if(!remove((current_dir+file_name).c_str())){
    cout<<"Error\n";
  }
}*/

/*void rename_file(string file_name, string new_name){
  if(file_name.find('\\')!=file_name.npos||file_name.find('/')!=file_name.npos||new_name.find('\\')!=new_name.npos||new_name.find('/')!=new_name.npos){
    cout<<"File names may not contain either '\\' or '/'.\n";
    return;
  }
  if(new_name==""){
    cout<<"Must have second parameter new name.\n";
    return;
  }
  vector<string> contents=file_tree[current_dir];
  auto iter=contents.begin();
  for(iter=contents.begin(); iter!=contents.end(); iter++){
    if(*iter==current_dir+file_name){
      break;
    }
  }
  if(iter==contents.end()){
    cout<<"File does not exist.\n";
    return;
  }
  if(!rename((current_dir+file_name).c_str(),(current_dir+new_name).c_str())){
    cout<<"Error.\n";
  }
}*/

int evaluate(string expression,vector<int> vars){
  //cout<<"Debug: "<<expression<<endl;
  string temp;
  int pos=0;
  for(auto i: expression){
    if(i=='['||i==' '){
      pos++;
      continue;
    }else if(i=='+'){
      return(stoi(temp)+evaluate(expression.substr(pos+1,expression.size()-pos),vars));
    }else if(i=='*'){
      return(stoi(temp)*evaluate(expression.substr(pos+1,expression.size()-pos),vars));
    }else if(i=='/'){
      return(stoi(temp)/evaluate(expression.substr(pos+1,expression.size()-pos),vars));
    }else if(i=='-'){
      return(stoi(temp)-evaluate(expression.substr(pos+1,expression.size()-pos),vars));
    }else if(i=='<'){
      return(stoi(temp)<evaluate(expression.substr(pos+1,expression.size()-pos),vars));
    }else if(i=='>'){
      return(stoi(temp)>evaluate(expression.substr(pos+1,expression.size()-pos),vars));
    }else if(i=='='){
      return(stoi(temp)==evaluate(expression.substr(pos+1,expression.size()-pos),vars));
    }else if(i==']'){
      temp=to_string(vars[stoi(temp)]);
    }else{
      temp+=i;
    }
    pos++;
  }
  //cout<<"DEBUG: "<<temp<<endl;
  return stoi(temp);
}

void interpret(string file){
  /*vector<string> contents=file_tree[current_dir];
  bool found=false;
  for(auto i:contents){
    if(i==current_dir+file){
      found=true;
      break;
    }
  }
  if(!found){
    cout<<"File does not exist.\n";
    return;
  }*/

	ifstream bloop;
	bloop.open(current_dir+file);
	string line;
	string word;
	stack<int> positions;
	stack<int> numbers;
	vector<int> vars (256,0);
	int temp;
	
	while(bloop>>word){
		if(word=="set"){
			bloop>>temp;
			getline(bloop,line);
      //cout<<temp<<' '<<line<<endl;
      vars[temp]=evaluate(line,vars);
		}else if(word=="out"){
			getline(bloop,line);
      cout<<evaluate(line,vars)<<endl;
		}
	}
	
	bloop.close();
}

void shutdown(){
  extern bool on;
  save_tree();
  cout<<"Shutting Down\n";
  on=false;
}

void login(){
  string user,user_path;
  FILE *user_file;
  cout<<"Welcome to the worst operating system, WTOS\n";
  while(true){ 
    cout<<"Please enter your username, or, to create a new account, type \"new\".\nAlternatively, type \"shutdown\" to shut down the OS.\nUsername: ";
    cin>>user;
    if(user=="new"){
      if(create_account()){break;}
    }else if(user=="shutdown"){
      shutdown();
      break;
    }else{
      user_path="users\\"+user+"\\password";
      //cout<<"User path is "<<user_path<<endl;
      user_file=fopen(user_path.c_str(),"r");
      if(user_file==NULL){
        cout<<"Non-existent account.\n";
      }else{
        if(authenticate(user_file,user)){
          break;
        }
      }
    }
  }
}

void logout(){
  extern string current_user,current_dir;
  save_tree();
  current_user="";
  current_dir="";
  login();
}

void blank(){
  for(int i=0; i<100; i++){
    cout<<"\n";
  }
}

void help(){
  blank();
  ifstream read;
  read.open("README.txt");
  string out;
  while(getline(read,out)){
    cout<<out<<endl;
  }
  read.close();
}

void status(){
  time_t t;
  time(&t);
  cout<<"\nUser: "<<current_user<<"\n\nCurrent Directory: "<<current_dir<<"\n\nAt "<<asctime(localtime(&t))<<endl;
}

void time(){
  time_t t;
  time(&t);
  cout<<"Current time is "<<asctime(localtime(&t))<<endl;
}

void newfile(string file_name){
  if(file_name.find('\\')!=file_name.npos||file_name.find('/')!=file_name.npos){
    cout<<"File names may not contain either '\\' or '/'.\n";
    return;
  }
  extern map<string,vector<string> > file_tree;
  extern string current_dir;
  ifstream n;
  n.open(file_name);
  n.close();
  file_tree[current_dir].push_back(current_dir+file_name);
}

void newdir(string dir_name){
  if(dir_name.find('\\')!=dir_name.npos||dir_name.find('/')!=dir_name.npos){
    cout<<"Folder names may not contain either '\\' or '/'.\n";
    return;
  }
  extern map<string,vector<string> > file_tree;
  extern string current_dir;
  file_tree[current_dir].push_back(current_dir+dir_name+"\\");
  file_tree[current_dir+dir_name+"\\"]=vector<string> (0);
}

void list(){
  extern map<string, vector<string> > file_tree;
  vector<string> dirs;
  vector<string> files;
  for(string i: file_tree[current_dir]){
    if(i[i.size()-1]=='\\'){
      dirs.push_back(i);
    }else{
      files.push_back(i);
    }
  }
  sort(dirs.begin(),dirs.end());
  sort(files.begin(),files.end());
  cout<<(dirs.size()?"Directories:\n":"No Directories\n");
  for(auto i: dirs){
    cout<<"    "<<i<<endl;
  }
  cout<<(files.size()?"Files:\n":"No Files\n");;
  for(auto i: files){
    cout<<"    "<<i<<endl;
  }
}

void cd(string path){
  extern string current_dir;
  if(path==""){
      current_dir="users\\"+current_user+"\\";
  }else if(path=="back"){
    if(current_dir=="users\\"+current_user+"\\"){
      cout<<"Access Restricted\n";
      return;
    }
    int size = current_dir.size();
    current_dir=current_dir.substr(0, current_dir.rfind('\\',size-2)+1);
  }else{
    if(file_tree.count(current_dir+path+"\\")){
      current_dir=current_dir+path+"\\";
    }else{
      cout<<"No such directory exists.\n";
    }
  }
}

void execute(string input){
  string command="";
  string args;
  int i;
  for(i=0; i<input.size(); i++){
    if(input[i]==' '){
      i++;
      break;
    }
    command+=input[i];
  }
  args=input.substr(i,input.size()-i);
  //cout<<command<<'\n'<<args<<endl;
  if(command=="logout"){
    logout();
  }else if(command=="help"){
    help();
  }else if(command=="status"){
    status();
  }else if(command=="shutdown"){
    shutdown();
  }else if(command=="newdir"){
    newdir(args);
  }else if(command=="cd"){
    cd(args);
  }else if(command=="list"){
    list();
  }else if(command=="time"){
    time();
  }else if(command=="newfile"){
    newfile(args);
  }else if(command=="write"){
    write_file(args);
  }else if(command=="view"){
    view_file(args);
  }/*else if(command=="delete"){
    delete_file(args);
  }else if(command=="rename"){
    int spacepos=args.find(" ");
    if(spacepos==args.npos){
      cout<<"Invalid parameters.\n";
    }else{
      rename_file(args.substr(0,spacepos),args.substr(spacepos+1,args.size()-spacepos));
    }
  }*/else if(command=="run"){
    interpret(args);
  }else if(command=="append"){
    append_file(args);
  }else{
    cout<<"Command \""<<command<<"\" not found.\n";
  }
}

int main() {
  build_tree();
  login();
  string input;
  getline(cin,input);
  while(on){
    cout<<current_dir<<" >>> ";
    getline(cin,input);
    execute(input);
  }
  /*int l[2]={2,3};
  cout<<(evaluate("2+3",l))<<endl;*/
}